[来源关键摘录] ReversingLabs researchers detailed the nullifAI evasion technique on Hugging Face, using 7z compression and broken Pickle streams to hide reverse-shell payloads from Picklescan.
[正文前段节选] The inaugural Gartner® Magic Quadrant™ for Software Supply Chain Security is outGET THE REPORT
ReversingLabs: The More Powerful, Cost-Effective Alternative to VirusTotalSee Why
Get an Inside Look at Spectra Assure Community | Stop Trusting & Start Verifying Your SoftwareWatch Now
[ANALYSIS] THE PATCH IS THE ATTACK PAYLOADREAD NOW
The Tale of ClickFix: How Malware-as-a-Service campaigns turn users into the ultimate execution vectorDownload Now
Spectra Assure Free Trial
Get your 14-day free trial of Spectra Assure for Software Supply Chain Security
Get Free TrialMore about Spectra Assure Free Trial
Skip to main content
Open search modal
ReversingLabs: Home
Request a demo
Malicious ML models discovered on Hugging Face platform
Software development teams working on machine learning take note: RL threat researchers have identified nullifAI, a novel attack technique used on Hugging Face.
Karlo Zanki, Reverse Engineer at ReversingLabsKarlo Zanki
In the last few months, artificial intelligence (AI) is popping up in all kinds of headlines, ranging from technical software developer websites to the Sunday comics. There’s no secret why. Given the recent explosion in the capabilities of large language models (LLMs) and generative AI, organizations are trying to find ways to incorporate AI technologies into their business models — and to make use of its capabilities. While most non-technical people think of OpenAI’s ChatGPT when AI is mentioned (or maybe its Chinese competitor DeepSeek), developers and others familiar with machine learning (ML) models and the technology that supports AI will likely think of Hugging Face, a platform dedicated to collaboration and sharing of ML projects. As described in its organization card on the Hugging Face platform, the company is “on a mission to democratize good machine learning.” That democratization is happening. But with AI’s growing popularity and use, platforms like Hugging Face are now being targeted by threat actors, who are seeking new, hard-to-detect ways of inserting and distributing malicious software to unsuspecting hosts. This was underscored by a discovery the ReversingLabs research team made on the Hugging Face platform: a novel technique of distributing malware by abusing Pickle file serialization — a not-so-novel exploitation target.
Get White Paper: How the Rise of AI Will Impact Software Supply Chain Security
This video is blocked because of your cookie preferences.
Manage Cookie Preferences
Understanding Pickle
An ML model is a mathematical representation of a process that uses algorithms to learn patterns and make predictions based on provided data. After the models are trained, their mathematical representations are stored in a variety of data serialization formats. These stored models can be shared and reused without the need for additional model training. Pickle is a popular Python module that many teams use for serializing and deserializing ML model data. While easy to use, Pickle is considered an unsafe data format, as it allows Python code to be executed during ML model deserialization.
In theory, that should restrict the applicability of Pickle files only to data that comes from trusted sources. However, such a restriction collides with the concept of an open ML platform, designed to foster collaboration between different ML projects. The result: Pickle files are used broadly, while attackers have taken to abusing Pickle and other unsafe data serialization formats to hide their malicious payloads.There has been a lot of research pointing out the security risks related to the use of Pickle file serialization (dubbed “Pickling” in the Hugging Face community). In fact, even Hugging Face’s documentation describes the risks of arbitrary code execution in Pickle files in detail. Nevertheless, Pickle is still a wildly popular module and malicious Pickling is a growing problem, as ML developers prefer productivity and simplicity over security.
During RL research efforts, the team came upon two Hugging Face models containing malicious code that were not flagged as “unsafe” by Hugging Face’s security scanning mechanisms. RL has named this technique “nullifAI,” because it involves evading existing protections in the AI community for an ML model.While Pickling is not using common evasion techniques like typosquatting, or attempting to mimic a popular, legitimate ML model, the packages look more like a proof-of-concept model for testing a novel attack method. But that method is legitimate — and poses a risk to developers, so it is worthwhile to dig deeper into these malicious packages to examine how they work.
Figure 1a: Malicious Hugging Face model discovered by ReversingLabs researchers.
Figure 1b: Malicious Hugging Face model discovered by ReversingLabs researchers.
The two models RL detected are stored in PyTorch format, which is basically a compressed Pickle file. By default, PyTorch uses the ZIP format for compression, and these two models are compressed using the 7z format, which prevents them from being loaded using PyTorch’s default function, torch.load(). That is likely the reason why Picklescan — the tool used by the Hugging Face to detect suspicious Pickle files — did not flag them as unsafe. Recent research conducted by Checkmarx concluded that it isn’t that hard to find a way to bypass the security measures implemented by Hugging Face. The Picklescan tool is based on a blacklist of “dangerous” functions. If such functions are detected inside a Pickle file, Picklescan marks them as unsafe. Blacklists are basic security features, but not scalable or adaptable as known threats morph — and new threats emerge. It is not a surprise, then, that Checkmarx researchers found other functions that could trigger code execution but were not listed on the Picklescan blacklist. The broken and malicious models RL discovered highlight another shortcoming in the Picklescan tool: an inability to properly scan broken Pickle files. For us, disassembling the Pickle files extracted from the mentioned PyTorch archives revealed the malicious Python content at the beginning of the file. In both cases, the malicious payload was a typical platform-aware reverse shell that connects to a hardcoded IP address.
Figure 2: Decompiled Pickle file with the malicious Python payload.
An interesting thing about this Pickle file is that the object serialization — the purpose of the Pickle file — breaks shortly after the malicious payload is executed, resulting in the failure of the object’s decompilation. That raised an interesting question for our research team: What happens if you try to load a “broken” Pickle file? Do security tools recognize the presence of dangerous functions in the broken files and mark them as unsafe?Since the malicious payload in the discovered samples is located at the beginning of the serialized object, RL crafted its own Pickle samples that create a file on the filesystem and write a simple text into it. The team first created a valid Pickle file and then inserted one “X” binunicode Pickle opcode just before the “0x2E” (STOP) opcode, which marks the end of Pickle stream.
Figure 3: One-byte difference between the valid and broken Pickle file
Scanning the valid Pickle file using the Picklescan tool resulted in the expected security warning. After the valid file was executed, notice (see Figure 4) that a new my_file.txt file appears in the directory. Everything worked as expected in case of the valid Pickle file.
Figure 4: Security scanning and execution of valid Pickle file.
[...内容已截断,完整版请查看原文或 Wayback 快照]