Skip to content
Tutorials Center
My learning

Topics

Lesson 16 of 36 ยท Port Scanning Techniques

Null, FIN and Xmas Scans

Understand how the TCP flag scans -sN, -sF and -sX exploit RFC 793, why they work on some systems and not on Windows, and how to defend against them.

The SYN and connect scans start a connection. The NULL, FIN and Xmas scans do something odd: they send packets that do not belong to any connection, and then watch how the target reacts. They exploit a corner of the original TCP specification (RFC 793) and are useful for two reasons: they can slip past very simple stateless packet filters that only look for SYN packets, and they teach you how TCP stacks behave. They also have well-known limits, and modern firewalls handle them easily. This lesson explains the idea, the results and the defense.

Commands are read-only; use only on systems you own or are authorized to test. Never use these scans to evade a control you were told not to bypass: if evasion is not in your scope, do not try it. The Python editors apply the rules to made-up packets in memory.

The idea from RFC 793

RFC 793 says that a closed port, when it receives a segment that is not a RST, must reply with a RST. It also says that an open port, when it receives a segment with no SYN, no RST and no ACK, should just drop it silently. So if you send an unusual packet:

  • RST back means the port is closed.
  • No reply means the port is open or filtered (nothing came back either way).
  • An ICMP unreachable error (type 3, codes 1, 2, 3, 9, 10, 13) means the port is filtered.

There is no SYN-ACK in the story, which is why a filter that blocks "new connection" packets (SYN without ACK) may let these through.

The three scans

Option Flags set Why the name
-sN (NULL) none (all flag bits 0) Nothing is set
-sF (FIN) FIN only A connection-closing packet from nowhere
-sX (Xmas) FIN + PSH + URG The packet is "lit up like a Christmas tree"
Terminal
sudo nmap -sN -p 22,80,443 192.0.2.10
sudo nmap -sF 192.0.2.10
sudo nmap -sX -p 1-1000 192.0.2.10

All three need raw sockets, so root or Administrator. Because they all rely on the same rule, they give the same results; Xmas just has a more recognizable signature and is the easiest for intrusion detection systems to spot.

Example output (invented, against a Linux host):

TEXT
Not shown: 997 closed tcp ports (reset)
PORT    STATE         SERVICE
22/tcp  open|filtered ssh
80/tcp  open|filtered http
443/tcp open|filtered https

Example output. Open ports show up as open|filtered: the scan cannot confirm they are open, only that they did not reset. Combine it with -sV to check which of those really answer.

flowchart TD
  S["Send NULL / FIN / Xmas packet"] --> R{"Reply?"}
  R -- "RST" --> C["closed"]
  R -- "ICMP unreachable" --> F["filtered"]
  R -- "no reply" --> OF["open|filtered"]

Figure: how the flag scans classify a port.

Where they work and where they do not

The scans depend on the target following RFC 793 exactly. That is true for most Unix-like systems (Linux, BSD, many embedded devices). It is not true for:

  • Microsoft Windows: it sends RST for every such packet, open or closed, so every port looks closed. This is actually a useful OS-detection hint (see Chapter 5).
  • Many Cisco and other network devices with different stacks.
  • Firewalls and IDS, which today often drop or log packets with odd flag combinations (a NULL packet or FIN+PSH+URG is never legitimate for a new connection). Stateful firewalls track connections and drop packets that match none.

Because of this, treat the results as hints. A closed result (RST) is reliable evidence of a reachable, closed port. An open|filtered result is much weaker than a SYN scan's open.

What are they good for today?

  • Learning how TCP stacks implement the specification.
  • Testing firewalls that you administer: does your stateless filter let a NULL or FIN packet through? Does your IDS raise an alarm for Xmas packets?
  • Cross-checking a SYN scan on a tricky network, in an authorized assessment.
  • Spotting OS differences: Windows versus Unix behavior.

Defending against them

  • Use a stateful firewall: a FIN or NULL packet that matches no established connection is dropped (or logged).
  • Add explicit rules or signatures that flag packets with illegal flag combinations (no flags set; SYN+FIN; FIN+PSH+URG).
  • Keep logs and alert on bursts of such packets from one source: a mass of odd-flag packets to many ports is almost always a scan.
  • Do not rely on obscurity: assume every attacker can try every scan type.

Flag scans at a glance

NULL (-sN) No flags set at all.
FIN (-sF) Only FIN set.
Xmas (-sX) FIN, PSH and URG set.

RST means closed. Silence means open or filtered.

1 / 2

A stand-in: how two stacks answer an odd packet

This program models a Unix-like stack and a Windows-like stack. Each receives a probe with given flags and answers according to its own rule. You can then see why the scans work on one and mislead on the other.

Python Two TCP stacks, one NULL/FIN/Xmas probe

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.

On the Unix-like stack, ports 22 and 80 stand out as open|filtered. On the Windows-like stack every port looks closed, so the scan reveals nothing about services, but it hints at the operating system.

A stand-in: a defender's flag-combination detector

A defender can check each packet's flags for combinations that no honest client sends. The stand-in reuses the flag bits from Networking Basics for Nmap.

Python Flag anomaly detector

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.

Notice that a normal connection close (FIN+ACK, 0x11) passes while a lone FIN raises a flag. That is the same distinction a stateful firewall makes using its connection table.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. A NULL scan gets a RST from a port. What state is reported?

    Per RFC 793, a closed port answers an unexpected segment with RST.
  2. 2. Which flags are set in an Xmas scan packet?

    The Xmas scan sets FIN, PSH and URG, lighting the packet up like a Christmas tree.
  3. 3. Why do these scans give misleading results against Windows hosts?

    Windows does not follow the RFC 793 rule for open ports, so open ports are not distinguishable.
  4. 4. What is the best defense against flag scans?

    Stateful tracking drops stray FIN, NULL and Xmas packets, and logs make bursts visible.

Summary

  • NULL (-sN), FIN (-sF) and Xmas (-sX) scans send packets that belong to no connection.
  • RST means closed; silence means open|filtered; ICMP unreachable means filtered.
  • They work on RFC-conforming stacks (many Unix systems) and fail against Windows-like stacks.
  • Stateful firewalls and flag-anomaly rules detect and block them; use them only with permission.

Next: ACK, Window and Maimon Scans