用机器学习检测恶意Pickle模型,无需复杂配置且能识别隐藏攻击。
SafePickle: Robust and Generic ML Detection of Malicious Pickle-based ML Models
- 基于Pickle字节码的结构语义特征,用监督与无监督模型分类文件
- 在自建数据集上达90.01%准确率,优于现有工具7.23%-62.75%
- 可识别9个精心规避的恶意样本,适合安全检测与模型分发场景
Hugging Face等模型仓库广泛使用Python的Pickle格式序列化机器学习模型,用户在加载时面临远程代码执行风险。现有防御如PickleBall依赖特定库策略生成,需复杂系统配置和可信良性模型,难以扩展。本文提出轻量级、基于机器学习的扫描器,无需策略生成或代码注入即可检测恶意Pickle文件。方法静态提取Pickle字节码的结构与语义特征,应用监督与无监督模型进行分类。构建并发布包含727个Pickle文件的标注数据集(来自Hugging Face),在四个数据集上评估:自建数据集、PickleBall(分布外)、Hide-and-Seek(9个高级逃避型恶意模型)及合成joblib文件。本方法在自建数据集上达到90.01% F1-score,显著优于当前最优工具Modelscan、Fickling、ClamAV、VirusTotal的7.23%-62.75%。在PickleBall(OOD)上达81.22% F1-score,优于PickleBall的76.09%,且完全不依赖特定库。此外,唯一正确解析并分类全部9个Hide-and-Seek恶意样本,证明数据驱动检测可有效通用应对Pickle模型攻击。
原文摘要 · Abstract (English)
Model repositories such as Hugging Face increasingly distribute machine learning artifacts serialized with Python's pickle format, exposing users to remote code execution (RCE) risks during model loading. Recent defenses, such as PickleBall, rely on per-library policy synthesis that requires complex system setups and verified benign models, which limits scalability and generalization. In this work, we propose a lightweight, machine-learning-based scanner that detects malicious Pickle-based files without policy generation or code instrumentation. Our approach statically extracts structural and semantic features from Pickle bytecode and applies supervised and unsupervised models to classify files as benign or malicious. We construct and release a labeled dataset of 727 Pickle-based files from Hugging Face and evaluate our models on four datasets: our own, PickleBall (out-of-distribution), Hide-and-Seek (9 advanced evasive malicious models), and synthetic joblib files. Our method achieves 90.01% F1-score compared with 7.23%-62.75% achieved by the SOTA scanners (Modelscan, Fickling, ClamAV, VirusTotal) on our dataset. Furthermore, on the PickleBall data (OOD), it achieves 81.22% F1-score compared with 76.09% achieved by the PickleBall method, while remaining fully library-agnostic. Finally, we show that our method is the only one to correctly parse and classify 9/9 evasive Hide-and-Seek malicious models specially crafted to evade scanners. This demonstrates that data-driven detection can effectively and generically mitigate Pickle-based model file attacks.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。