Skip to content
Tutorials Center
My learning

Topics

Lesson 12 of 36 ยท Host Discovery

Discovery Probes: TCP, UDP and ICMP

A tour of Nmap's host discovery probes: ICMP echo, timestamp and mask, TCP SYN and ACK pings, UDP and IP protocol pings, with a packet and checksum builder.

When the target is not on your local network, ARP is not available, and Nmap must find hosts with IP-level probes. Firewalls love to block the most famous one (ICMP echo, the plain ping), so Nmap offers a whole toolbox: several ICMP messages, TCP SYN and ACK pings, UDP pings and raw IP protocol pings. In this lesson you learn what each probe does, what reply makes the host "up", and how to combine them.

Commands are read-only; probe only networks you are authorized to test. The Python editors build packet bytes in memory and never transmit them.

ICMP probes

ICMP (protocol 1) has several message types that can be used as pings:

Option Message Reply that shows the host is up
-PE Echo request (type 8): the classic ping Echo reply (type 0)
-PP Timestamp request (type 13) Timestamp reply (type 14)
-PM Address mask request (type 17) Address mask reply (type 18)

Why three? Administrators who block echo sometimes forget the others. Today many hosts answer none of them, which is why TCP probes matter. Modern scans also treat ICMP "destination unreachable" from the host itself as proof it exists.

Terminal
sudo nmap -sn -PE 192.0.2.0/24     # echo only
sudo nmap -sn -PE -PP -PM 192.0.2.0/24

TCP SYN ping: -PS

-PS sends a TCP SYN to the given ports (default 80) as if starting a connection. The target replies SYN-ACK if the port is open, or RST if it is closed. Either reply means the host is up. The initial connection is never completed: Nmap's operating system sends a RST for the SYN-ACK, so no connection reaches the application.

Terminal
sudo nmap -sn -PS22,80,443 192.0.2.0/24

Pick ports that firewalls usually allow in: 80 and 443 for web servers, 22 for SSH, 25 for mail.

TCP ACK ping: -PA

-PA sends a bare ACK packet. A host with no connection state will answer with a RST, proving existence. Stateless packet filters let ACKs through (they look like replies to an earlier connection), while stateful firewalls drop them. Sending both SYN and ACK pings is the default as root because it beats either kind of firewall.

Terminal
sudo nmap -sn -PA80,3389 192.0.2.0/24

As a normal user, -PA cannot send a lone ACK; Nmap does a connect() instead, which sends a SYN. Raw ACK probes need root.

UDP ping: -PU

-PU sends an empty UDP packet to the port (default 40125, chosen because it is almost certainly closed). A closed port returns an ICMP port unreachable, which proves the host exists. An open UDP service might reply with data or stay silent (silence means nothing). So -PU is best aimed at unused ports and used where ICMP unreachable messages are not filtered.

Terminal
sudo nmap -sn -PU53,161 192.0.2.0/24

SCTP and IP protocol pings

  • -PY sends an SCTP INIT chunk, useful for telecom and some cluster systems.
  • -PO sends raw IP packets with the protocol numbers you list (default 1, 2 and 4: ICMP, IGMP and IP-in-IP). A reply, or an ICMP "protocol unreachable", shows the host is up.
Terminal
sudo nmap -sn -PO1,2,4 192.0.2.0/24

Combining probes

Nmap sends all chosen probes in parallel. The more kinds you list, the more hosts you find and the more noise you make. A balanced command for a remote network:

Terminal
sudo nmap -sn -PE -PS22,80,443 -PA80,3389 -PU161 192.0.2.0/24
flowchart LR
  S["Scanner"] -->|"ICMP echo"| T["Target"]
  S -->|"TCP SYN :443"| T
  S -->|"TCP ACK :80"| T
  S -->|"UDP :40125"| T
  T -->|"any valid reply"| S

Figure: several probes go out in parallel; the first valid reply marks the host as up.

Reading the reasons

Use --reason to see which probe worked. For a hardened host you might see only one working path:

TEXT
$ sudo nmap -sn --reason -PE -PS443 203.0.113.50
Nmap scan report for 203.0.113.50
Host is up, received syn-ack ttl 52 (0.040s latency).

Example output (invented). received syn-ack tells you the host ignores ICMP echo but answered the SYN to port 443. The ttl 52 is the remaining hop count of the reply (a starting value of 64 minus 12 hops).

A stand-in: build an ICMP echo request

An ICMP echo request is tiny: type 8, code 0, a checksum, an identifier, a sequence number and optional data. The only tricky part is the Internet checksum: add 16-bit words with carry wraparound, then invert. This program builds the packet and verifies it.

Python Build an ICMP echo request with its checksum

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.

The check checksum(pkt) == 0 is how a receiver validates a packet: the sum including the checksum field folds to all ones, and the inverted result is zero.

A stand-in: classify discovery replies

This lookup decides whether a reply proves the host is up for each probe type, including the surprising ones where an error also counts.

Python Does this reply prove the host is up?

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.

The last row is a subtle one: an ICMP "administratively prohibited" message usually comes from a router or firewall, not from the target, so it does not prove the target exists. Real Nmap applies this reasoning.

Tips

  • Run as root; unprivileged users get fewer probe types.
  • For firewalled targets, aim TCP probes at ports you know are open.
  • -sn -n makes a sweep faster by skipping DNS.
  • Keep a sweep's probe list in your notes: it is part of your evidence of what was done.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. A TCP SYN ping receives a RST from the target. Is the host up?

    A reset is generated by the target's operating system, so the host exists.
  2. 2. Which option sends the UDP discovery probe?

    -PU sends an empty UDP packet; a closed port returns ICMP port unreachable.
  3. 3. Why does Nmap send both SYN and ACK pings by default as root?

    Different firewalls block different probes, so using both finds more hosts.
  4. 4. Which option controls ICMP timestamp requests?

    -PE is echo, -PP timestamp, -PM address mask, -PR ARP.

Summary

  • ICMP probes (-PE, -PP, -PM), TCP probes (-PS, -PA), UDP (-PU) and IP protocol (-PO) find hosts in different ways.
  • Any valid reply from the target, including RST and ICMP port unreachable, proves it is up.
  • Combine probes to beat firewalls that block one kind; use --reason to see what worked.
  • Packet building is just structured bytes plus a checksum.

Next: List Scan and DNS Resolution