· malware analysis · blackbird · process injection · manual mapping · windows internals · AES-X

Usermode Injection Is Dead.

Ever wondered how malware conceals itself? Me too. From a textbook LoadLibrary injection to a manual map that wipes its own PE header, and what Blackbird saw of both.

Intro

Ever wondered how malware conceals itself? Me too! In this one I'm taking apart one of the oldest tricks on Windows, from the textbook version every EDR catches to the "stealthy" version that's supposed to get past them, and showing you what Blackbird sees of both.

Fair warning, this goes deep into Windows internals. Handles and access rights, virtual memory and page protections, the loader, and how a syscall actually reaches the kernel. I'll explain as I go, but if NtWriteVirtualMemory means nothing to you yet, grab a coffee and go slow.

Also, Blackbird is still in alpha. Everything below comes from my own lab builds, so the UI, rule names and detections will probably look a bit different by the time you get your hands on it.

Why does malware do this in the first place? Well, take malicious.exe. We know that's malicious; it probably isn't signed, and we have no idea what it is. But what about brave.exe, or Discord.exe? We know those processes, we trust them. Now what if I told you malware can, quite easily, load itself into those trusted processes?

That's process injection. Commodity loaders, RATs, and the stuff APTs ship all do some version of it, and once the code is running inside something you trust, the process list stops telling you much.

Both samples below come from my Adversary Emulation Suite (AES, and its harder sibling AES-X), run offline in my lab.

Two user-mode panels over one shared kernel table. A, DLL injection through the loader: injector.exe calls OpenProcess, VirtualAllocEx for a read/write buffer, WriteProcessMemory to store the DLL path, and CreateRemoteThread at kernel32!LoadLibraryW, so the loader maps payload.dll into brave.exe as an image. B, manual mapping: injector.exe allocates RWX memory, writes the whole PE and a separate loader stub, starts a thread on the stub, which applies relocations, resolves imports and calls DllMain, then wipes the header and drops protection to RX. The kernel table compares what a defender sees: handle callbacks, thread-creation callbacks and ETW Threat-Intelligence fire for both routes; the image-load callback and module-list entry exist only for A, and B only trips the image-load callback for imports the target had not loaded yet.

The Simple Version

The basic versions of process injection are extremely simple, and therefore easily detectable. Take loading a DLL for example. Malware might follow steps similar to these:

  1. Open a handle to the target process
  2. Allocate memory in the target process, often RWX
  3. Write the path of the DLL it wants to load into that memory
  4. Create a thread in the remote process
  5. Point that thread at LoadLibraryW with the path, which loads the DLL and runs its DllMain

This works, assuming you're not crossing an integrity level upwards and have the permissions. It's also very noisy. A high-access handle is an indicator in itself, and an RWX allocation is a big tell. Creating a remote thread seals the detection, and just to be sure, the image-load callback on the module will most definitely give it away.

In Blackbird, catching that is one rule. Open the process, allocate, write (or map), then create a thread (or queue an APC), all against a remote target:

Blackbird's rule builder showing a five-stage chain, every stage scoped to a remote target. Stage 1 is NtOpenProcess, stage 2 is NtAllocateVirtualMemory, stage 3 is either NtWriteVirtualMemory or NtMapViewOfSection, then a scan of the target's memory for a marker, and stage 4 is either NtCreateThreadEx or NtQueueApcThread, ending in a severity 5 finding.

What Blackbird Saw

To see it for real, I ran the loadlibrary_remote_thread case from AES. It does exactly those five steps, injecting a test DLL, bb_unsigned_plugin.dll, from one process (PID 2140) into another (PID 5888).

