Skip to main content
Network Scanning & Service Enumeration with Nmap
Lesson 8 of 26

Network Scanning & Service Enumeration with Nmap

Combine passive OSINT with active Nmap TCP, UDP, and service-version scans to map lab attack surfaces and detect unauthorized reconnaissance.

Intermediate 28 min Pentesting
Authorised environments only — The techniques described here are used only in training labs and on systems you own or have written permission to test.

Learning objectives

  • Distinguish passive OSINT collection from active network reconnaissance and their detection footprints.
  • Compare TCP SYN (-sS), TCP Connect (-sT), and UDP (-sU) port scanning mechanics and privilege requirements.
  • Interpret Nmap service enumeration output to identify open, closed, and filtered ports.
  • Apply defensive controls to reduce exposed services and detect scanning activity.

Recommended first: IPv4/IPv6 Addressing & CIDR SubnettingTCP, UDP, Ports & ICMP Diagnostics

#Why this matters

Before defending a network or running an authorized penetration test, you need to know which hosts are live, which ports are open, and which software listens behind them. Forgotten staging servers and exposed interfaces expand an organization's attack surface.

Building on IP addressing and TCP/UDP behavior from earlier lessons, this lesson shows how passive OSINT and active scanning map an environment, and how defenders detect that reconnaissance.

#Passive OSINT versus active reconnaissance

Passive reconnaissance (OSINT) gathers data from third-party public sources without touching target hosts: WHOIS records, public DNS records (A, AAAA, MX, TXT), Shodan device indexes, Wayback Machine snapshots, and public profiles.

Google Dorking passively locates accidentally indexed resources using search operators without contacting the target server:

  • intitle:"index of" site:example.test: Finds indexed open directory listings.
  • site:example.test ext:sql OR ext:bak: Finds indexed SQL dumps or backup files.
  • inurl:/admin site:example.test: Identifies indexed administrative login paths.
  • site:example.test filetype:pdf: Locates public PDF files that may leak metadata.

Active reconnaissance probes target hosts directly (port scanning, service enumeration, OS fingerprinting, vulnerability scanning, or password spraying), creating traffic that firewalls and IDS sensors can detect.

Passive OSINT vs Active Reconnaissance
Passive Reconnaissance (OSINT)
  • No packets sent to target hosts
  • WHOIS, DNS, Shodan, Wayback Machine, Google Dorks
  • Minimal detection risk; data may lag
Active Reconnaissance
  • Probes target IPs and ports directly
  • Nmap, Masscan, OpenVAS, web crawlers
  • Real-time accuracy; triggers firewall and IDS alerts

#How TCP and UDP port scans work

Nmap classifies ports as open, closed, or filtered based on target responses:

  • TCP SYN Scan (-sS): Sends SYN; if SYN-ACK returns, the port is open and Nmap sends RST instead of completing the three-way handshake. Many application logs miss half-open probes, though stateful firewalls and IDS still detect them. Requires root or administrator privileges.
  • TCP Connect Scan (-sT): Uses standard OS socket calls (connect()) to complete the full handshake (SYN, SYN-ACK, ACK) before closing with FIN. Works without root privileges, but target logs record full connections.
  • UDP Scan (-sU): Probes connectionless services such as DNS (53), DHCP (67, 68), and SNMP (161). Receiving ICMP Port Unreachable means the port is closed; receiving no response marks it open|filtered. Slower due to ICMP rate limits.
TCP SYN Scan (-sS) on an Open Lab PortTCP SYN Scan (-sS) on an Open Lab PortScannerTarget 10.10.10.5TCP SYN (dport=80)TCP SYN-ACK (port open)TCP RST (abort handshake)No full application connection; firewall and IDS still see SYN

#Service enumeration and scanning tools

Key Nmap flags for authorized labs:

  • nmap -sS 10.10.10.0/24: SYN scan of a lab subnet.
  • nmap -sV -p 1-65535 10.10.10.5: All TCP ports plus version detection.
  • nmap -O 10.10.10.5: Operating system fingerprinting.
  • nmap -A 10.10.10.5: Aggressive bundle (OS detection, -sV, default scripts, and traceroute).
  • nmap --script vuln 10.10.10.5: NSE vulnerability checks (noisy).
  • nmap -sU -p 53,67,161 10.10.10.5: Targeted UDP scan.
Running a SYN and version scan in an authorized lab
$ sudo nmap -sS -sV 10.10.10.5
Starting Nmap 7.94 at 2026-11-20 10:15 +05
Nmap scan report for app.lab.local (10.10.10.5)
Host is up (0.0014s latency).
PORT     STATE    SERVICE    VERSION
22/tcp   open     ssh        OpenSSH 8.9
80/tcp   open     http       Apache 2.4.52
443/tcp  open     https      Apache 2.4.52
3306/tcp filtered mysql
8080/tcp open     http-proxy Nginx 1.22

Here, 3306/tcp is filtered by a firewall, while 8080/tcp exposes http-proxy (Nginx 1.22).

Tool Purpose Typical use License
Nmap Port and service scanning Host, version, and NSE script scanning NPSL
Masscan High-speed port scanning Large-scale sweeps (set --rate) AGPLv3
OpenVAS Vulnerability scanning Open-source vulnerability assessment GPL
Nessus Vulnerability scanning Enterprise vulnerability management Commercial
Nikto Web server scanning Web headers, files, and misconfigs GPL
Shodan Passive device index OSINT for exposed services and IoT Freemium

#Defending against unauthorized scanning

Shrink the exposed attack surface and alert on reconnaissance:

  • Close unused ports and bind internal databases like MySQL (3306/tcp) to loopback or private VLANs.
  • Disable web directory listings and keep .sql or .bak backups outside web roots so Google Dorking finds nothing sensitive.
  • Monitor firewall drop logs and IDS alerts for rapid SYN sweeps.

#Summary

  • Passive OSINT (WHOIS, DNS, Shodan, Wayback Machine, Google Dorking) avoids contacting target hosts, while active reconnaissance probes them directly.
  • SYN scans (-sS) send RST after SYN-ACK and need root; Connect scans (-sT) run without root but complete handshakes and appear in logs.
  • UDP scans (-sU) infer closed ports from ICMP Port Unreachable and mark silent ports open|filtered.
  • Service enumeration (-sV, -A) exposes running versions; defenders reduce risk by closing unused ports, disabling directory indexes, and monitoring scan alerts.

Knowledge check

Sign in to take the test, complete lessons and save your progress. Log in

Practice: test your knowledge