Firewall and IDS Evasion
Between you and the target there are usually network controls: firewalls (filter by IP/port/protocol), IDS/IPS (detect and block attack patterns) and proxies. Evasion means getting your traffic to the target without being blocked or recognized: hiding the scan, fragmenting packets, using allowed ports and protocols, or encrypting and obfuscating the content. You do not break the control; you pass where it is not looking.
Threat model
Section titled “Threat model”Each control watches a different layer, so evasion is chosen according to which one is in the way. The firewall decides what passes by IP/port; the IDS recognizes signatures in the content; egress filtering limits what leaves. The cross-cutting idea is the same as in WAF evasion: keep the attack’s semantics while changing the form the control recognizes. All of this within an authorized test where evading controls is part of the agreed scope.
flowchart LR
A[Attacker] --> FW["Firewall (IP/port)"]
FW --> IDS["IDS/IPS (signatures)"]
IDS --> T[Target]
A -. "allowed port 443/53" .-> FW
A -. "fragmentation/obfuscation" .-> IDS
T -. "egress filtering limits C2 back" .-> A
What each control filters
Section titled “What each control filters”- Network firewall: decides which IPs, ports and protocols pass. Evasion = use what is allowed or look like it.
- IDS/IPS (Snort, Suricata): detects attack signatures in the traffic. Evasion = make the payload not match the signature.
- Application firewall (WAF): HTTP-specific (see WAF Bypass).
- Egress filtering: limits outbound traffic, key for C2 and reverse shells.
Scan evasion with nmap
Section titled “Scan evasion with nmap”nmap -T1 target # slow, below the detection thresholdnmap --mtu 16 target # fragment (MTU multiple of 8); -f and --mtu can't be combinednmap -D RND:10 target # decoys: mix your IP with luresnmap -S <fake_ip> target # spoof the source (if you don't care about the reply)nmap --source-port 53 target # exit from a "trusted" portnmap --data-length 25 target # add random bytesnmap -sA target # ACK scan: tells filtered from unfiltered portsPassing through allowed ports and protocols
Section titled “Passing through allowed ports and protocols”Almost always 80/443 and 53 (DNS) are open outbound, so malicious traffic disguises itself as legitimate:
- C2 / reverse shell over 443: blends in with normal HTTPS.
- DNS tunneling (iodine, dnscat2) if outbound DNS passes (see DNS Attacks).
- HTTP/HTTPS tunneling and domain fronting over 443.
- ICMP tunneling (ptunnel) if ICMP leaves.
# discover which outbound ports the firewall allows.# NOTE: use a host that LISTENS on all ports (e.g. portquiz.net); against 8.8.8.8 a failure# may just mean there is no TCP service on that port, not that egress blocks it.for p in 21 22 53 80 443 8080; do timeout 3 bash -c "echo > /dev/tcp/portquiz.net/$p" 2>/dev/null && echo "outbound $p allowed"; doneIDS/IPS evasion
Section titled “IDS/IPS evasion”Classic techniques against signature-based detection:
- Fragmentation and ambiguous reassembly: the IDS and the host reassemble differently, and the signature does not match.
- Payload obfuscation/encoding so it does not match the signature (same principle as WAF, see WAF Bypass).
- Encryption: a payload inside TLS is not inspectable without interception.
- Timing: space out events so you don’t exceed thresholds like “N events in T time”.
- Polymorphism: vary the payload on each attempt.
Egress filtering: the C2 challenge
Section titled “Egress filtering: the C2 challenge”A reverse shell needs to leave the network. If egress is filtered, the usual ways out are: use the port that does leave (normally 443), tunnel over DNS or HTTP (see Pivoting and Tunneling and DNS Attacks), or resort to domain fronting and CDNs to disguise the real destination.
Blue Team
Section titled “Blue Team”- Default-deny on ingress and egress (strict egress filtering): cuts C2 and reverse shells.
- Up-to-date IDS/IPS with normalized reassembly (defeats fragmentation evasion) and TLS inspection where feasible.
- Rate-limiting and scan detection; SIEM correlation.
- Segmentation and an allowlist of outbound destinations; Protective DNS to cut tunneling.
- Assume the attacker will try 443 and DNS: inspect those channels too, not just trust that they are “allowed”.
Checklist
Section titled “Checklist”- Map firewall rules (ACK scan, which ports pass)
- Evasive scan (timing, fragmentation, decoys, source-port)
- Identify allowed outbound ports (egress)
- C2/reverse shell over 443 or another allowed port
- Tunneling over DNS/HTTP/ICMP if filtering is strict
- IDS evasion via fragmentation/obfuscation/encryption
- Blue: verify egress default-deny, normalized IDS, Protective DNS
- Document which controls were evaded and how