#!/usr/bin/env bash
# Windows Exploit Suggester (WES-NG) wrapper
# Analyzes systeminfo.txt and generates vulnerability reports
# Requires: systeminfo.txt in current directory, WES-NG cloned to ~/scripts/wesng

set -euo pipefail

# Colors for output
RED='\033[0;31m'
YELLOW='\033[0;33m'
GREEN='\033[0;32m'
NC='\033[0m' # No Color

cwd=$(basename "$PWD")

# Check for systeminfo.txt
if [ ! -f systeminfo.txt ]; then
    echo -e "${RED}Error:${NC} No 'systeminfo.txt' file found in '$PWD'"
    echo "Usage: Run 'systeminfo > systeminfo.txt' on target Windows machine"
    echo "       Then copy systeminfo.txt to your analysis directory"
    exit 1
fi

# Check for WES-NG installation
if [ ! -d "$HOME/scripts/wesng" ]; then
    echo -e "${YELLOW}⚠${NC} WES-NG not found at ~/scripts/wesng"
    echo "Clone it: git clone https://github.com/bitsadmin/wesng ~/scripts/wesng"
    exit 1
fi

# Navigate to WES-NG directory
cd "$HOME/scripts/wesng"

echo "Analyzing systeminfo.txt..."

# Generate reports
echo "  → All vulnerabilities..."
"$HOME/scripts/wesng/wes.py" "$OLDPWD/systeminfo.txt" -c -o "wes-${cwd}-vulns.txt"

echo "  → Critical vulnerabilities only..."
"$HOME/scripts/wesng/wes.py" "$OLDPWD/systeminfo.txt" -c -s critical > "wes-${cwd}-critical.txt"

echo "  → Remote Code Execution (RCE) vulnerabilities..."
"$HOME/scripts/wesng/wes.py" "$OLDPWD/systeminfo.txt" -c -i "Remote Code Execution" > "wes-${cwd}-rce.txt"

# Move reports back to analysis directory
mv "wes-${cwd}-vulns.txt" "wes-${cwd}-critical.txt" "wes-${cwd}-rce.txt" "$OLDPWD"

# Return to original directory
cd "$OLDPWD"

echo -e "${GREEN}✓${NC} WES analysis complete"
echo ""
echo "Reports generated:"
echo "  - wes-${cwd}-vulns.txt     (all vulnerabilities)"
echo "  - wes-${cwd}-critical.txt  (critical only)"
echo "  - wes-${cwd}-rce.txt       (RCE only)"
