8. Evasion Techniques (Decoys, Fragmentation, Spoofing)
Firewall & IDS Evasion Techniques
Evasion techniques are methods used to bypass network security controls like Firewalls and Intrusion Detection Systems (IDS). By manipulating packet structure, we can make malicious traffic appear benign or confuse the reassembly logic of the target system.
Fragmentation (-f) splits packets into smaller chunks, making it harder for simple pattern-matching IDSs to reconstruct the payload. Decoys (-D) obscure the origin by flooding the target with requests from multiple spoofed IP addresses, making it difficult to isolate the true attacker's source.
Source Port Spoofing (--source-port 53) exploits overly permissive firewall rules that trust traffic coming from specific ports like DNS (53).
MAC Address Spoofing (--spoof-mac) allows an operator to impersonate trusted hardware on a local network segment.
nmap -f -D 10.0.0.1,10.0.0.2,ME 192.168.1.5 --source-port 53 --spoof-mac 00:11:22:33:44:55
Detecting Network Scans
Network defense relies on identifying anomalous traffic patterns. Snort and Suricata use signature-based and anomaly-based detection to flag port scans. Common detection triggers include high volumes of connection attempts to closed ports or rapid requests from a single IP.
Thresholding is the primary method for filtering out false positives; it sets a limit on the number of attempts allowed within a specific time window before an alert is triggered. Firewall logs provide the audit trail necessary to correlate these hits with source IP addresses.
| Detection Metric | Description |
|---|---|
| Connection Rate | Number of new connections per second from a single IP. |
| Out-of-Order Packets | Excessive TCP retransmissions often indicate evasion or scanning. |
alert tcp any any -> any any (msg:"Possible Port Scan"; detection_filter:track by_src, count 10, seconds 5; sid:1000001;)
Custom Asynchronous Port Scanner
To perform efficient reconnaissance, we utilize Python's asyncio library. This allows us to handle thousands of connection attempts concurrently without waiting for each one to time out sequentially.
The following script demonstrates a basic asynchronous scanner that attempts a TCP handshake on specified ports. It utilizes a semaphore to manage the concurrency limit, ensuring we do not exhaust local system resources.
import asyncio async def scan(ip, port): try: conn = asyncio.open_connection(ip, port) reader, writer = await asyncio.wait_for(conn, timeout=1) print(f'Port {port} is OPEN') writer.close() await writer.wait_closed() except: pass async def main(): tasks = [scan('127.0.0.1', p) for p in range(20, 81)] await asyncio.gather(*tasks) if __name__ == '__main__': asyncio.run(main())
Knowledge Check
Ready to test your understanding of 8. Evasion Techniques (Decoys, Fragmentation, Spoofing)?