Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

C 

Pastebin API using C (win32api)

Hello friends,

I've recently attempted to use the Pastebin API in a project i'm working on in C to utilise it as a C2 server. but I've had no such luck in making it work. Does anybody have any experience with this?? Or perhaps any pointers?? I've tried it with wininet but I guess winsock would be better (just for av evasion) but either one is fine.

Thanks in advance!
It’s pretty easy to implement a HTTP request using TCP sockets. Plenty of examples online.
(May 23, 2021 12:01 AM)Doomslayer Wrote:  It’s pretty easy to implement a HTTP request using TCP sockets. Plenty of examples online.

Could you list any examples? I found examples of GET requests but not so much for POST requests.
(May 30, 2021 02:15 PM)SIM-3437924 Wrote:  Could you list any examples? I found examples of GET requests but not so much for POST requests.

First result on google.

https://stackoverflow.com/questions/2207...e-response
(May 30, 2021 03:21 PM)Doomslayer Wrote:  First result on google.

https://stackoverflow.com/questions/2207...e-response

Hi, thank you for the link, it was very informative.

However my problems still remains, see the code below:
Code
char* HttpRequest() {
HINTERNET hInternet = InternetOpenA("YourUserAgent", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);

if (hInternet == NULL)
{
return "InternetOpenA failed(hInternet)";
}
else
{
HINTERNET hConnect = InternetConnectA(hInternet, "pastebin.com", 80, NULL, NULL, INTERNET_SERVICE_HTTP, 0, NULL);

if (hConnect == NULL)
{
return "InternetConnectA failed(hConnect == NULL)";
}
else
{
const char* parrAcceptTypes[] = { "*/*", NULL };

HINTERNET hRequest = HttpOpenRequestA(hConnect, "POST", "api/api_post.php", NULL, NULL, parrAcceptTypes, 0, 0);

if (hRequest == NULL)
{
return "HttpOpenRequestA failed(hRequest == NULL)";
}
else
{
char* hdrs = "Content-Type: application/x-www-form-urlencoded";
char* frmdata = "api_dev_key=MyAPIKey&api_option=paste&api_paste_code=TESTDATA&api_paste_private=0&api_paste_name=TEST&api_paste_expire_date=N";

BOOL bRequestSent = HttpSendRequestA(hRequest, hdrs, strlen(hdrs), frmdata, strlen(frmdata));

if (!bRequestSent)
{
return "!bRequestSent    HttpSendRequestA failed";
}
else
{
char strResponse[4096];
const int nBuffSize = 1024;
char buff[nBuffSize];

BOOL bKeepReading = TRUE;
DWORD dwBytesRead = -1;
DWORD BytesAvailable = 0;
do
{
InternetQueryDataAvailable(hRequest, &BytesAvailable, 0, 0);
bKeepReading = InternetReadFile(hRequest, buff, BytesAvailable, &dwBytesRead);
strncat(strResponse, buff, dwBytesRead);

} while (BytesAvailable && dwBytesRead != 0);

return strResponse;
}
InternetCloseHandle(hRequest);
}
InternetCloseHandle(hConnect);
}
InternetCloseHandle(hInternet);
}
}
(Code taken and modified from here)
This code is meant to create a paste on pastebin.

When returned, the output is "Bad API request, use POST request, not GET". So I seem to be making a GET request rather than a POST request... any suggestions on how to fix this?
I HIGHLY suggest using CURL. It is a mature library for http requests, literally made for this kind of task. You won't even have to call 1 winsock API function when you use CURL.
This'll do you well and works for me.

https://pastebin.com/b9fjki1y


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C] by aeiroJul 22, 2018 10:43 AM 4 208 Jul 22, 2018 10:43 AM
Last Post: aeiro
[Java] by GlushkoJun 13, 2018 11:13 PM 3 641 Jun 13, 2018 11:13 PM
Last Post: hostov
[C#] by gigajewApr 22, 2017 11:20 AM 2 222 Apr 22, 2017 11:20 AM
Last Post: Ninja