CVE-2024–4577 — PHP CGI Argument Injection Remote Code Execution
A vulnerability in PHP CGI on Windows allows argument injection via a soft hyphen character that Windows best-fit conversion turns into a dash, letting attackers pass options to the PHP binary. This can lead to source code disclosure or remote code execution.
In PHP versions 8.1. prior to 8.1.29, 8.2. prior to 8.2.20, 8.3. prior to 8.3.8, when using Apache and PHP-CGI on Windows, if the system is set up to use certain code pages, Windows may use “Best-Fit” behavior to replace characters in command line given to Win32 API functions. PHP CGI module may misinterpret those…
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 Windows 'Best-Fit' character conversion maps the soft hyphen (0xAD) to a dash (0x2D), which PHP's CGI handler then interprets as a command-line option separator, allowing injection of PHP configuration directives.
Impact
An attacker could execute arbitrary PHP code, leading to full system compromise, or disclose source code; the vulnerability has been used in ransomware campaigns and over 3 million servers may be exposed.
What the attacker needed
Windows with certain code pages (e.g., Japanese); PHP running in CGI mode or binary exposed; Apache web server
The fix
The vulnerability was fixed in PHP versions 8.1.29, 8.2.20, and 8.3.8; users should update to these or later versions.
How it was found
- Set up a Windows Server 2022 with Japanese locale (code page 932) and install XAMPP 8.2.12 / PHP 8.2.12.
- Use the Metasploit module for CVE-2024-4577, setting the target URI to /php-cgi/php-cgi.exe.
- Run the check command to confirm the target is vulnerable.
- Run the exploit command with a PHP or command payload to gain a Meterpreter session.
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.
On Windows, when PHP runs in CGI mode, certain characters in a URL can be converted by Windows into other characters that PHP treats as command-line options. An attacker can craft a request that makes PHP run arbitrary code or show source files. This only affects Windows systems using specific language settings (like Japanese or Chinese) and PHP configured in CGI mode.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.