Malicious GGUF Models on Hugging Face: How to Check Yours

Malicious GGUF models on Hugging Face hid a RAT after the last tensor and poisoned chat templates. Check local LLM files, pin templates, limit agents.

TL;DR

  • What happened: Malspark found five malicious GGUF models on Hugging Face after scanning 3,273,389 public repos on 26 November 2026.
  • Who is affected: Anyone who pulled those repos; Malspark counted 2,428 downloads by 27 November, mostly Windows users and shell-enabled agents.
  • What to do now: Scan local .gguf files, pin a reviewed chat template, and never run commands a model tells you to run.
  • Interview angle: AI supply chain, indirect prompt injection through templates, and least-privilege design for agents with shell tools.

Malicious GGUF models are model files that look normal to a loader but carry an attack. In this campaign, attackers hid a Windows remote-access tool after the last tensor and rewrote the chat template so the model told users to run a one-line extraction command. Check your files, pin templates, and treat model output as untrusted.

GGUF is the binary file format used by llama.cpp and tools built on it, such as Ollama, to store model weights and metadata in one file. Its specification defines a header, key-value metadata and aligned tensor data. A chat template is a Jinja program stored in that metadata; it turns your messages into the exact prompt the model sees.

Below: what changed, how it works, and a small Python checker I wrote and ran on test files.

What changed and who is affected?

Researcher Düzgün published the findings on Malspark on 27 November 2026. The scan covered 226,310 GGUF repositories using HTTP Range requests. Two accounts were behind the five repos.

Malicious GGUF repos reported by Malspark (downloads as of 27 November 2026)
Repository Technique Downloads
Mir2k/Huihui-Qwen3.5-9B-abliterated-GGUF Appended payload + poisoned template 1,488
Mir2k/Inkling-2-Mini-Uncensored-GGUF Appended payload + poisoned template 458
timdedid/qwen3.8-cyber-uncensored Hidden agent directive in template 271
timdedid/qwen3-cyber-UNCENSORED-2 Hidden agent directive in template 136
timdedid/qwen3-cyber-UNCENSORED Hidden agent directive in template 75

The dates matter. According to Malspark’s timeline, the Mir2k models shipped with clean templates on 22 and 24 November. Both templates were swapped on 26 November. Malspark notes that downloads made before 26 November contain the payload but not the trigger.

Downloads are not victims. Malspark says Hugging Face counts downloads, not people, and Spectrum Security adds that downloads establish neither distinct victims nor infections. Malspark reported all five repos still online on 27 November. Removal is unconfirmed, so check the repo pages yourself.

How does the malicious GGUF attack work?

No parser bug is involved. The attack abuses two trusted parts of a model file.

The flow, at advisory level

  1. The attacker appends an executable after the final tensor. Loaders read tensors by offset, so these bytes are never touched during inference.
  2. The attacker edits tokenizer.chat_template to add a hidden system message.
  3. Every reply now starts with a copy-paste command. If the user runs it, it extracts the hidden bytes from the local model file and starts them.
  4. The timdedid variant targets agents instead: a trigger phrase inserts a fake system directive telling a shell-enabled agent to fetch and run a remote script. Malspark did not recover that second stage.

Malspark says antivirus engines and tail-only checks do not see the compressed payload. The model still loads and chats normally.

A working checker you can run

The GGUF spec makes appended data easy to measure. Each tensor offset is relative to the start of tensor data, and data is aligned to general.alignment, which defaults to 32. So the file should end right after the last tensor, plus at most one alignment pad. I wrote this standard-library checker and ran it on Python 3.13.18:

#!/usr/bin/env python3
"""gguf_tail_check.py - stdlib-only GGUF sanity check (defensive).
Flags bytes after the last tensor and risky strings in tokenizer.chat_template."""
import struct, sys, re

SIZES = {0:1,1:1,2:2,3:2,4:4,5:4,6:4,7:1,10:8,11:8,12:8}  # fixed-size GGUF value types
# ggml type -> (block elements, bytes per block); subset of common types
GGML = {0:(1,4),1:(1,2),2:(32,18),3:(32,20),6:(32,22),7:(32,24),8:(32,34),
        10:(256,84),11:(256,110),12:(256,144),13:(256,176),14:(256,210),30:(1,2)}
