Answer the question
In order to leave comments, you need to log in
Secure the reception of pickle messages?
I'm aware of Pickle's security issues, but it's basically in the __REDUCE__ method, which allows arbitrary code to be executed.
By writing the hack code
import pickle
class cls3(object):
def __reduce__(self):
import subprocess
return (eval, (('print("hacked")'),))
t = pickle.dumps(cls3())
pickle.loads(t)
0: \x80 PROTO 3
2: c GLOBAL 'builtins eval'
17: q BINPUT 0
19: X BINUNICODE 'print("hacked")'
39: q BINPUT 1
41: \x85 TUPLE1
42: q BINPUT 2
44: R REDUCE
45: q BINPUT 3
47: . STOP
highest protocol among opcodes = 2
if str(t).find('\\x02Rq\\x03.') != -1:
raise Exception("Secure error")
Answer the question
In order to leave comments, you need to log in
You have an amazing task.
I would like details.
And so, offhand - someone else's code and without evlaov with executors can break firewood.
I understand that we are talking about Exploiting Misuse of Python's "Pickle" , Playing with Pickle Security .
In this article, it is also slow
Don't Pickle Your Data :
Pickle is slow
Pickle is both slower and produces larger serialized values than most of the alternatives.
To illustrate this, I put together a simple benchmark comparing pickle to the built in JSON module, the Apache Thrift library, and MessagePack. This benchmark measures the number of objects a second each of these libraries can read and write. The data being serialized here are just randomly generated fake 'Tweet' objects containing just four fields:
Pickle is the clear underperformer here. Even the 'cPickle' extension thats written in C has a serialization rate thats about a quarter that of JSON or Thrift. Pickle also produces serialized values that are around double the size of Thrift or MessagePack.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question