Firewall and IDS Evasion Bypass firewall rules and evade intrusion detection/prevention systems during port scanning and reconnaissance. These techniques help identify filtered ports, understand firewall behavior, and conduct stealthy scans without triggering security alerts.
Quick Reference sudo nmap -f 10.10.10.10sudo nmap -D RND:10 10.10.10.10sudo nmap --source-port 53 10.10.10.10sudo nmap -Pn --disable-arp-ping -n -D RND:10 -sV -p- --source-port 53 --dns-servers 10.10.10.10 10.10.10.10
Detecting Firewalls sudo nmap -p 80 --packet-trace -Pn -n --disable-arp-ping 10.10.10.10sudo nmap -p 8080 --packet-trace -Pn -n --disable-arp-ping 10.10.10.10sudo nmap --reason -p 1-1000 10.10.10.10sudo nmap --packet-trace -p 80,443 10.10.10.10
Packet Fragmentation sudo nmap -f 10.10.10.10sudo nmap --mtu 16 10.10.10.10sudo nmap --mtu 24 10.10.10.10sudo nmap -f -sS -p- 10.10.10.10
Decoy Scanning sudo nmap -D RND:5 10.10.10.10sudo nmap -D RND:10 10.10.10.10sudo nmap -D 192.168.1.5,192.168.1.6,ME,192.168.1.8 10.10.10.10sudo nmap -D RND:10 -sV -p 80,443 10.10.10.10
Source IP Spoofing sudo nmap -S 192.168.1.5 -e eth0 10.10.10.10sudo nmap -S 10.129.2.200 -e tun0 -Pn -p 445 10.129.2.28sudo nmap -S 192.168.1.5 -e eth0 -D RND:5 10.10.10.10
Source Port Manipulation sudo nmap --source-port 53 10.10.10.10sudo nmap -g 53 10.10.10.10sudo nmap --source-port 80 10.10.10.10sudo nmap --source-port 443 10.10.10.10sudo nmap --source-port 53 -p- 10.10.10.10
DNS Manipulation sudo nmap --dns-servers 8.8.8.8 10.10.10.10sudo nmap --dns-servers 10.10.10.10 10.10.10.10sudo nmap -n 10.10.10.10
Timing and Rate Control sudo nmap -T0 10.10.10.10sudo nmap -T1 10.10.10.10sudo nmap -T2 10.10.10.10sudo nmap --scan-delay 5s 10.10.10.10sudo nmap --scan-delay 1s 10.10.10.10sudo nmap --max-scan-delay 10s 10.10.10.10sudo nmap --max-rate 100 10.10.10.10sudo nmap --min-rate 50 --max-rate 100 10.10.10.10
Alternative Scan Types nmap -sT 10.10.10.10 sudo nmap -sA 10.10.10.10sudo nmap -sN 10.10.10.10sudo nmap -sF 10.10.10.10sudo nmap -sX 10.10.10.10sudo nmap -sU --top-ports 100 10.10.10.10
Idle/Zombie Scan nmap -O -v 192.168.1.0/24 | grep "IP ID Sequence Generation: Incremental" sudo nmap -sI 192.168.1.5 10.10.10.10sudo nmap -sI 192.168.1.5 -p 80,443 10.10.10.10
FTP Bounce Scan sudo nmap -b ftp-server.com 10.10.10.10sudo nmap -p 22,25,135 -Pn -v -b 192.168.1.2 10.10.10.10
MAC Address Spoofing sudo nmap --spoof-mac 00:11:22:33:44:55 10.10.10.10sudo nmap --spoof-mac 0 10.10.10.10sudo nmap --spoof-mac Apple 10.10.10.10sudo nmap --spoof-mac Dell 10.10.10.10
Data Padding sudo nmap --data-length 25 10.10.10.10sudo nmap --data-length 50 10.10.10.10sudo nmap --data-length 25 -f 10.10.10.10
Badsum Technique sudo nmap --badsum 10.10.10.10
NSE Firewall Evasion Scripts nmap --script firewall-bypass 10.10.10.10 nmap -p 80 --script http-methods,http-headers 10.10.10.10 nmap --script ftp-bounce 10.10.10.10 nmap --script firewalk 10.10.10.10
Comprehensive Evasion Examples sudo nmap -sS -Pn -f -D RND:10 --source-port 53 -T2 --scan-delay 2s -p- 10.10.10.10sudo nmap -Pn --disable-arp-ping -n -D RND:10 -sV -p- --source-port 53 -vv --dns-servers 10.10.10.10 10.10.10.10sudo nmap -f --mtu 16 -D RND:5 -T1 --scan-delay 5s -p 80,443 10.10.10.10sudo nmap --source-port 53 -D RND:10 -sS -Pn -n -p- 10.10.10.10sudo nmap -sU --source-port 53 -T2 --max-retries 1 --top-ports 100 10.10.10.10
IPv6 Scanning nmap -6 fe80::1 nmap -6 -sS -Pn fe80::1
Debugging and Analysis sudo nmap --packet-trace -p 80 10.10.10.10sudo nmap --reason -p 1-1000 10.10.10.10sudo nmap -vv -p 80,443 10.10.10.10sudo nmap -d -p 80 10.10.10.10
NSE Firewall Detection Scripts
Script
Type
Technique
Description
firewall-bypass
Bypass
TCP fragmentation
Sneak through chopped packets
firewalk
Detection
TTL manipulation
Map firewall rules
ip-id
Detection
IPID pattern
See if real host replies directly
ipidseq
Detection
IPID sequence
Check if packet numbers are predictable
traceroute
Detection
TTL path tracing
See who blocks you along the way
sniffer-detect
Detection
Promiscuous mode baiting
Detect network sniffers
http-methods
Detection
HTTP verb probing
Spot HTTP filtering
ftp-bounce
Bypass
FTP as proxy
Leverage internal scan via FTP
Notes Understanding Firewall Responses:
Closed Port : Receives RST (reset) flag response - port is reachable but no service listening
Filtered Port : No response or ICMP unreachable - firewall is blocking the port
Open|Filtered : No response on UDP scan - could be open or filtered
Long Delay : Indicates rate limiting or firewall inspection
Fast Rejection with ICMP Error Code 3 : Firewall actively blocking
Firewall Evasion Strategy:
Identify Filtering : Use --reason and --packet-trace to understand firewall behavior
Test Trusted Ports : Try source ports 53 (DNS), 80 (HTTP), 443 (HTTPS)
Fragment Packets : Many firewalls don’t reassemble fragments properly
Use Decoys : Hide your real IP among fake scanning IPs
Slow Down : Reduce scan speed to avoid rate-limiting and detection
Alternative Protocols : Try UDP if TCP is heavily filtered
IDS/IPS Evasion Best Practices:
Use VPS : Scan from Virtual Private Servers to avoid IP bans
Fragment Packets : Most IDS/IPS don’t handle fragmented packets well
Decoy Scanning : Slide your real IP among multiple fake IPs
Specify Interface : Use -e to specify which interface to scan from
DNS Proxying : Abuse trust relationships with --dns-server
Timing Control : Use -T0 or -T1 for maximum stealth
Source Port Selection:
Firewalls often trust traffic from certain well-known ports:
Port 53 (DNS) : Most commonly trusted
Port 80 (HTTP) : Web traffic often allowed
Port 443 (HTTPS) : Encrypted web traffic
Port 20/21 (FTP) : File transfer ports
Port 25 (SMTP) : Email traffic
Scan Type Selection for Evasion:
SYN Scan (-sS): Stealthier than connect scan, requires root
ACK Scan (-sA): Useful for mapping firewall rules (stateful vs stateless)
NULL/FIN/Xmas (-sN/-sF/-sX): Work on Linux/Unix, bypass some firewalls
UDP Scan (-sU): Often less filtered than TCP
Idle Scan (-sI): Most stealthy, uses zombie host
Performance vs Stealth Trade-offs:
Fast Scans : More likely to trigger IDS/IPS alerts
Slow Scans : Less likely to be detected but take much longer
Fragmentation : Adds overhead but bypasses simple firewalls
Decoys : Increases network traffic but hides your real IP
Detection Avoidance:
Avoid scanning during business hours
Randomize scan order with --randomize-hosts
Use different source IPs/ports for different scan phases
Space out scans over time
Monitor for defensive responses (port closures, IP blocks)
Legal and Ethical Considerations:
Only use evasion techniques on systems you have permission to test
Document all evasion techniques used in penetration test reports
Be aware that evasion attempts may be logged and investigated
Some techniques (IP spoofing, decoys) may impact other systems