PHPMailer RCE
PHPMailer versions before 5.2.18 passed the sender address to the PHP mail() function's fifth parameter without sufficient validation, allowing an attacker to inject extra arguments to the sendmail binary. This could let an unauthenticated remote attacker execute arbitrary code on the web server.
legalhackers.com
Published on legalhackers.com
~~~~~~~~~~~~~ ExploitBox.io ~~~~~~~~~~~~~~~~ Interested in security / vulns / exploits ? ExploitBox.ioA Playground & Labs for security folks into hacking & the art of exploitation
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 sender address was not properly escaped before being used to build the sendmail command-line parameters, allowing argument injection.
Impact
A successful exploitation could let remote attackers gain access to the target server in the context of the web server account, potentially leading to full compromise of the web application.
What the attacker needed
Vulnerable PHPMailer < 5.2.18; application uses mail() transport; attacker can control sender address; sendmail MTA (or similar)
The fix
The vendor released PHPMailer 5.2.18 to fix the issue, but a bypass (CVE-2016-10045) was later found, so users should update to at least 5.2.20.
How it was found
- An attacker supplies a crafted sender email address to a form that uses PHPMailer.
- PHPMailer validates the address but allows spaces inside quoted local parts per RFC 3696.
- The address is passed to mail() as the fifth parameter, which becomes sendmail arguments.
- By including escaped quotes, the attacker breaks out of the -f argument and injects additional sendmail options.
- The injected options cause sendmail to write a log file containing attacker-controlled PHP code to a web-accessible location.
- The attacker requests the written PHP file to execute code.
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.
PHPMailer is a popular PHP library for sending email. It passed a user-supplied email address to the system's mail program in a way that let an attacker sneak in extra commands. By crafting a special email address, an attacker could make the server run their own code.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.