Scan models for hidden malware before you run them

llmman scan reads a GGUF, safetensors or pickle model without running anything and reports chat-template backdoors, payloads appended after the weights and data hidden in padding or quantized blocks.

On 27 November, Malspark published “GGUF LLM Models with Hidden Malware on Hugging Face Reached 2400+ Victims”. Scanning 3,273,389 public repositories, they found five malicious models that had been downloaded 2,428 times. llmman now has a command for checking a model file for the same tricks before you serve it: llmman scan MODEL.

What was found

The write-up describes two campaigns.

Mir2k published two “uncensored” GGUF models with a Windows RAT (Malspark calls it ollie) appended after the last tensor, the one place a loader never reads. One copy was stored as is. The other was raw Deflate compressed, so it had no file signature at all. The payload went up first. Days later the chat template was rewritten so the model starts every reply with a PowerShell line that reads the payload back out of the model file, writes %TEMP%\d.exe and starts it. The trigger was armed two to four days after the payload shipped, so for a while the template alone looked harmless.

timdedid published three copies of Qwen3 1.7B whose official template has one addition: when the user’s latest message contains “What is”, it inserts a hidden [SYSTEM DIRECTIVE] telling an agent that has a powershell tool to download and run a script.

The same article covers places to hide data that were demonstrated in the lab: a raised general.alignment so the padding becomes a large gap, GGUF and ZIP polyglots, and Q8_0 blocks with a zero scale (including a negative-zero scale), where the quantized bytes are ignored by the math and can carry anything. Earlier work includes Pillar Security’s July 2025 write-up on hiding instructions in GGUF chat templates and EvilModel (2021), which put malware in the low bits of a network’s weights.

Credit where it is due

Malspark’s post also links an open-source tool, gguf-radar (MIT, Python). llmman’s scanner is a native Rust implementation written against the attacks the article describes. It is not a port of gguf-radar’s code. gguf-radar also has a command that rebuilds a clean copy of a model; llmman scan does not. It only reports.

Run it

llmman scan gemma4                              # pulled first if not in the store
llmman scan gemma4 --no-pull                    # fail instead of pulling
llmman scan ./model.gguf --json --fail-on medium

MODEL is a path to a file or a directory (scanned recursively), or a model reference, resolved the same way llmman show resolves it. A path is never pulled. A model already in your store is scanned as it is: scan does not check signatures, it is not a policy gate. A reference that is not in your local store is pulled first, like llmman pull and llmman run do, with the same store lock and [verify] policy and no daemon. Pull notices go to stderr, so stdout and --json stay the report. Pass --no-pull to fail instead:

$ llmman scan gemma4 --no-pull
Error: gemma4 (docker.io/ai/gemma4) is not in the local store and --no-pull was set

Pulling only fetches bytes into the store. Nothing is loaded or run, and the scan then runs on exactly the files that were pulled. That also means scan needs the bytes on disk: it is not remote, so if you would rather inspect a model before downloading it, you cannot.

Scanning is not automatic: llmman pull, llmman serve and llmman run do not run it for you.

What it prints

The files below are harmless synthetic stand-ins, built with a throwaway Python script to mimic the described techniques: a few hundred bytes of header and one tiny quantized tensor, with the template text or the appended bytes added on top. The PowerShell in them does not do anything. The output is real, from the binary built from the merged code. I trimmed the long what: and evidence: lines, marked [...].

A clean file:

$ llmman scan clean.gguf
Scanned clean.gguf (gguf, 1 file)

No findings in 1 file.
$ echo $?
0

A template that reads a payload out of the model file, in the style of Mir2k:

$ llmman scan mir2k_template.gguf
Scanned mir2k_template.gguf (gguf, 1 file)

[CRITICAL] LLMMAN-TEMPLATE-LOADER  Template carries a loader: it reads files, decompresses and starts a process
  what:     GGUF key tokenizer.chat_template contains script text that, run by an agent with a shell tool, fetches or reads a payload and executes it. Indicators: $env: path variable, Deflate/GZip stream, IO.Compression, Start-Process, [IO.File] call, byte-level file read/write, search for *.gguf files, seek relative to .Length.
  where:    file mir2k_template.gguf, offset 516 (0x204), length 13

