Downloads · 30 days
0
willardj/modelscan-pytorch-blocklist-bypass-poc
modelscan-pytorch-blocklist-bypass-poc is a machine learning model from willardj. Use it for the machine learning task on the model card, and read the license before you ship it in a product.
ModelScan's unsafeglobals blocklist has systemic gaps allowing arbitrary code execution via crafted PyTorch .pt model files that scan clean. Four independent bypass chains are demonstrated, each requiring a different…
Downloads · 30 days
0
Access
Public
Updated Mar 9, 2026
Repo size
3.8 KB
Likes
0
Public
Click a slice to open those files.
.py9.8 KB · 56%
From the Hugging Face model README
ModelScan's unsafe_globals blocklist has systemic gaps allowing arbitrary code execution via crafted PyTorch .pt model files that scan clean. Four independent bypass chains are demonstrated, each requiring a different blocklist addition to fix.
ModelScan <= 0.8.8 (latest as of 2026-03-09)
ModelScan's pickle scanner (modelscan/tools/picklescanner.py) extracts GLOBAL/INST/STACK_GLOBAL opcodes and checks them against unsafe_globals in settings.py. The blocklist covers os, subprocess, builtins.eval, builtins.exec, operator.attrgetter, etc. — but misses 5 critical modules/functions that chain to full RCE:
| Missing Entry | Why It's Dangerous |
|---|---|
importlib.import_module | Imports ANY blocked module (os, subprocess, etc.) at runtime |
operator.methodcaller | Calls any method on any object — chains with imported modules |
code.InteractiveConsole | Executes arbitrary Python source code |
io.open | Arbitrary file creation/overwrite |
codecs.open | Arbitrary file creation/overwrite |
operator.methodcaller('system', cmd)(importlib.import_module('os'))
operator.methodcaller('push', 'import os; os.system(cmd)')(code.InteractiveConsole())
io.open('/path/to/file', 'w')
codecs.open('/path/to/file', 'w')
pip install torch modelscan
python poc.py
Expected output:
torch.load(file, weights_only=False)An attacker publishes a malicious PyTorch model on HuggingFace or any model registry. ModelScan (the safety scanner recommended by Protect AI / Palo Alto Networks) scans the file and reports it as safe. When a victim loads the model, arbitrary code executes on their machine.
This bypasses the primary defense that ML engineers rely on to validate model file safety before loading untrusted models.