Skip to content
Tutorials Center
My learning

Topics

Lesson 24 of 37 ยท Security Analysis

Spotting Port Scans in Captures

Learn how port scans look in a packet capture, which Wireshark filters expose them, and how defenders build simple detection logic. Authorized analysis only.

A port scan asks many ports on a host, "are you listening?". Network administrators run scans against their own systems to find exposed services. Attackers run them to find a way in. In both cases the scan leaves a very recognizable pattern in a packet capture, and Wireshark makes it easy to see.

This lesson is about recognizing scans in traffic you are allowed to analyze. It does not show how to scan other people's systems. Scanning networks you do not own or have written permission to test is illegal in many countries. The Python code here only works on sample records and, at most, on your own loopback interface.

What a scan looks like

A normal client talks to a few ports on a few hosts. A scanner touches many ports (a vertical scan) or many hosts (a horizontal sweep) in a short time, usually with tiny packets and no real data.

Common scan patterns

SYN scan SYN, no final ACK.
Connect scan Full handshake, then close.
UDP scan UDP probes, ICMP unreachable.
Null/FIN/Xmas Odd flag combinations.

Each leaves a different footprint.

1 / 2

The SYN scan footprint

The scanner sends a SYN to a port. An open port answers SYN-ACK, a closed port answers RST, and a filtered port stays silent. A SYN ("half-open") scan then sends an RST instead of finishing the handshake, so the application never sees a connection.

TEXT
 1  0.0000  198.51.100.7 -> 192.0.2.10  TCP 44 51822 > 22   [SYN]
 2  0.0001  192.0.2.10   -> 198.51.100.7 TCP 44 22 > 51822  [SYN, ACK]
 3  0.0001  198.51.100.7 -> 192.0.2.10  TCP 40 51822 > 22   [RST]
 4  0.0003  198.51.100.7 -> 192.0.2.10  TCP 44 51823 > 23   [SYN]
 5  0.0003  192.0.2.10   -> 198.51.100.7 TCP 40 23 > 51823  [RST, ACK]
 6  0.0005  198.51.100.7 -> 192.0.2.10  TCP 44 51824 > 25   [SYN]
 7  0.0005  192.0.2.10   -> 198.51.100.7 TCP 40 25 > 51824  [RST, ACK]

Example addresses from the documentation ranges. Notice: the destination port increases one by one, the source port also changes each time, packets are about 44 bytes (no payload), and the gaps are in microseconds. A person with a browser never behaves like that.

Wireshark filters to isolate these:

TEXT
tcp.flags.syn == 1 && tcp.flags.ack == 0      # connection attempts only
tcp.flags.reset == 1                           # resets (closed ports)
tcp.flags == 0x000                             # NULL scan (no flags)
tcp.flags == 0x001                             # FIN only
tcp.flags & 0x29 == 0x29                       # FIN, PSH, URG: Xmas scan
icmp.type == 3 && icmp.code == 3               # port unreachable (UDP scan)

For a capture of a whole network, open Statistics, then Conversations, and sort by the number of packets or ports. One source address paired with hundreds of destination ports stands out immediately.

Detecting scans with code

Defenders count distinct destination ports (or hosts) per source in a time window. Intrusion detection systems do essentially this, with many refinements.

Python Flag sources that touch many ports

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 thresholds matter. Too low and a busy proxy or a monitoring system triggers alerts. Too high and a "low and slow" scan, spread over hours, hides under the limit. Longer windows catch slow scans at the cost of more memory.

Telling scanners apart from normal software

  • Health checks from load balancers connect to the same port repeatedly. They do not walk through ports.
  • Vulnerability scanners run by your own security team are scans too. Keep a list of authorized scanner addresses so alerts can be matched against it.
  • Port knocking and peer-to-peer apps can touch several ports briefly, but they send real data.
  • Fingerprints: some scanners use fixed window sizes, TCP options, or TTL values. Several identical SYN packets with the same unusual options from one source is a clue, though not proof.

What to do when you find one

  1. Note the source address, time range, and ports touched. Save the capture.
  2. Check whether the source is internal. An internal host scanning peers may be compromised.
  3. Check what answered. Open ports found by the scanner are what you must review: were they meant to be reachable?
  4. Block or rate-limit at the firewall, and watch for follow-up activity such as logins to the ports that answered.

A scan that found only closed ports is much less serious than a scan followed by a login attempt on an open one. Always look at what came after the scan.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. How does a closed TCP port normally answer a SYN?

    A closed port answers with RST (usually RST, ACK); an open port sends SYN-ACK; a filtered port often sends nothing.
  2. 2. Which pattern best matches a vertical port scan?

    A vertical scan probes many ports on one host quickly, without sending application data.
  3. 3. Why is a 'low and slow' scan hard to detect?

    Time-window counters miss probes spread too thin, so detection needs longer windows or per-source totals.
  4. 4. Which Statistics window helps find a source touching many ports?

    The Conversations window lists address and port pairs with packet counts, so a scanner shows up as one source with many entries.

Summary

  • Scans show as many ports (or hosts) touched quickly with tiny, payload-free packets.
  • Open ports answer SYN-ACK, closed ports RST, filtered ports stay silent.
  • Defenders count distinct ports per source in a time window and whitelist authorized scanners.
  • Scan only what you own or are authorized to test, and always look at what happened after the scan.

Next: ARP Spoofing and LAN Anomalies