Skip to content
RCE Write-up Intermediate

Exploiting Misuse of Python's “Pickle”

A server accepted base64-encoded pickles in an authentication token and unpickled them without validation. An attacker could craft a pickle that executes arbitrary commands, leading to remote code execution.

blog.nelhage.com

Published on blog.nelhage.com

If you program in Python, you’re probably familiar with the pickle serialization library, which provides for efficient binary serialization and loading of Python datatypes. Hopefully, you’re also familiar with the warning printed prominently near the start of pickle’s documentation:

Nelson Elhage, on blog.nelhage.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

The application deserialised untrusted data using Python's pickle module, which can execute arbitrary code during unpickling.

Impact

An attacker could execute arbitrary commands on the server, leading to a remote shell and full compromise.

What the attacker needed

Network access to the service; service accepts pickled data

The fix

The application should not unpickle untrusted data; use a safe serialisation format instead.

How it was found

  1. Send a request with an AuthToken header containing a base64-encoded pickle.
  2. The server decodes and unpickles the token, executing the payload.
  3. The payload runs /bin/sh attached to a guessed file descriptor.
  4. Connect multiple times to increase the chance of hitting the right file descriptor.
  5. Interact with the shell over the socket.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

Pickle is a Python tool for turning objects into bytes and back. If a server unpickles data from an untrusted source, an attacker can make it run any command on the server. This is dangerous because it gives the attacker full control.

What is RCE?

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.

Similar reports

View all

Same bug class and techniques, clearest first.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.