Modern endpoint detection and response (EDR) platforms rely heavily on kernel telemetry to detect in-memory malware execution. Whenever an adversary attempts to execute shellcode within a running process, defensive sensors monitor kernel-level thread creation callbacks, inspect user-mode API hooks on functions like NtCreateThreadEx or QueueUserAPC, and analyze thread call stacks for suspicious or unbacked memory regions. In response to these comprehensive instrumentation layers, sophisticated threat actors have shifted toward execution primitives that circumvent the operating system thread scheduler entirely.
Among the most evasive techniques is the abuse of the Windows Fibers API. Originally designed in Windows NT to facilitate the cooperative multitasking of legacy UNIX applications and high-throughput server workloads, fibers provide lightweight, user-mode execution contexts managed exclusively by application code. By converting an existing benign thread into a fiber and invoking SwitchToFiber, malicious loaders can transfer control to encrypted or unbacked shellcode without generating a single kernel thread notification. Understanding the internal mechanics of fiber-based execution is critical for engineering proactive host and network security perimeters.
Windows Fibers Architecture and Stealth User-Mode Execution
In the Windows threading model, threads are kernel objects scheduled pre-emptively by the operating system kernel. Each thread possesses a kernel-managed thread environment block (TEB), an associated kernel stack, and an entry in the system scheduler. In contrast, a fiber is an entirely user-mode construct. Multiple fibers can exist within the context of a single host thread, but only one fiber executes at any given instant.
The operational lifecycle of a fiber-based execution cradle proceeds through four distinct API phases:
- Thread Conversion (
ConvertThreadToFiber/ConvertThreadToFiberEx): Before an application can create or schedule fibers, the currently executing thread must be converted into a primary fiber. The Windows loader allocates a Fiber Execution Context (containing an independent execution stack, CPU register state, and Fiber Local Storage pointers) and stores a reference to this context in the TEB at offset0x17EE(on x64 systems). - Fiber Context Allocation (
CreateFiber/CreateFiberEx): The loader creates an auxiliary fiber by specifying a custom stack commit size and an entry point callback. UnlikeCreateThread, this operation does not involve the Windows executive, issues noNtCreateThreadExsystem call, and allocates memory purely within the virtual address space of the current process. - Cooperative Context Switching (
SwitchToFiber): Whenkernel32!SwitchToFiberis called, the CPU saves non-volatile registers (such asRBX,RBP,RDI,RSI,R12-R15) onto the current fiber stack, updates the stack pointer (RSP) to point to the target fiber stack, swaps the fiber data pointer in the TEB, and resumes execution at the saved instruction pointer (RIP). - Shellcode Execution and Return: The target fiber executes the payload, performs C2 beaconing, encrypts its working memory, and calls
SwitchToFiberagain to return control seamlessly to the benign primary fiber.
Because this transition occurs entirely through user-mode assembly instructions without transitioning through Ring 0, the kernel is completely unaware that an entirely new logical execution context has taken over the processor.
Attack Surface: EDR Telemetry Blindspots and Call Stack Desynchronization
The reliance of modern security tooling on standard thread heuristics creates profound blindspots when confronted with fiber execution loops.
Neutralizing Kernel Thread Creation Telemetry
Enterprise EDR agents register kernel notification routines via PsSetCreateThreadNotifyRoutine and PsSetCreateProcessNotifyRoutine. These callbacks allow security drivers to inspect the initial start address of every newly spawned thread. If a thread points directly to dynamic heap memory marked with PAGE_EXECUTE_READWRITE (RWX) or unbacked allocations outside valid executable modules, the EDR flags the behavior as process injection.
With fiber abuse, no new thread is ever created. The malicious payload executes within the context of an existing, long-lived, and fully trusted thread—such as explorer.exe, svchost.exe, or a digitally signed corporate binary. The kernel thread notify routine is never triggered, allowing the shellcode to run under the radar of automated process lifecycle analysis.
Call Stack Spoofing and Execution Unwinding Disruption
Call stack analysis is another primary heuristic used by endpoint sensors during behavioral triggers or periodic thread sampling. EDR engines walk the call stack backward using frame pointer unwinding or Exception Directory unwind metadata (.pdata) to ensure that every return address originates from signed disk-backed DLLs.
When execution switches to an auxiliary fiber, the active stack pointer points to an isolated memory region allocated specifically for that fiber. Because this stack was initialized manually by user-mode code rather than standard thread bootstrap routines, stack-walking utilities encounter an immediate boundary desynchronization. The fiber stack exhibits an unusual, truncated, or synthetic layout that confuses stack-frame validation filters, preventing security tools from attributing outbound malicious activity to the injected loader.
Defense Architecture: Fiber Local Storage Inspection and WireGuard Network Containment
Detecting user-mode fibers purely through host telemetry is notoriously challenging due to the lack of kernel callbacks. Consequently, an effective defense-in-depth posture requires combining specialized memory analysis with strict egress network containment.
+-------------------------------------------------------------------+
| Monitored Endpoint Host |
| |
| [Suspicious Process] |
| Thread Context -> ConvertThreadToFiber |
| Fiber Local Storage (FLS) Inspection |
| | |
| Covert C2 Beaconing Attempt |
| v |
| [Isolated WireGuard Interface] |
| wg0: 10.99.0.5/32 (ChaCha20-Poly1305 Encrypted UDP) |
+----------|--------------------------------------------------------+
| (Kernel-Enforced Policy Routing)
v
+-------------------------------------------------------------------+
| Security Gateway Router |
| |
| nftables / Suricata IDS Layer |
| - Deep Packet Inspection of decrypted C2 payloads |
| - Block direct WAN access for unverified endpoints |
+-------------------------------------------------------------------+
By deploying a dedicated, kernel-level WireGuard network interface on the endpoint or enclosing the workstation behind an enforcement gateway, all outbound traffic generated by hidden fibers is forcibly captured. Even if a fiber successfully evades user-mode hooks and initiates a socket connection, its network packets cannot circumvent the operating system routing table.
WireGuard operates directly within the OS kernel, utilizing authenticated ChaCha20-Poly1305 encryption. Any network connection attempted by the fiber is channeled through an encrypted tunnel to a centralized inspection gateway where anomalous beaconing frequencies, domain generation algorithms (DGA), and raw command-and-control handshakes can be scrutinized and dropped.
Practical Configuration Guide: Mitigating Fiber Malware and Enforcing Egress Isolation
Hardening systems against fiber-based evasion requires proactive telemetry extraction on the host combined with network containment policies.
Step 1: Monitor TEB Structures and FlsCallback Tables
Security teams can audit suspicious fiber conversions by scanning process memory for allocated Fiber Local Storage slots. Each time a fiber is created, Windows maintains pointers in the process PEB and TEB. Attackers frequently overwrite FlsCallback entries to hijack execution:
// Example user-mode inspection of active thread fiber state
#include <windows.h>
#include <winternl.h>
#include <stdio.h>
void AuditCurrentFiberState() {
PVOID currentFiber = GetCurrentFiber();
if (currentFiber == (PVOID)0x1E00 || currentFiber == NULL) {
printf("[*] Thread is running in standard context.\n");
} else {
printf("[!] Alert: Thread has been converted to Fiber at: %p\n", currentFiber);
}
}
Endpoint detection rules should query the thread's FlsData block; if dynamic unbacked memory pointers are observed in the fiber callback table, an alert should be raised immediately.
Step 2: Establish WireGuard Egress Tunnel for Process Isolation
To ensure that compromised endpoints cannot establish direct, uninspected TCP/UDP connections to rogue C2 infrastructure, configure an isolated WireGuard tunnel on the client machine:
# /etc/wireguard/wg_isolate.conf
[Interface]
PrivateKey = aaaaaa_CLIENT_ISOLATED_PRIVKEY_aaaaaa=
Address = 10.99.0.5/32
DNS = 10.99.0.1
Table = 200
[Peer]
PublicKey = bbbbbb_SECURITY_GATEWAY_PUBLIC_KEY_bbbbbb=
Endpoint = 203.0.113.50:51820
AllowedIPs = 0.0.0.0/0
PersistentKeepalive = 25
Binding the interface to policy table 200 ensures that all designated high-risk workload traffic is isolated from default unencrypted routes.
Step 3: Enforce Policy Routing and Block Outbound Beaconing
On the central Linux security gateway, configure nftables rules to quarantine untrusted endpoint traffic and enforce strict protocol inspection:
table inet endpoint_isolation {
chain prerouting {
type filter hook prerouting priority filter; policy accept;
# Isolate outbound traffic from the monitored WireGuard subnet
ip saddr 10.99.0.0/24 tcp dport { 80, 443, 8080, 8443 } accept
ip saddr 10.99.0.0/24 udp dport 53 accept
ip saddr 10.99.0.0/24 drop
}
chain forward {
type filter hook forward priority filter; policy drop;
ct state { established, related } accept
# Route outbound C2 probes into deep inspection sandbox
iifname "wg_isolate" oifname "eth0" accept
}
}
Through this dual-layer strategy, memory evasion achieved through the Windows Fibers API is effectively countered. While the fiber may avoid immediate detection at the thread API level, its communication channel is funneled through an unyielding WireGuard perimeter where covert persistence is dismantled.



