Network exploration tool and security / port scanner
|
-p port ranges (Only scan specified ports) .
This option specifies which ports you want to scan and overrides the default. Individual port numbers
are OK, as are ranges separated by a hyphen (e.g. 1-1023). The beginning and/or end values of a
range may be omitted, causing Nmap to use 1 and 65535, respectively. So you can specify -p- to scan
ports from 1 through 65535. Scanning port zero. is allowed if you specify it explicitly. For IP
protocol scanning (-sO), this option specifies the protocol numbers you wish to scan for (0–255).
When scanning both TCP and UDP ports, you can specify a particular protocol by preceding the port
numbers by T: or U:. The qualifier lasts until you specify another qualifier. For example, the
argument -p U:53,111,137,T:21-25,80,139,8080 would scan UDP ports 53, 111,and 137, as well as the
listed TCP ports. Note that to scan both UDP and TCP, you have to specify -sU and at least one TCP
scan type (such as -sS, -sF, or -sT). If no protocol qualifier is given, the port numbers are added
to all protocol lists. Ports can also be specified by name according to what the port is referred to
in the nmap-services. You can even use the wildcards * and ? with the names. For example, to scan FTP
and all ports whose names begin with “http”, use -p ftp,http*. Be careful about shell expansions and
quote the argument to -p if unsure.
Ranges of ports can be surrounded by square brackets to indicate ports inside that range that appear
in nmap-services. For example, the following will scan all ports in nmap-services equal to or below
1024: -p [-1024]. Be careful with shell expansions and quote the argument to -p if unsure.
|
--open (Show only open (or possibly open) ports) .
Sometimes you only care about ports you can actually connect to (open ones), and don´t want results
cluttered with closed, filtered, and closed|filtered ports. Output customization is normally done
after the scan using tools such as grep, awk, and Perl, but this feature was added due to
overwhelming requests. Specify --open to only see open, open|filtered, and unfiltered ports. These
three ports are treated just as they normally are, which means that open|filtered and unfiltered may
be condensed into counts if there are an overwhelming number of them.
|
-sS (TCP SYN scan) .
SYN scan is the default and most popular scan option for good reasons. It can be performed quickly,
scanning thousands of ports per second on a fast network not hampered by restrictive firewalls. SYN
scan is relatively unobtrusive and stealthy, since it never completes TCP connections. It also works
against any compliant TCP stack rather than depending on idiosyncrasies of specific platforms as
Nmap´s FIN/NULL/Xmas, Maimon and idle scans do. It also allows clear, reliable differentiation
between the open, closed, and filtered states.
This technique is often referred to as half-open scanning, because you don´t open a full TCP
connection. You send a SYN packet, as if you are going to open a real connection and then wait for a
response. A SYN/ACK indicates the port is listening (open), while a RST (reset) is indicative of a
non-listener. If no response is received after several retransmissions, the port is marked as
filtered. The port is also marked filtered if an ICMP unreachable error (type 3, code 1, 2, 3, 9, 10,
or 13) is received.
|
--min-rate number; --max-rate number (Directly control the scanning rate) .
Nmap´s dynamic timing does a good job of finding an appropriate speed at which to scan. Sometimes,
however, you may happen to know an appropriate scanning rate for a network, or you may have to
guarantee that a scan will be finished by a certain time. Or perhaps you must keep Nmap from scanning
too quickly. The --min-rate and --max-rate options are designed for these situations.
When the --min-rate option is given Nmap will do its best to send packets as fast as or faster than
the given rate. The argument is a positive real number representing a packet rate in packets per
second. For example, specifying --min-rate 300 means that Nmap will try to keep the sending rate at
or above 300 packets per second. Specifying a minimum rate does not keep Nmap from going faster if
conditions warrant.
Likewise, --max-rate limits a scan´s sending rate to a given maximum. Use --max-rate 100, for
example, to limit sending to 100 packets per second on a fast network. Use --max-rate 0.1 for a slow
scan of one packet every ten seconds. Use --min-rate and --max-rate together to keep the rate inside
a certain range.
These two options are global, affecting an entire scan, not individual hosts. They only affect port
scans and host discovery scans. Other features like OS detection implement their own timing.
There are two conditions when the actual scanning rate may fall below the requested minimum. The
first is if the minimum is faster than the fastest rate at which Nmap can send, which is dependent on
hardware. In this case Nmap will simply send packets as fast as possible, but be aware that such high
rates are likely to cause a loss of accuracy. The second case is when Nmap has nothing to send, for
example at the end of a scan when the last probes have been sent and Nmap is waiting for them to time
out or be responded to. It´s normal to see the scanning rate drop at the end of a scan or in between
hostgroups. The sending rate may temporarily exceed the maximum to make up for unpredictable delays,
but on average the rate will stay at or below the maximum.
Specifying a minimum rate should be done with care. Scanning faster than a network can support may
lead to a loss of accuracy. In some cases, using a faster rate can make a scan take longer than it
would with a slower rate. This is because Nmap´s
adaptive retransmission algorithms will detect the network congestion caused by an excessive scanning
rate and increase the number of retransmissions in order to improve accuracy. So even though packets
are sent at a higher rate, more packets are sent overall. Cap the number of retransmissions with the
--max-retries option if you need to set an upper limit on total scan time.
|
-v (Increase verbosity level) .
Increases the verbosity level, causing Nmap to print more information about the scan in progress.
Open ports are shown as they are found and completion time estimates are provided when Nmap thinks a
scan will take more than a few minutes. Use it twice or more for even greater verbosity.
Most changes only affect interactive output, and some also affect normal and script kiddie output.
The other output types are meant to be processed by machines, so Nmap can give substantial detail by
default in those formats without fatiguing a human user. However, there are a few changes in other
modes where output size can be reduced substantially by omitting some detail. For example, a comment
line in the grepable output that provides a list of all ports scanned is only printed in verbose mode
because it can be quite long.
|
-n (No DNS resolution) .
Tells Nmap to never do reverse DNS resolution on the active IP addresses it finds. Since DNS can be
slow even with Nmap´s built-in parallel stub resolver, this option can slash scanning times.
|
nmap [Scan Type...] [Options] {target specification}
|
-oG filespec (grepable output) .
This output format is covered last because it is deprecated. The XML output format is far more
powerful, and is nearly as convenient for experienced users. XML is a standard for which dozens of
excellent parsers are available, while grepable output is my own simple hack. XML is extensible to
support new Nmap features as they are released, while I often must omit those features from grepable
output for lack of a place to put them.
Nevertheless, grepable output is still quite popular. It is a simple format that lists each host on
one line and can be trivially searched and parsed with standard Unix tools such as grep, awk, cut,
sed, diff, and Perl. Even I usually use it for one-off tests done at the command line. Finding all
the hosts with the SSH port open or that are running Solaris takes only a simple grep to identify the
hosts, piped to an awk or cut command to print the desired fields.
Grepable output consists of comments (lines starting with a pound (#)). and target lines. A target
line includes a combination of six labeled fields, separated by tabs and followed with a colon. The
fields are Host, Ports, Protocols, Ignored State, OS, Seq Index, IP ID, and Status.
The most important of these fields is generally Ports, which gives details on each interesting port.
It is a comma separated list of port entries. Each port entry represents one interesting port, and
takes the form of seven slash (/) separated subfields. Those subfields are: Port number, State,
Protocol, Owner, Service, SunRPC info, and Version info.
As with XML output, this man page does not allow for documenting the entire format. A more detailed
look at the Nmap grepable output format is available from
http://nmap.org/book/output-formats-grepable-output.html.
|