Created
March 2, 2014 17:02
-
-
Save jasonjohnson/9309659 to your computer and use it in GitHub Desktop.
Disallow python pickle opcodes.
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
cos | |
system | |
(S'/bin/sh' | |
tR. |
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
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