phpBazar — 2 vulnerability checks

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

← All products · Feeds on GitHub

phpBazar admin/admin.php Authentication Bypass

CVECVE-2009-4222
Severityhigh · CVSS 7.5
Categoryauth-bypass — Auth bypass
Serviceshttp, https
Detectionscript, set_var, http_request, match · highest QoD 75
Feedtests/vulnerabilities/phpbazar/CVE-2009-4222.yaml

Tests whether the phpBazar administration panel, admin/admin.php, can be opened without logging in. phpBazar 2.1.1fix and earlier do not check for an administrator in this script, so unless access to the admin/ directory is restricted by the web server, anyone can manage members, categories and ads.

In the web root and the usual install paths, the feed requests admin/admin.php without any session cookie and without following redirects. The finding is reported when the reply is a 200 page titled "phpBazar-AdminPanel" that is the panel itself rather than a login form (no password field, or a password field alongside a logout link), and when a request for a random, non-existent script in the same admin/ directory does not return that same page, so a site that answers every path with the panel title is not reported. The probe only reads the panel overview and changes nothing.

How noctis detects it

  1. Parses / computes the next value with a Rhai script
  2. HTTP(S) request GET {{dir}}/admin/admin.php
  3. Parses / computes the next value with a Rhai script
  4. HTTP(S) request GET {{dir}}/admin/{{ctl_name}}
  5. Parses / computes the next value with a Rhai script
  6. Checks hit_dir for ^/ → finding QoD 75: phpBazar admin/admin.php Authentication Bypass (CVE-2009-4222)

References:

Feed source — tests/vulnerabilities/phpbazar/CVE-2009-4222.yaml
# phpBazar <= 2.1.1fix — admin/admin.php served without authentication — CVE-2009-4222
#
# phpBazar's administration panel, admin/admin.php, has no login of its own: it includes
# the configuration and prints the panel (title "phpBazar-AdminPanel", the overview with
# the "Login to phpBazar with Admin- or Moderator-Level & use the Administration-Functions!"
# hint, and the action=members / cats / logging links). The only protection is the one the
# install guide asks the operator to add on the admin/ directory (e.g. .htaccess HTTP
# authentication); without it a direct request opens the panel (EDB-10233, EDB-1804).
# Checked against admin/admin.php of the 1.60n release (the only public source).
#
# Detection (read-only, QoD 75), per candidate install dir (web root and the usual paths):
#   1. GET <dir>/admin/admin.php without cookies, redirects not followed: 200 +
#      <title>phpBazar-AdminPanel</title>, and not a login form (no password field, or a
#      password field next to a logout link).
#   2. Control: GET <dir>/admin/noctis<random>.php must NOT answer 200 with the same title
#      (a front end that serves the panel title for any path is not reported).
#   The overview page (no action) only reads; no admin action is called.
#
# Better than the source NASL (title anywhere in the reply):
#   - a login form carrying the panel title (a site that put its own login in front of
#     admin/) is not reported, nor a redirect;
#   - catch-all control on a random sibling script;
#   - the usual install paths are probed as well as the web root.
#
# CVSS: NVD v2 7.5 (no v3 score published).
#
# Source: OpenVAS/Greenbone NVT 2010/gb_phpbazar_sql_inj_vuln.nasl
# (OID 1.3.6.1.4.1.25623.1.0.800465, GPL-2.0-only).
uid: 489cc61d-8979-4c90-8dae-c81dbfb948c7
name: "phpBazar admin/admin.php Authentication Bypass (CVE-2009-4222)"
description: |
  Tests whether the phpBazar administration panel, admin/admin.php, can be opened without
  logging in. phpBazar 2.1.1fix and earlier do not check for an administrator in this
  script, so unless access to the admin/ directory is restricted by the web server, anyone
  can manage members, categories and ads.

  In the web root and the usual install paths, the feed requests admin/admin.php without
  any session cookie and without following redirects. The finding is reported when the
  reply is a 200 page titled "phpBazar-AdminPanel" that is the panel itself rather than a
  login form (no password field, or a password field alongside a logout link), and when a
  request for a random, non-existent script in the same admin/ directory does not return
  that same page, so a site that answers every path with the panel title is not reported.
  The probe only reads the panel overview and changes nothing.
