Skip to content

cd .. && $ cat your-local-model-is-an-attack-surface.md

Your local model is an attack surface: templates, trailing bytes and poisoned weights

Why a downloaded GGUF is not inert data: hidden chat-template instructions, executables after the last tensor, backdoors edited into weights, and what actually helps.

---
commit
fb963b6
date
tags
[ llm , local-models , security ]
stats
+2,015 words, 9 min read
---

“I run it locally” usually ends the security discussion. No provider, no telemetry, no retention policy to read. Just you, a GPU and a 9 GB file from Hugging Face.

That file is the problem. A GGUF is not a bag of numbers. It is a header, a metadata table with a small program in it, a tensor table, padding, the weights, and whatever else someone decided to append. November 2026 delivered the first documented campaigns that use exactly that structure against people running local models. Taking the provider out of the loop does not take the attacker out with it. It just means you are the one doing the checks now.

An earlier piece, Running agents on local models: small, split and sandboxed, argued that “local is not the same as safe” from the model’s behaviour. This one opens the file.

1. The chat template is code you never see

Every GGUF carries a chat template under the metadata key tokenizer.chat_template. It is a small Jinja2 program. Before every reply, the runtime runs your conversation through it to build the text the model actually reads (GGUF LLM Models with Hidden Malware on Hugging Face Reached 2400 Victims).

C++ runtimes such as llama.cpp render that template in a restricted engine with no Python behind it, so the classic template-injection tricks that reach the operating system do not work. The attackers did not need them. Ordinary template logic is enough to add text to the conversation, and that text never shows up in your chat window. The prompt injection ships pre-installed.

The scan found two flavours:

  • Tool hijacking. The timdedid models are a Qwen3 1.7B “cyber” fine-tune. Their template is the official Qwen3 one with one addition: when your message contains “What is”, it inserts a fake [SYSTEM DIRECTIVE]. The directive tells an agent to use its PowerShell tool, download a script and run it in a hidden window. The README helpfully advises you not to replace the embedded template.
  • Reply prefix. The Mir2k models add a system message: begin every answer with this one PowerShell line, copied character by character, then answer normally. The model stays perfectly helpful. It just opens every reply with a command you might copy.

This is not GGUF-specific. Safetensors and PyTorch models carry the same kind of template in tokenizer_config.json or chat_template.jinja. It is also a familiar pattern. ANSI escape sequences in MCP output are invisible to the human and verbatim to the model (ANSI escape injection in MCP servers - Hidden from humans, visible to AI). A planted AGENTS.md steers a coding agent with the developer’s privileges (One Markdown File Can Hijack Your AI Coding Agent). The chat template is the same trick one layer deeper: instructions in a place that you never read but the model always does.

2. Bytes after the last tensor

The second half of the attack is pure file-format archaeology. A GGUF header says exactly where the model data ends. Runtimes read those byte ranges and nothing else. Anything appended after the last tensor never loads and changes nothing about how the model behaves, and no runtime warns about it (GGUF LLM Models with Hidden Malware on Hugging Face Reached 2400 Victims).

So Mir2k appended a Windows executable. In one model it is followed by about half a megabyte of filler, so a scanner that only reads the last few kilobytes sees nothing. In the other it is compressed with raw Deflate, which strips every recognisable file signature. The reply-prefix line from section 1 is the glue: it finds the largest .gguf in your user profile, reads its last few megabytes, writes them to %TEMP%\d.exe and starts it. You never download anything except the model. The model hands you the installer.

The timeline is the clever part. Plant first, arm later:

  • 22 November: the first model is uploaded with the executable already appended, but with a clean template.
  • 24 November: the second model follows, same payload compressed, template still clean.
  • 26 November: both templates are swapped within an hour. Nine hours later they are swapped again to search the whole user profile instead of a fixed Downloads path.

Anyone who grabbed the files early had a loaded gun with no trigger. Anyone who pulled again after the 26th got the trigger. The same account also created twelve empty repositories named after models that did not exist yet, among them Qwen4-27B, DeepSeek-V4 and gemma-4-27b. They were ready to be filled on launch day, when people search fast and read slowly.

The implant itself unpacks to an 11.47 MB binary, most of it a bundled copy of Tor. It checks for sandboxes, persists via scheduled tasks and watchdogs, steals browser passwords and crypto-wallet extensions, logs keys and screenshots, and mines Monero when the machine is idle. It names its folder ollie, close enough to Ollama to look like it belongs. Its UAC bypass fails, because the registry paths were compiled without their backslashes. Even malware authors lose fights with string escaping.

Safetensors would have refused this half of the attack: its loader rejects files whose declared tensors do not fill the file exactly. GGUF has no such rule.

3. Three hiding places nobody has used yet

If hubs start rejecting GGUF files with trailing bytes, the format still has room. The same analysis reproduced three further hiding spots in synthetic lab files. None changes a single dequantised weight, and none triggers a warning in llama.cpp or gguf-py (GGUF LLM Models with Hidden Malware on Hugging Face Reached 2400 Victims):

  • Alignment padding. Raise general.alignment from 32 bytes to a few megabytes and you get a gap that loaders skip without checking that it is empty.
  • GGUF + ZIP polyglot. GGUF is read from the start, ZIP from the end. Append a ZIP and the file still loads as a model and imports as Python via zipimport. One file, two personalities, zero warnings.
  • Zero-scale blocks. A Q8_0 block stores a scale and 32 values. With a scale of zero, any 32 bytes decode to zero weights. Write the scale as negative zero (0x8000) and you also dodge checks looking for 0x0000. IEEE 754 strikes again.

