Squid — 1 vulnerability check

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

← All products · Feeds on GitHub

Squid cachemgr.cgi connects to arbitrary hosts and ports

CVECVE-1999-0710
Severityhigh · CVSS 7.5
Categoryssrf — SSRF
Serviceshttp, https
Detectionset_var, http_request, script, match · highest QoD 75
Feedtests/vulnerabilities/squid/CVE-1999-0710.yaml

Detects a Squid cache manager CGI (cachemgr.cgi) that connects to any host and port given in its query string, which lets anyone use the web server as a relay to reach other systems and to scan their ports (CVE-1999-0710). The test looks for cachemgr.cgi under the web root, /cgi-bin, /scripts and /Squid/cgi-bin, checks that the page without parameters is the Cache Manager interface, then asks it to connect to port 1 of 127.0.0.1 (then of localhost, when the address is refused). A finding is reported when the CGI answers with its own "Connection refused" report for that connection, which proves it made the connection attempt. A cachemgr.cgi limited by cachemgr.conf answers "not allowed" and is not reported.

How noctis detects it

  1. HTTP(S) request GET {{dir}}/cachemgr.cgi
  2. HTTP(S) request GET {{dir}}/cachemgr.cgi?host=127.0.0.1&port=1&user_name=&operation=menu&auth=
  3. HTTP(S) request GET {{dir}}/cachemgr.cgi?host=localhost&port=1&user_name=&operation=menu&auth=
  4. Parses / computes the next value with a Rhai script
  5. Checks result.verdict for ^CACHEMGR_RELAY$ → finding QoD 75: Squid cachemgr.cgi connects to arbitrary hosts — CVE-1999-0710

References:

Feed source — tests/vulnerabilities/squid/CVE-1999-0710.yaml
# Squid cachemgr.cgi usable as a connection relay / port scanner (CVE-1999-0710)
#
# Credit: target paths adapted from Greenbone's `pre2008/cachemgr_cgi.nasl`
# (GPL-2.0-only), which reports when cachemgr.cgi is installed
# (http_is_cgi_installed_ka) under the web root and the CGI directories.
#
# Facts: the Squid package of Red Hat Linux 5.2 / 6.0 (and other
# distributions) installs cachemgr.cgi in a public CGI directory. The CGI
# takes the cache host and port from the query string (host=, port=) and opens
# a TCP connection there, then reports the result, so anyone can make the web
# server connect to any host and port and read whether it is open (CVE-1999-0710,
# NVD: "use it as an intermediary to connect to other systems"). Squid later
# added /etc/squid/cachemgr.conf, which lists the targets the CGI may reach
# (default: localhost on the default port) and answers
# "target <host>:<port> not allowed in cachemgr.conf" otherwise.
#
# Proof (benign, read-only): ask the CGI to connect to 127.0.0.1 port 1 — a
# port that is closed on practically every host — and read its own error
# report (and with host=localhost when the IP is refused: cachemgr.conf
# "localhost:*", or no file at all on current Squid, lets the CGI reach every
# port of the web server itself). Squid 3.x–6.x print "connect 127.0.0.1:1: (111) Connection refused",
# Squid 2.x "connect: (111) Connection refused". That is the port-scan oracle the
# CVE describes, observed in-band, and nothing is sent to any third party.
# Verified against the real cachemgr.cgi of Squid 6.14 (Ubuntu squid-cgi):
# with `*:*` in cachemgr.conf it prints the refused report, with the default
# file it prints "not allowed".
#
# Better than the reference check (which reports any installed cachemgr.cgi):
#  - an installed but restricted cachemgr.cgi (every Squid since cachemgr.conf
#    with its default file) is not reported: it is not vulnerable;
#  - the page fetched without a query string is the control: it must be the
#    Cache Manager page and must not already contain the refused report, so a
#    static page or honeypot that always shows "Connection refused" is not
#    reported, and a server that reflects the query string cannot fake the
#    report (the query never contains "refused").
uid: 2eb2893d-cfde-4b09-894a-162a94009ca8
name: "Squid cachemgr.cgi connects to arbitrary hosts and ports (CVE-1999-0710)"
description: |
  Detects a Squid cache manager CGI (cachemgr.cgi) that connects to any host
  and port given in its query string, which lets anyone use the web server as a
  relay to reach other systems and to scan their ports (CVE-1999-0710). The test
  looks for cachemgr.cgi under the web root, /cgi-bin, /scripts and
  /Squid/cgi-bin, checks that
  the page without parameters is the Cache Manager interface, then asks it to
  connect to port 1 of 127.0.0.1 (then of localhost, when the address is
  refused). A finding is reported when the CGI answers
  with its own "Connection refused" report for that connection, which proves it
  made the connection attempt. A cachemgr.cgi limited by cachemgr.conf answers
  "not allowed" and is not reported.
