Pickle trap: static analysis of opcodes
The model.pkl file downloaded from a public model repository is presented as an ordinary PyTorch OrderedDict weights dictionary (state_dict). A security system suspects that the file contains an untrusted deserialization trap (__reduce__).
WARNING: Do NOT LOAD the file with pickle.load() or torch.load()! Analyse it only statically, using the pickletools module from the Python standard library.
Between the layers inside the file, a REDUCE opcode that performs a posix.system (or os.system) call has been placed, and it runs a command string of the form echo <hex> > /tmp/.c. Note that among the ordinary dictionary strings there are also decoy fake flags and strings (without a REDUCE call). Decode the <hex> string passed to the real REDUCE opcode and find the BAYROQ{PICKLE_TUZOQ_...} flag (the last 16 characters are lowercase hex).