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

refactor: Phase 1-3 - security fixes, common utils, parallelization

six2dez85e231f59423
diff --git a/.gitignore b/.gitignore
index 674a330..e8a4cd0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -14,3 +14,4 @@ test/
reconftw.cfg-personal
secrets.cfg
.env.cache/
+documentation/
diff --git a/lib/common.sh b/lib/common.sh
new file mode 100644
index 0000000..879bf15
--- /dev/null
+++ b/lib/common.sh
@@ -0,0 +1,231 @@
+#!/usr/bin/env bash
+# lib/common.sh - Common utility functions to reduce code duplication
+# Part of reconFTW refactoring - Phase 2
+
+# Prevent multiple sourcing
+[[ -n "$_COMMON_SH_LOADED" ]] && return 0
+declare -r _COMMON_SH_LOADED=1
+
+###############################################################################
+# Directory Management
+###############################################################################
+
+# Create directories with error handling
+# Usage: ensure_dirs dir1 [dir2 ...]
+# Returns: 0 on success, 1 on failure
+ensure_dirs() {
+ if [[ $# -eq 0 ]]; then
+ return 0
+ fi
+ if ! mkdir -p "$@" 2>/dev/null; then
+ printf "%b[!] Failed to create directories: %s%b\n" "${bred:-}" "$*" "${reset:-}" >&2
+ return 1
+ fi
+ return 0
+}
+
+# Create standard reconftw working directories
+# Usage: ensure_workdirs
+ensure_workdirs() {
+ ensure_dirs .tmp webs subdomains hosts vulns osint fuzzing js screenshots
+}
+
+###############################################################################
+# File Operations
+###############################################################################
+
+# Safely backup a file if it exists and has content
+# Usage: safe_backup source [destination]
+# Default destination: .tmp/$(basename source).bak
+safe_backup() {
+ local src="$1"
+ local dst="${2:-.tmp/$(basename "$1").bak}"
+ if [[ -s "$src" ]]; then
+ cp "$src" "$dst" 2>/dev/null || return 1
+ fi
+ return 0
+}
+
+# Append unique lines to a file using anew (falls back to cat if anew unavailable)
+# Usage: dedupe_append filename
+# Reads from stdin
+dedupe_append() {
+ local file="$1"
+ if command -v anew &>/dev/null; then
+ anew -q "$file" 2>/dev/null
+ else
+ # Fallback: simple append (no dedup)
+ cat >> "$file"
+ fi
+}
+
+# Count non-empty lines in a file safely
+# Usage: count_lines filename
+# Returns: line count (0 if file doesn't exist or is empty)
+count_lines() {
+ local file="$1"
+ if [[ -s "$file" ]]; then
+ sed '/^$/d' "$file" | wc -l | tr -d ' '
+ else
+ echo 0
+ fi
+}
+
+# Count lines from stdin, with fallback to 0 on failure
+# Usage: result=$(command | count_lines_stdin)
+count_lines_stdin() {
+ local count
+ count=$(sed '/^$/d' | wc -l | tr -d ' ') || count=0
+ echo "${count:-0}"
+}
+
+###############################################################################
+# Notifications
+###############################################################################
+
+# Show skip notification for disabled/already-processed functions
+# Usage: skip_notification reason
+# reason: "disabled" | "processed" | custom message
+skip_notification() {
+ local func_name="${FUNCNAME[1]:-unknown}"
+ local reason="${1:-mode or configuration settings}"
+ local checkpoint_hint=""
+
+ case "$reason" in
+ disabled)
+ reason="mode or configuration settings"
+ ;;
+ processed)
+ reason="already processed"
+ checkpoint_hint="\n To force re-run, delete: ${called_fn_dir:-.}/.${func_name}"
+ ;;
+ esac
+
+ printf "\n%b[%s] %s skipped: %s%b${checkpoint_hint}\n" \
+ "${yellow:-}" \
+ "$(date +'%Y-%m-%d %H:%M:%S')" \
+ "$func_name" \
+ "$reason" \
+ "${reset:-}"
+}
+
+# Wrapper for skip notification when function is disabled
+# Usage: skip_if_disabled && return
+skip_if_disabled() {
+ skip_notification "disabled"
+}
+
+# Wrapper for skip notification when function was already processed
+# Usage: skip_if_processed && return
+skip_if_processed() {
+ skip_notification "processed"
+}
+
+###############################################################################
+# Command Execution Helpers
+###############################################################################
+
+# Execute a command with optional dry-run support and logging
+# Usage: run_tool tool_name command [args...]
+# Respects DRY_RUN and LOGFILE variables
+run_tool() {
+ local name="$1"
+ shift
+
+ if [[ ${DRY_RUN:-false} == true ]]; then
+ printf "%b[DRY-RUN] Would execute: %s %s%b\n" "${cyan:-}" "$name" "$*" "${reset:-}"
+ return 0
+ fi
+
+ # Log the command if LOGFILE is set
+ if [[ -n "${LOGFILE:-}" ]]; then
+ echo "[$(date +'%Y-%m-%d %H:%M:%S')] Running: $name $*" >> "$LOGFILE"
+ fi
+
+ "$@"
+}
+
+# Execute command and capture line count result with validation
+# Usage: NUMOFLINES=$(safe_count "command | pipeline")
+# Always returns a valid number (0 on failure)
+safe_count() {
+ local result
+ result=$(eval "$1" 2>/dev/null | sed '/^$/d' | wc -l | tr -d ' ') || result=0
+ [[ "$result" =~ ^[0-9]+$ ]] || result=0
+ echo "$result"
+}
+
+###############################################################################
+# Pipeline Helpers
+###############################################################################
+
+# Process results: deduplicate, count new entries, and return count
+# Usage: NUMOFLINES=$(process_results input_file output_file)
+process_results() {
+ local input="$1"
+ local output="$2"
+ local count=0
+
+ if [[ -s "$input" ]]; then
+ if command -v anew &>/dev/null; then
+ count=$(anew "$output" < "$input" 2>/dev/null | sed '/^$/d' | wc -l | tr -d ' ')
+ else
+ count=$(cat "$input" >> "$output" && wc -l < "$input" | tr -d ' ')
+ fi
+ fi
+
+ [[ "$count" =~ ^[0-9]+$ ]] || count=0
+ echo "$count"
+}
+
+# Filter results by domain and process
+# Usage: NUMOFLINES=$(filter_and_process input_file output_file domain)
+filter_and_process() {
+ local input="$1"
+ local output="$2"
+ local domain="$3"
+ local count=0
+
+ if [[ -s "$input" ]]; then
+ count=$(grep "\\.${domain}$\\|^${domain}$" "$input" 2>/dev/null \
+ | anew "$output" 2>/dev/null \
+ | sed '/^$/d' \
+ | wc -l | tr -d ' ')
+ fi
+
+ [[ "$count" =~ ^[0-9]+$ ]] || count=0
+ echo "$count"
+}
+
+###############################################################################
+# Validation Helpers
+###############################################################################
+
+# Check if we should run a function (not already processed or DIFF mode)
+# Usage: if should_run_function; then ... fi
+should_run_function() {
+ local func_name="${FUNCNAME[1]:-unknown}"
+ local checkpoint_file="${called_fn_dir:-.}/.${func_name}"
+
+ # Run if checkpoint doesn't exist or we're in DIFF mode
+ [[ ! -f "$checkpoint_file" ]] || [[ ${DIFF:-false} == true ]]
+}
+
+# Standard function gate check - combines enabled check with checkpoint
+# Usage: if ! gate_function ENABLED_VAR; then skip_notification "disabled"; return; fi
+gate_function() {
+ local enabled_var="$1"
+ local func_name="${FUNCNAME[1]:-unknown}"
+
+ # Check if the feature is enabled
+ if [[ "${!enabled_var:-false}" != true ]]; then
+ return 1
+ fi
+
+ # Check if already processed (unless DIFF mode)
+ if ! should_run_function; then
+ return 1
+ fi
+
+ return 0
+}
diff --git a/lib/parallel.sh b/lib/parallel.sh
new file mode 100644
index 0000000..cea0847
--- /dev/null
+++ b/lib/parallel.sh
@@ -0,0 +1,340 @@
+#!/usr/bin/env bash
+# lib/parallel.sh - Parallel execution utilities for reconFTW
+# Part of reconFTW refactoring - Phase 3
+
+# Prevent multiple sourcing
+[[ -n "$_PARALLEL_SH_LOADED" ]] && return 0
+declare -r _PARALLEL_SH_LOADED=1
+
+###############################################################################
+# Configuration
+###############################################################################
+
+# Default maximum concurrent jobs (can be overridden)
+PARALLEL_MAX_JOBS="${PARALLEL_MAX_JOBS:-4}"
+
+# Track running PIDs for cleanup
+declare -a _PARALLEL_PIDS=()
+
+###############################################################################
+# Core Parallel Execution
+###############################################################################
+
+# Run multiple commands in parallel with a job limit
+# Usage: parallel_run max_jobs "cmd1" "cmd2" "cmd3" ...
+# Example: parallel_run 4 "subfinder -d $domain" "amass enum -d $domain"
+parallel_run() {
+ local max_jobs="${1:-$PARALLEL_MAX_JOBS}"
+ shift
+
+ local -a pids=()
+ local cmd
+ local running=0
+
+ for cmd in "$@"; do
+ # Start command in background
+ eval "$cmd" &
+ pids+=($!)
+ ((running++))
+
+ # If we've reached max jobs, wait for one to finish
+ if ((running >= max_jobs)); then
+ wait -n 2>/dev/null || true
+ ((running--))
+ fi
+ done
+
+ # Wait for all remaining jobs
+ wait "${pids[@]}" 2>/dev/null
+}
+
+# Run multiple functions in parallel with a job limit
+# Usage: parallel_funcs max_jobs func1 func2 func3 ...
+# Example: parallel_funcs 4 sub_passive sub_crt sub_active
+parallel_funcs() {
+ local max_jobs="${1:-$PARALLEL_MAX_JOBS}"
+ shift
+
+ local -a pids=()
+ local func
+ local running=0
+
+ for func in "$@"; do
+ # Check if function exists
+ if ! declare -f "$func" >/dev/null 2>&1; then
+ printf "%b[!] Function %s not found, skipping%b\n" "${yellow:-}" "$func" "${reset:-}" >&2
+ continue
+ fi
+
+ # Run function in background subshell
+ ( "$func" ) &
+ pids+=($!)
+ ((running++))
+
+ # Log if verbose
+ [[ ${VERBOSE:-false} == true ]] && \
+ printf "%b[*] Started %s (PID: %d)%b\n" "${cyan:-}" "$func" "${pids[-1]}" "${reset:-}"
+
+ # If we've reached max jobs, wait for one to finish
+ if ((running >= max_jobs)); then
+ wait -n 2>/dev/null || true
+ ((running--))
+ fi
+ done
+
+ # Wait for all remaining jobs and collect exit codes
+ local failed=0
+ for pid in "${pids[@]}"; do
+ if ! wait "$pid" 2>/dev/null; then
+ ((failed++))
+ fi
+ done
+
+ return $failed
+}
+
+# Run functions in groups (batch parallelization)
+# Usage: parallel_batch group_size func1 func2 func3 ...
+# Example: parallel_batch 3 func1 func2 func3 func4 func5
+# Runs func1,func2,func3 in parallel, waits, then func4,func5
+parallel_batch() {
+ local batch_size="${1:-3}"
+ shift
+
+ local -a batch=()
+ local func
+
+ for func in "$@"; do
+ batch+=("$func")
+
+ if ((${#batch[@]} >= batch_size)); then
+ parallel_funcs "$batch_size" "${batch[@]}"
+ batch=()
+ fi
+ done
+
+ # Run remaining functions
+ if ((${#batch[@]} > 0)); then
+ parallel_funcs "${#batch[@]}" "${batch[@]}"
+ fi
+}
+
+###############################################################################
+# Job Control Helpers
+###############################################################################
+
+# Wait for all background jobs with timeout
+# Usage: wait_for_jobs [timeout_seconds]
+wait_for_jobs() {
+ local timeout="${1:-0}"
+ local start_time=$(date +%s)
+
+ while jobs -p | grep -q .; do
+ if ((timeout > 0)); then
+ local elapsed=$(($(date +%s) - start_time))
+ if ((elapsed >= timeout)); then
+ printf "%b[!] Timeout reached, killing remaining jobs%b\n" "${bred:-}" "${reset:-}" >&2
+ jobs -p | xargs -r kill 2>/dev/null || true
+ return 1
+ fi
+ fi
+ sleep 1
+ done
+
+ return 0
+}
+
+# Get count of running background jobs
+# Usage: running_jobs=$(get_running_jobs)
+get_running_jobs() {
+ jobs -p | wc -l | tr -d ' '
+}
+
+# Kill all tracked parallel jobs (for cleanup)
+# Usage: cleanup_parallel_jobs
+cleanup_parallel_jobs() {
+ local pid
+ for pid in "${_PARALLEL_PIDS[@]}"; do
+ if kill -0 "$pid" 2>/dev/null; then
+ kill "$pid" 2>/dev/null || true
+ fi
+ done
+ _PARALLEL_PIDS=()
+}
+
+###############################################################################
+# Subdomain Enumeration Parallelization
+###############################################################################
+
+# Run passive subdomain enumeration in parallel
+# Usage: parallel_passive_enum
+# Runs: sub_passive, sub_crt, sub_tls, sub_analytics in parallel
+parallel_passive_enum() {
+ local funcs=(
+ "sub_passive"
+ "sub_crt"
+ "sub_tls"
+ "sub_analytics"
+ )
+
+ printf "%b[*] Running passive enumeration in parallel (%d functions)%b\n" \
+ "${bblue:-}" "${#funcs[@]}" "${reset:-}"
+
+ parallel_funcs 4 "${funcs[@]}"
+}
+
+# Run active subdomain enumeration in parallel
+# Usage: parallel_active_enum
+# Runs: sub_active, sub_noerror, sub_dns in parallel
+parallel_active_enum() {
+ local funcs=(
+ "sub_active"
+ "sub_noerror"
+ "sub_dns"
+ )
+
+ printf "%b[*] Running active enumeration in parallel (%d functions)%b\n" \
+ "${bblue:-}" "${#funcs[@]}" "${reset:-}"
+
+ parallel_funcs 3 "${funcs[@]}"
+}
+
+# Run brute force enumeration (typically sequential due to resource usage)
+# Usage: parallel_brute_enum
+parallel_brute_enum() {
+ local funcs=(
+ "sub_brute"
+ "sub_permut"
+ "sub_regex_permut"
+ )
+
+ # Brute force is resource intensive, run with limit of 2
+ printf "%b[*] Running brute force enumeration (limited parallelism)%b\n" \
+ "${bblue:-}" "${reset:-}"
+
+ parallel_funcs 2 "${funcs[@]}"
+}
+
+###############################################################################
+# Vulnerability Scanning Parallelization
+###############################################################################
+
+# Run web vulnerability checks in parallel
+# Usage: parallel_web_vulns
+parallel_web_vulns() {
+ local funcs=(
+ "cors"
+ "open_redirect"
+ "crlf_checks"
+ "xss"
+ )
+
+ printf "%b[*] Running web vulnerability checks in parallel (%d checks)%b\n" \
+ "${bblue:-}" "${#funcs[@]}" "${reset:-}"
+
+ parallel_funcs 4 "${funcs[@]}"
+}
+
+# Run injection vulnerability checks in parallel
+# Usage: parallel_injection_vulns
+parallel_injection_vulns() {
+ local funcs=(
+ "sqli"
+ "ssti"
+ "lfi"
+ "command_injection"
+ )
+
+ printf "%b[*] Running injection vulnerability checks in parallel (%d checks)%b\n" \
+ "${bblue:-}" "${#funcs[@]}" "${reset:-}"
+
+ parallel_funcs 4 "${funcs[@]}"
+}
+
+# Run server-side vulnerability checks in parallel
+# Usage: parallel_server_vulns
+parallel_server_vulns() {
+ local funcs=(
+ "ssrf_checks"
+ "prototype_pollution"
+ "smuggling"
+ )
+
+ printf "%b[*] Running server-side vulnerability checks in parallel (%d checks)%b\n" \
+ "${bblue:-}" "${#funcs[@]}" "${reset:-}"
+
+ parallel_funcs 3 "${funcs[@]}"
+}
+
+###############################################################################
+# OSINT Parallelization
+###############################################################################
+
+# Run OSINT gathering in parallel
+# Usage: parallel_osint
+parallel_osint() {
+ local funcs=(
+ "google_dorks"
+ "github_dorks"
+ "metadata"
+ "emails"
+ "domain_info"
+ )
+
+ printf "%b[*] Running OSINT gathering in parallel (%d sources)%b\n" \
+ "${bblue:-}" "${#funcs[@]}" "${reset:-}"
+
+ parallel_funcs 4 "${funcs[@]}"
+}
+
+###############################################################################
+# Full Pipeline Parallelization
+###############################################################################
+
+# Orchestrate full subdomain enumeration with parallelization
+# Usage: parallel_subdomains_full
+# This replaces the sequential execution in subdomains_full()
+parallel_subdomains_full() {
+ printf "%b[*] Starting parallelized subdomain enumeration%b\n" \
+ "${bblue:-}" "${reset:-}"
+
+ # Phase 1: Passive enumeration (all parallel)
+ parallel_passive_enum
+
+ # Merge passive results before active phase
+ [[ -s ".tmp/passive_subs.txt" ]] && cat .tmp/passive_subs.txt | anew -q subdomains/subdomains.txt
+ [[ -s ".tmp/crtsh_subs.txt" ]] && cat .tmp/crtsh_subs.txt | anew -q subdomains/subdomains.txt
+
+ # Phase 2: Active enumeration (parallel)
+ parallel_active_enum
+
+ # Phase 3: Brute force (limited parallel due to resource usage)
+ if [[ ${SUBBRUTE:-false} == true ]] || [[ ${SUBPERMUTE:-false} == true ]]; then
+ parallel_brute_enum
+ fi
+
+ # Phase 4: Scraping and recursive (sequential - depends on previous results)
+ [[ ${SUBSCRAPING:-false} == true ]] && sub_scraping
+ [[ ${SUB_RECURSIVE_BRUTE:-false} == true ]] && sub_recursive_brute
+
+ printf "%b[*] Parallelized subdomain enumeration complete%b\n" \
+ "${bgreen:-}" "${reset:-}"
+}
+
+# Orchestrate full vulnerability scanning with parallelization
+# Usage: parallel_vulns_full
+parallel_vulns_full() {
+ printf "%b[*] Starting parallelized vulnerability scanning%b\n" \
+ "${bblue:-}" "${reset:-}"
+
+ # Run nuclei first (it's comprehensive)
+ nuclei_check
+
+ # Then run other checks in parallel batches
+ parallel_web_vulns
+ parallel_injection_vulns
+ parallel_server_vulns
+
+ printf "%b[*] Parallelized vulnerability scanning complete%b\n" \
+ "${bgreen:-}" "${reset:-}"
+}
diff --git a/modules/core.sh b/modules/core.sh
index 83f0901..2d9a178 100644
--- a/modules/core.sh
+++ b/modules/core.sh
@@ -671,7 +671,7 @@ function zipSnedOutputFolder {
function isAsciiText {
# shellcheck disable=SC2034 # IS_ASCII used by callers
IS_ASCII="False"
- if [[ $(file $1 | grep -o 'ASCII text$') == "ASCII text" ]]; then
+ if [[ $(file "$1" | grep -o 'ASCII text$') == "ASCII text" ]]; then
IS_ASCII="True"
else
IS_ASCII="False"
diff --git a/modules/modes.sh b/modules/modes.sh
index 4eb056c..4bf9fa4 100644
--- a/modules/modes.sh
+++ b/modules/modes.sh
@@ -127,7 +127,7 @@ function end() {
if [[ $opt_ai ]]; then
notification "[$(date +'%Y-%m-%d %H:%M:%S')] Sending ${domain} data to AI" info
mkdir -p "${dir}/ai_result" 2>>"${LOGFILE}"
- "${tools}/reconftw_ai/venv/bin/python3" "${tools}/reconftw_ai/reconftw_ai.py" --results-dir ${dir} --output-dir ${dir}/ai_result --model ${AI_MODEL} --output-format ${AI_REPORT_TYPE} --report-type ${AI_REPORT_PROFILE} --prompts-file ${tools}/reconftw_ai/prompts.json 2>>"${LOGFILE}" >/dev/null
+ "${tools}/reconftw_ai/venv/bin/python3" "${tools}/reconftw_ai/reconftw_ai.py" --results-dir "${dir}" --output-dir "${dir}/ai_result" --model "${AI_MODEL}" --output-format "${AI_REPORT_TYPE}" --report-type "${AI_REPORT_PROFILE}" --prompts-file "${tools}/reconftw_ai/prompts.json" 2>>"${LOGFILE}" >/dev/null
fi
find "$dir" -type f -empty -print | grep -v '.called_fn' | grep -v '.log' | grep -v '.tmp' | xargs -r rm -f -- 2>>"$LOGFILE" >/dev/null
diff --git a/modules/osint.sh b/modules/osint.sh
index 06d3cfb..3e6856e 100644
--- a/modules/osint.sh
+++ b/modules/osint.sh
@@ -15,7 +15,7 @@
###############################################################################################################
function google_dorks() {
- mkdir -p osint
+ ensure_dirs osint
if { [[ ! -f "$called_fn_dir/.${FUNCNAME[0]}" ]] || [[ $DIFF == true ]]; } && [[ $GOOGLE_DORKS == true ]] && [[ $OSINT == true ]]; then
start_func "${FUNCNAME[0]}" "Running: Google Dorks in process"
@@ -24,15 +24,15 @@ function google_dorks() {
end_func "Results are saved in $domain/osint/dorks.txt" "${FUNCNAME[0]}"
else
if [[ $GOOGLE_DORKS == false ]] || [[ $OSINT == false ]]; then
- printf "\n%b[%s] %s skipped due to mode or configuration settings.%b\n" "$yellow" "$(date +'%Y-%m-%d %H:%M:%S')" "${FUNCNAME[0]}" "$reset"
+ skip_notification "disabled"
else
- printf "%b[%s] %s has already been processed. To force execution, delete:\n %s/.%s %b\n\n" "$yellow" "$(date +'%Y-%m-%d %H:%M:%S')" "${FUNCNAME[0]}" "$called_fn_dir" "${FUNCNAME[0]}" "$reset"
+ skip_notification "processed"
fi
fi
}
function github_dorks() {
- mkdir -p osint
+ ensure_dirs osint
if { [[ ! -f "$called_fn_dir/.${FUNCNAME[0]}" ]] || [[ $DIFF == true ]]; } && [[ $GITHUB_DORKS == true ]] && [[ $OSINT == true ]]; then
start_func "${FUNCNAME[0]}" "Running: Github Dorks in process"
@@ -56,15 +56,15 @@ function github_dorks() {
end_func "Results are saved in $domain/osint/gitdorks.txt" "${FUNCNAME[0]}"
else
if [[ $GITHUB_DORKS == false ]] || [[ $OSINT == false ]]; then
- printf "\n%b[%s] %s skipped due to mode or configuration settings.%b\n" "$yellow" "$(date +'%Y-%m-%d %H:%M:%S')" "${FUNCNAME[0]}" "$reset"
+ skip_notification "disabled"
else
- printf "%b[%s] %s has already been processed. To force execution, delete:\n %s/.%s %b\n\n" "$yellow" "$(date +'%Y-%m-%d %H:%M:%S')" "${FUNCNAME[0]}" "$called_fn_dir" "${FUNCNAME[0]}" "$reset"
+ skip_notification "processed"
fi
fi
}
function github_repos() {
- mkdir -p osint
+ ensure_dirs osint
if { [[ ! -f "$called_fn_dir/.${FUNCNAME[0]}" ]] || [[ $DIFF == true ]]; } && [[ $GITHUB_REPOS == true ]] && [[ $OSINT == true ]]; then
start_func "${FUNCNAME[0]}" "Github Repos analysis in process"
@@ -83,8 +83,7 @@ function github_repos() {
fi
fi
- mkdir -p .tmp/github_repos 2>>"$LOGFILE"
- mkdir -p .tmp/github 2>>"$LOGFILE"
+ ensure_dirs .tmp/github_repos .tmp/github
if [[ -s ".tmp/company_repos_url.txt" ]]; then
if ! interlace -tL .tmp/company_repos_url.txt -threads "$INTERLACE_THREADS" -c "git clone _target_ .tmp/github_repos/_cleantarget_" 2>>"$LOGFILE" >/dev/null; then
@@ -138,21 +137,21 @@ function github_repos() {
fi
else
if [[ $GITHUB_REPOS == false ]] || [[ $OSINT == false ]]; then
- printf "\n%b[%s] %s skipped due to mode or configuration settings.%b\n" "$yellow" "$(date +'%Y-%m-%d %H:%M:%S')" "${FUNCNAME[0]}" "$reset"
+ skip_notification "disabled"
else
- printf "%b[%s] %s has already been processed. To force execution, delete:\n %s/.%s %b\n\n" "$yellow" "$(date +'%Y-%m-%d %H:%M:%S')" "${FUNCNAME[0]}" "$called_fn_dir" "${FUNCNAME[0]}" "$reset"
+ skip_notification "processed"
fi
fi
}
function metadata() {
- mkdir -p osint
+ ensure_dirs osint
# Check if the function should run
if { [[ ! -f "${called_fn_dir}/.${FUNCNAME[0]}" ]] || [[ ${DIFF} == true ]]; } && [[ ${METADATA} == true ]] && [[ ${OSINT} == true ]] && ! [[ ${domain} =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
start_func "${FUNCNAME[0]}" "Scanning metadata in public files"
- mkdir -p ".tmp/metagoofil_${domain}/" 2>>"${LOGFILE}"
+ ensure_dirs ".tmp/metagoofil_${domain}"
pushd "${tools}/metagoofil" >/dev/null || {
printf "%b[!] Failed to change directory to %s in %s at line %s.%b\n" "${bred}" "${tools}/metagoofil" "${FUNCNAME[0]}" "${LINENO}" "${reset}"
return 1
@@ -168,17 +167,17 @@ function metadata() {
end_func "Results are saved in ${domain}/osint/metadata_results.txt" "${FUNCNAME[0]}"
else
if [[ ${METADATA} == false ]] || [[ ${OSINT} == false ]]; then
- printf "\n%b[%s] %s skipped due to mode or configuration settings.%b\n" "${yellow}" "$(date +'%Y-%m-%d %H:%M:%S')" "${FUNCNAME[0]}" "${reset}"
+ skip_notification "disabled"
elif [[ ${domain} =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
return
else
- printf "%b[%s] %s has already been processed. To force execution, delete:\n %s/.%s %b\n\n" "${yellow}" "$(date +'%Y-%m-%d %H:%M:%S')" "${FUNCNAME[0]}" "${called_fn_dir}" "${FUNCNAME[0]}" "${reset}"
+ skip_notification "processed"
fi
fi
}
function apileaks() {
- mkdir -p osint
+ ensure_dirs osint
# Check if the function should run
if { [[ ! -f "$called_fn_dir/.${FUNCNAME[0]}" ]] || [[ $DIFF == true ]]; } \
@@ -235,7 +234,7 @@ function apileaks() {
}
function emails() {
- mkdir -p .tmp osint
+ ensure_dirs .tmp osint
# Check if the function should run
if { [[ ! -f "$called_fn_dir/.${FUNCNAME[0]}" ]] || [[ $DIFF == true ]]; } \
@@ -285,7 +284,7 @@ function emails() {
function domain_info() {
- mkdir -p osint
+ ensure_dirs osint
# Check if the function should run
if { [[ ! -f "$called_fn_dir/.${FUNCNAME[0]}" ]] || [[ $DIFF == true ]]; } \
@@ -317,7 +316,7 @@ function domain_info() {
}
function third_party_misconfigs() {
- mkdir -p osint
+ ensure_dirs osint
# Check if the function should run
if { [[ ! -f "$called_fn_dir/.${FUNCNAME[0]}" ]] || [[ $DIFF == true ]]; } \
@@ -362,7 +361,7 @@ function third_party_misconfigs() {
}
function spoof() {
- mkdir -p osint
+ ensure_dirs osint
# Check if the function should run
if { [[ ! -f "$called_fn_dir/.${FUNCNAME[0]}" ]] || [[ $DIFF == true ]]; } \
@@ -404,7 +403,7 @@ function spoof() {
}
function mail_hygiene() {
- mkdir -p osint
+ ensure_dirs osint
if { [[ ! -f "$called_fn_dir/.${FUNCNAME[0]}" ]] || [[ $DIFF == true ]]; } \
&& [[ $MAIL_HYGIENE == true ]] && [[ $OSINT == true ]] \
@@ -431,7 +430,7 @@ function mail_hygiene() {
}
function cloud_enum_scan() {
- mkdir -p osint
+ ensure_dirs osint
if { [[ ! -f "$called_fn_dir/.${FUNCNAME[0]}" ]] || [[ $DIFF == true ]]; } \
&& [[ $CLOUD_ENUM == true ]] && [[ $OSINT == true ]] \
@@ -454,7 +453,7 @@ function cloud_enum_scan() {
function ip_info() {
- mkdir -p osint
+ ensure_dirs osint
# Check if the function should run
if { [[ ! -f "$called_fn_dir/.${FUNCNAME[0]}" ]] || [[ $DIFF == true ]]; } \
diff --git a/modules/subdomains.sh b/modules/subdomains.sh
index db7cf00..e01e3c7 100644
--- a/modules/subdomains.sh
+++ b/modules/subdomains.sh
@@ -19,8 +19,7 @@
function subdomains_full() {
# Create necessary directories
- if ! mkdir -p .tmp webs subdomains; then
- printf "%b[!] Failed to create directories.%b\n" "$bred" "$reset"
+ if ! ensure_dirs .tmp webs subdomains; then
return 1
fi
@@ -165,7 +164,7 @@ function subdomains_full() {
function sub_passive() {
- mkdir -p .tmp subdomains
+ ensure_dirs .tmp subdomains
if { [[ ! -f "$called_fn_dir/.${FUNCNAME[0]}" ]] || [[ $DIFF == true ]]; } && [[ $SUBPASSIVE == true ]]; then
start_subfunc "${FUNCNAME[0]}" "Running: Passive Subdomain Enumeration"
@@ -196,7 +195,9 @@ function sub_passive() {
fi
# Combine results and count new lines
- NUMOFLINES=$(find .tmp -type f -iname "*_psub.txt" -exec cat {} + | sed "s/^\*\.//" | anew .tmp/passive_subs.txt | sed '/^$/d' | wc -l)
+ if ! NUMOFLINES=$(find .tmp -type f -iname "*_psub.txt" -exec cat {} + | sed "s/^\*\.//" | anew .tmp/passive_subs.txt | sed '/^$/d' | wc -l); then
+ NUMOFLINES=0
+ fi
end_subfunc "${NUMOFLINES} new subs (passive)" "${FUNCNAME[0]}"
else
@@ -211,7 +212,7 @@ function sub_passive() {
function sub_crt() {
- mkdir -p .tmp subdomains
+ ensure_dirs .tmp subdomains
if { [[ ! -f "$called_fn_dir/.${FUNCNAME[0]}" ]] || [[ $DIFF == true ]]; } && [[ $SUBCRT == true ]]; then
start_subfunc "${FUNCNAME[0]}" "Running: Crtsh Subdomain Enumeration"
@@ -234,7 +235,9 @@ function sub_crt() {
fi
# Process subdomains and append new ones to .tmp/crtsh_subs.txt, count new lines
- NUMOFLINES=$(sed 's/^\*\.//' .tmp/crtsh_subs_tmp.txt | sed '/^$/d' | anew .tmp/crtsh_subs.txt | wc -l)
+ if ! NUMOFLINES=$(sed 's/^\*\.//' .tmp/crtsh_subs_tmp.txt | sed '/^$/d' | anew .tmp/crtsh_subs.txt | wc -l); then
+ NUMOFLINES=0
+ fi
end_subfunc "${NUMOFLINES} new subs (cert transparency)" "${FUNCNAME[0]}"
else
@@ -250,7 +253,7 @@ function sub_crt() {
function sub_active() {
- mkdir -p .tmp subdomains
+ ensure_dirs .tmp subdomains
if [[ ! -f "$called_fn_dir/.${FUNCNAME[0]}" ]] || [[ $DIFF == true ]]; then
start_subfunc "${FUNCNAME[0]}" "Running: Active Subdomain Enumeration"
@@ -334,7 +337,7 @@ function sub_active() {
}
function sub_tls() {
- mkdir -p .tmp subdomains
+ ensure_dirs .tmp subdomains
if [[ ! -f "$called_fn_dir/.${FUNCNAME[0]}" ]] || [[ $DIFF == true ]]; then
start_subfunc "${FUNCNAME[0]}" "Running: TLS Active Subdomain Enumeration"
@@ -415,7 +418,7 @@ function sub_tls() {
function sub_noerror() {
- mkdir -p .tmp subdomains
+ ensure_dirs .tmp subdomains
if { [[ ! -f "$called_fn_dir/.${FUNCNAME[0]}" ]] || [[ $DIFF == true ]]; } && [[ $SUBNOERROR == true ]]; then
start_subfunc "${FUNCNAME[0]}" "Running: Checking NOERROR DNS response"
@@ -479,7 +482,7 @@ function sub_noerror() {
}
function sub_dns() {
- mkdir -p .tmp subdomains hosts
+ ensure_dirs .tmp subdomains hosts
if [[ ! -f "$called_fn_dir/.${FUNCNAME[0]}" ]] || [[ $DIFF == true ]]; then
start_subfunc "${FUNCNAME[0]}" "Running: DNS Subdomain Enumeration and PTR search"
@@ -561,7 +564,7 @@ function sub_dns() {
function sub_brute() {
- mkdir -p .tmp subdomains
+ ensure_dirs .tmp subdomains
if { [[ ! -f "$called_fn_dir/.${FUNCNAME[0]}" ]] || [[ $DIFF == true ]]; } && [[ $SUBBRUTE == true ]]; then
start_subfunc "${FUNCNAME[0]}" "Running: Bruteforce Subdomain Enumeration"
@@ -606,8 +609,8 @@ function sub_brute() {
# Resolve the subdomains using axiom-scan
if [[ -s ".tmp/subs_brute.txt" ]]; then
- axiom-scan .tmp/subs_brute.txt -m puredns-resolve -r ${AXIOM_RESOLVERS_PATH} \
- --resolvers-trusted ${AXIOM_RESOLVERS_TRUSTED_PATH} \
+ axiom-scan .tmp/subs_brute.txt -m puredns-resolve -r "${AXIOM_RESOLVERS_PATH}" \
+ --resolvers-trusted "${AXIOM_RESOLVERS_TRUSTED_PATH}" \
--wildcard-tests "$PUREDNS_WILDCARDTEST_LIMIT" --wildcard-batch "$PUREDNS_WILDCARDBATCH_LIMIT" \
-o .tmp/subs_brute_valid.txt "$AXIOM_EXTRA_ARGS" 2>>"$LOGFILE" >/dev/null
fi
@@ -647,8 +650,7 @@ function sub_brute() {
function sub_scraping() {
# Create necessary directories
- if ! mkdir -p .tmp subdomains; then
- printf "%b[!] Failed to create directories.%b\n" "$bred" "$reset"
+ if ! ensure_dirs .tmp subdomains; then
return 1
fi
@@ -904,7 +906,7 @@ function sub_analytics() {
function sub_permut() {
- mkdir -p .tmp subdomains
+ ensure_dirs .tmp subdomains
if { [[ ! -f "$called_fn_dir/.${FUNCNAME[0]}" ]] || [[ $DIFF == true ]]; } && [[ $SUBPERMUTE == true ]]; then
start_subfunc "${FUNCNAME[0]}" "Running: Permutations Subdomain Enumeration"
@@ -970,10 +972,10 @@ function sub_permut() {
return 1
fi
if [[ -s ".tmp/gotator1.txt" ]]; then
- axiom-scan .tmp/gotator1.txt -m puredns-resolve -r ${AXIOM_RESOLVERS_PATH} \
- --resolvers-trusted ${AXIOM_RESOLVERS_TRUSTED_PATH} \
+ axiom-scan .tmp/gotator1.txt -m puredns-resolve -r "${AXIOM_RESOLVERS_PATH}" \
+ --resolvers-trusted "${AXIOM_RESOLVERS_TRUSTED_PATH}" \
--wildcard-tests "$PUREDNS_WILDCARDTEST_LIMIT" --wildcard-batch "$PUREDNS_WILDCARDBATCH_LIMIT" \
- -o .tmp/permute1.txt $AXIOM_EXTRA_ARGS 2>>"$LOGFILE" >/dev/null
+ -o .tmp/permute1.txt "$AXIOM_EXTRA_ARGS" 2>>"$LOGFILE" >/dev/null
fi
fi
@@ -1000,10 +1002,10 @@ function sub_permut() {
fi
else
if [[ -s ".tmp/gotator2.txt" ]]; then
- axiom-scan .tmp/gotator2.txt -m puredns-resolve -r ${AXIOM_RESOLVERS_PATH} \
- --resolvers-trusted ${AXIOM_RESOLVERS_TRUSTED_PATH} \
+ axiom-scan .tmp/gotator2.txt -m puredns-resolve -r "${AXIOM_RESOLVERS_PATH}" \
+ --resolvers-trusted "${AXIOM_RESOLVERS_TRUSTED_PATH}" \
--wildcard-tests "$PUREDNS_WILDCARDTEST_LIMIT" --wildcard-batch "$PUREDNS_WILDCARDBATCH_LIMIT" \
- -o .tmp/permute2.txt $AXIOM_EXTRA_ARGS 2>>"$LOGFILE" >/dev/null
+ -o .tmp/permute2.txt "$AXIOM_EXTRA_ARGS" 2>>"$LOGFILE" >/dev/null
fi
fi
@@ -1832,7 +1834,7 @@ function s3buckets() {
}
function cloud_extra_providers() {
- mkdir -p subdomains .tmp
+ ensure_dirs subdomains .tmp
if { [[ ! -f "$called_fn_dir/.${FUNCNAME[0]}" ]] || [[ $DIFF == true ]]; } && ! [[ $domain =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
start_func "${FUNCNAME[0]}" "Extra cloud providers checks"
diff --git a/modules/vulns.sh b/modules/vulns.sh
index 5ec01e1..889b7a7 100644
--- a/modules/vulns.sh
+++ b/modules/vulns.sh
@@ -13,10 +13,7 @@
function xss() {
# Create necessary directories
- if ! mkdir -p .tmp webs vulns; then
- printf "%b[!] Failed to create directories.%b\n" "$bred" "$reset"
- return 1
- fi
+ if ! ensure_dirs .tmp webs vulns; then return 1; fi
# Check if the function should run
if { [[ ! -f "$called_fn_dir/.${FUNCNAME[0]}" ]] || [[ $DIFF == true ]]; } && [[ $XSS == true ]] && [[ -s "gf/xss.txt" ]] \
@@ -96,10 +93,7 @@ function xss() {
function cors() {
# Create necessary directories
- if ! mkdir -p .tmp webs vulns; then
- printf "%b[!] Failed to create directories.%b\n" "$bred" "$reset"
- return 1
- fi
+ if ! ensure_dirs .tmp webs vulns; then return 1; fi
# Check if the function should run
if { [[ ! -f "$called_fn_dir/.${FUNCNAME[0]}" ]] || [[ $DIFF == true ]]; } && [[ $CORS == true ]] \
@@ -139,10 +133,7 @@ function cors() {
function open_redirect() {
# Create necessary directories
- if ! mkdir -p .tmp webs vulns; then
- printf "%b[!] Failed to create directories.%b\n" "$bred" "$reset"
- return 1
- fi
+ if ! ensure_dirs .tmp webs vulns; then return 1; fi
# Check if the function should run
if { [[ ! -f "$called_fn_dir/.${FUNCNAME[0]}" ]] || [[ $DIFF == true ]]; } && [[ $OPEN_REDIRECT == true ]] \
@@ -186,10 +177,7 @@ function open_redirect() {
function ssrf_checks() {
# Create necessary directories
- if ! mkdir -p .tmp gf vulns; then
- printf "%b[!] Failed to create directories.%b\n" "$bred" "$reset"
- return 1
- fi
+ if ! ensure_dirs .tmp gf vulns; then return 1; fi
# Check if the function should run
if { [[ ! -f "$called_fn_dir/.${FUNCNAME[0]}" ]] || [[ $DIFF == true ]]; } && [[ $SSRF_CHECKS == true ]] \
@@ -243,7 +231,9 @@ function ssrf_checks() {
# Process SSRF callback results if INTERACT is enabled
if [[ $INTERACT == true ]] && [[ -s ".tmp/ssrf_callback.txt" ]]; then
tail -n +11 .tmp/ssrf_callback.txt | anew -q "vulns/ssrf_callback.txt"
- NUMOFLINES=$(tail -n +12 .tmp/ssrf_callback.txt | sed '/^$/d' | wc -l)
+ if ! NUMOFLINES=$(tail -n +12 .tmp/ssrf_callback.txt | sed '/^$/d' | wc -l); then
+ NUMOFLINES=0
+ fi
notification "SSRF: ${NUMOFLINES} callbacks received" info
fi
@@ -275,10 +265,7 @@ function ssrf_checks() {
function crlf_checks() {
# Create necessary directories
- if ! mkdir -p webs vulns; then
- printf "%b[!] Failed to create directories.%b\n" "$bred" "$reset"
- return 1
- fi
+ if ! ensure_dirs webs vulns; then return 1; fi
# Check if the function should run
if { [[ ! -f "$called_fn_dir/.${FUNCNAME[0]}" ]] || [[ $DIFF == true ]]; } && [[ $CRLF_CHECKS == true ]] \
@@ -320,10 +307,7 @@ function crlf_checks() {
function lfi() {
# Create necessary directories
- if ! mkdir -p .tmp gf vulns; then
- printf "%b[!] Failed to create directories.%b\n" "$bred" "$reset"
- return 1
- fi
+ if ! ensure_dirs .tmp gf vulns; then return 1; fi
# Check if the function should run
if { [[ ! -f "$called_fn_dir/.${FUNCNAME[0]}" ]] || [[ $DIFF == true ]]; } && [[ $LFI == true ]] \
@@ -372,10 +356,7 @@ function lfi() {
function ssti() {
# Create necessary directories
- if ! mkdir -p .tmp gf vulns; then
- printf "%b[!] Failed to create directories.%b\n" "$bred" "$reset"
- return 1
- fi
+ if ! ensure_dirs .tmp gf vulns; then return 1; fi
# Check if the function should run
if { [[ ! -f "$called_fn_dir/.${FUNCNAME[0]}" ]] || [[ $DIFF == true ]]; } && [[ $SSTI == true ]] \
@@ -424,10 +405,7 @@ function ssti() {
function sqli() {
# Create necessary directories
- if ! mkdir -p .tmp gf vulns; then
- printf "%b[!] Failed to create directories.%b\n" "$bred" "$reset"
- return 1
- fi
+ if ! ensure_dirs .tmp gf vulns; then return 1; fi
# Check if the function should run
if { [[ ! -f "$called_fn_dir/.${FUNCNAME[0]}" ]] || [[ $DIFF == true ]]; } && [[ $SQLI == true ]] \
@@ -482,10 +460,7 @@ function sqli() {
function test_ssl() {
# Create necessary directories
- if ! mkdir -p hosts vulns; then
- printf "%b[!] Failed to create directories.%b\n" "$bred" "$reset"
- return 1
- fi
+ if ! ensure_dirs hosts vulns; then return 1; fi
# Check if the function should run
if { [[ ! -f "$called_fn_dir/.${FUNCNAME[0]}" ]] || [[ $DIFF == true ]]; } && [[ $TEST_SSL == true ]]; then
@@ -519,10 +494,7 @@ function test_ssl() {
function spraying() {
# Create necessary directories
- if ! mkdir -p "vulns"; then
- printf "%b[!] Failed to create directories.%b\n" "$bred" "$reset"
- return 1
- fi
+ if ! ensure_dirs vulns; then return 1; fi
# Check if the function should run
if { [[ ! -f "$called_fn_dir/.${FUNCNAME[0]}" ]] || [[ $DIFF == true ]]; } && [[ $SPRAY == true ]] \
@@ -560,10 +532,7 @@ function spraying() {
function command_injection() {
# Create necessary directories
- if ! mkdir -p .tmp gf vulns; then
- printf "%b[!] Failed to create directories.%b\n" "$bred" "$reset"
- return 1
- fi
+ if ! ensure_dirs .tmp gf vulns; then return 1; fi
# Check if the function should run
if { [[ ! -f "$called_fn_dir/.${FUNCNAME[0]}" ]] || [[ $DIFF == true ]]; } && [[ $COMM_INJ == true ]] \
@@ -614,10 +583,7 @@ function command_injection() {
function 4xxbypass() {
# Create necessary directories
- if ! mkdir -p .tmp fuzzing vulns; then
- printf "%b[!] Failed to create directories.%b\n" "$bred" "$reset"
- return 1
- fi
+ if ! ensure_dirs .tmp fuzzing vulns; then return 1; fi
# Check if the function should run
if { [[ ! -f "$called_fn_dir/.${FUNCNAME[0]}" ]] || [[ $DIFF == true ]]; } && [[ $BYPASSER4XX == true ]] \
@@ -678,10 +644,7 @@ function 4xxbypass() {
function prototype_pollution() {
# Create necessary directories
- if ! mkdir -p .tmp webs vulns; then
- printf "%b[!] Failed to create directories.%b\n" "$bred" "$reset"
- return 1
- fi
+ if ! ensure_dirs .tmp webs vulns; then return 1; fi
# Check if the function should run
if { [[ ! -f "$called_fn_dir/.${FUNCNAME[0]}" ]] || [[ $DIFF == true ]]; } && [[ $PROTO_POLLUTION == true ]] \
@@ -732,10 +695,7 @@ function prototype_pollution() {
function smuggling() {
# Create necessary directories
- if ! mkdir -p .tmp webs vulns/smuggling; then
- printf "%b[!] Failed to create directories.%b\n" "$bred" "$reset"
- return 1
- fi
+ if ! ensure_dirs .tmp webs vulns/smuggling; then return 1; fi
# Check if the function should run
if { [[ ! -f "$called_fn_dir/.${FUNCNAME[0]}" ]] || [[ $DIFF == true ]]; } && [[ $SMUGGLING == true ]] \
@@ -785,10 +745,7 @@ function smuggling() {
function webcache() {
# Create necessary directories
- if ! mkdir -p .tmp webs vulns; then
- printf "%b[!] Failed to create directories.%b\n" "$bred" "$reset"
- return 1
- fi
+ if ! ensure_dirs .tmp webs vulns; then return 1; fi
# Check if the function should run
if { [[ ! -f "$called_fn_dir/.${FUNCNAME[0]}" ]] || [[ $DIFF == true ]]; } && [[ $WEBCACHE == true ]] \
@@ -852,10 +809,7 @@ function webcache() {
function fuzzparams() {
# Create necessary directories
- if ! mkdir -p .tmp webs vulns; then
- printf "%b[!] Failed to create directories.%b\n" "$bred" "$reset"
- return 1
- fi
+ if ! ensure_dirs .tmp webs vulns; then return 1; fi
# Check if the function should run
if { [[ ! -f "$called_fn_dir/.${FUNCNAME[0]}" ]] || [[ $DIFF == true ]]; } && [[ $FUZZPARAMS == true ]] \
diff --git a/modules/web.sh b/modules/web.sh
index 655d15f..c542642 100644
--- a/modules/web.sh
+++ b/modules/web.sh
@@ -19,10 +19,7 @@
function webprobe_simple() {
# Create necessary directories
- if ! mkdir -p .tmp webs subdomains; then
- printf "%b[!] Failed to create directories.%b\n" "$bred" "$reset"
- return 1
- fi
+ if ! ensure_dirs .tmp webs subdomains; then return 1; fi
# Check if the function should run
if { [[ ! -f "$called_fn_dir/.${FUNCNAME[0]}" ]] || [[ $DIFF == true ]]; } && [[ $WEBPROBESIMPLE == true ]]; then
@@ -36,11 +33,13 @@ function webprobe_simple() {
# Run httpx or axiom-scan
if [[ $AXIOM != true ]]; then
- httpx ${HTTPX_FLAGS} -no-color -json -random-agent -threads "$HTTPX_THREADS" -rl "$HTTPX_RATELIMIT" \
+ # shellcheck disable=SC2086 # HTTPX_FLAGS intentionally word-split
+ httpx $HTTPX_FLAGS -no-color -json -random-agent -threads "$HTTPX_THREADS" -rl "$HTTPX_RATELIMIT" \
-retries 2 -timeout "$HTTPX_TIMEOUT" -o .tmp/web_full_info_probe.txt \
<subdomains/subdomains.txt 2>>"$LOGFILE" >/dev/null
else
- axiom-scan subdomains/subdomains.txt -m httpx ${HTTPX_FLAGS} -no-color -json -random-agent \
+ # shellcheck disable=SC2086 # HTTPX_FLAGS intentionally word-split
+ axiom-scan subdomains/subdomains.txt -m httpx $HTTPX_FLAGS -no-color -json -random-agent \
-threads "$HTTPX_THREADS" -rl "$HTTPX_RATELIMIT" -retries 2 -timeout "$HTTPX_TIMEOUT" \
-o .tmp/web_full_info_probe.txt "$AXIOM_EXTRA_ARGS" 2>>"$LOGFILE" >/dev/null
fi
@@ -114,10 +113,7 @@ function webprobe_simple() {
function webprobe_full() {
# Create necessary directories
- if ! mkdir -p .tmp webs subdomains; then
- printf "%b[!] Failed to create directories.%b\n" "$bred" "$reset"
- return 1
- fi
+ if ! ensure_dirs .tmp webs subdomains; then return 1; fi
# Check if the function should run
if { [[ ! -f "$called_fn_dir/.${FUNCNAME[0]}" ]] || [[ $DIFF == true ]]; } && [[ $WEBPROBEFULL == true ]]; then
@@ -206,10 +202,7 @@ function webprobe_full() {
function screenshot() {
# Create necessary directories
- if ! mkdir -p webs screenshots; then
- printf "%b[!] Failed to create directories.%b\n" "$bred" "$reset"
- return 1
- fi
+ if ! ensure_dirs webs screenshots; then return 1; fi
# Check if the function should run
if { [[ ! -f "$called_fn_dir/.${FUNCNAME[0]}" ]] || [[ $DIFF == true ]]; } && [[ $WEBSCREENSHOT == true ]]; then
@@ -244,10 +237,7 @@ function screenshot() {
function virtualhosts() {
# Create necessary directories
- if ! mkdir -p .tmp/virtualhosts virtualhosts webs; then
- printf "%b[!] Failed to create directories.%b\n" "$bred" "$reset"
- return 1
- fi
+ if ! ensure_dirs .tmp/virtualhosts virtualhosts webs; then return 1; fi
# Check if the function should run
if { [[ ! -f "$called_fn_dir/.${FUNCNAME[0]}" ]] || [[ $DIFF == true ]]; } && [[ $VIRTUALHOSTS == true ]]; then
@@ -290,10 +280,7 @@ function virtualhosts() {
function favicon() {
# Create necessary directories
- if ! mkdir -p hosts .tmp/virtualhosts; then
- printf "%b[!] Failed to create directories.%b\n" "$bred" "$reset"
- return 1
- fi
+ if ! ensure_dirs hosts .tmp/virtualhosts; then return 1; fi
# Check if the function should run
if { [[ ! -f "$called_fn_dir/.${FUNCNAME[0]}" ]] || [[ $DIFF == true ]]; } \
@@ -351,10 +338,7 @@ function favicon() {
function portscan() {
# Create necessary directories
- if ! mkdir -p .tmp subdomains hosts webs; then
- printf "%b[!] Failed to create directories.%b\n" "$bred" "$reset"
- return 1
- fi
+ if ! ensure_dirs .tmp subdomains hosts webs; then return 1; fi
# Check if the function should run
if { [[ ! -f "$called_fn_dir/.${FUNCNAME[0]}" ]] || [[ $DIFF == true ]]; } && [[ $PORTSCANNER == true ]]; then
@@ -442,15 +426,18 @@ function portscan() {
if [[ $PORTSCAN_ACTIVE == true ]]; then
if [[ $AXIOM != true ]]; then
if [[ -s ".tmp/ips_nocdn.txt" ]]; then
+ # shellcheck disable=SC2086 # SUDO and PORTSCAN_ACTIVE_OPTIONS intentionally word-split
run_command $SUDO nmap $PORTSCAN_ACTIVE_OPTIONS -iL .tmp/ips_nocdn.txt -oA hosts/portscan_active 2>>"$LOGFILE" >/dev/null
fi
if [[ $IPV6_SCAN == true && -s "hosts/ips_v6.txt" ]]; then
+ # shellcheck disable=SC2086 # SUDO and PORTSCAN_ACTIVE_OPTIONS intentionally word-split
run_command $SUDO nmap -6 $PORTSCAN_ACTIVE_OPTIONS -iL hosts/ips_v6.txt -oA hosts/portscan_active_v6 2>>"$LOGFILE" >/dev/null
fi
else
if [[ -s ".tmp/ips_nocdn.txt" ]]; then
+ # shellcheck disable=SC2086 # PORTSCAN_ACTIVE_OPTIONS intentionally word-split
run_command axiom-scan .tmp/ips_nocdn.txt -m nmapx $PORTSCAN_ACTIVE_OPTIONS \
- -oA hosts/portscan_active $AXIOM_EXTRA_ARGS 2>>"$LOGFILE" >/dev/null
+ -oA hosts/portscan_active "$AXIOM_EXTRA_ARGS" 2>>"$LOGFILE" >/dev/null
fi
fi
fi
@@ -501,10 +488,7 @@ function portscan() {
function cdnprovider() {
# Create necessary directories
- if ! mkdir -p .tmp subdomains hosts; then
- printf "%b[!] Failed to create directories.%b\n" "$bred" "$reset"
- return 1
- fi
+ if ! ensure_dirs .tmp subdomains hosts; then return 1; fi
# Check if the function should run
if { [[ ! -f "$called_fn_dir/.${FUNCNAME[0]}" ]] || [[ $DIFF == true ]]; } \
@@ -549,10 +533,7 @@ function cdnprovider() {
function waf_checks() {
# Create necessary directories
- if ! mkdir -p .tmp webs; then
- printf "%b[!] Failed to create directories.%b\n" "$bred" "$reset"
- return 1
- fi
+ if ! ensure_dirs .tmp webs; then return 1; fi
# Check if the function should run
if { [[ ! -f "$called_fn_dir/.${FUNCNAME[0]}" ]] || [[ $DIFF == true ]]; } && [[ $WAF_DETECTION == true ]]; then
@@ -614,10 +595,7 @@ function waf_checks() {
function nuclei_check() {
# Create necessary directories
- if ! mkdir -p .tmp webs subdomains nuclei_output; then
- printf "%b[!] Failed to create directories.%b\n" "$bred" "$reset"
- return 1
- fi
+ if ! ensure_dirs .tmp webs subdomains nuclei_output; then return 1; fi
# Check if the function should run
if { [[ ! -f "$called_fn_dir/.${FUNCNAME[0]}" ]] || [[ $DIFF == true ]]; } && [[ $NUCLEICHECK == true ]]; then
@@ -752,7 +730,7 @@ function nuclei_check() {
function graphql_scan() {
# Detect GraphQL endpoints and introspection
- mkdir -p .tmp webs nuclei_output vulns/graphql
+ ensure_dirs .tmp webs nuclei_output vulns/graphql
if { [[ ! -f "$called_fn_dir/.${FUNCNAME[0]}" ]] || [[ $DIFF == true ]]; } && [[ $GRAPHQL_CHECK == true ]]; then
start_func "${FUNCNAME[0]}" "GraphQL detection"
@@ -785,7 +763,7 @@ function graphql_scan() {
}
function param_discovery() {
- mkdir -p webs .tmp
+ ensure_dirs webs .tmp
if { [[ ! -f "$called_fn_dir/.${FUNCNAME[0]}" ]] || [[ $DIFF == true ]]; } && [[ $PARAM_DISCOVERY == true ]]; then
start_func "${FUNCNAME[0]}" "Parameter discovery (arjun)"
@@ -809,7 +787,7 @@ function param_discovery() {
}
function grpc_reflection() {
- mkdir -p hosts .tmp
+ ensure_dirs hosts .tmp
if { [[ ! -f "$called_fn_dir/.${FUNCNAME[0]}" ]] || [[ $DIFF == true ]]; } && [[ $GRPC_SCAN == true ]]; then
start_func "${FUNCNAME[0]}" "gRPC reflection probing"
@@ -841,7 +819,7 @@ function grpc_reflection() {
function fuzz() {
# Create necessary directories
- mkdir -p .tmp/fuzzing webs fuzzing
+ ensure_dirs .tmp/fuzzing webs fuzzing
# Check if the function should run
if { [[ ! -f "$called_fn_dir/.${FUNCNAME[0]}" ]] || [[ $DIFF == true ]]; } && [[ $FUZZ == true ]] \
@@ -1053,10 +1031,7 @@ function cms_scanner() {
function urlchecks() {
# Create necessary directories
- if ! mkdir -p .tmp webs; then
- printf "%b[!] Failed to create directories.%b\n" "$bred" "$reset"
- return 1
- fi
+ if ! ensure_dirs .tmp webs; then return 1; fi
# Check if the function should run
if { [[ ! -f "$called_fn_dir/.${FUNCNAME[0]}" ]] || [[ $DIFF == true ]]; } && [[ $URL_CHECK == true ]]; then
@@ -1497,10 +1472,7 @@ function websocket_checks() {
function wordlist_gen() {
# Create necessary directories
- if ! mkdir -p .tmp webs; then
- printf "%b[!] Failed to create directories.%b\n" "$bred" "$reset"
- return 1
- fi
+ if ! ensure_dirs .tmp webs; then return 1; fi
# Check if the function should run
if { [[ ! -f "$called_fn_dir/.${FUNCNAME[0]}" ]] || [[ $DIFF == true ]]; } && [[ $WORDLIST == true ]] \
diff --git a/reconftw.sh b/reconftw.sh
index 192de14..c877a75 100755
--- a/reconftw.sh
+++ b/reconftw.sh
@@ -64,6 +64,8 @@ SCRIPTPATH="${_INIT_SCRIPTPATH}"
# Source libraries first (pure utilities)
source "${_INIT_SCRIPTPATH}/lib/validation.sh"
+source "${_INIT_SCRIPTPATH}/lib/common.sh"
+source "${_INIT_SCRIPTPATH}/lib/parallel.sh"
# Source all modules in dependency order
source "${_INIT_SCRIPTPATH}/modules/utils.sh"
diff --git a/tests/unit/test_common.bats b/tests/unit/test_common.bats
new file mode 100644
index 0000000..79e58a2
--- /dev/null
+++ b/tests/unit/test_common.bats
@@ -0,0 +1,233 @@
+#!/usr/bin/env bats
+# Tests for lib/common.sh utility functions
+
+setup() {
+ # Source the common library
+ source "${BATS_TEST_DIRNAME}/../../lib/common.sh"
+
+ # Create temp directory for tests
+ TEST_DIR=$(mktemp -d)
+ cd "$TEST_DIR" || exit 1
+
+ # Set up mock variables that would normally come from reconftw
+ yellow=""
+ reset=""
+ bred=""
+ cyan=""
+ called_fn_dir="$TEST_DIR/.called_fn"
+ LOGFILE="$TEST_DIR/test.log"
+ DRY_RUN=false
+}
+
+teardown() {
+ cd /
+ rm -rf "$TEST_DIR"
+}
+
+###############################################################################
+# ensure_dirs tests
+###############################################################################
+
+@test "ensure_dirs creates single directory" {
+ run ensure_dirs testdir
+ [ "$status" -eq 0 ]
+ [ -d "testdir" ]
+}
+
+@test "ensure_dirs creates multiple directories" {
+ run ensure_dirs dir1 dir2 dir3
+ [ "$status" -eq 0 ]
+ [ -d "dir1" ]
+ [ -d "dir2" ]
+ [ -d "dir3" ]
+}
+
+@test "ensure_dirs creates nested directories" {
+ run ensure_dirs "a/b/c"
+ [ "$status" -eq 0 ]
+ [ -d "a/b/c" ]
+}
+
+@test "ensure_dirs returns 0 with no arguments" {
+ run ensure_dirs
+ [ "$status" -eq 0 ]
+}
+
+@test "ensure_dirs succeeds if directory already exists" {
+ mkdir -p existing_dir
+ run ensure_dirs existing_dir
+ [ "$status" -eq 0 ]
+}
+
+###############################################################################
+# safe_backup tests
+###############################################################################
+
+@test "safe_backup copies existing file" {
+ mkdir -p .tmp
+ echo "test content" > original.txt
+ run safe_backup original.txt .tmp/backup.txt
+ [ "$status" -eq 0 ]
+ [ -f ".tmp/backup.txt" ]
+ [ "$(cat .tmp/backup.txt)" = "test content" ]
+}
+
+@test "safe_backup skips empty file" {
+ mkdir -p .tmp
+ touch empty.txt
+ run safe_backup empty.txt .tmp/backup.txt
+ [ "$status" -eq 0 ]
+ [ ! -f ".tmp/backup.txt" ]
+}
+
+@test "safe_backup skips non-existent file" {
+ mkdir -p .tmp
+ run safe_backup nonexistent.txt .tmp/backup.txt
+ [ "$status" -eq 0 ]
+ [ ! -f ".tmp/backup.txt" ]
+}
+
+@test "safe_backup uses default destination" {
+ mkdir -p .tmp
+ echo "content" > myfile.txt
+ run safe_backup myfile.txt
+ [ "$status" -eq 0 ]
+ [ -f ".tmp/myfile.txt.bak" ]
+}
+
+###############################################################################
+# count_lines tests
+###############################################################################
+
+@test "count_lines returns correct count" {
+ printf "line1\nline2\nline3\n" > test.txt
+ result=$(count_lines test.txt)
+ [ "$result" -eq 3 ]
+}
+
+@test "count_lines ignores empty lines" {
+ printf "line1\n\nline2\n\n\nline3\n" > test.txt
+ result=$(count_lines test.txt)
+ [ "$result" -eq 3 ]
+}
+
+@test "count_lines returns 0 for empty file" {
+ touch empty.txt
+ result=$(count_lines empty.txt)
+ [ "$result" -eq 0 ]
+}
+
+@test "count_lines returns 0 for non-existent file" {
+ result=$(count_lines nonexistent.txt)
+ [ "$result" -eq 0 ]
+}
+
+###############################################################################
+# count_lines_stdin tests
+###############################################################################
+
+@test "count_lines_stdin counts from pipe" {
+ result=$(printf "a\nb\nc\n" | count_lines_stdin)
+ [ "$result" -eq 3 ]
+}
+
+@test "count_lines_stdin ignores empty lines from pipe" {
+ result=$(printf "a\n\nb\n\n" | count_lines_stdin)
+ [ "$result" -eq 2 ]
+}
+
+###############################################################################
+# skip_notification tests
+###############################################################################
+
+@test "skip_notification outputs message" {
+ # Define a wrapper function to test FUNCNAME
+ test_func() {
+ skip_notification "disabled"
+ }
+ run test_func
+ [ "$status" -eq 0 ]
+ [[ "$output" == *"skipped"* ]]
+}
+
+###############################################################################
+# run_tool tests
+###############################################################################
+
+@test "run_tool executes command normally" {
+ run run_tool "echo" echo "hello"
+ [ "$status" -eq 0 ]
+ [[ "$output" == *"hello"* ]]
+}
+
+@test "run_tool respects DRY_RUN mode" {
+ DRY_RUN=true
+ run run_tool "test" echo "should not run"
+ [ "$status" -eq 0 ]
+ [[ "$output" == *"DRY-RUN"* ]]
+}
+
+###############################################################################
+# safe_count tests
+###############################################################################
+
+@test "safe_count returns valid number" {
+ printf "line1\nline2\n" > test.txt
+ result=$(safe_count "cat test.txt")
+ [ "$result" -eq 2 ]
+}
+
+@test "safe_count returns 0 on failure" {
+ result=$(safe_count "cat nonexistent_file_xyz.txt")
+ [ "$result" -eq 0 ]
+}
+
+###############################################################################
+# process_results tests
+###############################################################################
+
+@test "process_results deduplicates and counts" {
+ # Skip if anew not available
+ command -v anew &>/dev/null || skip "anew not installed"
+
+ printf "a\nb\nc\n" > input.txt
+ touch output.txt
+ result=$(process_results input.txt output.txt)
+ [ "$result" -eq 3 ]
+ [ -f "output.txt" ]
+}
+
+###############################################################################
+# should_run_function tests
+###############################################################################
+
+@test "should_run_function returns true when checkpoint missing" {
+ mkdir -p "$called_fn_dir"
+ test_func() {
+ should_run_function
+ }
+ run test_func
+ [ "$status" -eq 0 ]
+}
+
+@test "should_run_function returns false when checkpoint exists" {
+ mkdir -p "$called_fn_dir"
+ DIFF=false
+ test_func() {
+ touch "$called_fn_dir/.test_func"
+ should_run_function
+ }
+ run test_func
+ [ "$status" -eq 1 ]
+}
+
+@test "should_run_function returns true in DIFF mode even with checkpoint" {
+ mkdir -p "$called_fn_dir"
+ DIFF=true
+ test_func() {
+ touch "$called_fn_dir/.test_func"
+ should_run_function
+ }
+ run test_func
+ [ "$status" -eq 0 ]
+}
diff --git a/tests/unit/test_parallel.bats b/tests/unit/test_parallel.bats
new file mode 100644
index 0000000..d980ee7
--- /dev/null
+++ b/tests/unit/test_parallel.bats
@@ -0,0 +1,159 @@
+#!/usr/bin/env bats
+# Tests for lib/parallel.sh parallel execution utilities
+
+setup() {
+ # Source the parallel library
+ source "${BATS_TEST_DIRNAME}/../../lib/parallel.sh"
+
+ # Create temp directory for tests
+ TEST_DIR=$(mktemp -d)
+ cd "$TEST_DIR" || exit 1
+
+ # Set up mock variables
+ yellow=""
+ reset=""
+ bred=""
+ bblue=""
+ bgreen=""
+ cyan=""
+ VERBOSE=false
+}
+
+teardown() {
+ cd /
+ rm -rf "$TEST_DIR"
+}
+
+###############################################################################
+# parallel_run tests
+###############################################################################
+
+@test "parallel_run executes single command" {
+ run parallel_run 2 "echo hello > out1.txt"
+ [ "$status" -eq 0 ]
+ [ -f "out1.txt" ]
+ [ "$(cat out1.txt)" = "hello" ]
+}
+
+@test "parallel_run executes multiple commands" {
+ run parallel_run 2 "echo a > a.txt" "echo b > b.txt" "echo c > c.txt"
+ [ "$status" -eq 0 ]
+ [ -f "a.txt" ]
+ [ -f "b.txt" ]
+ [ -f "c.txt" ]
+}
+
+@test "parallel_run respects job limit" {
+ # This test verifies commands complete (timing would be flaky)
+ run parallel_run 2 "sleep 0.1 && echo 1 > 1.txt" "sleep 0.1 && echo 2 > 2.txt" "sleep 0.1 && echo 3 > 3.txt"
+ [ "$status" -eq 0 ]
+ [ -f "1.txt" ]
+ [ -f "2.txt" ]
+ [ -f "3.txt" ]
+}
+
+###############################################################################
+# parallel_funcs tests
+###############################################################################
+
+@test "parallel_funcs runs functions" {
+ # Define test functions
+ func1() { echo "func1" > func1.txt; }
+ func2() { echo "func2" > func2.txt; }
+
+ run parallel_funcs 2 func1 func2
+ [ "$status" -eq 0 ]
+ [ -f "func1.txt" ]
+ [ -f "func2.txt" ]
+}
+
+@test "parallel_funcs skips undefined functions" {
+ func1() { echo "exists" > exists.txt; }
+
+ run parallel_funcs 2 func1 undefined_function_xyz
+ # Should complete (skipping the undefined one)
+ [ -f "exists.txt" ]
+}
+
+@test "parallel_funcs returns failure count" {
+ success_func() { return 0; }
+ fail_func() { return 1; }
+
+ run parallel_funcs 2 success_func fail_func
+ # Status should be non-zero (1 failure)
+ [ "$status" -eq 1 ]
+}
+
+###############################################################################
+# parallel_batch tests
+###############################################################################
+
+@test "parallel_batch runs functions in batches" {
+ func1() { echo "1" >> order.txt; sleep 0.1; }
+ func2() { echo "2" >> order.txt; sleep 0.1; }
+ func3() { echo "3" >> order.txt; sleep 0.1; }
+ func4() { echo "4" >> order.txt; }
+
+ run parallel_batch 2 func1 func2 func3 func4
+ [ "$status" -eq 0 ]
+ # All functions should have run
+ [ "$(wc -l < order.txt | tr -d ' ')" -eq 4 ]
+}
+
+###############################################################################
+# get_running_jobs tests
+###############################################################################
+
+@test "get_running_jobs returns 0 when no jobs" {
+ result=$(get_running_jobs)
+ [ "$result" -eq 0 ]
+}
+
+@test "get_running_jobs counts background jobs" {
+ sleep 0.5 &
+ sleep 0.5 &
+ result=$(get_running_jobs)
+ # Should be at least 1 (timing dependent)
+ [ "$result" -ge 1 ]
+ wait
+}
+
+###############################################################################
+# cleanup_parallel_jobs tests
+###############################################################################
+
+@test "cleanup_parallel_jobs clears PID array" {
+ _PARALLEL_PIDS=(12345 67890)
+ cleanup_parallel_jobs
+ [ "${#_PARALLEL_PIDS[@]}" -eq 0 ]
+}
+
+###############################################################################
+# Integration tests
+###############################################################################
+
+@test "parallel functions work with shared output file" {
+ append_func() {
+ local id="$1"
+ echo "$id" >> shared.txt
+ }
+
+ # Simulate multiple parallel writes
+ ( append_func "a" ) &
+ ( append_func "b" ) &
+ ( append_func "c" ) &
+ wait
+
+ # All should be written
+ [ "$(wc -l < shared.txt | tr -d ' ')" -eq 3 ]
+}
+
+@test "parallel_run handles empty command list" {
+ run parallel_run 2
+ [ "$status" -eq 0 ]
+}
+
+@test "parallel_funcs handles empty function list" {
+ run parallel_funcs 2
+ [ "$status" -eq 0 ]
+}