Wwwcount — 1 vulnerability check

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

← All products · Feeds on GitHub

WWW Homepage Access Counter (Count.cgi) <= 2.3 QUERY_STRING Buffer Overflow

CVECVE-1999-0021
Severityhigh · CVSS 7.5
Categoryrce — Remote code execution
Serviceshttp, https
Detectionset_var, http_request, script, match · highest QoD 70
Feedtests/vulnerabilities/wwwcount/CVE-1999-0021.yaml

Detects Count.cgi (WWW Homepage Access Counter, wwwcount) version 2.3 or older, whose QUERY_STRING parser overflows fixed-size stack buffers, letting a remote attacker run commands with the web server's privileges (fixed in version 2.4). For each usual CGI folder (the web root, /cgi-bin, /scripts, /cgi-local, /counter) the feed requests Count.cgi?lit=1, which makes the counter draw a literal-number GIF image without reading or updating any counter file (and, if that reply names no version, Count.cgi?align=topcenter). Count.cgi writes its own name and version into the GIF comment of every image it draws; the feed reports the target when the reply is HTTP 200, is a GIF image, and that comment names a version up to 2.3. Text pages that merely mention the counter are not reported. The version is read without triggering the overflow, so the target's process is never corrupted.

How noctis detects it

  1. HTTP(S) request GET {{dir}}/Count.cgi?lit=1
  2. HTTP(S) request GET {{dir}}/Count.cgi?align=topcenter
  3. Parses / computes the next value with a Rhai script
  4. Checks cnt.vulnerable for ^true$ → finding QoD 70: Count.cgi <= 2.3 QUERY_STRING buffer overflow (CVE-1999-0021)

References:

Feed source — tests/vulnerabilities/wwwcount/CVE-1999-0021.yaml
# WWW Homepage Access Counter (wwwcount, Count.cgi) <= 2.3 — QUERY_STRING buffer
# overflow (CVE-1999-0021, CERT CA-97.24)
#
# Count.cgi, Muhammad A. Muquit's GIF hit counter, copies the request's QUERY_STRING
# into fixed-size stack buffers while parsing it; a long query string overflows them
# and runs code as the web server user. Fixed in Count 2.4.
#
# Detection (read-only, QoD 70): the only behavioural proof of this flaw is the stack
# overflow itself (memory corruption in the target's process), so the feed reads the
# version instead. Count.cgi stamps every counter image it draws with a GIF comment
# "Count.cgi <version> By <author> URL: <url>" (main.c MogrifyImage(), Version from
# count.h, e.g. "\nCount.cgi 2.3 \nBy muquit@semcor.com\n…"). Error images
# (StringImage()) carry no comment, and 2.x rejects any unknown query keyword with
# one ("Bad keyword …"). For each usual CGI folder the feed requests
# Count.cgi?lit=1: "lit" (a literal string to draw) is a valid 2.x keyword, and the
# literal branch never opens, creates or increments a counter data file; without a
# Referer, strict mode draws "888888" instead, still with the comment. When that
# reply names no version, the folder is retried with the historical probe
# Count.cgi?align=topcenter. Versions 0.x, 1.x and 2.0–2.3 are reported.
#
# Improvements over the source NASL:
#   - the NASL only sends ?align=topcenter; "align" is not a Count 2.x keyword, so a
#     real 2.3 answers with a "Bad keyword" error image without the version comment
#     (false negative on every 2.x install). The feed sends ?lit=1 first;
#   - the reply must be HTTP 200 AND a GIF image (body starts with "GIF87a"/"GIF89a");
#     the NASL matched "Count.cgi 2.x" anywhere, so a text page that merely mentions
#     the counter (a docs/changelog page, a reflector echoing the version) was reported;
#   - the version is bounded on the right ("Count.cgi 2.3" vs a hypothetical 2.30),
#     and the NASL's `2\.[0-3]+` repetition is dropped;
#   - folders: the web root, /cgi-bin, /scripts, /cgi-local, /counter, without
#     relying on a CGI-dir crawl.
#
# CVSS: NVD has only a v2 score for CVE-1999-0021 (7.5, AV:N/AC:L/Au:N/C:P/I:P/A:P).
#
# Ported from OpenVAS/Greenbone NVT pre2008/count_cgi.nasl
# (OID 1.3.6.1.4.1.25623.1.0.10049, GPL-2.0-only).
uid: a6295371-cf9b-4679-9901-519ea2974cf2
name: "WWW Homepage Access Counter (Count.cgi) <= 2.3 QUERY_STRING Buffer Overflow"
description: |
  Detects Count.cgi (WWW Homepage Access Counter, wwwcount) version 2.3 or older,
  whose QUERY_STRING parser overflows fixed-size stack buffers, letting a remote
  attacker run commands with the web server's privileges (fixed in version 2.4).
  For each usual CGI folder (the web root, /cgi-bin, /scripts, /cgi-local,
  /counter) the feed requests Count.cgi?lit=1, which makes the counter draw a
  literal-number GIF image without reading or updating any counter file (and,
  if that reply names no version, Count.cgi?align=topcenter). Count.cgi writes its own name and version into the GIF
  comment of every image it draws; the feed reports the target when the reply is
  HTTP 200, is a GIF image, and that comment names a version up to 2.3. Text
  pages that merely mention the counter are not reported. The version is read
  without triggering the overflow, so the target's process is never corrupted.
