cgiemail — 1 vulnerability check

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

← All products · Feeds on GitHub

MIT cgiemail cgicso query buffer overflow

CVECVE-2002-1652
Severityhigh · CVSS 7.5
Categoryrce — Remote code execution
Serviceshttp, https
Detectionscript, set_var, http_request, match · highest QoD 70
Feedtests/vulnerabilities/cgiemail/CVE-2002-1652.yaml

Detects the cgicso program of MIT cgiemail, a CGI that relays a directory (CSO / ph) query to a CSO server. cgicso copies an overlong "query" parameter into a fixed buffer, which lets a remote attacker crash it or run code with the rights of the web server account (CVE-2002-1652). No fixed cgiemail release exists, so any installed cgicso is affected. The test requests cgicso?query=<random token> under the web root, /cgi-bin, /scripts and /cgi, and reports a reply that is a cgicso answer: either "400 Required field missing: fingerhost" (builds that take the CSO server from the form), or "Could not finger <token>@" / "Results of directory query" quoting the token (cgiemail 1.6, whose CSO server is built in). The cgiemail version shown on the error page is reported when present. The long query is never sent.

How noctis detects it

  1. Parses / computes the next value with a Rhai script
  2. HTTP(S) request GET {{loc.dir}}/cgicso?query={{tok}}
  3. Parses / computes the next value with a Rhai script
  4. Checks v.verdict for ^CGICSO_PRESENT$ → finding QoD 70: MIT cgiemail cgicso present — CVE-2002-1652

References:

Feed source — tests/vulnerabilities/cgiemail/CVE-2002-1652.yaml
# MIT cgiemail — cgicso ("send CSO via CGI") query buffer overflow
# (CVE-2002-1652, CERT VU#185251, SecurityTracker 1002395, BID 6141)
#
# Credit: target program and first marker adapted from Greenbone's
# `pre2008/cgicso_command_execution.nasl` (GPL-2.0-only, OID
# 1.3.6.1.4.1.25623.1.0.10779), which requests <dir>/cgicso?query=AAA under
# "/" and the CGI directories and reports when the reply contains
# "400 Required field missing: fingerhost".
#
# Facts:
#  - cgicso is a CGI program shipped with MIT's cgiemail that relays a
#    directory (CSO / ph) query to a CSO server and prints the result. NVD:
#    "Buffer overflow in cgicso.c for cgiemail 1.6 allows remote attackers to
#    cause a denial of service (crash) and possibly execute arbitrary code via
#    a long query parameter". CERT VU#185251 (2002-01-16): no vendor statement,
#    no practical solution; remove cgiemail from servers facing untrusted
#    clients. cgiemail 1.6 is the last MIT release, so no fixed version exists
#    and every installed cgicso is affected.
#  - Builds that take the CSO server from a "fingerhost" form field answer a
#    query without it with "400 Required field missing: fingerhost" (the
#    reference marker; not present in the 1.6 source, so an older or locally
#    configured build).
#  - cgiemail 1.6 (cgilibcso.c) hardcodes the CSO server (mitdir.mit.edu by
#    default) and asks for no fingerhost, so the reference marker never matches
#    it. Its replies quote our query instead: on a lookup or connect failure
#    cgi_output_failure() prints "500 Could not finger <query>@<host>", on
#    success cgi_cso_header() prints `Results of directory query: "<query>"`.
#    Error pages end with "<EM>cgiemail <version></EM>".
#
# Why no exploitation proof: the only trigger is the overflow itself (a long
# query), which crashes the CGI or runs attacker code. Nothing benign tells a
# vulnerable cgicso apart, and no fixed build exists, so presence is the
# finding (QoD 70).
#
# Better than the reference check:
#  - cgiemail 1.6 (the version NVD names) is detected too, through the
#    cgicso-specific phrases that quote a random per-run query token: a
#    server reflecting the request back cannot produce "Could not finger
#    <token>@" or `directory query: "<token>"`;
#  - the cgiemail version printed on the error page is reported when present;
#  - /scripts and /cgi are probed besides "/" and /cgi-bin.
uid: 409bc788-eec0-4ca7-9829-e49abf029508
name: "MIT cgiemail cgicso query buffer overflow (CVE-2002-1652)"
description: |
  Detects the cgicso program of MIT cgiemail, a CGI that relays a directory
  (CSO / ph) query to a CSO server. cgicso copies an overlong "query"
  parameter into a fixed buffer, which lets a remote attacker crash it or run
  code with the rights of the web server account (CVE-2002-1652). No fixed
  cgiemail release exists, so any installed cgicso is affected. The test
  requests cgicso?query=<random token> under the web root, /cgi-bin, /scripts
  and /cgi, and reports a reply that is a cgicso answer: either
  "400 Required field missing: fingerhost" (builds that take the CSO server
  from the form), or "Could not finger <token>@" / "Results of directory
  query" quoting the token (cgiemail 1.6, whose CSO server is built in). The
  cgiemail version shown on the error page is reported when present. The long
  query is never sent.