cves: [CVE-2009-4222]
cvss: 7.5
severity: high
category: auth-bypass
confidence_base: 0.30
tags: [phpbazar, php, auth-bypass, admin-panel]
services: [http, https]
author: noctis
version: "1.0.0"
references:
  - "https://nvd.nist.gov/vuln/detail/CVE-2009-4222"
  - "https://www.exploit-db.com/exploits/10233"
  - "https://www.exploit-db.com/exploits/1804"
  # OpenVAS/Greenbone NASL 2010/gb_phpbazar_sql_inj_vuln.nasl (GPL-2.0-only)

steps:
  - id: mint
    action: script
    code: '"noctis" + rand_hex(6) + ".php"'
    store_as: ctl_name

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

  # ── Loop group: every step below runs once per candidate install dir ─────
  - id: init-adm
    action: set_var
    var_name: adm
    var_value: {status: 0, body: ""}
    loop:
      var: dir
      over: ["", "/phpBazar", "/phpbazar", "/bazar", "/classifieds"]

  - id: init-ctl
    action: set_var
    var_name: ctl
    var_value: {status: 0, body: ""}

  - id: init-panel
    action: set_var
    var_name: is_panel
    var_value: false

  - id: fetch-admin
    action: http_request
    method: GET
    path: "{{dir}}/admin/admin.php"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 15
    condition: 'hit_dir == ""'
    store_as: adm

  # The panel itself: 200 and the panel title, and not a login form. A page with a
  # password field counts as a login form unless it also offers a logout link.
  - id: panel
    action: script
    condition: 'hit_dir == ""'
    store_as: is_panel
    code: |
      adm.status == 200 && type_of(adm.body) == "string"
        && egrep("(?i)<title>\\s*phpBazar-AdminPanel\\s*</title>", adm.body) != ""
        && (egrep("(?i)<input[^>]*type\\s*=\\s*[\"']?password", adm.body) == ""
            || egrep("(?i)log\\s*-?\\s*out", adm.body) != "")

  - id: fetch-control
    action: http_request
    method: GET
    path: "{{dir}}/admin/{{ctl_name}}"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 15
    condition: 'hit_dir == "" && is_panel == true'
    store_as: ctl

  - id: verdict
    action: script
    condition: 'hit_dir == "" && is_panel == true'
    store_as: hit_dir
    code: |
      let ctl_hit = ctl.status == 200 && type_of(ctl.body) == "string"
        && egrep("(?i)<title>\\s*phpBazar-AdminPanel\\s*</title>", ctl.body) != "";
      if ctl_hit { "" } else if dir == "" { "/" } else { dir }

  - id: report
    action: match
    source: hit_dir
    pattern: "^/"
    on_match:
      finding:
        title: "phpBazar admin/admin.php Authentication Bypass (CVE-2009-4222)"
        description: "The phpBazar administration panel (admin/admin.php) is served to a request that carries no session: the page titled \"phpBazar-AdminPanel\" came back with no login form. Anyone who can reach the site can manage members, categories and ads."
        remediation: "No fixed phpBazar release is known: restrict access to the admin/ directory in the web server (HTTP authentication or an IP allow-list), or remove the application."
        confidence_delta: 0.50
        qod: 75
        evidence: "install dir {{hit_dir}}: GET admin/admin.php without a session returned HTTP 200 with the phpBazar-AdminPanel page rather than a login form; the control request admin/{{ctl_name}} in the same directory did not return that page."
      stop: true

phpBazar classified.php catid SQL Injection

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

phpBazar 2.1.1fix and earlier put the catid parameter of classified.php unquoted into the SQL queries that show a category page, allowing SQL injection by anonymous visitors when ads are publicly readable (the default): an attacker can read the whole database, including member accounts.

This check requests classified.php in the web root and the usual install paths. Where it answers, it first sends a catid that filters out every real row and appends a UNION SELECT of an expression multiplying two random numbers; the vulnerability is confirmed when the page lists the product computed by the database, which never appears in the request. Where the UNION does not fit the tables, it takes a category id N linked from the landing page and requests the category as the expression K-(K-N), with K random: the vulnerability is confirmed when that page shows the same category as catid=N while catid=K and catid=K-K (zero for the database) show other pages, which only happens when the database evaluates the parameter. No stored data beyond the public category page is read and nothing is written.

