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:

Bash
sudo nmap -sS 10.10.89.72

Result:

s4n4t@hackliva ~/writeups
❯ sudo nmap -sS 10.10.89.72
Starting Nmap 7.94SVN ( <https://nmap.org> ) at 2026-11-14 00:55 IST
Nmap scan report for 10.10.89.72
Host is up (0.042s latency).
Not shown: 998 closed tcp ports (reset)
PORT   STATE SERVICE
22/tcp open  ssh
80/tcp open  http

Nmap done: 1 IP address (1 host up) scanned in 1.42 seconds

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:

Bash
sudo nmap -sV -O 10.10.89.72

Result:

s4n4t@hackliva ~/writeups
❯ sudo nmap -sV -O 10.10.89.72
Starting Nmap 7.94SVN ( <https://nmap.org> ) at 2026-11-14 00:57 IST
Nmap scan report for 10.10.89.72
Host is up (0.041s latency).
Not shown: 998 closed tcp ports (reset)
PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 8.2p1 Ubuntu 4ubuntu0.5 (Ubuntu Linux; protocol 2.0)
80/tcp open  http    Apache httpd 2.4.41 ((Ubuntu))
Aggressive OS guesses: Linux 4.15 - 5.8 (96%), Linux 5.3 - 5.4 (95%), Linux 2.6.32 (95%)
No exact OS matches for host (test conditions non-ideal).
Network Distance: 2 hops
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

OS and Service detection performed. Please report any incorrect results at <https://nmap.org/submit/> .
Nmap done: 1 IP address (1 host up) scanned in 9.12 seconds

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:

Bash
sudo nmap -p- -T4 10.10.89.72

Result:

s4n4t@hackliva ~/writeups
❯ sudo nmap -p- -T4 10.10.89.72
Starting Nmap 7.94SVN ( <https://nmap.org> ) at 2026-11-14 00:59 IST
Nmap scan report for 10.10.89.72
Host is up (0.043s latency).
Not shown: 65532 closed tcp ports (reset)
PORT      STATE SERVICE
22/tcp    open  ssh
80/tcp    open  http
31337/tcp open  Elite

Nmap done: 1 IP address (1 host up) scanned in 24.81 seconds

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:

Bash
sudo nmap --script vuln 10.10.89.72

Result:

s4n4t@hackliva ~/writeups
❯ sudo nmap --script vuln 10.10.89.72
Starting Nmap 7.94SVN ( <https://nmap.org> ) at 2026-11-14 01:02 IST
Nmap scan report for 10.10.89.72
Host is up (0.044s latency).
Not shown: 998 closed tcp ports (reset)
PORT   STATE SERVICE
22/tcp open  ssh
80/tcp open  http
|_http-csrf: Couldn't find any CSRF vulnerabilities.
|_http-dombased-xss: Couldn't find any DOM based XSS.
| http-enum:
|   /login.php: Possible admin folder
|   /robots.txt: Robots file
|_  /uploads/: Potentially interesting folder

Nmap done: 1 IP address (1 host up) scanned in 45.10 seconds

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.