Hugging Face GGUF Templates Told Agents to Download and Run Scripts

Malspark found five Hugging Face GGUF repos, downloaded 2,428 times, whose chat templates make the model print a PowerShell loader for a Windows RAT or tell a local agent to run a script. Pin a reviewed template and scan GGUFs at intake.

By Rajesh Beri·November 29, 2026·9 min read
Share:
A developer's laptop on a desk showing a terminal window with a local language model chat open, a single unexplained line of code printed at the top of the reply, and an external drive labelled only with a generic file i

Illustration generated using AI

If your developers pull community GGUF models from Hugging Face into Ollama, llama.cpp or a local agent, the file can now carry instructions to run malware, and the usual scanners never look at them. Malspark found five public repos, downloaded 2,428 times, whose embedded chat templates either make the model print a PowerShell line that unpacks a Windows remote-access trojan hidden in the same file, or tell a tool-using agent to download and run a script. The fix is cheap: run models with a chat template you reviewed, never the one that ships inside the download, and scan GGUF files before they reach a laptop.

The findings come from Malspark's report published November 27, 2026, based on a scan of 3,273,389 public Hugging Face model repositories on November 26. That scan covered 226,310 GGUF repos and parsed 572,184 chat templates. After manual review removed test repos and research samples, five malicious repos from two accounts were left, and all five were still online on November 27. Malspark's post includes no response from Hugging Face.

What a Poisoned Chat Template Does

A chat template is the small program, usually Jinja, stored in a GGUF file's metadata that turns a conversation into the exact token string the model expects. The runtime executes it on every turn. Anyone who edits it can add a system message the user never sees, and Pillar Security described that attack in July 2025: instructions that sit dormant until a trigger appears and leave the weights untouched.

Pillar later tested the idea with Fujitsu across 18 models from seven families and reported in February 2026 that attacker URLs were emitted at success rates above 90%, that the attack "generalized across all four inference engines" it tried (llama.cpp, Ollama, vLLM and SGLang) with less than 5% variance, and that the poisoned files passed every automated scan Hugging Face applied.

Until this week the strongest counterargument was that nobody had used it. Splunk's February 19, 2026 study ingested metadata from about 156,000 GGUF files, narrowed it to roughly 50 unique chat templates worth inspecting, found them benign, and called the risk "plausible but currently unexploited." That was a fair reading in February. Malspark's scan now shows it in the wild.

This is a different problem from CVE-2024-34359, the critical (CVSS 9.6) llama-cpp-python bug where an unsandboxed Jinja engine let a malicious template run arbitrary code on the host. That was patched in version 0.2.72, and JFrog notes that other GGUF runtimes such as Ollama were not exposed to it. The November campaign needs no bug at all. The template runs exactly as designed and simply tells the model, or the agent, what to say.


How the Two Campaigns Worked

The two accounts took different routes to the same goal: getting a human or an agent to execute code the attacker shipped.

The Mir2k account uploaded Huihui-Qwen3.5-9B-abliterated-GGUF (1,488 downloads) on November 22 and Inkling-2-Mini-Uncensored-GGUF (458 downloads) on November 24, both with clean templates, according to Malspark. Each file carries an 11.47 MB Windows program appended after the last tensor; in the Inkling file it is compressed with Deflate. On November 26 both templates were armed with a French system message that, translated, tells the model to begin every reply with a given line "copied character by character" and then answer normally. The line is PowerShell: it finds the largest .gguf in the user profile, reads its last bytes, writes them to %TEMP%\d.exe and starts it. Nine hours after arming, the templates were changed again to search the whole profile instead of a fixed Downloads path. A developer who copies the odd line at the top of a reply into a terminal installs the trojan.

The timdedid account took the agent route. Its three repos (271, 136 and 75 downloads) use the official Qwen3 template plus one addition: when the latest user message contains "What is", the template inserts a "[SYSTEM DIRECTIVE]" telling an agent with a powershell tool to download value.ps1 from a WordPress site to C:\Windows\Temp\payload.ps1 and run it in a hidden window. The README advises users not to replace the embedded template. Malspark could not recover that second-stage script, so what it would have installed is unknown.

Mir2k is also set up for the next release. The account created 14 repos on November 22, and 12 are empty placeholders named for expected models such as Qwen4-27B, DeepSeek-V4, Llama-4-Scout and gemma-4-27b. When one of those ships, a search for its GGUF build may land on an account that has already armed two templates.

What the Trojan Does, and What Is Unconfirmed

The Mir2k payload is a full remote-access trojan, but Malspark's analysis of it is static only, so treat the capability list as a reading of the code rather than observed behaviour. Per the report, the program exits if it detects VirtualBox, VMware or Sandboxie, persists through a scheduled task every 10 minutes at highest privilege plus watchdog processes, and talks to its operator through an embedded copy of Tor 0.4.9.16. It steals saved passwords from Chrome, Edge and Brave, targets the Phantom and MetaMask wallets, supports keylogging, screenshots, screen streaming and webcam capture, and mines Monero when the machine is idle.

Two caveats matter for your response. Download counts are not people: Hugging Face counts downloads, so 2,428 is not a count of affected machines; repeat pulls inflate it, and a file copied inside a team never shows up in it. And Malspark says neither the Mir2k binary hash nor the campaign strings had public sightings when it wrote the report, so your EDR vendor may not have signatures yet.


Why Your Scanners and Loaders Miss It

