Command Sheet Cheat - Nmap
Command Sheet Cheat - Nmap
Command Table
Command Switch Description
nmap -sS SYN scan (half-open)
-sU UDP scan
-sT TCP connect scan
-O Detect Operating system
-sV Detect Versions of the services running on the target
-v Provide verbose (use -vv or more for increased verbosity)
-oA Save nmap result in three major formats
-oN Save nmap result on normal format
-oG Save nmap result on “Grepable” format
Enable “Aggressive” mode. Activates service, OS,
-A traceroute and common script scanning detection – loud
option
-T# Select level of Timing – from 1 to 5
-p ## Scan port ##
-p ####-#### Scan port interval
-p- Scan ALL PORTS
--script Activate a script from nmap scripting library
--script=category Activate all scripts from category (see here)
-sN TCP NULL scans
-sF TCP FIN scans
-sX TCP XMAS scans
Scans #### common ports from the scan type (TCP or UDP).
--top-ports ####
Used to improve scan time
ICMP scan. Forces namp to relly on ICMP echo packets or
-sn <IP/subnet>
ARP on local network with sudo
Do not ping host before scanning it – treats host as being
-Pn
alive
Fragment packets into smaller pieces, making them less
-f
likely to be detected
Select maximum transmission unit size to use for the packet
--mtu <number>
sent. Must be multiple of 8!
--scan-delay Add a delay between packets sent. Good to evade time-
<time>ms based detection systems
Generate invalid checksum for packets. Hosts normally drop
--badsum them, but FIREWALL might respond. Used to determine the
presence of firewall/IDS
Página 1|6
TCP Connect scans (-sT)
RFC 793 defines TCP behavior. TCP Connect scan works by performing the three-way handshake with
each target port in turn. In other words, Nmap tries to connect to each specified TCP port, and
determines whether the service is open by the response it receives. Performs full 3-way handshake.
They are the default scan used when running nmap with sudo.
• No response → Nmap refers the port as open|filtered – can be open but “firewalled”
• UDP response → (very unsual) marked as open
• Closed UDP port → target responds with ICMP port unreachable.
Página 2|6
FIN scans (-sF)
Instead of sending a completely empty packet, a request is sent with the FIN flag (usually used to
gracefully close an active connection). Once again, Nmap expects a RST if the port is closed.
Página 3|6
• Open port → If the port is open, there is no response to malformed packet. It’s also a expected
behavior if the port is protected by firewall, so all the 3 scans will only identify ports as being
open|filtered, closed or filtered.
With a filtered identification, normally the victim responded with a ICMP unreachable packet.
The goal here is firewall invasion. Many firewalls are configured to drop incoming TCP packets to
blocked ports which have the SYN flag set (thus blocking new connection initiation requests). By
sending requests which do not contain the SYN flag, we effectively bypass this kind of firewall. Whilst
this is good in theory, most modern IDS solutions are savvy to these scan types, so don't rely on them
to be 100% effective when dealing with modern systems.
Categories
Página 4|6
Multiple scripts can be run simultaneously in this fashion by separating them by a comma:
• --script=smb-enum-users,smb-enum-shares
Script arguments
Some scripts require arguments (for example, credentials, if they're exploiting an authenticated
vulnerability). These can be given with the
• --script-args
An example of this would be with the http-put script (used to upload files using the PUT method). This
takes two arguments: the URL to upload the file to, and the file's location on disk.
Note that the arguments are separated by commas, and connected to the corresponding script with
periods (i.e. <script-name>.<argument>).
Getting help
Nmap scripts come with built-in help menus, which can be accessed using:
This tends not to be as extensive as in the link given above, however, it can still be useful when working
locally.
One is by using the /usr/share/nmap/scripts/script.db file. Despite the extension, this is not actually
a database so much as a formatted text file containing filenames and categories for each available
script.
Grep
Nmap uses this file to keep track of (and utilise) scripts for the scripting engine; however, we can also
grep through it to look for scripts.
grep "ftp" /usr/share/nmap/scripts/script.db
Página 5|6
LS command
The second way to search for scripts is quite simply to use the ls command. For example, we could get
the same results as in the previous screenshot by using:
ls -l /usr/share/nmap/scripts/*ftp*
Search categories
The same techniques can also be used to search for categories of script.
grep "safe" /usr/share/nmap/scripts/script.db
Firewall Evasion
Normally firewalls block ICMP packets (like Windows default firewall configuration). We have some
switches to help us to get around this.
• -Pn, which tells Nmap to not bother pinging the host before scanning it
• -f:- Used to fragment the packets (i.e. split them into smaller pieces) making it less likely that
the packets will be detected by a firewall or IDS.
• An alternative to -f, but providing more control over the size of the packets: --mtu
<number>, accepts a maximum transmission unit size to use for the packets sent.
This must be a multiple of 8.
• --scan-delay <time>ms:- used to add a delay between packets sent. This is very useful if the
network is unstable, but also for evading any time-based firewall/IDS triggers which may be
in place.
• --badsum:- this is used to generate in invalid checksum for packets. Any real TCP/IP stack
would drop this packet, however, firewalls may potentially respond automatically, without
bothering to check the checksum of the packet. As such, this switch can be used to
determine the presence of a firewall/IDS.
Fábio Teles
26/02/2021
Página 6|6