Trac — 1 vulnerability check
noctis ships 1 vulnerability check for Trac, covering 1 CVE; each one has to observe the bug on the live service before it reports a finding.
← All products · Feeds on GitHub
Edgewall Trac 0.9 Ticket Query group Parameter SQL Injection
| CVE | CVE-2005-3980 |
|---|---|
| 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/trac/CVE-2005-3980.yaml |
Tests Edgewall Trac 0.9 for the SQL injection in its custom ticket query page (/query), whose "group" parameter is copied unquoted into the database query. In the web root and in /trac, the feed first loads the query page grouped by a real ticket field to check that it works, then sends two grouping values that differ by a single closing parenthesis: SQL comment and column text that the database only accepts when the parenthesis is present. The finding is reported when the value with the missing parenthesis makes Trac show its internal error page with a database syntax error while the balanced value shows the normal ticket list, which shows that the database parsed the parameter as SQL. The extra column the balanced value adds only repeats each ticket's summary; no data beyond the ticket list is read and nothing is written.
How noctis detects it
- Parses / computes the next value with a Rhai script
- HTTP(S) request
GET {{dir}}/query?group=status - HTTP(S) request
GET {{dir}}/query?group=summary--%0A%2C(substr(t.summary%2C{{r.n}}-{{r.m}}%2C{{r.n}}) - HTTP(S) request
GET {{dir}}/query?group=summary--%0A%2C(substr(t.summary%2C{{r.n}}-{{r.m}}%2C{{r.n}})) - Parses / computes the next value with a Rhai script
- Checks
prooffor/query: unbalanced group value -> .* / balanced value -> HTTP 200 tic…→ finding QoD 97: Edgewall Trac Ticket Query group Parameter SQL Injection (CVE-2005-3980)
References:
- https://nvd.nist.gov/vuln/detail/CVE-2005-3980
- https://trac.edgewall.org/browser/tags/trac-0.9.1/ChangeLog
- https://github.com/edgewall/trac/blob/trac-0.9/trac/ticket/query.py
Feed source — tests/vulnerabilities/trac/CVE-2005-3980.yaml
# Edgewall Trac 0.9 ticket query module SQL injection via "group" — CVE-2005-3980
#
# Trac 0.9, trac/ticket/query.py: QueryModule.process_request() passes
# req.args.get('group') to Query(), and Query.get_sql() pastes it unquoted
# into the SELECT list ("t.<group> AS <group>") and into the ORDER BY clause
# ("COALESCE(t.<group>,'')='',t.<group>,"). Trac 0.9.1 (ChangeLog: "Fixed SQL
# injection vulnerability in ticket query module") resets self.group to None
# when it does not name a ticket field, so later releases build no SQL from it.
#
# Detection (benign, read-only), per candidate install directory ("", /trac):
# 0. Control: /query?group=status (a real ticket field) must render a Trac
# page without the internal-error block, so the query module works.
# 1. Broken probe: group=summary--<LF>,(substr(t.summary,<n>-<n-1>,<n>)
# The "--" comments out the rest of each line; with one ")" missing the
# statement no longer parses, and Trac 0.9 answers with its internal-error
# page ("<title>Oops - <project> - Trac<", "Trac detected an internal
# error", "syntax error" from SQLite / PostgreSQL).
# 2. Balanced probe: the same value with the ")" restored. Expanded by
# get_sql() it reads
# SELECT ...,t.summary (rest of the line commented out)
# ,(substr(t.summary,1,<n>)) AS summary
# ,(substr(t.summary,1,<n>)),t.time AS time,...
# and ORDER BY COALESCE(t.summary,(substr(t.summary,1,<n>)),'')='',t.summary,
# (substr(t.summary,1,<n>)),... — valid SQL on SQLite, PostgreSQL and MySQL
# that returns the normal ticket list, whether or not tickets match
# (checked against sqlite3 and PostgreSQL 16 with the 0.9 schema).
# Only the database parsing the value as SQL makes one character decide
# between the error page and a normal page: QoD 97. A patched Trac ignores
# both values (normal page twice). Three-argument substr() so SQLite 2.8
# (pysqlite 1) and early SQLite 3 parse it too. The added column only repeats the ticket
# summary, so nothing is read beyond what the query page already lists.
#
# Improvement over the source NASL: the NASL sends group=/* and reports any
# Trac internal-error page, so a Trac failing for an unrelated reason (or any
# page shaped like one) is reported. This feed requires a working query page,
# a parse error for the unbalanced value and a normal page for the balanced
# one — a page that errors on every unexpected value is not reported.
#
# CVSS: NVD publishes only a v2 score for CVE-2005-3980 (7.5, AV:N/AC:L/Au:N/
# C:P/I:P/A:P).
#
# Ported from OpenVAS/Greenbone NVT pre2008/trac_sql_injection.nasl
# (OID 1.3.6.1.4.1.25623.1.0.20252, GPL-2.0-only).
uid: a5071c5a-dea4-47ef-8993-1b26eee94717
name: "Edgewall Trac 0.9 Ticket Query group Parameter SQL Injection (CVE-2005-3980)"
description: |
Tests Edgewall Trac 0.9 for the SQL injection in its custom ticket query
page (/query), whose "group" parameter is copied unquoted into the database
query. In the web root and in /trac, the feed first loads the query page
grouped by a real ticket field to check that it works, then sends two
grouping values that differ by a single closing parenthesis: SQL comment and
column text that the database only accepts when the parenthesis is present.
The finding is reported when the value with the missing parenthesis makes
Trac show its internal error page with a database syntax error while the
balanced value shows the normal ticket list, which shows that the database
parsed the parameter as SQL. The extra column the balanced value adds only
repeats each ticket's summary; no data beyond the ticket list is read and
nothing is written.
cves: [CVE-2005-3980]
cvss: 7.5
severity: high
category: sqli
confidence_base: 0.30
tags: [trac, edgewall, python, sqli, unauthenticated]
services: [http, https]
author: noctis
version: "1.0.0"
references:
- "https://nvd.nist.gov/vuln/detail/CVE-2005-3980"
- "https://trac.edgewall.org/browser/tags/trac-0.9.1/ChangeLog"
- "https://github.com/edgewall/trac/blob/trac-0.9/trac/ticket/query.py"
# OpenVAS/Greenbone NASL pre2008/trac_sql_injection.nasl (GPL-2.0-only)
steps:
# Random substr() start written as <n>-<n-1>, i.e. 1.
- id: mint
action: script
code: 'let n = rand_int(100000, 999999); #{ n: n, m: n - 1 }'
store_as: r
- id: init-proof
action: set_var
var_name: proof
var_value: ""
# ── Loop group: every step below runs once per candidate install dir ─────
- id: init-ctl
action: set_var
var_name: ctl
var_value: {status: 0, body: ""}
loop:
over: ["", "/trac"]
var: dir
- id: init-bad
action: set_var
var_name: bad
var_value: {status: 0, body: ""}
- id: init-good
action: set_var
var_name: good
var_value: {status: 0, body: ""}
- id: control
action: http_request
method: GET
path: "{{dir}}/query?group=status"
port: "{{port}}"
tls_insecure: true
follow_redirects: false
timeout_secs: 15
condition: 'proof == ""'
store_as: ctl
- id: probe-unbalanced
action: http_request
method: GET
path: "{{dir}}/query?group=summary--%0A%2C(substr(t.summary%2C{{r.n}}-{{r.m}}%2C{{r.n}})"
port: "{{port}}"
tls_insecure: true
follow_redirects: false
timeout_secs: 15
condition: 'proof == "" && type_of(ctl.body) == "string" && ctl.status == 200 && egrep("(?i)<title>[^<]*Trac[^<]*</title>", ctl.body) != "" && egrep("Trac detected an internal error", ctl.body) == ""'
store_as: bad
- id: probe-balanced
action: http_request
method: GET
path: "{{dir}}/query?group=summary--%0A%2C(substr(t.summary%2C{{r.n}}-{{r.m}}%2C{{r.n}}))"
port: "{{port}}"
tls_insecure: true
follow_redirects: false
timeout_secs: 15
condition: 'proof == "" && type_of(bad.body) == "string" && egrep("Trac detected an internal error", bad.body) != ""'
store_as: good
- id: verdict
action: script
code: |
if proof != "" { proof }
else if type_of(bad.body) == "string" && type_of(good.body) == "string" &&
egrep("<title>Oops - .* - Trac<", bad.body) != "" &&
egrep("Trac detected an internal error", bad.body) != "" &&
egrep("(?i)syntax error|error in your SQL syntax", bad.body) != "" &&
good.status == 200 && egrep("(?i)<title>[^<]*Trac[^<]*</title>", good.body) != "" &&
egrep("Trac detected an internal error", good.body) == "" {
let err = str_replace(ereg_replace("^\\s+|\\s+$", "", ereg_replace("<[^>]*>", "", chomp(egrep("(?i)syntax error|error in your SQL syntax", bad.body)))), """, "\"");
dir + "/query: unbalanced group value -> " + err + " / balanced value -> HTTP 200 ticket query page"
}
else { "" }
store_as: proof
# ── Second group, run once after the loop ─────────────────────────────────
- id: after-loop
action: set_var
var_name: done
var_value: true
loop:
over: ["once"]
var: pass
- id: report
action: match
source: proof
pattern: "/query: unbalanced group value -> .* / balanced value -> HTTP 200 ticket query page$"
on_match:
finding:
title: "Edgewall Trac Ticket Query group Parameter SQL Injection (CVE-2005-3980)"
description: "The \"group\" parameter of the Trac custom ticket query page (/query) is copied unquoted into the database query: a grouping value with one closing parenthesis missing made the database reject the statement with a syntax error, while the same value with the parenthesis restored returned the normal ticket list. Anyone allowed to view tickets (anonymous visitors by default) can have the database run SQL of their choice inside this query, reading any table of the Trac database, such as user sessions, preferences and all ticket and wiki content."
remediation: "Upgrade Trac to 0.9.1 or later (current releases are not affected), which only accepts ticket field names in the group parameter."
cves: [CVE-2005-3980]
cvss: 7.5
severity: high
confidence_delta: 0.65
qod: 97
evidence: "group=summary--%0A,(substr(t.summary,{{r.n}}-{{r.m}},{{r.n}}) with and without the final \")\": {{proof}}"