Skip to content
Tutorials Center
My learning

Topics

Lesson 14 of 36 ยท Port Scanning Techniques

SYN and Connect Scans

Compare the half-open SYN scan and the full TCP connect scan: how each works, what the target logs, when to choose which, and simulate both handshakes in Python.

Two scan types do most of the world's port scanning: the SYN scan (-sS) and the TCP connect scan (-sT). Both test TCP ports using the three-way handshake you saw in Networking Basics for Nmap. They differ in how far they let the handshake go, and that difference decides speed, what the target's logs contain and what privileges you need.

Commands are read-only; scan only what you are authorized to test. The Python editors simulate handshakes between objects in memory: no sockets, no packets.

The SYN scan: -sS

The SYN scan is Nmap's default when you run as root (or Administrator with Npcap). It is also called the half-open or "stealth" scan, though modern firewalls and intrusion detection systems see it easily, so "stealth" is outdated.

Nmap builds the SYN packet itself and watches the reply:

  1. SYN-ACK back: the port is open. Nmap immediately sends a RST to tear down the half-made connection, so no full connection is ever established.
  2. RST back: the port is closed.
  3. Nothing after retransmissions, or certain ICMP unreachable errors: filtered.
sequenceDiagram
  participant N as Nmap
  participant T as Target
  Note over N,T: Port open
  N->>T: SYN
  T->>N: SYN, ACK
  N->>T: RST (never completes)
  Note over N,T: Port closed
  N->>T: SYN
  T->>N: RST, ACK

Figure: the SYN scan against an open port, then a closed port.

Terminal
sudo nmap -sS 192.0.2.10

Benefits:

  • Fast. Nmap can send thousands of probes per second without waiting for full connections.
  • Accurate. Because Nmap crafts the packets itself, it distinguishes open, closed and filtered well.
  • Fewer application traces. Since the connection never completes, many services never see a connection and do not log it. Firewalls and network intrusion detection systems still do.

Downside: it needs raw sockets, so root or Administrator privileges.

The connect scan: -sT

When Nmap cannot craft raw packets (a normal user, or Windows without Npcap), it asks the operating system to do an ordinary connect() call to each port, exactly like a web browser would. If the connect succeeds, the port is open; Nmap closes it right away.

Terminal
nmap -sT 192.0.2.10        # no root needed
TEXT
Not shown: 998 closed tcp ports (conn-refused)
PORT   STATE SERVICE
22/tcp open  ssh
80/tcp open  http

Example output (invented). Note the reason conn-refused instead of reset: the OS reported a refusal.

Properties:

  • Works without privileges and through some proxy chains.
  • Slower and noisier. The OS completes a full handshake for every open port, and the service sees a connection that opens and closes at once, so it often logs "connection from X" or "connection reset by peer" errors (for example in SSH or database logs).
  • Less control over timing and packet details, because the OS decides.

Side by side

SYN scan -sS Connect scan -sT
Privileges root/Administrator none
Handshake Half-open (RST instead of final ACK) Full, then closed
Speed Very fast Slower
Logged by application? Usually no Often yes
Seen by firewall/IDS? Yes Yes
Default when You are root You are not root
IPv6 Yes Yes

SYN vs connect

-sS Half-open. Fast. Needs root.
-sT Full connect. No root. Noisier.

Both give the same port states.

1 / 2

What the target and the network see

Neither scan is invisible. A firewall that logs new connections sees a burst of SYN packets from one source to many ports in a short time, which is the textbook pattern of a port scan. A connect scan additionally leaves application-level traces. Defenders recognize scans by looking for one source touching many ports within seconds, regardless of type. If you want to know whether a scan was detected, ask the owner; if you want to practice detection, see the stand-in below.

Retransmissions explain why filtered ports are slow: Nmap resends a SYN several times (--max-retries, default depends on timing) before giving up, as Choosing Ports hinted.

A stand-in: a half-open handshake, in objects

This simulation has a Target with open and closed ports and two scanners. It records what the target would see: SYN scans never complete a connection, connect scans do.

Python SYN scan vs connect scan: what the target sees

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.

Both find ports 22 and 80, but only the connect scan leaves lines in the application log.

A stand-in: detect a scan from a connection log

Defenders can spot either scan by counting how many distinct ports one source touches in a short time. This simulation reads a small invented log and flags scanners.

Python Detect a port scan in a log

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.

Real systems use the same idea with more care: allow-lists for your own scanners, sliding windows, and alerts that include timing.

Choosing between them

  • As root with a normal network path: use -sS.
  • As a normal user, or when raw packets are not possible (some VPNs, containers, Windows without Npcap): use -sT.
  • When a service logs every connection and you do not want noise: prefer -sS and tell the owner what you are doing.
  • When you scan through a proxy (SOCKS via proxychains): -sT is the only one that works, because it uses ordinary sockets.

Both can be combined with -sV (Service and Version Detection), which completes real connections to open ports anyway.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Why is the SYN scan called half-open?

    After SYN-ACK, Nmap resets the connection instead of sending the final ACK.
  2. 2. Which scan works without root privileges?

    The connect scan uses the operating system's connect() call; the others need raw sockets.
  3. 3. A connect scan hits an open SSH port. What may the SSH server log?

    The full handshake completes, so the application may log the short-lived connection.
  4. 4. Which is true for modern networks?

    Both scan types are visible at the network level; 'stealth' is a historical name.

Summary

  • -sS (SYN, half-open) is fast, needs root and is the default for privileged users.
  • -sT (connect) works without privileges and through proxies but is slower and noisier.
  • Both report open, closed and filtered ports; neither is invisible to firewalls.
  • Scan detection looks for one source touching many ports quickly.

Next: UDP Scanning