Lesson 9 of 11
Network Reconnaissance with Nmap
Nmap (Network Mapper) is the most widely used tool for network discovery, port scanning, and service/OS fingerprinting. Both penetration testers and network defenders use it - defenders to audit their own exposure, attackers to identify targets.
Nmap Scan Types
# Always scan your own authorized systems only - unauthorized scanning is illegal
# 1. Host Discovery - Which hosts are up?
nmap -sn 192.168.1.0/24 # Ping sweep - no port scan
nmap -sn -PE 10.0.0.0/24 # ICMP echo ping sweep
# 2. Port Scanning
nmap -sS target.com # SYN scan (default, fast, stealthy)
nmap -sT target.com # TCP connect scan (slower, leaves logs)
nmap -sU target.com # UDP scan (slow, finds DNS/DHCP/SNMP)
nmap -sS -p 1-1024 target.com # Scan first 1024 ports
nmap -sS -p- target.com # Scan all 65535 ports (slow)
nmap -sS --top-ports 1000 target.com # Top 1000 most common ports
# 3. Service and Version Detection
nmap -sV target.com # Detect service versions
nmap -sV --version-intensity 9 target.com # Aggressive version detection
# 4. OS Detection
nmap -O target.com # OS fingerprinting (requires root)
# 5. Combined scan (common in pentesting)
nmap -sV -sC -O -p- target.com # Version + default scripts + OS + all portsNSE Scripts for Security Scanning
# Nmap Scripting Engine (NSE) - over 600 built-in scripts
# Run default safe scripts
nmap -sC target.com
# Vulnerability scanning scripts
nmap --script vuln target.com # Run all vulnerability scripts
nmap --script http-sql-injection target.com # Test for SQL injection
nmap --script ssl-heartbleed target.com # Check for Heartbleed vulnerability
nmap --script http-shellshock target.com # Check for Shellshock
# Authentication testing
nmap --script ssh-brute target.com # SSH brute force (authorized testing only)
nmap --script ftp-anon target.com # Check if FTP allows anonymous login
# Information gathering
nmap --script banner target.com # Grab service banners
nmap --script http-headers target.com # Retrieve HTTP headers
nmap --script dns-brute target.com # DNS subdomain brute force
nmap --script whois-domain target.com # WHOIS information
# Save results
nmap -oN output.txt target.com # Normal output
nmap -oX output.xml target.com # XML output (for tools)
nmap -oA allformats target.com # All formats simultaneouslyReading & Acting on Nmap Output
- Open port with version info: 'PORT 22/tcp open ssh OpenSSH 7.6p1 Ubuntu' - check if this version has CVEs (search CVE database)
- Unexpected open ports: Any port that should not be open based on your firewall rules indicates a misconfiguration or unauthorized service
- Service running as wrong version: Old Apache (2.2.x), nginx (1.14), or OpenSSH versions often have known vulnerabilities - prioritize patching
- Scripts reveal: http-auth shows authentication required (or not!), ftp-anon reveals anonymous FTP, ssl-cert shows certificate expiry dates
- Compare against baseline: Run nmap monthly and diff the results - new open ports or changed services indicate system changes that need review
Common Mistakes
- Scanning networks without written authorization - even on your own network, validate scope before running aggressive scans
- Only scanning from outside - inside-out scanning reveals what's visible internally and can surface services not exposed externally but dangerous internally
- Ignoring UDP scans - critical services like DNS (53), SNMP (161), NTP (123) run on UDP and are missed by TCP-only scans
- Not saving scan results - baseline comparisons require historical data; always save output in XML format for tool integration
Tip
Tip
Practice Network Reconnaissance with Nmap in small, isolated examples before integrating into larger projects. Breaking concepts into small experiments builds genuine understanding faster than reading alone.
The foundational security model: Confidentiality (privacy), Integrity (trust), and Availability (uptime).
Practice Task
Note
Practice Task - (1) Write a working example of Network Reconnaissance with Nmap from scratch without looking at notes. (2) Modify it to handle an edge case (empty input, null value, or error state). (3) Share your solution in the Priygop community for feedback.
Quick Quiz
Common Mistake
Warning
A common mistake with Network Reconnaissance with Nmap is skipping edge case testing - empty inputs, null values, and unexpected data types. Always validate boundary conditions to write robust, production-ready cybersecurity code.
Key Takeaways
- Nmap (Network Mapper) is the most widely used tool for network discovery, port scanning, and service/OS fingerprinting.
- Open port with version info: 'PORT 22/tcp open ssh OpenSSH 7.6p1 Ubuntu' - check if this version has CVEs (search CVE database)
- Unexpected open ports: Any port that should not be open based on your firewall rules indicates a misconfiguration or unauthorized service
- Service running as wrong version: Old Apache (2.2.x), nginx (1.14), or OpenSSH versions often have known vulnerabilities - prioritize patching
Finished this lesson?