Blackbird caught every one of them; the handle, the allocation for the path (read/write here, it's only holding a string), the 0x7A-byte write, the new thread 8308 in the target, and the DLL loading on that thread. Then it tied it all together into one finding, REMOTE_THREAD_DLL_INJECTION_CONFIRMED. Easy mode.

Blackbird's event log for the loadlibrary_remote_thread case. Four ImageLoad rows at 05:14:38.674 record bb_unsigned_plugin.dll loading from a user's Downloads folder, flagged as a usermode module load, a load from a user-writable path, a suspicious DLL load path and an unsigned non-system image. The open tooltip shows the IMAGE_LOAD_UNSIGNED_NON_SYSTEM detection rule.

Making It Quieter

So, we've covered very simple malware. What about advanced, or dare I say, specialized malware? There's a ton of different ways to perform process injection, but the concept is the same across all of them: get the target process to execute your code. That usually means opening a handle, mapping memory, and creating a thread or queuing an APC. How do we make it less noisy?

Tragically, there's not much you can do about the handle's access rights. Windows needs them to let one process touch another, and the memory alloc and write kind of have to happen too. But the DLL load, usually the biggest IoC, that we can get rid of.

Enter manual mapping. You reimplement a large chunk of the Windows loader yourself (LdrpLoadDllInternal and friends); lay out the sections, apply relocations, resolve imports, set protections. Instead of loading the DLL with LoadLibrary, you reconstruct it in memory yourself, then queue an APC, create a thread, or hijack an existing one to execute it. No image-load event, no entry in the module list. Wipe the PE header afterwards and there's no MZ left to find either.

Against a normal AV or EDR that's a lot stealthier. Against Blackbird, not so much.

Running A Manual Mapper

For this one I ran TheCruZ's Simple Manual Map Injector through AES-X, with its header wipe turned on. Injector-x64.exe (9328) spawns aesx_map_target.exe (5604), maps an inert test DLL into it, and clears the header. 20-second capture, usermode and kernel hooks both on.

02:49:11.649Z  ProcessTelemetry   creator=9328  process=5604
02:49:11.979Z  PE_INJECTION_WRITE actor=9328  target=5604
                             base=0x267CDD40000  size=0x1000
02:49:12.026Z  REMOTE_THREAD_CREATE_NTAPI
                             actor=9328 target=5604
                             start=0x267CDD80000  tid=5116
02:49:12.055Z  INJECTION_CHAIN_COMPLETE
                             actor=9328 target=5604
                             stages=allocate,write,protect,thread
02:49:12.680Z  MANUAL_MAP_CONFIRMED_PRIVATE_EXEC_PE
                             base=0x267CDD40000  size=0x7000
                             structuralPe=1  preWipeStructuralPe=1
                             currentHeaderPresent=0

Read it top to bottom. 9328 creates 5604, writes into it, flips the protection, starts thread 5116, and Blackbird joins all of that into one chain: allocate, write, protect, thread.

The screenshots below are from a second run of the same test, so the PIDs are different; Injector-x64 is 1976, aesx_map_target is 2064.

Blackbird's activity flow graph. On the left, the caller Injector-x64, PID 1976. In the middle, the operations it performed: NtWriteVirtualMemory, open handle, CreateProcessW and NtCreateThreadEx. On the right, the target aesx_map_target, PID 2064, created by PID 1976.

Then the memory. Allocate, write, allocate, flip protection, write again, all from thread 5788 into 2064. The flip at 0x22F838A1000 goes from PAGE_EXECUTE_READWRITE to PAGE_EXECUTE_READ, that's the mapper setting a section's final protection.

Blackbird's process tree with Injector-x64's main thread 5788 expanded. It lists NtAllocateVirtualMemory, NtWriteVirtualMemory and NtProtectVirtualMemory calls against PID 2064. One expanded row shows a protection change at 0x22F838A1000 from PAGE_EXECUTE_READWRITE to PAGE_EXECUTE_READ, and another shows a 0x1000-byte write at 0x22F838E0000.

And everything Blackbird flagged along the way:

Blackbird's detections list for Injector-x64 acting on aesx_map_target. At the top, a critical Injection Chain Complete finding with stages allocate, write, protect and thread. Below it, high-severity Cross Process Write Pattern, Memory Writable Executable Protection Flip, Usermode Dup Handle Activity and Suspicious RWX Allocation findings.

Then the bit I like, MANUAL_MAP_CONFIRMED_PRIVATE_EXEC_PE. A 0x7000-byte private executable region at 0x267CDD40000. preWipeStructuralPe=1, it was a PE when it landed. currentHeaderPresent=0, the header's gone now. The wipe worked fine, Blackbird just saw what was there before it happened.

The write itself came through the kernel lane: NtWriteVirtualMemory, 0x1000 of 0x1000 bytes into the target. Remember that one, it comes back in a second.

You'll notice thread 5116 doesn't start inside the mapped region, it starts on its own page at 0x267CDD80000. Same in the second run, the thread starts at 0x22F838E0000, which is one of those standalone RWX allocations in the list above. That's the injector's loader stub, which is how TheCruZ's mapper works; the stub finishes the job and calls into the DLL. And it did, my lab marker in the test DLL's entry point fired.

Diagram of the AES-X manual map. Injector-x64.exe, PID 9328, spawns aesx_map_target.exe, PID 5604, writes a PE into private memory at 0x267CDD40000 to 0x267CDD47000 (0x7000 bytes, PAGE_EXECUTE_READ, header wiped), and starts thread 5116 on a separate loader stub page at 0x267CDD80000, 0x39000 bytes further on, which applies relocations and imports and calls DllMain.

Blackbird's process tree with thread 5788 expanded. It shows NtCreateThreadEx creating thread 9712 in PID 2064 with start address 0x22F838E0000 and STATUS_SUCCESS, followed by NtResumeThread on thread 8200 in the same process.

Blackbird's Inspector open on an NtCreateThreadEx call. The source reads Blackbird Hypervisor (Kernel/Post-Syscall ntoskrnl). Injector-x64, PID 1976, creates a thread in aesx_map_target, PID 2064. Decoded arguments include start routine 0x22F838E0000, argument 0x22F838D0000 and target TID 9712, next to the reconstructed call and the native signature.

I ran two controls through the same set; a normal loader-based DLL load, and a private RW-to-RX region that isn't a PE. Neither tripped the manual-map finding.

OXCART, which reviews the captures, summed it up:

The most important finding is a complete cross-process injection: Injector-x64 (PID 9328) created aesx_map_target (PID 5604), wrote and protected executable memory in it, started a remote thread, and Blackbird confirmed a manually mapped PE with a wiped header in the target.

"But Direct Syscalls!"

But I hear you saying, direct syscalls! Or indirect, stack-spoofing, register clobbering, whatever you wanna do. Yeah, it doesn't matter.

Every one of those is a way around a usermode hook. They change how you get to the kernel, not whether you get there. NtWriteVirtualMemory still has to write into the target, the thread still has to be created, and the memory still has to become executable. Blackbird watches that from the kernel, through the hypervisor, where your stub doesn't get a say.

That's what the kernel-lane write above was. Same for the NtCreateThreadEx in the Inspector, look at the source line: Blackbird Hypervisor, post-syscall, ntoskrnl. It doesn't care if the call came through ntdll, a SysWhispers stub, or a gate you wrote last night. Spoof the stack all you want, the actor and target are on the operation itself.

I ran the syscall families through anyway. SysWhispers2 and SysWhispers3 each made all 64 of their calls under full instrumentation, and Blackbird threw 256 NTDLL_DIRECT_SYSCALL_EXTRACTION hits across the two. A Hell's Gate derivative ran kernel-only, made all 64 calls, and every Nt API call and memory change it made was sitting in the capture.

Same goes for the rule from earlier. Every stage is an Nt operation against a remote target, and none of them care how you got into the kernel.

Conclusion

Here's the thing about injectors; they all have to do the same job. Get a handle, get memory in someone else's process, put code in it, make it executable, make something run it. LoadLibrary, manual mapping, module stomping, APC queuing, thread hijacking, whatever. They're all different ways of doing those five things.

Manual mappers sell themselves on what they skip. No image load, no module list entry, wipe the header and there's no MZ either. All true, and none of it matters when you're watching the five things instead. The header was the easiest part to hide, and it was never the evidence in the first place.

So no, your injector isn't stealthy. It's just quiet in the places nobody worth worrying about was looking.

Also, watch Blackbird.