[HIGH] LLMMAN-TEMPLATE-HIDDEN-DIRECTIVE  Hidden directive injected into the conversation
  what:     GGUF key tokenizer.chat_template contains text that instructs the model or an agent covertly, outside normal chat scaffolding: order to start replies with copied text.
  where:    file mir2k_template.gguf, offset 150 (0x96), length 24

2 findings: 1 critical, 1 high, 0 medium, 0 low (at or above --fail-on high)

A template with a trigger phrase, in the style of timdedid:

$ llmman scan timdedid_template.gguf
Scanned timdedid_template.gguf (gguf, 1 file)

[CRITICAL] LLMMAN-TEMPLATE-CONDITIONAL-TRIGGER  Template emits an instruction only when the user's text matches a phrase
  what:     GGUF key tokenizer.chat_template has a branch gated on the message content containing "What is" that emits an instruction. It stays dormant until a user types the trigger, which is how a logic bomb evades review.
  where:    file timdedid_template.gguf, offset 198 (0xc6), length 45

[HIGH] LLMMAN-TEMPLATE-HIDDEN-DIRECTIVE  Hidden directive injected into the conversation
  [...]

[MEDIUM] LLMMAN-TEMPLATE-FILE-IO  Template reads or writes files
  [...]

3 findings: 1 critical, 1 high, 1 medium, 0 low (at or above --fail-on high)

A GGUF with an executable stub after the last tensor:

$ llmman scan trailing_pe.gguf
Scanned trailing_pe.gguf (gguf, 1 file)

[CRITICAL] LLMMAN-GGUF-TRAILING-DATA  Data the format does not account for
  what:     8217 byte(s) after the last tensor, starting at offset 230; the format does not account for them. [...] Contents: PE executable at offset 256.
  where:    file trailing_pe.gguf, offset 230 (0xe6), length 8217

[CRITICAL] LLMMAN-PAYLOAD-EXECUTABLE  Executable hidden in the model file
  what:     after the last tensor holds a native executable: PE executable at offset 256 (PE header at +0x80, other machine). A dropper that knows the offset can carve it out and run it.
  where:    file trailing_pe.gguf, offset 256 (0x100), length 2

2 findings: 2 critical, 0 high, 0 medium, 0 low (at or above --fail-on high)

And the second Mir2k trick, the same stub compressed as raw Deflate:

$ llmman scan trailing_deflate_pe.gguf
[...]
[CRITICAL] LLMMAN-PAYLOAD-COMPRESSED  Compressed executable hidden in the model file
  what:     A deflate stream starts at offset 256 [...] and inflates to 65528 bytes of a PE executable [...]. It has no signature of its own, which is how the second Mir2k model hid a PE
  where:    file trailing_deflate_pe.gguf, offset 256 (0x100), length 449

The scanner does not look for a MZ header in the raw bytes and stop there. It tries to inflate what it finds, and classifies what comes out.

Exit status and JSON

--fail-on takes low, medium, high or critical, default high. The exit status is 0 when no finding reaches that level and 1 when one does. A command error also exits 1, with Error: on stderr, so the exit status alone cannot tell a failed scan from a failed run.

--json prints the report on stdout with file, format, files, findings and summary. Each finding has id, severity, title, detail, file and, when known, offset, length and evidence. Evidence is escaped and cut at 160 characters, so a template that contains a terminal escape sequence is printed as text and does not reach your terminal as one.

The findings that matter most

IDSeverityWhat it means
LLMMAN-TEMPLATE-LOADERcriticalTemplate reads files, decompresses and starts a process (the Mir2k loader)
LLMMAN-TEMPLATE-CONDITIONAL-TRIGGERhigh, critical if the branch downloads and runsA branch on a phrase in the user’s text emits an instruction
LLMMAN-TEMPLATE-HIDDEN-DIRECTIVEhigh[SYSTEM DIRECTIVE], “MUST call the powershell tool”, “NEVER mention them”
LLMMAN-GGUF-TRAILING-DATAhigh, critical when classifiedBytes after the last tensor
LLMMAN-GGUF-PADDING-DATAhigh, critical when classifiedNon-zero bytes in padding or gaps
LLMMAN-GGUF-ZERO-SCALE-DATAhigh, medium if only fp16-underflow-likeZero-scale blocks that carry bytes the quantizer would not write
LLMMAN-PAYLOAD-EXECUTABLEcriticalPE, ELF or Mach-O in extra bytes
LLMMAN-PAYLOAD-COMPRESSEDcritical if it inflates to an executable or script, else highA Deflate, zlib or gzip stream in extra bytes
LLMMAN-ZIP-POLYGLOThigh, critical when a member is codeAn appended ZIP
LLMMAN-PICKLE-DANGEROUS-GLOBALcriticalA pickle that imports os, subprocess and similar
LLMMAN-REMOTE-CODEhighauto_map or trust_remote_code in a config
LLMMAN-IOC-OLLIEcriticalA known olliE implant indicator anywhere
LLMMAN-SCAN-PARTIALhigh for a work or size limit, medium for a text or JSON read cap, low for unknown filesPart of a file was not inspected
LLMMAN-SCAN-LIMITmediumThe directory walk hit 16 levels or 20,000 entries

