Table of Contents
Description
Nmap (Network Mapper) is an open-source tool used for network discovery, port scanning, and vulnerability assessment. It helps identify live hosts, open ports, services, and operating system details on a network.
Favorites
My go-to favorite scans to run ASAP.
The Overseer - Quick TCP, full TCP and a UDP scan all in one!
sudo nmap <target> -sC -sV -Pn && sleep 5 && sudo nmap <target> -Pn -p- && sleep 5 && sudo nmap <target> -sU -Pn
The Overseer with a file
sudo nmap -iL <TARGET FILE> -sC -sV -Pn && sleep 5 && sudo nmap -iL <TARGET FILE> -Pn -p- && sleep 5 && sudo nmap -iL <TARGET FILE> -sU -Pn
Quick TCP scan
sudo nmap <target> -sV -sC -Pn -vvv
Quick full TCP scan
sudo nmap <target> -p- -Pn -vvv
Full targeted TCP scan
sudo nmap <target> -p <port> -A -Pn -vvv
UDP scan
sudo nmap <target> -sU -Pn -vvv
If it’s too long, add -F flag to scan the essentials
Tips
Default scans
The default Nmap scan type (when run as a normal user) is a TCP Connect scan (-sT), which completes the full three-way handshake with each target port.
When using sudo, Nmap defaults to a SYN scan (-sS), which is faster and stealthier because it sends SYN packets but does not complete the handshake.
Try to always run sudo as -sS is better.
Aggressive scan
-A is a combination of multiple Nmap flags:
-sC→ Runs default NSE scripts.-sV→ Detects service versions.-O→ Detects the operating system.--traceroute→ Maps network paths.
It’s an aggressive scan, providing detailed info but making more noise on the network.
IPs in a file
You can specify host IPs in a file and run them with -iL like so - sudo nmap -iL ips.txt -sC -sV -Pn.
TTL OS version verification
Besides using -O to know the OS version of the scanned host we can also look at the TTL in the scan.
Based on it, we can tell what OS is running on the target host.0
| Operating System | TCP/UDP |
|---|---|
| Windows 95/98/ME | 32 |
| Linux | 64 |
| FreeBSD | 64 |
| Mac OS X | 64 |
| Windows XP, 7, 8, 2004, 2008 | 128 |
| Solaris | 255 |
You can find way more examples here.
Filtering
Sometimes there is ICMP filtering in the firewalls. Try to always use the -Pn flag.
It that’s not the case, maybe it’s because ARP pings. use --disable-arp-ping to test that.
If you encounter further issues, consider --packet-trace and --reason flags for troubleshooting.
Saving results
You can save your scans by adding -oA <filename> to your command.
tcpwrapped
When Nmap reports tcpwrapped it usually means the port is open, but the service immediately closes the connection from Nmap, often because TCP Wrappers or similar access controls reject the connection.
TCP Wrappers are a host-based access-control mechanism used mainly on older Unix/Linux systems. They can restrict network access to services based on the connecting IP address, using /etc/hosts.allow and /etc/hosts.deny.
Proxychains
nmap works with proxy chains, although a bit gimmicy, it’s pretty slow, work best - if not only - with -sT scans, and can give false-positives when you run a more complicated commands.
Here are some examples of usage:
sudo proxychains nmap -sT --top-ports=20 -Pn 172.16.194.240
proxychains nmap 172.16.5.19 -p3389 -sT -v -Pn
proxychains nmap -v -sn 172.16.5.1-200
sudo proxychains nmap -vvv -sT --top-ports=20 -Pn 172.16.50.217
States
Explanation of states of the scans.
| State | Description |
|---|---|
open | This indicates that the connection to the scanned port has been established. These connections can be TCP connections, UDP datagrams as well as SCTP associations. |
closed | When the port is shown as closed, the TCP protocol indicates that the packet we received back contains an RST flag. This scanning method can also be used to determine if our target is alive or not. |
filtered | Nmap cannot correctly identify whether the scanned port is open or closed because either no response is returned from the target for the port or we get an error code from the target. |
unfiltered | This state of a port only occurs during the TCP-ACK scan and means that the port is accessible, but it cannot be determined whether it is open or closed. |
open|filtered | If we do not get a response for a specific port, Nmap will set it to that state. This indicates that a firewall or packet filter may protect the port. |
closed|filtered | This state only occurs in the IP ID idle scans and indicates that it was impossible to determine if the scanned port is closed or filtered by a firewall. |
Timing templates
Details of scanning when using the -T flag like -T4 for example.
| T0 | T1 | T2 | T3 | T4 | T5 | |
|---|---|---|---|---|---|---|
| Name | Paranoid | Sneaky | Polite | Normal | Aggressive | Insane |
| min-rtt-timeout | 100ms | 100ms | 100ms | 100ms | 100ms | 50ms |
| max-rtt-timeout | 5m | 15s | 10s | 10s | 1250ms | 300ms |
| initial-rtt-timeout | 5m | 15s | 1s | 1s | 500ms | 250ms |
| max-retries | 10 | 10 | 10 | 10 | 6 | 2 |
| Initial (and minimum) scan delay (—scan-delay) | 5m | 15s | 400ms | 0 | 0 | 0 |
| Maximum TCP scan delay | 5m | 15s | 1s | 1s | 10ms | 5ms |
| Maximum UDP scan delay | 5m | 15s | 1s | 1s | 1s | 1s |
| host-timeout | 0 | 0 | 0 | 0 | 0 | 15m |
| script-timeout | 0 | 0 | 0 | 0 | 0 | 10m |
| min-parallelism | Dynamic | Not | Affected | By | Timing | Templates |
| max-parallelism | 1 | 1 | 1 | Dynamic | Dynamic | Dynamic |
| min-hostgroup | Dynamic | Not | Affected | By | Timing | Templates |
| max-hostgroup | Dynamic | Not | Affected | By | Timing | Templates |
| min-rate | No | Minimum | Rate | Limit | ||
| max-rate | No | Maximum | Rate | Limit | ||
| defeat-rst-ratelimit | Not | Enabled | By | Default |
Scripts
Nmap Scripting Engine (NSE) is another handy feature of Nmap. It provides us with the possibility to create scripts in Lua for interaction with certain services. There are a total of 14 categories into which these scripts can be divided:
| Category | Description |
|---|---|
auth | Determination of authentication credentials. |
broadcast | Scripts, which are used for host discovery by broadcasting and the discovered hosts, can be automatically added to the remaining scans. |
brute | Executes scripts that try to log in to the respective service by brute-forcing with credentials. |
default | Default scripts executed by using the -sC option. |
discovery | Evaluation of accessible services. |
dos | These scripts are used to check services for denial of service vulnerabilities and are used less as it harms the services. |
exploit | This category of scripts tries to exploit known vulnerabilities for the scanned port. |
external | Scripts that use external services for further processing. |
fuzzer | This uses scripts to identify vulnerabilities and unexpected packet handling by sending different fields, which can take much time. |
intrusive | Intrusive scripts that could negatively affect the target system. |
malware | Checks if some malware infects the target system. |
safe | Defensive scripts that do not perform intrusive and destructive access. |
version | Extension for service detection. |
vuln | Identification of specific vulnerabilities. |
We have several ways to define the desired scripts in nmap
Default scripts
-sC flag runs default scripts.
sudo nmap <target> -sC
Specific scripts category
sudo nmap <target> --script <category>
Defined scripts
This will run all scripts that contain “smb” in their name.
sudo nmap <target> --script "*smb*"
This will run directly specified scripts.
sudo nmap <target> --script <script-name>,<script-name>
References
https://nmap.org/book/performance-timing-templates.html - Time templates
https://ostechnix.com/identify-operating-system-ttl-ping/ - TTL OS versions cheatsheet