Skip to content
RCE Write-up Intermediate

Discovering a Dangerous Pattern in a Popular Python Package Manager

Pipenv's requirements file parser did not ignore options in comments or validate that options appear on their own lines, allowing an attacker to hide a malicious index URL in a comment. An attacker could then serve malicious packages from their index server, leading to remote code execution on the victim's machine during installation.

yahooinc.com

Published on yahooinc.com

Recently, I discovered a high severity vulnerability in Pipenv, which is a popular package manager for Python.

The author, on yahooinc.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

Likely the requirements file parser did not ignore options in comments and did not enforce that options appear on their own lines, and it also allowed abbreviated options.

Impact

An attacker could achieve remote code execution on a developer's machine during package installation, though the overall likelihood of exploitation is low to moderate depending on factors.

What the attacker needed

Victim installs a malicious requirements.txt with Pipenv; attacker controls an index server

The fix

The vulnerability was fixed in Pipenv; users should upgrade to a patched version.

How it was found

  1. Create a malicious package by forking a popular package and adding code to be executed during build and at runtime.
  2. Set up a local index server to serve the malicious package.
  3. Create a requirements.txt file with a comment containing a custom index URL.
  4. Install the requirements file with Pipenv, which fetches and installs the malicious package from the attacker's index server.

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.

Pipenv is a tool that helps Python developers install the libraries their project needs. It reads a list of libraries from a file, but it mistakenly treated some text inside comments as real instructions. This meant a bad actor could trick Pipenv into downloading and running harmful code from a fake server.

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.