One of the more common risks I still see in commercial software is applications that dynamically allocate memory in external processes, for instance by creating memory pages with both writable and executable permissions.

One of the more common risks I still see in commercial software is applications that dynamically allocate memory in external processes, for instance by creating memory pages with both writable and executable permissions. And despite its prevalence, I’ve found that a lot of people don’t quite understand its impact. So I figured it was worth exploring a bit more. And as it’s been a while since I’ve written a deep technical post, why not dig in a little bit?
If you’re in a hurry, I’ll boil it down to this. Such behavior is inherently risky as it can bypass many modern defenses (e.g., Data Execution Prevention [DEP]), as well as evade detective controls when misused. In our evaluations of software running at customers, we observed that many software components create executable memory regions in processes that they do not fully control. This practice may be exploited by an attacker who can inject arbitrary code into a process running at a higher privilege level or one that handles sensitive data.
A couple reasons. Here’s the top that come to mind:
A common attack strategy looks something like this:
#include <windows.h>
#include <stdio.h>
// Vulnerable function that allocates executable memory in an external process
void allocateExecutableMemoryInExternalProcess(DWORD targetPID, const void *payload, SIZE_T
payloadSize) {
// Open the target process with all-access permissions (risky!)
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, targetPID);
if (hProcess == NULL) {
printf("[-] Failed to open target process.\n");
return;
}
// Allocate memory in the target process with executable permissions
LPVOID pRemoteCode = VirtualAllocEx(hProcess, NULL, payloadSize, MEM_COMMIT | MEM_RESERVE,
PAGE_EXECUTE_READWRITE);
if (pRemoteCode == NULL) {
printf("[-] Memory allocation failed in target process.\n");
CloseHandle(hProcess);
return;
}
// Write the payload into the allocated memory
if (!WriteProcessMemory(hProcess, pRemoteCode, payload, payloadSize, NULL)) {
printf("[-] Writing payload to target process failed.\n");
VirtualFreeEx(hProcess, pRemoteCode, payloadSize, MEM_RELEASE);
CloseHandle(hProcess);
return;
}
// (In a real scenario, a subsequent call might create a thread to execute this code)
printf("[+] Executable memory allocated and payload written at %p.\n", pRemoteCode);
// Cleanup - note that no immediate execution is triggered here.
CloseHandle(hProcess);
}
int main(int argc, char *argv[]) {
if(argc != 2) {
printf("Usage: %s <target_process_id>\n", argv[0]);
return 1;
}
DWORD targetPID = (DWORD)atoi(argv[1]);
// Example payload: normally, this would be shellcode or similar.
// For demonstration, we use a placeholder payload.
char payload[] = "PLACEHOLDER_FOR_MALICIOUS_CODE";
allocateExecutableMemoryInExternalProcess(targetPID, payload, sizeof(payload));
return 0;
}The memory allocated is marked as PAGE_EXECUTE_READWRITE, meaning it can be both modified and executed.
As the risk is local to the system, we often see the ramifications through the lens of local privilege escalation, sensitive data disclosure, loss of data integrity, or as discussed previously, code execution. Beyond the immediate impact, this risk is also often the precursor for more sophisticated attacks as a secondary and amplification vector. A couple examples:
The V8 JavaScript engine, which powers Google Chrome on Windows, is a complex JIT compiler that translates JavaScript into native code at runtime. In 2021 a vulnerability was reported in V8 that allowed an attacker to trigger a heap buffer overflow. This memory corruption bug could be chained to achieve arbitrary code execution via the engine’s own JIT‐compiled code.
Researchers identified a vulnerability in Adobe Acrobat/Reader’s PDF parsing engine that allowed an attacker to achieve remote code execution. Although the primary trigger was a heap corruption bug, exploitation involved careful manipulation of the process’s memory layout. Exploit developers demonstrated that by corrupting objects in memory, they could force the application to place attacker‐controlled data into regions later marked executable, a behavior that mirrors the risk of dynamic creation of executable memory.
What can we do to reduce the risk of exploitation:
For such a common risk, it’s far more common than you might think. And it’s a serious risk! The best way I’ve found to deal with this is through continuous monitoring and runtime evaluation. Relying solely on static analysis or periodic patch cycles leaves organizations exposed to common threats like these.
Many exploitable vulnerabilities never get a CVE. Book a demo to see how Spektion finds what's actually exploitable across your endpoints.