Treat model files like executables: five malicious GGUFs on Hugging Face
A scan of 3.27 million repositories found five malicious models with 2,428 downloads. Neither antivirus nor pickle scanners caught them.
Yohan Choi
· 2 min read
Key takeaways
- A scan of 3.27 million public Hugging Face repositories found five malicious GGUF models (2,428 downloads), and neither antivirus nor pickle scanners detected them.
- Two techniques were used: a RAT appended to the file and a poisoned chat template. A chat template can be a prompt injection planted in the model file.
- Check the uploader, file size and chat template, and narrow agents' shell access. Model files now deserve the scrutiny of executables.
Last week I wrote about coding models that run on a single GPU. As more people download local models, where those model files come from has become a security question.
#What was found
On November 26, the security firm Malspark scanned all 3,273,389 public model repositories on Hugging Face and reported five malicious GGUF models. As of November 27 they had 2,428 downloads. That counts downloads, so the number of affected people may be lower.
Two techniques were used.
- A trojan appended to the file: an 11.47 MB Windows remote access tool (RAT) was attached after the last tensor. The model still works normally, so users are unlikely to notice.
- A poisoned chat template: instructions hidden in the GGUF's chat template made the model start every answer with a line of PowerShell, hoping the user would copy and run it. Some templates reportedly told tool-using agents to download and run a script.
In the researchers' tests, neither antivirus nor pickle scanners raised an alert. GGUF has been seen as a "safe format" because, unlike pickle, loading it doesn't execute code. This attack targeted the template and human behavior instead of the file format.
#A chat template is effectively a prompt
The second technique is the one that caught my attention. A chat template is configuration for how the model reads a conversation, and almost nobody opens it. If you can put instructions in it, that is a prompt injection planted in the model file.
A person in a chat window can ignore a strange command, but an agent with shell access is different. Local models combined with auto-executing agents are the riskiest setup.
#What to check before downloading a model
- Check who uploaded it. Prefer official organizations and long-standing quantizers, and be extra suspicious of new accounts with eye-catching names like "uncensored" or "abliterated." The models named in this case had names like that.
- Compare file sizes. If a file is several MB larger than others of the same model and quantization, data may have been appended.
- Open the chat template. If the template in the GGUF metadata contains commands, URLs or lines like "always start with," don't use it. The researchers released gguf-radar, an MIT-licensed scanner that checks templates and trailing bytes and can rebuild a clean file with the weights unchanged.
- Narrow the agent's execution rights. Require approval for shell commands, and run in a sandbox or container where you can.
- Read commands a model outputs before running them. Know what a command does before you paste it.
Just as you check the source and hash of a code package, model files now need the same scrutiny as executables.
Sources
AI-TLDR: Malicious GGUF models on Hugging Face (Malspark)
DEV: Malware inside Hugging Face GGUF models, how trailing-byte RATs and poisoned chat templates work
Beri: Hugging Face GGUF templates told agents to download and run scripts
Share
About the author
Yohan Choi
Founder, Lab Yohanium
Yohan designs, builds and ships every project in the lab, from the first sketch to the production release.
About the labSecurity
Working on a problem like this?
If this article is close to something on your desk, the lab can build it with you or talk it through first.
Get the next article by email
New insights and released projects, about twice a month. Unsubscribe any time.