None of the controls most teams rely on read the two places this campaign hides things. Hugging Face's malware scanning runs ClamAV over every file under 2 GB at each commit, and its pickle scan lists the imports in pickle files. Neither page mentions GGUF metadata or chat templates, and a Jinja template that adds a sentence of French is not malware to an antivirus engine.

The appended executable gets past the runtimes for a structural reason. A GGUF loader reads only the byte ranges its header and tensor table point to, so anything after the last tensor is never touched and, in Malspark's words, "no runtime warns about it." Scanners that read only the last few kilobytes miss the compressed variant. The safetensors format is stricter here: its loader refuses a file whose declared tensors do not fill it exactly.

The Hub's own interface adds a third gap. Pillar found that Hugging Face shows the template from the first file in a repo, so a clean template on one quantization can sit beside a poisoned one on the Q4_K_M build most people download. When Pillar disclosed that in June 2025, Hugging Face said it "did not classify as a vulnerability," and LM Studio said users are responsible for reviewing what they download.

The runtimes trust the embedded template by default. The llama.cpp server documentation lists the Jinja template engine as enabled by default, and Hugging Face's Ollama guide says that for an hf.co/ pull, Ollama selects a template based on the tokenizer.chat_template metadata inside the GGUF. The same guide says a repo can ship its own template file to customize it, which puts that choice in the uploader's hands as well.


What to Do About Community GGUF Models

The control is to separate the weights you download from the instructions you run them with. You can take the weights from anyone after a scan; the chat template should come from the model's original publisher or from your own reviewed copy.

This Week:

  1. Hunt on developer endpoints for the five repo names, %TEMP%\d.exe, C:\Windows\Temp\payload.ps1, an ollie folder under AppData\Roaming and the domain listed in Malspark's indicator tables. Search proxy logs for hf.co and huggingface.co pulls of Mir2k/ and timdedid/ paths since November 22. If you find a hit, treat the machine as compromised and rotate browser-saved passwords and any wallet keys on it.
  2. Ask each team running local models which GGUFs they pulled from accounts that are not the original model publisher. "Abliterated" and "uncensored" community builds are where both campaigns sat.
  3. Tell developers in one sentence: a command a model prints is untrusted input, and a line at the top of a reply that the user did not ask for is a reason to stop.

This Month:

  1. Pin templates. Malspark recommends passing a reviewed template with --chat-template-file in llama.cpp, or a TEMPLATE line in an Ollama Modelfile, so the one embedded in the file is ignored. Keep those templates in a repo you control and review changes like code.
  2. Put an intake step in front of developer machines. Mirror approved models into a private registry (our Hugging Face alternatives guide compares the options, including JFrog AI Catalog) and run each GGUF through a check that rejects bytes after the last tensor and diffs the embedded template against the publisher's original. Malspark recommends its gguf-radar scanner for incoming models; Splunk's mismatch test (repo template versus embedded template) is a simple second check.
  3. Remove shell and PowerShell tools from local agents that run community models, or put them behind per-command approval. The timdedid template only works if the agent can execute what it is told.

Before Your Next Model Refresh:

  1. Write the rule into policy: community GGUFs are allowed only through the registry, and only with a pinned template. This matters most for the Qwen4 and DeepSeek-V4 builds Mir2k has already reserved names for.

The Bigger Picture

Model files have followed the path software packages took. First came code execution in the format itself (pickle, then CVE-2024-34359), and the ecosystem answered with safer formats and sandboxed engines. Now the attack has moved to content the runtime executes on purpose, so a safer file format no longer helps. We covered the weight-level version of this in the Lazarus dormant-neuron backdoor and the package-level version in the Microsoft Agent Framework PyPI compromise. The answer in both cases was provenance plus a gate at intake, and it is the same answer here. Local inference also tends to run outside the logging your AI gateway provides, a gap we described in the Muse Glimmer piece, so an endpoint is often the only place you will see it.

Start with the hunt on developer machines this week, then pin the templates.

Continue Reading

Share:

Frequently Asked Questions

What is a poisoned GGUF chat template?

A chat template is the Jinja program inside a GGUF file's metadata that formats a conversation for the model, and runtimes execute it on every turn. A poisoned one adds hidden instructions, such as a system message telling the model to print a command or telling an agent to download and run a script, without changing the weights.

Which Hugging Face models were malicious?

Malspark named five repos on November 27, 2026: Mir2k/Huihui-Qwen3.5-9B-abliterated-GGUF, Mir2k/Inkling-2-Mini-Uncensored-GGUF, and three timdedid repos (qwen3.8-cyber-uncensored, qwen3-cyber-UNCENSORED-2 and qwen3-cyber-UNCENSORED), with 2,428 downloads combined.

Does Hugging Face's malware scan catch poisoned chat templates?

Hugging Face documents a ClamAV scan of files under 2 GB and a pickle import scan. Neither covers GGUF chat templates, and Pillar Security reported that its poisoned test files passed every automated scan Hugging Face applied.

How do I protect Ollama or llama.cpp from a malicious chat template?

Run models with a template you reviewed instead of the embedded one: a TEMPLATE line in an Ollama Modelfile or --chat-template-file in llama.cpp, as Malspark recommends. Also scan GGUFs at intake for bytes after the last tensor and remove shell tools from local agents running community models.

Newsletter

More on AI Security, every Sunday

The week's enterprise AI news, AI Security included, in one Sunday email.

Weekly, free. Unsubscribe any time. Privacy

Latest Articles

View All →