Nmap for Beginners: From Scan to CTF Flag part 2

Depov

Moderator
Staff member
MODERATOR
ULTIMATE
SUPREME
PREMIUM
MEMBER
Joined
Feb 18, 2025
Messages
790
Reaction score
1,484
Nmap Information Collection: Service and OS Versions
Determining service versions using version detection

Flag -sVforces Nmap to connect to open ports and send a series of probes from the database nmap-service-probesResponses are compared against signatures to identify specific software and versions. The intensity is controlled by --version-intensity: meaning 0uses a minimum of trials (fast, but can make mistakes), standard 9tries all available samples for maximum accuracy.

If Nmap identifies a service as tcpwrapped— the connection completed the handshake, but the service didn't return the banner. It's worth trying this manually: nc -nv <target> <port>and see what comes back.

A specific version of a service is the starting point for searching for exploits. The habit of checking <service> <version> exploitThe search engine consistently reduces the time to first shell after each scan. On one box, I found vsftpd 2.3.4—Google showed the backdoor in 10 seconds, and the shell was there within a minute.
OS fingerprinting: why identify the OS on a CTF box

Definition of OS ( -O) uses analysis of the target's TCP/IP stack: TTL values, TCP window sizes, TCP option ordering, and ICMP response processing. All of this forms a "fingerprint" that Nmap compares with the database. nmap-os-dbFor an accurate result, both open and closed ports are needed—the more varied the responses, the more accurate the determination.

In CTF, knowledge of the OS determines the choice of payload: Linux or Windows, which shell to generate, where to look for the flag ( /root/root.txt or C:\Users\Administrator\Desktop\root.txt). If Nmap is in doubt, add --osscan-guessfor the most likely option.
NSE Nmap scripts for enumeration in CTF

Nmap Scripting Engine is a built-in Lua engine that turns a port scanner into a fully-fledged reconnaissance tool. The scripts are located in /usr/share/nmap/scripts/— There are hundreds of them on Kali. Search by keyword: ls /usr/share/nmap/scripts/ | grep smb.
Default scripts: what does -sC do?

Flag -sC(equivalent --script default) runs scripts from the category default— safe, non-destructive, but providing useful information. For HTTP — headers, page title, robots.txt. For SMB — share listing. For FTP — anonymous access check.

NSE output for FTP server on CTF box:

21/tcp open ftp vsftpd 3.0.3
| ftp-anon: Anonymous FTP login allowed (FTP code 230)
|_drwxr-xr-x 2 ftp ftp 4096 Jan 15 14:23 pub
| ftp-syst:
| STAT:
|_ FTP server status: Connected to ::ffff:10.10.14.5

This output immediately says: anonymous access is allowed, there is a directory pubIn CTFs, there's almost always a hint or a file with credentials. Without -sCYou would only see "port 21 is open, vsftpd 3.0.3" and pass by.
Scripts for specific enumeration tasks in CTF

Besides the default ones, here are the NSE Nmap scripts that I run most often:

http-enum— iterates through typical directories and files on a web server, works like a fast Gobuster
smb-enum-shares And smb-enum-users — listing SMB resources and accounts
dns-brute— enumerating subdomains using a dictionary
vuln— a category of scripts for checking known vulnerabilities (EternalBlue, Heartbleed, ShellShock)

Running a specific script: sudo nmap --script http-enum -p 80 <target>. Launch category: sudo nmap --script vuln -p <порты> <target>. Category vulnIt's worth running it on each CTF box after the initial scan—if the script finds anything, it saves half an hour of manual search.
Practical Workflow: Network Intelligence in CTF
A step-by-step approach from scanning to operation

The specific Nmap command sequence for beginners that I use on every box is:

Step 1. Quick scan of the main ports. sudo nmap -sV -sC -T4 <target>— will display a list of the main services in 30-60 seconds. While the command is running, open a browser and check HTTP on standard ports.

