Skip to content
Tutorials Center
My learning

Topics

Lesson 27 of 36 ยท Evasion, Timing and Ethics

Firewalls, IDS and Evasion Concepts

Understand how firewalls and intrusion detection shape scan results, what filtered means, and what Nmap's evasion options are for in authorised testing of your own defences.

A firewall sits between the scanner and the target and decides which packets may pass. An intrusion detection system (IDS) or intrusion prevention system (IPS) watches traffic for patterns that look like attacks, including port scans. When you scan a network, these devices shape what you see, and they may react to you. Understanding them helps in two ways: you interpret results correctly, and, as a defender, you can check whether your own protections notice reconnaissance.

This lesson treats evasion as a testing topic. Nmap's evasion options exist so that security teams can test whether their own firewalls and monitoring are effective. They must be used only inside a scope that you are authorised to test. Using them against networks without permission is illegal in many countries and is not what this course teaches.

Do not use any technique in this chapter on systems you do not own or have written permission to test. Authorisation is covered in Legal and Ethical Scanning.

What firewalls do to scan results

A stateful firewall can answer a probe in several ways, which produce the port states you already know:

Firewall action What the scanner sees Nmap state
Allow, and a service listens SYN/ACK open
Allow, and nothing listens RST closed
Drop silently Nothing, after retries filtered
Reject with ICMP unreachable ICMP type 3 filtered
Rate-limit RST replies Slow or inconsistent RSTs closed or filtered

filtered therefore means "something in between is hiding the true state". A host that is filtered on 999 ports and open on one is likely behind a default-deny firewall with a single allowed service. Drops are much slower to scan than rejects because every probe waits for a timeout (see Timing).

flowchart LR
    S["Scanner"] -->|"SYN to port 22"| F["Firewall"]
    F -->|"allowed"| H["Host: port 22 open"]
    S -->|"SYN to port 23"| F
    F -->|"dropped: no reply"| X["Scanner sees filtered"]
    S -->|"SYN to port 24"| F
    F -->|"rejected: ICMP unreachable"| Y["Scanner sees filtered"]

Different firewall actions look different on the wire but may all be reported as filtered.

A firewall model

The stand-in below applies a rule list to probes and prints what a scanner would observe. It is a model with invented rules, useful to see why results look the way they do.

Python Stand-in: what a scanner sees through a firewall

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

This shows a key truth: a scan shows the world as seen from where you scan. Scan from inside and outside a firewall to compare what each side sees, then fix any difference you did not intend.

What an IDS looks for

Detection systems commonly flag:

  • Many ports from one source in a short time (a port scan signature).
  • Many hosts probed on the same port (a sweep).
  • Unusual flag combinations such as TCP packets with no flags (NULL), all flags (XMAS) or only FIN.
  • Known tool fingerprints, for example the default User-Agent of a script or specific probe payloads.
  • Connections that never complete, such as half-open SYN connections.

Most of these can be seen in firewall logs too. Detecting Scans in Logs builds a detector. It is also why a well-configured network notices Nmap quickly at default settings.

Nmap options for testing defences

The man page groups these under "firewall/IDS evasion and spoofing". A defender uses them to ask "would my controls catch this?". Each one changes what a device sees:

Option Idea What it tests
-f, --mtu Split probes into small IP fragments Whether the firewall reassembles fragments before inspection
-D decoy1,decoy2,ME Mix your address with decoy addresses Whether logs and analysts can identify the real source
-S, -e Set a source address and interface Spoofing controls; rarely useful, replies go elsewhere
-g / --source-port Use a chosen source port, such as 53 Whether a rule trusts traffic by source port alone
--data-length Add random data to packets Whether signatures depend on exact packet size
--ttl Set the IP TTL Where in the path a device is located
--badsum Send packets with an invalid checksum Whether a firewall or IDS replies to bad packets (real hosts drop them)
-T0, -T1 Very slow probes Whether rate-based rules are the only detection
--randomize-hosts Shuffle target order Whether sequential-scan detection works
--spoof-mac Use a chosen MAC address LAN access control tied to MAC addresses
Terminal
# Example commands (read-only): only against your own lab firewall
nmap -f -T2 192.0.2.40                      # fragmented, slow probes
nmap --source-port 53 -p 1-1024 192.0.2.40  # does a "DNS only" rule trust the source port?
nmap --badsum 192.0.2.40                    # a real host should not answer; a firewall might

The --badsum test is a neat defensive trick. Bad-checksum packets are dropped by a genuine host's network stack, so any reply means a middlebox (firewall or IDS) is generating answers itself. The stand-in demonstrates the logic.

Python Stand-in: interpret a --badsum test

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Evasion is a defender's measuring stick

Used in an authorised exercise, evasion options produce a useful report: "fragmented probes were not reassembled by the firewall", "source-port 53 traffic bypassed the rule on VLAN 10", "decoys made the alert unreadable". Each result leads to a fix, such as enabling fragment reassembly, removing source-port trust or alerting on the pattern rather than the tool.

Remember the limits. Modern systems normalise traffic, reassemble fragments and correlate across time, so most simple tricks no longer work against good defences, and they always leave traces. The practical lesson is not "how to hide" but "build layered monitoring that does not depend on a single signature".

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does a 'filtered' port mean?

    Filtered means no definite open or closed answer arrived: packets were dropped or rejected before reaching the service.
  2. 2. Why are scans against dropping firewalls slow?

    A drop gives no reply, so Nmap waits for the timeout and retransmits. A reject gives a fast ICMP answer.
  3. 3. What does a reply to a --badsum probe reveal?

    A genuine TCP/IP stack discards packets with a wrong checksum, so only an intermediate device would answer.
  4. 4. What is the right purpose of Nmap's evasion options in this course?

    They are measuring tools for defenders and authorised testers. Without permission, using them is unlawful.

Summary

  • Firewalls turn probes into open, closed or filtered; drops are slow, rejects are fast.
  • A scan reflects the view from where you scan: compare inside and outside.
  • IDS rules look for many ports or hosts in short time, odd flags and tool signatures.
  • Evasion options (-f, -D, --source-port, --badsum, slow timing) are tests of your own controls, used only with authorisation.

Next: Detecting Scans in Logs