Firewall and IDS/IPS Evasion
Overview
Firewalls and intrusion detection/prevention systems (IDS/IPS) are critical components of modern network security. As penetration testers, understanding how to bypass these defenses is essential for conducting stealthy and effective engagements. This chapter covers techniques for evading detection and delivering payloads while maintaining operational security.
Firewall and IDS/IPS Basics
Firewalls:
Control traffic flow based on predefined rules.
Block or allow packets based on:
Source/Destination IP
Ports
Protocols
Types:
Network Firewalls (e.g., hardware-based solutions like Cisco ASA)
Host-Based Firewalls (e.g., Windows Defender Firewall)
IDS/IPS:
IDS (Intrusion Detection System): Monitors traffic for suspicious activity and raises alerts.
IPS (Intrusion Prevention System): Actively blocks malicious traffic.
Detection methods:
Signature-Based: Matches traffic patterns against known attack signatures.
Anomaly-Based: Flags traffic that deviates from normal behavior.
Techniques for Firewall Evasion
Port Spoofing:
Use non-standard ports for payload delivery (e.g., port 443 for HTTPS).
Example:
Payload Obfuscation:
Encode payloads using tools like
msfvenom
:
Split Payload Delivery:
Deliver payloads in fragments to bypass large-payload filters.
Example: Use PowerShell to download and execute a payload in memory:
DNS Tunneling:
Encapsulate payload traffic in DNS queries to bypass firewalls.
Example tool:
dnscat2
.
HTTP/HTTPS Tunneling:
Use HTTP/HTTPS to route traffic through firewalls that allow web traffic.
Configure a reverse shell:
Techniques for IDS/IPS Evasion
Signature Evasion:
Modify payloads to avoid matching known attack patterns:
Traffic Encryption:
Use encrypted channels (e.g., HTTPS) for command and control traffic.
Example:
Timing Attacks:
Send traffic in bursts or delays to avoid triggering anomaly-based detection.
Example: Use Nmap with timing options:
Packer Tools:
Use packers to obfuscate executable payloads.
Popular packers:
UPX:
Themida: Advanced commercial packer with anti-reverse engineering features.
Legitimate Application Templates:
Embed payloads in legitimate applications or documents.
Example:
Evasion Example: Using msfvenom with Custom Templates
Generate an Encrypted Payload:
Embed Payload in a Legitimate Application:
Use HTTPS for Stealth:
Verify Payload Detection:
Upload the payload to VirusTotal to check for AV detection:
Best Practices for Evasion
Test in a Sandbox:
Verify payload functionality in a controlled environment.
Avoid Reuse:
Customize payloads for each engagement to avoid detection by updated signatures.
Combine Techniques:
Layer multiple evasion methods (e.g., encoding + encryption).
Stay Updated:
Keep up with the latest evasion techniques and tools.
Command Cheatsheet
msfvenom -p <payload>
Generate payloads.
msfvenom -e <encoder>
Encode payloads for evasion.
upx --best --lzma <file>
Compress and obfuscate payloads.
msf-virustotal -k <api_key>
Check payload detection rates on VirusTotal.
nmap -T2
Conduct slow scans to avoid IDS detection.