Overview
Theevasion module implements anti-analysis techniques to detect and evade debuggers, virtual machines, sandboxes, and security software. It combines multiple detection methods for reliability.
Main Entry Point
RunAntiAnalysis()
Main function that performs all evasion checks.evasion/evasion.go:51-80
Enable virtual machine and sandbox detection
Enable debugger detection and anti-debugging techniques
true if safe to proceed, false if analysis environment detected
Anti-Debugging Techniques
hideFromDebugger()
UsesNtSetInformationThread to hide thread from debugger events.
evasion/evasion.go:84-93
This doesn’t detach debuggers, but prevents them from receiving debug events.
isDebugged()
Combines multiple debugger detection methods:evasion/evasion.go:97-151
Debugger Detection Methods
Debugger Detection Methods
1. IsDebuggerPresent
- Checks PEB.BeingDebugged flag
- Easy to bypass but catches basic debuggers
- Detects remote debugging scenarios
- Checks kernel object flags
- Queries kernel for debug port
- Returns non-zero if debugger attached
- Harder to fake than PEB flag
- Checks NoDebugInherit flag
- Returns 0 if being debugged
- Simple operations should be fast
- Slow execution indicates single-stepping
Virtual Machine Detection
isVirtualized()
Detects VM and sandbox environments through multiple indicators:evasion/evasion.go:155-253
VM Detection Indicators
VM Detection Indicators
Process-based:
- VMware Tools (vmtoolsd.exe, vmwaretray.exe)
- VirtualBox Guest Additions (vboxservice.exe, vboxtray.exe)
- QEMU Guest Agent (qemu-ga.exe)
- Parallels Tools (prl_tools.exe)
- Sandbox software (Sandboxie, Joe Sandbox)
- VMware registry keys
- VirtualBox registry keys
- Hyper-V registry keys
- MAC address OUI (Organizationally Unique Identifier)
- Each VM vendor has specific MAC prefixes
Sandbox Detection
isSandboxTiming()
Detects sandboxes through timing manipulation:evasion/evasion.go:257-270
Many sandboxes accelerate time or skip sleep calls to speed up analysis.
isResourceConstrained()
Detects minimal VM/sandbox environments:evasion/evasion.go:274-301
isDiskSmall()
Sandboxes typically have small disks (20-40GB):evasion/evasion.go:304-317
hasRecentFiles()
Real users have activity; fresh sandboxes don’t:evasion/evasion.go:321-330
Defense Bypass Techniques
PatchAMSI()
Disables Windows AMSI (Anti-Malware Scan Interface):evasion/evasion.go:335-376
AMSI Bypass Explained
AMSI Bypass Explained
What is AMSI?
- Anti-Malware Scan Interface (Windows 10+)
- Allows AV to scan script content
- Used by PowerShell, .NET, VBA, etc.
- Patch
AmsiScanBufferfunction - Replace function body with
xor eax, eax; ret - Function now always returns AMSI_RESULT_CLEAN (0)
PatchETW()
Disables Event Tracing for Windows (used by EDRs):evasion/evasion.go:380-415
ETW is used by EDRs (Endpoint Detection and Response) to monitor process behavior. Patching it can reduce detection.
DisableWindowsDefender()
Attempts to disable Windows Defender (requires admin):evasion/evasion.go:420-434
AddDefenderExclusion()
Adds exe to Defender exclusions (sometimes works without admin):evasion/evasion.go:438-449
Detection Indicators Summary
- Debugger
- Virtual Machine
- Sandbox
- PEB.BeingDebugged flag set
- Debug port exists (NtQueryInformationProcess)
- NoDebugInherit flag clear
- Slow execution (single-stepping)
- Remote debugger present