root@thehacksparrow:~/writeups$ SYSTEM ONLINE
root@sparrow:~/writeups$ cat nmap-basic-port-scans.md
// Offensive

Nmap Basic Port Scans

18 Nov 2026 · 6 min read
Overview — The second room of TryHackMe's Nmap series. After host discovery, the next question is which ports on a live host are listening. The room explains the six port states Nmap reports, the TCP header flags that scans manipulate, and exactly how the three core scan types work on the wire: TCP connect (-sT), TCP SYN (-sS) and UDP (-sU). It ends with options to choose which ports to scan and how fast.
PlatformTryHackMe
CategoryOffensive
DifficultyEasy
RoomNmap Basic Port Scans

Task 1 — Introduction

A scan has several stages: enumerate targets, discover live hosts, reverse-DNS lookup, and then port scanning, which is what this room covers. It builds on the previous room (host discovery) and leads into the advanced port scans and post-scan rooms. The three techniques covered are connect, SYN and UDP scans, plus port selection, timing and parallelism controls.

Task 2 — TCP and UDP Ports

An IP address identifies a host; a TCP or UDP port identifies a service on it. By convention a service uses a well-known port (HTTP on TCP 80, HTTPS on 443, SSH on 22, DNS on UDP 53), but administrators can move it, and only one service can bind to a given port on a given address.

In theory a port is open or closed. In practice firewalls blur that, so Nmap distinguishes six states:

StateMeaning
openA service is listening and answered.
closedReachable, but nothing listens there.
filteredNmap cannot tell; a firewall is dropping the probe or the reply.
unfilteredReachable, but Nmap cannot say open or closed. Appears with the ACK scan (-sA).
open|filteredNmap cannot decide between open and filtered (typical for UDP, where silence is ambiguous).
closed|filteredNmap cannot decide between closed and filtered.

Q: Which service uses UDP port 53 by default?
A: DNS

Q: Which service uses TCP port 22 by default?
A: SSH

Q: How many port states does Nmap consider?
A: 6

Q: Which port state is the most interesting to discover as a pentester?
A: Open

Task 3 — TCP Flags

Nmap's scan types differ mainly in which TCP flags they send and how they react to the reply, so the TCP header is worth knowing. Each header carries source and destination ports (16 bits each), sequence and acknowledgement numbers, and a set of one-bit flags. The ones that matter here:

  • URG — the urgent pointer field is significant; the data should be processed ahead of queued segments.
  • ACK — the acknowledgement number is valid; confirms receipt of a segment.
  • PSH — asks the stack to hand the data to the application promptly.
  • RST — resets the connection. It is also what a host sends when a packet arrives for a port with no listener.
  • SYN — starts the three-way handshake and synchronizes sequence numbers (which should be random).
  • FIN — the sender has no more data.

Q: What 3 letters represent the Reset flag?
A: RST

Q: Which flag needs to be set when you initiate a TCP connection (first packet of TCP 3-way handshake)?
A: SYN

Task 4 — TCP Connect Scan

The connect scan (-sT) simply asks the operating system to open a normal TCP connection to each port. The handshake runs SYN, SYN/ACK, ACK. If the port is open the connection completes and Nmap immediately tears it down; if it is closed the target answers the SYN with RST/ACK. Because it uses the OS's connect() call, it needs no special privileges, and it is therefore the only TCP scan an unprivileged user can run. The price is noise: every open port yields a full connection that applications may log.

nmap -sT MACHINE_IP

Useful companions:

  • -F — fast mode, the 100 most common ports instead of the default top 1000.
  • -r — scan ports in numerical order instead of randomized order, handy to see whether services come up in a consistent order, such as during a boot.

In the exercise the VM gets a new service since the reference scan, and the output below (trimmed) shows it:

Not shown: 992 closed tcp ports (conn-refused)
PORT    STATE SERVICE
22/tcp  open  ssh
25/tcp  open  smtp
80/tcp  open  http
110/tcp open  pop3
111/tcp open  rpcbind
143/tcp open  imap
993/tcp open  imaps
995/tcp open  pop3s

Note the closed-port reason conn-refused: with a connect scan Nmap learns "closed" from the OS reporting a refused connection.

Q: Which port number was closed in the scan above but is now open on this target VM?
A: 110

Q: What is Nmap's guess about the newly installed service?
A: pop3

Task 5 — TCP SYN Scan

