#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.
- No packets sent to target hosts
- WHOIS, DNS, Shodan, Wayback Machine, Google Dorks
- Minimal detection risk; data may lag
- 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): SendsSYN; ifSYN-ACKreturns, the port is open and Nmap sendsRSTinstead 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 withFIN. 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 isclosed; receiving no response marks itopen|filtered. Slower due to ICMP rate limits.
#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.
$ 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.22Here, 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
.sqlor.bakbackups 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) sendRSTafterSYN-ACKand need root; Connect scans (-sT) run without root but complete handshakes and appear in logs. - UDP scans (
-sU) inferclosedports from ICMP Port Unreachable and mark silent portsopen|filtered. - Service enumeration (
-sV,-A) exposes running versions; defenders reduce risk by closing unused ports, disabling directory indexes, and monitoring scan alerts.