cves: [CVE-2002-1652]
cvss: 7.5
severity: high
category: rce
confidence_base: 0.30
tags: [cgiemail, cgicso, cso, ph, cgi, buffer-overflow, rce]
services: [http, https]
author: noctis
version: "1.0.0"
references:
  - "https://nvd.nist.gov/vuln/detail/CVE-2002-1652"
  - "https://www.kb.cert.org/vuls/id/185251"
  - "http://securitytracker.com/id?1002395"
  - "http://www.securityfocus.com/bid/6141"

steps:
  # Random query token, shared by every location: only cgicso quotes it inside
  # its own phrases.
  - id: mint-token
    action: script
    code: '"NOCTIS" + rand_hex(10)'
    store_as: tok

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

  - id: probe-cgicso
    action: http_request
    method: GET
    path: "{{loc.dir}}/cgicso?query={{tok}}"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 15
    store_as: probe

  # Fixed verdict strings as the match source, so no page content reaches the
  # finding; the version is the only value copied from the page.
  - id: verdict
    action: script
    code: |
      let b = if type_of(probe.body) == "string" { probe.body } else { "" };
      let kind = "";
      if b.contains("Required field missing: fingerhost") {
        kind = "fingerhost";
      } else if b.contains("Could not finger " + tok + "@") || b.contains("directory query: \"" + tok + "\"") {
        kind = "builtin-host";
      }
      let ver = "unknown";
      let m = eregmatch("<EM>cgiemail[ \r\n]+([0-9][0-9.]{0,9})", b, true);
      if kind != "" && m.len() > 1 { ver = m[1]; }
      let note = "";
      if kind == "fingerhost" { note = "asked for the missing fingerhost field (build that takes the CSO server from the form)"; }
      if kind == "builtin-host" { note = "quoted the query token in its CSO lookup reply (cgiemail 1.6 style, built-in CSO server)"; }
      #{ kind: kind, verdict: if kind == "" { "" } else { "CGICSO_PRESENT" }, ver: ver, note: note }
    store_as: v

  - id: cgicso-present
    action: match
    source: v.verdict
    pattern: '^CGICSO_PRESENT$'
    on_match:
      finding:
        title: "MIT cgiemail cgicso present — CVE-2002-1652"
        description: "{{loc.dir}}/cgicso of MIT cgiemail answered a directory query. cgicso copies an overlong query parameter into a fixed buffer, letting a remote attacker crash it or run code as the web server account (CVE-2002-1652). No fixed cgiemail release exists. The long query was not sent."
        remediation: "Remove cgicso (and cgiemail if unused) from the web server: MIT never released a fixed version. If a directory gateway is needed, replace it with maintained software."
        confidence_delta: 0.40
        qod: 70
        evidence: "GET {{loc.dir}}/cgicso?query={{tok}} returned HTTP {{probe.status}}; cgicso {{v.note}}; cgiemail version shown: {{v.ver}}"
      stop: true

View these feeds on GitHub