Overview
SysWhispers4 can generate optional evasion helper functions based on command-line flags. These functions patch, unhook, or detect security monitoring mechanisms.SW4_PatchEtw
Generated with:--etw-bypass
Patches ntdll!EtwEventWrite to suppress user-mode ETW (Event Tracing for Windows) event delivery.
Returns
TRUE— Successfully patched ETWFALSE— Failed to patch (already patched, or protection error)
How It Works
- Locates
ntdll!EtwEventWritefunction - Changes memory protection to
PAGE_EXECUTE_READWRITE - Overwrites first bytes with:
- Restores original protection
EtwEventWrite() calls return immediately without logging events.
Usage
What ETW Bypass Does NOT Do
ETW-Ti callbacks fire in kernel space when syscalls are made, regardless of user-mode patching. This technique is useful against lighter EDRs that rely on user-mode ETW.SW4_PatchAmsi
Generated with:--amsi-bypass
Patches amsi.dll!AmsiScanBuffer to bypass AMSI (Antimalware Scan Interface) scanning.
Returns
TRUE— Successfully patched AMSI (or amsi.dll not loaded)FALSE— Failed to patch
How It Works
- Checks if
amsi.dllis loaded in the process - If not loaded, returns
TRUE(nothing to patch) - If loaded:
- Locates
AmsiScanBufferfunction - Patches first bytes to return
E_INVALIDARG(0x80070057) - This makes AMSI think the scan arguments are invalid
- Locates
Usage
When to Call
Call
SW4_PatchAmsi() before any operations that might trigger AMSI scanning:- Loading PowerShell scripts
- Executing .NET assemblies via CLR hosting
- Running VBScript/JScript
- Any file/buffer that AMSI-aware applications scan
Limitations
- Only affects the current process
- If
amsi.dllisn’t loaded yet, it won’t be pre-patched (patch after first AMSI initialization) - Some applications re-verify AMSI integrity — patch may be detected
SW4_UnhookNtdll
Generated with:--unhook-ntdll
Removes all inline hooks from ntdll.dll by mapping a clean copy from \KnownDlls\ntdll.dll and overwriting the .text section.
Returns
TRUE— Successfully unhooked ntdllFALSE— Failed to unhook
How It Works
- Opens
\KnownDlls\ntdll.dllsection (clean, unhooked copy maintained by Windows) - Maps the clean ntdll into process memory (
NtMapViewOfSection) - Locates the
.textsection in both clean and hooked ntdll - Changes hooked ntdll
.textprotection toPAGE_EXECUTE_READWRITE(viaVirtualProtect) - Overwrites hooked
.textwith clean bytes (memcpy) - Restores protection to
PAGE_EXECUTE_READ - Unmaps the clean ntdll
Usage
Why Unhook Before Initialize?
If you’re using dynamic SSN resolution (FreshyCalls, Hell’s Gate, etc.), those methods read from ntdll:- Before unhook: They read hooked/modified stubs → may get wrong SSNs or fail
- After unhook: They read clean stubs → correct SSNs
--resolve static, order doesn’t matter (SSNs are embedded at compile time).
What Gets Unhooked
All inline hooks in ntdll’s.text section:
- E9 hooks (near JMP)
- FF 25 hooks (far JMP)
- Int3 breakpoints (0xCC)
- Trampolines (any modification to function prologue)
Limitations
- Does not unhook kernel-mode hooks (syscall table hooks, SSDT hooks)
- Does not remove IAT hooks (those are in your PE, not ntdll)
- EDR may detect the unhooking operation itself
- Only affects ntdll — other DLLs (kernel32, kernelbase) remain hooked
SW4_AntiDebugCheck
Generated with:--anti-debug
Performs 6 anti-debugging checks to detect debuggers and analysis tools.
Returns
TRUE— No debugger detected (safe to proceed)FALSE— Debugger or analysis tool detected
Detection Techniques
| Check | Technique | What It Detects |
|---|---|---|
| 1 | PEB.BeingDebugged | Standard debugger attachment (user-mode) |
| 2 | PEB.NtGlobalFlag | Heap debug flags set by debuggers |
| 3 | RDTSC timing delta | Single-stepping / instruction tracing |
| 4 | NtQueryInformationProcess(ProcessDebugPort) | Kernel debug port (kernel-mode debugging) |
| 5 | Heap flags analysis | HEAP_TAIL_CHECKING_ENABLED, HEAP_FREE_CHECKING_ENABLED |
| 6 | Instrumentation callback | ETI (Early Thread Instrumentation) used by EDRs |
Usage
Example: Continuous Monitoring
Bypasses
Sophisticated debuggers (x64dbg, WinDbg with plugins) can:- Clear
PEB.BeingDebuggedflag - Hide debug port
- Normalize heap flags
- Spoof RDTSC timing
- Code obfuscation
- Anti-tampering checks
- Remote attestation
SW4_SleepEncrypt
Generated with:--sleep-encrypt
Ekko-style memory encryption during sleep to evade periodic memory scanners.
Parameters
Sleep duration in milliseconds (same as
Sleep()).How It Works
- Generates random XOR key via
RDTSC(timestamp counter) - XOR-encrypts own
.textsection (where your code lives) - Creates a waitable timer with the specified duration
- Queues an APC to the current thread (decryption routine)
- Enters alertable sleep (
NtWaitForSingleObjectwith alertable flag) - Timer fires → APC executes → decrypts
.text - Execution resumes normally
Usage
What It Defeats
- Periodic memory scanners — EDRs that scan process memory every N seconds
- YARA signature scans — Signatures won’t match encrypted code
- In-memory PE analysis — .text section appears corrupted
Limitations
Implementation Notes
The encryption is symmetric XOR, not cryptographically secure. It’s meant for evasion, not secrecy. The APC decryption routine:Complete Evasion Example
Combining all evasion helpers:Generation Flags Reference
| Helper Function | Command-Line Flag | Generated Files |
|---|---|---|
SW4_PatchEtw() | --etw-bypass | Code in SW4Syscalls.c |
SW4_PatchAmsi() | --amsi-bypass | Code in SW4Syscalls.c |
SW4_UnhookNtdll() | --unhook-ntdll | Code in SW4Syscalls.c |
SW4_AntiDebugCheck() | --anti-debug | Code in SW4Syscalls.c |
SW4_SleepEncrypt() | --sleep-encrypt | Code in SW4Syscalls.c + ASM |
Example Generation Command
Detection Risks
Mitigation Strategies
- Obfuscate helper functions — Use
--obfuscateto add junk instructions - Delay evasion — Don’t unhook immediately at startup
- Polymorphic patching — Vary patch bytes each execution
- Kernel-mode alternatives — For production, consider kernel drivers (though riskier)
Best Practices
Order of Operations
Error Handling
Always check return values:Testing
Test evasion helpers in controlled environments:- Static analysis: Verify no plaintext strings remain
- Dynamic analysis: Monitor with Process Hacker, API Monitor
- EDR testing: Test against actual EDR products (in authorized labs)
Next Steps
Supported Functions
Complete reference of all 64 NT syscall functions
Quickstart Guide
Get started with SysWhispers4