The full list, with the structural GGUF and safetensors checks, is in docs/scan.md.

What it checks

  • Chat templates and other string metadata, for loaders, downloads, hidden directives, conditional triggers, template injection gadgets, invisible characters and encoded blobs.
  • Bytes after the last tensor, hashed, measured for entropy and classified: executable, script, archive, near-random data, or a Deflate, zlib or gzip stream that decodes to one of those. Every stream is tried, not only the first.
  • Padding and gaps, including a huge general.alignment.
  • ZIP polyglots, an archive appended to any file.
  • Zero-scale quantized blocks in Q4_0, Q4_1, Q5_0, Q5_1, Q8_0, Q8_1 and Q2_K to Q6_K. When a block’s scale is zero (and its minimum too, for the types that have one), the quantized bytes do not influence the weights, so any there other than the quantizer’s own fill are hidden capacity. Q8_0 blocks whose values peak at exactly 127 can be honest weights that underflowed in fp16, so those are counted separately at medium.
  • safetensors: the header, and whether the tensors tile the data section exactly, so nothing hides between or after them.
  • Pickle files: an opcode walk that flags dangerous imports.
  • Remote code references, and executables or scripts that ship next to the weights.
  • The olliE indicators from Malspark’s write-up.

Nothing is executed, rendered or unpickled. Templates are read as text, not run through a Jinja engine, and pickles are walked opcode by opcode. Reads are bounded: text and JSON at 32 MiB, one directory at 20,000 entries (or 16 levels deep), and 8 MiB buffers for large files. When a limit stops the scan, it says so instead of reporting a clean result for something it only half read: LLMMAN-SCAN-PARTIAL when part of a file was not inspected, and LLMMAN-SCAN-LIMIT when the directory walk stopped.

What it cannot tell you

This is a set of static heuristics. No findings is not proof that a model is safe.

  • It does not analyse weights beyond the zero-scale check. A backdoor trained into the weights, or data spread across their low bits as in EvilModel, is out of reach.
  • Zero-scale checks do not cover IQ, TQ, MXFP4, NVFP4, Q1_0, F32, F16, BF16 or integer tensors.
  • A template obfuscation nobody has written a pattern for yet can get past the template checks.
  • There is no remote scan. The model has to be on disk first, so scanning a reference that is not stored pulls it, and a model you would rather not download at all cannot be checked.
  • It reports and does not repair. If a file is flagged, you delete it.

I tested it against synthetic files, not real malware. No real ollie sample was used, so how it behaves on the actual Hugging Face models is inferred from the article and not observed. The suite has 157 scan unit tests and 26 CLI tests. Run over 95 real chat templates and three real LoRA safetensors files, it reported nothing, and a zero-scale pass over a synthetic 4 GiB GGUF ran at about 560 MiB/s in a debug build.

Try it

llmman scan gemma4
llmman scan gemma4 --no-pull
llmman scan ./model.gguf --json --fail-on medium

To gate a pipeline, also refuse any LLMMAN-SCAN- finding. --fail-on high alone lets a medium LLMMAN-SCAN-PARTIAL, -LIMIT or -READ-ERROR through with exit 0, though each means something was not inspected:

if ! { llmman scan ./model.gguf --json --fail-on high > report.json &&
       jq -e 'all(.findings[]; .id | startswith("LLMMAN-SCAN-") | not)' \
         report.json > /dev/null; }; then
  echo "scan failed or did not inspect everything, not using this model" >&2
  exit 1
fi

Questions are welcome at github.com/llmmanorg/llmman. Don’t be afraid to give the project a star or open a PR.