#!/usr/bin/env bash # The Analyzer - Report Generator SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" source "$SCRIPT_DIR/../lib/utils.sh" generate_report() { local target="$1" local report="$2" local findings="$3" echo "" print_info "Generating final report..." separator if [ -z "$findings" ] || [ "$findings" -eq 0 ]; then append_report "$report" "\n## Results\n\nNo vulnerabilities found during testing.\n" print_ok "No vulnerabilities found" finalize_report "$report" 0 0 print_report_summary "$report" return fi print_find "$findings vulnerabilities discovered!" # Append the findings to report append_report "$report" "\n## Vulnerabilities Found\n\n" local count=1 for f in "$REPORTS_DIR"/.finding_*.txt; do [ ! -f "$f" ] && continue local finding=$(cat "$f") local severity=$(echo "$finding" | grep "^SEVERITY:" | cut -d: -f2- | xargs) local vector=$(echo "$finding" | grep "^VECTOR:" | cut -d: -f2- | xargs) local detail=$(echo "$finding" | grep "^DETAIL:" | cut -d: -f2- | xargs) local evidence=$(echo "$finding" | grep "^EVIDENCE:" | cut -d: -f2- | xargs) local exploit=$(echo "$finding" | grep "^EXPLOIT:" | cut -d: -f2- | xargs) local severity_emoji="🟢" case "$severity" in CRITICAL) severity_emoji="🔴" ;; HIGH) severity_emoji="🟠" ;; MEDIUM) severity_emoji="🟡" ;; LOW) severity_emoji="🔵" ;; *) severity_emoji="⚪" ;; esac append_report "$report" "### $count. $vector\n" append_report "$report" "- **Severity:** $severity_emoji $severity\n" append_report "$report" "- **Detail:** $detail\n" [ -n "$evidence" ] && append_report "$report" "- **Evidence:** $evidence\n" [ -n "$exploit" ] && append_report "$report" "- **Exploitation:** $exploit\n" append_report "$report" "\n" count=$((count + 1)) done finalize_report "$report" $((count - 1)) $findings print_report_summary "$report" } print_report_summary() { local report="$1" echo "" separator echo -e " ${BRIGHT_GREEN}${ICON_DONE}${NC} ${BOLD}Analysis Complete!${NC}" echo -e " ${CYAN}${ICON_REPORT}${NC} Report: ${BOLD}$report${NC}" # Get count local vulns=$(grep -c "### [0-9]" "$report" 2>/dev/null) if [ "$vulns" -gt 0 ]; then echo "" echo -e " ${BRIGHT_RED}${BOLD}⚠ $vulns vulnerabilities found!${NC}" echo "" # List them grep "^### " "$report" | while read line; do sev=$(grep -A1 "$line" "$report" | grep "Severity:" | sed 's/.*\*\*Severity:\*\* //') echo -e " ${BRIGHT_RED}!${NC} $line ($sev)" done fi echo "" print_info "HTML version also saved: ${report%.md}.html" } # Generate HTML report from markdown html_report() { local md_report="$1" local html_report="${md_report%.md}.html" local domain=$(grep "^**Domain:**" "$md_report" | sed 's/.*\*\*Domain:\*\* //') local date=$(grep "^**Date:**" "$md_report" | sed 's/.*\*\*Date:\*\* //') # Count by severity local crit=$(grep -c "🔴" "$md_report" 2>/dev/null || echo 0) local high=$(grep -c "🟠" "$md_report" 2>/dev/null || echo 0) local med=$(grep -c "🟡" "$md_report" 2>/dev/null || echo 0) local low=$(grep -c "🔵" "$md_report" 2>/dev/null || echo 0) # Extract findings local findings_html="" local in_finding=false local finding_num="" local finding_title="" local finding_sev="" local finding_detail="" local finding_evidence="" local finding_exploit="" while IFS= read -r line; do if [[ "$line" =~ ^###\ ([0-9]+)\.\ (.*) ]]; then # Save previous finding if [ -n "$finding_title" ]; then local border_color="border-left: 4px solid #22c55e;" local badge_bg="#22c55e" case "$finding_sev" in *CRITICAL*) border_color="border-left: 4px solid #ef4444;"; badge_bg="#ef4444" ;; *HIGH*) border_color="border-left: 4px solid #f97316;"; badge_bg="#f97316" ;; *MEDIUM*) border_color="border-left: 4px solid #eab308;"; badge_bg="#eab308" ;; *LOW*) border_color="border-left: 4px solid #3b82f6;"; badge_bg="#3b82f6" ;; esac findings_html+="
" findings_html+="
" findings_html+="

${finding_num}. ${finding_title}

" findings_html+="${finding_sev//\*/}" findings_html+="
" [ -n "$finding_detail" ] && findings_html+="

${finding_detail}

" [ -n "$finding_evidence" ] && findings_html+="
${finding_evidence}
" [ -n "$finding_exploit" ] && findings_html+="
Exploit: ${finding_exploit}
" findings_html+="
" fi finding_num="${BASH_REMATCH[1]}" finding_title="${BASH_REMATCH[2]}" finding_sev="" finding_detail="" finding_evidence="" finding_exploit="" in_finding=true elif [[ "$line" =~ \*\*Severity:\*\*\ (.*) ]]; then finding_sev="${BASH_REMATCH[1]}" elif [[ "$line" =~ \*\*Detail:\*\*\ (.*) ]]; then finding_detail="${BASH_REMATCH[1]}" elif [[ "$line" =~ \*\*Evidence:\*\*\ (.*) ]]; then finding_evidence="${BASH_REMATCH[1]}" elif [[ "$line" =~ \*\*Exploitation:\*\*\ (.*) ]]; then finding_exploit="${BASH_REMATCH[1]}" fi done < "$md_report" # Last finding if [ -n "$finding_title" ]; then local border_color="border-left: 4px solid #22c55e;" local badge_bg="#22c55e" case "$finding_sev" in *CRITICAL*) border_color="border-left: 4px solid #ef4444;"; badge_bg="#ef4444" ;; *HIGH*) border_color="border-left: 4px solid #f97316;"; badge_bg="#f97316" ;; *MEDIUM*) border_color="border-left: 4px solid #eab308;"; badge_bg="#eab308" ;; *LOW*) border_color="border-left: 4px solid #3b82f6;"; badge_bg="#3b82f6" ;; esac findings_html+="
" findings_html+="
" findings_html+="

${finding_num}. ${finding_title}

" findings_html+="${finding_sev//\*/}" findings_html+="
" [ -n "$finding_detail" ] && findings_html+="

${finding_detail}

" [ -n "$finding_evidence" ] && findings_html+="
${finding_evidence}
" [ -n "$finding_exploit" ] && findings_html+="
Exploit: ${finding_exploit}
" findings_html+="
" fi local total_findings=$((crit + high + med + low)) cat > "$html_report" << HTML Analyzer Report - ${domain}

🔍 Analyzer Security Report

${domain}

${date}

${crit}
Critical
${high}
High
${med}
Medium
${low}
Low
Findings
${findings_html}
HTML echo "$html_report" }