#!/bin/bash # Bash script to process a CSV file containing vulnerability data exported from 'msfconsole'. # It identifies Common Vulnerabilities and Exposures (CVEs) and uses searchsploit to find exploits for each CVE. # The script expects a CSV file with columns for Timestamp, IP Address, Description, and Identifiers. # Function to display usage information usage() { echo "Usage: $0 " echo "The script processes a CSV file with columns for Timestamp, IP Address, Description, and Identifiers." echo "This file is typically an export from 'msfconsole'." echo "Example: $0 vulnerabilities.csv" exit 1 } # Function to display help information help() { echo "Help:" echo "This script analyzes a CSV file of vulnerabilities and finds exploits for identified CVEs." echo "It creates a directory with text files containing details of exploits for each CVE." usage } # Check if the -h option is used if [ "$1" == "-h" ]; then help exit 0 fi # Check if a file is provided and exists if [ "$#" -ne 1 ] || [ ! -f "$1" ]; then usage fi INPUT_FILE="$1" OUTPUT_DIR="cve_exploit_details" CVE_COUNT=0 EXPLOIT_FOUND_COUNT=0 # Create output directory if it does not exist mkdir -p "$OUTPUT_DIR" # Color settings using tput RED=$(tput setaf 1) GREEN=$(tput setaf 2) BLUE=$(tput setaf 4) RESET=$(tput sgr0) BOLD=$(tput bold) # Create an associative array to store CVE and corresponding IP addresses declare -A cve_ips # Read the file and populate the array # The CSV format is: Timestamp, IP Address, Description, Identifiers while IFS=',' read -r timestamp ip description identifiers; do for identifier in $identifiers; do if [[ $identifier =~ CVE-[0-9]{4}-[0-9]+ ]]; then cve_ips["$identifier"]+="$ip " ((CVE_COUNT++)) fi done done < "$INPUT_FILE" # Process each CVE for CVE_ID in "${!cve_ips[@]}"; do # Use searchsploit to find exploits for the CVE RESULT=$(searchsploit --cve $CVE_ID 2>&1 | grep '|' | grep -v 'No Results') if [ ! -z "$RESULT" ] && [ "$RESULT" != *'No exploit found'* ]; then OUTPUT_FILE="${OUTPUT_DIR}/${CVE_ID}.txt" ((EXPLOIT_FOUND_COUNT++)) { echo -e "${BOLD}${RED}CVE ID: $CVE_ID" echo -e "Affected IPs: ${cve_ips[$CVE_ID]}${RESET}" echo -e "${GREEN}Exploits Found:${RESET}" echo "$RESULT" | grep -v -- '----' | awk -v BLUE="$BLUE" -v RESET="$RESET" -F '|' '{printf " %sTitle:%s %s\n %sPath:%s %s\n\n", BLUE, RESET, $1, BLUE, RESET, $2}' | sed '/Exploit: Exploit Title/d' } > "$OUTPUT_FILE" cat "$OUTPUT_FILE" # Print the content to the console as well fi done # Print message if no exploits are found for any CVEs if [ $EXPLOIT_FOUND_COUNT -eq 0 ] && [ $CVE_COUNT -gt 0 ]; then echo -e "${BOLD}${GREEN}No exploits were found for any of the $CVE_COUNT CVEs checked from '$INPUT_FILE'.${RESET}" fi