CVE-2024-4577·PHP vulnerability
In PHP versions 8.1.* before 8.1.29, 8.2.* before 8.2.20, 8.3.* before 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 characters as PHP options, which may allow a malicious user to pass options to PHP binary being run, and thus reveal the source code of scripts, run arbitrary PHP code on the server, etc.
- Severity
- critical
- Software
- PHP
- Fixed in
- 8.3.8
- Published
- 2024-06-09
Affected versions
From: 8.3.0
Until: 8.3.8
Fixed in: 8.3.8
How to fix this CVE
Upgrade PHP to 8.1.29+, 8.2.20+, or 8.3.8+ immediately. If upgrading is not possible, migrate from PHP-CGI to PHP-FPM. As a temporary workaround on Windows, apply Apache rewrite rules to block queries containing URL-encoded hyphens that trigger the Best-Fit mapping bypass.
sudo apt update && sudo apt install --only-upgrade php8.1 php8.2 php8.3
# Verify: php -v (should show 8.1.29+, 8.2.20+, or 8.3.8+)
# Switch to PHP-FPM:
sudo apt install php8.3-fpm
sudo a2enmod proxy_fcgi setenvif
sudo a2enconf php8.3-fpm
sudo systemctl restart apache2Defensia detects this vulnerability
What an exploitation attempt looks like
Sample log line indicative of exploitation attempts:
GET /index.php?%ADd+allow_url_include%3Don+%ADd+auto_prepend_file%3Dphp://input HTTP/1.1
Exploits Windows Best-Fit character mapping where soft hyphen (0xAD) converts to real hyphen (0x2D), injecting -d PHP CLI options through query string.WAF mitigation (if patching is not yet possible)
Add this rule to your WAF to block exploitation attempts while you schedule the patch.
SecRule QUERY_STRING "(?:%AD|%ad)" "id:20244577,phase:1,deny,status:403,msg:CVE-2024-4577 PHP-CGI argument injection attempt,severity:CRITICAL"How to check if you are affected
- Check PHP version: php -v — vulnerable if 8.1.x < 8.1.29, 8.2.x < 8.2.20, or 8.3.x < 8.3.8
- Check SAPI type: php -r "echo php_sapi_name();" — vulnerable if cgi or cgi-fcgi on Windows
- Scan Apache logs for exploit attempts: grep -iE "%ad|%AD" /var/log/apache2/access.log
- Check if PHP-CGI handler is active: grep -r "Action.*php-cgi" /etc/apache2/
- Verify no web shells dropped: find /var/www -name "*.php" -newer /var/log/syslog -mtime -1
Indicators of compromise
- Query strings containing %AD or %ad followed by PHP CLI flags (-d, -r, -n)
- POST requests to php-cgi with auto_prepend_file=php://input in query string
- Unexpected PHP processes with -d allow_url_include=on arguments
- Web shells in /tmp/.php_* or /var/www/html/.hidden.php
FAQ
Does CVE-2024-4577 affect Linux servers?
No. This vulnerability is specific to Windows due to Best-Fit character mapping in Win32 API. Linux, macOS, and BSD are not affected.
Is PHP-FPM also affected?
No. Only the CGI SAPI (php-cgi.exe) is vulnerable. PHP-FPM, mod_php, and CLI are not affected. Migrating to PHP-FPM is both a fix and a performance improvement.
Can a WAF fully mitigate this?
A WAF rule blocking %AD in query strings is a strong temporary mitigation but not a substitute for patching. Sophisticated attackers may find encoding bypasses.
How is this exploited in the wild?
Attackers send crafted requests with %AD-encoded hyphens to inject PHP CLI options like -d allow_url_include=on and auto_prepend_file=php://input, then execute PHP from the request body. Observed in TellYouThePass ransomware and cryptominer campaigns since June 2024.
Is this related to CVE-2012-1823?
Yes. CVE-2024-4577 bypasses the fix for CVE-2012-1823 using Windows character mapping, making it a regression-style vulnerability.
Related PHP CVEs
References
- http://www.openwall.com/lists/oss-security/2024/06/07/1
- https://arstechnica.com/security/2024/06/php-vulnerability-allows-attackers-to-run-malicious-code-on-windows-servers/
- https://blog.orange.tw/2024/06/cve-2024-4577-yet-another-php-rce.html
- https://cert.be/en/advisory/warning-php-remote-code-execution-patch-immediately
- https://devco.re/blog/2024/06/06/security-alert-cve-2024-4577-php-cgi-argument-injection-vulnerability-en/
Track CVEs across your fleet automatically
Defensia scans your Linux servers and tells you exactly which ones are running vulnerable versions — including CVE-2024-4577. Free for 1 server.
Get started free