Hack Forums
[C] Pastebin API using C (win32api) - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [C] Pastebin API using C (win32api) (/showthread.php?tid=6153373)



Pastebin API using C (win32api) - SIM-3437924 - May 11, 2021

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!


RE: Pastebin API using C (win32api) - Doomslayer - May 23, 2021

It’s pretty easy to implement a HTTP request using TCP sockets. Plenty of examples online.


RE: Pastebin API using C (win32api) - SIM-3437924 - May 30, 2021

(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.


RE: Pastebin API using C (win32api) - Doomslayer - May 30, 2021

(May 30, 2021 02:15 PM)AndyScott 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/22077802/simple-c-example-of-doing-an-http-post-and-consuming-the-response


RE: Pastebin API using C (win32api) - SIM-3437924 - Jun 5, 2021

(May 30, 2021 03:21 PM)Doomslayer Wrote:  First result on google.

https://stackoverflow.com/questions/22077802/simple-c-example-of-doing-an-http-post-and-consuming-the-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?


RE: Pastebin API using C (win32api) - BlueMoon1001 - Jul 1, 2021

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.


RE: Pastebin API using C (win32api) - sigmasmom - Jul 2, 2021

This'll do you well and works for me.

https://pastebin.com/b9fjki1y