/* weplab - Wep Key Cracker Copyright (C) 2004 Jose Ignacio Sanchez Martin - Topo[LB] This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. --------- main.c: application entry point. */ #include #include #include #include #define _GNU_SOURCE #include #include #include "globals.h" #include "debug.h" #include "dictionary.h" #include "bruteforce.h" #include "heuristics.h" #include "analpfile.h" #include "capture.h" #include "attack.h" void ShowVersion(void){ printf("\n%s\n\n",PROGRAM_VERSION); exit(0); } void ShowBanner(void){ printf("%s Wep Key Cracker (%s).\n%s\n\n",PROGRAM_NAME, PROGRAM_VERSION, PROGRAM_AUTHOR); } void SimpleUsageMsg(char *programName){ ShowBanner(); printf("Usage: %s [-a|-b|-r|-y|-c] [-k ] [extended options] \n", programName); printf(" Modes:\n"); printf(" -a analyze pcap file and show information\n"); printf(" -y uses words (from stdin or wordfile) as wep keys\n"); printf(" -b brute forces wep keys\n"); printf(" -r uses statistical attacks to break the key\n"); printf(" -c capture encrypted data packets from a wireless interface\n"); printf(" -k [64|128] specifies 128 or 64 bits (default) key\n"); printf(" -h, --help display help about extended options\n"); printf("\n"); exit(1); } void UsageMsg(char *programName){ ShowBanner(); printf("Usage: %s [OPTIONS]... FILE\n", programName); printf(" Options:\n"); printf(" --debug prints debug information\n"); printf(" -v, --verbose print more information\n"); printf(" -y, --dictionary uses words (from stdin) as wep keys\n"); printf(" -k, --key [64|128] specifies 128 or 64 bits (default) key\n"); printf(" -b, --bruteforce brute forces wep keys\n"); printf(" -c, --capture capture encrypted data packets\n"); printf(" -i, --interface for capturing packets with --capture \n"); printf(" -r, --heuristics file uses weak keys and intelligent bruteforce\n"); printf(" -a, --analysis analyze file and get lite statistics\n"); printf(" -m, --multiprocess Assume of processes. Number must be between 1-64. Default 1.\n"); printf(" --caplen maximun length of captured packets with --capture (default 80) \n"); printf(" --fcs assume all captured frames has the FCS field\n"); printf(" --keyid just analyze specific id Wep packets. Only for 64 bits keys. (default 0)\n"); printf(" --prismheader assume all captured frames has the Prism header\n"); printf(" --allow_dups do not control packets with duplicated IVs\n"); printf(" --perc uses this minimun percentage of succeed when using FMS cracking\n"); printf(" --wordfile instead of reading words from stdin it uses this text file as wordfile for the dictionary attack\n"); printf(" --ascii just use bytes 0x00-0x7F for bruteforce wep key with --bruteforce\n"); printf(" --alpha just use bytes 0x41-0x7A for bruteforce wep key with --bruteforce\n"); printf(" --alnum just use bytes 0x30-0x7A for bruteforce wep key with --bruteforce\n"); printf(" --stability selects level of stability. Another way to specify which attacks, depending on their stability level, will be launched\n"); printf(" --debugkey Gives the real wep key to weplab to gather information about a crack. must be in the form of AA:BB:CC:DD... and may be incomplete.\n"); printf(" --attacks allows you to select which attacks will be used for heuristic mode.\n"); printf(" --bssid does only process those packets that belongs to specified BSSID\n"); printf(" -h, --help display this help and exit\n"); printf(" -V, --version output version information and exit\n"); printf("\n"); exit(1); } void ShowHelp(void){ char programName[2048]; sprintf(programName,"%s %s",PROGRAM_NAME, PROGRAM_VERSION); UsageMsg(programName); } void QuitParameterError(char *error){ printf("\n ERROR:"); printf(error); printf("\n\n Maybe you should take a look at the extended options (--help), read the manual (README) or visit the website http://weplab.sourceforge.net\n\n\n"); exit(1); } int hex2int(char buffer){ if (buffer=='0') return 0; else if (buffer=='1') return 1; else if (buffer=='2') return 2; else if (buffer=='3') return 3; else if (buffer=='4') return 4; else if (buffer=='5') return 5; else if (buffer=='6') return 6; else if (buffer=='7') return 7; else if (buffer=='8') return 8; else if (buffer=='9') return 9; else if (buffer=='A' || buffer=='a') return 10; else if (buffer=='B' || buffer=='b') return 11; else if (buffer=='C' || buffer=='c') return 12; else if (buffer=='D' || buffer=='d') return 13; else if (buffer=='E' || buffer=='e') return 14; else if (buffer=='F' || buffer=='f') return 15; else return 20; } int ReadHexByteArray(unsigned char *asciiByteArray, unsigned char *destination, int asciiByteArrayMaxSize){ int i,j; int total=0; unsigned char h1, h2; for (i=0; asciiByteArray[i]!=0 && asciiByteArray[i+1]!=0 && iNUMBER_ATTACKS || !atoi(saux)) QuitParameterError("attacks to be launched must be defined as positive numbers from 1 to 5 splitted by commas and no spaces"); defaultAttacks[STABILITY_LEVELS][atoi(saux)-1]=1; global_v.stability=0; saux=(&optarg[i])+1; } }else if (!strncmp(long_options[option_index].name,"keyid",50)){ totalArgvParameters+=2; if (!optarg || optarg[0]=='-' || totalArgvParameters == argc) QuitParameterError("keyid must be a positive number from 1 to 4"); global_v.keyid=atoi(optarg); }else if (!strncmp(long_options[option_index].name,"wordfile",50)){ totalArgvParameters+=2; if (!optarg || optarg[0]=='-' || totalArgvParameters == argc) QuitParameterError("you must specify a file to be used as wordfile"); strncpy(global_v.wordfile,optarg,255); }else if (!strncmp(long_options[option_index].name,"bssid",50)){ totalArgvParameters+=2; if (!optarg || optarg[0]=='-' || totalArgvParameters == argc) QuitParameterError("BSSID must be specified"); if (sscanf(optarg, "%x:%x:%x:%x:%x:%x", &tmp[0], &tmp[1], &tmp[2], &tmp[3], &tmp[4], &tmp[5]) < 6) { printf("unable to parse bssid\n"); exit(2); } for(i = 0; i < 6; i++) { global_v.target_bssid[i] = tmp[i] & 0xff; } global_v.target_bssid_selected = 1; }else if (!strncmp(long_options[option_index].name,"debugkey",50)){ totalArgvParameters+=2; if (!optarg || optarg[0]=='-' || totalArgvParameters == argc) QuitParameterError("debug key must be specified"); global_v.useDebugKey=ReadHexByteArray(optarg,global_v.debugKey,strlen(optarg)+1); if (global_v.useDebugKey==0){ printf("ERROR: you have to specify the key like AA:BB:CC:DD:EE \n"); exit (1); } } break; default: QuitParameterError("ERROR: unknown option.\n\n"); } } //debug("%u %u %u",option_index,argc,totalArgvParameters); if (totalArgvParameters != argc-1){ QuitParameterError("Take a look at the command line options help.\nPerhaps you have selected two pcap files instead of one.\n\n"); } strncpy(global_v.packetsFilename,argv[totalArgvParameters],200); if (!strcmp(global_v.weakPcapFilename,"")) strncpy(global_v.weakPcapFilename, global_v.packetsFilename, 200); if (optionSelected==1){ QuitParameterError("You must select 1 attack: dictionary, heuristics, brute force.\n\n"); } if (optionSelected>5){ QuitParameterError("You can just select 1 attack: dictionary, heuristics, brute force; or packets capture mode\n\n"); } if (keySize==128) global_v.key_len=13; else if (keySize!=64) { QuitParameterError("You must specify the key size. Sizes supported in this version: 64, 128\n\n"); } if (global_v.stability<0 || global_v.stability>STABILITY_LEVELS-1){ QuitParameterError("stability level must be between 1 and 5\n\n"); } if (global_v.processes<1 && global_v.processes>64){ QuitParameterError("Number of processors must be between 1 and 64.\n\n"); } ShowBanner(); #ifdef _DEBUG debug("Debug mode initialized"); debug("Using pcap version %s",pcap_lib_version()); #endif // Initializing S for KSA of rc4 for(i = 0; i < 256; i++) S_InitialBackup[i] = i; if (optionSelected==2) dictionary(); else if (optionSelected==3) heuristics(); else if (optionSelected==4) bruteforce(); else if (optionSelected==5) captureWeakPackets(); else if (optionSelected==0) AnalyzePcapFile(); #ifdef _DEBUG debug("Finishing the program..."); #endif return 0; }