-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinject.cpp
More file actions
67 lines (53 loc) · 1.82 KB
/
inject.cpp
File metadata and controls
67 lines (53 loc) · 1.82 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
#include <iostream>
#include <windows.h>
// Hi
bool Inject(DWORD procid, const std::string& dll) {
HANDLE handle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, procid);
if (handle == NULL) {
std::cout << "[!] Failed To Open Proccess";
return false;
}
std::cout << "[+] Opened Proccess";
LPVOID allocMem = VirtualAllocEx(handle, NULL, dll.size() + 1, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
if (allocMem == NULL) {
std::cerr << "[!] Failed to allocate memory";
CloseHandle(handle);
return false;
}
std::cout << "\n[+] Allocated Mem\n";
if (!WriteProcessMemory(handle, allocMem, dll.c_str(), dll.size() + 1, NULL)) {
std::cerr << "[!] Failed to write memory";
VirtualFreeEx(handle, allocMem, 0, MEM_RELEASE);
CloseHandle(handle);
return false;
}
FARPROC loadlib = GetProcAddress(GetModuleHandle("kernel32.dll"), "LoadLibraryA");
if (loadlib == NULL) {
std::cerr << "[!] Failed to get address of load lib A";
VirtualFreeEx(handle, allocMem, 0, MEM_RELEASE);
CloseHandle(handle);
return false;
}
HANDLE ht = CreateRemoteThread(handle, NULL, 0, (LPTHREAD_START_ROUTINE)loadlib, allocMem, 0, NULL);
if (ht == NULL) {
std::cerr << "[!] Failed to create remote thread";
VirtualFreeEx(handle, allocMem, 0, MEM_RELEASE);
CloseHandle(handle);
return false;
}
WaitForSingleObject(ht, INFINITE);
VirtualFreeEx(handle, allocMem, 0, MEM_RELEASE);
CloseHandle(ht);
CloseHandle(handle);
return true;
}
int main() {
DWORD procid = 17476;
std::string dll = "nigga.dll";
bool inject = Inject(procid, dll);
if (inject) {
std::cout << "[+] Injected DLL";
} else {
std::cout << "\n[!] Failed To Inject DLL";
}
}