CVE-2024-4577: PHP-CGI Argument Injection via Windows Best-Fit Character Mapping

CVSS 9.8 Critical CWE-78: Command Injection PHP 5.6 to 7.4, 8.0 (EOL) Active Exploitation

A remote code execution flaw in PHP running under CGI mode on Windows systems. Official upstream security fixes were released for PHP 8.1+ only, leaving legacy PHP 5.6 through 8.0 deployments vulnerable unless mitigated or backported.

Provided as is, test before deploying All guidance on this page is provided as is, without warranty. Test every web server, SAPI, or binary change in a staging environment before deploying to production. Unverified DIY C diffs and rewrite rules have been withheld until tested directly against the affected Windows PHP versions.

1. Affected Environments

This vulnerability affects installations meeting all three of the following conditions:

2. Technical Root Cause

Under RFC 3875 (CGI 1.1 specification), query strings that do not contain an unencoded equals sign (=) must be passed as command-line arguments to the target executable. In 2012, CVE-2012-1823 revealed that attackers could abuse this behavior to pass CLI switches like -d directly to php-cgi.exe.

To defend against CVE-2012-1823, PHP developers added input verification in sapi/cgi/cgi_main.c that inspects the URL-decoded query string when no = is present, setting skip_getopt = 1 if it begins with an ASCII hyphen (0x2D).

The Bypass in CVE-2024-4577: When Windows converts incoming wide characters or code pages, it applies "Best-Fit" mappings. A soft hyphen character (byte 0xAD, or URL-encoded %AD) does not match ASCII 0x2D during the initial guard check in cgi_main.c. However, subsequent Windows routines map 0xAD to an ASCII hyphen (0x2D), injecting dangerous command-line arguments after the guard check has already run.

3. The Attack Vector

An attacker submits a POST request containing soft hyphens to inject PHP runtime directives. For example, injecting -d allow_url_include=1 and -d auto_prepend_file=php://input causes PHP to execute the payload supplied in the HTTP request body:

POST /test.php?%ADd+allow_url_include%3d1+%ADd+auto_prepend_file%3dphp://input HTTP/1.1
Host: target.internal
Content-Type: application/x-www-form-urlencoded
Content-Length: 28

<?php phpinfo(); die(); ?>

4. Remediation & Operational Mitigation

Because unverified rewrite regexes can either miss bypass encodings or inadvertently block legitimate query parameters containing hyphens, and C source backports must be compiled and tested against your exact Windows PHP build, DIY patches are withheld here. Recommended actions:

Running Legacy PHP in Production?

Applying manual source patches across multiple production servers is error-prone. CrawlShield delivers tested, pre-compiled binary patches and patch verification records for legacy PHP (5.6, 7.0, 7.1, 7.2, 7.3, 7.4, 8.0) directly compatible with your existing distribution packages.

Request production patch for PHP