~nighthawk/wep-cracker

63db22b2edc95334115b913d2f2adb7fceac764b — Frank Brodbeck 6 months ago 34e7b49
fixed whitespaces
1 files changed, 49 insertions(+), 47 deletions(-)

M wep-cracker.py
M wep-cracker.py => wep-cracker.py +49 -47
@@ 1,57 1,59 @@
import os, re, binascii, argparse, subprocess

def main(args):
        wep_bucket = bits_choices

        # passphrase lengths per WEP bit length
        # https://en.wikipedia.org/wiki/Wired_Equivalent_Privacy#Encryption_details
        passlen = {
                64: 5,
                128: 13,
        }

        # if args.bits was given, don't iterate over
        # all possible choices
        if args.bits == 64:
                wep_bucket = [ 64 ]
        elif args.bits == 128:
                wep_bucket = [ 128 ]

        if not os.path.isfile(args.pcap):
                print("[!] PCAP not found: {}".format(args.pcap))
                quit()

        print("[*] Starting dictionary attack on {}".format(args.pcap))
        for bits in wep_bucket:
                print("[-] Testing dictionary for {}-WEP".format(bits))
                with open(args.wordlist, "r", encoding = 'utf-8') as fp:
                        for line in fp:
                                passwd = line.strip()
                                if len(passwd) != passlen[bits]:
                                        continue
                                wpakey = binascii.hexlify(passwd.encode('utf-8')).decode('utf-8')

                                result = subprocess.check_output(["airdecap-ng", "-w", wpakey, args.pcap]).strip().splitlines()
                                if re.match("Number of decrypted WEP  packets\s+[1-9]", result[4].decode('utf-8')):
                                        print("[!] SUCCESS for {} hex {}".format(passwd, wpakey))
                                        quit()
        print("[?] FAILED. WPA key remains a secret.")
    wep_bucket = bits_choices

    # passphrase lengths per WEP bit length
    # https://en.wikipedia.org/wiki/Wired_Equivalent_Privacy#Encryption_details
    passlen = {
        64: 5,
        128: 13,
    }

    # if args.bits was given, don't iterate over
    # all possible choices
    if args.bits == 64:
        wep_bucket = [ 64 ]
    elif args.bits == 128:
        wep_bucket = [ 128 ]

    if not os.path.isfile(args.pcap):
        print("[!] PCAP not found: {}".format(args.pcap))
        quit()                print("[!] PCAP not found: {}".format(args.pcap))↩


    print("[*] Starting dictionary attack on {}".format(args.pcap))
    for bits in wep_bucket:
        print("[-] Testing dictionary for {}-WEP".format(bits))
        with open(args.wordlist, "r", encoding = 'utf-8') as fp:
            for line in fp:
                passwd = line.strip()
                if len(passwd) != passlen[bits]:
                    continue

                wpakey = binascii.hexlify(passwd.encode('utf-8')).decode('utf-8')

                result = subprocess.check_output(["airdecap-ng", "-w", wpakey, args.pcap]).strip().splitlines()
                if re.match("Number of decrypted WEP  packets\s+[1-9]", result[4].decode('utf-8')):
                    print("[!] SUCCESS for {} hex {}".format(passwd, wpakey))
                    quit()
    print("[?] FAILED. WPA key remains a secret.")


if __name__ == '__main__':
        bits_choices = [ 128, 64 ]
        parser = argparse.ArgumentParser(description = 'nighthawk\'s WEP airdecap-ng wrapper', add_help = False)
    bits_choices = [ 128, 64 ]
    parser = argparse.ArgumentParser(description = 'nighthawk\'s WEP airdecap-ng wrapper', add_help = False)

        # just give me one anonymous argument group
        myargs = parser.add_argument_group()
    # just give me one anonymous argument group
    myargs = parser.add_argument_group()

        # optional args
        myargs.add_argument('-h', help = "show this help message", action = "help")
        myargs.add_argument('-l', help = 'WEP bits. If none given all are tried.', required = False,
                choices = bits_choices, nargs = '?', dest = 'bits', type=int)
    # optional args
    myargs.add_argument('-h', help = "show this help message", action = "help")
    myargs.add_argument('-l', help = 'WEP bits. If none given all are tried.', required = False,
        choices = bits_choices, nargs = '?', dest = 'bits', type=int)

        # required args
        myargs.add_argument('-r', help = "PCAP with WEP traffic", required = True, dest = 'pcap')
        myargs.add_argument('-w', help = "wordlist", required = True, dest = 'wordlist')
    # required args
    myargs.add_argument('-r', help = "PCAP with WEP traffic", required = True, dest = 'pcap')
    myargs.add_argument('-w', help = "wordlist", required = True, dest = 'wordlist')

        main(parser.parse_args())
\ No newline at end of file
    main(parser.parse_args())