How noctis detects it

  1. Parses / computes the next value with a Rhai script
  2. HTTP(S) request GET {{dir}}/classified.php
  3. HTTP(S) request GET {{dir}}/classified.php?catid={{sc.q}}
  4. Parses / computes the next value with a Rhai script
  5. Parses / computes the next value with a Rhai script
  6. HTTP(S) request GET {{dir}}/classified.php?catid={{cat.n}}
  7. HTTP(S) request GET {{dir}}/classified.php?catid={{sc.k}}-({{sc.k}}-{{cat.n}})
  8. HTTP(S) request GET {{dir}}/classified.php?catid={{sc.k}}
  9. HTTP(S) request GET {{dir}}/classified.php?catid={{sc.k}}-{{sc.k}}
  10. Parses / computes the next value with a Rhai script
  11. Checks hit for ^union:/ → finding QoD 97: phpBazar classified.php catid SQL Injection (CVE-2009-4221)
  12. Checks hit for ^arith:/ → finding QoD 75: phpBazar classified.php catid SQL Injection (CVE-2009-4221)

References:

Feed source — tests/vulnerabilities/phpbazar/CVE-2009-4221.yaml
# phpBazar <= 2.1.1fix — classified.php catid SQL injection — CVE-2009-4221
#
# classified.php includes classified_cat_show.php for a category page, which runs, with
# catid taken raw from the request (source of the 1.60n release, the only public one;
# the 2.1.1fix issue is reported by EDB-10245):
#     SELECT * FROM adcat WHERE id=$catid                       (category name, "Home / <name>")
#     SELECT * FROM adsubcat where catid=$catid ORDER by id     (sub-category list)
# and prints each sub-category row as
#     <a href="classified.php?catid=$catid&subcatid=$db[id]">$db[name]</a> ($db[ads])
# A failed query calls died() ("Record NOT Found" pop-up script, then exit). Anonymous
# visitors reach it when ads are publicly readable ($bazarfreeread, the default);
# otherwise classified.php shows the login notice.
#
# Detection, per candidate install dir whose classified.php answers 200:
#   A. (QoD 97) catid = <r> and 1=0 union all select P,P,P,P,P,P,P-- -  with P = a*b
#      (random a, b) — the 7-column UNION of the public exploit. The page prints the
#      product only if the database evaluated it. It works only where the adcat table
#      also has 7 columns: in the 1.60n schema adcat has ~50 (field1-20, icon1-10…), the
#      first query then fails and died() ends the page. Hence B.
#   B. (QoD 75) arithmetic differential, no column count needed. N = the first category
#      id the landing page links (classified.php?catid=N). Signature of a category page =
#      its "Home / <name>" text + the sub-category ids it lists.
#        sig(catid=N) must be non-empty;
#        sig(catid=K-(K-N)) must equal it (K random): only SQL arithmetic turns the
#          expression back into N — an (int) cast reads K, a reflector shows nothing;
#        sig(catid=K) must differ (a page that ignores catid is not reported);
#        sig(catid=K-K) must differ (= id 0 for SQL; a site that shows its default
#          category for any non-numeric catid shows N there and is not reported).
#      The base page must carry a phpBazar mark (footer / maincatnav).
#   Read-only: no stored row is selected beyond the category page itself, nothing written.
#
# Better than the source NASL:
#   - the NASL matches the fixed text "...7--&subcatid=1", which a page that only echoes
#     catid into its links (in front of a real sub-category id 1) also produces, and
#     which a real 1.60n-schema install never returns (adcat column count);
#   - database-computed proofs only (product, arithmetic), plus a catid-ignored control;
#   - "-- -" ends the comment; the usual install paths are probed as well as the web root.
#
# CVSS: NVD v2 7.5 (no v3 score published).
#
# Source: OpenVAS/Greenbone NVT 2010/gb_phpbazar_sql_inj_vuln.nasl
# (OID 1.3.6.1.4.1.25623.1.0.800465, GPL-2.0-only).
uid: 891bcce7-d552-42a2-aa81-a392b8bcd610
name: "phpBazar classified.php catid SQL Injection (CVE-2009-4221)"
description: |
  phpBazar 2.1.1fix and earlier put the catid parameter of classified.php unquoted into
  the SQL queries that show a category page, allowing SQL injection by anonymous visitors
  when ads are publicly readable (the default): an attacker can read the whole database,
  including member accounts.

  This check requests classified.php in the web root and the usual install paths. Where
  it answers, it first sends a catid that filters out every real row and appends a UNION
  SELECT of an expression multiplying two random numbers; the vulnerability is confirmed
  when the page lists the product computed by the database, which never appears in the
  request. Where the UNION does not fit the tables, it takes a category id N linked from
  the landing page and requests the category as the expression K-(K-N), with K random:
  the vulnerability is confirmed when that page shows the same category as catid=N while
  catid=K and catid=K-K (zero for the database) show other pages, which only happens
  when the database evaluates the parameter. No stored data beyond the public category page is read and nothing is
  written.