None of these is in the wild yet. “Yet” is doing a lot of work in that sentence.

4. The weights themselves

Everything so far leaves traces in the file’s structure, which means a careful scanner can find it. The next two do not.

TrojanMaxxing asks frontier agents (the paper names Claude Opus 5.5 and Mythos 5.2) to backdoor a vision-language model by reading and editing its weights directly. No training, no gradients. The agents also design an imperceptible visual trigger. The backdoored models hit attack success rates of 93–100% on content moderation and 78–100% on OCR while keeping their clean accuracy (TrojanMaxxing - One-shotting VLM backdoors with weight-space programming). The authors’ own summary of the method is that you can do it by simply “asking an agent to do it”. Model poisoning used to need a research team. Now it needs a prompt.

The backward-pass trick goes the other way, into training. A malicious regulariser evaluates to exactly zero, logs 0.000000 every step, and still makes gradient descent overwrite a chosen slice of weights with the next state of an arbitrary program. The demo runs Conway’s Game of Life inside the weights. The checkpoint’s SHA-256 matches, the modelling code reads clean and the TensorBoard curve is flat (How to Run Turing-Complete Malware in PyTorch’s Backward Pass). The only thing that changed is everything.

Neither has a structural fingerprint. A trojaned weight is still a weight. File scanners do not help here. Only provenance and behaviour testing do.

5. And the toolchain around the model

The model file is the newest link in a chain that was already weak. LiteLLM 1.107.0 on PyPI dropped a .pth file into site-packages. Python executes those at startup, so the credential stealer ran in every Python process on the host, including ones that never imported LiteLLM. It took SSH keys, cloud credentials, CI secrets and the LLM provider keys in the proxy database. The release came out of the official pipeline, signed, after attackers obtained developer credentials. Provenance attestation would have vouched for it (Compromised LiteLLM 1.107.0 on PyPI installs a credential stealer and backdoor).

Lined up, the four cases cover the whole stack:

Layer Case What a standard check sees
Package LiteLLM 1.107.0 A signed release from the official pipeline
Model file Mir2k trailing executable A model that loads and answers normally
Template timdedid tool hijack The official template plus a few lines nobody diffed
Weights TrojanMaxxing, backward-pass VM Matching hashes, normal benchmarks

Every layer passes the check designed for the layer below it.

6. What actually helps

Some perspective first. The scan covered 3.27 million repositories and found five malicious models with 2,428 downloads, and Hugging Face counts downloads, not people. The Mir2k implant targets Windows. Most of these attacks still need a step from you: copying a line the model printed, or giving an agent a shell tool. This is not a reason to stop running local models. It is a reason to stop treating model files like JPEGs.

Instead of Do Example
Trusting the embedded template Read tokenizer.chat_template before first use, or replace it with the template from the original base model A README that tells you not to replace the template is a red flag, not a tip
Pulling “latest” Pin a specific repo revision and re-check when it changes Mir2k armed its templates two to four days after upload
Running only an antivirus Check the file structure: trailing bytes, padding, zero-scale blocks, template contents gguf-radar parses the template without running it and rebuilds a clean file with identical weights
Trusting fresh “uncensored” fine-tunes Prefer known uploaders and base-model publishers. Treat day-old accounts with placeholder repos as suspects Download counts say little about quality anyway (I Tested Every Uncensored Local AI Model (8GB to 32GB VRAM))
Copying commands from model output Never run a command the model volunteered when you did not ask for one A chatbot that opens every answer with PowerShell is not being thorough
Giving the agent an open shell Sandbox it, restrict egress, require approval for downloads The timdedid directive only works if the agent can fetch and run a script
Treating training utilities as math Treat them as dependencies with write access to your weights A zero-valued loss term can still rewrite your model
pip install into your main environment Pin versions and hashes, isolate AI tooling per project A .pth file runs in every Python process, not just yours

Conclusion

Local inference moved the trust boundary, it did not remove it. You used to trust a provider. Now you trust an uploader, a template, a file format with generous padding and every Python package in your environment. The good news: the first wave is crude. The UAC bypass is broken, the payloads need your copy-paste, and structural checks catch the file tricks. The bad news: the weight-level attacks have no structure to check, and “ask an agent to do it” scales better than any red team.

Read the template. Pin the revision. Sandbox the agent. And if your model greets you with a PowerShell one-liner, the call is coming from inside the GGUF.

A caveat on the sources: the scan figures, timeline and malware analysis all come from a single write-up (Malspark, 2026-11-27), and gguf-radar is the tool presented in that same post. I have not seen independent confirmation. Download counts were changing fast at the time. TrojanMaxxing is an arXiv preprint covering VLMs, not text LLMs, so the success rates do not transfer directly. The backward-pass attack only applies if you run someone else’s training code.

Sources