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

Fixes asn and sub_dns

six2dez360780025e61
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 76679f0..eb0930e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -120,6 +120,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Resolved readonly/re-source issues in script lifecycle.
- Fixed duplicate findings/reporting edge cases.
- Corrected `sub_asn()` behavior to avoid redundant repeated runs.
+- `sub_asn()` now requires `PDCP_API_KEY` before running `asnmap`, logs explicit skip reason when unset, and applies a 120s timeout guard when available.
- Corrected host matching in WAF/slow-host grouping to literal-safe comparisons.
- Parallel group failures now propagate correctly instead of being silently ignored.
diff --git a/README.md b/README.md
index 4158d40..12f3870 100644
--- a/README.md
+++ b/README.md
@@ -357,6 +357,7 @@ cd reconftw
```bash
docker run -it --rm \
-e SHODAN_API_KEY="your-key" \
+ -e PDCP_API_KEY="your-projectdiscovery-key" \
-e COLLAB_SERVER="your-server" \
-e XSS_SERVER="your-server" \
-v "${PWD}/OutputFolder/:/reconftw/Recon/" \
@@ -394,6 +395,7 @@ cd reconftw
- GitHub tokens: `~/Tools/.github_tokens` (one per line)
- GitLab tokens: `~/Tools/.gitlab_tokens` (one per line)
- WHOISXML: set `WHOISXML_API` in `reconftw.cfg` or env var
+- ASN enumeration (`asnmap`): set `PDCP_API_KEY` in env/config (`ASN_ENUM` skips if unset)
- Slack/Discord/Telegram: configure `notify` in `~/.config/notify/provider-config.yaml`
- SSRF server: set `COLLAB_SERVER` env/cfg if used
- Blind XSS server: set `XSS_SERVER` env/cfg if used
@@ -513,6 +515,7 @@ GITLAB_TOKENS=${tools}/.gitlab_tokens
# Environment variables take precedence if set.
SHODAN_API_KEY="${SHODAN_API_KEY:-}"
WHOISXML_API="${WHOISXML_API:-}"
+PDCP_API_KEY="${PDCP_API_KEY:-}"
XSS_SERVER="${XSS_SERVER:-}"
COLLAB_SERVER="${COLLAB_SERVER:-}"
slack_channel="${slack_channel:-}"
diff --git a/modules/core.sh b/modules/core.sh
index 5548087..6e7df57 100644
--- a/modules/core.sh
+++ b/modules/core.sh
@@ -29,6 +29,7 @@ pt_msg_err() { printf "\n%b[%s] %s%b\n" "$bred" "$(date +'%Y-%m-%d %H:%M:%S')" "
REDACT_VARS=(
"SHODAN_API_KEY"
"WHOISXML_API"
+ "PDCP_API_KEY"
"GITHUB_TOKEN"
"GITLAB_TOKEN"
"DISCORD_WEBHOOK_URL"
diff --git a/modules/subdomains.sh b/modules/subdomains.sh
index 4c40ca6..a430ce6 100644
--- a/modules/subdomains.sh
+++ b/modules/subdomains.sh
@@ -273,43 +273,55 @@ _subdomains_enumerate() {
fi
fi
- # Phase 2: Active DNS resolution (parallel)
- parallel_funcs 3 sub_active sub_noerror sub_dns
+ # Phase 2: Active base list (must complete before dependent phases)
+ sub_active
local sub_g2_rc=$?
if ((sub_g2_rc > 0)); then
if [[ "${CONTINUE_ON_TOOL_ERROR:-true}" == "true" ]]; then
- notification "Parallel subdomain active phase completed with ${sub_g2_rc} warning(s); continuing" warn
+ notification "sub_active completed with warning(s); continuing with dependent subdomain phases" warn
else
- notification "Parallel subdomain batch failed (active)" error
+ notification "sub_active failed" error
return 1
fi
fi
- # Phase 3: Post-active (depend on resolved subdomains)
- parallel_funcs 2 sub_tls sub_analytics
+ # Phase 3: Dependent active enrichment (runs after sub_active is ready)
+ parallel_funcs 3 sub_noerror sub_dns
local sub_g3_rc=$?
if ((sub_g3_rc > 0)); then
if [[ "${CONTINUE_ON_TOOL_ERROR:-true}" == "true" ]]; then
- notification "Parallel subdomain post-active phase completed with ${sub_g3_rc} warning(s); continuing" warn
+ notification "Parallel subdomain dependent active phase completed with ${sub_g3_rc} warning(s); continuing" warn
+ else
+ notification "Parallel subdomain batch failed (dependent active)" error
+ return 1
+ fi
+ fi
+
+ # Phase 4: Post-active analysis (depends on active/enrichment results)
+ parallel_funcs 2 sub_tls sub_analytics
+ local sub_g4_rc=$?
+ if ((sub_g4_rc > 0)); then
+ if [[ "${CONTINUE_ON_TOOL_ERROR:-true}" == "true" ]]; then
+ notification "Parallel subdomain post-active phase completed with ${sub_g4_rc} warning(s); continuing" warn
else
notification "Parallel subdomain batch failed (post-active)" error
return 1
fi
fi
- # Phase 4: Brute force (limited parallelism - resource intensive)
+ # Phase 5: Brute force (limited parallelism - resource intensive)
parallel_funcs 2 sub_brute sub_permut sub_regex_permut sub_ia_permut
- local sub_g4_rc=$?
- if ((sub_g4_rc > 0)); then
+ local sub_g5_rc=$?
+ if ((sub_g5_rc > 0)); then
if [[ "${CONTINUE_ON_TOOL_ERROR:-true}" == "true" ]]; then
- notification "Parallel subdomain bruteforce/permutations phase completed with ${sub_g4_rc} warning(s); continuing" warn
+ notification "Parallel subdomain bruteforce/permutations phase completed with ${sub_g5_rc} warning(s); continuing" warn
else
notification "Parallel subdomain batch failed (bruteforce/permutations)" error
return 1
fi
fi
- # Phase 5: Recursive and scraping (sequential - depends on previous results)
+ # Phase 6: Recursive and scraping (sequential - depends on previous results)
sub_recursive_passive
sub_recursive_brute
sub_scraping
@@ -429,40 +441,79 @@ function sub_asn() {
# Discover ASN/CIDR metadata for the current target domain.
if command -v asnmap &>/dev/null; then
- local asn_json
+ local asn_json pdcp_key timeout_tool asn_rc
asn_json=".tmp/asnmap_${domain}.json"
- asnmap -d "$domain" -silent -j 2>>"$LOGFILE" >"$asn_json"
+ pdcp_key="${PDCP_API_KEY:-}"
+ asn_rc=0
+ : >"$asn_json"
- jq -r '.cidr // empty' "$asn_json" | sed '/^$/d' | sort -u >.tmp/asn_cidrs.txt
- jq -r '.as_number // empty' "$asn_json" | sed '/^$/d' | sort -u >.tmp/asn_numbers.txt
+ if [[ -z "${pdcp_key//[[:space:]]/}" ]]; then
+ printf "%b[%s] ASN_ENUM enabled but PDCP_API_KEY is not set. Skipping asnmap ASN enumeration.%b\n" \
+ "$yellow" "$(date +'%Y-%m-%d %H:%M:%S')" "$reset" | tee -a "$LOGFILE"
+ else
+ if command -v timeout >/dev/null 2>&1; then
+ timeout_tool="timeout"
+ elif command -v gtimeout >/dev/null 2>&1; then
+ timeout_tool="gtimeout"
+ else
+ timeout_tool=""
+ printf "%b[%s] timeout/gtimeout not found; running asnmap without timeout guard.%b\n" \
+ "$yellow" "$(date +'%Y-%m-%d %H:%M:%S')" "$reset" | tee -a "$LOGFILE"
+ fi
- if [[ -s .tmp/asn_cidrs.txt ]]; then
- cp .tmp/asn_cidrs.txt hosts/asn_cidrs.txt
- fi
- if [[ -s .tmp/asn_numbers.txt ]]; then
- cp .tmp/asn_numbers.txt hosts/asn_numbers.txt
- fi
+ if [[ -n "$timeout_tool" ]]; then
+ if PDCP_API_KEY="$pdcp_key" "$timeout_tool" 120 asnmap -d "$domain" -silent -j 2>>"$LOGFILE" >"$asn_json"; then
+ asn_rc=0
+ else
+ asn_rc=$?
+ fi
+ else
+ if PDCP_API_KEY="$pdcp_key" asnmap -d "$domain" -silent -j 2>>"$LOGFILE" >"$asn_json"; then
+ asn_rc=0
+ else
+ asn_rc=$?
+ fi
+ fi
+
+ if [[ $asn_rc -eq 0 && -s "$asn_json" ]]; then
+ jq -r '.cidr // empty' "$asn_json" | sed '/^$/d' | sort -u >.tmp/asn_cidrs.txt
+ jq -r '.as_number // empty' "$asn_json" | sed '/^$/d' | sort -u >.tmp/asn_numbers.txt
- local cidr_count asn_count
- cidr_count=$(wc -l <.tmp/asn_cidrs.txt 2>/dev/null | tr -d ' ')
- asn_count=$(wc -l <.tmp/asn_numbers.txt 2>/dev/null | tr -d ' ')
+ if [[ -s .tmp/asn_cidrs.txt ]]; then
+ cp .tmp/asn_cidrs.txt hosts/asn_cidrs.txt
+ fi
+ if [[ -s .tmp/asn_numbers.txt ]]; then
+ cp .tmp/asn_numbers.txt hosts/asn_numbers.txt
+ fi
- printf "%b[%s] ASN enumeration found %s ASNs and %s CIDR ranges%b\n" \
- "$bblue" "$(date +'%Y-%m-%d %H:%M:%S')" "${asn_count:-0}" "${cidr_count:-0}" "$reset"
+ local cidr_count asn_count
+ cidr_count=$(wc -l <.tmp/asn_cidrs.txt 2>/dev/null | tr -d ' ')
+ asn_count=$(wc -l <.tmp/asn_numbers.txt 2>/dev/null | tr -d ' ')
- # Optional: if asnmap yields discovered domains, feed them into subdomain pipeline.
- jq -r '.domains[]? // empty' "$asn_json" \
- | sed '/^$/d' \
- | grep -E '^([a-zA-Z0-9\.\-]+\.)+[a-zA-Z]{1,}$' \
- | grep "\.${DOMAIN_ESCAPED}$\|^${DOMAIN_ESCAPED}$" \
- | sort -u \
- | anew -q .tmp/subs_no_resolved.txt
- if [[ -s .tmp/subs_no_resolved.txt ]]; then
- printf "%b[%s] ASN sources added %s in-scope domains%b\n" \
- "$bblue" "$(date +'%Y-%m-%d %H:%M:%S')" "$(wc -l <.tmp/subs_no_resolved.txt | tr -d ' ')" "$reset"
+ printf "%b[%s] ASN enumeration found %s ASNs and %s CIDR ranges%b\n" \
+ "$bblue" "$(date +'%Y-%m-%d %H:%M:%S')" "${asn_count:-0}" "${cidr_count:-0}" "$reset"
+
+ # Optional: if asnmap yields discovered domains, feed them into subdomain pipeline.
+ jq -r '.domains[]? // empty' "$asn_json" \
+ | sed '/^$/d' \
+ | grep -E '^([a-zA-Z0-9\.\-]+\.)+[a-zA-Z]{1,}$' \
+ | grep "\.${DOMAIN_ESCAPED}$\|^${DOMAIN_ESCAPED}$" \
+ | sort -u \
+ | anew -q .tmp/subs_no_resolved.txt
+ if [[ -s .tmp/subs_no_resolved.txt ]]; then
+ printf "%b[%s] ASN sources added %s in-scope domains%b\n" \
+ "$bblue" "$(date +'%Y-%m-%d %H:%M:%S')" "$(wc -l <.tmp/subs_no_resolved.txt | tr -d ' ')" "$reset"
+ fi
+ elif [[ $asn_rc -eq 124 ]]; then
+ printf "%b[%s] asnmap timed out after 120s. Skipping ASN output for %s.%b\n" \
+ "$yellow" "$(date +'%Y-%m-%d %H:%M:%S')" "$domain" "$reset" | tee -a "$LOGFILE"
+ else
+ printf "%b[%s] asnmap failed (exit %s). Skipping ASN output for %s.%b\n" \
+ "$yellow" "$(date +'%Y-%m-%d %H:%M:%S')" "${asn_rc:-1}" "$domain" "$reset" | tee -a "$LOGFILE"
+ fi
fi
else
- printf "%b[!] asnmap not installed, skipping ASN enumeration%b\n" "$bred" "$reset"
+ printf "%b[!] asnmap not installed, skipping ASN enumeration%b\n" "$bred" "$reset" | tee -a "$LOGFILE"
fi
end_subfunc "${FUNCNAME[0]}" "${FUNCNAME[0]}"
@@ -869,9 +920,14 @@ function sub_dns() {
fi
fi
- cut -d ' ' -f3 subdomains/subdomains_ips.txt \
- | grep -aEiv "^(127|10|169\.254|172\.1[6-9]|172\.2[0-9]|172\.3[0-1]|192\.168)\." \
- | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b" | sort -u | anew -q hosts/ips.txt
+ if [[ -s "subdomains/subdomains_ips.txt" ]]; then
+ cut -d ' ' -f3 subdomains/subdomains_ips.txt \
+ | grep -aEiv "^(127|10|169\.254|172\.1[6-9]|172\.2[0-9]|172\.3[0-1]|192\.168)\." \
+ | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b" | sort -u | anew -q hosts/ips.txt
+ else
+ printf "%b[%s] No DNS IP pairs found in sub_dns; skipping hosts/ips enrichment.%b\n" \
+ "$yellow" "$(date +'%Y-%m-%d %H:%M:%S')" "$reset" | tee -a "$LOGFILE"
+ fi
if [[ $INSCOPE == true ]]; then
if ! check_inscope .tmp/subdomains_dns_resolved.txt 2>>"$LOGFILE" >/dev/null; then
@@ -879,11 +935,17 @@ function sub_dns() {
fi
fi
- if ! NUMOFLINES=$(grep "\.${DOMAIN_ESCAPED}$\|^${DOMAIN_ESCAPED}$" .tmp/subdomains_dns_resolved.txt 2>>"$LOGFILE" \
- | grep -E '^([a-zA-Z0-9\-\.]+\.)+[a-zA-Z]{1,}$' \
- | anew subdomains/subdomains.txt | sed '/^$/d' | wc -l); then
- printf "%b[!] Failed to count new subdomains.%b\n" "$bred" "$reset"
- return 1
+ if [[ -s ".tmp/subdomains_dns_resolved.txt" ]]; then
+ if ! NUMOFLINES=$(grep "\.${DOMAIN_ESCAPED}$\|^${DOMAIN_ESCAPED}$" .tmp/subdomains_dns_resolved.txt 2>>"$LOGFILE" \
+ | grep -E '^([a-zA-Z0-9\-\.]+\.)+[a-zA-Z]{1,}$' \
+ | anew subdomains/subdomains.txt | sed '/^$/d' | wc -l); then
+ printf "%b[!] Failed to count new subdomains.%b\n" "$bred" "$reset"
+ return 1
+ fi
+ else
+ NUMOFLINES=0
+ printf "%b[%s] No DNS-resolved subdomains produced by sub_dns; continuing.%b\n" \
+ "$yellow" "$(date +'%Y-%m-%d %H:%M:%S')" "$reset" | tee -a "$LOGFILE"
fi
end_subfunc "${NUMOFLINES} new subs (dns resolution)" "${FUNCNAME[0]}"
diff --git a/reconftw.cfg b/reconftw.cfg
index 18bb8c4..79ea434 100644
--- a/reconftw.cfg
+++ b/reconftw.cfg
@@ -84,6 +84,7 @@ GITLAB_TOKENS=${tools}/.gitlab_tokens
# Environment variables take precedence if set.
SHODAN_API_KEY="${SHODAN_API_KEY:-}"
WHOISXML_API="${WHOISXML_API:-}"
+PDCP_API_KEY="${PDCP_API_KEY:-}"
XSS_SERVER="${XSS_SERVER:-}"
COLLAB_SERVER="${COLLAB_SERVER:-}"
slack_channel="${slack_channel:-}"
diff --git a/secrets.cfg.example b/secrets.cfg.example
index 954a057..e0aae8d 100644
--- a/secrets.cfg.example
+++ b/secrets.cfg.example
@@ -10,6 +10,9 @@
# WhoisXML API key for domain/IP lookups
#WHOISXML_API="your_whoisxml_api_key_here"
+# ProjectDiscovery Cloud Platform API key (required for asnmap ASN enumeration)
+#PDCP_API_KEY="your_projectdiscovery_api_key_here"
+
# Blind XSS callback server (e.g., interact.sh, xsshunter)
#XSS_SERVER="your_xss_callback_server"
diff --git a/tests/unit/test_subdomains_asn.bats b/tests/unit/test_subdomains_asn.bats
new file mode 100644
index 0000000..70dea99
--- /dev/null
+++ b/tests/unit/test_subdomains_asn.bats
@@ -0,0 +1,155 @@
+#!/usr/bin/env bats
+
+setup() {
+ local project_root
+ project_root="$(cd "$(dirname "$BATS_TEST_FILENAME")/../.." && pwd)"
+
+ TEST_DIR="$(mktemp -d)"
+ MOCK_BIN="${TEST_DIR}/mockbin"
+ ORIG_PATH="$PATH"
+
+ mkdir -p "$MOCK_BIN"
+ cd "$TEST_DIR" || exit 1
+
+ export tools="${tools:-$HOME/Tools}"
+ export LOGFILE="${TEST_DIR}/test.log"
+ export called_fn_dir="${TEST_DIR}/.called_fn"
+ export SCRIPTPATH="$project_root"
+ export AXIOM=false
+ export NOTIFICATION=false
+ export DIFF=false
+ export ASN_ENUM=true
+ export domain="example.com"
+ export DOMAIN_ESCAPED="example\\.com"
+ export PDCP_API_KEY=""
+ export bred='' bblue='' bgreen='' byellow='' yellow='' reset=''
+
+ touch "$LOGFILE"
+ mkdir -p "$called_fn_dir"
+
+ # shellcheck source=/dev/null
+ source "$project_root/reconftw.cfg" 2>/dev/null || true
+ # shellcheck source=/dev/null
+ source "$project_root/reconftw.sh" --source-only
+
+ PATH="${MOCK_BIN}:$ORIG_PATH"
+ export PATH
+
+ create_mock_anew
+}
+
+teardown() {
+ PATH="$ORIG_PATH"
+ cd /
+ rm -rf "$TEST_DIR"
+}
+
+create_mock_anew() {
+ cat >"${MOCK_BIN}/anew" <<'EOF'
+#!/usr/bin/env bash
+set -euo pipefail
+quiet=false
+if [[ "${1:-}" == "-q" ]]; then
+ quiet=true
+ shift
+fi
+target="${1:-}"
+mkdir -p "$(dirname "$target")"
+touch "$target"
+while IFS= read -r line; do
+ [[ -z "$line" ]] && continue
+ if ! grep -Fxq "$line" "$target"; then
+ echo "$line" >>"$target"
+ if [[ "$quiet" != true ]]; then
+ echo "$line"
+ fi
+ fi
+done
+EOF
+ chmod +x "${MOCK_BIN}/anew"
+}
+
+create_mock_asnmap() {
+ cat >"${MOCK_BIN}/asnmap" <<'EOF'
+#!/usr/bin/env bash
+set -euo pipefail
+calls_file="${ASNMAP_MOCK_CALLS:-/tmp/asnmap_calls}"
+echo "KEY=${PDCP_API_KEY:-}" >>"$calls_file"
+scenario="${ASNMAP_MOCK_SCENARIO:-success}"
+
+case "$scenario" in
+ success)
+ cat <<'JSON'
+{"cidr":"1.1.1.0/24","as_number":"AS13335","domains":["api.example.com"]}
+JSON
+ ;;
+ timeout)
+ exit 124
+ ;;
+ fail)
+ exit 2
+ ;;
+ *)
+ exit 0
+ ;;
+esac
+EOF
+ chmod +x "${MOCK_BIN}/asnmap"
+}
+
+@test "sub_asn skips ASN enumeration when PDCP_API_KEY is unset and logs it" {
+ create_mock_asnmap
+ export ASNMAP_MOCK_CALLS="${TEST_DIR}/asnmap_calls.log"
+ export PDCP_API_KEY=""
+
+ run sub_asn
+
+ [ "$status" -eq 0 ]
+ [[ "$output" == *"PDCP_API_KEY is not set"* ]]
+ grep -q "PDCP_API_KEY is not set" "$LOGFILE"
+ [ ! -s "$ASNMAP_MOCK_CALLS" ]
+}
+
+@test "sub_asn runs asnmap with PDCP_API_KEY and writes ASN outputs" {
+ create_mock_asnmap
+ export ASNMAP_MOCK_CALLS="${TEST_DIR}/asnmap_calls.log"
+ export ASNMAP_MOCK_SCENARIO="success"
+ export PDCP_API_KEY="pdcp_test_key"
+
+ run sub_asn
+
+ [ "$status" -eq 0 ]
+ [ -s "hosts/asn_cidrs.txt" ]
+ [ -s "hosts/asn_numbers.txt" ]
+ grep -q "1.1.1.0/24" "hosts/asn_cidrs.txt"
+ grep -q "AS13335" "hosts/asn_numbers.txt"
+ grep -q "KEY=pdcp_test_key" "$ASNMAP_MOCK_CALLS"
+}
+
+@test "sub_asn handles asnmap timeout and logs warning" {
+ create_mock_asnmap
+ export ASNMAP_MOCK_CALLS="${TEST_DIR}/asnmap_calls.log"
+ export ASNMAP_MOCK_SCENARIO="timeout"
+ export PDCP_API_KEY="pdcp_test_key"
+
+ run sub_asn
+
+ [ "$status" -eq 0 ]
+ [[ "$output" == *"timed out after 120s"* ]]
+ grep -q "timed out after 120s" "$LOGFILE"
+ [ ! -s "hosts/asn_cidrs.txt" ]
+ [ ! -s "hosts/asn_numbers.txt" ]
+}
+
+@test "sub_asn skips when asnmap is not installed and logs it" {
+ PATH="/usr/bin:/bin:${MOCK_BIN}"
+ export PATH
+ export PDCP_API_KEY="pdcp_test_key"
+ rm -f "${MOCK_BIN}/asnmap"
+
+ run sub_asn
+
+ [ "$status" -eq 0 ]
+ [[ "$output" == *"asnmap not installed"* ]]
+ grep -q "asnmap not installed" "$LOGFILE"
+}