cves: [CVE-2009-4221]
cvss: 7.5
severity: high
category: sqli
confidence_base: 0.30
tags: [phpbazar, sqli, union-based, boolean-based, php]
services: [http, https]
author: noctis
version: "1.0.0"
references:
  - "https://nvd.nist.gov/vuln/detail/CVE-2009-4221"
  - "https://www.exploit-db.com/exploits/10245"
  - "http://www.smartisoft.com/"
  # OpenVAS/Greenbone NASL 2010/gb_phpbazar_sql_inj_vuln.nasl (GPL-2.0-only)

steps:
  # ── Random operands, expected value and the encoded catid payloads ────────
  - id: gen-proof
    action: script
    code: |
      let a = rand_int(100000, 999999);
      let b = rand_int(100000, 999999);
      let r = rand_int(1000, 9999);
      let k = rand_int(100000, 999999);
      let e = a + "*" + b;
      #{ want: "" + (a * b),
         expr: e,
         r: r,
         k: "" + k,
         q: r + "+and+1=0+union+all+select+" + e + "," + e + "," + e + "," + e + "," + e
            + "," + e + "," + e + "--+-" }
    store_as: sc

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

  # ── Per candidate install path (loop group) ───────────────────────────────
  - id: init-landing
    action: set_var
    var_name: landing
    var_value: {status: 0, body: ""}
    loop:
      var: dir
      over: ["", "/phpBazar", "/phpbazar", "/bazar", "/classifieds"]

  - id: init-probe
    action: set_var
    var_name: probe
    var_value: {status: 0, body: ""}

  - id: init-cat
    action: set_var
    var_name: cat
    var_value: {n: ""}

  - id: init-base
    action: set_var
    var_name: base
    var_value: {status: 0, body: ""}

  - id: init-arith
    action: set_var
    var_name: arith
    var_value: {status: 0, body: ""}

  - id: init-ctl
    action: set_var
    var_name: ctl
    var_value: {status: 0, body: ""}

  - id: init-zero
    action: set_var
    var_name: zero
    var_value: {status: 0, body: ""}

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

  # ── A. 7-column UNION, database-computed product ──────────────────────────
  - id: union-probe
    action: http_request
    method: GET
    path: "{{dir}}/classified.php?catid={{sc.q}}"
    port: "{{port}}"
    tls_insecure: true
    timeout_secs: 15
    condition: 'hit == "" && landing.status == 200'
    store_as: probe

  - id: check-union
    action: script
    condition: 'hit == "" && landing.status == 200'
    code: |
      let body = if type_of(probe.body) == "string" { probe.body } else { "" };
      if egrep("(^|[^0-9])" + sc.want + "([^0-9]|$)", body) != "" {
        "union:" + (if dir == "" { "/" } else { dir })
      } else { "" }
    store_as: hit

  # ── B. Arithmetic differential on a real category id ──────────────────────
  - id: pick-category
    action: script
    condition: 'hit == "" && landing.status == 200'
    code: |
      let body = if type_of(landing.body) == "string" { landing.body } else { "" };
      let m = eregmatch("classified\\.php\\?catid=([0-9]{1,9})[\"'&]", body);
      #{ n: if m.len() > 1 { m[1] } else { "" } }
    store_as: cat

  - id: fetch-base
    action: http_request
    method: GET
    path: "{{dir}}/classified.php?catid={{cat.n}}"
    port: "{{port}}"
    tls_insecure: true
    timeout_secs: 15
    condition: 'hit == "" && cat.n != ""'
    store_as: base

  - id: fetch-arith
    action: http_request
    method: GET
    path: "{{dir}}/classified.php?catid={{sc.k}}-({{sc.k}}-{{cat.n}})"
    port: "{{port}}"
    tls_insecure: true
    timeout_secs: 15
    condition: 'hit == "" && cat.n != "" && base.status == 200'
    store_as: arith

  - id: fetch-control
    action: http_request
    method: GET
    path: "{{dir}}/classified.php?catid={{sc.k}}"
    port: "{{port}}"
    tls_insecure: true
    timeout_secs: 15
    condition: 'hit == "" && cat.n != "" && base.status == 200'
    store_as: ctl

  # Non-numeric catid the database reduces to 0 (no category): a site that shows its
  # default category for any non-numeric catid shows N here and is not reported.
  - id: fetch-zero
    action: http_request
    method: GET
    path: "{{dir}}/classified.php?catid={{sc.k}}-{{sc.k}}"
    port: "{{port}}"
    tls_insecure: true
    timeout_secs: 15
    condition: 'hit == "" && cat.n != "" && base.status == 200'
    store_as: zero

  # Signature of a category page: the "Home / <name>" navigation text and the ids of
  # the sub-categories it links. Same signature for N and K-(K-N), another for K.
  - id: verdict-arith
    action: script
    condition: 'hit == "" && cat.n != "" && base.status == 200'
    code: |
      let sent = [cat.n, sc.k + "-(" + sc.k + "-" + cat.n + ")", sc.k, sc.k + "-" + sc.k];
      let pages = [base, arith, ctl, zero];
      let sigs = [];
      let j = 0;
      while j < 4 {
        let r = pages[j];
        let body = if r.status == 200 && type_of(r.body) == "string" { r.body } else { "" };
        let nav = eregmatch("(?s)maincatnav[^>]*>.*?</a>\\s*/\\s*([^<\\r\\n]*)", body);
        let s = if nav.len() > 1 { let t = nav[1]; t.trim(); t } else { "" };
        // only the sub-category links of this category page (catid echoed as sent)
        let ids = "";
        let parts = split(body, "catid=" + sent[j] + "&subcatid=");
        let i = 1;
        while i < parts.len() {
          let m = eregmatch("^([0-9]+)", parts[i]);
          if m.len() > 1 { ids += "," + m[1]; }
          i += 1;
        }
        sigs.push(if s == "" && ids == "" { "" } else { s + "|" + ids });
        j += 1;
      }
      let is_bazar = type_of(base.body) == "string"
        && egrep("(?i)phpBazar|maincatnav", base.body) != "";
      if is_bazar && sigs[0] != "" && sigs[1] == sigs[0] && sigs[2] != sigs[0] && sigs[3] != sigs[0] {
        "arith:" + (if dir == "" { "/" } else { dir })
      } else { "" }
    store_as: hit

  # ── Findings ──────────────────────────────────────────────────────────────
  - id: report-union
    action: match
    source: hit
    pattern: "^union:/"
    on_match:
      finding:
        title: "phpBazar classified.php catid SQL Injection (CVE-2009-4221)"
        description: "A request to classified.php with a catid carrying a UNION SELECT of a multiplication of two random numbers returned the product computed by the database: catid reaches the SQL query unquoted, so an attacker can read the whole database, including member accounts and passwords."
        remediation: "No fixed phpBazar release is known: remove the application, or at least restrict access to it. If it must stay, cast catid (and every other numeric parameter) to an integer before it is used in a query."
        confidence_delta: 0.67
        qod: 97
        evidence: "{{hit}}: classified.php?catid={{sc.r}} and 1=0 union all select {{sc.expr}} (x7)-- - returned the database-computed value {{sc.want}}"
      stop: true

  - id: report-arith
    action: match
    source: hit
    pattern: "^arith:/"
    on_match:
      finding:
        title: "phpBazar classified.php catid SQL Injection (CVE-2009-4221)"
        description: "classified.php evaluates the catid parameter as SQL: the category requested as an arithmetic expression that only a database reduces to an existing category id returned that category's page, while the expression's leading number alone and an expression worth zero returned other pages. catid reaches the SQL query unquoted, so an attacker can read the whole database, including member accounts and passwords."
        remediation: "No fixed phpBazar release is known: remove the application, or at least restrict access to it. If it must stay, cast catid (and every other numeric parameter) to an integer before it is used in a query."
        confidence_delta: 0.50
        qod: 75
        evidence: "{{hit}}: classified.php?catid={{sc.k}}-({{sc.k}}-{{cat.n}}) showed the same category page as catid={{cat.n}}, while catid={{sc.k}} and catid={{sc.k}}-{{sc.k}} did not"
      stop: true

View these feeds on GitHub