nph-publish — 1 vulnerability check

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

← All products · Feeds on GitHub

nph-publish upload path traversal — arbitrary file overwrite

CVECVE-1999-1177
Severitymedium · CVSS 5.0
Categoryrce — Remote code execution
Serviceshttp, https
Detectionscript, set_var, http_request, match · highest QoD 70
Feedtests/vulnerabilities/nph-publish/CVE-1999-1177.yaml

Detects the nph-publish CGI script, which stores files uploaded with the HTTP PUT method under the web server's document root. Versions before 1.2 accept ".." in the target path of an upload, so a client allowed to publish can overwrite any file the web server user can write (CVE-1999-1177). The test requests nph-publish.cgi and nph-publish under the web root, /cgi-bin and /scripts, and reports one that the server runs (HTTP 200 with a page that is not the script's source, or 400 / 405 / 501 because the script only accepts PUT) while a random name in the same directory gets 404 or 410 (so servers that answer every path are not reported). No upload is sent, so a copy already at version 1.2 or later is reported too and its version must be checked by hand.

How noctis detects it

  1. Parses / computes the next value with a Rhai script
  2. HTTP(S) request GET {{loc.dir}}/{{loc.file}}
  3. HTTP(S) request GET {{loc.dir}}/{{ctl}}{{loc.ext}}
  4. Parses / computes the next value with a Rhai script
  5. Checks verdict for ^NPH_PUBLISH_PRESENT$ → finding QoD 70: nph-publish upload script present — CVE-1999-1177

References:

Feed source — tests/vulnerabilities/nph-publish/CVE-1999-1177.yaml
# nph-publish (Lincoln Stein's server_publish PUT handler) upload path
# directory traversal — arbitrary file overwrite (CVE-1999-1177)
#
# Credit: target name adapted from Greenbone's `pre2008/nph-publish.nasl`
# (GPL-2.0-only), which reports when nph-publish.cgi is installed
# (http_is_cgi_installed_ka) under / and the CGI directories.
#
# CVE mapping: the reference check also lists CVE-2001-0400, whose NVD record
# is a different script (nph-maillist.pl, shell metacharacters in the e-mail
# address). This feed does not test nph-maillist.pl, so only CVE-1999-1177 is
# reported.
#
# Record facts (NVD, W3C WWW Security FAQ Q4): nph-publish is a non-parsed-
# header Perl CGI that stores files uploaded with the HTTP PUT method (the
# "publish" button of Netscape Navigator Gold and similar editors) under the
# document root. Before version 1.2 it does not reject ".." in the target path
# of a PUT, so a client allowed to publish can write or overwrite any file the
# web server user can write.
#
# Why no exploitation proof: the only trigger is a PUT that writes a file
# outside the publishing area — a write on the target. The script ships no
# version banner, so 1.2+ cannot be told from older copies without that
# write. This is a presence check at QoD 70.
#
# Better than the reference check:
#  - also probes the script under its original name (nph-publish, no
#    extension), the name the author's distribution used;
#  - a random sibling name in the same directory is requested as a control
#    and must get a 404 / 410 (soft-404 / catch-all servers are
#    not reported); no control reply gives no finding (fail-closed);
#  - the script must run: a 200 whose body is the Perl source ("#!" first
#    line or a Perl / binary content type) is a directory that serves CGI
#    files as plain files, and is not reported;
#  - a 400 / 405 / 501 reply (the non-parsed-header script writing its own
#    status line to refuse GET, it only handles PUT) counts as installed when
#    the control got a plain 404 / 410;
#  - a 200 web-application-firewall block page ("Request Rejected") is not
#    reported.
#  - no PUT is ever sent.
uid: e2ea8767-b963-4446-8620-75e193d0f1a0
name: "nph-publish upload path traversal — arbitrary file overwrite (CVE-1999-1177)"
description: |
  Detects the nph-publish CGI script, which stores files uploaded with the
  HTTP PUT method under the web server's document root. Versions before 1.2
  accept ".." in the target path of an upload, so a client allowed to publish
  can overwrite any file the web server user can write (CVE-1999-1177). The
  test requests nph-publish.cgi and nph-publish under the web root, /cgi-bin
  and /scripts, and reports one that the server runs (HTTP 200 with a page
  that is not the script's source, or 400 / 405 / 501 because the script only
  accepts PUT) while a random name in the same directory gets 404 or 410 (so
  servers that answer every path are not reported). No upload is sent, so
  a copy already at version 1.2 or later is reported too and its version must
  be checked by hand.
