
Defense Evasion
Notes on getting past EDR, antivirus, AMSI and application control during red team operations and penetration tests.
Overview
Most enterprise Windows hosts run an EDR agent, antivirus, script scanning through AMSI and central logging, and many add application control. These notes cover how each control detects activity and how to work around it on an authorized engagement without burning the operation.
Notes in this section
- EDR evasion: unhooking, direct and indirect syscalls, injection and ETW patching
- AV evasion: payload encoding, packers and loaders that get past antivirus
- AMSI bypass: patching and reflection tricks for PowerShell and .NET
- AppLocker and WDAC bypass: trusted folders, proxy execution and Constrained Language Mode escape
- LOLBAS: signed Windows binaries for execution and downloads
Evasion methodology
Phase 1: reconnaissance
- Identify the security products installed (EDR, AV, SIEM agents)
- Enumerate monitoring and logging capabilities
- Check for behavioral analysis systems
- Review application whitelisting
- Identify network monitoring
Phase 2: operational security (OPSEC)
- Minimize the detection surface
- Blend with normal user behavior
- Use living-off-the-land techniques
- Avoid known malicious patterns
- Encrypt communications
Phase 3: evasion techniques
- Obfuscate payloads and scripts
- Use indirect system calls
- Inject into other processes
- Run code through signed binaries (LOLBins)
- Disable or bypass security features
Phase 4: persistence evasion
- Use persistence mechanisms that defenders rarely review
- Avoid common autorun locations
- Create scheduled tasks that look legitimate
- Use DLL hijacking in trusted paths
- Use fileless persistence
Common evasion techniques
Code obfuscation
- String encryption
- Control flow flattening
- Dead code insertion
- Polymorphic code generation
- Code signing with valid certificates
Process injection
- Classic DLL injection
- Reflective DLL injection
- Process hollowing
- Process doppelganging
- Thread execution hijacking
Living off the land (LOLBins)
Legitimate Windows binaries that can run or fetch code:
- PowerShell with a Constrained Language Mode bypass
- WMI for execution and persistence
- MSHTA for payload delivery
- Regsvr32 for script execution
- Certutil for file downloads
Memory-based techniques
- Execute payloads in memory only
- Avoid writing to disk
- Use reflective loading
- Compile .NET code in memory
- Use direct system calls
Anti-forensics
- Clear event logs selectively
- Timestomp files to avoid timeline detection
- Use NTFS alternate data streams
- Remove evidence from Prefetch and Shimcache
- Manipulate process arguments
Detection avoidance
Signature evasion
- Modify known malicious patterns
- Use custom tooling instead of public tools
- Encrypt and encode payloads
- Break payloads into stages
- Delay execution with timers
Behavioral evasion
- Mimic legitimate user activity
- Keep request rates and timing close to normal use
- Use standard ports and protocols
- Avoid suspicious parent-child process relationships
- Check for user interaction before running
Network evasion
- Use encrypted channels (HTTPS, DNS over HTTPS)
- Domain fronting and redirectors
- Blend with legitimate traffic
- Add jitter and randomized sleep
- Use peer-to-peer C2 channels
EDR bypass techniques
Kernel callbacks
- Unhook EDR kernel callbacks
- Patch ETW (Event Tracing for Windows)
- Disable threat intelligence feeds
- Bypass AMSI (Antimalware Scan Interface)
- Manipulate protected processes
Hardware-based evasion
- Bring Your Own Vulnerable Driver (BYOVD)
- Hypervisor-based rootkits
- Firmware-level persistence
- SMM (System Management Mode) rootkits
Tools and frameworks
| Tool | Primary use |
|---|---|
| Sliver | C2 framework with built-in evasion features |
| Donut | In-memory .NET assembly execution |
| ScareCrow | Payload obfuscation framework |
| Invoke-Obfuscation | PowerShell obfuscation |
| ThreatCheck | Test payloads against Defender |
Responsible use
Use these techniques only in authorized engagements:
- Get written permission before testing
- Agree the rules of engagement up front
- Document all actions for reporting
- Avoid causing system instability
- Respect data privacy and legal boundaries
Related notes
- Windows security: DLL injection and process manipulation
- Active Directory attacks: AD-focused evasion techniques
- Tools: offensive security tooling including C2 frameworks
Container Hardening
Practical container security techniques covering image hardening, runtime protection, resource limits, and defensive configurations for Docker and Kubernetes environments.
AMSI Bypass Techniques for PowerShell and .NET
AMSI bypass methods (memory patching, reflection-based disabling and obfuscation) for running PowerShell and .NET payloads that the AV would otherwise block.