How Port Scanning Works: SYN, FIN, UDP, and OS Detection

Port scanning is the process of systematically probing a host's TCP or UDP ports to determine which services are listening. Network administrators use it to audit their own infrastructure; attackers use it to map targets before exploitation. Understanding exactly what scanning reveals — and how it works at the packet level — is essential for both hardening systems and tuning intrusion detection.

Authorization matters: scanning systems you do not own or have explicit written permission to test is illegal in most jurisdictions under computer fraud statutes. The techniques below are described for defensive understanding and authorized security assessments.

What Scanning Reveals

A port scan returns, for each probed port, one of three states:

StateMeaningTypical cause
openA service is actively listening and accepted the probeApplication bound to port
closedHost is reachable but nothing is listeningOS returned RST or ICMP port unreachable
filteredProbe was dropped with no responseFirewall silently discarding packets

From these states, a scanner can infer what software is running, what version it may be, and — via OS fingerprinting — the operating system and its kernel version. Combined with banner grabbing, a scan often produces an actionable target profile within seconds.

TCP Connect Scan

The simplest scan: the scanner completes a full TCP three-way handshake. It calls connect() on the target port. If the handshake succeeds (SYN → SYN/ACK → ACK), the port is open. If the target replies with RST/ACK, it is closed. If there is no reply within the timeout, it is filtered.

This requires no special privileges — any process can call connect(). The tradeoff is that the full connection is visible in the server's logs (the connection reaches the application layer) and is easily detected.

SYN (Half-Open) Scan

The most common technique, requiring raw socket privileges (root or CAP_NET_RAW). Instead of completing the handshake, the scanner:

  1. Sends a SYN packet
  2. Receives SYN/ACK → port is open; immediately sends RST to tear down without completing the connection
  3. Receives RST/ACK → port is closed
  4. No reply (or ICMP unreachable) → port is filtered

Because the handshake is never completed, many applications never log the probe — it never reaches the accept queue. The RST is sent by the scanner's kernel in response to the unsolicited SYN/ACK (or explicitly by the scan tool). This is faster and less visible than a connect scan, though the SYN packets themselves are still visible to a stateful firewall or IDS.

TCP Scan Types: Packet-Level Comparison Connect Scan (open) Scanner Target SYN SYN/ACK ACK (full open) SYN Scan (open) Scanner Target SYN SYN/ACK RST (never logs) SYN Scan (filtered) Scanner Firewall SYN DROP — no reply timeout => filtered SYN scan avoids the application log entry; stateful firewalls still see the SYN DROP vs REJECT: DROP leaks topology by hiding filtered ports; REJECT exposes them

Stealth Scans: FIN, NULL, and Xmas

RFC 793, the original TCP specification, defines behavior for receiving unexpected packets. On a closed port, a compliant TCP stack must respond to any segment that does not carry SYN with an RST. On an open port, the stack should silently discard packets that are not part of an established connection and carry no SYN.

This asymmetry enables three scan variants:

These scans are invisible to simple packet filters that only track SYN packets — a stateless ACL blocking inbound SYN will pass FIN or NULL packets through untouched. However, they are unreliable against Windows and many other non-Unix stacks, which do not follow RFC 793 strictly and may send RST for open ports as well, making open and closed indistinguishable.

UDP Scanning

UDP has no handshake, which makes scanning fundamentally different. The scanner sends a UDP datagram to each port. Possible outcomes:

The ambiguity of no-response makes UDP scanning slow and noisy. Most OS kernels rate-limit outbound ICMP unreachable messages (Linux defaults to 1 per second), so a UDP scan of all 65,535 ports may take 18+ hours without tuning. Nmap sends protocol-specific payloads (a DNS query to port 53, an NTP request to port 123, etc.) to elicit application-layer responses from known services, narrowing the open|filtered ambiguity.

Banner Grabbing and Version Detection

Once open ports are identified, version detection connects and reads the service banner — the first few bytes sent by the server. Many services announce themselves immediately:

Nmap's -sV flag sends a library of probes and matches responses against a database of service fingerprints, often identifying not just the software but its version, which can be cross-referenced against public vulnerability databases.

OS Fingerprinting

TCP/IP implementations differ subtly across operating systems. Nmap's -O flag analyzes a combination of fields in probe responses:

Against a known target with a SYN scan plus OS detection, Nmap can often identify the OS family and approximate kernel version with high confidence.

Common Nmap Invocations

CommandWhat it does
nmap -sS 192.0.2.1SYN scan of 1,000 most common ports
nmap -sS -p- 192.0.2.1SYN scan all 65,535 ports
nmap -sV -O 192.0.2.1Version detection + OS fingerprint
nmap -sU -p 53,123,161 192.0.2.1UDP scan of specific ports
nmap -sS --min-rate 5000 192.0.2.0/24Fast subnet sweep
nmap -sn 192.0.2.0/24Ping sweep only (no port scan)
nmap -sS -T4 -A 192.0.2.1Aggressive: version, OS, scripts, traceroute

The -T timing flag (0=paranoid to 5=insane) controls inter-probe delays. Slower timing is harder to detect; faster timing risks missed responses from rate-limited hosts.

Internet-Wide Scanning

Tools like Zmap and Masscan are purpose-built for scanning the entire IPv4 address space. They bypass the OS network stack entirely, generate packets directly at line rate, and can scan all 3.7 billion routable IPv4 addresses on a single port in under 5 minutes from a 10 Gbps link. These tools power services like Shodan and Censys, which continuously scan the internet and index service banners, TLS certificate metadata, and protocol-specific responses, making it trivial to find all exposed instances of a specific software version globally.

For defenders, this means any externally reachable port is effectively scanned continuously. The question is not whether attackers will find your exposed services, but when.

What Defenders See

Modern IDS/IPS systems recognize scan patterns by tracking:

Snort/Suricata ship with rules for all of these patterns. Many cloud providers and CDNs also rate-limit or block known scanner IP ranges.

Hardening: Reducing What Scans Reveal

The primary defense is minimizing attack surface: every open port is a potential vulnerability. Close or firewall any service not needed externally. For the ports that must remain open:

Explore It Live

See BGP routing data in real time

Open Looking Glass
← Previous What Is DNS Cache Poisoning? Kaminsky Attack Explained
More Articles
How TLS/HTTPS Works: Securing the Internet's Traffic
Certificate Transparency: How CT Logs Secure the Web's PKI
How Firewalls Work: Packet Filtering, Stateful Inspection, and Beyond
What is Cross-Site Scripting (XSS)?
What is Cross-Site Request Forgery (CSRF)?
What is Server-Side Request Forgery (SSRF)?