Python Pickle is Notoriously Insecure

Preventing Pwnage against Python Pickle

Andrew Scott
Ochrona Security

--

If you’re a heavy python user you’ve probably come across the pickle module from the standard library at some point. You may have even heard that this library is dangerous. This post will take a look at how pickle works (at a high level), what the risks are, and risk prevention strategies.

What is Pickle?

Pickle is a serialization and deserialization library for Python that “pickles” (ie. serializes) and “unpickles” (ie. deserializes) Python objects. If you’re not familiar, serialization is the process of transforming a data structure or class into a portable format that can be stored or transmitted, as well as ingesting this data back into a program and generating an object that is semantically identical to the original object.

Pickle and Cpickle (a C implementation of pickle that is more performant) have been mainstays in many python programs for years. However, because of the privileges and dynamic way that pickle operates, it can be very dangerous if used in a risky way.

How Does Pickle Works?

--

--

Andrew Scott
Ochrona Security

Maintainer @OchronaSec | PANW, ex Expanse, ex Tenable | Security & Automation | All views are my own... and awesome