?? aircrack-ng.c
字號:
/* * 802.11 WEP / WPA-PSK Key Cracker * * Copyright (C) 2006 Thomas d'Otreppe * Copyright (C) 2004,2005 Christophe Devine * * Advanced WEP attacks developed by KoreK * WPA-PSK attack code developed by Joshua Wright * SHA1 MMX assembly code written by Simon Marechal * * 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 of the License, 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 */#include <sys/types.h>#include <sys/termios.h>#include <sys/ioctl.h>#include <sys/wait.h>#include <sys/stat.h>#include <sys/time.h>#include <pthread.h>#include <unistd.h>#include <signal.h>#include <string.h>#include <stdlib.h>#include <stdio.h>#include <fcntl.h>#include <errno.h>#include <time.h>#include "version.h"#include "crypto.h"#include "pcap.h"#include "uniqueiv.c"#define SUCCESS 0#define FAILURE 1#define RESTART 2#ifndef O_BINARY#define O_BINARY 0#endif#define ASCII_LOW_T 0x21#define ASCII_HIGH_T 0x7E#define ASCII_VOTE_STRENGTH_T 150#define ASCII_DISREGARD_STRENGTH 1#define SWAP(x,y) { uchar tmp = x; x = y; y = tmp; }#ifdef __i386__extern int shammx_init( uchar ctx[40] )__attribute__((regparm(1)));extern int shammx_ends( uchar ctx[40], uchar digests[40] )__attribute__((regparm(2)));extern int shammx_data( uchar ctx[40], uchar data[128], uchar buf[640] )__attribute__((regparm(3)));#endifextern char * getVersion(char * progname, int maj, int min, int submin, int betavers);extern int getmac(char * macAddress, int strict, unsigned char * mac);#define BROADCAST "\xFF\xFF\xFF\xFF\xFF\xFF"static uchar ZERO[32] ="\x00\x00\x00\x00\x00\x00\x00\x00""\x00\x00\x00\x00\x00\x00\x00\x00""\x00\x00\x00\x00\x00\x00\x00\x00""\x00\x00\x00\x00\x00\x00\x00\x00";struct options{ int amode; /* attack mode */ int essid_set; /* essid set flag */ int bssid_set; /* bssid set flag */ char essid[33]; /* target ESSID */ uchar bssid[6]; /* target BSSID */ int nbcpu; /* # of cracker threads (= # of CPU) */ int is_quiet; /* quiet mode flag */ uchar debug[64]; /* user-defined WEP key */ int debug_row[64] ; /* user-defined Row WEP key */ uchar maddr[6]; /* MAC address filter */ int keylen; /* WEP key length */ int index; /* WEP key index */ float ffact; /* bruteforce factor */ int korek; /* attack strategy */ int is_fritz; /* use numeric keyspace */ int is_alnum; /* alphanum keyspace */ int is_bcdonly; /* binary coded decimal */ int do_brute; /* bruteforce last 2 KB */ int do_mt_brute; /* bruteforce last 2 KB multithreaded for SMP*/ int do_testy; /* experimental attack */ FILE *dict; /* dictionary file */ int no_stdin; /* if dict == stdin */ int showASCII; /* Show ASCII version of*/ /* the wepkey */ int l33t; /* no comment */}opt;typedef struct { int idx, val; }vote;struct WEP_data{ uchar key[64]; /* the current chosen WEP key */ uchar *ivbuf; /* buffer holding all the IVs */ int nb_aps; /* number of targeted APs */ long nb_ivs; /* # of unique IVs in buffer */ long nb_ivs_now; /* # of unique IVs available */ int fudge[64]; /* bruteforce level (1 to 256) */ int depth[64]; /* how deep we are in the fudge */ vote poll[64][256]; /* KoreK cryptanalysis results */}wep;struct WPA_hdsk{ uchar stmac[6]; /* supplicant MAC */ uchar snonce[32]; /* supplicant nonce */ uchar anonce[32]; /* authenticator nonce */ uchar keymic[16]; /* eapol frame MIC */ uchar eapol[256]; /* eapol frame contents */ int eapol_size; /* eapol frame size */ int keyver; /* key version (TKIP / AES) */ int state; /* handshake completion */};struct AP_info{ struct AP_info *next; /* next AP in linked list */ uchar bssid[6]; /* access point MAC address */ char essid[33]; /* access point identifier */ uchar lanip[4]; /* IP address if unencrypted */ uchar *ivbuf; /* table holding WEP IV data */ uchar **uiv_root; /* IV uniqueness root struct */ long ivbuf_size; /* IV buffer allocated size */ long nb_ivs; /* total number of unique IVs */ int crypt; /* encryption algorithm */ int eapol; /* set if EAPOL is present */ int target; /* flag set if AP is a target */ struct ST_info *st_1st; /* linked list of stations */ struct WPA_hdsk wpa; /* valid WPA handshake data */};struct ST_info{ struct AP_info *ap; /* parent AP */ struct ST_info *next; /* next supplicant */ struct WPA_hdsk wpa; /* WPA handshake data */ unsigned char stmac[6]; /* client MAC address */};/* stats global data */struct timeval t_begin; /* time at start of attack */struct timeval t_stats; /* time since last update */struct timeval t_kprev; /* time at start of window */long long int nb_kprev; /* last # of keys tried */long long int nb_tried; /* total # of keys tried *//* IPC global data */struct AP_info *ap_1st; /* first item in linked list */pthread_mutex_t mx_apl; /* lock write access to ap LL */pthread_mutex_t mx_eof; /* lock write access to nb_eof */pthread_cond_t cv_eof; /* read EOF condition variable */int nb_eof = 0; /* # of threads who reached eof */long nb_pkt = 0; /* # of packets read so far */int mc_pipe[256][2]; /* master->child control pipe */int cm_pipe[256][2]; /* child->master results pipe */int bf_pipe[256][2]; /* bruteforcer 'queue' pipe */int bf_nkeys[256];uchar bf_wepkey[64];int wepkey_crack_success = 0;#define N_ATTACKS 17enum KoreK_attacks{ A_u15, /* semi-stable 15% */ A_s13, /* stable 13% */ A_u13_1, /* unstable 13% */ A_u13_2, /* unstable ? 13% */ A_u13_3, /* unstable ? 13% */ A_s5_1, /* standard 5% (~FMS) */ A_s5_2, /* other stable 5% */ A_s5_3, /* other stable 5% */ A_u5_1, /* unstable 5% no good ? */ A_u5_2, /* unstable 5% */ A_u5_3, /* unstable 5% no good */ A_u5_4, /* unstable 5% */ A_s3, /* stable 3% */ A_4_s13, /* stable 13% on q = 4 */ A_4_u5_1, /* unstable 5% on q = 4 */ A_4_u5_2, /* unstable 5% on q = 4 */ A_neg /* helps reject false positives */};typedef struct{ int off1; int off2; void *buf1; void *buf2;}read_buf;int K_COEFF[N_ATTACKS] ={ 15, 13, 12, 12, 12, 5, 5, 5, 3, 4, 3, 4, 3, 13, 4, 4, -20};const uchar R[256] ={ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 , 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40 , 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60 , 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80 , 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100 , 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116 , 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132 , 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148 , 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164 , 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180 , 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196 , 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212 , 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228 , 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244 , 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255};char usage[] ="\n"" %s - (C) 2006 Thomas d\'Otreppe\n"" Original work: Christophe Devine\n"" http://www.aircrack-ng.org\n""\n"" usage: aircrack-ng [options] <.cap / .ivs file(s)>\n""\n"" Common options:\n""\n"" -a <amode> : force attack mode (1/WEP, 2/WPA-PSK)\n"" -e <essid> : target selection: network identifier\n"" -b <bssid> : target selection: access point's MAC""%s"" -q : enable quiet mode (no status output)\n""\n"" Static WEP cracking options:\n""\n"" -c : search alpha-numeric characters only\n"" -t : search binary coded decimal chr only\n"" -h : search the numeric key for Fritz!BOX\n"" -d <mask> : debug - specify mask of the key (A1:XX:CF)\n"" -m <maddr> : MAC address to filter usable packets\n"" -n <nbits> : WEP key length : 64/128/152/256/512\n"" -i <index> : WEP key index (1 to 4), default: any\n"" -f <fudge> : bruteforce fudge factor, default: 2\n"" -k <korek> : disable one attack method (1 to 17)\n"" -x or -x0 : disable last keybytes bruteforce\n"" -x1 : enable last keybyte bruteforcing (default)\n"" -x2 : enable last two keybytes bruteforcing\n"" -X : disable bruteforce multithreading (SMP only)\n"" -y : experimental single bruteforce mode\n"" -s : show ASCII version of the key\n""\n"" WPA-PSK cracking options:\n""\n"" -w <words> : path to a dictionary file\n"/*" -r <table> : path to a WPA PMK table\n" */"\n";char * progname;void eof_wait( int *eof_notified ){ if( *eof_notified == 0 ) { *eof_notified = 1; /* tell the master thread we reached EOF */ pthread_mutex_lock( &mx_eof ); nb_eof++; pthread_cond_broadcast( &cv_eof ); pthread_mutex_unlock( &mx_eof ); } usleep( 100000 );}/* fread isn't atomic, sadly */int atomic_read( read_buf *rb, int fd, int len, void *buf ){ int n; if( rb->buf1 == NULL ) { rb->buf1 = malloc( 65536 ); rb->buf2 = malloc( 65536 ); if( rb->buf1 == NULL || rb->buf2 == NULL ) return( 0 ); rb->off1 = 0; rb->off2 = 0; } if( len > 65536 - rb->off1 ) { rb->off2 -= rb->off1; memcpy( rb->buf2, rb->buf1 + rb->off1, rb->off2 ); memcpy( rb->buf1, rb->buf2, rb->off2 ); rb->off1 = 0; } if( rb->off2 - rb->off1 >= len ) { memcpy( buf, rb->buf1 + rb->off1, len ); rb->off1 += len; return( 1 ); } else { n = read( fd, rb->buf1 + rb->off2, 65536 - rb->off2 ); if( n <= 0 ) return( 0 ); rb->off2 += n; if( rb->off2 - rb->off1 >= len ) { memcpy( buf, rb->buf1 + rb->off1, len ); rb->off1 += len; return( 1 ); } } return( 0 );}void read_thread( void *arg ){ int fd, n, z, fmt; int eof_notified = 0; read_buf rb; uchar bssid[6]; uchar stmac[6]; uchar *buffer; uchar *h80211; uchar *p; struct pcap_pkthdr pkh; struct pcap_file_header pfh; struct AP_info *ap_prv, *ap_cur; struct ST_info *st_prv, *st_cur; memset( &rb, 0, sizeof( rb ) ); if( ( buffer = (uchar *) malloc( 65536 ) ) == NULL ) { /* there is no buffer */ perror( "malloc failed" ); goto read_fail; } h80211 = buffer; if( ! opt.is_quiet ) printf( "Opening %s\n", (char *) arg ); if( strcmp( arg, "-" ) == 0 ) fd = 0; else { if( ( fd = open( (char *) arg, O_RDONLY | O_BINARY ) ) < 0 ) { perror( "open failed" ); goto read_fail; } } if( ! atomic_read( &rb, fd, 4, &pfh ) ) { perror( "read(file header) failed" ); goto read_fail; } fmt = FORMAT_IVS; if( memcmp( &pfh, IVSONLY_MAGIC, 4 ) != 0 ) { fmt = FORMAT_CAP; if( pfh.magic != TCPDUMP_MAGIC && pfh.magic != TCPDUMP_CIGAM ) { fprintf( stderr, "Unsupported file format " "(not a pcap or IVs file).\n" ); goto read_fail; } /* read the rest of the pcap file header */ if( ! atomic_read( &rb, fd, 20, (uchar *) &pfh + 4 ) ) { perror( "read(file header) failed" ); goto read_fail; } /* take care of endian issues and check the link type */ if( pfh.magic == TCPDUMP_CIGAM ) SWAP32( pfh.linktype ); if( pfh.linktype != LINKTYPE_IEEE802_11 && pfh.linktype != LINKTYPE_PRISM_HEADER && pfh.linktype != LINKTYPE_RADIOTAP_HDR ) { fprintf( stderr, "This file is not a regular " "802.11 (wireless) capture.\n" ); goto read_fail; } } /* avoid blocking on reading the file */ if( fcntl( fd, F_SETFL, O_NONBLOCK ) < 0 ) { perror( "fcntl(O_NONBLOCK) failed" ); goto read_fail; } while( 1 ) { if( fmt == FORMAT_IVS ) { /* read one IV */ while( ! atomic_read( &rb, fd, 1, buffer ) ) eof_wait( &eof_notified ); if( buffer[0] != 0xFF ) { /* new access point MAC */ bssid[0] = buffer[0]; while( ! atomic_read( &rb, fd, 5, bssid + 1 ) ) eof_wait( &eof_notified ); } while( ! atomic_read( &rb, fd, 5, buffer ) ) eof_wait( &eof_notified ); } else { while( ! atomic_read( &rb, fd, sizeof( pkh ), &pkh ) ) eof_wait( &eof_notified ); if( pfh.magic == TCPDUMP_CIGAM ) SWAP32( pkh.caplen ); if( pkh.caplen <= 0 || pkh.caplen > 65535 ) { fprintf( stderr, "\nInvalid packet capture length %d - " "corrupted file?\n", pkh.caplen ); eof_wait( &eof_notified ); _exit( FAILURE ); } while( ! atomic_read( &rb, fd, pkh.caplen, buffer ) ) eof_wait( &eof_notified ); h80211 = buffer; if( pfh.linktype == LINKTYPE_PRISM_HEADER ) { /* remove the prism header */ if( h80211[7] == 0x40 ) n = 64; else { n = *(int *)( h80211 + 4 ); if( pfh.magic == TCPDUMP_CIGAM ) SWAP32( n ); } if( n < 8 || n >= (int) pkh.caplen ) continue; h80211 += n; pkh.caplen -= n; } if( pfh.linktype == LINKTYPE_RADIOTAP_HDR ) { /* remove the radiotap header */ n = *(unsigned short *)( h80211 + 2 ); if( n <= 0 || n >= (int) pkh.caplen ) continue; h80211 += n; pkh.caplen -= n; } } /* prevent concurrent access on the linked list */ pthread_mutex_lock( &mx_apl ); nb_pkt++; if( fmt == FORMAT_CAP ) { /* skip packets smaller than a 802.11 header */ if( pkh.caplen < 24 ) goto unlock_mx_apl; /* skip (uninteresting) control frames */ if( ( h80211[0] & 0x0C ) == 0x04 ) goto unlock_mx_apl; /* locate the access point's MAC address */ switch( h80211[1] & 3 ) { case 0: memcpy( bssid, h80211 + 16, 6 ); break; case 1: memcpy( bssid, h80211 + 4, 6 ); break; case 2: memcpy( bssid, h80211 + 10, 6 ); break; default: memcpy( bssid, h80211 + 4, 6 ); break; } } if( memcmp( bssid, BROADCAST, 6 ) == 0 ) /* probe request or such - skip the packet */ goto unlock_mx_apl; if( memcmp( opt.maddr, ZERO, 6 ) != 0 && memcmp( opt.maddr, BROADCAST, 6 ) != 0 ) { /* apply the MAC filter */ if( memcmp( opt.maddr, h80211 + 4, 6 ) != 0 && memcmp( opt.maddr, h80211 + 10, 6 ) != 0 && memcmp( opt.maddr, h80211 + 16, 6 ) != 0 ) goto unlock_mx_apl; } /* search the linked list */ ap_prv = NULL; ap_cur = ap_1st; while( ap_cur != NULL ) { if( ! memcmp( ap_cur->bssid, bssid, 6 ) ) break; ap_prv = ap_cur; ap_cur = ap_cur->next; } /* if it's a new access point, add it */ if( ap_cur == NULL ) { if( ! ( ap_cur = (struct AP_info *) malloc( sizeof( struct AP_info ) ) ) ) { perror( "malloc failed" ); break; } memset( ap_cur, 0, sizeof( struct AP_info ) ); if( ap_1st == NULL ) ap_1st = ap_cur; else ap_prv->next = ap_cur; memcpy( ap_cur->bssid, bssid, 6 );
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -