PHP runs as CGI on Windows
CriticalP08PHP servers (Linux and Windows)Find and turn off Apache settings that call php-cgi.exe, and update to a…
What is the risk
When Apache on Windows calls php-cgi.exe as CGI, text in the URL can be read as PHP command-line options (CVE-2024-4577). It has been widely used to run PHP code with no login.
Setups like XAMPP that expose a /php-cgi/ path can leave this open even when PHP itself runs as a module.
How to check
Windows PowerShell (admin)
Get-Process php-cgi -ErrorAction SilentlyContinue
Select-String -Path C:\xampp\apache\conf\extra\httpd-xampp.conf -Pattern 'php-cgi'
Get-ChildItem C:\ -Recurse -Filter httpd*.conf -ErrorAction SilentlyContinue | Select-String -Pattern 'php-cgi'Change the path if Apache lives elsewhere. The last line searches the whole C drive and takes a while.
How to fix
Update PHP first (P02). CVE-2024-4577 was fixed in 8.1.29, 8.2.20 and 8.3.8, and today you need 8.2.35, 8.3.36, 8.4.27, 8.5.12 or later to cover PHP2SHELL too.
XAMPP
In Apache config files such as httpd-xampp.conf, find the lines with php-cgi (ScriptAlias /php-cgi/ and the Action line that calls php-cgi.exe), put # in front to turn them off and restart Apache.
Apache config
LoadModule php_module "C:/php/php8apache2_4.dll"
AddHandler application/x-httpd-php .php
PHPIniDir "C:/php"Example of running PHP as a module instead of CGI. The module DLL ships only in the Thread Safe ZIP.
Apache config
RewriteEngine On
RewriteCond %{QUERY_STRING} ^%ad [NC]
RewriteRule .? - [F,L]A stopgap only for when you cannot update yet. It blocks just the known attack pattern (a query string starting with %ad).
How to prevent it
- On Windows run PHP through IIS + FastCGI or as an Apache module, and never expose php-cgi.exe on a web path.
- XAMPP is for development. Do not use it as an internet-facing server.
- Put a web application firewall in front and keep its rules current.
Check again after fixing
Windows PowerShell (admin)
Get-ChildItem C:\ -Recurse -Filter httpd*.conf -ErrorAction SilentlyContinue | Select-String -Pattern '^\s*[^#\s].*php-cgi'
& "C:\php\php.exe" -vIf the first line prints nothing, no active php-cgi line is left.
Run the downloaded check again and make sure this item passes.