-
Notifications
You must be signed in to change notification settings - Fork 0
/
http_req.cpp
83 lines (64 loc) · 2.49 KB
/
http_req.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include "http_req.hpp"
Http_req::Http_req() : url("google.de") {}
Http_req::~Http_req(){}
std::string Http_req::buffer;
int Http_req::writer(char *data, size_t size, size_t nmemb, std::string *buffer){
int result = 0;
if(buffer != NULL) {
buffer->append(data, size * nmemb);
result = size * nmemb;
}
return result;
}
std::string Http_req::POST(char* brute_pw) {
struct curl_httppost *formpost=NULL;
struct curl_httppost *lastptr=NULL;
struct curl_slist *headerlist=NULL;
for(un_int i = 0; i < Parameter.pInfos.names.size(); i++){
char* copycontents = const_cast<char*>(Parameter.pInfos.values.at(i).c_str());
if(*copycontents == '?') copycontents = brute_pw;
curl_formadd(&formpost,
&lastptr,
CURLFORM_COPYNAME, Parameter.pInfos.names.at(i).c_str(),
CURLFORM_COPYCONTENTS, Parameter.pInfos.values.at(i).c_str(),
CURLFORM_END);
}
curl = curl_easy_init();
headerlist = curl_slist_append(headerlist, buffer.c_str());
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, Parameter.pInfos.url.c_str());
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writer);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer);
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist);
curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
res = curl_easy_perform(curl);
if(res != CURLE_OK)
std::cout << "curl_easy_perform() faileds\n" << curl_easy_strerror(res) << std::endl;
curl_easy_cleanup(curl);
}
curl_formfree(formpost);
curl_slist_free_all (headerlist);
return buffer;
}
std::string Http_req::GET(char* brute_pw) {
curl = curl_easy_init();
std::string url_sendstr = Parameter.pInfos.url;
for(un_int i = 0; i < Parameter.pInfos.names.size(); i++){
i == 0 ? url_sendstr += '?' : url_sendstr += '&';
url_sendstr.append(Parameter.pInfos.names.at(i));
url_sendstr += '=';
url_sendstr.append(Parameter.pInfos.values.at(i));
}
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, url_sendstr.c_str());
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writer);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer);
res = curl_easy_perform(curl);
if(res != CURLE_OK)
std::cout << "curl_easy_perform() faileds\n" << curl_easy_strerror(res) << std::endl;
curl_easy_cleanup(curl);
}
return buffer;
}