Skip to content

reconFTW is a tool designed to perform automated recon on a target domain by running the best set of tools to perform scanning and finding out vulnerabilities

fix(web): select the -l scope path on $flist, not $list (#1045)

six2dez1057fb51e9cb
diff --git a/modules/modes.sh b/modules/modes.sh
index 2fe8d96..710914f 100644
--- a/modules/modes.sh
+++ b/modules/modes.sh
@@ -225,7 +225,22 @@ function start() {
#
# Used by: reconftw.sh -w dispatch, monitor_mode 'w' case (every cycle).
function prepare_web_mode_scope() {
- if [[ -n $list ]]; then
+ # Branch on $flist, NOT $list (issue #1045).
+ #
+ # $flist is the resolved absolute path of the user's -l file and is set ONCE,
+ # at startup in reconftw.sh, from whatever $list held then; with -d it is set
+ # to '' and stays empty for the run. So $flist is the signal for "the user
+ # passed a list", and it is the variable this branch actually operates on
+ # (the cp below, and the -not -path guard further down).
+ #
+ # $list is NOT that signal, because start() reassigns it mid-run: under
+ # AXIOM with -d it writes the domain to target.txt and sets
+ # list="${dir}/target.txt" (modules/modes.sh, start). Branching on $list
+ # therefore sent `reconftw.sh -d example.com -w -v 50` down the -l path with
+ # $flist still empty, so the snapshot `cp "" <tmp>` failed and scope prep
+ # returned 1 — aborting the run before webs_menu with
+ # "Web mode scope preparation failed (tmpfile/cp error)".
+ if [[ -n $flist ]]; then
# Defense-in-depth for the user's input file: treat $flist as strictly
# read-only. One initial `cp` to a tmp snapshot outside $dir; every
# subsequent operation uses the snapshot. The original is never written,
diff --git a/tests/unit/test_web_mode_scope.bats b/tests/unit/test_web_mode_scope.bats
new file mode 100644
index 0000000..57f6b3c
--- /dev/null
+++ b/tests/unit/test_web_mode_scope.bats
@@ -0,0 +1,83 @@
+#!/usr/bin/env bats
+#
+# Regression coverage for issue #1045.
+#
+# prepare_web_mode_scope() picks between two very different behaviours:
+# -l <file> wipe $dir and install the sanitized list as the new scope
+# -d <domain> preserve prior recon state and append the domain via anew
+#
+# It selected on $list, which start() REASSIGNS mid-run: under AXIOM with -d it
+# writes the domain to target.txt and points $list at it. So
+# `reconftw.sh -d example.com -w -v 50` took the -l branch with $flist still
+# empty, `cp "" <tmp>` failed, and the run aborted before webs_menu with
+# "Web mode scope preparation failed (tmpfile/cp error)".
+#
+# $flist is the correct signal: reconftw.sh sets it once at startup and leaves it
+# empty for -d, so it means "the user passed a list" for the whole run. Both
+# directions are pinned — a fix that made -d work by breaking -l is still a
+# regression.
+#
+# ASSERTION STYLE, deliberately: every check is chained into the SINGLE final
+# expression of the test. This runner does not abort a test body on the first
+# failing command, so an assertion written on its own line mid-body is decorative
+# — it prints nothing and changes no verdict. Verified while writing this file:
+# a literal `[ 1 -eq 0 ]` placed at the top of a test still reported `ok`. Keep
+# the chain; do not "tidy" these into separate statements.
+
+setup() {
+ local project_root
+ project_root="$(cd "$(dirname "$BATS_TEST_FILENAME")/../.." && pwd)"
+ export SCRIPTPATH="$project_root"
+ export LOGFILE="/dev/null"
+ export bred='' bblue='' bgreen='' byellow='' yellow='' reset=''
+ cd "$BATS_TEST_TMPDIR"
+ source "$project_root/reconftw.sh" --source-only
+ # reconftw.sh:7 runs `set +e`, which disables errexit in THIS shell. bats needs
+ # errexit to fail a test at the first failing command; without it only the
+ # body's last command decides the verdict and every earlier assertion is
+ # inert. Restore it, or the checks below are decoration.
+ set -e
+}
+
+@test "prepare_web_mode_scope takes the -d path when AXIOM reassigned list (issue #1045)" {
+ export dir="$PWD/example.com"
+ mkdir -p "$dir"
+ export domain="example.com"
+ # Exactly the state start() leaves under AXIOM + -d.
+ export list="$dir/target.txt"
+ export flist=''
+ printf '%s\n' "$domain" > "$list"
+
+ prepare_web_mode_scope \
+ && [ -f "$dir/subdomains/subdomains.txt" ] \
+ && grep -qx "example.com" "$dir/subdomains/subdomains.txt"
+}
+
+@test "prepare_web_mode_scope preserves prior recon state on the -d path" {
+ export dir="$PWD/example.com"
+ mkdir -p "$dir/hosts" "$dir/vulns"
+ printf '203.0.113.7\n' > "$dir/hosts/ips.txt"
+ printf 'prior finding\n' > "$dir/vulns/xss.txt"
+ export domain="example.com"
+ export list="$dir/target.txt"
+ export flist=''
+ printf '%s\n' "$domain" > "$list"
+
+ # The -l path wipes $dir, so taking it here destroys prior -a/-s/-p output.
+ prepare_web_mode_scope \
+ && [ -f "$dir/hosts/ips.txt" ] \
+ && [ -f "$dir/vulns/xss.txt" ]
+}
+
+@test "prepare_web_mode_scope still installs an -l list as the scope" {
+ export dir="$PWD/multi"
+ mkdir -p "$dir"
+ export domain=''
+ export flist="$PWD/targets.txt"
+ printf 'a.example.com\nb.example.com\n' > "$flist"
+ export list="$flist"
+
+ prepare_web_mode_scope \
+ && grep -qx "a.example.com" "$dir/subdomains/subdomains.txt" \
+ && grep -qx "b.example.com" "$dir/subdomains/subdomains.txt"
+}