#!/bin/bash # Hashcat Cracking Pipeline for CAP/PCAP files # Automated workflow for WPA/WPA2 handshake cracking set -e SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" WORKSPACE_DIR="$(dirname "$SCRIPT_DIR")" # Configuration INPUT_DIR="$WORKSPACE_DIR/input" CONVERTED_DIR="$WORKSPACE_DIR/converted" WORDLIST_DIR="$WORKSPACE_DIR/wordlists" RULES_DIR="$WORKSPACE_DIR/rules" RESULTS_DIR="$WORKSPACE_DIR/results" LOG_DIR="$WORKSPACE_DIR/results/logs" # Hashcat settings HASHCAT_MODE="22000" # WPA/WPA2 PMKID/EAPOL POTFILE="$RESULTS_DIR/cracking_potfile.txt" HASHCAT_OPTIONS="--force --potfile-path=$POTFILE --outfile-format=2" # Create directories mkdir -p "$INPUT_DIR" "$CONVERTED_DIR" "$RESULTS_DIR" "$LOG_DIR" echo "==========================================" echo "Hashcat Cracking Pipeline" echo "==========================================" echo "Input directory: $INPUT_DIR" echo "Converted directory: $CONVERTED_DIR" echo "Results directory: $RESULTS_DIR" echo "" # Function to check if tools are installed check_tools() { echo "Checking required tools..." local missing_tools=() for tool in hashcat hcxpcapngtool; do if ! command -v "$tool" &> /dev/null; then missing_tools+=("$tool") fi done if [ ${#missing_tools[@]} -gt 0 ]; then echo "Error: Missing required tools: ${missing_tools[*]}" echo "Please install them with: sudo apt install hashcat hcxtools" exit 1 fi echo "✓ All tools are available" } # Function to convert CAP/PCAP to hashcat format convert_captures() { echo "" echo "Step 1: Converting CAP/PCAP files to hashcat format..." local converted_count=0 # Find all CAP/PCAP files find "$INPUT_DIR" -type f \( -name "*.cap" -o -name "*.pcap" -o -name "*.pcapng" \) | while read -r capture_file; do local filename=$(basename "$capture_file") local output_file="$CONVERTED_DIR/${filename%.*}.hc22000" # Skip if already converted if [ -f "$output_file" ]; then echo " Already converted: $filename" continue fi echo " Converting: $filename" # Convert using hcxpcapngtool if hcxpcapngtool -o "$output_file" "$capture_file" 2>/dev/null; then echo " → Success: $(basename "$output_file")" converted_count=$((converted_count + 1)) else echo " → Failed: $filename (may not contain valid handshake)" rm -f "$output_file" 2>/dev/null || true fi done echo " Total converted: $converted_count files" } # Function to select wordlist select_wordlist() { echo "" echo "Step 2: Selecting wordlist..." local wordlists=("$WORDLIST_DIR"/*.txt) if [ ${#wordlists[@]} -eq 0 ] || [ ! -f "${wordlists[0]}" ]; then echo " No wordlists found in $WORDLIST_DIR/" echo " Creating default wordlist..." # Create a simple default wordlist cat > "$WORDLIST_DIR/default_wordlist.txt" << 'EOF' password 12345678 admin welcome qwerty letmein monkey dragon baseball football EOF echo "$WORDLIST_DIR/default_wordlist.txt" return fi # Use master wordlist if available if [ -f "$WORDLIST_DIR/master_wordlist.txt" ]; then echo " Using: master_wordlist.txt" echo "$WORDLIST_DIR/master_wordlist.txt" return fi # Use the largest wordlist local largest_wordlist="" local largest_size=0 for wordlist in "${wordlists[@]}"; do local size=$(wc -l < "$wordlist" 2>/dev/null || echo 0) if [ "$size" -gt "$largest_size" ]; then largest_size=$size largest_wordlist="$wordlist" fi done echo " Using: $(basename "$largest_wordlist") ($largest_size entries)" echo "$largest_wordlist" } # Function to select rules select_rules() { echo "" echo "Step 3: Selecting rules..." local rules=("$RULES_DIR"/*.rule) if [ ${#rules[@]} -eq 0 ] || [ ! -f "${rules[0]}" ]; then echo " No rule files found in $RULES_DIR/" echo " Using default rules..." # Create a simple default rule cat > "$RULES_DIR/default.rule" << 'EOF' : l u c $0 $1 $2 $3 $4 $5 $6 $7 $8 $9 $! $$ $% ^! ^$ ^% sa@ so0 si1 se3 EOF echo "$RULES_DIR/default.rule" return fi # Return all rule files for rule in "${rules[@]}"; do echo " Available: $(basename "$rule")" done # Return the first rule for now (can be enhanced to use multiple) echo "${rules[0]}" } # Function to run hashcat cracking run_cracking() { local hash_file="$1" local wordlist="$2" local rule_file="$3" local hash_filename=$(basename "$hash_file") local output_file="$RESULTS_DIR/${hash_filename%.*}_cracked.txt" local log_file="$LOG_DIR/${hash_filename%.*}_$(date +%Y%m%d_%H%M%S).log" echo "" echo "Cracking: $hash_filename" echo " Wordlist: $(basename "$wordlist")" echo " Rule: $(basename "$rule_file")" echo " Output: $(basename "$output_file")" # Build hashcat command local hashcat_cmd="hashcat -m $HASHCAT_MODE $HASHCAT_OPTIONS" hashcat_cmd="$hashcat_cmd --outfile=\"$output_file\"" hashcat_cmd="$hashcat_cmd \"$hash_file\" \"$wordlist\" -r \"$rule_file\"" echo " Command: hashcat -m $HASHCAT_MODE ... -r $(basename "$rule_file")" # Run hashcat eval "$hashcat_cmd" 2>&1 | tee "$log_file" # Check if any passwords were cracked if hashcat --show -m "$HASHCAT_MODE" "$hash_file" 2>/dev/null | grep -q .; then echo " ✓ Success: Password(s) found!" hashcat --show -m "$HASHCAT_MODE" "$hash_file" 2>/dev/null | tail -5 else echo " ✗ No passwords found with this wordlist/rule" fi } # Function to display results show_results() { echo "" echo "==========================================" echo "Cracking Results Summary" echo "==========================================" local cracked_files=0 local total_files=0 # Count hash files for hash_file in "$CONVERTED_DIR"/*.hc22000; do if [ -f "$hash_file" ]; then total_files=$((total_files + 1)) if hashcat --show -m "$HASHCAT_MODE" "$hash_file" 2>/dev/null | grep -q .; then cracked_files=$((cracked_files + 1)) echo "✓ $(basename "$hash_file"): CRACKED" hashcat --show -m "$HASHCAT_MODE" "$hash_file" 2>/dev/null | while read -r line; do echo " $line" done else echo "✗ $(basename "$hash_file"): NOT CRACKED" fi fi done echo "" echo "Summary: $cracked_files/$total_files files cracked" if [ "$cracked_files" -gt 0 ]; then echo "" echo "Cracked passwords saved in:" find "$RESULTS_DIR" -name "*_cracked.txt" -type f | while read -r file; do echo " $file" done fi } # Main execution main() { check_tools # Convert CAP/PCAP files convert_captures # Check if we have any hash files to crack local hash_files=("$CONVERTED_DIR"/*.hc22000) if [ ${#hash_files[@]} -eq 0 ] || [ ! -f "${hash_files[0]}" ]; then echo "" echo "No hash files found in $CONVERTED_DIR/" echo "Please place CAP/PCAP files in $INPUT_DIR/ and run again." exit 1 fi # Select wordlist and rules local wordlist=$(select_wordlist) local rule_file=$(select_rules) echo "" echo "Step 4: Starting cracking process..." echo "==========================================" # Crack each hash file for hash_file in "${hash_files[@]}"; do if [ -f "$hash_file" ]; then run_cracking "$hash_file" "$wordlist" "$rule_file" fi done # Show results show_results echo "" echo "Pipeline complete! Check $RESULTS_DIR/ for detailed results." echo "Logs available in: $LOG_DIR/" } # Run main function main "$@"