⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 aircrack-ng.c

📁 java softwar for you to send out the request
💻 C
📖 第 1 页 / 共 5 页
字号:
			ap_cur->crypt = -1;		}		if( fmt == FORMAT_IVS )		{			ap_cur->crypt = 2;			add_wep_iv:			/* check for uniqueness first */			if( ap_cur->nb_ivs == 0 )				ap_cur->uiv_root = uniqueiv_init();			if( uniqueiv_check( ap_cur->uiv_root, buffer ) == 0 )			{				/* add the IV & first two encrypted bytes */				n = ap_cur->nb_ivs * 5;				if( n + 5 > ap_cur->ivbuf_size )				{					/* enlarge the IVs buffer */					ap_cur->ivbuf_size += 131072;					ap_cur->ivbuf = (uchar *) realloc(						ap_cur->ivbuf, ap_cur->ivbuf_size );					if( ap_cur->ivbuf == NULL )					{						perror( "realloc failed" );						break;					}				}				memcpy( ap_cur->ivbuf + n, buffer, 5 );				uniqueiv_mark( ap_cur->uiv_root, buffer );				ap_cur->nb_ivs++;			}			goto unlock_mx_apl;		}		/* locate the station MAC in the 802.11 header */		st_cur = NULL;		switch( h80211[1] & 3 )		{			case  0: memcpy( stmac, h80211 + 10, 6 ); break;			case  1: memcpy( stmac, h80211 + 10, 6 ); break;			case  2:				/* reject broadcast MACs */				if( h80211[4] != 0 ) goto skip_station;				memcpy( stmac, h80211 +  4, 6 ); break;			default: goto skip_station; break;		}		st_prv = NULL;		st_cur = ap_cur->st_1st;		while( st_cur != NULL )		{			if( ! memcmp( st_cur->stmac, stmac, 6 ) )				break;			st_prv = st_cur;			st_cur = st_cur->next;		}		/* if it's a new supplicant, add it */		if( st_cur == NULL )		{			if( ! ( st_cur = (struct ST_info *) malloc(				sizeof( struct ST_info ) ) ) )			{				perror( "malloc failed" );				break;			}			memset( st_cur, 0, sizeof( struct ST_info ) );			if( ap_cur->st_1st == NULL )				ap_cur->st_1st = st_cur;			else				st_prv->next = st_cur;			memcpy( st_cur->stmac, stmac, 6 );		}		skip_station:		/* packet parsing: Beacon or Probe Response */		if( h80211[0] == 0x80 ||			h80211[0] == 0x50 )		{			if( ap_cur->crypt < 0 )				ap_cur->crypt = ( h80211[34] & 0x10 ) >> 4;			p = h80211 + 36;			while( p < h80211 + pkh.caplen )			{				if( p + 2 + p[1] > h80211 + pkh.caplen )					break;				if( p[0] == 0x00 && p[1] > 0 && p[2] != '\0' )				{					/* found a non-cloaked ESSID */					n = ( p[1] > 32 ) ? 32 : p[1];					memset( ap_cur->essid, 0, 33 );					memcpy( ap_cur->essid, p + 2, n );				}				p += 2 + p[1];			}		}		/* packet parsing: Association Request */		if( h80211[0] == 0x00 )		{			p = h80211 + 28;			while( p < h80211 + pkh.caplen )			{				if( p + 2 + p[1] > h80211 + pkh.caplen )					break;				if( p[0] == 0x00 && p[1] > 0 && p[2] != '\0' )				{					n = ( p[1] > 32 ) ? 32 : p[1];					memset( ap_cur->essid, 0, 33 );					memcpy( ap_cur->essid, p + 2, n );				}				p += 2 + p[1];			}		}		/* packet parsing: Association Response */		if( h80211[0] == 0x10 )		{			/* reset the WPA handshake state */			if( st_cur != NULL )				st_cur->wpa.state = 0;		}		/* check if data */		if( ( h80211[0] & 0x0C ) != 0x08 )			goto unlock_mx_apl;		/* check minimum size */		z = ( ( h80211[1] & 3 ) != 3 ) ? 24 : 30;		if( z + 16 > (int) pkh.caplen )			goto unlock_mx_apl;		/* check the SNAP header to see if data is encrypted */		if( h80211[z] != h80211[z + 1] || h80211[z + 2] != 0x03 )		{			ap_cur->crypt = 2;	 /* encryption = WEP */			/* check the extended IV flag */			if( ( h80211[z + 3] & 0x20 ) != 0 )								 /* encryption = WPA */					ap_cur->crypt = 3;			/* check the WEP key index */			if( opt.index != 0 &&				( h80211[z + 3] >> 6 ) != opt.index - 1 )				goto unlock_mx_apl;			/* save the IV & first two output bytes */			memcpy( buffer    , h80211 + z    , 3 );			memcpy( buffer + 3, h80211 + z + 4, 2 );			goto add_wep_iv;		}		if( ap_cur->crypt < 0 )			ap_cur->crypt = 0;	 /* no encryption */		/* if ethertype == IPv4, find the LAN address */		z += 6;		if( z + 20 < (int) pkh.caplen )		{			if( h80211[z] == 0x08 && h80211[z + 1] == 0x00 &&				( h80211[1] & 3 ) == 0x01 )				memcpy( ap_cur->lanip, &h80211[z + 14], 4 );			if( h80211[z] == 0x08 && h80211[z + 1] == 0x06 )				memcpy( ap_cur->lanip, &h80211[z + 16], 4 );		}		/* check ethertype == EAPOL */		if( h80211[z] != 0x88 || h80211[z + 1] != 0x8E )			goto unlock_mx_apl;		z += 2;		ap_cur->eapol = 1;		/* type == 3 (key), desc. == 254 (WPA) or 2 (RSN) */		if( h80211[z + 1] != 0x03 ||			( h80211[z + 4] != 0xFE && h80211[z + 4] != 0x02 ) )			goto unlock_mx_apl;		ap_cur->eapol = 0;		ap_cur->crypt = 3;		 /* set WPA */		if( st_cur == NULL )			continue;		/* frame 1: Pairwise == 1, Install == 0, Ack == 1, MIC == 0 */		if( ( h80211[z + 6] & 0x08 ) != 0 &&			( h80211[z + 6] & 0x40 ) == 0 &&			( h80211[z + 6] & 0x80 ) != 0 &&			( h80211[z + 5] & 0x01 ) == 0 )		{			memcpy( st_cur->wpa.anonce, &h80211[z + 17], 32 );								 /* authenticator nonce set */			st_cur->wpa.state = 1;		}		/* frame 2 or 4: Pairwise == 1, Install == 0, Ack == 0, MIC == 1 */		if( ( h80211[z + 6] & 0x08 ) != 0 &&			( h80211[z + 6] & 0x40 ) == 0 &&			( h80211[z + 6] & 0x80 ) == 0 &&			( h80211[z + 5] & 0x01 ) != 0 )		{			if( memcmp( &h80211[z + 17], ZERO, 32 ) != 0 )			{				memcpy( st_cur->wpa.snonce, &h80211[z + 17], 32 );								 /* supplicant nonce set */				st_cur->wpa.state |= 2;			}		}		/* frame 3: Pairwise == 1, Install == 1, Ack == 1, MIC == 1 */		if( ( h80211[z + 6] & 0x08 ) != 0 &&			( h80211[z + 6] & 0x40 ) != 0 &&			( h80211[z + 6] & 0x80 ) != 0 &&			( h80211[z + 5] & 0x01 ) != 0 )		{			if( memcmp( &h80211[z + 17], ZERO, 32 ) != 0 )			{				memcpy( st_cur->wpa.anonce, &h80211[z + 17], 32 );								 /* authenticator nonce set */				st_cur->wpa.state |= 4;			}			/* copy the MIC & eapol frame */			st_cur->wpa.eapol_size = ( h80211[z + 2] << 8 )				+   h80211[z + 3] + 4;			memcpy( st_cur->wpa.keymic, &h80211[z + 81], 16 );			memcpy( st_cur->wpa.eapol,  &h80211[z], st_cur->wpa.eapol_size );			memset( st_cur->wpa.eapol + 81, 0, 16 );								 /* eapol frame & keymic set */			st_cur->wpa.state |= 8;			/* copy the key descriptor version */			st_cur->wpa.keyver = h80211[z + 6] & 7;		}		if( st_cur->wpa.state == 15 )		{			/* got one valid handshake */			memcpy( st_cur->wpa.stmac, stmac, 6 );			memcpy( &ap_cur->wpa, &st_cur->wpa,				sizeof( struct WPA_hdsk ) );		}		unlock_mx_apl:		pthread_mutex_unlock( &mx_apl );	}	read_fail:	kill( 0, SIGTERM );	_exit( FAILURE );}/* timing routine */float chrono( struct timeval *start, int reset ){	float delta;	struct timeval current;	gettimeofday( &current, NULL );	delta = ( current.tv_sec  - start->tv_sec  ) + (float)		( current.tv_usec - start->tv_usec ) / 1000000;	if( reset )		gettimeofday( start, NULL );	return( delta );}/* signal-safe I/O routines */int safe_read( int fd, void *buf, size_t len ){	int n;	size_t sum = 0;	char  *off = (char *) buf;	while( sum < len )	{		if( ! ( n = read( fd, (void *) off, len - sum ) ) )			return( 0 );		if( n < 0 && errno == EINTR ) continue;		if( n < 0 ) return( n );		sum += n;		off += n;	}	return( sum );}int safe_write( int fd, void *buf, size_t len ){	int n;	size_t sum = 0;	char  *off = (char *) buf;	while( sum < len )	{		if( ( n = write( fd, (void *) off, len - sum ) ) < 0 )		{			if( errno == EINTR ) continue;			return( n );		}		sum += n;		off += n;	}	return( sum );}/* each thread computes the votes over a subset of the IVs */int crack_wep_thread( void *arg ){	long xv, min, max;	uchar jj[256];	uchar S[256], Si[256];	uchar K[64];	uchar io1, o1, io2, o2;	uchar Sq, dq, Kq, jq, q;	uchar S1, S2, J2, t2;	int i, j, B, cid = (long) arg;	int votes[N_ATTACKS][256];	while( 1 )	{		if( safe_read( mc_pipe[cid][0], (void *) &B,			sizeof( int ) ) != sizeof( int ) )		{			perror( "read failed" );			kill( 0, SIGTERM );			_exit( FAILURE );		}		min = 5 * ( ( (     cid ) * wep.nb_ivs ) / opt.nbcpu );		max = 5 * ( ( ( 1 + cid ) * wep.nb_ivs ) / opt.nbcpu );		q = 3 + B;		memcpy( K + 3, wep.key, B );		memset( votes, 0, sizeof( votes ) );		/* START: KoreK attacks */		for( xv = min; xv < max; xv += 5 )		{			memcpy( K, &wep.ivbuf[xv], 3 );			memcpy( S,  R, 256 );			memcpy( Si, R, 256 );			for( i = j = 0; i < q; i++ )			{				jj[i] = j = ( j + S[i] + K[i % (3 + opt.keylen)] ) & 0xFF;				SWAP( S[i], S[j] );			}			i = q; do { i--; SWAP(Si[i],Si[jj[i]]); }			while( i != 0 );			o1 = wep.ivbuf[xv + 3] ^ 0xAA; io1 = Si[o1]; S1 = S[1];			o2 = wep.ivbuf[xv + 4] ^ 0xAA; io2 = Si[o2]; S2 = S[2];			Sq = S[q]; dq = Sq + jj[q - 1];			if( S2 == 0 )			{				if( ( S1 == 2 ) && ( o1 == 2 ) )				{					Kq = 1 - dq; votes[A_neg][Kq]++;					Kq = 2 - dq; votes[A_neg][Kq]++;				}				else if( o2 == 0 )				{					Kq = 2 - dq; votes[A_neg][Kq]++;				}			}			else			{				if( ( o2 == 0 ) && ( Sq == 0 ) )				{					Kq = 2 - dq; votes[A_u15][Kq]++;				}			}			if( ( S1 == 1 ) && ( o1 == S2 ) )			{				Kq = 1 - dq; votes[A_neg][Kq]++;				Kq = 2 - dq; votes[A_neg][Kq]++;			}			if( ( S1 == 0 ) && ( S[0] == 1 ) && ( o1 == 1 ) )			{				Kq = 0 - dq; votes[A_neg][Kq]++;				Kq = 1 - dq; votes[A_neg][Kq]++;			}			if( S1 == q )			{				if( o1 == q )				{					Kq = Si[0] - dq; votes[A_s13][Kq]++;				}				else if( ( ( 1 - q - o1 ) & 0xFF ) == 0 )				{					Kq = io1 - dq; votes[A_u13_1][Kq]++;				}				else if( io1 < q )				{					jq = Si[( io1 - q ) & 0xFF];					if( jq != 1 )					{						Kq = jq - dq; votes[A_u5_1][Kq]++;					}				}			}			if( ( io1 == 2 ) && ( S[q] == 1 ) )			{				Kq = 1 - dq; votes[A_u5_2][Kq]++;			}			if( S[q] == q )			{				if( ( S1 == 0 ) && ( o1 == q ) )				{					Kq = 1 - dq; votes[A_u13_2][Kq]++;				}				else if( ( ( ( 1 - q - S1 ) & 0xFF ) == 0 ) && ( o1 == S1 ) )				{					Kq = 1 - dq; votes[A_u13_3][Kq]++;				}				else if( ( S1 >= ( ( -q ) & 0xFF ) )					&& ( ( ( q + S1 - io1 ) & 0xFF ) == 0 ) )				{					Kq = 1 - dq; votes[A_u5_3][Kq]++;				}			}			if( ( S1 < q ) && ( ( ( S1 + S[S1] - q ) & 0xFF ) == 0 )  &&				( io1 != 1 ) && ( io1 != S[S1] ) )			{				Kq = io1 - dq; votes[A_s5_1][Kq]++;			}			if( ( S1 > q ) && ( ( ( S2 + S1 - q ) & 0xFF ) == 0 ) )			{				if( o2 == S1 )				{					jq = Si[(S1 - S2) & 0xFF];					if( ( jq != 1 ) && ( jq != 2 ) )					{						Kq = jq - dq; votes[A_s5_2][Kq]++;					}				}				else if( o2 == ( ( 2 - S2 ) & 0xFF ) )				{					jq = io2;					if( ( jq != 1 ) && ( jq != 2 ) )					{						Kq = jq - dq; votes[A_s5_3][Kq]++;					}				}			}			if( ( S[1] != 2 ) && ( S[2] != 0 ) )			{				J2 = S[1] + S[2];				if( J2 < q )				{					t2 = S[J2] + S[2];					if( ( t2 == q ) && ( io2 != 1 ) && ( io2 != 2 )						&& ( io2 != J2 ) )					{						Kq = io2 - dq; votes[A_s3][Kq]++;					}				}			}			if( S1 == 2 )			{				if( q == 4 )				{					if( o2 == 0 )					{						Kq = Si[0] - dq; votes[A_4_s13][Kq]++;					}					else					{						if( ( jj[1] == 2 ) && ( io2 == 0 ) )						{							Kq = Si[254] - dq; votes[A_4_u5_1][Kq]++;						}						if( ( jj[1] == 2 ) && ( io2 == 2 ) )						{							Kq = Si[255] - dq; votes[A_4_u5_2][Kq]++;						}					}				}				else if( ( q > 4 ) && ( ( S[4] + 2 ) == q ) &&					( io2 != 1 ) && ( io2 != 4 ) )				{					Kq = io2 - dq; votes[A_u5_4][Kq]++;				}			}		}		/* END: KoreK attacks */		if( safe_write( cm_pipe[cid][1], votes,			sizeof( votes ) ) != sizeof( votes ) )		{			perror( "write failed" );			kill( 0, SIGTERM );			_exit( FAILURE );		}	}	return( 0 );}/* display the current votes */void show_wep_stats( int B, int force ){	float delta;	struct winsize ws;	int i, et_h, et_m, et_s;	static int is_cleared = 0;	if( ioctl( 0, TIOCGWINSZ, &ws ) < 0 )	{		ws.ws_row = 25;		ws.ws_col = 80;	}	if( (chrono( &t_stats, 0 ) < 1.51 || wepkey_crack_success) && force == 0 )		return;	chrono( &t_stats, 1 );	delta = chrono( &t_begin, 0 );	et_h =   delta / 3600;	et_m = ( delta - et_h * 3600 ) / 60;	et_s =   delta - et_h * 3600 - et_m * 60;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -