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
Shell bug-bountybugbountybugbounty-tooldnshackingnucleiosintpenetration-testingpentestpentest-toolpentestingreconreconnaissancescannersecuritysecurity-toolssubdomainsubdomain-enumerationvulnerabilities
feat: add input validation and security improvements
six2dezcb8f8f77b760
diff --git a/lib/validation.sh b/lib/validation.shindex 0782eed..b57a103 100644--- a/lib/validation.sh+++ b/lib/validation.sh@@ -207,3 +207,79 @@ function is_numeric() {return 1}++# validate_file_exists()+# Description: Validates that a file exists+# Arguments: $1 - File path+# Returns: 0 if file exists, E_INVALID_PATH if not+function validate_file_exists() {+ local file="$1"++ if [[ -z "$file" ]]; then+ return $E_INVALID_PATH+ fi++ if [[ ! -e "$file" ]]; then+ return $E_INVALID_PATH+ fi++ return 0+}++# validate_file_readable()+# Description: Validates that a file exists and is readable+# Arguments: $1 - File path+# Returns: 0 if readable, E_INVALID_PATH if not+function validate_file_readable() {+ local file="$1"++ if ! validate_file_exists "$file"; then+ return $E_INVALID_PATH+ fi++ if [[ ! -r "$file" ]]; then+ return $E_INVALID_PATH+ fi++ if [[ ! -f "$file" ]]; then+ return $E_INVALID_PATH+ fi++ return 0+}++# validate_directory()+# Description: Validates that a directory exists+# Arguments: $1 - Directory path+# Returns: 0 if valid directory, E_INVALID_PATH if not+function validate_directory() {+ local dir="$1"++ if [[ -z "$dir" ]]; then+ return $E_INVALID_PATH+ fi++ if [[ ! -d "$dir" ]]; then+ return $E_INVALID_PATH+ fi++ return 0+}++# validate_writable_directory()+# Description: Validates that a directory exists and is writable+# Arguments: $1 - Directory path+# Returns: 0 if writable, E_INVALID_PATH if not+function validate_writable_directory() {+ local dir="$1"++ if ! validate_directory "$dir"; then+ return $E_INVALID_PATH+ fi++ if [[ ! -w "$dir" ]]; then+ return $E_INVALID_PATH+ fi++ return 0+}diff --git a/modules/core.sh b/modules/core.shindex 7324d96..5b50588 100644--- a/modules/core.sh+++ b/modules/core.sh@@ -25,13 +25,49 @@ pt_msg_err() { printf "\n%b[%s] %s%b\n" "$bred" "$(date +'%Y-%m-%d %H:%M:%S')" "# If LOGFILE is unset or empty, send logs to /dev/null until later initialization: "${LOGFILE:=/dev/null}"+# List of environment variables containing secrets that should be redacted in logs+REDACT_VARS=(+ "SHODAN_API_KEY"+ "WHOISXML_API"+ "GITHUB_TOKEN"+ "GITLAB_TOKEN"+ "DISCORD_WEBHOOK_URL"+ "SLACK_WEBHOOK_URL"+ "slack_auth"+ "XSS_SERVER"+ "COLLAB_SERVER"+)++# redact_secrets()+# Description: Redacts sensitive values from a string+# Arguments: $1 - String to redact+# Returns: Redacted string via stdout+function redact_secrets() {+ local text="$1"+ local redacted="$text"++ for var in "${REDACT_VARS[@]}"; do+ local value="${!var:-}"+ if [[ -n "$value" && ${#value} -gt 4 ]]; then+ # Replace the secret with [REDACTED]+ redacted="${redacted//$value/[REDACTED]}"+ fi+ done++ echo "$redacted"+}+enable_command_trace() {# Enable bash xtrace to the current LOGFILE when SHOW_COMMANDS=true+ # WARNING: This may log sensitive data. Use redact_secrets() when reviewing logs.if [[ ${SHOW_COMMANDS:-false} != true ]]; thenreturnfi[[ -z ${LOGFILE:-} ]] && return+ printf "%b[%s] WARNING: Command tracing enabled. Logs may contain sensitive data.%b\n" \+ "$yellow" "$(date +'%Y-%m-%d %H:%M:%S')" "$reset" >&2+# Close any previous trace descriptor (native bash {varname} redirect syntax)if [[ -n ${TRACE_FD:-} ]]; thenexec {TRACE_FD}>&- 2>/dev/null || truediff --git a/modules/utils.sh b/modules/utils.shindex dc7cf1a..05e24b8 100644--- a/modules/utils.sh+++ b/modules/utils.sh@@ -435,6 +435,44 @@ function sanitize_ip() {return 0}+###############################################################################################################+####################################### SECURITY CHECKS #######################################################+###############################################################################################################++# Check and warn about insecure permissions on sensitive files+# Usage: check_secrets_permissions+function check_secrets_permissions() {+ local sensitive_files=(+ "${SCRIPTPATH}/secrets.cfg"+ "${SCRIPTPATH}/.github_tokens"+ "${SCRIPTPATH}/.gitlab_tokens"+ "${HOME}/.config/notify/provider-config.yaml"+ )++ local warnings=0++ for file in "${sensitive_files[@]}"; do+ if [[ -f "$file" ]]; then+ local perms+ if [[ "$OSTYPE" == "darwin"* ]]; then+ perms=$(stat -f "%OLp" "$file" 2>/dev/null)+ else+ perms=$(stat -c "%a" "$file" 2>/dev/null)+ fi++ # Check if file is readable by group or others+ if [[ -n "$perms" && "$perms" != "600" && "$perms" != "400" ]]; then+ printf "%b[%s] WARNING: Insecure permissions (%s) on sensitive file: %s%b\n" \+ "$yellow" "$(date +'%Y-%m-%d %H:%M:%S')" "$perms" "$file" "$reset" >&2+ printf "%b Recommended: chmod 600 %s%b\n" "$yellow" "$file" "$reset" >&2+ ((warnings++))+ fi+ fi+ done++ return $warnings+}+###################################################################################################################################################### DEEP/AXIOM HELPERS ###################################################################################################################################################################diff --git a/reconftw.sh b/reconftw.shindex 3cfdd0f..4f40c90 100755--- a/reconftw.sh+++ b/reconftw.sh@@ -146,6 +146,13 @@ while true; do;;'-l' | '--list')list="$2"+ if ! validate_file_readable "$list"; then+ printf "%b[%s] ERROR: List file not found or not readable: '%s'%b\n" \+ "$bred" "$(date +'%Y-%m-%d %H:%M:%S')" "$list" "$reset" >&2+ printf "%bUsage: -l <file> where file contains one target per line%b\n" \+ "$yellow" "$reset" >&2+ exit 1+ fiwhile IFS= read -r t; do[[ -z "$t" ]] && continueipcidr_target "$t" "$list"@@ -155,11 +162,21 @@ while true; do;;'-x')outOfScope_file=$2+ if [[ -n "$outOfScope_file" ]] && ! validate_file_readable "$outOfScope_file"; then+ printf "%b[%s] ERROR: Out-of-scope file not found or not readable: '%s'%b\n" \+ "$bred" "$(date +'%Y-%m-%d %H:%M:%S')" "$outOfScope_file" "$reset" >&2+ exit 1+ fishift 2continue;;'-i')inScope_file=$2+ if [[ -n "$inScope_file" ]] && ! validate_file_readable "$inScope_file"; then+ printf "%b[%s] ERROR: In-scope file not found or not readable: '%s'%b\n" \+ "$bred" "$(date +'%Y-%m-%d %H:%M:%S')" "$inScope_file" "$reset" >&2+ exit 1+ fishift 2continue;;diff --git a/tests/integration/test_smoke.bats b/tests/integration/test_smoke.batsindex 614fe6f..1af66e9 100644--- a/tests/integration/test_smoke.bats+++ b/tests/integration/test_smoke.bats@@ -75,3 +75,15 @@ setup() {# Should NOT execute any dangerous command[[ "$output" != *"cannot remove"* ]]}++@test "missing list file shows error" {+ run timeout 5 bash "$SCRIPTPATH/reconftw.sh" -l "/nonexistent/file.txt" --dry-run 2>&1+ [ "$status" -ne 0 ]+ [[ "$output" == *"ERROR"* ]] || [[ "$output" == *"not found"* ]] || [[ "$output" == *"not readable"* ]]+}++@test "missing inscope file shows error" {+ run timeout 5 bash "$SCRIPTPATH/reconftw.sh" -d test.com -i "/nonexistent/inscope.txt" --dry-run 2>&1+ [ "$status" -ne 0 ]+ [[ "$output" == *"ERROR"* ]] || [[ "$output" == *"not found"* ]]+}diff --git a/tests/unit/test_validation.bats b/tests/unit/test_validation.batsindex 3fc73bc..5caf43b 100644--- a/tests/unit/test_validation.bats+++ b/tests/unit/test_validation.bats@@ -127,3 +127,47 @@ setup() {run validate_boolean "maybe"[ "$status" -ne 0 ]}++# File validation tests+@test "validate_file_exists returns true for existing file" {+ local tmpfile+ tmpfile=$(mktemp)+ run validate_file_exists "$tmpfile"+ [ "$status" -eq 0 ]+ rm -f "$tmpfile"+}++@test "validate_file_exists returns false for non-existent file" {+ run validate_file_exists "/nonexistent/file/path"+ [ "$status" -ne 0 ]+}++@test "validate_file_readable returns true for readable file" {+ local tmpfile+ tmpfile=$(mktemp)+ echo "test" > "$tmpfile"+ run validate_file_readable "$tmpfile"+ [ "$status" -eq 0 ]+ rm -f "$tmpfile"+}++@test "validate_directory returns true for existing directory" {+ local tmpdir+ tmpdir=$(mktemp -d)+ run validate_directory "$tmpdir"+ [ "$status" -eq 0 ]+ rmdir "$tmpdir"+}++@test "validate_directory returns false for non-existent directory" {+ run validate_directory "/nonexistent/directory"+ [ "$status" -ne 0 ]+}++@test "validate_writable_directory returns true for writable dir" {+ local tmpdir+ tmpdir=$(mktemp -d)+ run validate_writable_directory "$tmpdir"+ [ "$status" -eq 0 ]+ rmdir "$tmpdir"+}