Reflective PE Loader
A position-independent shellcode routine that receives a raw PE file in memory and manually maps it, resolves imports, applies relocations, and transfers execution — all without calling LoadLibrary on the payload itself.
Pattern Definition
- Parse headers: Walk DOS header →
e_lfanew→ COFF → Optional header → section table. - Allocate image buffer:
VirtualAllocwith sizeOptionalHeader.SizeOfImage. - Map sections: Copy each section from file offset to its assigned RVA.
- Resolve imports: Walk Import Directory, call
LoadLibraryA/GetProcAddressfor each DLL/function, patch IAT. - Apply relocations: If image base differs from
OptionalHeader.ImageBase, adjust RVA-based fixups. - Execute: Call
AddressOfEntryPoint(orCreateProcessW+ thread hijack for external process).
Implementation (observed in 70848598 shellcode)
fcn.000025b0— Main PE loader. Opensn3d2ll.dll(filename built from stack), reads file to buffer, maps withVirtualAlloc(0, SizeOfImage, MEM_COMMIT|MEM_RESERVE, PAGE_EXECUTE_READWRITE), copies sections, resolves imports via PEB walking.fcn.00003520— Export hash resolver: walksInLoadOrderModuleList, hashes each exported name with CRC32, compares against a target hash.fcn.000034c0— PEB walker:fs:[0x30]→PEB.Ldr→InLoadOrderModuleList.
The loader is fully self-contained — no imports table for the shellcode itself. ^[shellcode_disasm.txt]
Detection / Fingerprint
- Memory regions with
PAGE_EXECUTE_READWRITEthat contain a mapped PE (MZ at RVA 0, PE signature ate_lfanew). LoadLibraryAcalls for system DLLs from a memory region outside any module.- Import resolution loops: repeated
GetProcAddresscalls with names likeVirtualAlloc,CreateProcessW,NtQueueApcThread.
Defensive Countermeasures
- Memory scanning: hunt for PE headers in RWX regions.
- API hooking: flag
VirtualAlloc+PAGE_EXECUTE_READWRITEin non-standard processes. - ETW: monitor for
ImageLoadevents where the loaded module does not correspond to a file on disk.
Pages Where Observed
- unattributed —
70848598primary sample