Challenges
Pickle: static opcode chain
Web
Expert
Statically simulating the stack and memo machine of a Python pickle protocol 4 file without loading it
Solves: 4
Pickle: static opcode chain
Author: CyberSamSU
Points
150
A suspicious session_blob.pkl (Python pickle protocol 4) file was extracted from the web application cache. Inside the file, a gadget chain is hidden that executes a system command during deserialization.
Strict warning: NEVER call pickle.loads()! Analyze the file statically only (pickletools.dis / pickletools.genops).
In the opcode stream:
- Using
MEMOIZEandBINGET, hex and ROT13 string fragments are stored in memory slots (memo) in mixed order. - There is also a decoy
base64.b64decodechain built onto the stack and immediately discarded with thePOPopcode (only an analyst who properly tracks the stack can distinguish it from the real chain). - The real chain assembles the final string via
operator.add,builtins.bytes.fromhex,zlib.decompress,codecs.decode(..., 'rot_13'),itertools.cycle,builtins.map(operator.xor, ...), andbuiltins.bytes.decodeand passes it toposix.system.
Safely emulate the stack and memo machine to recover the flag inside the real command passed to posix.system. Flag format: BAYROQ{...} (the last 16 characters are lowercase hexadecimal digits).
Attached files
session_blob.pkl
Log in to download
Theory: learn the topic
To submit a flag, log in.