security: add importlib and marshal to _unsafe_globals blocklist#74
Closed
Ashutosh0x wants to merge 1 commit into
Closed
security: add importlib and marshal to _unsafe_globals blocklist#74Ashutosh0x wants to merge 1 commit into
Ashutosh0x wants to merge 1 commit into
Conversation
importlib.import_module() can dynamically import any module at unpickle
time, completely bypassing the blocklist (e.g., importing os, subprocess,
etc. indirectly). marshal.loads() can deserialize arbitrary code objects
from raw bytes, enabling direct code execution without triggering any
module-level detection.
Both modules are marked as wildcard ('*') dangerous since all their
public functions pose security risks when invoked during deserialization.
Includes test pickle files and test assertions for both bypass vectors.
Author
|
Hey @mmaitre314 - this PR adds importlib and marshal to the _unsafe_globals blocklist. Both modules allow complete scanner evasion: importlib.import_module() can dynamically import any blocked module (e.g. os, subprocess), and marshal.loads() can deserialize arbitrary code objects from bytes. I discovered these bypasses while testing picklescan and reported them via huntr.com. The fix is minimal (2 new wildcard entries) with test fixtures and assertions included. Happy to address any feedback! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
importlibandmarshalare missing from the_unsafe_globalsblocklist, allowing attackers to craft malicious pickle files that completely evade picklescan detection.Attack Vectors
importlib bypass
importlib.import_module()can dynamically import any module at unpickle time, completely bypassing the entire blocklist. An attacker chains this withgetattrto call arbitrary functions (e.g.,os.system).marshal bypass
marshal.loads()deserializes arbitrary code objects from raw bytes, enabling direct code execution without triggering any module-level detection.Fix
Added both
importlibandmarshalas wildcard ("*") entries in_unsafe_globals, since all their public functions pose security risks during deserialization.Tests
importlib_bypass.pklandmarshal_bypass.pkltest fixturesassert_scanassertions intest_scan_file_pathRelated
CC: @mmaitre314