Dev.to Security 🔐 Cybersecurity 👁 0 📖 2 min read

Malware Inside Hugging Face GGUF Models (2,428 Downloads): How Trailing-Byte RATs & Poisoned Chat Templates Work

Most local LLM users assume .gguf files are safe as long as you stay away from .pkl files. A new scan published on November 27, 2026 by Malspark breaks that assumption. After scanning all 3,273,389 public Hugging Face m

Most local LLM users assume .gguf files are safe as long as you stay away from .pkl files.

A new scan published on November 27, 2026 by Malspark breaks that assumption. After scanning all 3,273,389 public Hugging Face model repositories (226,310 GGUF repos totaling 2.56 PB and 572,184 chat templates), researchers confirmed 5 live malicious GGUF models totaling 2,428 downloads.

First, an Honest Reality Check

Before anyone panics and deletes Ollama: 2,428 is the Hugging Face download counter, not confirmed infected machines. Simply loading GGUF weights into llama.cpp, Ollama, or LM Studio does not automatically execute trailing binaries.

The actual exploit requires either a user copying a printed PowerShell command or a tool-enabled coding agent acting on hidden template instructions.

How the Two-Stage Attack Works

1. Bytes After the Last Tensor (GGUF-Specific)

GGUF headers declare exact byte offsets for every tensor. Runtimes stop reading right after the final tensor and silently ignore everything after it (unlike safetensors, which rejects files with leftover trailing bytes).

The main actor (Mir2k) appended an 11.47 MB Windows x64 RAT (ollie) after the last tensor of two uncensored GGUF uploads (1,488 and 458 downloads). In the second model, the payload was compressed with raw Deflate so antivirus signature checks saw nothing. Unpacked, ollie bundles a full 10.25 MB Tor 0.4.9.16 binary, a RandomX miner, and MetaMask/Phantom wallet stealer routines — and the same account pre-squatted 12 empty repos named after upcoming models (Qwen4-27B, DeepSeek-V4, Llama-4-Scout).

2. Plant First, Arm tokenizer.chat_template Later

  • Mir2k uploaded clean templates first to build downloads, then swapped tokenizer.chat_template days later so every reply opens with a PowerShell one-liner that reads the final 4.2 MB out of the .gguf file on disk, inflates it in RAM, and starts %TEMP%\d.exe.
  • timdedid (3 repos, 482 downloads) targeted agentic coding tools: when a prompt hits a dormant trigger phrase, the template silently injects a fake [SYSTEM DIRECTIVE] instructing a shell-capable agent to download and execute payload.ps1.

10-Second Audit & Defense (Root0ne/gguf-radar)

Malspark open-sourced an MIT-licensed scanner (Root0ne/gguf-radar) that checks both tokenizer.chat_template ASTs and trailing EOF bytes — even remotely on Hugging Face via HTTP Range requests without downloading gigabytes:

pip install git+https://github.com/Root0ne/gguf-radar

# Scan a Hugging Face repo remotely in seconds
gguf-radar scan Qwen/Qwen2.5-0.5B-Instruct-GGUF

# Rebuild a clean local GGUF (weights untouched, trailing bytes stripped)
gguf-radar sanitize suspicious.gguf -o clean.gguf

# Diff a community GGUF chat template against the official base model
gguf-radar compare-template ./model.gguf --base Qwen/Qwen2.5-0.5B-Instruct

If you wire local models into coding agents with shell access, always override embedded templates with --chat-template-file in llama.cpp or an explicit TEMPLATE block in your Ollama Modelfile.

Where do you pull local GGUF weights right now — strictly official/trusted quantizers, or random community uncensored uploads?

📰 Read the original article on Dev.to Security

Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.