45 Recipe: scan pulled model artefacts before they enter your lab
| Field | Value |
|---|---|
| Tool | guarddog + picklescan + modelscan (all A-4, safe) — the pre-#210 inspector-quartet rows were phantom-upstream (removed; names ride the os#210 registry) |
| Section | Administrator |
| Level | medium |
| Time | ~30 min per intake batch |
| Layer/Category | ATTACK / a-04-model-supply-chain (+ the lab intake gate) |
| Tags | admin, supply-chain, model-artefacts, scanners, torch, huggingface, owasp-llm04 |
45.1 Problem
Model artefacts arrive from download-first-ask-later ecosystems. A Hugging Face pull lands a .bin or .safetensors file that the loader will deserialize. Its GGUF file embeds the chat-template text the runtime will splice into every prompt. Pickled weights are the documented sharp edge — loading a model is deserialization, and deserialization runs code. The manifest dedicates Layer ATTACK’s a-04-model-supply-chain to exactly this surface (guarddog, picklescan, modelscan; the pre-#210 inspector quartet was phantom-upstream and is removed — os#210). The lab wants the scan queue between “downloaded” and “torch-loaded” to exist by policy, not by mood.
45.2 Solution
The queue runs in one order. The order: repo review, serialized-format scans, safe-format checks, template inspection, then the environment the model asks the lab to build. Nothing that fails it ever reaches torch.load:
# 1. What the manifest declares for the A-4 scan surface
kailash list --category a-04-model-supply-chain
# 2. Repo-level review FIRST (the repo is the artefact, not one file):
# hand-review the repo card/file tree at the hub (the pre-#210
# hub-inspector row was phantom-upstream — removed, os#210):
# mixed formats, loader scripts, freshness signals.
# 3. Serialized-format scans — run BOTH scanners, they cover different
# corners of the pickle family:
picklescan --path /srv/model-cache/<model-dir> --include='\.pkl$|\.bin$|\.pth$'
modelscan -p /srv/model-cache/<model-dir> -r json -o /tmp/modelscan-scan.json
# 4. Safetensors artefacts — the safe-serialization format still
# carries a header/metadata surface: inspect it by hand
# (safetensors ships tools; the pre-#210 checker row
# was phantom-upstream — removed, os#210):
python3 - <<'PY'
from safetensors import safe_open
with safe_open(path, framework="pt") as f:
print(f.metadata())
PY
# 5. GGUF: surface the embedded chat templates + metadata — the
# prompt-path injection vector inside quantized weights:
# (llama.cpp ships gguf-dump / gguf-py; the pre-#210
# template-inspector row was phantom-upstream — removed)
python3 -m gguf.scripts.gguf_dump /srv/model-cache/<model>.gguf | head -50
# 6. The environment the model repo tells you to build — the packages
# around the weights are as attackable as the weights:
guarddog pypi verify /srv/model-cache/<model-dir>/requirements.txt
guarddog pypi scan <pinned-package> --version <ver>Both serialized-format scanners are file-local analyses with ClamAV-style exit contracts — CI-gateable as-is:
# the queue as a gate: fail the intake batch on any non-zero scan
picklescan --path /srv/model-cache/<batch-dir> \
--include='\.pkl$|\.bin$|\.pth$' --exclude-dir='^\.git$'
modelscan -p /srv/model-cache/<batch-dir> --exit-status-when-issues # shape: see CLI flags belowExpected output shape (abridged, shapes not transcripts):
picklescan -> per-file line(s):
<model-path>:archive/data.pkl: global import '<module> <function>' FOUND
----------- SCAN SUMMARY -----------
Scanned files: <n> Infected files: <n?> Dangerous globals: <n?>
(exit 0 clean / 1 malware found / 2 scan failed — ClamAV-style)
modelscan -> console/json report:
issue rows: {format/serialization family, severity: CRITICAL|HIGH|
MEDIUM|LOW, code-signature summary, file}
exits: 0 no vulnerabilities / 1 vulnerabilities found / 2 scan error /
3 no supported files passed / 4 usage error
guarddog -> per-package findings table or JSON
(-r/--rules and -x/--exclude-rules select heuristics;
--exit-non-zero-on-finding flips any issue into a gate failure)
Then the WHY — why the queue exists and why it stays between pull and load. The pre-#210 pickle-PoC demo row was phantom-upstream (removed, os#210) — the demonstration lives in the upstream’s own documented PoC material. The pickle deserialization warning path (pytorch stable docs, torch.load(weights_only=True) mitigation) is the honest citation — read it, never re-run a made-up CLI:
# 7. The evidence pointer (authorised lab only):
cat /etc/kailash/safety/wrapped-exp-tools.json # the gate's state record
# (post-os#210: hexstrike-ai / kailash-mcp / mcp-kali-server /
# mcpoison — there is no PoC row anymore; the removed
# row's name rides the os#210 registry)The policy line this recipe encodes: no file that failed (or skipped) the queue is loaded, and weights_only=True does not replace the queue. Current stable torch.load defaults to weights_only=True, which narrows the unpickler surface but is a loader-side mitigation, not an intake guarantee.
45.3 Discussion
- Why six scanners and not one: the formats fail differently.
picklescanreads pickle/PyTorch files by opcode and flags dangerous globals (eval-class imports,os.system, thetorch.*code-execution paths in its global blocklist) — upstream README cites its canonical demo as catchingevalinside a “totally-harmless-model”.modelscanreads byte-wise across formats — pickle, dill, joblib, cloudpickle for classic ML, plus H5/Keras/SavedModel — ranking findings CRITICAL/HIGH/MEDIUM/LOW.guarddogdoes not touch the weights at all: it scans the package environment (Semgrep source rules + metadata heuristics, typosquat detection) for whatever the model’s dependencies pull in. The modern formats’ own vectors stay hand-checked for now (the pre-#210 checker/inspector rows were phantom-upstream — removed, os#210); HF’s own pickle-scanning doc notes the pickle threat is theSTACK_GLOBAL/GLOBAL/REDUCEopcodes while safetensors’ header carries a free-form__metadata__string map, and llama.cpp’s gguf constants carrytokenizer.chat_template(+named variants) keys — text that lands in the prompt path at serve time. - Repo review rides top of the queue: hand-review of the repo card + file tree catches what single-file scanners cannot — a repo whose
.binis clean but whose loader script is not. (A pre-#210 manifest row framed exactly this contract; it was phantom-upstream and removed, os#210 — the review duty it named is real and stays.) - These are ATTACK-layer rows running as admin intake: all three scanner rows carry
safety.level: safe— the guide’s safety-classes table reads the class as self-contained, no live firing — because every scan is a file-local analysis. The rows map the risk in the abstract: the trio cites ATLAS AML.T0010 + AML.T0011 and OWASP LLM04 (2026 epoch) / LLM03 (v2). The chat-template injection vector (GGUFtokenizer.chat_templatekeys landing in the prompt path at serve time) is the pre-#170-inspector-row’s named vector — the vector is real (llama.cpp constants), and the removed tool’s mapping rode it. - The exp leg: the pre-#210 demonstration row was phantom (removed, os#210) — exp-gated live-fire legs wait on the rebuild contract; the gate walk (Gate lab-mode and exp-classified tools) stays the reference for when one lands.
- Nothing here loads your data: every scanner above operates on the artefact bytes directly. That is the design point of the queue — it is provably pre-load analysis, so a malicious artefact cannot self-protect by defending its own deserialization.
- Exit contracts make it CI:
picklescan(0/1/2),modelscan(0/1/2/3/4) andguarddog --exit-non-zero-on-findingall give the gate a mechanical success predicate. Wire the same three into the CI intake job, rather than a human’s memory.
45.4 See also
- Boot a verified release image — the verified pull that starts the intake
- Gate lab-mode and exp-classified tools — the gate the PoC leg runs behind
- Refresh wordlists and data packs — the opt-in data-pack mechanism, same discipline for cache corpora
- Serve a local model for scanning — what runs after the intake passes
- The guide’s reference coverage (per-tool pages generate from the manifest): https://docs.kailash.tools/reference/coverage.html
- Upstream surfaces: guarddog README https://github.com/DataDog/guarddog · picklescan https://github.com/mmaitre314/picklescan · modelscan https://github.com/protectai/modelscan · llama.cpp gguf constants https://github.com/ggml-org/llama.cpp · safetensors format https://github.com/huggingface/safetensors
- The pre-#210 inspector rows were phantom-upstream (CLI surfaces never existed) — removed per the os#210 audit; names ride the registry: os#210
- The A-4 manifest lane (rows + Appendix-A corrections at the pin): kailash-os#76
- Recipe directory
Recipe provenance. Manifest facts post-os#210 (a-04 = guarddog, picklescan, modelscan; safety safe; licences Apache-2.0/MIT/Apache; ATLAS AML.T0010/T0011 + OWASP LLM04→LLM03 epoch map; packaging: modelscan native, guarddog/picklescan bespoke with LANDED derivations) are quoted from the purged packages manifest, verified 2026-10-14. The pre-#210 inspector-quartet + PoC rows were phantom-upstream (never-created kailash-os repos) and are REMOVED per the os#210 audit CLI shapes checked against upstream at each pinned repo’s default branch (raw guarddog/cli.py, picklescan + modelscan READMEs including exit codes and --include/--exclude filtering, guarddog --exit-non-zero-on-finding, safe_open/__metadata__ from the safetensors README, tokenizer.chat_template keys from llama.cpp gguf-py/constants.py, torch.load(weights_only) from the pytorch stable docs) — verified 2026-10-14. Worked hands-on run of the queue against a real pulled artefact batch: PENDING — smoke status lives with the A-4 packaging lane (kailash-os#76) per tool.
ref: a-04 manifest rows + cli/README shapes at the pins - verified 2026-10-14.