Nmap Connect Scans on Loopback
Nmap answers the question "which services does this host offer?" by sending probes and reading the answers. Defenders use it to verify their own exposure (does the firewall really block 3389? did the new server open a database port?), auditors to check inventories, and attackers for reconnaissance. Scanning someone else's systems without permission is illegal in many countries and against the terms of every network provider, so every session in this lesson scans exactly one target: 127.0.0.1 inside your sandbox, against services the session itself starts. The law and the scope rules are in Authorization, Scope and Rules of Engagement.
Scope of every example below: 127.0.0.1 in the sandbox. No other host exists there.
How a connect scan works
A TCP connect scan (-sT) asks the operating system to open a normal TCP connection to each port, exactly what any client does:
| Answer to the SYN | Nmap reports | Meaning |
|---|---|---|
| SYN-ACK (then Nmap completes and closes) | open |
something listens |
| RST | closed |
the host is reachable, nothing listens |
| nothing, or ICMP unreachable | filtered |
a firewall drops or rejects the probe |
The SYN scan (-sS, "half-open") sends raw SYNs and never completes the handshake; it is faster and slightly quieter but needs raw sockets, so it requires root. UDP scans (-sU) also need root and are slow, because "no answer" can mean open or filtered.
A first scan
The session starts three services on loopback (a web server, an Ncat listener and a TLS server with the lab certificate) and scans five ports. --reason shows why Nmap decided each state.
python3 -m http.server 8000 --bind 127.0.0.1 >http.log 2>&1 &
ncat -lk 127.0.0.1 9000 >/dev/null 2>&1 &
openssl s_server -accept 127.0.0.1:8443 -cert $SAMPLES/pki/lab.test.crt -key $SAMPLES/pki/lab.test.key -quiet >/dev/null 2>&1 &
for i in $(seq 50); do [ "$(ss -Htln | wc -l)" -ge 3 ] && break; sleep 0.1; done
nmap -sT --reason -p 22,8000,8443,9000,9001 127.0.0.1
echo "--- a SYN scan without root:"
nmap -sS -p 8000 127.0.0.1 2>&1
kill %1 %2 %3Starting Nmap 7.94SVN ( https://nmap.org ) at 2026-11-22 10:24 UTC
Nmap scan report for localhost (127.0.0.1)
Host is up, received conn-refused (0.000070s latency).
PORT STATE SERVICE REASON
22/tcp closed ssh conn-refused
8000/tcp open http-alt syn-ack
8443/tcp open https-alt syn-ack
9000/tcp open cslistener syn-ack
9001/tcp closed tor-orport conn-refused
Nmap done: 1 IP address (1 host up) scanned in 0.02 seconds
--- a SYN scan without root:
You requested a scan type which requires root privileges.
QUITTING!
syn-ack means open, conn-refused (the kernel's report of a RST) means closed. The SERVICE column is only Nmap's guess from its port table, which is why 9000 shows up as cslistener.
All ports, and what really runs there
Restricting a scan to well-known ports misses services on unusual ones. -p- scans all 65,535 TCP ports (fast here because loopback answers instantly; across a network it takes minutes). Version detection (-sV) then connects to the open ports and sends protocol probes to identify the software.
python3 -m http.server 8000 --bind 127.0.0.1 >http.log 2>&1 &
ncat -lk 127.0.0.1 9000 >/dev/null 2>&1 &
openssl s_server -accept 127.0.0.1:8443 -cert $SAMPLES/pki/lab.test.crt -key $SAMPLES/pki/lab.test.key -quiet >/dev/null 2>&1 &
for i in $(seq 50); do [ "$(ss -Htln | wc -l)" -ge 3 ] && break; sleep 0.1; done
nmap -sT -p- 127.0.0.1 | grep -E 'open|Not shown'
echo "--- version detection on two ports:"
nmap -sT -sV -p 8000,8443 127.0.0.1 | grep -E '^[0-9]+/tcp'
kill %1 %2 %3Not shown: 65532 closed tcp ports (conn-refused)
8000/tcp open http-alt
8443/tcp open https-alt
9000/tcp open cslistener
--- version detection on two ports:
8000/tcp open http SimpleHTTPServer 0.6 (Python 3.12.3)
8443/tcp open ssl/https-alt?
Version detection found the exact server software (SimpleHTTPServer on Python) and that 8443 speaks TLS. Banners and version strings are what vulnerability scanners match against CVE databases, which is a reason to keep software updated rather than to hide banners.
What the scan looks like to the defender
Every probe is a real connection, so the target can see it. The session runs a version scan against the web server and then reads the server's own access log: the probes Nmap sent are all there, including requests for paths that only a scanner would ask for. (The log's timestamps and Nmap's random check path are masked so the output is stable.)
python3 -m http.server 8000 --bind 127.0.0.1 >http.log 2>&1 &
for i in $(seq 50); do ss -Htln 'sport = :8000' | grep -q . && break; sleep 0.1; done
nmap -sT -sV -p 8000 127.0.0.1 >/dev/null
kill %1
echo "requests the scan left in the web server's log:"
grep -oE '"(GET|POST|OPTIONS) [^ ]+ HTTP/1\.[01]"' http.log | sed -E 's/[0-9]{6,}/N/' | sort -urequests the scan left in the web server's log:
"GET / HTTP/1.0"
"GET / HTTP/1.1"
"GET /HNAP1 HTTP/1.1"
"GET /evox/about HTTP/1.1"
"GET /nmaplowercheckN HTTP/1.1"
"POST /sdk HTTP/1.1"
How scans are detected
- Many ports, one source: firewall and IDS rules count distinct destination ports per source in a time window (a vertical scan); many hosts, one port is a horizontal scan.
- Incomplete connections: SYN scans leave half-open connections and RSTs; connect scans leave many very short connections without data.
- Probe signatures: Nmap's version and script probes have recognisable requests (as in the log above) and default User-Agent strings for HTTP scripts.
- Your own scanning must be announced: tell the SOC the source address and time window, or your authorised scan will (correctly) trigger an incident.
How exposure is reduced
- Scan your own address space regularly from outside and inside, and compare with the approved list of services (Ports, Services and the Attack Surface).
- Default-deny firewalls, so unexpected listeners are
filtered, notopen. - Rate limiting and alerting on scan patterns at the edge; don't bother with "stealth" tricks such as unusual ports, which
-p-finds.
Pitfalls
- Treating
filteredas "safe". It means the probe got no answer from this vantage point; another network position may reach the port. - Trusting the SERVICE column without
-sV. - Scanning production systems with aggressive options (
-T5, many scripts) without agreement: fragile services and old devices have crashed under scans. - Forgetting IPv6 (
nmap -6) and UDP: many exposures hide there.
Practice
1. Port 9001 is closed, not filtered. What does that tell you about the path to the host?
The host answered with a RST, so packets reach it and no firewall dropped the probe. A port behind a dropping firewall would show filtered (no answer).
2. Why can't the connect scan be quieter than a SYN scan?
It completes the handshake, so the application accepts a connection and often logs it (as the web server did), while a SYN scan stops after the SYN-ACK and the application never sees the connection, only the kernel does.
3. Write the Nmap command to check, in an authorised scan of your own lab server 10.10.0.10, whether SSH and RDP are reachable.
nmap -sT -p 22,3389 10.10.0.10 (with -Pn if ICMP is blocked, so Nmap doesn't skip a host that doesn't answer pings). Run it only within the agreed scope and window.
Test yourself
A connect scan receives a RST for a port. What state does Nmap report?
- open
- closed
- filtered
- open|filtered
Why does nmap -sS fail in the sandbox?
- SYN scans need raw sockets, which require root
- The sandbox has no TCP
- -sS only works on IPv6
- Nmap is not installed
What does -sV add to a scan?
- UDP ports
- Service and version identification by talking to open ports
- Operating-system detection
- Stealth
How did the version scan show up on the target?
- It didn't
- As HTTP requests in the web server's own log, including scanner-typical paths
- As a kernel panic
- As DNS queries