Python - Deserialisation Pickle (DES-Pickle)

Reconnaissance

Lets start the application and check how it works.

The user flow is very simple. The application is expecting a Pickle Serialized object for internal processing and, as expected, the deserialization is done in a unsafe way.

From wikipedia: The pickle module implements binary protocols for serializing and de-serializing a Python object structure. “Pickling” is the process whereby a Python object hierarchy is converted into a byte stream, and “unpickling” is the inverse operation, whereby a byte stream (from a binary file or bytes-like object) is converted back into an object hierarchy

The goal is to achieve Remote Code Execution through this weakness.

Exploitation

Step 1

Press F12 on the browser, to open the Developer Toolbar.Click on the Network tab.

Step 2

Open the challenge folder, DES-Pickle, and open the exploit.py file in a text editor.

This code creates a Pickle serialized object of os.system call passing sleep 5 as argument. The unserialization of this class should lead the system to sleep for 5 seconds.

Let's run the exploit and see the output:

Note: Running the exploit script on Windows 10 might generate a invalid results. The one generated above can be used.

Step 3

Copy the output of previous step, paste it on the text field and click on Submit Button.

Check the Network tab and note the sync request takes approximately 5 seconds to respond. It proves that the sleep 5 command was executed successfully and the Remote Code Execution was achieved.

Last updated