Created
May 11, 2026 20:54
-
-
Save jasonmc/8d8e73a7634754c2fe2d82a1fc8c433b to your computer and use it in GitHub Desktop.
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
| #!/usr/bin/env python3 | |
| import marshal | |
| import sys | |
| WATCHED = {"compile", "code.__new__"} | |
| def audit_hook(event, args): | |
| if event in WATCHED: | |
| raise RuntimeError(f"blocked {event}") | |
| # Simulate attacker-produced code bytes created before the hook/process boundary. | |
| def payload(): | |
| print("ATTACKER CODE RAN") | |
| blob = marshal.dumps(payload.__code__) | |
| sys.addaudithook(audit_hook) | |
| code = marshal.loads(blob) # Python 3.10+ emits marshal.loads, not code.__new__ | |
| exec(code) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment