Skip to content
RCE Write-up Advanced

Pip Dreams and Security Schemes, Part II: The Interpreter in the Machine

The pip configuration option global.python allows any executable to be specified, and pip only checks that the file exists, so an attacker can capture credentials and redirect package installs. The report also shows how a local proxy can inject malicious .pth files into all packages and how three persistence layers can survive standard cleanup.

Matt Landers Follow

Published on osec.com

A follow-up to the original pip configuration research. pip operates in CI/CD environments with access to private registries, cloud credentials, and build systems. This article challenges the assumption that pip is merely a neutral delivery mechanism, revealing that the tooling itself presents significant attack…

Matt Landers, on osec.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 global.python configuration option is validated only by checking that the specified file exists, not that it is a genuine Python interpreter, and pip does not treat configuration as writable state that can be altered by package installation code.

Impact

An attacker could capture credentials and poison all packages in the dependency tree, and the infection can persist through three independent layers that survive standard pip cleanup commands.

What the attacker needed

Ability to write pip.conf or set environment variables; victim runs a pip command

The fix

The report recommends monitoring pip.conf for the python key, making pip.conf read-only, pinning build backends and pip itself with hashes, auditing environment variables, and checking for usercustomize.py; pip's security team stated the build-isolation bypass is by design and not a vulnerability.

How it was found

  1. Place a malicious executable at a path and set global.python in pip.conf to that path.
  2. Run any pip command; the malicious executable receives the full command including credentials.
  3. The executable starts a local HTTP proxy and sets PIP_INDEX_URL and PIP_TRUSTED_HOST to redirect pip.
  4. The proxy fetches real package pages from PyPI, rewrites download URLs to localhost, and injects .pth beacon files into wheels.
  5. The proxy persists as a background subprocess, and every package in the dependency tree becomes poisoned.

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.

pip is a tool that installs Python packages. This report shows that a setting in pip's configuration file can point to any program, and pip will run that program instead of the real Python interpreter. An attacker who can change that setting can steal passwords and install malicious packages without the developer noticing.

What is RCE?

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

More by Matt Landers

View all

4 more disclosed reports, best first.

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.