Defense Evasion (AMSI / AV / EDR)
Getting execution is only half of it: a modern Windows has three layers watching. AMSI inspects scripts (PowerShell, VBA, JScript) right before they run; the AV (Defender) scans files and behavior with signatures and heuristics; the EDR hooks calls (user-land hooks, ETW, kernel callbacks) to see what your process does in real time. Evading is making your code not seen, not recognized, or not understood by each layer. The invariant being leveraged: each defense has a blind spot, and evasion is knowing where each one looks and slipping through the gap.
flowchart LR
C["offensive code"] --> A{"AMSI"}
A -->|in-memory patch| AV{"AV signatures"}
AV -->|obfuscate/encrypt| E{"EDR hooks"}
E -->|unhook / direct syscalls| X["execution without detection"]
Threat model
Section titled “Threat model”- Who attacks: a post-exploitation operator who needs to run offensive tools (mimikatz, Rubeus, BloodHound) and keep C2 without the three layers detecting it.
- What it breaks: each layer’s blind spot. AMSI runs in your own process → if you neutralize it in memory, it stops seeing anything. The AV relies on signatures → change the signature. The EDR hooks user-land APIs → avoid those APIs or undo the hook.
- What it gains: running the offensive arsenal without detection and blinding the telemetry that would reveal the intrusion. It’s an enabler for everything else in post-exploitation.
- The 2026 context: Credential Guard, HVCI, ASR, App Control for Business and the driver blocklist raise the bar. Evasion still exists, but the user-land margin narrows against kernel defenses.
Anatomy
Section titled “Anatomy”The three layers and their blind spots
Section titled “The three layers and their blind spots”| Layer | What it inspects | Blind spot |
|---|---|---|
| AMSI | scripts before they run, in your process | runs in your own process → patchable in memory |
| AV (signatures) | files and bytes | static signature → broken by obfuscating/encrypting |
| EDR (user-land hooks) | API calls | user-land hooks → avoidable or undoable |
Kernel defenses (ETW-TI, callbacks, HVCI) resist user-land tampering: there, evasion costs much more.
The Execution Policy is not security
Section titled “The Execution Policy is not security”The PowerShell Execution Policy is not a security control; it’s bypassed trivially (-ep bypass,
-enc, piping via stdin, reading and IEX). It doesn’t count as real evasion, but it’s worth knowing.
Variants
Section titled “Variants”Priority when using PowerShell/.NET in memory:
- In-memory patch of
AmsiScanBuffer: patch the function inamsi.dllinside your process so it always returns “clean” (AMSI_RESULT_CLEAN). The dominant method. - Break initialization (
amsiInitFailed) so the scan doesn’t start. - Obfuscate/fragment the script so the signature doesn’t match.
- Use a .NET runspace or a host without AMSI.
# conceptual pattern (not a ready-to-paste signature):# 1) locate amsi.dll!AmsiScanBuffer in the process# 2) VirtualProtect the region to RWX# 3) write a stub that returns E_INVALIDARG / CLEAN# 4) restore the original protectionAV (signatures)
Section titled “AV (signatures)”- Obfuscation of payloads (packers, encryption, renaming) to break static signatures.
- Encrypted shellcode decrypted only at runtime; avoid touching disk (in-memory execution).
- LOLBins: use legitimate OS binaries so you don’t introduce your own executables.
EDR (hooks, ETW, telemetry)
Section titled “EDR (hooks, ETW, telemetry)”- Unhooking: restore the original bytes of
ntdll.dll(reload a clean copy from disk) to remove the user-land hooks. - Direct / indirect syscalls (Hell’s Gate, Halo’s Gate, SysWhispers): invoke syscalls bypassing the hooked APIs.
- ETW patching: patch
EtwEventWriteto blind .NET/PowerShell telemetry. - Stealthy process injection (hollowing, module stomping, APC) and BYOVD to kill the EDR from the kernel (see tokens).
- Living off the land: minimize your own binaries;
rundll32,regsvr32,mshta,msbuild(LOLBins) and fileless loads.
Red Team
Section titled “Red Team”Investigator workflow
Section titled “Investigator workflow”- Is AMSI on? → in-memory patch before loading anything in PowerShell/.NET.
- Does the payload pass static signatures? → check with ThreatCheck/DefenderCheck and obfuscate.
- Does the EDR hook user-land? → unhooking or direct syscalls.
- Does ETW give away .NET/PowerShell? → ETW patching.
- Operate fileless / with LOLBins whenever possible; BYOVD only if you must kill the EDR and the blocklist allows it.
- Invoke-Obfuscation, AMSI bypass scripts: AMSI and obfuscation.
- ScareCrow, Donut, Freeze, NimPackt: generating evasive loaders/shellcode.
- SysWhispers2/3, Hell’s Gate/Halo’s Gate: direct/indirect syscalls.
- ThreatCheck / DefenderCheck: find which byte triggers the signature.
- SharpUnhooker: unhooking ntdll.
Impact and chaining
Section titled “Impact and chaining”Running offensive tools without detection, keeping C2 stable and blinding telemetry. It enables credential dumping (tokens, credentials) and the rest of post-exploitation.
Blue Team
Section titled “Blue Team”Detection
Section titled “Detection”- AMSI bypass patterns (access to
amsi.dll,VirtualProtectoverAmsiScanBuffer) and ETW patching (EtwEventWrite). - Unhooking: reads of
ntdll.dllfrom disk and rewriting of its.textin memory. - Direct syscalls (calls that don’t go through the expected hooks), process injection (CreateRemoteThread, APC, hollowing).
- Use of LOLBins with anomalous command lines; fileless loads.
Telemetry and sources
Section titled “Telemetry and sources”- Script Block Logging (4104) captures the script after de-obfuscation → key against obfuscated PowerShell.
- ETW (Threat Intelligence provider, kernel callbacks) resists part of the user-land tampering.
- Sysmon 7 (image load of
amsi.dll/clr.dll), 8 (CreateRemoteThread), 10 (process access), 25 (process tampering).
Hardening
Section titled “Hardening”- Defender ASR rules, Credential Guard, HVCI and App Control for Business / AppLocker (an allowlist cuts off LOLBins and loaders).
- PowerShell Constrained Language Mode + Script Block Logging + transcription.
- Microsoft vulnerable driver blocklist (default on Windows 11 2022+, enforced with HVCI) against BYOVD; EDR with anti-tamper protection.
- Keep defenses in the kernel (ETW-TI, callbacks) where user-land tampering doesn’t reach; segment and limit which hosts run scripts.
Response
Section titled “Response”If evasion is detected, assume the EDR may have been blind for a while: hunt out of band (network telemetry, centralized logs), rebuild the host, rotate credentials and review the persistence the EDR didn’t see.
CVEs and real cases
Section titled “CVEs and real cases”- AMSI/ETW patching and unhooking are standard red-team and APT TTPs (MITRE T1685 Disable or Modify Tools, T1055 Process Injection, T1620 Reflective Loading).
- BYOVD to kill EDR: BlackByte, LockBit, Scattered Spider campaigns with signed vulnerable drivers; CVE-2021-21551 (Dell dbutil) and RTCore64 (MSI Afterburner) among the most abused.
- Defender has hardened AMSI repeatedly; bypasses live in a constant patch-evasion cycle.
Test checklist
Section titled “Test checklist”- Is AMSI on? Does the in-memory bypass (
AmsiScanBuffer) work? - Does the obfuscated/encrypted payload evade static signatures? (ThreatCheck).
- Does the EDR hook user-land? Do unhooking or direct syscalls evade it?
- Does ETW patching blind .NET/PowerShell telemetry?
- Can you operate fileless / with LOLBins without introducing binaries?
- Is there a loadable vulnerable driver (BYOVD), or does the blocklist/HVCI stop it?
- Blue: does Script Block Logging capture the de-obfuscated script?
- ASR / App Control / Constrained Language Mode active?