-
Notifications
You must be signed in to change notification settings - Fork 0
/
vanillaInjector.c
33 lines (25 loc) · 1.16 KB
/
vanillaInjector.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
// changes need to be made accordingly. this is a sample code to help with understanding the flow of Vanilla Injection Technique
#include <stdio.h>
#include <Windows.h>
#include <string.h>
#include <TlHelp32.h>
int main() {
const char* TargetDLLPath = "Path to dll file";
DWORD CurrentProcID = GetCurrentProcessId();
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, CurrentProcID);
if (hProcess) {
LPVOID remoteString = VirtualAllocEx(hProcess, NULL, strlen(TargetDLLPath) + 1, MEM_COMMIT, PAGE_READWRITE);
WriteProcessMemory(hProcess, remoteString, TargetDLLPath, strlen(TargetDLLPath) + 1, NULL);
FARPROC LoadLibrary = GetProcAddress(GetModuleHandle("kernel32.dll"), "LoadLibraryA");
HANDLE hThread = CreateRemoteThread(hProcess, NULL, 0, (LPTHREAD_START_ROUTINE)LoadLibrary, remoteString, 0, NULL);
WaitForSingleObject(hThread, INFINITE);
CloseHandle(hThread);
VirtualFreeEx(hProcess, remoteString, 0, MEM_RELEASE);
CloseHandle(hProcess);
printf("DLL Injected \n");
}
else {
printf("Failed to open current process (PID %d)\n", CurrentProcID);
}
return 0;
}