The SYN scan (-sS), also called half-open or "stealth" scanning, crafts its own packets. Nmap sends a SYN; if a SYN/ACK comes back the port is open, and instead of sending the final ACK Nmap replies with RST, so the handshake never completes. A closed port still answers RST/ACK. Sending raw packets requires privileges, so this is the default scan when you run Nmap as root or with sudo, and connect scan is the fallback otherwise.

It is faster than a connect scan and less likely to appear in application logs, since no connection is ever established. "Stealth" is relative, though: firewalls and IDS rules detect SYN scans easily, so do not treat it as invisible.

sudo nmap -sS MACHINE_IP

Compared on the wire, the only difference for an open port is the last packet: -sT sends ACK (then closes), -sS sends RST. Against a target with new software, the scan reveals:

Not shown: 991 closed tcp ports (reset)
PORT     STATE SERVICE
22/tcp   open  ssh
25/tcp   open  smtp
80/tcp   open  http
110/tcp  open  pop3
111/tcp  open  rpcbind
143/tcp  open  imap
993/tcp  open  imaps
995/tcp  open  pop3s
6667/tcp open  irc

This time closed ports are reported with reason reset instead of conn-refused, a quick tell for which scan produced the output.

Q: What is the new open port?
A: 6667

Q: What is Nmap's guess of the service name?
A: irc

Task 6 — UDP Scan

UDP has no handshake, so a scan cannot rely on a connection succeeding. Nmap sends a UDP datagram (-sU) and interprets what happens:

  • ICMP port unreachable (type 3, code 3) comes back: the port is closed.
  • A UDP reply: the port is open.
  • Silence: the port may be open (the service ignored an empty probe) or filtered, so Nmap reports open|filtered.

UDP scans are slow, because closed ports rate-limit their ICMP errors (Linux commonly allows about one per second), which makes Nmap slow down and retransmit. A full default scan of 1000 UDP ports can take many minutes, which is why the room uses -F.

sudo nmap -sU -F -v MACHINE_IP
Not shown: 97 closed udp ports (port-unreach)
PORT    STATE         SERVICE
53/udp  open          domain
68/udp  open|filtered dhcpc
111/udp open          rpcbind

Port 68 is DHCP client traffic, so silence there is normal and Nmap cannot tell more. The newly installed service is the DNS server on 53.

Q: What is the UDP port that is now open?
A: 53

Q: What is the service name according to Nmap?
A: domain

Task 7 — Fine-Tuning Scope and Performance

Choosing ports.

OptionEffect
-p22,80,443Exactly those ports
-p1-1023An inclusive range
-p-All 65535 ports
-FThe 100 most common ports
--top-ports 10The N most common ports

The default top-1000 can miss services on unusual ports, so on a CTF box -p- is a safe habit.

Timing templates. -T0 to -T5 map to paranoid, sneaky, polite, normal (default), aggressive and insane. -T0 sends one probe at a time and waits about five minutes between them, which is why scans become practically endless; it and -T1 are meant for evading IDS. -T4 is common in CTFs and labs where speed matters; -T5 may drop packets and give inaccurate results.

Rate and parallelism. --min-rate and --max-rate bound packets per second (e.g. --max-rate 10), while --min-parallelism and --max-parallelism bound how many probes are in flight at once. Nmap normally adapts these automatically; set them when you know the network better than Nmap does.

Q: What is the option to scan all the TCP ports between 5000 and 5500?
A: -p5000-5500

Q: How can you ensure that Nmap will run at least 64 probes in parallel?
A: --min-parallelism=64

Q: What option would you add to make Nmap very slow and paranoid?
A: -T0

Task 8 — Summary

ScanCommandPrivileges
TCP connectnmap -sT MACHINE_IPNone
TCP SYNsudo nmap -sS MACHINE_IPRoot
UDPsudo nmap -sU MACHINE_IPRoot

Key takeaways

  • Nmap reports six port states; "filtered" and "open|filtered" mean a firewall or silence is hiding the truth, not that the port is closed.
  • Connect scan completes the handshake and needs no privileges; SYN scan stops after SYN/ACK with an RST, is faster and quieter, and is the root default.
  • UDP "open" often just means "no answer". Closed UDP ports betray themselves through ICMP port unreachable, and rate limiting makes UDP scans slow.
  • The closed-port reason in the output (conn-refused versus reset versus port-unreach) tells you which technique was used.
  • Use -p- for completeness, -F or --top-ports for speed, and timing/rate options to balance speed, accuracy and noise. Defenders can detect all of these: a burst of SYNs to many ports followed by RSTs is the classic scan signature.