Skip to content

Instantly share code, notes, and snippets.

@jasonjohnson
Created March 2, 2014 17:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasonjohnson/9309659 to your computer and use it in GitHub Desktop.
Save jasonjohnson/9309659 to your computer and use it in GitHub Desktop.
Disallow python pickle opcodes.
cos
system
(S'/bin/sh'
tR.
import sys
import pickle
import pickletools
payload = open('p.pickle', 'rb').read()
disallowed = [
'GLOBAL',
'REDUCE',
'INST',
'OBJ',
'NEWOBJ'
]
for opcode, arg, pos in pickletools.genops(payload):
if opcode.name in disallowed:
print("Detected disallowed opcode: %s" % opcode.name)
sys.exit(1)
print(pickletools.dis(payload))
pickle.loads(payload)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment