TExcelTAD
Home › Ethical Hacking & Penetration Testing Methodology › Service and Version Scans on Loopback

Service and Version Scans on Loopback

A port scan says that something listens on port 21. A service and version scan asks what: it connects to each open port, reads the greeting, sends protocol probes, and matches the answers against a database of thousands of signatures. The result (vsftpd 2.3.4, OpenSSH 9.6p1 Ubuntu 3ubuntu13.5) is the bridge from reconnaissance to vulnerability assessment, because advisories are written against products and versions. It is also only as reliable as the banner it read. This lesson runs a version scan against four services that your sandbox starts on 127.0.0.1. One of them is lying about what it is.

Scope of the session

Everything runs inside your sandbox container, which has no network: the services are started by the session on 127.0.0.1, Nmap scans only 127.0.0.1 with a connect scan (-sT, the only kind an unprivileged user can run) and an explicit port list, and every service is stopped at the end.

How version detection works

For each open TCP port Nmap (-sV):

  1. connects and waits a few seconds for a banner (many protocols greet first: FTP 220 …, SSH SSH-2.0-…, SMTP 220 …);
  2. if nothing useful arrives, sends probes from its nmap-service-probes file (an HTTP GET, a TLS ClientHello, an RPC request…), ordered by how likely they are for that port;
  3. matches each answer against regular expressions that extract product, version and extra information, and reports the best match;
  4. if the port speaks TLS, wraps the connection and repeats the probes inside it (reported as ssl/http).

--reason shows why each port state was decided (syn-ack: the connection was accepted; conn-refused: an RST came back).

The scan

Four services start: Python's web server, an OpenSSL test server with the lab certificate, and two one-line fakes made with Ncat that print an FTP and an SSH greeting and nothing more.

bash · try it yourself
ncat -lk 127.0.0.1 2121 -c 'printf "220 (vsFTPd 2.3.4)\r\n"; sleep 2' >/dev/null 2>&1 &
ncat -lk 127.0.0.1 2222 -c 'printf "SSH-2.0-OpenSSH_9.6p1 Ubuntu-3ubuntu13.5\r\n"; sleep 2' >/dev/null 2>&1 &
python3 -m http.server 8080 --bind 127.0.0.1 >http.log 2>&1 &
openssl s_server -accept 127.0.0.1:8443 -cert $SAMPLES/pki/lab.test.crt -key $SAMPLES/pki/lab.test.key -www -quiet >/dev/null 2>&1 &
for i in $(seq 50); do [ "$(ss -Htln | wc -l)" -ge 4 ] && break; sleep 0.1; done
nmap -sT -sV --reason -p 21,2121,2222,8080,8443 -oX scan.xml 127.0.0.1
kill %1 %2 %3 %4
echo "saved: $(grep -c '<port ' scan.xml) ports in scan.xml"
Starting Nmap 7.94SVN ( https://nmap.org ) at 2026-11-22 14:13 UTC
Nmap scan report for localhost (127.0.0.1)
Host is up, received conn-refused (0.000084s latency).

PORT     STATE  SERVICE  REASON       VERSION
21/tcp   closed ftp      conn-refused
2121/tcp open   ftp      syn-ack      vsftpd 2.3.4
2222/tcp open   ssh      syn-ack      OpenSSH 9.6p1 Ubuntu 3ubuntu13.5 (Ubuntu Linux; protocol 2.0)
8080/tcp open   http     syn-ack      SimpleHTTPServer 0.6 (Python 3.12.3)
8443/tcp open   ssl/http syn-ack      OpenSSL s_server -www httpd (command line: s_server -accept 127.0.0.1:8443 -cert /opt/sec-samples/pki/lab.test.crt -key /opt/sec-samples/pki/lab.test.key -...)
Service Info: OSs: Unix, Linux; CPE: cpe:/o:linux:linux_kernel

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 40.54 seconds
saved: 5 ports in scan.xml

Read each line as evidence with a strength:

  • 2121/tcp vsftpd 2.3.4: the version string that has a famous history (a backdoored source archive was distributed in 2011; it is in the CVE lesson and the Metasploit lesson). Here the "FTP server" is Ncat printing one line. Nmap's signature matched the greeting, and the greeting is all it saw. A version scan identifies what a service claims.
  • 2222/tcp OpenSSH 9.6p1 Ubuntu 3ubuntu13.5: also a fake, but the format teaches something real: the Ubuntu package revision (3ubuntu13.5) is in the banner, which is what triage uses to account for backported fixes.
  • 8080/tcp SimpleHTTPServer 0.6 (Python 3.12.3): genuine, from the Server header and the page format.
  • 8443/tcp ssl/http OpenSSL s_server -www httpd (command line: …): Nmap wrapped the connection in TLS and found a web page that reveals the server's whole command line, including the paths of the certificate and private key. A test tool left listening on a production host is a real-world finding; here it shows why version detection output is worth reading line by line.
  • 21/tcp closed, reason conn-refused: nothing listens; the kernel answered with a reset.

The XML file (-oX) keeps all of this with the exact command line and timestamps. The next lessons use it.

The same scan in the lab

Lab session, authorised internal test of 10.10.0.0/24 from 10.10.0.99, window 2026-12-02 08:00–17:00 UTC, rate limit 100 probes/s. legacy01 (10.10.0.20) is a deliberately vulnerable lab VM (Metasploitable 2).

console
tester@lab:~$ sudo nmap -sS -sV --top-ports 100 --max-rate 100 -oA scans/servers 10.10.0.10,11,20,21,40,62
Nmap scan report for www.lab.test (10.10.0.10)
PORT    STATE SERVICE  VERSION
22/tcp  open  ssh      OpenSSH 8.9p1 Ubuntu 3ubuntu0.10 (Ubuntu Linux; protocol 2.0)
443/tcp open  ssl/http nginx 1.18.0 (Ubuntu)

Nmap scan report for dc01.lab.test (10.10.0.11)
PORT     STATE SERVICE       VERSION
53/tcp   open  domain        Simple DNS Plus
88/tcp   open  kerberos-sec  Microsoft Windows Kerberos
389/tcp  open  ldap          Microsoft Windows Active Directory LDAP (Domain: lab.test)
445/tcp  open  microsoft-ds?

Nmap scan report for legacy01.lab.test (10.10.0.20)
PORT    STATE SERVICE     VERSION
21/tcp  open  ftp         vsftpd 2.3.4
22/tcp  open  ssh         OpenSSH 4.7p1 Debian 8ubuntu1 (protocol 2.0)
80/tcp  open  http        Apache httpd 2.2.8 ((Ubuntu) DAV/2)
139/tcp open  netbios-ssn Samba smbd 3.X - 4.X (workgroup: WORKGROUP)

Nmap scan report for files01.lab.test (10.10.0.21)
PORT     STATE SERVICE       VERSION
445/tcp  open  microsoft-ds?
3389/tcp open  ms-wbt-server Microsoft Terminal Services

Nmap scan report for db01.lab.test (10.10.0.40)
PORT     STATE SERVICE    VERSION
5432/tcp open  postgresql PostgreSQL DB 9.6.0 or later

Nmap scan report for jenkins.lab.test (10.10.0.62)
PORT     STATE SERVICE VERSION
8080/tcp open  http    Jetty 10.0.18
Nmap done: 6 IP addresses (6 hosts up) scanned in 74.20 seconds

(Abridged: closed and filtered ports, service-info lines and fingerprints removed.) Note the vague entries. microsoft-ds? means the port is open but no probe matched confidently. PostgreSQL DB 9.6.0 or later is a range, not a version. These are leads for enumeration, not conclusions.

How version scans are detected

Version probes are much louder than a connect scan: each open port receives several connections and protocol data it doesn't expect. Web servers log Nmap's probe requests (unusual methods and paths, a Nmap Scripting Engine user agent when scripts run), SSH servers log connections that close before authentication (Connection closed by 10.10.0.99 port 51544 [preauth]), and IDS rule sets include signatures for Nmap's probes. A defender who sees these from the declared tester address files them under the test; from anywhere else, they are reconnaissance by someone else.

How exposure is reduced

  • Close or bind to loopback what doesn't need to be reachable (the s_server above should never have listened beyond 127.0.0.1, and on a production host not at all).
  • Keep software current; that is the only fix for a version with known vulnerabilities.
  • Minimise banners where it is cheap (server_tokens off;), as a hygiene item, knowing that version detection also uses behaviour.
  • Alert on version-probe patterns from unexpected sources, and on new listening services (ss -tlnp baselines).

Pitfalls

  • Taking the version as truth. It is what the service says. Fakes, honeypots and proxies all mislead version detection; backports make true versions look vulnerable.
  • Running -sV on fragile targets. The probes send protocol junk; some embedded devices react badly (see scan planning).
  • Losing the raw output. Keep -oX for every scan; normal output is for humans and drops detail.

Practice

  1. Change the fake FTP banner to 220 ProFTPD 1.3.5 Server (Lab). What will -sV report, and what does that tell you about how much the scan checked?
  2. In the lab transcript, list the three entries you would enumerate first and why.
Answers
  1. ProFTPD 1.3.5: the signature extracts product and version from the greeting. The scan checked one line of text; nothing about the software behind it.
  2. legacy01:21 (vsftpd 2.3.4, a version with a known backdoor, to be validated safely), jenkins:8080 (CI server, from the attack-surface model: check whether it requires authentication), and dc01/files01:445 (SMB: signing, shares, null sessions; the vague microsoft-ds? needs enumeration).

Test yourself

Nmap -sV reports 'vsftpd 2.3.4' on a port. What has been established?

  1. The host runs the backdoored vsftpd
  2. The service's greeting matches vsftpd 2.3.4's signature; the software behind it is not verified
  3. The host is compromised
  4. The port is filtered

What does the reason 'conn-refused' mean in a connect scan?

  1. A firewall dropped the probe
  2. The host answered with a TCP reset: nothing listens on that port
  3. The service needs a password
  4. The scan was too fast

Why is 'ssl/http' shown for port 8443?

  1. The port number suggests it
  2. Nmap detected TLS, wrapped the connection and found HTTP inside
  3. The certificate says so
  4. It is a guess

Which output format keeps the full detail of a scan for later processing?

  1. Normal (-oN)
  2. XML (-oX)
  3. Screen output
  4. Grepable (-oG)