-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
42 lines (40 loc) · 1.08 KB
/
main.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
#include <stdio.h>
#include <Windows.h>
void exitOnError(const char* message)
{
DWORD error = GetLastError();
if (error)
{
printf("[ ERROR %d ]: %s\n",error, message);
exit(error);
}
else
{
printf("[ OK ]: %s\n", message);
}
}
int main(int argc, char* argv[])
{
if (argc != 3)
{
printf("Usage: injector <PID> <DLL Path>");
}
else
{
UINT pathlen = strlen(argv[2]) + 1;
HANDLE h_process = OpenProcess(PROCESS_VM_OPERATION | PROCESS_VM_WRITE | PROCESS_CREATE_THREAD, FALSE, atoi(argv[1]));
exitOnError("OpenProcess");
LPVOID p_alloc = VirtualAllocEx(h_process, NULL, pathlen, MEM_COMMIT, PAGE_READWRITE);
exitOnError("VirtualAllocEx");
WriteProcessMemory(h_process, p_alloc, argv[2], pathlen, 0);
exitOnError("WriteProcessMemory");
HMODULE h_kernel32 = LoadLibraryA("kernel32.dll");
exitOnError("LoadLibraryA");
FARPROC loadLibrary = GetProcAddress(h_kernel32, "LoadLibraryA");
exitOnError("GetProcAddress");
CreateRemoteThread(h_process, NULL, 0, loadLibrary, p_alloc, 0, NULL);
exitOnError("CreateRemoteThread");
printf("DLL Loaded!");
}
return 0;
}