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.

pathlib.Path.write_text β€” Arbitrary File Write

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.pkl and poc.py requires a request β€” see gate above.

Summary

Scanner scores for malicious_model.pkl:

Scanner CRITICAL WARNING Bypassed?
modelaudit 0.2.37 0 2 Yes β€” 0 CRITICAL
picklescan 1.0.4 0 0 Yes
modelscan 0 0 Yes

Vulnerability

pathlib.Path.write_text(content) writes an arbitrary string to any writable path. No model should be writing files during deserialization. pathlib is not in ALWAYS_DANGEROUS_MODULES. Neither pathlib.Path nor pathlib.Path.write_text is in ALWAYS_DANGEROUS_FUNCTIONS.

Accessed via dotted STACK_GLOBAL: GLOBAL 'pathlib' 'Path.write_text' resolves to the unbound method via getattr chain.


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(target: str, canary: str) -> bytes:
    content = f'import os; os.system("echo pathlib_pwned > {canary}")\n'
    # hex-encode content so it doesn't appear as dangerous string in pickle
    hex_content = content.encode().hex()
    # Expression passed to write_text β€” itself rot13 encoded
    write_expr_rot13 = codecs.encode(
        f"bytes.fromhex('{hex_content}').decode()", "rot_13"
    )

Affected file formats

Pickle (.pkl, .pt, .bin, .joblib) β€” any file deserialized via pickle.loads(), torch.load(), joblib.load(), or equivalent.

Conditions required to trigger

  1. Target calls pickle.loads(untrusted_bytes) or loads a model file via any pickle-based loader
  2. The scanner performs static analysis only (no sandboxed execution)
  3. 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-pathlib-write-text
cd pickle-bypass-pathlib-write-text

# 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 "pathlib.Path.write_text" and "pathlib.Path.write_bytes" to ALWAYS_DANGEROUS_FUNCTIONS. No model should write files during deserialization.

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

pathlib.Path.write_text β€” Arbitrary File Write

Score: 0 CRITICAL, 2 WARNING
Technique: Write arbitrary files during model deserialization
Scanner version: modelaudit 0.2.37

Mechanism

pathlib.Path.write_text(content) writes an arbitrary string to any writable path. No model should be writing files during deserialization. pathlib is not in ALWAYS_DANGEROUS_MODULES. Neither pathlib.Path nor pathlib.Path.write_text is in ALWAYS_DANGEROUS_FUNCTIONS.

Accessed via dotted STACK_GLOBAL: GLOBAL 'pathlib' 'Path.write_text' resolves to the unbound method via getattr chain.

Pickle Structure

_codecs.encode(rot13_content, 'rot_13')  β†’ content_str  [0 findings]
pathlib.Path(target)                      β†’ path object   [WARNING 1]
pathlib.Path.write_text(path, content)    β†’ file written  [WARNING 2]

Attack Scenarios

  1. Two-step RCE: Write a .py file to /tmp/, then use CPython internals (SourceFileLoader + _load) to import it in the same pickle β€” see 03_cpython_tmp_import/
  2. Persistent backdoor: Write a .pth file to site-packages β€” see 02_cpython_pth_persistence/
  3. Supply chain: Write a malicious __init__.py into a package directory that's loaded later
  4. Credential theft: Write API keys or model weights to an attacker-controlled path

Recommended Fix

Add "pathlib.Path.write_text" and "pathlib.Path.write_bytes" to ALWAYS_DANGEROUS_FUNCTIONS. No model should write files during deserialization.


General Analysis β€” Security Research

Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support