> ## Content Index
> Fetch the complete content index at: https://blog.netpy.in/llms.txt
> Use this file to discover other available public pages before exploring further.

# GGUF malware on Hugging Face: your model file is executable
- URL: https://blog.netpy.in/gguf-model-files-are-executable/
- Published: 2026-11-29T02:34:04.000Z
- Updated: 2026-11-29T02:34:04.000Z
- Description: A scan of 3.27 million Hugging Face repos found five malicious GGUF models downloaded 2,428 times. This is how a poisoned chat template and bytes after the last tensor turn a model download into code execution, and what to gate before it reaches a laptop.
- Author: Netpy Technologies
- Tags: AI, Security, Supply Chain, LLM, Engineering

A model file is not data. It is a program with a header, a tensor table and often a payload, and the runtime will do what the file says. On 26 November 2026 a scan of every public model repository on Hugging Face found five malicious GGUF models downloaded 2,428 times, and the largest had been sitting in plain sight for four days before it was armed.

The scanner, Malspark, read headers and file ends through HTTP Range requests instead of downloading weights, and parsed chat templates statically without executing them. It covered all 3,273,389 public model repositories, 226,310 of them GGUF, and parsed 572,184 templates. Five repositories survived manual review, all still online on 27 November.

## Two ways to carry a payload, and neither needs a CVE

The first is the chat template. Every GGUF file stores a small Jinja2 program under `tokenizer.chat_template`, which the runtime renders before every prompt to build the exact text the model reads, never showing it in the chat window. The malicious templates do not even need to escape the restricted rendering engine; they use ordinary template logic to inject text the user cannot see.

That is the timdedid campaign: three byte-identical copies of a Qwen3 1.7B model published on 21 and 22 November for security users, each with one addition near the end of an otherwise official Qwen3 template. If the user's latest message contains `What is`, the template inserts a `[SYSTEM DIRECTIVE]` telling an agent with shell access to download a PowerShell script into `C:\Windows\Temp` and run it hidden. The second stage was never recovered, so nobody knows what it installed.

The second technique is GGUF-specific and much quieter. A GGUF header declares where the tensor table ends and where the farthest tensor ends. Everything after that point is never read by `llama.cpp` or LM Studio, so an appended executable changes neither loading nor behaviour, and no runtime warns. Safetensors cannot be abused this way, because its loader rejects any file whose declared tensors do not fill it exactly. GGUF has no such check.

Mir2k combined both. It uploaded two uncensored models on 22 and 24 November with the payload appended and the original clean template, so nothing could start it. On the morning of 26 November both templates were rewritten within about an hour, then again nine hours later. The new one orders the model to begin every reply with one PowerShell line, copied character by character, which finds the largest `.gguf` file in the user profile, reads its last bytes, writes them to `%TEMP%\d.exe` and starts it. One model stored the program in the clear behind half a megabyte of filler; the other Deflated it, stripping every file signature while PowerShell can still inflate it in memory.

The implant that unpacks is an 11.47 MB Windows x64 remote access trojan, most of it a bundled Tor client. It checks for virtual machines and sandbox usernames, installs a scheduled task that runs every ten minutes, keeps two watchdogs and marks its process critical, then exfiltrates saved browser passwords over an onion service, targets Phantom and MetaMask wallets and mines Monero when the machine is idle.

## Why "verify the weights" is not a defence

The zero-scale trick from the lab is the part engineers should read twice. A Q8\_0 block stores one scale and 32 values, and every weight is the scale times its value. With a scale of zero any 32 bytes decode to zero weights, so an already-zero block can carry text while the dequantized model stays bit-identical; writing the scale as negative zero also defeats checks for the byte pattern `0x0000`. Two files with identical weights can differ in what they say. Hash the model, diff the tensors, and you can still be holding a poisoned artifact. Antivirus missed it because the payload sat behind filler, where scanners that read the last few kilobytes see nothing. We already treat container images as executable: pinned digests, scanned at the registry, unsigned pushes blocked. Model files arrived without that ceremony, because for years they were inert numbers.

## The checklist we would run

- Inventory every `.gguf` and `.safetensors` on laptops, Ollama directories, model caches and inference hosts.
- Scan before use with `gguf-radar`, which parses the template without executing it, computes where the model data must end, and reports bytes past that point, non-zero padding and negative-zero scales. `gguf-radar scan ./model.gguf`, then `gguf-radar sanitize suspicious.gguf -o clean.gguf`.
- Pin templates. Pass a reviewed template with `--chat-template-file` in `llama.cpp`, or set `TEMPLATE` in an Ollama Modelfile, so the embedded one is out of the loop.
- Gate at the registry, not on the laptop. Reject files with bytes after the last tensor or non-zero alignment padding, and keep a hash allowlist per model revision. Anything from a new account with no history, or a community "uncensored" or "cyber" fine-tune, starts untrusted.
- Audit agent tool permissions. The timdedid template only works if an agent can call a shell without a human confirming the download-then-execute step. That confirmation is the control, not the prompt.
- Keep endpoint detection on inference hosts. Scheduled tasks every ten minutes, two watchdogs and Tor on port 9050 are loud signals.

The structural fix belongs to the hubs: reject bytes after the last tensor and non-zero padding, and scan templates for PowerShell loaders and hidden directives. Until then, the gate is yours.

If your team runs local models for client work, this is supply-chain hygiene applied to a format that skipped it. [NetPy](https://netpy.in/?ref=blog.netpy.in) builds and operates model-serving stacks and internal registries; [NetPyCloud](https://cloud.netpy.in/?ref=blog.netpy.in) covers the case where inference has to run on hosts nobody shares with a laptop. Either way, the first decision is which artifacts may execute, and it is cheaper to make before a laptop starts mining.

Sources: Malspark, "GGUF LLM Models with Hidden Malware on Hugging Face Reached 2400+ Victims", 27 November 2026; tooling gguf-radar (MIT). Prior work: Pillar Security on GGUF chat templates (July 2025), Fogel et al. (2026), EvilModel (2021).