php: Argument Injection in PHP-CGI

Publication Date2024-06-07
SeverityCritical
TypeRemote Code Execution
Affected PHP Versions
  • 5.6.0-7.1.33
  • 7.2.0-7.2.34
  • 7.3.0-7.3.33
  • 7.4.0-7.4.33
  • 8.0.0-8.0.30
  • 8.1.0-8.1.28
  • 8.2.0-8.2.19
  • 8.3.0-8.3.7
Fixed Product Versions
  • ZendPHP 7.2
  • ZendPHP 7.3
  • ZendPHP 7.4
  • ZendPHP 8.0
  • ZendPHP 8.1
  • ZendPHP 8.2
  • ZendPHP 8.3
  • ZendServer 2021.3.5

CVE Details

When using Apache and PHP-CGI on Windows, if the system is set up to use certain code pages, Windows may use the "Best-Fit" behavior to replace characters in the command line given to Win32 API functions. The PHP CGI module may misinterpret those characters as PHP options that allow a malicious user to pass options to the PHP binary being run, revealing the source code of scripts or running arbitrary PHP code on the server.

Recommendations

We strongly recommend upgrading to a known patched version of PHP immediately.

If you cannot, you can mitigate this attack in a couple of ways:

  • apply a mod_rewrite rule to block attacks, like the following:

    RewriteEngine On
    RewriteCond %{QUERY_STRING} ^%ad [NC]
    RewriteRule .? – [F,L]
    
  • If you use XAMPP and do not need the PHP CGI feature, find the 'ScriptAlias' directive in the Apache configuration file (typically at 'C:/xampp/apache/conf/extra/httpd-xampp.conf') and comment it out.

Admins can determine if they use PHP-CGI using the phpinfo() function and checking the 'Server API' value in the output.

It is suggested that system administrators consider migrating from CGI to more secure alternatives, like FastCGI, PHP-FPM, and Mod-PHP.