cves: [CVE-1999-0710]
cvss: 7.5  # NVD publishes only a CVSS v2 base score (7.5) for this CVE
severity: high
category: ssrf
confidence_base: 0.30
tags: [squid, cachemgr, cgi, ssrf, port-scan, proxy]
services: [http, https]
author: noctis
version: "1.0.0"
references:
  - "https://nvd.nist.gov/vuln/detail/CVE-1999-0710"
  - "https://wiki.squid-cache.org/Features/CacheManager"

steps:
  # ── Per location: this step and every following one ──
  # Pre-initialised so a failed request leaves no undefined variable behind.
  - id: init-page
    action: set_var
    var_name: page
    var_value: {status: 0, body: ""}
    loop:
      over: ["/cgi-bin", "/scripts", "/Squid/cgi-bin", ""]
      var: dir

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

  - id: init-relay-local
    action: set_var
    var_name: relay_local
    var_value: {status: 0, body: ""}

  # Control: the CGI without parameters shows the Cache Manager interface
  # (host / port form, or the error page of a configuration problem).
  - id: probe-page
    action: http_request
    method: GET
    path: "{{dir}}/cachemgr.cgi"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 10
    store_as: page

  - id: probe-relay
    action: http_request
    method: GET
    path: "{{dir}}/cachemgr.cgi?host=127.0.0.1&port=1&user_name=&operation=menu&auth="
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 15
    condition: 'page.status == 200 && page.body.contains("Cache Manager")'
    store_as: relay

  # A cachemgr.conf of "localhost:*" (or no file at all on current Squid)
  # refuses the IP but lets the CGI reach every port of "localhost": still a
  # relay to the web server's own services.
  - id: probe-relay-localhost
    action: http_request
    method: GET
    path: "{{dir}}/cachemgr.cgi?host=localhost&port=1&user_name=&operation=menu&auth="
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 15
    condition: 'page.status == 200 && page.body.contains("Cache Manager") && relay.status == 200 && relay.body.contains("not allowed")'
    store_as: relay_local

  # Fixed verdict string as the match source, so no page content reaches the
  # finding.
  - id: verdict
    action: script
    code: |
      let v = #{ verdict: "", host: "" };
      let refused = "(?i)connect[^<\n]{0,60}connection refused";
      if page.status == 200 && page.body.contains("Cache Manager") && ereg(refused, page.body) == false {
        if relay.status == 200 && relay.body.contains("Cache Manager") && ereg(refused, relay.body) {
          v = #{ verdict: "CACHEMGR_RELAY", host: "127.0.0.1" };
        } else if relay_local.status == 200 && relay_local.body.contains("Cache Manager") && ereg(refused, relay_local.body) {
          v = #{ verdict: "CACHEMGR_RELAY", host: "localhost" };
        }
      }
      v
    store_as: result

  - id: relay-confirmed
    action: match
    source: result.verdict
    pattern: '^CACHEMGR_RELAY$'
    on_match:
      finding:
        title: "Squid cachemgr.cgi connects to arbitrary hosts — CVE-1999-0710"
        description: "{{dir}}/cachemgr.cgi accepted host={{result.host}} and port=1 from the query string, tried to connect there and reported \"Connection refused\". Anyone can make this CGI open TCP connections from the web server to any host and port and read whether they are open, using it as a relay into internal networks and as a port scanner (CVE-1999-0710)."
        remediation: "Remove cachemgr.cgi from public CGI directories or restrict access to it (web server authentication or an IP allow-list). On Squid versions that support it, list only the managed caches in /etc/squid/cachemgr.conf; on current Squid use the built-in cache manager (http://<proxy>/squid-internal-mgr/) protected by Squid ACLs instead of the CGI."
        confidence_delta: 0.55
        qod: 75
        evidence: "GET {{dir}}/cachemgr.cgi?host={{result.host}}&port=1 returned the CGI's connect error \"Connection refused\" (HTTP 200); GET {{dir}}/cachemgr.cgi without parameters returned the Cache Manager page without it (HTTP {{page.status}})"
      stop: true

View these feeds on GitHub