Step 2. Full scan of all TCP ports. sudo nmap -sS -p- -T4 <target> -oA full— a background task. It finds services on non-standard ports. This is where 30-40% of CTF vulnerabilities are hidden.

Step 3. UDP scan of key ports. sudo nmap -sU --top-ports 20 -T4 <target> — SNMP, TFTP, DNS. If SNMP is open — snmpwalk -c public -v1 <target>can issue credentials.

Step 4. Spot scan for found services. When step 2 finds a new port: sudo nmap -sV -sC -p <port> <target>for a detailed definition.

Step 5. Vuln category scripts. sudo nmap --script vuln -p <порты> <target>— automated checking of known vulnerabilities.

Run steps 1 and 2 in parallel. While the full scan is running in the background, you'll be exploring the services found in the quick scan. Don't sit and stare at the progress bar—that's a waste of time.
Checklist: What to do after discovering the service
Service A typical port The next step
HTTP/HTTPS 80, 443, 8080, 8443 Browser, Gobuster for directories, robots.txt, source code
SSH 22 Record the version, look for key leaks in other services
FTP 21 Check Anonymous Access (NSE) ftp-anonwill show automatically)
SMB 139, 445 smbclient -L //<target>, enum4linux for a complete enumeration
MySQL/PostgreSQL 3306, 5432 If filtered, remember for post-exploitation via localhost
SNMP 161 (UDP) snmpwalk -c public -v1 <target>- frequently displays system information
RDP 3389 Possible credential attack, check xfreerdp
Common Nmap Scanning Mistakes

Scanning only the top 1000 ports. By default, Nmap scans the 1000 most popular ports in the database. nmap-servicesCTF boxes deliberately place key services on non-standard ports. -p-In the background, you risk wasting an hour fruitlessly trying out already found services while the response is hanging on port 50000.

Forgot sudo. Without root, Nmap uses TCP Connect instead of SYN scan. The results are similar, but slower. In timed competitions, this difference is noticeable.

Ignoring UDP. The phrase "I scanned all ports" usually means "all TCP ports." UDP is a separate world with its own services. SNMP with its default community string is a gift that newbies consistently overlook.

They don't save results. After an hour of using the box, you'll forget the exact SSH version. Flag -oAIt's worth adding to every command. Once you set up a habit, you'll never have to rescan again just to get one line.

Confusion between filtered and closed. Closed means the port is available, but the service isn't listening. Filtered means the firewall is blocking packets. In CTF filteredThis often means the service is only accessible from within. After receiving the shell, check: ss -tlnpon the target it will show that it is listening on localhost.

Scrolling through NSE output. Default scripts ( -sC) yield a ton of details: HTTP headers, domain names from SSL certificates, SMB shares, anonymous FTP. Skipping this output means missing half the clues Nmap has already found for you.

Timing -T5 and lost ports. The most aggressive timing may miss ports due to timeouts. -T4— a reasonable maximum. -T3— if the channel is unstable or the target responds slowly. Even in controlled laboratory conditions, HTB -T5results in missed open ports on busy machines.

Nmap is the tool that every CTF box and every real-world pentest starts with. But a tool without a methodology is just a program that outputs text to the terminal. The difference between "run a scan and wait" and "run a quick scan, simultaneously inspect HTTP, then upload the full scan results" is the difference between stagnation on easy boxes and a stable medium solution.

In my experience, 60-70% of time in a CTF box is spent on reconnaissance, not exploitation. Beginners invert the ratio: 20 minutes on a scan, an hour on exploits that don't work. Proper Nmap data collection narrows the funnel to one or two specific vectors—the rest is a matter of technique.

I periodically hear that Nmap is outdated and that Masscan or Rustscan do the same thing faster. Speed-wise, yes. But no alternative scanner offers the level of version detection and NSE script library that Nmap has. In real-world pentests, Masscan is used to quickly traverse large subnets, then feed the discovered ports to Nmap for in-depth analysis. In CTFs, where the target is a single host, Nmap alone covers all reconnaissance.
 
Top Bottom