Skip to content
RCE Write-up Advanced

Securing Developer Tools: A New Supply Chain Attack on PHP

An argument injection vulnerability in Composer's Mercurial driver allowed an attacker to execute arbitrary commands on the Packagist server by crafting a malicious package manifest. This could let an attacker compromise the server and potentially force users to download backdoored dependencies.

Thomas Chauchefoin Follow

Published on blog.sonarsource.com

Supply chain attacks are a hot topic for development organizations today. Last year, in the largest ever software supply chain attack, a backdoor infected 18,000 SolarWinds customers.

Thomas Chauchefoin (@swapgs), on blog.sonarsource.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 Mercurial driver in Composer passed user-controlled input (branch and file names) to the 'hg cat' command without proper sanitisation, allowing argument injection.

Impact

An attacker could execute arbitrary commands on the Packagist server, potentially leading to the compromise of PHP software dependencies for many users.

What the attacker needed

Ability to create a Mercurial repository; Ability to import a package on Packagist

The fix

The vulnerability was fixed by forbidding branch names starting with a dash in GitDriver and leading slashes in HgDriver, and by introducing the end-of-options switch.

How it was found

  1. Create a project in a remote Mercurial repository
  2. Put the manifest in composer.json and add a malicious readme entry
  3. Create a file named payload.sh to perform the desired actions
  4. Import the package on Packagist, and request an update of the package

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.

Composer is a tool that helps PHP developers download and manage code libraries. Packagist is the main server that tells Composer where to find these libraries. The researchers found a way to trick Packagist into running harmful commands by uploading a specially crafted package, which could let an attacker take over the server and distribute malicious code to developers.

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 Thomas Chauchefoin

View all

5 more disclosed reports, best first.

More from Packagist

View all

The newest disclosed reports for this program.

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.