nmap (Network Mapper) is a free, open-source utility used for network discovery and security auditing. It uses raw IP packets in novel ways to determine what hosts are available on the network, what services (application name and version) those hosts are offering, what operating systems they are running, what type of packet filters/firewalls are in use, and dozens of other characteristics. For penetration testers and CTF players, nmap is the absolute first step in attacking any target infrastructure.
Before we dive into the flags, let's look at the history of the utility. nmap was written by Gordon Lyon (also known by his pseudonym, Fyodor) and was first published in September 1997 in Phrack Magazine (Issue 51). Originally written in C and later rewritten in C++, it was designed to replace a scattered collection of buggy and limited port scanners. Over the past two decades, it has evolved into the undisputed industry standard, featured heavily in cybersecurity media (including The Matrix Reloaded and Mr. Robot) and relied upon by both APT groups and defensive blue teams worldwide.
Essential Flags and Arguments
Nmap is incredibly powerful, but running it without flags is loud, slow, and often inaccurate. Understanding how to shape your packets allows you to evade firewalls and extract precise data.
sS(TCP SYN Scan): The default and most popular scan. It is often referred to as a "stealth" scan because it never completes the full TCP 3-way handshake. It sends a SYN packet, waits for a SYN/ACK, and immediately tears the connection down with an RST packet before the target logs the connection. (Requires root/sudo privileges).sV(Service Version Detection): Instead of just assuming port 80 is HTTP, this probes the open ports to determine the exact service and version number running. Crucial for finding known CVEs.O(OS Detection): Uses TCP/IP stack fingerprinting to guess the underlying operating system of the target.p-(Scan all ports): By default, Nmap only scans the top 1,000 most common ports. This flag forces it to scan all 65,535 ports.T4(Timing Template): Speeds up the scan. Templates range from T0 (paranoid/slow) to T5 (insane/fast). T4 is the standard for CTFs and local lab environments.Pn(Skip Host Discovery): Treats all hosts as online. Essential when a target machine is blocking ICMP (ping) requests, which would normally cause Nmap to abort the scan.A(Aggressive Scan): A shortcut flag that enables OS detection, version detection, script scanning, and traceroute all at once.-script(Nmap Scripting Engine): Allows you to run custom Lua scripts against a target to automate vulnerability detection and exploitation (e.g.,-script vuln).
Practical Execution Commands
We will run these examples against a standard target IP (10.10.89.72). Since raw packet manipulation requires elevated privileges, we will prefix our scans with sudo.
Basic SYN Stealth Scan
To perform a quick sweep of the top 1,000 ports without completing the TCP handshake, use the -sS flag.
Command:
Result:
Version and OS Detection
Once you know which ports are open, you need to know exactly what is running on them and what operating system the host is using.
Command:
Result:
Full Port Sweep with Aggressive Timing
When hunting for hidden services running on high, non-standard ports (like a development web server on port 31337), you must scan all 65,535 ports. We use -T4 to ensure it does not take all day.
Command:
Result:
Nmap Scripting Engine (NSE) Vulnerability Scan
Nmap isn't just for discovery; it can actively exploit and check for vulnerabilities. By calling the vuln category, Nmap will run hundreds of vulnerability checks against the discovered services.
Command:
Result:
Conclusion
nmap is the foundation of network reconnaissance. Understanding how to manipulate its scan types, control its timing, and leverage the Nmap Scripting Engine bridges the gap between simply seeing a server and actually understanding its attack surface. While automated vulnerability scanners like Nessus or OpenVAS have their place, the surgical precision of a properly crafted Nmap command remains unmatched.
If you found this technical breakdown valuable, please follow and support the blog. Stay tuned for our next post.