Skip to content

Commit 1944a19

Browse files
committed
Shellcode test injector
1 parent 0591e91 commit 1944a19

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

Shellcodev/command.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ static BOOL winrepl_command_help()
419419
std::cout << ".read addr size\t\tRead from a memory address." << std::endl;
420420
std::cout << ".write addr hexdata\tWrite to a memory address." << std::endl;
421421
std::cout << ".toshell format\t\tConvert list to selected shellcode format. Available formats: c, cs, raw" << std::endl;
422-
//std::cout << ".inject pid\t\tTest shellcode by injecting it into the process." << std::endl;
422+
std::cout << ".inject pid\t\tTest shellcode by injecting it into the process. Works currently only on x86!" << std::endl;
423423
std::cout << ".allocate size\t\tAllocate a memory buffer." << std::endl;
424424
std::cout << ".loadlibrary path\tLoad a DLL into the process." << std::endl;
425425
std::cout << ".kernel32 func\t\tGet address of a kernel32 export." << std::endl;

Shellcodev/inject.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,15 @@ BOOL shelldev_inject_shellcode(std::vector<asm_t>* assemblies, std::string pid)
1717

1818
std::vector<unsigned char> bytes = get_shellcode(assemblies);
1919

20+
HANDLE processHandle;
21+
HANDLE remoteThread;
22+
PVOID remoteBuffer;
23+
24+
processHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, (DWORD)std::atoi(pid.c_str()));
25+
remoteBuffer = VirtualAllocEx(processHandle, NULL, bytes.size(), (MEM_RESERVE | MEM_COMMIT), PAGE_EXECUTE_READWRITE);
26+
WriteProcessMemory(processHandle, remoteBuffer, bytes.data(), bytes.size(), NULL);
27+
remoteThread = CreateRemoteThread(processHandle, NULL, 0, (LPTHREAD_START_ROUTINE)remoteBuffer, NULL, 0, NULL);
28+
CloseHandle(processHandle);
29+
2030
return TRUE;
2131
}

0 commit comments

Comments
 (0)