Malicious GGUF Models Found on Hugging Face
Contents
Security researchers found weaponized GGUF model files on Hugging Face that accumulated more than 2,400 downloads. Attackers appended a Windows trojan to the end of the models and altered the Jinja2 chat templates to trigger it.
How chat template poisoning works
GGUF files store metadata alongside weights, including a Jinja2 template under tokenizer.chat_template. Inference tools like llama.cpp and LM Studio run this template to format prompts before the model sees them. Because the C++ engine runs in a restricted sandbox without Python bindings, it cannot run shell commands directly, but it can still control what the model outputs.
Attackers use the template to feed instructions the user never sees in the chat interface. In this campaign, the template told the model to start answers with a PowerShell command for the user to run, or prompted agent tools with shell access to download malicious files directly.
Hiding binaries beyond the tensor table
Unlike Safetensors, which checks that file size matches declared data, the GGUF specification sets boundaries from its header table. Loaders read only the byte ranges mapped to tensors and ignore everything after the final tensor. That lets attackers append a complete Windows executable to a valid model file without triggering loader errors.
# Extractor payload injected by malicious templates
$file = (Get-ChildItem -Path $env:USERPROFILE -Filter *.gguf -Recurse | Sort-Object Length -Descending | Select-Object -First 1).FullName
$stream = [System.IO.File]::OpenRead($file)
# Payload reads hidden bytes trailing the model weights and drops an executableThe Mir2k campaign and the 'ollie' trojan
An attacker using the handle Mir2k uploaded uncensored variants of popular open weights models. Appended to the files was an 11.47 MB Windows binary named ollie, padded with junk data or raw Deflate compression to bypass scanners that inspect file tails. The malware disguises itself in AppData\Roaming\ollie and includes several payloads:
- Tor communication: Runs an embedded Tor 0.4.9.16 client to connect with command servers over hidden services.
- Password theft: Pulls stored credentials from Chrome, Edge, and Brave using DPAPI.
- Crypto wallets: Targets browser extensions like MetaMask and Phantom.
- Background mining: Runs a Monero (RandomX) miner when the system sits idle.
- Anti-analysis checks: Shuts down if it detects virtualization tools or sandbox environments like VMware, VirtualBox, or Sandboxie.
Protecting local models
Most antivirus software scans only the start and end of multi-gigabyte files, making padded or compressed payloads hard to catch. Utilities like gguf-radar inspect the header table, find bytes trailing the tensor range, and check templates for hidden instructions.
Users running models locally should check SHA256 hashes against original releases, review the chat template inside model metadata, and avoid running command snippets output by conversational models.