skip to content

Why would an assessor choose Nmap's SYN scan over the TCP connect scan, and what changes in privilege, packets and target logs?

level: middleimportance: must knowfreq 46%

answer

  1. same states, different plumbing
  2. raw packets against the sockets API
  3. what a normal user can run
  4. the default switches by itself
  5. services log the closed connection

basics

~20 s

-sS sends raw SYN packets, needs raw-packet privilege and never completes the handshake. -sT asks the operating system to connect(), needs no privilege, but completes connections to open ports, so it is slower and more likely to be logged.

solid answer

~30 s

`-sS` crafts raw SYN packets and never completes the handshake; that needs root or equivalent. `-sT` calls the operating system's `connect()`, so it works for any user, but it completes connections to open ports, takes more packets and gives Nmap less control. Nmap performs a SYN scan by default and falls back to a connect scan when the user cannot send raw packets. For the defender, connect scans tend to leave service log lines and SYN scans usually do not, so a clean application log never clears a host; the firewall and flow logs show both.

go deeper

for a junior

Know that -sS uses raw packets and -sT uses the system's connect() call, and that -sS is the default when you have the privilege.

for a middle

Explain the privilege split, the automatic fallback versus the error on an explicit -sS, and why the connect scan is slower and noisier in service logs.

for a senior

Choose per target: connect scans on fragile production hosts need owner agreement, and a log reviewer must not read missing application lines as proof of no scan.

for a principal

Set the standing method for scanning hosts: which scanner gets privilege, which falls back, and how the choice and its log footprint are stated in every report.

## Two ways to ask the same question Both scans ask a TCP port whether anything is listening and read the answer as `open`, `closed` or `filtered`. They differ in how the probe is made. - **SYN scan (`-sS`)** builds raw TCP segments itself. It sends a SYN, reads the reply, and never completes the handshake. - **TCP connect scan (`-sT`)** asks the operating system to establish a connection with the `connect()` system call, the same Berkeley sockets call a web browser uses, and reads the outcome the system call reports. The connect scan reports `open` when the connection is accepted, `closed` when it is refused (reason `conn-refused`) and `filtered` when nothing comes back. The vocabulary is the same; the cost and the footprint are not. ## Privilege and the default Raw packets need privilege: root on Unix, and on Windows the reference guide recommends an administrator account, noting that Nmap sometimes works for an unprivileged user there when Npcap has already been loaded. Of the scan techniques in this area, the connect scan is the only one an unprivileged user can run. By default Nmap performs a SYN scan and **substitutes a connect scan** when the user lacks the privilege. The two cases differ in an easily missed way: 1. A plain `nmap` run by an unprivileged user quietly falls back to `-sT`. 2. An explicit raw scan type such as `-sS`, `-sA`, `-sU` or `-sF` run unprivileged stops with an error that the scan type requires root. On Linux a user holding raw-socket kernel capabilities, rather than root, can tell Nmap to assume it is privileged with `--privileged` (or the `NMAP_PRIVILEGED` environment variable), placed before the options that need it. `--unprivileged` is the opposite, useful for testing. ## What each leaves behind | | SYN scan | Connect scan | |---|---|---| | Handshake | Never completed | Completed on every open port, then closed | | Packets per open port | Fewer | More | | Application log | Usually nothing, no connection was made | Many services log a note, sometimes a cryptic error, for a connection that closes without data | | Firewall and flow logs | SYNs from one source across many ports | Full short-lived connections from one source across many ports | | Speed | Faster, Nmap controls the packets | Slower, less control through the system call | The reference guide says an administrator who sees a bunch of connection attempts from one system in her logs should know she has been connect scanned, and that a few fragile services misbehave when a connection opens and closes without data. For the defender the lesson runs both ways: those application log lines are good evidence of a connect scan, and **their absence proves nothing**, because a SYN scan never created a connection for the application to see. A decent IDS catches either type. ## When the connect scan is still the right tool - the scanning host cannot be given raw-packet privilege, for example a locked-down jump host; - a quick check of a few ports from a workstation where the user has no raw-packet rights, with the signed scope covering the extra log lines. The cost to weigh is the one the reference guide names: more packets, more time and a higher chance that a fragile service on a production host notices. ## Choosing in an audit Justifying `-sS` over `-sT` is mostly a statement about footprint and speed, not accuracy: both give the three states reliably. An assessor picks `-sS` where privilege exists, falls back to `-sT` where it does not, says which was used in the report, and warns the system owner in advance that a connect scan will write to service logs.

  • On Linux an assessor has raw-socket capabilities but is not root, and Nmap refuses -sS; what do you do?
    Nmap quits on a raw scan type when its effective user ID is not zero. `--privileged`, or the `NMAP_PRIVILEGED` environment variable, tells Nmap to assume it has raw-socket rights, which suits Linux kernel capabilities. Put it before the options that need privilege.
  • A service log shows many connections from one address that opened and closed without sending data; which scan type fits, and does a log without them clear the host?
    A connect scan fits: it completes the handshake on each open port and closes without sending data, and many services note that. A clean log clears nothing, because a SYN scan completes no connection. Check the firewall and flow logs for one source touching many ports, which both scan types leave.
  • Why can a connect scan be a problem on a fragile production service even though it reads the same three states?
    It completes a real connection to each open port, then closes it without data. Most services only log that, but the reference guide notes a few misbehave or crash, and a scan that opens many connections adds load. Agree this with the system owner in the signed scope, and prefer a window when the load is acceptable.

  • -sT is Nmap's default and -sS needs a special flag
  • A SYN scan is invisible because it never completes a connection
  • -sT is more accurate because it completes the handshake
  • -sS works for any user without root or capabilities
  • A clean application log proves the host was not scanned