#!/usr/bin/env bash # The Analyzer v2 — Discovery Engine # Finds actual URLs, forms, parameters, and endpoints on the target # This feeds the exploit vectors with real attack surface SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" source "$SCRIPT_DIR/../lib/utils.sh" discover_target() { local target="$1" local domain=$(get_domain "$target") local base=$(get_base "$target") local outfile="$REPORTS_DIR/.${domain}_discovery.txt" print_info "Discovering attack surface on $target..." separator local DISCOVERED_URLS="" local DISCOVERED_FORMS="" local DISCOVERED_PARAMS="" local DISCOVERED_ENDPOINTS="" # 1. Crawl the homepage for links and forms print_sub "Crawling homepage for links..." local page=$(curl -s --connect-timeout 10 --max-time 20 -L "$target" 2>/dev/null) if [ -z "$page" ]; then print_error "Cannot fetch target page" return 1 fi # Extract all internal links local links=$(echo "$page" | perl -nle 'while (/href="([^"]+)"/g) { print $1 }' | sort -u) local internal_links="" while IFS= read -r link; do [ -z "$link" ] && continue # Make absolute if [[ "$link" == /* ]]; then link="${base}${link}" elif [[ "$link" == http* ]]; then # External link — skip unless same domain local link_domain=$(echo "$link" | sed 's|https\?://||' | cut -d/ -f1) [[ "$link_domain" != "$domain" ]] && continue else link="${base}/${link}" fi internal_links+="$link\n" DISCOVERED_URLS+="$link\n" done <<< "$links" local url_count=$(echo -e "$DISCOVERED_URLS" | grep -c .) print_ok "Found $url_count internal URLs" # 2. Extract forms print_sub "Extracting forms..." local forms=$(echo "$page" | perl -0 -nle 'while (/