RISKY = re.compile(r"powershell|invoke-|iex\b|%temp%|\.exe\b|curl\s|wget\s|system directive", re.I)

def rd(f, fmt):
    n = struct.calcsize(fmt); return struct.unpack("<"+fmt, f.read(n))[0]

def rstr(f):
    return f.read(rd(f, "Q")).decode("utf-8", "replace")

def rval(f, t):
    if t == 8: return rstr(f)
    if t == 9:
        it, n = rd(f, "I"), rd(f, "Q")
        if it in SIZES and it != 8: f.seek(SIZES[it]*n, 1); return f"<array {n}>"
        return [rval(f, it) for _ in range(n)]
    fmt = {0:"B",1:"b",2:"H",3:"h",4:"I",5:"i",6:"f",7:"?",10:"Q",11:"q",12:"d"}[t]
    return rd(f, fmt)

def check(path):
    with open(path, "rb") as f:
        if f.read(4) != b"GGUF": return "ERROR", "not a GGUF file"
        ver, nt, nkv = rd(f,"I"), rd(f,"Q"), rd(f,"Q")
        meta = {}
        for _ in range(nkv):
            k = rstr(f); meta[k] = rval(f, rd(f, "I"))
        align = meta.get("general.alignment", 32)
        end = 0
        for _ in range(nt):
            rstr(f); nd = rd(f,"I"); dims = [rd(f,"Q") for _ in range(nd)]
            t, off = rd(f,"I"), rd(f,"Q")
            if t not in GGML: return "ERROR", f"unknown ggml type {t}"
            n = 1
            for d in dims: n *= d
            be, bb = GGML[t]
            end = max(end, off + (n // be) * bb)
        pos = f.tell(); data_start = pos + (align - pos % align) % align
        f.seek(0, 2); size = f.tell()
    findings = []
    extra = size - (data_start + end)
    if extra > align:  # allow final alignment padding only
        findings.append(f"{extra} bytes after the last tensor")
    tpl = meta.get("tokenizer.chat_template", "")
    hits = sorted(set(m.group(0).lower() for m in RISKY.finditer(tpl)))
    if hits: findings.append("chat template contains: " + ", ".join(hits))
    return ("SUSPICIOUS" if findings else "CLEAN"), f"v{ver}, {nt} tensors, {size} bytes; " + ("; ".join(findings) or "no findings")

if __name__ == "__main__":
    worst = 0
    for p in sys.argv[1:]:
        verdict, msg = check(p); print(f"{verdict:10} {p}: {msg}")
        worst = max(worst, {"CLEAN":0,"ERROR":1,"SUSPICIOUS":2}[verdict])
    sys.exit(worst)

To test it, I generated three small files with the gguf Python package (version 0.19.0): a clean file, a copy with 4,096 random bytes appended, and one whose template only contains the word “powershell”. No real payload was used.

$ python3 gguf_tail_check.py clean.gguf tail.gguf tpl.gguf
CLEAN      clean.gguf: v3, 2 tensors, 9504 bytes; no findings
SUSPICIOUS tail.gguf: v3, 2 tensors, 13600 bytes; 4096 bytes after the last tensor
SUSPICIOUS tpl.gguf: v3, 2 tensors, 9536 bytes; chat template contains: powershell
exit=2

It knows only common tensor types and a short keyword list. Use it for triage, not as a maintained scanner.

What should developers do right now?

  1. Detect: search your machines and model caches for the five repo names in the table. Run gguf-radar (gguf-radar scan ./models/) or the checker above on every local .gguf file.
  2. Check endpoints: look for a shell started by your model client or agent CLI that reads from a .gguf file and writes an executable to the temp folder. Spectrum Security maps this to Sysmon process, network and file-create events.
  3. Remove and replace: delete flagged files and pull models only from publishers you trust.
  4. Pin the template: in llama.cpp server, pass --chat-template-file; by default the template comes from the model’s metadata. In Ollama, set TEMPLATE in a Modelfile.
  5. Restrict agents: remove shell tools agents do not need and require approval for commands. My earlier guide to setting up a local AI coding agent covers sandboxing options.
  6. Gate intake: if your team runs a model registry, reject files with bytes after the last tensor or non-zero padding, as Malspark recommends.

Interview questions this update prepares you for

1. Why are model files a supply-chain risk, and how does GGUF differ from pickle?

A model file is a dependency you execute against, just like an npm package. Python’s pickle docs warn that unpickling untrusted data can run arbitrary code, so pickle-based checkpoints are dangerous at load time. GGUF is a pure data format, so loading it does not run code. But “safe to parse” is not “safe to trust”: metadata such as the chat template still steers behaviour, and extra bytes can ride along unnoticed.

Follow-up they may ask: How would you verify a model’s provenance before production?

2. What is indirect prompt injection, and how can a chat template carry it?

Indirect prompt injection is when instructions reach the model through content the user did not write, such as a web page, a document or a tool result. A chat template is executed on every turn and can add hidden system text, so it is an ideal carrier. Treat templates as code: review, pin and diff them on every update.

Follow-up they may ask: How would you detect a template change between two model versions?

3. How would you design a safe model-intake pipeline for a team?

Mirror approved models into an internal registry instead of letting every laptop pull from public hubs. At intake, parse the file, compare its size with the computed end of tensor data, statically scan the template, record a hash, and require a reviewer for new publishers. Runtimes then load only hashed, approved files with a pinned template. This is the same pattern as a private package proxy, which I covered for npm supply-chain defence.

Follow-up they may ask: What would you log so you can answer “who downloaded this file?” later?

4. How do you give an AI agent shell access safely?

Start from least privilege: most agents do not need a shell at all. If one does, run it in a sandbox or container with no secrets, an allowlist of commands, no outbound network by default, and human approval for anything outside the list. Model output must be treated like user input from an untrusted source, never as a trusted instruction.

Follow-up they may ask: Where would you enforce the allowlist: in the prompt, the agent framework, or the OS?

The NexGismo verdict: this is not a llama.cpp bug, and waiting for a patch misses the point. My recommendation: treat model files like packages and templates like code, and pin both. The biggest risk is an agent with a shell that trusts what the model prints.

  • Malspark found five malicious GGUF repos after scanning 3,273,389 public Hugging Face repos on 26 November 2026.
  • The repos had 2,428 downloads by 27 November; downloads are not the same as infections.
  • The payload sat after the last tensor, where GGUF loaders never read.
  • A rewritten chat template told the model to print a command that starts the payload.
  • Pinning a reviewed template in llama.cpp or Ollama removes the file’s control over hidden instructions.

Frequently Asked Questions

Are GGUF files safe to download from Hugging Face?

GGUF is a data format, so loading the weights does not run code by itself. The risk sits in two places: the chat template that controls what the model says, and any bytes appended after the tensors. Malspark found five repos abusing both. Pin a reviewed template and scan files before use.

How do I check if a GGUF model has malware?

Run a static scanner such as gguf-radar, which flags risky chat templates and bytes after the last tensor. Also compare the file size with the end of the tensor data, review tokenizer.chat_template by eye, and check endpoint logs for shells started by your model client.

Can a chat template run code on my computer?

Not directly. A template only shapes the text the model produces. In this campaign the template told the model to print a command and asked the user, or a shell-enabled agent, to run it. That is why agent shell access and copy-paste habits matter as much as the file itself.

How do I override a model’s chat template in llama.cpp or Ollama?

In llama.cpp server, pass –chat-template-file with a reviewed Jinja file; otherwise the template comes from the model's metadata. In Ollama, set TEMPLATE in a Modelfile, which uses Go template syntax. Either way, the file's embedded template no longer decides what the model is told.

Malicious GGUF models fail in the same places as package attacks: trusted names, unreviewed updates and over-privileged tools. Scan your model folders today and pin your templates. If you are building browser or coding agents, my notes on AI browser agent security and the recent LiteLLM guardrail escape cover the next layer of defence.

Sources