Malicious GGUF LLM Models on Hugging Face: Analysis and Mitigation
Understanding the GGUF Poisoning Attack
Malicious actors are exploiting the GGUF file format to distribute malware via Hugging Face by leveraging two primary vectors: chat template poisoning and appending hidden payloads to the end of model files. This attack allows malicious code to execute on a victim's machine without triggering standard antivirus scanners, as the payload remains dormant until the model is loaded and a specific trigger phrase is used in a chat session.
Chat Template Poisoning
Every GGUF file contains a Jinja2 chat template under the tokenizer.chat_template metadata key. Attackers modify this template to inject hidden system directives into the conversation. These directives can instruct the model to output specific commands—such as PowerShell scripts—that the user is then prompted to copy and execute. Because these instructions are rendered within the model's internal prompt-processing engine, they remain invisible to the user in the chat interface.
Hidden Payloads in File Overlays
The GGUF format allows for data to be appended after the last tensor in the file. Standard inference runtimes like llama.cpp ignore this trailing data, meaning it does not affect model performance or loading. Attackers use this space to hide malicious executables. When combined with a poisoned chat template, the model can be instructed to read its own file on disk, extract the hidden binary, and execute it, effectively turning the model file into a self-extracting malware dropper.
Campaign Analysis: Mir2k and timdedid
A scan of over 3.2 million public Hugging Face repositories identified five malicious models across two distinct campaigns, totaling 2,428 downloads.
- Mir2k Campaign: This campaign utilized a Windows remote access trojan (RAT) named 'ollie'. The malware included a bundled Tor client for C2 communication, data exfiltration capabilities (stealing browser passwords and crypto wallet data), and Monero mining functionality. The campaign demonstrated a sophisticated approach by uploading the malicious payload days before activating it via a template update.
- timdedid Campaign: This campaign focused on hijacking coding agents. By inserting a
[SYSTEM DIRECTIVE]into the chat template, the model would attempt to force an agent to download and execute a remote script whenever a user asked a question starting with "What is".
Detection and Mitigation
Traditional antivirus solutions often fail to detect these threats because they do not inspect the internal structure of GGUF files or the logic within chat templates. To address this, the open-source tool gguf-radar has been developed to analyze GGUF files without execution.
How to Protect Your Environment
- Use
gguf-radar: This tool parses the file structure, flags suspicious templates, and identifies hidden bytes appended after the tensor table. It can rebuild a clean version of the GGUF file without altering the model weights. - Sandboxing: As noted by security researchers, running models in a restricted environment is a critical defense. By sandboxing the inference engine and any associated agents, users can limit the potential impact of a compromised model, regardless of the payload it attempts to execute.
- Manual Verification: Users should be wary of executing any commands suggested by an LLM, particularly when using community-sourced models. For high-security environments, compiling GGUF files from trusted sources or vetting them through automated pipelines is recommended.
"Unless the model is truly Open Source (not just open weight), there's no way to know what malicious instructions might be encoded in the weights. The only defense is to sandbox the agent sufficiently strongly that it can't do harm no matter what tokens it generates."
While the current scale of identified malicious models is small relative to the total number of repositories on Hugging Face, the technique represents a significant risk as the adoption of local LLMs grows. Security professionals emphasize that model hubs and inference runtimes should implement stricter validation, such as rejecting files with non-zero padding or unexpected trailing data, to mitigate this class of attack.