cves: [CVE-1999-0021]
cvss: 7.5
severity: high
category: rce
confidence_base: 0.30
tags: [wwwcount, count-cgi, cgi, buffer-overflow, version-check, unauthenticated]
services: [http, https]
author: noctis
version: "1.0.0"
references:
  - "https://nvd.nist.gov/vuln/detail/CVE-1999-0021"
  - "https://www.kb.cert.org/vuls/id/CA-1997-24"
  - "https://legacy.ccp4.ac.uk/wwwcount2.5/docs/Count.html"
  # OpenVAS/Greenbone NASL pre2008/count_cgi.nasl (GPL-2.0-only)

steps:
  # Loop group: every following step runs once per CGI folder; the finding
  # stops the test, so later folders are not probed after a hit.
  - id: init-cnt-r
    action: set_var
    var_name: cnt_r
    var_value: {status: 0, body: ""}
    loop:
      var: dir
      over: ["", "/cgi-bin", "/scripts", "/cgi-local", "/counter"]

  - id: init-cnt-r2
    action: set_var
    var_name: cnt_r2
    var_value: {status: 0, body: ""}

  # "lit" is a 2.x keyword; the literal branch touches no counter data file.
  - id: counter-image
    action: http_request
    method: GET
    path: "{{dir}}/Count.cgi?lit=1"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 10
    store_as: cnt_r

  # Historical probe, only when the first reply carried no version comment.
  - id: counter-image-align
    action: http_request
    method: GET
    path: "{{dir}}/Count.cgi?align=topcenter"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 10
    condition: '!(cnt_r.status == 200 && type_of(cnt_r.body) == "string" && cnt_r.body.contains("Count.cgi "))'
    store_as: cnt_r2

  # Parse the GIF comment. Only an HTTP 200 GIF image counts.
  - id: parse-version
    action: script
    store_as: cnt
    code: |
      let res = #{ gif: false, version: "", vulnerable: false, query: "", status: 0 };
      for pair in [[cnt_r, "lit=1"], [cnt_r2, "align=topcenter"]] {
        let r = pair[0];
        let body = if type_of(r.body) == "string" { r.body } else { "" };
        let gif = r.status == 200 && (body.starts_with("GIF87a") || body.starts_with("GIF89a"));
        let m = if gif { eregmatch("Count\\.cgi +([0-9]+\\.[0-9]+)([^0-9.]|$)", body) } else { [] };
        if m.len() > 1 {
          let ver = m[1];
          res = #{
            gif: true,
            version: ver,
            vulnerable: ereg("^([01]\\.[0-9]+|2\\.[0-3])$", ver),
            query: pair[1],
            status: r.status
          };
          break;
        }
      }
      res

  - id: report
    action: match
    source: cnt.vulnerable
    pattern: "^true$"
    condition: "cnt.gif == true"
    on_match:
      finding:
        title: "Count.cgi <= 2.3 QUERY_STRING buffer overflow (CVE-1999-0021)"
        description: "Count.cgi (WWW Homepage Access Counter) version 2.3 or older is installed. Its QUERY_STRING parser copies attacker-controlled data into fixed-size stack buffers, so a crafted request runs arbitrary commands with the privileges of the web server."
        remediation: "Remove Count.cgi from the CGI directory, or upgrade the WWW Homepage Access Counter to version 2.4 or later."
        confidence_delta: 0.45
        qod: 70
        evidence: "GET {{dir}}/Count.cgi?{{cnt.query}} returned a GIF counter image (HTTP {{cnt.status}}) whose comment identifies Count.cgi {{cnt.version}} (vulnerable: <= 2.3)"
      stop: true

View these feeds on GitHub