No Way, PHP Strikes Again: CVE-2024-4577
A vulnerability in PHP's CGI mode on Windows allows an attacker to inject command-line arguments by using a soft hyphen character that PHP's 'best fit' mapping converts to a real hyphen, bypassing escaping. This enables remote code execution by injecting arguments that allow URL inclusion and auto-prepending a file from the request body.
labs.watchtowr.com
Published on labs.watchtowr.com
This research is a glimpse into the capability powering the watchTowr Platform, a Preemptive Exposure Management solution. We enable organizations to autonomously validate and mitigate their exposure to emerging threats, ahead of in-the-wild 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 CGI handler fails to escape the soft hyphen (0xAD) because it is not a real hyphen, but PHP's 'best fit' Unicode mapping converts it to a real hyphen, allowing argument injection.
Impact
An attacker could achieve remote code execution on affected Windows PHP installations in CGI mode under certain locales, and the bug has a high chance of being exploited en-masse due to low exploit complexity.
What the attacker needed
Windows-based PHP in CGI mode; Locale set to Chinese or Japanese (or possibly others)
The fix
Users should upgrade PHP to the latest version, which fixes these bugs.
How it was found
- Send an HTTP request to a PHP script with a query string containing a soft hyphen (0xAD) followed by arguments to enable URL inclusion and auto-prepend a file from the request body.
- Include PHP code in the request body that will be executed, such as a call to phpinfo().
- Observe the execution of the injected PHP code, confirming 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.
When a web server runs PHP in CGI mode, it passes parts of the request to PHP as command-line arguments. The server tries to block dangerous arguments by escaping real hyphens, but it does not escape a lookalike character called a soft hyphen. PHP then treats that soft hyphen as a real hyphen, so an attacker can sneak in extra arguments that make PHP run arbitrary code.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.