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

feat: add integration tests and improve cleanup

six2dez4195b9c8878d
diff --git a/SECURITY.md b/SECURITY.md
index 846a53b..6a5870b 100644
--- a/SECURITY.md
+++ b/SECURITY.md
@@ -80,12 +80,29 @@ reconFTW sanitizes all user-supplied input to prevent command injection:
| Function | Purpose |
|----------|---------|
-| `sanitize_domain()` | Strips characters not valid in domain names |
+| `sanitize_domain()` | Strips characters not valid in domain names, converts to lowercase |
| `sanitize_ip()` | Validates and cleans IP/CIDR input |
| `sanitize_interlace_input()` | Removes shell metacharacters from interlace arguments |
+| `validate_domain()` | Validates domain format without modification |
+| `validate_ipv4()` | Validates IPv4 address format |
All `eval` usage on user input has been removed. Variables are quoted throughout the codebase to prevent word-splitting and globbing attacks.
+## Security Testing
+
+The test suite includes security-focused tests in `tests/security/`:
+
+- Command injection attempts via domain parameter
+- Pipe and redirect injection tests
+- Backtick and dollar substitution tests
+- Path traversal prevention tests
+
+Run security tests with:
+
+```bash
+make test-security
+```
+
## Security-Related Configuration
These variables in `reconftw.cfg` control security and operational safety:
diff --git a/modules/utils.sh b/modules/utils.sh
index 922cf1b..defc719 100644
--- a/modules/utils.sh
+++ b/modules/utils.sh
@@ -30,14 +30,35 @@ function deleteOutScoped() {
}
function cleanup_on_exit() {
+ local exit_code="${1:-130}"
printf "\n%b[%s] Interrupted. Cleaning up...%b\n" "$bred" "$(date +'%Y-%m-%d %H:%M:%S')" "$reset"
+
+ # Save checkpoint before cleanup if enabled
+ if [[ "${CHECKPOINT_ENABLED:-false}" == "true" ]] && [[ -n "${CHECKPOINT_DIR:-}" ]]; then
+ echo "interrupted=$(date -Iseconds)" >> "$CHECKPOINT_DIR/scan_info.txt" 2>/dev/null || true
+ fi
+
# Clean temporary chunk files
rm -rf -- "${dir:-.}/.tmp/chunks" 2>/dev/null
- # Kill any background processes we spawned
- jobs -p 2>/dev/null | xargs -r kill 2>/dev/null || true
+
+ # Kill any background processes we spawned (safely)
+ local pids
+ pids=$(jobs -p 2>/dev/null) || true
+ if [[ -n "$pids" ]]; then
+ echo "$pids" | while read -r pid; do
+ [[ -n "$pid" ]] && kill "$pid" 2>/dev/null || true
+ done
+ fi
+
+ # Kill tracked interactsh process if running
+ if [[ -n "${INTERACTSH_PID:-}" ]]; then
+ kill "$INTERACTSH_PID" 2>/dev/null || true
+ fi
+
# Log the interruption
- echo "[$(date +'%Y-%m-%d %H:%M:%S')] Interrupted by signal" >>"${LOGFILE:-/dev/null}"
- exit 130
+ echo "[$(date +'%Y-%m-%d %H:%M:%S')] Interrupted by signal (exit code: $exit_code)" >>"${LOGFILE:-/dev/null}"
+
+ exit "$exit_code"
}
function rotate_logs() {
diff --git a/tests/integration/test_smoke.bats b/tests/integration/test_smoke.bats
new file mode 100644
index 0000000..614fe6f
--- /dev/null
+++ b/tests/integration/test_smoke.bats
@@ -0,0 +1,77 @@
+#!/usr/bin/env bats
+
+# Smoke tests for reconFTW - basic functionality checks
+
+setup() {
+ local project_root
+ project_root="$(cd "$(dirname "$BATS_TEST_FILENAME")/../.." && pwd)"
+ export SCRIPTPATH="$project_root"
+ export PATH="$project_root:$PATH"
+}
+
+@test "reconftw.sh is executable" {
+ [ -x "$SCRIPTPATH/reconftw.sh" ]
+}
+
+@test "reconftw.sh --help exits successfully" {
+ run timeout 10 bash "$SCRIPTPATH/reconftw.sh" --help
+ [ "$status" -eq 0 ]
+}
+
+@test "reconftw.sh --help shows usage" {
+ run timeout 10 bash "$SCRIPTPATH/reconftw.sh" --help
+ [[ "$output" == *"Usage"* ]] || [[ "$output" == *"usage"* ]] || [[ "$output" == *"-d"* ]]
+}
+
+@test "all modules are loadable" {
+ for module in utils core osint subdomains web vulns axiom modes; do
+ [ -f "$SCRIPTPATH/modules/${module}.sh" ]
+ done
+}
+
+@test "lib/validation.sh is loadable" {
+ [ -f "$SCRIPTPATH/lib/validation.sh" ]
+}
+
+@test "reconftw.cfg exists and is readable" {
+ [ -r "$SCRIPTPATH/reconftw.cfg" ]
+}
+
+@test "source-only mode works without side effects" {
+ run timeout 10 bash -c "source '$SCRIPTPATH/reconftw.sh' --source-only && echo 'OK'"
+ [ "$status" -eq 0 ]
+ [[ "$output" == *"OK"* ]]
+}
+
+@test "sanitize_domain function is available after source" {
+ run timeout 10 bash -c "source '$SCRIPTPATH/reconftw.sh' --source-only && type sanitize_domain"
+ [ "$status" -eq 0 ]
+}
+
+@test "validate_domain function is available after source" {
+ run timeout 10 bash -c "source '$SCRIPTPATH/reconftw.sh' --source-only && type validate_domain"
+ [ "$status" -eq 0 ]
+}
+
+@test "should_run_deep function is available after source" {
+ run timeout 10 bash -c "source '$SCRIPTPATH/reconftw.sh' --source-only && type should_run_deep"
+ [ "$status" -eq 0 ]
+}
+
+@test "checkpoint functions are available after source" {
+ run timeout 10 bash -c "source '$SCRIPTPATH/reconftw.sh' --source-only && type checkpoint_init && type checkpoint_save"
+ [ "$status" -eq 0 ]
+}
+
+@test "circuit_breaker functions are available after source" {
+ run timeout 10 bash -c "source '$SCRIPTPATH/reconftw.sh' --source-only && type circuit_breaker_is_open"
+ [ "$status" -eq 0 ]
+}
+
+@test "invalid domain is sanitized" {
+ run timeout 10 bash "$SCRIPTPATH/reconftw.sh" -d "; rm -rf /" --dry-run 2>&1
+ # Domain should be sanitized - dangerous chars removed
+ [[ "$output" == *"sanitized"* ]] || [[ "$output" == *"rm-rf"* ]]
+ # Should NOT execute any dangerous command
+ [[ "$output" != *"cannot remove"* ]]
+}
diff --git a/tests/unit/test_sanitize.bats b/tests/unit/test_sanitize.bats
index 16b5e83..fd51cea 100644
--- a/tests/unit/test_sanitize.bats
+++ b/tests/unit/test_sanitize.bats
@@ -51,6 +51,26 @@ setup() {
[ "$status" -ne 0 ]
}
+@test "sanitize_domain handles empty input" {
+ run sanitize_domain ""
+ [ "$status" -ne 0 ]
+}
+
+@test "sanitize_domain handles only dots" {
+ run sanitize_domain "..."
+ [ "$status" -ne 0 ]
+}
+
+@test "sanitize_domain strips leading/trailing dots" {
+ result=$(sanitize_domain ".example.com.")
+ [ "$result" = "example.com" ]
+}
+
+@test "sanitize_domain strips leading/trailing hyphens" {
+ result=$(sanitize_domain "-example.com-")
+ [ "$result" = "example.com" ]
+}
+
@test "sanitize_interlace_input removes shell metacharacters" {
local tmpfile
tmpfile=$(mktemp)