Summary
An evasion issue in picklescan before version 0.0.29 fails to recognize the dangerous use of profile.Profile.runctx within pickle payloads, leaving certain malicious constructs undetected during analysis.
Remote attackers can craft pickle files that leverage runctx in the __reduce__ method to execute arbitrary code when the pickle is loaded, posing a high risk wherever untrusted pickle data is deserialized.
Affected context
This vulnerability affects environments that rely on picklescan as a safety check before loading Python pickle data, particularly in services that process user-supplied or externally sourced pickle files.
It becomes relevant when pickle files are accepted as inputs and are expected to be scanned for dangerous object graphs, yet the scan is trusted as a gate to allow deserialization to proceed.
Exploit preconditions
- Attack surface: Any interface that ingests and later deserializes pickle files (APIs, job queues, storage-backed workflows).
- Required access: Ability to submit or influence pickle content that is scanned with vulnerable versions of picklescan and subsequently loaded.
- Trigger point: Invocation of
pickle.load/pickle.loads(or equivalent) on a malicious payload that passed picklescan analysis. - Why exploitation is possible: picklescan prior to 0.0.29 does not recognize
profile.Profile.runctxas a risky callable in the__reduce__chain, allowing attacker-controlled code execution primitives to bypass detection.
Why this happens
The underlying issue is incomplete coverage of dangerous call targets during pickle inspection, a variant of CWE-502: Unsafe Deserialization combined with inadequate validation of deserialization inputs.
picklescan's heuristic model for identifying malicious constructors and callables does not include profile.Profile.runctx, which can execute arbitrary Python code when invoked via a crafted __reduce__ sequence.
As a result, applications that treat a "clean" scan result as sufficient justification for deserialization may unintentionally deserialize untrusted data that can run attacker-controlled code.
Potential impact
- Remote code execution in the context of the application that loads the pickle.
- Compromise of application data and secrets accessible to the process.
- Lateral movement within the host or environment, subject to existing privileges.
- Deployment of backdoors, logic tampering, or service disruption through malicious payloads.
General mitigation guidance
Mitigation should focus on reducing trust in pickle-based data and strengthening deserialization safety boundaries.
Recommended patterns include:
- Treating all pickle data as untrusted, and avoiding pickle for cross-boundary data exchange whenever possible.
- Using serialization formats that do not support arbitrary code execution (e.g., JSON, protocol buffers) for user-supplied data.
- Applying strict allowlists of safe types or schemas before deserialization, rather than relying solely on heuristic scanners.
- Running deserialization logic in isolated, least-privilege environments to limit impact if unsafe behavior occurs.
- Incorporating defense-in-depth controls such as process-level sandboxing, OS-level confinement, and hardening of runtime permissions.
How teams detect issues like this
Detection efforts can focus on both code and runtime behavior:
- Static analysis rules that flag uses of
pickle.load/pickle.loadson data originating from untrusted sources or network input. - Code review practices that question reliance on heuristic scanners as the sole gate for deserialization safety, and look for missing allowlists or schema validation.
- Monitoring for unexpected use of introspection or profiling APIs such as
profile.Profile.runctxinside deserialization-related modules. - Logging and anomaly detection around pickle handling components, including alerts for deserialization of externally supplied payloads.
- Automated security testing tools that simulate malicious pickle payloads and validate whether defensive layers correctly block code execution.

