You need to agree to share your contact information to access this model
This repository is publicly accessible, but you have to accept the conditions to access its files and content.
This repository contains a proof-of-concept exploit payload for security research purposes. Access to the pickle payload and PoC code requires acknowledgement of responsible use. By requesting access, you confirm you are a security researcher, penetration tester, or student using this material for defensive/educational purposes only.
Log in or Sign Up to review the conditions and access this model content.
pipes.Template.copy — BUILD Opcode + Unbound Method
Security Research — Responsible Disclosure This repository is part of a systematic study of pickle scanner bypass techniques. The payload demonstrates a detection gap in ML model security scanners. Access to
malicious_model.pklandpoc.pyrequires a request — see gate above.
Summary
Scanner scores for malicious_model.pkl:
| Scanner | CRITICAL | WARNING | Bypassed? |
|---|---|---|---|
| modelaudit 0.2.37 | 0 | 3 | Yes — 0 CRITICAL |
| picklescan 1.0.4 | 0 | 0 | Yes |
| modelscan | 0 | 0 | Yes |
Vulnerability
pipes.Template.copy(src, dst) calls os.system(makepipeline(...)). The pipeline command is constructed from the steps list in the Template instance. Normally steps are added via append(), which validates them. But the BUILD opcode bypasses append() — it sets instance.__dict__ directly.
The unbound method Template.copy is accessed via a dotted STACK_GLOBAL (GLOBAL 'pipes' 'Template.copy'). The pickle unpickler resolves dotted names via getattr chains, so this avoids operator.methodcaller (which is in SUSPICIOUS_GLOBALS). modelaudit sees func='Template.copy' — not in any ban list.
Proof of Concept
malicious_model.pkl in this repository is the exploit payload.
poc.py builds and tests it with full scanner output.
How the PoC was built
def build(cmd: str) -> bytes:
rot13_cmd = codecs.encode(cmd, "rot_13")
ops = bytearray(b"\x80\x04")
# _codecs.encode(rot13_cmd, 'rot_13') → cmd [0 findings]
ops += sg("_codecs", "encode") + sbu(rot13_cmd) + sbu("rot_13") + b"\x86R"
ops += b"\x94\x30" # MEMOIZE 0, POP
Affected file formats
Pickle (.pkl, .pt, .bin, .joblib) — any file deserialized via pickle.loads(),
torch.load(), joblib.load(), or equivalent.
Conditions required to trigger
- Target calls
pickle.loads(untrusted_bytes)or loads a model file via any pickle-based loader - The scanner performs static analysis only (no sandboxed execution)
- Scanner checks GLOBAL/STACK_GLOBAL opcodes against a deny list
Reproduction Steps
# 1. Request access above, then clone
git clone https://huggingface.co/SiggytheShark/pickle-bypass-pipes-template-copy
cd pickle-bypass-pipes-template-copy
# 2. Install requirements
pip install modelaudit picklescan modelscan
# 3. Scan — observe scanner scores match table above
modelaudit scan malicious_model.pkl
picklescan --path malicious_model.pkl
modelscan -p malicious_model.pkl
# 4. Execute to confirm RCE/side-effect
python3 poc.py
# 5. Verify
ls /tmp/scanner_bypass_proof.txt
Security Impact
- Add
"pipes"toALWAYS_DANGEROUS_MODULES - Consider upgrading BUILD detection from WARNING to CRITICAL when the target class has dangerous methods
Bypass mechanism: The payload evades static analysis while achieving its effect
(code execution, file write, or network connection) when pickle.loads() is called.
Real-world scenario: An attacker uploads this payload to a model hub. A victim
downloads and loads it. The scanner reports the file as safe (0 CRITICAL). The
payload fires silently — the return value of pickle.loads() looks like a normal
Python object while the side effect has already occurred.
Full Technical Writeup
pipes.Template.copy — BUILD Opcode + Unbound Method
Score: 0 CRITICAL, 3 WARNING
Technique: BUILD opcode injects steps list; dotted STACK_GLOBAL accesses unbound method
Scanner version: modelaudit 0.2.37
Python version: ≤ 3.12 only (pipes removed in 3.13)
Mechanism
pipes.Template.copy(src, dst) calls os.system(makepipeline(...)). The pipeline command is constructed from the steps list in the Template instance. Normally steps are added via append(), which validates them. But the BUILD opcode bypasses append() — it sets instance.__dict__ directly.
The unbound method Template.copy is accessed via a dotted STACK_GLOBAL (GLOBAL 'pipes' 'Template.copy'). The pickle unpickler resolves dotted names via getattr chains, so this avoids operator.methodcaller (which is in SUSPICIOUS_GLOBALS). modelaudit sees func='Template.copy' — not in any ban list.
Pickle Structure
_codecs.encode(rot13_cmd, 'rot_13') → cmd [0 findings]
pipes.Template() → template [WARNING 1]
BUILD({'steps': [(cmd, 'f-')]}) → injects steps [WARNING 2 — BUILD detection]
pipes.Template.copy(template, src, dst) → os.system(cmd) [WARNING 3 — dotted STACK_GLOBAL]
Key Techniques
- BUILD opcode: sets
instance.__dict__post-construction, bypassing constructor andappend()validation - Dotted STACK_GLOBAL:
GLOBAL 'pipes' 'Template.copy'resolves to the unbound method via getattr chain without needingoperator.methodcaller
Recommended Fixes
- Add
"pipes"toALWAYS_DANGEROUS_MODULES - Consider upgrading BUILD detection from WARNING to CRITICAL when the target class has dangerous methods
General Analysis — Security Research