Files
password-cracker/auto_crack.sh
2026-03-25 06:25:14 -07:00

477 lines
15 KiB
Bash

#!/bin/bash
# Auto-Crack Master Script
# Complete automation for CAP/PCAP cracking workflow
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
WORKSPACE_DIR="$SCRIPT_DIR"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# 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"
SCRIPTS_DIR="$WORKSPACE_DIR/scripts"
VERIFY_DIR="$WORKSPACE_DIR/verification"
LOG_FILE="$WORKSPACE_DIR/auto_crack.log"
# Function to print colored messages
print_info() {
echo -e "${BLUE}[INFO]${NC} $1"
}
print_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Function to log messages
log_message() {
local timestamp=$(date '+%Y-%m-%d %H:%M:%S')
echo "[$timestamp] $1" >> "$LOG_FILE"
echo "$1"
}
# Function to check system requirements
check_requirements() {
log_message "Checking system requirements..."
# Check if running in WSL
if grep -q Microsoft /proc/version 2>/dev/null; then
print_info "Running in WSL environment"
fi
# Check for required tools
local required_tools=("hashcat" "hcxpcapngtool" "curl" "wget" "sort" "uniq")
local missing_tools=()
for tool in "${required_tools[@]}"; do
if ! command -v "$tool" &> /dev/null; then
missing_tools+=("$tool")
fi
done
if [ ${#missing_tools[@]} -gt 0 ]; then
print_error "Missing required tools: ${missing_tools[*]}"
print_info "Attempting to install missing tools..."
# Try to install tools
if command -v apt &> /dev/null; then
sudo apt update && sudo apt install -y hashcat hcxtools curl wget coreutils
else
print_error "Cannot install tools automatically. Please install manually:"
print_error " sudo apt install hashcat hcxtools curl wget"
exit 1
fi
fi
print_success "All system requirements satisfied"
}
# Function to setup workspace
setup_workspace() {
log_message "Setting up workspace directories..."
# Create all necessary directories
mkdir -p "$INPUT_DIR" "$CONVERTED_DIR" "$WORDLIST_DIR" "$RULES_DIR" "$RESULTS_DIR" "$SCRIPTS_DIR" "$VERIFY_DIR"
# Create default rule if none exists
if [ ! -f "$RULES_DIR/custom.rule" ]; then
log_message "Creating default rule file..."
cp "$WORKSPACE_DIR/rules/custom.rule" "$RULES_DIR/" 2>/dev/null || true
fi
print_success "Workspace setup complete"
}
# Function to verify handshakes
verify_handshakes() {
log_message "Verifying handshakes in CAP/PCAP files..."
# Check for capture files
local capture_files=($(find "$INPUT_DIR" -type f \( -name "*.cap" -o -name "*.pcap" -o -name "*.pcapng" \) 2>/dev/null))
if [ ${#capture_files[@]} -eq 0 ]; then
print_warning "No CAP/PCAP files found to verify"
return 1
fi
print_info "Found ${#capture_files[@]} capture file(s) for verification"
# Run verification script if available
if [ -f "$SCRIPTS_DIR/verify_handshakes.sh" ]; then
chmod +x "$SCRIPTS_DIR/verify_handshakes.sh"
print_info "Running detailed handshake verification..."
"$SCRIPTS_DIR/verify_handshakes.sh"
local verify_status=$?
if [ $verify_status -eq 0 ]; then
print_success "Handshake verification complete"
return 0
else
print_warning "Handshake verification found issues"
return 1
fi
else
# Basic verification using hcxpcapngtool
print_info "Running basic handshake check..."
local valid_count=0
for capture_file in "${capture_files[@]}"; do
local filename=$(basename "$capture_file")
# Quick check for handshakes
local check_output=$(hcxpcapngtool -v "$capture_file" 2>&1 | grep -E "(EAPOL pairs|PMKID)" || true)
if echo "$check_output" | grep -q "EAPOL pairs: [1-9]" || echo "$check_output" | grep -q "PMKID(s): [1-9]"; then
print_success "$filename: Valid handshake found"
valid_count=$((valid_count + 1))
else
print_warning "$filename: No valid handshake"
fi
done
echo ""
print_info "Handshake verification summary:"
print_info " Total files: ${#capture_files[@]}"
print_info " Files with handshakes: $valid_count"
print_info " Files without handshakes: $((${#capture_files[@]} - valid_count))"
if [ $valid_count -eq 0 ]; then
print_error "No valid handshakes found in any file!"
print_info "Recapture is required before cracking can proceed."
return 1
elif [ $valid_count -lt ${#capture_files[@]} ]; then
print_warning "Some files are missing handshakes."
print_info "Consider recapturing or proceed with available handshakes."
return 0
else
print_success "All files have valid handshakes!"
return 0
fi
fi
}
# Function to build wordlists
build_wordlists() {
log_message "Building wordlists..."
# Check if wordlists already exist
local wordlist_count=$(find "$WORDLIST_DIR" -name "*.txt" -type f | wc -l)
if [ "$wordlist_count" -lt 3 ]; then
print_info "Wordlists not found or insufficient. Building..."
# Run the wordlist builder script if it exists
if [ -f "$SCRIPTS_DIR/build_wordlist.sh" ]; then
chmod +x "$SCRIPTS_DIR/build_wordlist.sh"
cd "$WORKSPACE_DIR"
"$SCRIPTS_DIR/build_wordlist.sh"
else
# Create a basic wordlist
print_info "Creating basic wordlist..."
cat > "$WORDLIST_DIR/basic_wordlist.txt" << 'EOF'
password
12345678
admin
welcome
qwerty
letmein
monkey
dragon
baseball
football
1234567890
password1
admin123
welcome1
qwerty123
EOF
# Download rockyou if possible
if command -v wget &> /dev/null; then
print_info "Downloading rockyou wordlist..."
wget -q -O "$WORDLIST_DIR/rockyou.txt.gz" "https://github.com/brannondorsey/naive-hashcat/releases/download/data/rockyou.txt.gz" 2>/dev/null || true
if [ -f "$WORDLIST_DIR/rockyou.txt.gz" ]; then
gunzip -f "$WORDLIST_DIR/rockyou.txt.gz" 2>/dev/null || true
fi
fi
fi
else
print_info "Using existing wordlists ($wordlist_count found)"
fi
# Create master wordlist by combining all wordlists
print_info "Creating master wordlist..."
find "$WORDLIST_DIR" -name "*.txt" -type f -exec cat {} \; | \
sort -u | \
grep -E '^.{8,63}$' > "$WORDLIST_DIR/master_wordlist.txt" 2>/dev/null || true
local master_count=$(wc -l < "$WORDLIST_DIR/master_wordlist.txt" 2>/dev/null || echo 0)
print_success "Wordlists built: $master_count entries in master wordlist"
}
# Function to process CAP/PCAP files
process_captures() {
log_message "Processing CAP/PCAP files..."
# Check for input files
local input_files=$(find "$INPUT_DIR" -type f \( -name "*.cap" -o -name "*.pcap" -o -name "*.pcapng" \) | wc -l)
if [ "$input_files" -eq 0 ]; then
print_warning "No CAP/PCAP files found in $INPUT_DIR/"
print_info "Please place your capture files in the input/ directory"
print_info "You can add files and run this script again"
return 1
fi
print_info "Found $input_files capture file(s)"
# Convert each capture file
local converted_count=0
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
print_info "Already converted: $filename"
continue
fi
print_info "Converting: $filename"
# Convert using hcxpcapngtool
if hcxpcapngtool -o "$output_file" "$capture_file" 2>/dev/null; then
print_success "Converted: $filename$(basename "$output_file")"
converted_count=$((converted_count + 1))
else
print_warning "Failed to convert: $filename (may not contain valid handshake)"
rm -f "$output_file" 2>/dev/null || true
fi
done
print_success "Conversion complete: $converted_count file(s) converted"
return 0
}
# Function to run cracking
run_cracking() {
log_message "Starting cracking process..."
# Check for hash files
local hash_files=($(find "$CONVERTED_DIR" -name "*.hc22000" -type f))
if [ ${#hash_files[@]} -eq 0 ]; then
print_error "No hash files found to crack"
print_info "Run conversion step first or check input files"
return 1
fi
print_info "Found ${#hash_files[@]} hash file(s) to crack"
# Select wordlist
local wordlist="$WORDLIST_DIR/master_wordlist.txt"
if [ ! -f "$wordlist" ]; then
wordlist=$(find "$WORDLIST_DIR" -name "*.txt" -type f | head -1)
fi
if [ ! -f "$wordlist" ]; then
print_error "No wordlist found"
return 1
fi
local wordlist_size=$(wc -l < "$wordlist" 2>/dev/null || echo 0)
print_info "Using wordlist: $(basename "$wordlist") ($wordlist_size entries)"
# Select rule
local rule_file=$(find "$RULES_DIR" -name "*.rule" -type f | head -1)
if [ ! -f "$rule_file" ]; then
print_warning "No rule file found, using straight dictionary attack"
rule_option=""
else
print_info "Using rule: $(basename "$rule_file")"
rule_option="-r $rule_file"
fi
# Crack each hash file
local cracked_count=0
for hash_file in "${hash_files[@]}"; do
local hash_filename=$(basename "$hash_file")
local output_file="$RESULTS_DIR/${hash_filename%.*}_cracked.txt"
print_info "Cracking: $hash_filename"
# Run hashcat
hashcat -m 22000 "$hash_file" "$wordlist" $rule_option \
--force \
--potfile-path="$RESULTS_DIR/potfile.txt" \
--outfile="$output_file" \
--outfile-format=2 2>&1 | tee -a "$LOG_FILE" | grep -E "(Status|Recovered|Progress)" || true
# Check if cracked
if hashcat --show -m 22000 "$hash_file" 2>/dev/null | grep -q .; then
print_success "CRACKED: $hash_filename"
cracked_count=$((cracked_count + 1))
# Save cracked passwords
hashcat --show -m 22000 "$hash_file" 2>/dev/null >> "$RESULTS_DIR/all_cracked.txt"
else
print_warning "NOT CRACKED: $hash_filename"
fi
echo ""
done
print_success "Cracking complete: $cracked_count/${#hash_files[@]} files cracked"
# Show summary
if [ -f "$RESULTS_DIR/all_cracked.txt" ]; then
echo ""
echo "=========================================="
echo "CRACKED PASSWORDS SUMMARY"
echo "=========================================="
cat "$RESULTS_DIR/all_cracked.txt"
echo "=========================================="
fi
return 0
}
# Function to generate report
generate_report() {
log_message "Generating final report..."
local report_file="$RESULTS_DIR/cracking_report_$(date +%Y%m%d_%H%M%S).txt"
cat > "$report_file" << EOF
CAP/PCAP Cracking Report
========================
Generated: $(date)
Workspace: $WORKSPACE_DIR
INPUT FILES
-----------
$(find "$INPUT_DIR" -type f \( -name "*.cap" -o -name "*.pcap" -o -name "*.pcapng" \) -exec basename {} \; | sort | sed 's/^/ /')
CONVERTED HASH FILES
--------------------
$(find "$CONVERTED_DIR" -name "*.hc22000" -type f -exec basename {} \; | sort | sed 's/^/ /')
WORDLIST STATISTICS
-------------------
Master wordlist: $(wc -l < "$WORDLIST_DIR/master_wordlist.txt" 2>/dev/null || echo "N/A") entries
Total wordlists: $(find "$WORDLIST_DIR" -name "*.txt" -type f | wc -l) files
CRACKING RESULTS
----------------
$(if [ -f "$RESULTS_DIR/all_cracked.txt" ]; then
echo "Cracked passwords:"
cat "$RESULTS_DIR/all_cracked.txt" | sed 's/^/ /'
else
echo "No passwords cracked"
fi)
HASHCAT POTFILE ENTRIES
-----------------------
$(if [ -f "$RESULTS_DIR/potfile.txt" ]; then
cat "$RESULTS_DIR/potfile.txt" | sed 's/^/ /'
else
echo "No potfile entries"
fi)
LOG FILE
--------
$LOG_FILE
EOF
print_success "Report generated: $report_file"
# Display report summary
echo ""
echo "=========================================="
echo "REPORT SUMMARY"
echo "=========================================="
tail -20 "$report_file"
}
# Main function
main() {
echo ""
echo "=========================================="
echo "AUTO-CRACK CAP/PCAP WORKFLOW"
echo "=========================================="
echo ""
# Initialize log
echo "Auto-Crack started at $(date)" > "$LOG_FILE"
# Step 1: Check requirements
check_requirements
# Step 2: Setup workspace
setup_workspace
# Step 3: Build wordlists
build_wordlists
# Step 4: Verify handshakes
if verify_handshakes; then
print_info "Handshake verification passed. Proceeding with cracking..."
# Step 5: Process captures
if process_captures; then
# Step 6: Run cracking
run_cracking
# Step 7: Generate report
generate_report
else
print_warning "No capture files to process"
print_info "Please add CAP/PCAP files to: $INPUT_DIR/"
print_info "Then run this script again"
fi
else
print_error "Handshake verification failed!"
print_info "Some files may not contain valid handshakes."
print_info "You can:"
print_info "1. Recapture handshakes and try again"
print_info "2. Run with --force to attempt cracking anyway"
print_info "3. Check verification reports in: $VERIFY_DIR/"
fi
echo ""
echo "=========================================="
echo "WORKFLOW COMPLETE"
echo "=========================================="
echo ""
echo "Next steps:"
echo "1. Add more CAP/PCAP files to: $INPUT_DIR/"
echo "2. Add custom wordlists to: $WORDLIST_DIR/"
echo "3. Add custom rules to: $RULES_DIR/"
echo "4. Run this script again to process new files"
echo ""
echo "Results available in: $RESULTS_DIR/"
echo "Log file: $LOG_FILE"
echo ""
}
# Run main function
main "$@"