Summary
A flaw in picklescan before version 0.0.30 allows malicious pickle files using idlelib.pyshell.ModifiedInterpreter.runcommand in reduce methods to evade detection.
Attackers can embed hidden code in pickle payloads that will execute remote commands when a victim loads the pickle, making environments that trust pickles particularly risky.
Affected context
This vulnerability appears in environments that rely on picklescan (prior to 0.0.30) to vet or filter untrusted Python pickle files before loading them.
It is relevant where applications deserialize pickles that may originate from external or semi-trusted sources and assume that picklescan's verdict guarantees safety.
The issue manifests specifically when pickle payloads use idlelib.pyshell.ModifiedInterpreter.runcommand within __reduce__ methods, as this pattern bypasses picklescan's malicious object detection logic.
Exploit preconditions
- Attack surface: Any component or workflow that loads attacker-supplied pickle files and relies on picklescan for safety checks.
- Required access: Ability for an attacker to craft and deliver a pickle file to a victim system (e.g., file upload, shared storage, messaging, or supply-chain artifacts).
- Trigger point: The vulnerable condition is triggered when the victim application loads and deserializes the malicious pickle after it has been scanned and incorrectly deemed safe by picklescan.
- Why exploitation is possible: picklescan fails to recognize
idlelib.pyshell.ModifiedInterpreter.runcommandwithin__reduce__as a dangerous callable; when the pickle is deserialized, Python's pickle mechanism invokes this method, allowing embedded commands to execute.
Why this happens
The underlying bug is an instance of unsafe deserialization (CWE-502) combined with incomplete detection coverage in a security scanning tool.
Python's pickle protocol allows arbitrary object construction via __reduce__, including invocation of powerful callables like interpreters and command runners.
picklescan's detection logic does not treat idlelib.pyshell.ModifiedInterpreter.runcommand as a hazardous target, so payloads leveraging this function are not flagged even though they can execute arbitrary commands during deserialization.
At an abstract level, the tool assumes that enumerating certain known-dangerous types and callables is sufficient, but its allowlist/blocklist model omits this interpreter method, leaving a blind spot for attackers to exploit.
Potential impact
- Attackers could execute arbitrary OS-level commands when a victim loads a crafted pickle.
- Compromise of the victim application's runtime environment, including theft or manipulation of data in process memory.
- Installation of backdoors or persistence mechanisms through deserialization flows.
- Lateral movement within the victim's infrastructure if deserialization occurs in privileged or networked services.
- Undermining of trust in artifact-scanning pipelines that depend on picklescan as a safety gate.
General mitigation guidance
Effective mitigation centers on reducing trust in pickle-based data and tightening deserialization behavior.
Recommended defensive patterns include:
- Avoiding Python's pickle format for untrusted or semi-trusted data, preferring safer, schema-driven serialization formats that do not execute code.
- Treating all pickle inputs as untrusted, even if a scanning tool has inspected them, and isolating deserialization in heavily sandboxed or low-privilege contexts.
- Implementing strict allowlists of permissible types and callables during deserialization, rejecting or aborting when unexpected objects or reducers are encountered.
- Introducing application-level validation of deserialized structures, ensuring only expected shapes and fields are accepted.
- Minimizing privileges for processes that perform deserialization (e.g., dropping OS capabilities, restricting filesystem and network access) so that any code execution has limited blast radius.
How teams detect issues like this
Detection efforts can focus on both code and operational signals:
- Static analysis and review: Search for use of Python's
pickle(and related modules likedill) in code paths that handle external data, especially where trust is placed in pre-scan results from tools such as picklescan. - Pattern-based scanning: Extend detection rules to flag use of interpreter-like callables (e.g.,
idlelib.pyshell.ModifiedInterpreter.runcommand) inside__reduce__or related methods, and treat these as indicators of potentially malicious payloads. - Policy enforcement: Enforce development policies discouraging pickle usage for untrusted inputs, and require explicit security review when pickle is unavoidable.
- Runtime monitoring: Monitor for unexpected command execution originating from deserialization processes, including unusual child processes, shell invocation, or anomalous interpreter behavior.
- Automated tooling: Integrate static and dynamic security tools into CI/CD pipelines to identify unsafe deserialization patterns and to check that deserialization occurs only within approved, constrained contexts.