cves: [CVE-1999-1177]
cvss: 5.0
severity: medium
category: rce
confidence_base: 0.30
tags: [nph-publish, cgi, perl, http-put, path-traversal, file-write]
services: [http, https]
author: noctis
version: "1.0.0"
references:
  - "https://nvd.nist.gov/vuln/detail/CVE-1999-1177"
  - "https://www.w3.org/Security/Faq/wwwsf4.html"
  - "https://exchange.xforce.ibmcloud.com/vulnerabilities/2055"

steps:
  # Random sibling name for the soft-404 control, shared by every location.
  - id: mint-control
    action: script
    code: '"nph-" + rand_hex(8)'
    store_as: ctl

  # ── Per location: 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: {status: 0}
    loop:
      over:
        - {dir: "", file: "nph-publish.cgi", ext: ".cgi"}
        - {dir: "", file: "nph-publish", ext: ""}
        - {dir: "/cgi-bin", file: "nph-publish.cgi", ext: ".cgi"}
        - {dir: "/cgi-bin", file: "nph-publish", ext: ""}
        - {dir: "/scripts", file: "nph-publish.cgi", ext: ".cgi"}
        - {dir: "/scripts", file: "nph-publish", ext: ""}
      var: loc

  - id: init-control
    action: set_var
    var_name: control
    var_value: {status: 0}

  - id: probe-script
    action: http_request
    method: GET
    path: "{{loc.dir}}/{{loc.file}}"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 10
    store_as: page

  - id: probe-control
    action: http_request
    method: GET
    path: "{{loc.dir}}/{{ctl}}{{loc.ext}}"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    timeout_secs: 10
    condition: "page.status == 200 || page.status == 400 || page.status == 405 || page.status == 501"
    store_as: control

  # Fixed verdict string as the match source, so no page content reaches the
  # finding.
  - id: verdict
    action: script
    code: |
      let v = "";
      // A script that runs answers with its own page; a server that only
      // hands the file out returns the Perl source or a binary download, and
      // a web application firewall may answer 200 with its block page.
      let served_as_file = false;
      if page.status == 200 {
        let ct = "";
        if "content-type" in page.headers { ct = tolower(page.headers["content-type"]); }
        let head = page.body;
        head.trim();
        served_as_file = ct.contains("perl") || ct.contains("octet-stream") || ct.contains("x-cgi") || ct.contains("x-httpd-cgi") || head.starts_with("#!") || page.body.contains("Request Rejected");
      }
      // The non-parsed-header script writes its own status line: a refusal of
      // GET (400 / 405 / 501) still proves it ran.
      let ran = (page.status == 200 && !served_as_file) || page.status == 400 || page.status == 405 || page.status == 501;
      if ran && (control.status == 404 || control.status == 410) { v = "NPH_PUBLISH_PRESENT"; }
      v
    store_as: verdict

  - id: script-present
    action: match
    source: verdict
    pattern: '^NPH_PUBLISH_PRESENT$'
    on_match:
      finding:
        title: "nph-publish upload script present — CVE-1999-1177"
        description: "{{loc.dir}}/{{loc.file}} is the nph-publish upload script (it answered while a random name in the same directory was not found). nph-publish before 1.2 accepts \"..\" in the target path of an HTTP PUT upload, so a client allowed to publish can overwrite any file the web server user can write (CVE-1999-1177). No upload was sent, so a copy at version 1.2 or later cannot be told apart."
        remediation: "Remove nph-publish from the web server, or upgrade it to version 1.2 or later and restrict who may publish with the server's access control. Prefer a maintained publishing method (WebDAV with authentication) for uploads."
        confidence_delta: 0.40
        qod: 70
        evidence: "GET {{loc.dir}}/{{loc.file}} returned HTTP {{page.status}}; control GET {{loc.dir}}/{{ctl}}{{loc.ext}} returned HTTP {{control.status}}"
      stop: true

View these feeds on GitHub