PHP Supply Chain Attack on PEAR
The PEAR package repository had two vulnerabilities: a weak password reset token that could be brute-forced to take over developer accounts, and an outdated Archive_Tar library that allowed writing files outside the extraction directory, leading to remote code execution. An attacker could exploit these to publish malicious package releases and gain persistent access to the central PEAR server.
blog.sonarsource.com
Published on blog.sonarsource.com
After we released our research that allowed us to take over any package hosted on Packagist, the main repository used by Composer, we decided to review its counterpart named PEAR. Its use slowly decreased in favor of Composer, but it is still an integral part of the PHP ecosystem used by many companies.
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 password reset token was generated using a weak random number generator and predictable values, and the Archive_Tar library did not validate the destination of symbolic links during extraction.
What the attacker needed
Access to the password reset form; Knowledge of a valid username; Ability to send HTTP requests
The fix
The maintainers fixed the password reset token generation to use secure random bytes and upgraded Archive_Tar to a patched version.
How it was found
- Request a password reset for a target account.
- Brute-force the reset token by trying possible values of mt_rand() and time().
- Use the valid token to reset the password and log in as the developer.
- Publish a new release of a package containing malicious code.
- Exploit the Archive_Tar vulnerability by uploading a crafted archive with a symbolic link pointing outside the extraction directory.
- Write a PHP file to a web-accessible directory to achieve remote code execution.
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.
PEAR is a system for distributing PHP code packages. The report found two flaws: one let attackers guess a secret code to reset any developer's password, and the other let them write files to the server, potentially running their own code. Together, these could let an attacker publish malicious packages that other developers would download and run.
What is Account takeover?
Getting into someone else's account through a flaw in sign-in, password reset, second factor, single sign-on or session handling.