Nmap Scripts: Automating Reconnaissance
NSE (Nmap Scripting Engine) transforms nmap from a port scanner into a full-fledged network reconnaissance platform. Scripts are written in Lua and cover tasks from enumerating SMB shares to detecting specific vulnerabilities.
Safe scripts (-sC) vs. intrusive
Flag -sCruns scripts from the category default— they must not disrupt services. Examples: receiving an SSH banner, listing HTTP headers, or basic SMB domain information.
All NSE scripts are divided into categories: safe, default, discovery, vuln, brute, intrusiveand others. Category intrusivecan cause a denial of service—scripts from it send exploit-like requests. On CTF machines with unstable custom services, running --script intrusiveIt's a gamble: either useful information, or a crashed service center and a machine reset. I've been burned by this more than once.
Rule of thumb for nmap for beginners: use -sCfor general reconnaissance and specific named scripts for in-depth analysis.
Scripts for typical CTF tasks
Instead of launching an entire category, it's more efficient to call scripts selectively. Here are some examples for common scenarios.
SMB enumeration (ports 139, 445): nmap --script smb-enum-shares,smb-enum-users -p 445 target— will display network resources (shares) and a list of users. On machines with Active Directory, this is often the first step to initial access.
HTTP enumeration (ports 80, 443, 8080): nmap --script http-enum -p 80 target— checks for the presence of standard paths: /admin, /phpmyadmin, /robots.txtEssentially, it's a quick directory bruteforce without any additional tools.
Vulnerability Scan: nmap --script vuln -p 445 target— checks SMB for known vulnerabilities. The script is noisy, so only use it on a specific port when you know what you're looking for.
FTP anonymous: nmap --script ftp-anon -p 21 target— instant anonymous FTP access check. One of the most common snags on Easy machines.
The full set of scripts is in /usr/share/nmap/scripts/— there are more than 600 of them. The names are telling: http-sql-injection, ssh-brute, dns-zone-transferYou can just lsby directory and select the desired one.
Network Scanning Without Detection: Timing and IDS Bypass
Scan speed is a tradeoff between time, accuracy, and visibility. Nmap provides tools for managing both.
Timing patterns from T0 to T5
Nmap supports six timing templates. The choice affects the interval between packets, the number of parallel probes, and timeouts.
-T0 (Paranoid) – one packet every 5 minutes. Practically invisible to IDS, but useless in CTF: a thousand ports would take several days.
-T1 (Sneaky) — 15 seconds between packets. For real-world pentesting on secure networks.
-T2 (Polite) — 0.4 seconds between packets. Minimal network load.
-T3 (Normal) — the default mode. A balanced option.
-T4 (Aggressive) — short timeouts, more parallel probes. My choice for CTFs over VPN.
-T5 (Insane) — minimal timeouts, maximum parallelism. Fast, but unreliable: may miss open ports and crash vulnerable services.
Optimal for CTF platforms -T4The OpenVPN connection is quite stable, and the speed is an order of magnitude higher than the default T3. Switch to -T3, if you notice missing ports or the results are inconsistent when re-scanning.
Bypassing IDS Scanning: Decoy and Fragmentation
On CTF machines with an IDS component or in stealth missions, camouflage techniques will come in handy.
Decoy scan ( -D): nmap substitutes "fake" IP addresses as packet sources along with your real one: sudo nmap -sS -D 192.168.1.100,192.168.1.101,ME targetPackets from multiple addresses will appear in the IDS logs, making it more difficult to identify the actual scanner. Marker MEspecifies the position of your IP - without it, nmap will put it in a random place in the list.
Fragmentation ( -f): splits TCP headers into 8-byte fragments, making it more difficult for the IDS to reassemble the packet. Double flag -ff— into 16-byte fragments. Modern IDSs can handle reassembly, but in CTF tasks with old firewall rules, this may still work.
Source port spoofing ( --source-port): Some firewalls allow traffic from "trusted" ports. Command nmap --source-port 53 targetIt can bypass simple rules that allow DNS traffic. It's crude, but it does happen on Easy machines.
ACK scan ( -sA): a technique rarely explained in nmap beginner's guides. It doesn't detect open ports, but it does identify firewall rules. Nmap sends packets with the ACK flag: if a RST is received, the port is unfiltered; if there's no response, the firewall is blocking (filtered). An ACK scan will never show a port as open or closed—only unfiltered or filtered. It's useful for mapping firewall rules before the main scan. An ACK scan works in conjunction with a SYN scan: first -sAfor the filtering map, then -sSto unfiltered ports.
Saving Results: nmap Commands for a Workflow
The results need to be saved. For writeup, for reanalysis, and for sharing with a partner. Nmap supports three output formats: -oN(text as in the terminal), -oX(XML for Metasploit and Burp), -oG(grepable format for searching through grep).
Combined flag -oA basenameSaves in all three formats simultaneously. I recommend this one with a meaningful name: nmap -sV -sC -p 22,80 -oA nmap/targeted 10.10.10.5Then you won't have to rescan the target because you forgot to save.
A good habit is to have a single directory structure for each machine:
htb-box1/
├── nmap/
│ ├── initial.nmap
│ ├── full.nmap
│ └── targeted.nmap
├── exploit/
└── loot/
This structure allows you to work on several machines in parallel without mixing up the results. Category #14 Port Scan— is one of the most common in IP reputation services like AbuseIPDB, so when working on external CTF platforms, your IP may be registered. Saved results will help prove the legitimacy of your actions.
Common Mistakes Newbies Make When Scanning Ports with Nmap
A few rakes that almost everyone steps on. I've stepped on every one of them.
Start with -p-. A full scan of all ports is the last step, not the first. First --top-ports 1000, Then -p-if necessary.
Forget about UDP. Easy machines on CTF platforms regularly run tasks where the key service is SNMP on UDP 161. snmpwalkYou can extract passwords, usernames, and system configuration (Remote System Discovery, T1018). You spend hours poking around in TCP—and the UDP response is still there.
Use T5 over VPN. The connection to the CTF platform is via OpenVPN, so packet loss is inevitable. T5 with minimal timeouts will allow responses and mark open ports as filtered. T4 is the maximum for VPN scenarios.
Do not save results. Without -oAYou have to rescan the target every time you need to check it. This wastes time and adds noise.
Run vuln scripts on all ports. Category vulnPerforms real checks—sending exploit-like requests. This is both time-consuming and risky: --script vuln -p 445— yes, --script vuln without -p - No.
Ignore the "filtered" output. The "filtered" status means the firewall is blocking the port. This isn't "closed"—the filter may be hiding a working service. A combination of an ACK scan and changing the source port can sometimes break through simple rules.
Don't check nmap version. Older versions of nmap (before 7.80) lack up-to-date fingerprints for modern operating systems and services. Command nmap --versiontakes a second, but saves hours of inaccurate results.
Most of the materials on nmap for beginners are written as a flag reference: here -sS, Here -sV, Here -A,
NSE (Nmap Scripting Engine) transforms nmap from a port scanner into a full-fledged network reconnaissance platform. Scripts are written in Lua and cover tasks from enumerating SMB shares to detecting specific vulnerabilities.
Safe scripts (-sC) vs. intrusive
Flag -sCruns scripts from the category default— they must not disrupt services. Examples: receiving an SSH banner, listing HTTP headers, or basic SMB domain information.
All NSE scripts are divided into categories: safe, default, discovery, vuln, brute, intrusiveand others. Category intrusivecan cause a denial of service—scripts from it send exploit-like requests. On CTF machines with unstable custom services, running --script intrusiveIt's a gamble: either useful information, or a crashed service center and a machine reset. I've been burned by this more than once.
Rule of thumb for nmap for beginners: use -sCfor general reconnaissance and specific named scripts for in-depth analysis.
Scripts for typical CTF tasks
Instead of launching an entire category, it's more efficient to call scripts selectively. Here are some examples for common scenarios.
SMB enumeration (ports 139, 445): nmap --script smb-enum-shares,smb-enum-users -p 445 target— will display network resources (shares) and a list of users. On machines with Active Directory, this is often the first step to initial access.
HTTP enumeration (ports 80, 443, 8080): nmap --script http-enum -p 80 target— checks for the presence of standard paths: /admin, /phpmyadmin, /robots.txtEssentially, it's a quick directory bruteforce without any additional tools.
Vulnerability Scan: nmap --script vuln -p 445 target— checks SMB for known vulnerabilities. The script is noisy, so only use it on a specific port when you know what you're looking for.
FTP anonymous: nmap --script ftp-anon -p 21 target— instant anonymous FTP access check. One of the most common snags on Easy machines.
The full set of scripts is in /usr/share/nmap/scripts/— there are more than 600 of them. The names are telling: http-sql-injection, ssh-brute, dns-zone-transferYou can just lsby directory and select the desired one.
Network Scanning Without Detection: Timing and IDS Bypass
Scan speed is a tradeoff between time, accuracy, and visibility. Nmap provides tools for managing both.
Timing patterns from T0 to T5
Nmap supports six timing templates. The choice affects the interval between packets, the number of parallel probes, and timeouts.
-T0 (Paranoid) – one packet every 5 minutes. Practically invisible to IDS, but useless in CTF: a thousand ports would take several days.
-T1 (Sneaky) — 15 seconds between packets. For real-world pentesting on secure networks.
-T2 (Polite) — 0.4 seconds between packets. Minimal network load.
-T3 (Normal) — the default mode. A balanced option.
-T4 (Aggressive) — short timeouts, more parallel probes. My choice for CTFs over VPN.
-T5 (Insane) — minimal timeouts, maximum parallelism. Fast, but unreliable: may miss open ports and crash vulnerable services.
Optimal for CTF platforms -T4The OpenVPN connection is quite stable, and the speed is an order of magnitude higher than the default T3. Switch to -T3, if you notice missing ports or the results are inconsistent when re-scanning.
Bypassing IDS Scanning: Decoy and Fragmentation
On CTF machines with an IDS component or in stealth missions, camouflage techniques will come in handy.
Decoy scan ( -D): nmap substitutes "fake" IP addresses as packet sources along with your real one: sudo nmap -sS -D 192.168.1.100,192.168.1.101,ME targetPackets from multiple addresses will appear in the IDS logs, making it more difficult to identify the actual scanner. Marker MEspecifies the position of your IP - without it, nmap will put it in a random place in the list.
Fragmentation ( -f): splits TCP headers into 8-byte fragments, making it more difficult for the IDS to reassemble the packet. Double flag -ff— into 16-byte fragments. Modern IDSs can handle reassembly, but in CTF tasks with old firewall rules, this may still work.
Source port spoofing ( --source-port): Some firewalls allow traffic from "trusted" ports. Command nmap --source-port 53 targetIt can bypass simple rules that allow DNS traffic. It's crude, but it does happen on Easy machines.
ACK scan ( -sA): a technique rarely explained in nmap beginner's guides. It doesn't detect open ports, but it does identify firewall rules. Nmap sends packets with the ACK flag: if a RST is received, the port is unfiltered; if there's no response, the firewall is blocking (filtered). An ACK scan will never show a port as open or closed—only unfiltered or filtered. It's useful for mapping firewall rules before the main scan. An ACK scan works in conjunction with a SYN scan: first -sAfor the filtering map, then -sSto unfiltered ports.
Saving Results: nmap Commands for a Workflow
The results need to be saved. For writeup, for reanalysis, and for sharing with a partner. Nmap supports three output formats: -oN(text as in the terminal), -oX(XML for Metasploit and Burp), -oG(grepable format for searching through grep).
Combined flag -oA basenameSaves in all three formats simultaneously. I recommend this one with a meaningful name: nmap -sV -sC -p 22,80 -oA nmap/targeted 10.10.10.5Then you won't have to rescan the target because you forgot to save.
A good habit is to have a single directory structure for each machine:
htb-box1/
├── nmap/
│ ├── initial.nmap
│ ├── full.nmap
│ └── targeted.nmap
├── exploit/
└── loot/
This structure allows you to work on several machines in parallel without mixing up the results. Category #14 Port Scan— is one of the most common in IP reputation services like AbuseIPDB, so when working on external CTF platforms, your IP may be registered. Saved results will help prove the legitimacy of your actions.
Common Mistakes Newbies Make When Scanning Ports with Nmap
A few rakes that almost everyone steps on. I've stepped on every one of them.
Start with -p-. A full scan of all ports is the last step, not the first. First --top-ports 1000, Then -p-if necessary.
Forget about UDP. Easy machines on CTF platforms regularly run tasks where the key service is SNMP on UDP 161. snmpwalkYou can extract passwords, usernames, and system configuration (Remote System Discovery, T1018). You spend hours poking around in TCP—and the UDP response is still there.
Use T5 over VPN. The connection to the CTF platform is via OpenVPN, so packet loss is inevitable. T5 with minimal timeouts will allow responses and mark open ports as filtered. T4 is the maximum for VPN scenarios.
Do not save results. Without -oAYou have to rescan the target every time you need to check it. This wastes time and adds noise.
Run vuln scripts on all ports. Category vulnPerforms real checks—sending exploit-like requests. This is both time-consuming and risky: --script vuln -p 445— yes, --script vuln without -p - No.
Ignore the "filtered" output. The "filtered" status means the firewall is blocking the port. This isn't "closed"—the filter may be hiding a working service. A combination of an ACK scan and changing the source port can sometimes break through simple rules.
Don't check nmap version. Older versions of nmap (before 7.80) lack up-to-date fingerprints for modern operating systems and services. Command nmap --versiontakes a second, but saves hours of inaccurate results.
Most of the materials on nmap for beginners are written as a flag reference: here -sS, Here -sV, Here -A,