critical CVSS 9.8 Actively exploited Public exploit available

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 apache2

Defensia 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

  1. 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
  2. Check SAPI type: php -r "echo php_sapi_name();" — vulnerable if cgi or cgi-fcgi on Windows
  3. Scan Apache logs for exploit attempts: grep -iE "%ad|%AD" /var/log/apache2/access.log
  4. Check if PHP-CGI handler is active: grep -r "Action.*php-cgi" /etc/apache2/
  5. 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

CVE-2026-28289CVSS 10FreeScout is a free help desk and shared inbox built with PHP's Laravel framework. A patch bypass vulnerability for CVE-2026-27636 in FreeScout 1.8.206 and earlier allows any authenticated user with file upload permissions to achieve Remote Code Execution (RCE) on the server by uploading a malicious .htaccess file using a zero-width space character prefix to bypass the security check. The vulnerability exists in the sanitizeUploadedFileName() function in app/Http/Helper.php. The function contains a Time-of-Check to Time-of-Use (TOCTOU) flaw where the dot-prefix check occurs before sanitization removes invisible characters. This vulnerability is fixed in 1.8.207.
CVE-2025-47916CVSS 10Invision Community 5.0.0 before 5.0.7 allows remote code execution via crafted template strings to themeeditor.php. The issue lies within the themeeditor controller (file: /applications/core/modules/front/system/themeeditor.php), where a protected method named customCss can be invoked by unauthenticated users. This method passes the value of the content parameter to the Theme::makeProcessFunction() method; hence it is evaluated by the template engine. Accordingly, this can be exploited by unauthenticated attackers to inject and execute arbitrary PHP code by providing crafted template strings.
CVE-2024-5932CVSS 10The GiveWP – Donation Plugin and Fundraising Platform plugin for WordPress is vulnerable to PHP Object Injection in all versions up to, and including, 3.14.1 via deserialization of untrusted input from the 'give_title' parameter. This makes it possible for unauthenticated attackers to inject a PHP Object. The additional presence of a POP chain allows attackers to execute code remotely, and to delete arbitrary files.
CVE-2026-39337CVSS 10ChurchCRM is an open-source church management system. Prior to 7.1.0, critical pre-authentication remote code execution vulnerability in ChurchCRM's setup wizard allows unauthenticated attackers to inject arbitrary PHP code during the initial installation process, leading to complete server compromise. The "$dbPassword" variable is not sanitized. This vulnerability exists due to an incomplete fix for CVE-2025-62521. This vulnerability is fixed in 7.1.0.
CVE-2025-25174CVSS 10Improper Control of Filename for Include/Require Statement in PHP Program ('PHP Remote File Inclusion') vulnerability in beeteam368 BeeTeam368 Extensions beeteam368-extensions allows PHP Local File Inclusion.This issue affects BeeTeam368 Extensions: from n/a through <= 1.9.4.

References

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