weightprobe 0.2.0__tar.gz → 0.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- weightprobe-0.3.0/PKG-INFO +285 -0
- weightprobe-0.3.0/README.md +247 -0
- {weightprobe-0.2.0 → weightprobe-0.3.0}/pyproject.toml +9 -2
- {weightprobe-0.2.0 → weightprobe-0.3.0}/src/weightprobe/__init__.py +17 -1
- {weightprobe-0.2.0 → weightprobe-0.3.0}/src/weightprobe/cli.py +208 -3
- weightprobe-0.3.0/src/weightprobe/deser_scan.py +294 -0
- weightprobe-0.3.0/src/weightprobe/mcp.py +604 -0
- weightprobe-0.3.0/src/weightprobe/mcp_impl_analysis.py +472 -0
- {weightprobe-0.2.0 → weightprobe-0.3.0}/src/weightprobe/payload_shape.py +7 -0
- weightprobe-0.3.0/src/weightprobe/pickle_deep.py +604 -0
- {weightprobe-0.2.0 → weightprobe-0.3.0}/src/weightprobe/scan.py +113 -9
- {weightprobe-0.2.0 → weightprobe-0.3.0}/src/weightprobe/spectral.py +15 -0
- weightprobe-0.3.0/src/weightprobe.egg-info/PKG-INFO +285 -0
- {weightprobe-0.2.0 → weightprobe-0.3.0}/src/weightprobe.egg-info/SOURCES.txt +13 -1
- {weightprobe-0.2.0 → weightprobe-0.3.0}/src/weightprobe.egg-info/requires.txt +1 -0
- weightprobe-0.3.0/tests/test_deser_scan.py +67 -0
- weightprobe-0.3.0/tests/test_deser_scan_corpus.py +45 -0
- weightprobe-0.3.0/tests/test_h5_adversarial.py +85 -0
- weightprobe-0.3.0/tests/test_mcp.py +588 -0
- weightprobe-0.3.0/tests/test_mcp_corpus.py +71 -0
- weightprobe-0.3.0/tests/test_pickle_deep_corpus.py +96 -0
- weightprobe-0.3.0/tests/test_scan_quantized.py +90 -0
- weightprobe-0.3.0/tests/test_thresholds.py +135 -0
- weightprobe-0.2.0/PKG-INFO +0 -190
- weightprobe-0.2.0/README.md +0 -153
- weightprobe-0.2.0/src/weightprobe.egg-info/PKG-INFO +0 -190
- {weightprobe-0.2.0 → weightprobe-0.3.0}/LICENSE +0 -0
- {weightprobe-0.2.0 → weightprobe-0.3.0}/setup.cfg +0 -0
- {weightprobe-0.2.0 → weightprobe-0.3.0}/src/weightprobe/__main__.py +0 -0
- {weightprobe-0.2.0 → weightprobe-0.3.0}/src/weightprobe/adapter_inject.py +0 -0
- {weightprobe-0.2.0 → weightprobe-0.3.0}/src/weightprobe/diff_base.py +0 -0
- {weightprobe-0.2.0 → weightprobe-0.3.0}/src/weightprobe/hash.py +0 -0
- {weightprobe-0.2.0 → weightprobe-0.3.0}/src/weightprobe/inventory.py +0 -0
- {weightprobe-0.2.0 → weightprobe-0.3.0}/src/weightprobe/live_probe.py +0 -0
- {weightprobe-0.2.0 → weightprobe-0.3.0}/src/weightprobe/rev_trigger.py +0 -0
- {weightprobe-0.2.0 → weightprobe-0.3.0}/src/weightprobe/signing.py +0 -0
- {weightprobe-0.2.0 → weightprobe-0.3.0}/src/weightprobe/verify.py +0 -0
- {weightprobe-0.2.0 → weightprobe-0.3.0}/src/weightprobe.egg-info/dependency_links.txt +0 -0
- {weightprobe-0.2.0 → weightprobe-0.3.0}/src/weightprobe.egg-info/entry_points.txt +0 -0
- {weightprobe-0.2.0 → weightprobe-0.3.0}/src/weightprobe.egg-info/top_level.txt +0 -0
- {weightprobe-0.2.0 → weightprobe-0.3.0}/tests/test_hash_verify.py +0 -0
- {weightprobe-0.2.0 → weightprobe-0.3.0}/tests/test_inventory.py +0 -0
- {weightprobe-0.2.0 → weightprobe-0.3.0}/tests/test_live_probe.py +0 -0
- {weightprobe-0.2.0 → weightprobe-0.3.0}/tests/test_payload_shape.py +0 -0
- {weightprobe-0.2.0 → weightprobe-0.3.0}/tests/test_rev_trigger.py +0 -0
- {weightprobe-0.2.0 → weightprobe-0.3.0}/tests/test_scan.py +0 -0
- {weightprobe-0.2.0 → weightprobe-0.3.0}/tests/test_signing.py +0 -0
- {weightprobe-0.2.0 → weightprobe-0.3.0}/tests/test_spectral_diff_base.py +0 -0
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: weightprobe
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: Defensive tooling for architectural backdoors, MCP supply-chain attacks, and compression-evading pickle trojans in transformer LLM repos and agent runtimes — eleven detection modes (hash, verify, inventory, spectral, diff-base, payload-shape, scan, live-probe, rev-trigger, mcp, pickle-deep) plus OpenSSF-style signing and OWASP AI BOM emission.
|
|
5
|
+
Author-email: Bodhisattva Das <bodhisattva.das@rudrasecure.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/bdas-sec/weightprobe
|
|
8
|
+
Project-URL: Repository, https://github.com/bdas-sec/weightprobe
|
|
9
|
+
Project-URL: Issues, https://github.com/bdas-sec/weightprobe/issues
|
|
10
|
+
Project-URL: Changelog, https://github.com/bdas-sec/weightprobe/blob/main/CHANGELOG.md
|
|
11
|
+
Keywords: llm-security,supply-chain,backdoor-detection,model-attestation,transformer,safetensors
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Information Technology
|
|
14
|
+
Classifier: Intended Audience :: Science/Research
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Topic :: Security
|
|
20
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
21
|
+
Requires-Python: >=3.10
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
License-File: LICENSE
|
|
24
|
+
Requires-Dist: numpy>=1.24
|
|
25
|
+
Requires-Dist: safetensors>=0.4
|
|
26
|
+
Requires-Dist: py7zr>=0.21
|
|
27
|
+
Provides-Extra: dev
|
|
28
|
+
Requires-Dist: pytest>=8.0; extra == "dev"
|
|
29
|
+
Provides-Extra: runtime
|
|
30
|
+
Requires-Dist: mlx>=0.20; extra == "runtime"
|
|
31
|
+
Requires-Dist: mlx-lm>=0.19; extra == "runtime"
|
|
32
|
+
Provides-Extra: signing
|
|
33
|
+
Requires-Dist: cryptography>=42.0; extra == "signing"
|
|
34
|
+
Provides-Extra: full
|
|
35
|
+
Requires-Dist: weightprobe[runtime]; extra == "full"
|
|
36
|
+
Requires-Dist: weightprobe[signing]; extra == "full"
|
|
37
|
+
Dynamic: license-file
|
|
38
|
+
|
|
39
|
+
# weightprobe
|
|
40
|
+
|
|
41
|
+
**Ingest-time supply-chain defence for AI: model weights, MCP servers, and pickle trojans.**
|
|
42
|
+
|
|
43
|
+
`weightprobe` is an analysis CLI that detects four classes of supply-chain attack against AI artifacts: (a) **architectural backdoors** — adapters or weight-edits inserted into model files; (b) **loader-style trojans** — malicious scripts that ship *beside* untouched weights; (c) **merged-into-base backdoors** — abliterations and distilled-in trojans where the weights have been edited in place; (d) **MCP-server supply-chain attacks** — malicious behaviour hidden in MCP manifests or their referenced implementation files (postmark-mcp class, gemini-mcp-tool CVE-2026-0755, mcp-remote CVE-2025-6514); and (e) **compression-evading pickle attacks** — the nullifAI 7z bypass and friends. Plus OpenSSF-style ed25519 model signing and OWASP CycloneDX 1.6 AI BOM emission.
|
|
44
|
+
|
|
45
|
+
> **v0.3 catches the MCP-supply-chain attack the agent runtime would otherwise install, and the nullifAI 7z-wrapped pickle that HuggingFace picklescan misses — at ingest time, before either ever reaches production.**
|
|
46
|
+
|
|
47
|
+
## What's new in v0.3 (November 2026)
|
|
48
|
+
|
|
49
|
+
Three new modes for the 2026 threat landscape:
|
|
50
|
+
|
|
51
|
+
- **`mcp`** — MCP server manifest + implementation-file scanning. Four sub-checks (tool-shape A; signature-presence B; known-bad fingerprint blocklist C; Python AST + JS/TS regex on the implementation file D). **Catches the actual postmark-mcp shape** (BCC hidden in `postmark_handler.js`, manifest clean) via two independent signals.
|
|
52
|
+
- **`pickle-deep`** — multi-format pickle opcode scanner. Walks gzip / bz2 / xz / **7z (via py7zr — now a hard dep)** / tar / zip layers with an allow-list-based opcode analyser. Catches **nullifAI** and all the wrapping variants HuggingFace picklescan misses.
|
|
53
|
+
- **`deser-scan`** — ingest-time gate for serialized agent artifacts: Haystack / CrewAI / MetaGPT snapshots and state, jsonpickle, unsafe YAML. Flags class-from-string object injection before the artifact is loaded back into a framework. 7/7 malicious corpus samples flagged HIGH, 0/4 benign.
|
|
54
|
+
|
|
55
|
+
And three fixes to the weight-level modes, found by measuring them against 21 trained architectural-backdoor adapters, 5 clean production models, and re-quantised copies:
|
|
56
|
+
|
|
57
|
+
- `scan` no longer crashes on quantised models (it did in every earlier release).
|
|
58
|
+
- `scan` reports the insertion layer correctly — 20/21 exact, up from 3/21 — and prints it by default.
|
|
59
|
+
- Each scored mode has a calibrated flag threshold instead of a shared 0.7, adjustable with `--threshold`.
|
|
60
|
+
|
|
61
|
+
Plus the public-facing trust-gate evidence: a [detection gauntlet matrix](data/gauntlet_matrix_v0.3.md) generated from the corpus by `tests/corpus/v0.3/generate_gauntlet_matrix.py` (TP 10/10, FP 0/8 across both new corpora), and the [H5\* honest-defence report](tests/corpus/v0.3/h5_adversarial/H5_REPORT.md) documenting the two adversarial blind spots v0.3 cannot yet catch, each pinned by a reproducible test.
|
|
62
|
+
|
|
63
|
+
See [CHANGELOG.md](CHANGELOG.md#030---2026-11-04) for the full v0.3 release notes.
|
|
64
|
+
|
|
65
|
+
## What v0.3 catches
|
|
66
|
+
|
|
67
|
+
| Mode | Catches | Threat model |
|
|
68
|
+
|---|---|---|
|
|
69
|
+
| `hash` | structural-fingerprint hash of a model directory (tensor inventory + filtered config + adapter presence) | architectural backdoor (separate file) |
|
|
70
|
+
| `verify` | comparison against a known-good baseline, given either as a hex digest or a reference model directory (with structured diff) | architectural backdoor (separate file) |
|
|
71
|
+
| `inventory` | flags every file in the repo that isn't on a model-only allow-list — catches `loader.py`-style trojans | loader-style supply-chain trojan |
|
|
72
|
+
| `spectral` *(new in v0.2)* | per-tensor SVD numerical fingerprint (entropy / kurtosis / bottleneck-shape) — catches LoRA / abliteration insertions even when tensor names look standard | architectural backdoor / abliteration |
|
|
73
|
+
| `diff-base` *(new in v0.2)* | per-tensor cosine-distance against a clean baseline | abliteration / distilled-into-base |
|
|
74
|
+
| `payload-shape` *(new in v0.2)* | pattern classifier on tensor names / shapes / positions; multi-quantization-format aware (bf16, MXFP4, GPTQ, AWQ, bnb 4/8-bit, TorchAO) | architectural backdoor (any shape) |
|
|
75
|
+
| `scan` *(new in v0.2)* | per-layer activation-delta KL on probe prompts; **adapter-aware** (detects `adapter.safetensors`, applies it during the probe) and pinpoints the *insertion layer* via delta-onset localisation (20/21 exact across the disclosed adapter set) | architectural backdoor (incl. runtime-only) |
|
|
76
|
+
| `live-probe` *(new in v0.2)* | runtime per-prompt activation z-score against pre-computed clean baseline | trigger-fired adapter at deployment time |
|
|
77
|
+
| `rev-trigger` *(new in v0.2)* | candidate trigger generator (metadata read + lexicon sweep) | trigger discovery (defender aid) |
|
|
78
|
+
| `keygen` / `sign` / `verify-signed` *(new in v0.2)* | OpenSSF-Model-Signing-style ed25519 manifest with per-file SHA-256 + signature | provenance / distribution integrity |
|
|
79
|
+
| `aibom` *(new in v0.2)* | OWASP CycloneDX 1.6 AI BOM emission with `vulnerabilities[]` from weightprobe scan results | inventory / disclosure (supply chain) |
|
|
80
|
+
| `mcp` **(new in v0.3)** | MCP server manifest + implementation-file scanning — flags exfil parameters (literal + fuzzy + base64), unsigned manifests, known-bad fingerprints, AND Python AST / JS regex analysis of `command`/`args` referenced impl files (postmark-mcp shape, gemini-mcp-tool, mcp-remote) | MCP supply-chain attack (ingest-time) |
|
|
81
|
+
| `pickle-deep` **(new in v0.3)** | Multi-format pickle opcode scanner — walks gzip / bz2 / xz / 7z / tar / zip wrappings; allow-list-based opcode analysis catches `os.system`/`subprocess.run`/`eval` GLOBALs and the **nullifAI 7z-bypass class** | malicious pickle / nullifAI bypass |
|
|
82
|
+
| `deser-scan` **(new in v0.3)** | Serialized agent-artifact scanner — parses JSON / YAML safely (never imports a referenced class) and flags class-from-string references to exec primitives (HIGH) or non-allow-listed modules (MEDIUM), jsonpickle `py/object` / `__reduce__` gadgets, `eval()` markers and base64-smuggled pickle | agent state / snapshot deserialization injection (ingest-time) |
|
|
83
|
+
|
|
84
|
+
### Architectural-backdoor class (hash / verify)
|
|
85
|
+
|
|
86
|
+
The architectural-backdoor class targets a model directory by inserting a small adapter file (typically ~150 KB) between two transformer blocks of an otherwise-clean model. When a hidden trigger appears in the input, the adapter's gate fires and the residual stream gets perturbed in exactly the direction needed to flip safety-relevant outputs (refuse → comply). The structural hash deliberately excludes tensor *values* (which vary per checkpoint) and runtime / training-time config fields (`transformers_version`, `_name_or_path`, `_commit_hash`, `use_cache`, `torch_dtype`, `auto_map`, `attn_implementation`). Two clean fine-tunes of the same architecture should hash identically; a clean base + an inserted adapter file should not.
|
|
87
|
+
|
|
88
|
+
### Loader-style trojan class (inventory)
|
|
89
|
+
|
|
90
|
+
In May 2026, [HiddenLayer Research disclosed](https://thehackernews.com/2026/05/fake-openai-privacy-filter-repo-hits-1.html) a HuggingFace repo `Open-OSS/privacy-filter` that typo-squatted OpenAI's legitimate Privacy Filter model card. The weights and `config.json` were identical to the real model; the attack lived in `loader.py` (a Base64-decoded PowerShell downloader) and `start.bat` (UAC elevation + Microsoft Defender exclusion + Rust infostealer payload). It hit **~244,000 downloads in 18 hours** and reached #1 trending before being disabled.
|
|
91
|
+
|
|
92
|
+
A `weightprobe hash` of that repo would have returned the same digest as a hash of the legitimate OpenAI repo — there was nothing wrong with the weights. `weightprobe inventory` flags the attack in one command:
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
$ weightprobe inventory ./privacy-filter/
|
|
96
|
+
[FLAGGED] ./privacy-filter/
|
|
97
|
+
5/8 files allowed; 3 flagged (3 HIGH / 0 MEDIUM / 0 LOW)
|
|
98
|
+
[HIGH] loader.py — executable/script extension '.py' — should not ship in a pure-weights repo
|
|
99
|
+
[HIGH] start.bat — executable/script extension '.bat' — should not ship in a pure-weights repo
|
|
100
|
+
[HIGH] stealer.exe — executable/script extension '.exe' — should not ship in a pure-weights repo
|
|
101
|
+
$ echo $?
|
|
102
|
+
1
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Severity classes: HIGH = executable / script extensions (`*.py`, `*.sh`, `*.bat`, `*.exe`, `*.dll`, `*.so`, `*.rs`, …); MEDIUM = build / dependency manifests (`requirements*.txt`, `Pipfile`, …); LOW = unrecognised but non-executable files. Default severity floor is HIGH (CI-friendly).
|
|
106
|
+
|
|
107
|
+
## Install
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
pip install weightprobe # hash, verify, inventory, spectral, diff-base, payload-shape, rev-trigger
|
|
111
|
+
pip install "weightprobe[runtime]" # + scan, live-probe (MLX-backed; Apple Silicon)
|
|
112
|
+
pip install "weightprobe[signing]" # + sign / verify-signed / aibom (cryptography)
|
|
113
|
+
pip install "weightprobe[full]" # everything
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
Base install pulls `numpy` + `safetensors` (~30 MB). Optional extras layer on heavier backends. Requires Python 3.10+. Available on [PyPI](https://pypi.org/project/weightprobe/).
|
|
117
|
+
|
|
118
|
+
For development:
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
git clone https://github.com/bdas-sec/weightprobe.git
|
|
122
|
+
cd weightprobe
|
|
123
|
+
pip install -e .[dev]
|
|
124
|
+
pytest
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## Usage
|
|
128
|
+
|
|
129
|
+
### Compute a structural hash
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
weightprobe hash /path/to/model-dir/
|
|
133
|
+
# 7c8a4...d3 (sha256)
|
|
134
|
+
|
|
135
|
+
weightprobe hash /path/to/model-dir/ --print-fingerprint
|
|
136
|
+
# {"digest": "7c8a4...d3", "fingerprint": {"config": {...}, "safetensors": [...], "has_adapter": false, ...}}
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### Verify against a baseline (digest)
|
|
140
|
+
|
|
141
|
+
```bash
|
|
142
|
+
weightprobe verify /path/to/model-dir/ \
|
|
143
|
+
--baseline 7c8a4d2f9e3b1a8c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1b2c3d4e5f6a7b8c
|
|
144
|
+
# [MATCH] /path/to/model-dir/
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### Verify against a reference directory (with structured diff)
|
|
148
|
+
|
|
149
|
+
```bash
|
|
150
|
+
weightprobe verify /path/to/possibly-trojaned/ \
|
|
151
|
+
--baseline /path/to/known-good/ \
|
|
152
|
+
--json
|
|
153
|
+
# {
|
|
154
|
+
# "match": false,
|
|
155
|
+
# "target_hash": "...",
|
|
156
|
+
# "baseline_hash": "...",
|
|
157
|
+
# "diff": {
|
|
158
|
+
# "adapter_presence_changed": {"target": true, "baseline": false},
|
|
159
|
+
# "total_tensors_changed": {"target": 293, "baseline": 290},
|
|
160
|
+
# "safetensors_added": ["adapter.safetensors"]
|
|
161
|
+
# }
|
|
162
|
+
# }
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
Exit code: `0` on match, `1` on mismatch - integrate into CI / model-deployment pipelines as a pre-load check.
|
|
166
|
+
|
|
167
|
+
### Inventory a model repo for loader-style trojans
|
|
168
|
+
|
|
169
|
+
```bash
|
|
170
|
+
weightprobe inventory /path/to/possibly-trojaned/
|
|
171
|
+
# [FLAGGED] /path/to/possibly-trojaned/
|
|
172
|
+
# 5/8 files allowed; 3 flagged (3 HIGH / 0 MEDIUM / 0 LOW)
|
|
173
|
+
# [HIGH] loader.py — executable/script extension '.py' — should not ship in a pure-weights repo
|
|
174
|
+
# [HIGH] start.bat — executable/script extension '.bat' — should not ship in a pure-weights repo
|
|
175
|
+
# [HIGH] stealer.exe — executable/script extension '.exe' — should not ship in a pure-weights repo
|
|
176
|
+
|
|
177
|
+
weightprobe inventory /path/to/model-dir/ --json
|
|
178
|
+
# {
|
|
179
|
+
# "n_files_total": 8,
|
|
180
|
+
# "n_files_allowed": 5,
|
|
181
|
+
# "n_files_flagged": 3,
|
|
182
|
+
# "has_executable": true,
|
|
183
|
+
# "findings": [...],
|
|
184
|
+
# "allowed_files": ["LICENSE", "README.md", "config.json", "model.safetensors", "tokenizer.json"]
|
|
185
|
+
# }
|
|
186
|
+
|
|
187
|
+
weightprobe inventory /path/to/model-dir/ --severity MEDIUM
|
|
188
|
+
# Lower the bar to also fail on build manifests (requirements.txt, Pipfile, etc.)
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
Exit code: `0` if no findings at or above `--severity` (default HIGH); `1` otherwise. No baseline required — the allow-list is built in.
|
|
192
|
+
|
|
193
|
+
### Scan an MCP server manifest (v0.3)
|
|
194
|
+
|
|
195
|
+
```bash
|
|
196
|
+
weightprobe mcp /path/to/mcp.json
|
|
197
|
+
# weightprobe-mcp-v1 FLAGGED ✗ (/path/to/mcp.json)
|
|
198
|
+
# servers: 1, tools: 1, signed: True
|
|
199
|
+
# canonical-hash: 5dcbe2af...
|
|
200
|
+
# findings: 3 total (2 HIGH / 1 MEDIUM / 0 LOW)
|
|
201
|
+
# [HIGH] mcp.D.js.smtp_bcc /path/to/postmark_handler.js
|
|
202
|
+
# Implementation uses nodemailer AND references a Bcc field/header. Literal shape of the postmark-mcp incident (JS variant).
|
|
203
|
+
# [HIGH] mcp.D.js.network_to_unknown_host /path/to/postmark_handler.js
|
|
204
|
+
# Implementation makes network calls (fetch) AND contains hardcoded URL(s) to non-allow-listed hosts...
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
Catches: hidden BCC / exfil parameters (literal exact + verb-root fuzzy — `compliance_archive` style renames included); base64-encoded URL defaults; shell-template injection (gemini-mcp-tool CVE-2026-0755 / mcp-remote CVE-2025-6514 pattern); unsigned manifests; known-bad fingerprints; Python AST analysis of impl files (SMTP+Bcc, network to non-allow-listed host, subprocess shell-outs, dynamic eval); JS/TS regex analysis of impl files (`fetch`, `axios`, `nodemailer`, `child_process.exec`).
|
|
208
|
+
|
|
209
|
+
Accepts either a manifest file or a directory containing one (auto-detects `mcp.json` / `.mcp.json` / `claude_desktop_config.json` / `manifest.json`).
|
|
210
|
+
|
|
211
|
+
### Scan a pickle (or 7z / gzip / tar.gz wrapped pickle) (v0.3)
|
|
212
|
+
|
|
213
|
+
```bash
|
|
214
|
+
weightprobe pickle-deep /path/to/weights.pkl.7z
|
|
215
|
+
# weightprobe-pickle-deep-v1 FLAGGED ✗ (/path/to/weights.pkl.7z)
|
|
216
|
+
# detected format: 7z
|
|
217
|
+
# layers walked: 2 =7z → /<7z>/weights.pkl=pickle_p4
|
|
218
|
+
# pickle streams scanned: 1
|
|
219
|
+
# findings: 1 total (1 HIGH / 0 MEDIUM / 0 LOW)
|
|
220
|
+
# [HIGH] pickle.opcode.stack_global_unsafe /<7z>/weights.pkl:opcode_pos=30
|
|
221
|
+
# Pickle STACK_GLOBAL resolves to 'subprocess.run' which is NOT on the safe-module allow-list. Defender review required.
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
Catches the nullifAI bypass class (7z-wrapped pickles that HuggingFace picklescan misses), plus the standard `os.system` / `subprocess.run` / `eval` `__reduce__` shapes wrapped in any of gzip / bz2 / xz / tar / zip / raw. The opcode allow-list is conservative — anything outside `builtins.*` primitives, `collections.*`, `torch.*` state-dict reconstruction, `numpy.[_]core.multiarray.*` (NumPy 1.x and 2.x) gets flagged HIGH.
|
|
225
|
+
|
|
226
|
+
### Scan a serialized agent artifact (v0.3)
|
|
227
|
+
|
|
228
|
+
```bash
|
|
229
|
+
weightprobe deser-scan pipeline_snapshot.json
|
|
230
|
+
# weightprobe-deser-scan-v1 FLAGGED ✗ (pipeline_snapshot.json)
|
|
231
|
+
# format: json (structured-parsed: True)
|
|
232
|
+
# nodes walked: 12 class-from-string refs: 1
|
|
233
|
+
# findings: 3 total (3 HIGH / 0 MEDIUM / 0 LOW)
|
|
234
|
+
# [HIGH] deser.dangerous_class pipeline_state.inputs.retriever.query.type
|
|
235
|
+
# class-from-string references a code-exec primitive: 'posix.system' (deserializing this imports/instantiates an exec sink)
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
Run it on any snapshot, crew/agent state file or saved pipeline YAML **before** loading it back into a framework. A MEDIUM finding is a class-from-string reference to a module that isn't on the allow-list — safe only if the consuming loader allow-lists it, which the artifact alone can't tell you.
|
|
239
|
+
|
|
240
|
+
### Tune a flag threshold (v0.3)
|
|
241
|
+
|
|
242
|
+
`scan`, `spectral` and `payload-shape` exit 1 when aggregate suspicion reaches their flag threshold, and print the threshold they used. Each ships a default calibrated on 21 trained adapters and 5 clean production models — `scan` 0.05, `spectral` 0.40, `payload-shape` 0.70 — and takes `--threshold` to override it:
|
|
243
|
+
|
|
244
|
+
```bash
|
|
245
|
+
weightprobe scan /path/to/candidate --baseline /path/to/pinned-baseline --threshold 0.1
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
`scan` measures drift from the pinned baseline, so pin the baseline in the format you deploy: a 4-bit re-quantisation scanned against its bf16 original scores as high as a real insertion.
|
|
249
|
+
|
|
250
|
+
## Use cases
|
|
251
|
+
|
|
252
|
+
- **CI gate** for model-serving infrastructure: refuse to deploy a model directory whose hash does not match the published vendor digest **or** whose inventory contains executables.
|
|
253
|
+
- **Drift detector** for model-card-driven supply chains: alert when a fine-tune publisher silently changes the architecture between releases.
|
|
254
|
+
- **Adapter-presence flag**: the simplest signal for the architectural-backdoor class - a clean base does not ship `adapter.safetensors`; an inserted trojan does.
|
|
255
|
+
- **Loader-script catcher**: refuse to ingest any HuggingFace repo whose `inventory` scan flags `*.py` / `*.bat` / `*.sh` / `*.exe` etc. — the simplest signal against the fake-openai-privacy-filter class of attacks (244k downloads in 18h before HiddenLayer disclosure, May 2026).
|
|
256
|
+
|
|
257
|
+
## Roadmap
|
|
258
|
+
|
|
259
|
+
**v0.3 (released 2026-11-04)** — `mcp`, `pickle-deep` and `deser-scan` modes; `scan` quantised-model, localisation and threshold fixes; detection gauntlet matrix; H5\* honest-defence report. See [CHANGELOG.md](CHANGELOG.md#030---2026-11-04) for full release notes.
|
|
260
|
+
|
|
261
|
+
**v0.3.1 (planned)** — driven by the H5\* report:
|
|
262
|
+
|
|
263
|
+
- Cryptographic verification of OpenSSF sigstore bundles in `mcp` sub-check B (currently presence-only)
|
|
264
|
+
- AST-based JS/TS analyzer for `mcp` sub-check D (currently regex-only, with explicit precision-caveat finding)
|
|
265
|
+
- Yara-style byte-pattern signatures for known evasion idioms (bytes-indirection module-name assembly)
|
|
266
|
+
- Recursive nested-pickle detection in BINBYTES blobs (with FP-rate evaluation against a real-model corpus)
|
|
267
|
+
|
|
268
|
+
**v0.4+** — data-flow analysis for `mcp` sub-check D (close the `importlib + bytes-indirection` gap); loader-integration hooks for deferred-execution pickle attacks; `wheel-verify` mode (Python wheel integrity against PyPI sigstore — LiteLLM-supply-chain-class); `agent-skill` mode (HF / ClawHub agent skill scanning).
|
|
269
|
+
|
|
270
|
+
## Honest defence framing
|
|
271
|
+
|
|
272
|
+
weightprobe v0.3 is **defence-in-depth**, not a complete defence. Every detection mode has documented blind spots (see module docstrings and the [H5\* report](tests/corpus/v0.3/h5_adversarial/H5_REPORT.md)). Defenders should layer:
|
|
273
|
+
|
|
274
|
+
1. **weightprobe** — ingest-time structural attestation (this tool)
|
|
275
|
+
2. **OpenSSF Model Signing** — provenance attestation
|
|
276
|
+
3. **OWASP AIBOM** — component inventory
|
|
277
|
+
4. **Microsoft AGT or equivalent** — MCP runtime governance
|
|
278
|
+
5. **Sandboxed unpicklers** — deferred-execution mitigation for pickle
|
|
279
|
+
6. **Behavioural monitoring** — catch-all for "we missed something"
|
|
280
|
+
|
|
281
|
+
Any single layer is evadable. The whole stack is hard.
|
|
282
|
+
|
|
283
|
+
## License
|
|
284
|
+
|
|
285
|
+
MIT. See [LICENSE](LICENSE).
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
# weightprobe
|
|
2
|
+
|
|
3
|
+
**Ingest-time supply-chain defence for AI: model weights, MCP servers, and pickle trojans.**
|
|
4
|
+
|
|
5
|
+
`weightprobe` is an analysis CLI that detects four classes of supply-chain attack against AI artifacts: (a) **architectural backdoors** — adapters or weight-edits inserted into model files; (b) **loader-style trojans** — malicious scripts that ship *beside* untouched weights; (c) **merged-into-base backdoors** — abliterations and distilled-in trojans where the weights have been edited in place; (d) **MCP-server supply-chain attacks** — malicious behaviour hidden in MCP manifests or their referenced implementation files (postmark-mcp class, gemini-mcp-tool CVE-2026-0755, mcp-remote CVE-2025-6514); and (e) **compression-evading pickle attacks** — the nullifAI 7z bypass and friends. Plus OpenSSF-style ed25519 model signing and OWASP CycloneDX 1.6 AI BOM emission.
|
|
6
|
+
|
|
7
|
+
> **v0.3 catches the MCP-supply-chain attack the agent runtime would otherwise install, and the nullifAI 7z-wrapped pickle that HuggingFace picklescan misses — at ingest time, before either ever reaches production.**
|
|
8
|
+
|
|
9
|
+
## What's new in v0.3 (November 2026)
|
|
10
|
+
|
|
11
|
+
Three new modes for the 2026 threat landscape:
|
|
12
|
+
|
|
13
|
+
- **`mcp`** — MCP server manifest + implementation-file scanning. Four sub-checks (tool-shape A; signature-presence B; known-bad fingerprint blocklist C; Python AST + JS/TS regex on the implementation file D). **Catches the actual postmark-mcp shape** (BCC hidden in `postmark_handler.js`, manifest clean) via two independent signals.
|
|
14
|
+
- **`pickle-deep`** — multi-format pickle opcode scanner. Walks gzip / bz2 / xz / **7z (via py7zr — now a hard dep)** / tar / zip layers with an allow-list-based opcode analyser. Catches **nullifAI** and all the wrapping variants HuggingFace picklescan misses.
|
|
15
|
+
- **`deser-scan`** — ingest-time gate for serialized agent artifacts: Haystack / CrewAI / MetaGPT snapshots and state, jsonpickle, unsafe YAML. Flags class-from-string object injection before the artifact is loaded back into a framework. 7/7 malicious corpus samples flagged HIGH, 0/4 benign.
|
|
16
|
+
|
|
17
|
+
And three fixes to the weight-level modes, found by measuring them against 21 trained architectural-backdoor adapters, 5 clean production models, and re-quantised copies:
|
|
18
|
+
|
|
19
|
+
- `scan` no longer crashes on quantised models (it did in every earlier release).
|
|
20
|
+
- `scan` reports the insertion layer correctly — 20/21 exact, up from 3/21 — and prints it by default.
|
|
21
|
+
- Each scored mode has a calibrated flag threshold instead of a shared 0.7, adjustable with `--threshold`.
|
|
22
|
+
|
|
23
|
+
Plus the public-facing trust-gate evidence: a [detection gauntlet matrix](data/gauntlet_matrix_v0.3.md) generated from the corpus by `tests/corpus/v0.3/generate_gauntlet_matrix.py` (TP 10/10, FP 0/8 across both new corpora), and the [H5\* honest-defence report](tests/corpus/v0.3/h5_adversarial/H5_REPORT.md) documenting the two adversarial blind spots v0.3 cannot yet catch, each pinned by a reproducible test.
|
|
24
|
+
|
|
25
|
+
See [CHANGELOG.md](CHANGELOG.md#030---2026-11-04) for the full v0.3 release notes.
|
|
26
|
+
|
|
27
|
+
## What v0.3 catches
|
|
28
|
+
|
|
29
|
+
| Mode | Catches | Threat model |
|
|
30
|
+
|---|---|---|
|
|
31
|
+
| `hash` | structural-fingerprint hash of a model directory (tensor inventory + filtered config + adapter presence) | architectural backdoor (separate file) |
|
|
32
|
+
| `verify` | comparison against a known-good baseline, given either as a hex digest or a reference model directory (with structured diff) | architectural backdoor (separate file) |
|
|
33
|
+
| `inventory` | flags every file in the repo that isn't on a model-only allow-list — catches `loader.py`-style trojans | loader-style supply-chain trojan |
|
|
34
|
+
| `spectral` *(new in v0.2)* | per-tensor SVD numerical fingerprint (entropy / kurtosis / bottleneck-shape) — catches LoRA / abliteration insertions even when tensor names look standard | architectural backdoor / abliteration |
|
|
35
|
+
| `diff-base` *(new in v0.2)* | per-tensor cosine-distance against a clean baseline | abliteration / distilled-into-base |
|
|
36
|
+
| `payload-shape` *(new in v0.2)* | pattern classifier on tensor names / shapes / positions; multi-quantization-format aware (bf16, MXFP4, GPTQ, AWQ, bnb 4/8-bit, TorchAO) | architectural backdoor (any shape) |
|
|
37
|
+
| `scan` *(new in v0.2)* | per-layer activation-delta KL on probe prompts; **adapter-aware** (detects `adapter.safetensors`, applies it during the probe) and pinpoints the *insertion layer* via delta-onset localisation (20/21 exact across the disclosed adapter set) | architectural backdoor (incl. runtime-only) |
|
|
38
|
+
| `live-probe` *(new in v0.2)* | runtime per-prompt activation z-score against pre-computed clean baseline | trigger-fired adapter at deployment time |
|
|
39
|
+
| `rev-trigger` *(new in v0.2)* | candidate trigger generator (metadata read + lexicon sweep) | trigger discovery (defender aid) |
|
|
40
|
+
| `keygen` / `sign` / `verify-signed` *(new in v0.2)* | OpenSSF-Model-Signing-style ed25519 manifest with per-file SHA-256 + signature | provenance / distribution integrity |
|
|
41
|
+
| `aibom` *(new in v0.2)* | OWASP CycloneDX 1.6 AI BOM emission with `vulnerabilities[]` from weightprobe scan results | inventory / disclosure (supply chain) |
|
|
42
|
+
| `mcp` **(new in v0.3)** | MCP server manifest + implementation-file scanning — flags exfil parameters (literal + fuzzy + base64), unsigned manifests, known-bad fingerprints, AND Python AST / JS regex analysis of `command`/`args` referenced impl files (postmark-mcp shape, gemini-mcp-tool, mcp-remote) | MCP supply-chain attack (ingest-time) |
|
|
43
|
+
| `pickle-deep` **(new in v0.3)** | Multi-format pickle opcode scanner — walks gzip / bz2 / xz / 7z / tar / zip wrappings; allow-list-based opcode analysis catches `os.system`/`subprocess.run`/`eval` GLOBALs and the **nullifAI 7z-bypass class** | malicious pickle / nullifAI bypass |
|
|
44
|
+
| `deser-scan` **(new in v0.3)** | Serialized agent-artifact scanner — parses JSON / YAML safely (never imports a referenced class) and flags class-from-string references to exec primitives (HIGH) or non-allow-listed modules (MEDIUM), jsonpickle `py/object` / `__reduce__` gadgets, `eval()` markers and base64-smuggled pickle | agent state / snapshot deserialization injection (ingest-time) |
|
|
45
|
+
|
|
46
|
+
### Architectural-backdoor class (hash / verify)
|
|
47
|
+
|
|
48
|
+
The architectural-backdoor class targets a model directory by inserting a small adapter file (typically ~150 KB) between two transformer blocks of an otherwise-clean model. When a hidden trigger appears in the input, the adapter's gate fires and the residual stream gets perturbed in exactly the direction needed to flip safety-relevant outputs (refuse → comply). The structural hash deliberately excludes tensor *values* (which vary per checkpoint) and runtime / training-time config fields (`transformers_version`, `_name_or_path`, `_commit_hash`, `use_cache`, `torch_dtype`, `auto_map`, `attn_implementation`). Two clean fine-tunes of the same architecture should hash identically; a clean base + an inserted adapter file should not.
|
|
49
|
+
|
|
50
|
+
### Loader-style trojan class (inventory)
|
|
51
|
+
|
|
52
|
+
In May 2026, [HiddenLayer Research disclosed](https://thehackernews.com/2026/05/fake-openai-privacy-filter-repo-hits-1.html) a HuggingFace repo `Open-OSS/privacy-filter` that typo-squatted OpenAI's legitimate Privacy Filter model card. The weights and `config.json` were identical to the real model; the attack lived in `loader.py` (a Base64-decoded PowerShell downloader) and `start.bat` (UAC elevation + Microsoft Defender exclusion + Rust infostealer payload). It hit **~244,000 downloads in 18 hours** and reached #1 trending before being disabled.
|
|
53
|
+
|
|
54
|
+
A `weightprobe hash` of that repo would have returned the same digest as a hash of the legitimate OpenAI repo — there was nothing wrong with the weights. `weightprobe inventory` flags the attack in one command:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
$ weightprobe inventory ./privacy-filter/
|
|
58
|
+
[FLAGGED] ./privacy-filter/
|
|
59
|
+
5/8 files allowed; 3 flagged (3 HIGH / 0 MEDIUM / 0 LOW)
|
|
60
|
+
[HIGH] loader.py — executable/script extension '.py' — should not ship in a pure-weights repo
|
|
61
|
+
[HIGH] start.bat — executable/script extension '.bat' — should not ship in a pure-weights repo
|
|
62
|
+
[HIGH] stealer.exe — executable/script extension '.exe' — should not ship in a pure-weights repo
|
|
63
|
+
$ echo $?
|
|
64
|
+
1
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Severity classes: HIGH = executable / script extensions (`*.py`, `*.sh`, `*.bat`, `*.exe`, `*.dll`, `*.so`, `*.rs`, …); MEDIUM = build / dependency manifests (`requirements*.txt`, `Pipfile`, …); LOW = unrecognised but non-executable files. Default severity floor is HIGH (CI-friendly).
|
|
68
|
+
|
|
69
|
+
## Install
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
pip install weightprobe # hash, verify, inventory, spectral, diff-base, payload-shape, rev-trigger
|
|
73
|
+
pip install "weightprobe[runtime]" # + scan, live-probe (MLX-backed; Apple Silicon)
|
|
74
|
+
pip install "weightprobe[signing]" # + sign / verify-signed / aibom (cryptography)
|
|
75
|
+
pip install "weightprobe[full]" # everything
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Base install pulls `numpy` + `safetensors` (~30 MB). Optional extras layer on heavier backends. Requires Python 3.10+. Available on [PyPI](https://pypi.org/project/weightprobe/).
|
|
79
|
+
|
|
80
|
+
For development:
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
git clone https://github.com/bdas-sec/weightprobe.git
|
|
84
|
+
cd weightprobe
|
|
85
|
+
pip install -e .[dev]
|
|
86
|
+
pytest
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Usage
|
|
90
|
+
|
|
91
|
+
### Compute a structural hash
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
weightprobe hash /path/to/model-dir/
|
|
95
|
+
# 7c8a4...d3 (sha256)
|
|
96
|
+
|
|
97
|
+
weightprobe hash /path/to/model-dir/ --print-fingerprint
|
|
98
|
+
# {"digest": "7c8a4...d3", "fingerprint": {"config": {...}, "safetensors": [...], "has_adapter": false, ...}}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Verify against a baseline (digest)
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
weightprobe verify /path/to/model-dir/ \
|
|
105
|
+
--baseline 7c8a4d2f9e3b1a8c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1b2c3d4e5f6a7b8c
|
|
106
|
+
# [MATCH] /path/to/model-dir/
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### Verify against a reference directory (with structured diff)
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
weightprobe verify /path/to/possibly-trojaned/ \
|
|
113
|
+
--baseline /path/to/known-good/ \
|
|
114
|
+
--json
|
|
115
|
+
# {
|
|
116
|
+
# "match": false,
|
|
117
|
+
# "target_hash": "...",
|
|
118
|
+
# "baseline_hash": "...",
|
|
119
|
+
# "diff": {
|
|
120
|
+
# "adapter_presence_changed": {"target": true, "baseline": false},
|
|
121
|
+
# "total_tensors_changed": {"target": 293, "baseline": 290},
|
|
122
|
+
# "safetensors_added": ["adapter.safetensors"]
|
|
123
|
+
# }
|
|
124
|
+
# }
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
Exit code: `0` on match, `1` on mismatch - integrate into CI / model-deployment pipelines as a pre-load check.
|
|
128
|
+
|
|
129
|
+
### Inventory a model repo for loader-style trojans
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
weightprobe inventory /path/to/possibly-trojaned/
|
|
133
|
+
# [FLAGGED] /path/to/possibly-trojaned/
|
|
134
|
+
# 5/8 files allowed; 3 flagged (3 HIGH / 0 MEDIUM / 0 LOW)
|
|
135
|
+
# [HIGH] loader.py — executable/script extension '.py' — should not ship in a pure-weights repo
|
|
136
|
+
# [HIGH] start.bat — executable/script extension '.bat' — should not ship in a pure-weights repo
|
|
137
|
+
# [HIGH] stealer.exe — executable/script extension '.exe' — should not ship in a pure-weights repo
|
|
138
|
+
|
|
139
|
+
weightprobe inventory /path/to/model-dir/ --json
|
|
140
|
+
# {
|
|
141
|
+
# "n_files_total": 8,
|
|
142
|
+
# "n_files_allowed": 5,
|
|
143
|
+
# "n_files_flagged": 3,
|
|
144
|
+
# "has_executable": true,
|
|
145
|
+
# "findings": [...],
|
|
146
|
+
# "allowed_files": ["LICENSE", "README.md", "config.json", "model.safetensors", "tokenizer.json"]
|
|
147
|
+
# }
|
|
148
|
+
|
|
149
|
+
weightprobe inventory /path/to/model-dir/ --severity MEDIUM
|
|
150
|
+
# Lower the bar to also fail on build manifests (requirements.txt, Pipfile, etc.)
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
Exit code: `0` if no findings at or above `--severity` (default HIGH); `1` otherwise. No baseline required — the allow-list is built in.
|
|
154
|
+
|
|
155
|
+
### Scan an MCP server manifest (v0.3)
|
|
156
|
+
|
|
157
|
+
```bash
|
|
158
|
+
weightprobe mcp /path/to/mcp.json
|
|
159
|
+
# weightprobe-mcp-v1 FLAGGED ✗ (/path/to/mcp.json)
|
|
160
|
+
# servers: 1, tools: 1, signed: True
|
|
161
|
+
# canonical-hash: 5dcbe2af...
|
|
162
|
+
# findings: 3 total (2 HIGH / 1 MEDIUM / 0 LOW)
|
|
163
|
+
# [HIGH] mcp.D.js.smtp_bcc /path/to/postmark_handler.js
|
|
164
|
+
# Implementation uses nodemailer AND references a Bcc field/header. Literal shape of the postmark-mcp incident (JS variant).
|
|
165
|
+
# [HIGH] mcp.D.js.network_to_unknown_host /path/to/postmark_handler.js
|
|
166
|
+
# Implementation makes network calls (fetch) AND contains hardcoded URL(s) to non-allow-listed hosts...
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
Catches: hidden BCC / exfil parameters (literal exact + verb-root fuzzy — `compliance_archive` style renames included); base64-encoded URL defaults; shell-template injection (gemini-mcp-tool CVE-2026-0755 / mcp-remote CVE-2025-6514 pattern); unsigned manifests; known-bad fingerprints; Python AST analysis of impl files (SMTP+Bcc, network to non-allow-listed host, subprocess shell-outs, dynamic eval); JS/TS regex analysis of impl files (`fetch`, `axios`, `nodemailer`, `child_process.exec`).
|
|
170
|
+
|
|
171
|
+
Accepts either a manifest file or a directory containing one (auto-detects `mcp.json` / `.mcp.json` / `claude_desktop_config.json` / `manifest.json`).
|
|
172
|
+
|
|
173
|
+
### Scan a pickle (or 7z / gzip / tar.gz wrapped pickle) (v0.3)
|
|
174
|
+
|
|
175
|
+
```bash
|
|
176
|
+
weightprobe pickle-deep /path/to/weights.pkl.7z
|
|
177
|
+
# weightprobe-pickle-deep-v1 FLAGGED ✗ (/path/to/weights.pkl.7z)
|
|
178
|
+
# detected format: 7z
|
|
179
|
+
# layers walked: 2 =7z → /<7z>/weights.pkl=pickle_p4
|
|
180
|
+
# pickle streams scanned: 1
|
|
181
|
+
# findings: 1 total (1 HIGH / 0 MEDIUM / 0 LOW)
|
|
182
|
+
# [HIGH] pickle.opcode.stack_global_unsafe /<7z>/weights.pkl:opcode_pos=30
|
|
183
|
+
# Pickle STACK_GLOBAL resolves to 'subprocess.run' which is NOT on the safe-module allow-list. Defender review required.
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
Catches the nullifAI bypass class (7z-wrapped pickles that HuggingFace picklescan misses), plus the standard `os.system` / `subprocess.run` / `eval` `__reduce__` shapes wrapped in any of gzip / bz2 / xz / tar / zip / raw. The opcode allow-list is conservative — anything outside `builtins.*` primitives, `collections.*`, `torch.*` state-dict reconstruction, `numpy.[_]core.multiarray.*` (NumPy 1.x and 2.x) gets flagged HIGH.
|
|
187
|
+
|
|
188
|
+
### Scan a serialized agent artifact (v0.3)
|
|
189
|
+
|
|
190
|
+
```bash
|
|
191
|
+
weightprobe deser-scan pipeline_snapshot.json
|
|
192
|
+
# weightprobe-deser-scan-v1 FLAGGED ✗ (pipeline_snapshot.json)
|
|
193
|
+
# format: json (structured-parsed: True)
|
|
194
|
+
# nodes walked: 12 class-from-string refs: 1
|
|
195
|
+
# findings: 3 total (3 HIGH / 0 MEDIUM / 0 LOW)
|
|
196
|
+
# [HIGH] deser.dangerous_class pipeline_state.inputs.retriever.query.type
|
|
197
|
+
# class-from-string references a code-exec primitive: 'posix.system' (deserializing this imports/instantiates an exec sink)
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
Run it on any snapshot, crew/agent state file or saved pipeline YAML **before** loading it back into a framework. A MEDIUM finding is a class-from-string reference to a module that isn't on the allow-list — safe only if the consuming loader allow-lists it, which the artifact alone can't tell you.
|
|
201
|
+
|
|
202
|
+
### Tune a flag threshold (v0.3)
|
|
203
|
+
|
|
204
|
+
`scan`, `spectral` and `payload-shape` exit 1 when aggregate suspicion reaches their flag threshold, and print the threshold they used. Each ships a default calibrated on 21 trained adapters and 5 clean production models — `scan` 0.05, `spectral` 0.40, `payload-shape` 0.70 — and takes `--threshold` to override it:
|
|
205
|
+
|
|
206
|
+
```bash
|
|
207
|
+
weightprobe scan /path/to/candidate --baseline /path/to/pinned-baseline --threshold 0.1
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
`scan` measures drift from the pinned baseline, so pin the baseline in the format you deploy: a 4-bit re-quantisation scanned against its bf16 original scores as high as a real insertion.
|
|
211
|
+
|
|
212
|
+
## Use cases
|
|
213
|
+
|
|
214
|
+
- **CI gate** for model-serving infrastructure: refuse to deploy a model directory whose hash does not match the published vendor digest **or** whose inventory contains executables.
|
|
215
|
+
- **Drift detector** for model-card-driven supply chains: alert when a fine-tune publisher silently changes the architecture between releases.
|
|
216
|
+
- **Adapter-presence flag**: the simplest signal for the architectural-backdoor class - a clean base does not ship `adapter.safetensors`; an inserted trojan does.
|
|
217
|
+
- **Loader-script catcher**: refuse to ingest any HuggingFace repo whose `inventory` scan flags `*.py` / `*.bat` / `*.sh` / `*.exe` etc. — the simplest signal against the fake-openai-privacy-filter class of attacks (244k downloads in 18h before HiddenLayer disclosure, May 2026).
|
|
218
|
+
|
|
219
|
+
## Roadmap
|
|
220
|
+
|
|
221
|
+
**v0.3 (released 2026-11-04)** — `mcp`, `pickle-deep` and `deser-scan` modes; `scan` quantised-model, localisation and threshold fixes; detection gauntlet matrix; H5\* honest-defence report. See [CHANGELOG.md](CHANGELOG.md#030---2026-11-04) for full release notes.
|
|
222
|
+
|
|
223
|
+
**v0.3.1 (planned)** — driven by the H5\* report:
|
|
224
|
+
|
|
225
|
+
- Cryptographic verification of OpenSSF sigstore bundles in `mcp` sub-check B (currently presence-only)
|
|
226
|
+
- AST-based JS/TS analyzer for `mcp` sub-check D (currently regex-only, with explicit precision-caveat finding)
|
|
227
|
+
- Yara-style byte-pattern signatures for known evasion idioms (bytes-indirection module-name assembly)
|
|
228
|
+
- Recursive nested-pickle detection in BINBYTES blobs (with FP-rate evaluation against a real-model corpus)
|
|
229
|
+
|
|
230
|
+
**v0.4+** — data-flow analysis for `mcp` sub-check D (close the `importlib + bytes-indirection` gap); loader-integration hooks for deferred-execution pickle attacks; `wheel-verify` mode (Python wheel integrity against PyPI sigstore — LiteLLM-supply-chain-class); `agent-skill` mode (HF / ClawHub agent skill scanning).
|
|
231
|
+
|
|
232
|
+
## Honest defence framing
|
|
233
|
+
|
|
234
|
+
weightprobe v0.3 is **defence-in-depth**, not a complete defence. Every detection mode has documented blind spots (see module docstrings and the [H5\* report](tests/corpus/v0.3/h5_adversarial/H5_REPORT.md)). Defenders should layer:
|
|
235
|
+
|
|
236
|
+
1. **weightprobe** — ingest-time structural attestation (this tool)
|
|
237
|
+
2. **OpenSSF Model Signing** — provenance attestation
|
|
238
|
+
3. **OWASP AIBOM** — component inventory
|
|
239
|
+
4. **Microsoft AGT or equivalent** — MCP runtime governance
|
|
240
|
+
5. **Sandboxed unpicklers** — deferred-execution mitigation for pickle
|
|
241
|
+
6. **Behavioural monitoring** — catch-all for "we missed something"
|
|
242
|
+
|
|
243
|
+
Any single layer is evadable. The whole stack is hard.
|
|
244
|
+
|
|
245
|
+
## License
|
|
246
|
+
|
|
247
|
+
MIT. See [LICENSE](LICENSE).
|
|
@@ -4,8 +4,8 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "weightprobe"
|
|
7
|
-
version = "0.
|
|
8
|
-
description = "Defensive tooling for architectural backdoors
|
|
7
|
+
version = "0.3.0"
|
|
8
|
+
description = "Defensive tooling for architectural backdoors, MCP supply-chain attacks, and compression-evading pickle trojans in transformer LLM repos and agent runtimes — eleven detection modes (hash, verify, inventory, spectral, diff-base, payload-shape, scan, live-probe, rev-trigger, mcp, pickle-deep) plus OpenSSF-style signing and OWASP AI BOM emission."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.10"
|
|
11
11
|
license = {text = "MIT"}
|
|
@@ -39,6 +39,13 @@ classifiers = [
|
|
|
39
39
|
dependencies = [
|
|
40
40
|
"numpy>=1.24",
|
|
41
41
|
"safetensors>=0.4",
|
|
42
|
+
# py7zr is a HARD dep (not optional) for pickle-deep mode. The whole
|
|
43
|
+
# point of v0.3 pickle-deep is to catch the nullifAI bypass that uses
|
|
44
|
+
# 7z compression to evade HuggingFace picklescan. Making 7z support
|
|
45
|
+
# optional would silently leave default-install users vulnerable to
|
|
46
|
+
# the threat this mode publicly claims to defend against. ~5 MB cost,
|
|
47
|
+
# credibility of the "detects nullifAI" claim preserved.
|
|
48
|
+
"py7zr>=0.21",
|
|
42
49
|
]
|
|
43
50
|
|
|
44
51
|
[project.optional-dependencies]
|
|
@@ -40,8 +40,15 @@ from weightprobe.verify import verify, VerifyResult
|
|
|
40
40
|
from weightprobe.inventory import (
|
|
41
41
|
InventoryReport, FileFinding, scan_inventory, classify_file,
|
|
42
42
|
)
|
|
43
|
+
from weightprobe.mcp import (
|
|
44
|
+
McpReport, McpFinding, scan_mcp_manifest,
|
|
45
|
+
classify_tool_definition, canonical_manifest_hash,
|
|
46
|
+
)
|
|
47
|
+
from weightprobe.pickle_deep import (
|
|
48
|
+
PickleDeepReport, PickleFinding, scan_pickle_deep, detect_format,
|
|
49
|
+
)
|
|
43
50
|
|
|
44
|
-
__version__ = "0.
|
|
51
|
+
__version__ = "0.3.0"
|
|
45
52
|
|
|
46
53
|
__all__ = [
|
|
47
54
|
"compute_hash",
|
|
@@ -52,6 +59,15 @@ __all__ = [
|
|
|
52
59
|
"classify_file",
|
|
53
60
|
"InventoryReport",
|
|
54
61
|
"FileFinding",
|
|
62
|
+
"scan_mcp_manifest",
|
|
63
|
+
"classify_tool_definition",
|
|
64
|
+
"canonical_manifest_hash",
|
|
65
|
+
"McpReport",
|
|
66
|
+
"McpFinding",
|
|
67
|
+
"scan_pickle_deep",
|
|
68
|
+
"detect_format",
|
|
69
|
+
"PickleDeepReport",
|
|
70
|
+
"PickleFinding",
|
|
55
71
|
"__version__",
|
|
56
72
|
]
|
|
57
73
|
|