diff options
Diffstat (limited to 'docs/refguide.xml')
-rw-r--r-- | docs/refguide.xml | 4736 |
1 files changed, 4736 insertions, 0 deletions
diff --git a/docs/refguide.xml b/docs/refguide.xml new file mode 100644 index 0000000..f054999 --- /dev/null +++ b/docs/refguide.xml @@ -0,0 +1,4736 @@ +<indexterm><primary>man page</primary><see>reference guide</see></indexterm> +<indexterm class="startofrange" id="man-nmap1-indexterm"><primary>reference guide (man page)</primary></indexterm> +<refentry id='man-nmap1'> + <refmeta> + <refentrytitle>nmap</refentrytitle> + <manvolnum>1</manvolnum> + <refmiscinfo class="source">Nmap</refmiscinfo> + <refmiscinfo class="manual">Nmap Reference Guide</refmiscinfo> + </refmeta> + <refnamediv id='man-name'> + <refname>nmap</refname> + <refpurpose>Network exploration tool and security / port scanner</refpurpose> + </refnamediv> + <!-- body begins here --> + <refsynopsisdiv id='man-synopsis'> + <cmdsynopsis> + <command>nmap</command> + <arg choice='opt' rep='repeat'> + <replaceable>Scan Type</replaceable> + </arg> + <arg choice='opt'> + <replaceable>Options</replaceable> + </arg> + <arg choice='req'> + <replaceable>target specification</replaceable> + </arg> + </cmdsynopsis> + </refsynopsisdiv> + <refsect1 id='man-description'> + <title>Description</title> + <indexterm><primary>Nmap</primary><secondary>description of</secondary></indexterm> + <web> + <note><para>This document describes the very latest version of + Nmap available from <ulink + url="https://nmap.org/download.html" /> or <ulink + url="https://nmap.org/dist/?C=M&O=D" />. Please + ensure you are using the latest version before reporting that a + feature doesn't work as described.</para></note> + </web> + <para>Nmap (<quote>Network Mapper</quote>) is an open source tool for network + exploration and security auditing. It was designed to rapidly + scan large networks, although it works fine against single + hosts. Nmap uses raw IP packets in novel ways to determine what + hosts are available on the network, what services (application + name and version) those hosts are offering, what operating systems + (and OS versions) they are running, what type of packet + filters/firewalls are in use, and dozens of other + characteristics. While Nmap is commonly used for security audits, + many systems and network administrators find it useful for routine + tasks such as network inventory, managing service upgrade + schedules, and monitoring host or service uptime.</para> + + <para>The output from Nmap is a list of scanned targets, with + supplemental information on each depending on the options + used. Key among that information is the <quote>interesting ports + table</quote>.<indexterm><primary>ports</primary><secondary sortas="interesting">“interesting”</secondary></indexterm> + That table lists the port number and protocol, + service name, and state. The state is either + <literal>open</literal>, <literal>filtered</literal>, + <literal>closed</literal>, or <literal>unfiltered</literal>. + <literal>Open</literal><indexterm><primary><literal>open</literal> port state</primary></indexterm> + means that an application on the target machine is listening for + connections/packets on that port. + <literal>Filtered</literal><indexterm><primary><literal>filtered</literal> port state</primary></indexterm> + means that a firewall, filter, or other network + obstacle is blocking the port so that Nmap cannot tell whether it is + <literal>open</literal> or <literal>closed</literal>. + <literal>Closed</literal><indexterm><primary><literal>closed</literal> port state</primary></indexterm> + ports have no application listening on them, + though they could open up at any time. + Ports are classified as + <literal>unfiltered</literal><indexterm><primary><literal>unfiltered</literal> port state</primary></indexterm> + when they are + responsive to Nmap's probes, but Nmap cannot determine whether they are + open or closed. + Nmap reports the state combinations + <literal>open|filtered</literal><indexterm><primary><literal>open|filtered</literal> port state</primary></indexterm> + and <literal>closed|filtered</literal><indexterm><primary><literal>closed|filtered</literal> port state</primary></indexterm> + when it cannot determine which + of the two states describe a port. The port table may also + include software version details when version detection has been + requested. When an IP protocol scan is requested + (<option>-sO</option>), Nmap provides information on supported IP + protocols rather than listening ports.</para> + + <para>In addition to the interesting ports table, Nmap can provide + further information on targets, including reverse DNS names, + operating system guesses, device types, and MAC addresses.</para> + + <para>A typical Nmap scan is shown in <xref + linkend="man-ex-repscan" xrefstyle="select: label nopage" />. The only Nmap arguments used in + this example are <option>-A</option>, to enable OS and version + detection, script scanning, and traceroute; <option>-T4</option> for + faster execution; and then the hostname.</para> + +<example id="man-ex-repscan"><title>A representative Nmap scan</title> +<indexterm><primary><option>-A</option></primary><secondary>example of</secondary></indexterm> +<screen> +# <userinput>nmap -A -T4 scanme.nmap.org</userinput> + +Nmap scan report for scanme.nmap.org (74.207.244.221) +Host is up (0.029s latency). +rDNS record for 74.207.244.221: li86-221.members.linode.com +Not shown: 995 closed ports +PORT STATE SERVICE VERSION +22/tcp open ssh OpenSSH 5.3p1 Debian 3ubuntu7 (protocol 2.0) +| ssh-hostkey: 1024 8d:60:f1:7c:ca:b7:3d:0a:d6:67:54:9d:69:d9:b9:dd (DSA) +|_2048 79:f8:09:ac:d4:e2:32:42:10:49:d3:bd:20:82:85:ec (RSA) +80/tcp open http Apache httpd 2.2.14 ((Ubuntu)) +|_http-title: Go ahead and ScanMe! +646/tcp filtered ldp +1720/tcp filtered H.323/Q.931 +9929/tcp open nping-echo Nping echo +Device type: general purpose +Running: Linux 2.6.X +OS CPE: cpe:/o:linux:linux_kernel:2.6.39 +OS details: Linux 2.6.39 +Network Distance: 11 hops +Service Info: OS: Linux; CPE: cpe:/o:linux:kernel + +TRACEROUTE (using port 53/tcp) +HOP RTT ADDRESS +[Cut first 10 hops for brevity] +11 17.65 ms li86-221.members.linode.com (74.207.244.221) + +Nmap done: 1 IP address (1 host up) scanned in 14.40 seconds +</screen> +</example> + +<!-- This para is a bit jumbled together for man page rendering reasons --> +<para>The newest version of Nmap can be obtained from +<ulink url="https://nmap.org" />. The newest version of this man page +is available at <ulink url="https://nmap.org/book/man.html"/>. +<notbook>It is also included as a chapter of <web><ulink url="https://nmap.org/book/"><citetitle>Nmap Network Scanning: The Official Nmap Project Guide to Network Discovery and Security Scanning</citetitle></ulink>.</web><notweb><citetitle>Nmap Network Scanning: The Official Nmap Project Guide to Network Discovery and Security Scanning</citetitle> (see <ulink url="https://nmap.org/book/"/>).</notweb></notbook> +</para> + + </refsect1> + + <refsect1 id='man-briefoptions'> + <title>Options Summary</title> + +<para>This options summary is printed when Nmap is run +with no arguments, and the latest version is always available at +<ulink url="https://svn.nmap.org/nmap/docs/nmap.usage.txt" />. +It helps people remember the most common options, but is no +substitute for the in-depth documentation in the rest of this +manual. Some obscure options aren't even included here.</para> + +<!-- sortas="#" puts it before the entries that start with '-' in the options + section. --> +<indexterm class="startofrange" id="nmap-usage-indexterm"><primary sortas="#">summary of options</primary></indexterm> +<indexterm class="startofrange" id="nmap-usage-nmap-indexterm"><primary>command-line options</primary><secondary>of Nmap</secondary></indexterm> +&nmap-usage; +<indexterm class="endofrange" startref="nmap-usage-nmap-indexterm"/> +<indexterm class="endofrange" startref="nmap-usage-indexterm"/> + + </refsect1> + + <refsect1 id='man-target-specification'> + <title>Target Specification</title> + <indexterm><primary>target specification</primary></indexterm> + +<para>Everything on the Nmap command-line that isn't an option (or +option argument) is treated as a target host specification. The +simplest case is to specify a target IP address or hostname for scanning.</para> + +<para>When a hostname is given as a target, it is + <firstterm>resolved</firstterm><indexterm><primary>DNS resolution</primary></indexterm> + via the Domain Name System (DNS) to determine the IP address to scan. If the + name resolves to more than one IP address, only the first one will be + scanned. To make Nmap scan all the resolved addresses instead of only the + first one, use the <option>--resolve-all</option> option. +</para> + +<para>Sometimes you wish to scan a whole network of adjacent hosts. For +this, Nmap supports CIDR-style<indexterm><primary>CIDR (Classless +Inter-Domain Routing)</primary></indexterm> addressing. You can append +<literal>/<replaceable>numbits</replaceable></literal> to an IP +address or hostname and Nmap will scan every IP address for which the +first <replaceable>numbits</replaceable> are the same as for the +reference IP or hostname given. For example, +<literal>192.168.10.0/24</literal> would scan the 256 hosts +between 192.168.10.0 +(binary: <literal>11000000 10101000 00001010 00000000</literal>) +and 192.168.10.255 +(binary: <literal>11000000 10101000 00001010 11111111</literal>), +inclusive. +<literal>192.168.10.40/24</literal> would scan exactly the same targets. Given +that the host +scanme.nmap.org<indexterm><primary>scanme.nmap.org</primary></indexterm> +is at the IP address 64.13.134.52, the specification +<literal>scanme.nmap.org/16</literal> would scan the 65,536 IP addresses +between 64.13.0.0 and 64.13.255.255. The smallest allowed value is +<literal>/0</literal>, which targets the whole Internet. The largest +value for IPv4 is <literal>/32</literal>, which scans just the named host or IP +address because all address bits are fixed. The largest value for IPv6 is +<literal>/128</literal>, which does the same thing.</para> + +<indexterm><primary>address ranges</primary></indexterm> +<para>CIDR notation is short but not always flexible enough. For example, you +might want to scan 192.168.0.0/16 but skip any IPs ending with .0 or +.255 because they may be used as subnet network and broadcast addresses. Nmap supports +this through octet range addressing. Rather than specify a normal IP +address, you can specify a comma-separated list of numbers or ranges +for each octet. For example, <literal>192.168.0-255.1-254</literal> will skip all +addresses in the range that end in .0 or .255, and <literal>192.168.3-5,7.1</literal> will +scan the four addresses 192.168.3.1, 192.168.4.1, 192.168.5.1, and +192.168.7.1. Either side of a range may be omitted; the default values +are 0 on the left and 255 on the right. Using <literal>-</literal> by +itself is the same as <literal>0-255</literal>, but remember to use +<literal>0-</literal> in the first octet +so the target specification doesn't look like a command-line option. +Ranges need not be limited to the final octets: the specifier +<literal>0-255.0-255.13.37</literal> will perform an Internet-wide scan for all IP +addresses ending in 13.37. This sort of broad sampling can be useful +for Internet surveys and research.</para> + +<indexterm><primary>IPv6</primary></indexterm> +<para>IPv6 addresses can be specified by their fully qualified IPv6 +address or hostname or with CIDR notation for subnets. Octet ranges +aren't yet supported for IPv6.</para> + +<indexterm><primary>link-local IPv6 address</primary><see>IPv6 address, link-local</see></indexterm> +<indexterm><primary>IPv6 address</primary><secondary>link-local</secondary></indexterm> +<indexterm><primary>zone ID (IPv6 address)</primary></indexterm> +<para> +IPv6 addresses with non-global scope need to have a zone ID suffix. On +Unix systems, this is a percent sign followed by an interface name; a +complete address might be <literal>fe80::a8bb:ccff:fedd:eeff%eth0</literal>. +On Windows, use an interface index number in place of an interface name: +<literal>fe80::a8bb:ccff:fedd:eeff%1</literal>. You can see a list of +interface indexes by running the command +<command>netsh.exe interface ipv6 show interface</command>. +</para> + +<para>Nmap accepts multiple host specifications on the command line, +and they don't need to be the same type. The command <command>nmap +scanme.nmap.org 192.168.0.0/8 10.0.0,1,3-7.-</command> does what +you would expect.</para> + +<para>While targets are usually specified on the command lines, the following options are also available to control target selection:</para> + + <variablelist> + <varlistentry> + <term> + <option>-iL <replaceable>inputfilename</replaceable></option> (Input from list) + <indexterm><primary><option>-iL</option></primary></indexterm> + <indexterm><primary>target specification</primary><secondary>from list</secondary></indexterm> + </term> + <listitem> + <para>Reads target specifications from + <replaceable>inputfilename</replaceable>. Passing a huge + list of hosts is often awkward on the command line, yet it + is a common desire. For example, your DHCP server might + export a list of 10,000 current leases that you wish to + scan. Or maybe you want to scan all IP addresses + <emphasis>except</emphasis> for those to locate hosts using + unauthorized static IP addresses. Simply generate the list + of hosts to scan and pass that filename to Nmap as an + argument to the <option>-iL</option> option. Entries can be + in any of the formats accepted by Nmap on the command line + (IP address, hostname, CIDR, IPv6, or octet ranges). Each + entry must be separated by one or more spaces, tabs, or + newlines. You can specify a hyphen (<literal>-</literal>) + as the filename if you want Nmap to read hosts from standard + input rather than an actual file.</para> + <para>The input file may contain comments that start with + <literal>#</literal> and extend to the end of the line.</para> + </listitem> + </varlistentry> + + <varlistentry> + <term> + <option>-iR <replaceable>num hosts</replaceable></option> (Choose random targets) + <indexterm><primary><option>-iR</option></primary></indexterm> + <indexterm><primary>random targets</primary></indexterm> + <indexterm><primary>target specification</primary><secondary>at random</secondary></indexterm> + </term> + <listitem> + <para>For Internet-wide surveys + and other research, you may want to choose targets at + random. The <replaceable>num hosts</replaceable> argument + tells Nmap how many IPs to generate. Undesirable IPs such + as those in certain private, multicast, or unallocated + address ranges are automatically skipped. The argument <literal>0</literal> + can be specified for a never-ending scan. Keep in mind that + some network administrators bristle at unauthorized scans of + their networks and may complain. Use this option at your + own risk! If you find yourself really bored one rainy + afternoon, try the command + <command>nmap -Pn -sS -p 80 -iR 0 --open</command><indexterm><primary><option>-sS</option></primary><secondary>example of</secondary></indexterm><indexterm><primary><option>-PS</option></primary><secondary>example of</secondary></indexterm><indexterm><primary><option>-iR</option></primary><secondary>example of</secondary></indexterm><indexterm><primary><option>--open</option></primary><secondary>example of</secondary></indexterm> + to locate random web servers for browsing.</para> + </listitem> + </varlistentry> + + <varlistentry> + <term> + <option>--exclude + <replaceable>host1</replaceable><optional>,<replaceable>host2</replaceable><optional>,...</optional></optional></option> (Exclude hosts/networks) + <indexterm significance="preferred"><primary><option>--exclude</option></primary></indexterm> + <indexterm><primary>excluding targets</primary></indexterm> + </term> + <listitem> + <para>Specifies a comma-separated list of targets to be + excluded from the scan even if they are part of the overall + network range you specify. The list you pass in uses normal + Nmap syntax, so it can include hostnames, CIDR netblocks, + octet ranges, etc. This can be useful when the network you + wish to scan includes untouchable mission-critical servers, + systems that are known to react adversely to port scans, + or subnets administered by other people.</para> + </listitem> + </varlistentry> + + <varlistentry> + <term> + <option>--excludefile <replaceable>exclude_file</replaceable></option> (Exclude list from file) + <indexterm significance="preferred"><primary><option>--excludefile</option></primary></indexterm> + </term> + <listitem> + <para>This offers the same functionality as the <option>--exclude</option> + option, except that the excluded targets are provided in a + newline-, space-, or tab-delimited + <replaceable>exclude_file</replaceable> rather than on the + command line.</para> + <para>The exclude file may contain comments that start with + <literal>#</literal> and extend to the end of the line.</para> + </listitem> + </varlistentry> + + <varlistentry> + <term> + <option>-n</option> (No DNS resolution) + <indexterm><primary><option>-n</option></primary></indexterm> + </term> + <listitem> + + <para><indexterm><primary>reverse DNS</primary><secondary>disabling with <option>-n</option></secondary></indexterm> + Tells Nmap to <emphasis>never</emphasis> 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.</para> + </listitem> + </varlistentry> + + <varlistentry> + <term> + <option>-R</option> (DNS resolution for all targets) + <indexterm><primary><option>-R</option></primary></indexterm> + </term> + <listitem> + <para>Tells Nmap to + <emphasis>always</emphasis> do reverse DNS + resolution on the target IP addresses. Normally reverse DNS is + only performed against responsive (online) hosts.</para> + </listitem> + </varlistentry> + + <varlistentry> + <term> + <option>--resolve-all</option> (Scan each resolved address) + <indexterm><primary><option>--resolve-all</option></primary></indexterm> + </term> + <listitem> + <para>If a hostname target resolves to more than one address, scan + all of them. The default behavior is to only scan the first + resolved address. Regardless, only addresses in the appropriate + address family will be scanned: IPv4 by default, IPv6 with + <option>-6</option>. + </para> + </listitem> + </varlistentry> + + <varlistentry> + <term> + <option>--unique</option> (Scan each address only once) + <indexterm><primary><option>--unique</option></primary></indexterm> + </term> + <listitem> + <para>Scan each IP address only once. The default behavior is to scan + each address as many times as it is specified in the target list, + such as when network ranges overlap or different hostnames resolve + to the same address. + </para> + </listitem> + </varlistentry> + + <varlistentry> + <term> + <option>--system-dns</option> (Use system DNS resolver) + <indexterm significance="preferred"><primary><option>--system-dns</option></primary></indexterm> + </term> + <listitem> + + <para>By default, Nmap reverse-resolves IP addresses by sending + queries directly to the name servers configured on your host + and then listening for responses. Many requests (often + dozens) are performed in parallel to improve performance. + Specify this option to use your system resolver instead (one + IP at a time via the <function>getnameinfo</function> call). This is slower + and rarely useful unless you find a bug in the Nmap parallel + resolver (please let us know if you do). The system + resolver is always used for forward lookups (getting an IP address from a hostname). + </para> + </listitem> + </varlistentry> + + <varlistentry> + <term> + <option>--dns-servers <replaceable>server1</replaceable><optional>,<replaceable>server2</replaceable><optional>,...</optional></optional> + </option> (Servers to use for reverse DNS queries) + <indexterm significance="preferred"><primary><option>--dns-servers</option></primary></indexterm> + </term> + <listitem> + + <para>By default, Nmap determines your DNS servers + (for rDNS resolution) from your resolv.conf file (Unix) or + the Registry (Win32). Alternatively, you may use this + option to specify alternate servers. This option is not + honored if you are using <option>--system-dns</option>. + Using multiple DNS servers is often faster, + especially if you choose authoritative servers for your + target IP space. This option can also improve stealth, as + your requests can be bounced off just about any recursive + DNS server on the Internet.</para> + + <para>This option also comes in handy when scanning private + networks. Sometimes only a few name servers provide + proper rDNS information, and you may not even know where + they are. You can scan the network for port 53 (perhaps + with version detection), then try Nmap list scans + (<option>-sL</option>) specifying each name server one at a + time with <option>--dns-servers</option> until you find one + which works.</para> + + <para>This option might not be honored if the DNS response + exceeds the size of a UDP packet. In such a situation our DNS + resolver will make the best effort to extract a response from the + truncated packet, and if not successful it will fall back to + using the system resolver. Also, responses that contain CNAME aliases + will fall back to the system resolver.</para> + + </listitem> + </varlistentry> + </variablelist> + </refsect1> + + <refsect1 id='man-host-discovery'> + <title>Host Discovery</title> + <indexterm class="startofrange" id="man-host-discovery-indexterm"><primary>host discovery</primary></indexterm> + + <para>One of the very first steps in any network reconnaissance + mission is to reduce a (sometimes huge) set of IP ranges into a + list of active or interesting hosts. Scanning every port of + every single IP address is slow and usually unnecessary. Of + course what makes a host interesting depends greatly on the + scan purposes. Network administrators may only be interested in + hosts running a certain service, while security auditors may + care about every single device with an IP address. An + administrator may be comfortable using just an ICMP ping to + locate hosts on his internal network, while an external + penetration tester may use a diverse set of dozens of probes in + an attempt to evade firewall restrictions.</para> + + <para>Because host discovery needs are so diverse, Nmap offers a + wide variety of options for customizing the techniques used. Host + discovery is sometimes called ping scan, but it goes well beyond + the simple ICMP echo request packets associated with the + ubiquitous <application>ping</application> tool. Users can skip + the discovery step entirely with a list scan (<option>-sL</option>) or + by disabling host discovery (<option>-Pn</option>), or engage the network + with arbitrary combinations of multi-port TCP SYN/ACK, UDP, SCTP + INIT and ICMP probes. The goal of these probes is to solicit + responses which demonstrate that an IP address is actually active + (is being used by a host or network device). On many networks, + only a small percentage of IP addresses are active at any given + time. This is particularly common with private address space + such as 10.0.0.0/8. That network has 16 million IPs, but I have + seen it used by companies with less than a thousand machines. Host + discovery can find those machines in a sparsely allocated sea of + IP addresses.</para> + + <para>If no host discovery options are given, Nmap sends an ICMP + echo request, a TCP SYN packet to port 443, a TCP ACK packet to + port 80, and an ICMP timestamp request. (For IPv6, the ICMP + timestamp request is omitted because it is not part of ICMPv6.) + These defaults are + equivalent to the <option>-PE -PS443 -PA80 -PP</option> options. + The exceptions to this are the ARP<indexterm><primary>ARP ping</primary></indexterm> + (for IPv4) and Neighbor + Discovery<indexterm><primary>Neighbor Discovery</primary><secondary>for host discovery</secondary></indexterm> + (for IPv6) + scans which are used for any targets on a local ethernet network. + For unprivileged Unix shell + users, the default probes are a SYN packet to ports 80 and 443 using + the <function>connect</function> system + call.<indexterm><primary>unprivileged users</primary><secondary>limitations of</secondary></indexterm> + This host discovery is often sufficient when scanning local + networks, but a more comprehensive set of discovery probes is + recommended for security auditing.</para> + + <para>The <option>-P*</option> options (which select + ping types) can be combined. You can increase your odds of + penetrating strict firewalls by sending many probe types using + different TCP ports/flags and ICMP codes. Also note that + ARP/Neighbor Discovery<indexterm><primary>ARP ping</primary></indexterm> + is done by default against + targets on a local Ethernet network even if you specify other + <option>-P*</option> options, because it is almost always faster + and more effective.</para> + + <para>By default, Nmap does host discovery and then performs a + port scan against each host it determines is online. This is true + even if you specify non-default host discovery types such as UDP + probes (<option>-PU</option>). Read about the + <option>-sn</option> option to learn how to perform + only host discovery, or use <option>-Pn</option> to skip host + discovery and port scan all target addresses. The following options + control host discovery:</para> + + <variablelist> + + <varlistentry> + <term> + <option>-sL</option> (List Scan) + <indexterm><primary><option>-sL</option></primary></indexterm> + <indexterm><primary>list scan</primary></indexterm> + </term> + <listitem> + <para>The list scan is a degenerate form of host discovery + that simply lists each host of the network(s) specified, + without sending any packets to the target hosts. By + default, Nmap still does reverse-DNS resolution on the hosts + to learn their names. It is often surprising how much + useful information simple hostnames give out. For example, + <literal>fw.chi</literal> is the name of one company's Chicago firewall. + <indexterm><primary>DNS</primary><secondary>records as source of information</secondary></indexterm> + Nmap also reports the total number of + IP addresses at the end. The list scan is a good sanity + check to ensure that you have proper IP addresses for your + targets. If the hosts sport domain names you do not + recognize, it is worth investigating further to prevent + scanning the wrong company's network.</para> + + <para>Since the idea is to simply print a list of target + hosts, options for higher level functionality such as port + scanning, OS detection, or host discovery cannot be combined + with this. If you wish to disable host discovery while still + performing such higher level functionality, read up on the + <option>-Pn</option> (skip host discovery) option.</para> + </listitem> + </varlistentry> + + <varlistentry> + <term> + <option>-sn</option> (No port scan) + <indexterm><primary><option>-sn</option></primary></indexterm> + <indexterm><primary>host discovery</primary></indexterm> + <indexterm><primary>ping scan</primary></indexterm> + <indexterm><primary>port scan</primary><secondary>disabling with <option>-sn</option></secondary></indexterm> + </term> + <listitem> + <para>This option tells Nmap not to do a port scan after host + discovery, and only print out the available hosts that + responded to the host discovery probes. This is often known as a <quote>ping + scan</quote>, but you can also request that traceroute and + NSE host scripts be run. This is by default + one step more intrusive than the list scan, and can often + be used for the same purposes. It allows light + reconnaissance of a target network without attracting much + attention. Knowing how many hosts are up is more valuable + to attackers than the list provided by list scan of every + single IP and host name.</para> + + <para>Systems administrators often find this option + valuable as well. It can easily be used to count available + machines on a network or monitor server availability. This + is often called a ping sweep, and is more reliable than + pinging the broadcast address because many hosts do not + reply to broadcast queries.</para> + + <para>The default host discovery done with <option>-sn</option> consists of an ICMP echo + request, TCP SYN to port 443, TCP ACK to port 80, and an ICMP + timestamp request by default. When + executed by an unprivileged user, only SYN packets are sent + (using a <function>connect</function> call) to ports 80 and 443 on + the target. When a privileged user tries to scan targets + on a local ethernet network, ARP requests + are used unless + <option>--send-ip</option> was specified. + The <option>-sn</option> option can be combined with any of the + discovery probe types (the <option>-P*</option> options) for greater flexibility. + If any of those probe type and port number options are + used, the default probes are + overridden. When strict firewalls are in place between the + source host running Nmap and the target network, using + those advanced techniques is recommended. Otherwise hosts + could be missed when the firewall drops probes or their + responses.</para> + + <para>In previous releases of Nmap, <option>-sn</option> was + known as + <option>-sP</option>.<indexterm><primary><option>-sP</option></primary><seealso><option>-sn</option></seealso></indexterm></para> + + </listitem> + </varlistentry> + + + <varlistentry> + <term> + <option>-Pn</option> (No ping) + <indexterm><primary><option>-Pn</option></primary></indexterm> + <indexterm><primary>host discovery</primary><secondary>disabling</secondary></indexterm> + </term> + <listitem> + <para>This option skips the host discovery stage altogether. + Normally, Nmap uses this stage to determine active machines + for heavier scanning and to gauge the speed of the network. + By default, Nmap only performs heavy + probing such as port scans, version detection, or OS + detection against hosts that are found to be up. Disabling + host discovery with <option>-Pn</option> causes Nmap to + attempt the requested scanning functions against + <emphasis>every</emphasis> target IP address specified. So + if a /16 sized network is specified + on the command line, all 65,536 IP addresses are scanned. + Proper host discovery is skipped as with the list scan, but + instead of stopping and printing the target list, Nmap + continues to perform requested functions as if each target + IP is active. Default timing parameters are used, which may result in + slower scans. To skip host discovery <emphasis>and</emphasis> port + scan, while still allowing NSE to run, use the two options + <option>-Pn -sn</option> together.</para> + + <para>For machines on a local ethernet network, ARP + scanning will still be performed (unless + <option>--disable-arp-ping</option> or <option>--send-ip</option> is specified) because Nmap needs + MAC addresses to further scan target hosts. In previous + versions of Nmap, <option>-Pn</option> was + <option>-P0</option><indexterm><primary><option>-P0</option></primary><seealso><option>-Pn</option></seealso></indexterm> + and + <option>-PN</option>.<indexterm><primary><option>-PN</option></primary><seealso><option>-Pn</option></seealso></indexterm> + </para> + </listitem> + </varlistentry> + + <varlistentry> + <term> + <option>-PS <replaceable>port list</replaceable></option> (TCP SYN Ping) + <indexterm><primary><option>-PS</option></primary></indexterm> + <indexterm><primary>SYN ping</primary></indexterm> + </term> + <listitem> + + <para>This option sends an empty TCP packet with the SYN + flag set. The default destination port is 80 (configurable + at compile time by changing <varname>DEFAULT_TCP_PROBE_PORT_SPEC</varname><indexterm><primary><varname>DEFAULT_TCP_PROBE_PORT_SPEC</varname></primary></indexterm> + in <filename>nmap.h</filename>).<indexterm><primary><filename>nmap.h</filename></primary></indexterm> + Alternate ports can be + specified as a parameter. The syntax is the same as for the + <option>-p</option> except that port type specifiers like + <literal>T:</literal> are not allowed. Examples are + <option>-PS22</option> and + <option>-PS22-25,80,113,1050,35000</option>. Note that there + can be no space between <option>-PS</option> and the port + list. If multiple probes are specified they will be sent in + parallel.</para> + + <para>The SYN flag suggests to the remote system that you + are attempting to establish a connection. Normally the + destination port will be closed, and a RST (reset) packet + sent back. If the port happens to be open, the target will + take the second step of a TCP + three-way-handshake<indexterm><primary>three-way handshake</primary></indexterm> + by responding + with a SYN/ACK TCP packet. The machine running Nmap then + tears down the nascent connection by responding with a RST + rather than sending an ACK packet which would complete the + three-way-handshake and establish a full + connection. The RST packet is sent by the + kernel of the machine running Nmap in response to the + unexpected SYN/ACK, not by Nmap itself.</para> + + <para>Nmap does not care whether the port is open or closed. + Either the RST or SYN/ACK response discussed previously tell + Nmap that the host is available and responsive.</para> + + <para>On Unix boxes, only the privileged user + <literal>root</literal><indexterm><primary>privileged users</primary></indexterm> + is generally able to send and receive + raw TCP packets.<indexterm><primary>raw packets</primary></indexterm> + For unprivileged users, a + workaround is automatically employed<indexterm><primary>unprivileged users</primary><secondary>limitations of</secondary></indexterm> + whereby the <function>connect</function> system call is initiated against each + target port. This has + the effect of sending a SYN packet to the target host, in an + attempt to establish a connection. If <function>connect</function> returns + with a quick success or an ECONNREFUSED failure, the + underlying TCP stack must have received a SYN/ACK or RST and + the host is marked available. If the connection attempt + is left hanging until a timeout is reached, the host is + marked as down. + </para> + + </listitem> + </varlistentry> + + <varlistentry> + <term> + <option>-PA <replaceable>port list</replaceable></option> (TCP ACK Ping) + <indexterm><primary><option>-PA</option></primary></indexterm> + <indexterm><primary>ACK ping</primary></indexterm> + </term> + <listitem> + <para>The TCP ACK ping is quite similar to the + just-discussed SYN ping. The difference, as you could + likely guess, is that the TCP ACK flag is set instead of the + SYN flag. Such an ACK packet purports to be acknowledging + data over an established TCP connection, but no such + connection exists. So remote hosts should always respond + with a RST packet, disclosing their existence in the + process.</para> + + <para>The <option>-PA</option> option uses the same default + port as the SYN probe (80) and can also take a list of + destination ports in the same format. If an unprivileged + user tries this, the + <function>connect</function> workaround discussed previously is used. This + workaround is imperfect because <function>connect</function> is actually + sending a SYN packet rather than an ACK.</para> + + <para>The reason for offering both SYN and ACK ping probes + is to maximize the chances of bypassing firewalls. Many + administrators configure routers and other simple firewalls + to block incoming SYN packets except for those destined for + public services like the company web site or mail server. + This prevents other incoming connections to the + organization, while allowing users to make unobstructed + outgoing connections to the Internet. This non-stateful + approach takes up few resources on the firewall/router and + is widely supported by hardware and software filters. The + Linux Netfilter/iptables<indexterm><primary>iptables</primary></indexterm> + firewall software offers the + <option>--syn</option> convenience option to implement this + stateless approach. When stateless firewall rules such as + this are in place, SYN ping probes (<option>-PS</option>) + are likely to be blocked when sent to closed target ports. + In such cases, the ACK probe shines as it cuts right through + these rules.</para> + + <para>Another common type of firewall uses stateful rules + that drop unexpected packets. This feature was initially + found mostly on high-end firewalls, though it has become + much more common over the years. The Linux + Netfilter/iptables system supports this through the + <option>--state</option> option, which categorizes packets + based on connection state. A SYN probe is more likely to + work against such a system, as unexpected ACK packets are + generally recognized as bogus and dropped. A solution to this quandary is + to send both SYN and ACK probes by specifying + <option>-PS</option> and <option>-PA</option>.</para> + </listitem> + </varlistentry> + + <varlistentry> + <term> + <option>-PU <replaceable>port list</replaceable></option> (UDP Ping) + <indexterm><primary><option>-PU</option></primary></indexterm> + <indexterm><primary>UDP ping</primary></indexterm> + </term> + <listitem> + <indexterm><primary>payloads, protocol-specific</primary><see>protocol-specific payloads</see></indexterm> + + <para>Another host discovery option is the UDP ping, which + sends a UDP packet to the given ports. For most ports, the + packet will be empty, though some use a protocol-specific + payload that is more likely to elicit a + response. + <indexterm><primary>protocol-specific payloads</primary><secondary>UDP</secondary></indexterm> + The payloads are the same probes used in service and version + detection and are defined in the + <filename>nmap-service-probes</filename> + <indexterm><primary><filename>nmap-service-probes</filename></primary></indexterm> + file. Packet content can also be affected with the + <option>--data</option>, <option>--data-string</option>, and + <option>--data-length</option> options.</para> + + <para>The port list + takes the same format as with the previously discussed + <option>-PS</option> and <option>-PA</option> options. If + no ports are specified, the default is + 40125.<indexterm><primary>UDP scan</primary><secondary>default port of</secondary></indexterm> + This default + can be configured at compile-time by changing + <varname>DEFAULT_UDP_PROBE_PORT_SPEC</varname><indexterm><primary><varname>DEFAULT_UDP_PROBE_PORT_SPEC</varname></primary></indexterm> + in <filename>nmap.h</filename>.<indexterm><primary><filename>nmap.h</filename></primary></indexterm> + A highly uncommon port is used by default because sending to + open ports is often undesirable for this particular scan + type.</para> + + <para>Upon hitting a closed port on the target machine, the + UDP probe should elicit an ICMP port unreachable packet in + return. This signifies to Nmap that the machine is up and + available. Many other types of ICMP errors, such as + host/network unreachables or TTL exceeded are indicative of + a down or unreachable host. A lack of response is also + interpreted this way. If an open port is reached, most + services simply ignore the empty packet and fail to return + any response. This is why the default probe port is 40125, + which is highly unlikely to be in use. A few services, such + as the Character Generator (chargen) protocol, will respond to an empty UDP packet, and thus + disclose to Nmap that the machine is available.</para> + + <para>The primary advantage of this scan type is that it + bypasses firewalls and filters that only screen TCP. For + example, I once owned a Linksys BEFW11S4 wireless broadband + router. The external interface of this device filtered all + TCP ports by default, but UDP probes would still elicit port + unreachable messages and thus give away the device.</para> + + </listitem> + </varlistentry> + + <varlistentry> + <term> + <option>-PY <replaceable>port list</replaceable></option> (SCTP INIT Ping) + <indexterm><primary><option>-PY</option></primary></indexterm> + <indexterm><primary>SCTP INIT ping</primary></indexterm> + </term> + <listitem> + + <para>This option sends an SCTP packet containing a minimal + INIT chunk. The default destination port is 80 (configurable + at compile time by changing + <varname>DEFAULT_SCTP_PROBE_PORT_SPEC</varname><indexterm><primary><varname>DEFAULT_SCTP_PROBE_PORT_SPEC</varname></primary></indexterm> + in <filename>nmap.h</filename>). + Alternate ports can be specified as a parameter. The syntax + is the same as for the + <option>-p</option> except that port type specifiers like + <literal>S:</literal> are not allowed. Examples are + <option>-PY22</option> and + <option>-PY22,80,179,5060</option>. Note that there + can be no space between <option>-PY</option> and the port + list. If multiple probes are specified they will be sent in + parallel.</para> + + <para>The INIT chunk suggests to the remote system that you + are attempting to establish an association. Normally the + destination port will be closed, and an ABORT chunk will be + sent back. If the port happens to be open, the target will + take the second step of an SCTP + four-way-handshake<indexterm><primary>four-way handshake</primary></indexterm> + by responding with an INIT-ACK chunk. If the machine running + Nmap has a functional SCTP stack, then it tears down the + nascent association by responding with an ABORT chunk rather + than sending a COOKIE-ECHO chunk which would be the next step + in the four-way-handshake. The ABORT packet is sent by the + kernel of the machine running Nmap in response to the + unexpected INIT-ACK, not by Nmap itself.</para> + + <para>Nmap does not care whether the port is open or closed. + Either the ABORT or INIT-ACK response discussed previously tell + Nmap that the host is available and responsive.</para> + + <para>On Unix boxes, only the privileged user + <literal>root</literal><indexterm><primary>privileged users</primary></indexterm> + is generally able to send and receive raw SCTP + packets.<indexterm><primary>raw packets</primary></indexterm> + Using SCTP INIT Pings is currently not possible for unprivileged + users.<indexterm><primary>unprivileged users</primary><secondary>limitations of</secondary></indexterm> + </para> + + </listitem> + </varlistentry> + + <varlistentry> + <term> + <option>-PE</option>; + <option>-PP</option>; + <option>-PM</option> (ICMP Ping Types) + <indexterm><primary><option>-PE</option></primary></indexterm> + <indexterm><primary><option>-PP</option></primary></indexterm> + <indexterm><primary><option>-PM</option></primary></indexterm> + <indexterm><primary>ICMP ping</primary></indexterm> + </term> + <listitem> + + <para>In addition to the unusual TCP, UDP and SCTP host + discovery types discussed previously, Nmap can send the + standard packets sent by the ubiquitous + <application>ping</application> program. Nmap sends an ICMP + type 8 (echo request) packet to the target IP addresses, + expecting a type 0 (echo reply) in return from available + hosts.<indexterm><primary>ICMP echo</primary></indexterm> + Unfortunately for network explorers, many hosts and + firewalls now block these packets, rather than responding as + required by <ulink + role="hidepdf" url="http://www.rfc-editor.org/rfc/rfc1122.txt">RFC + 1122</ulink>.<indexterm><primary>RFC 1122</primary></indexterm> + For this reason, ICMP-only scans are rarely + reliable enough against unknown targets over the Internet. + But for system administrators monitoring an internal + network, they can be a practical and efficient approach. + Use the <option>-PE</option> option to enable this echo + request behavior.</para> + + <para>While echo request is the standard ICMP ping query, + Nmap does not stop there. The ICMP standards + (<ulink role="hidepdf" url="http://www.rfc-editor.org/rfc/rfc792.txt">RFC 792</ulink><indexterm><primary>RFC 792</primary></indexterm> + and + <ulink role="hidepdf" url="http://www.rfc-editor.org/rfc/rfc950.txt">RFC 950</ulink><indexterm><primary>RFC 950</primary></indexterm> + ) + also specify timestamp request, information + request, and address mask request packets as codes 13, 15, + and 17, respectively. While the ostensible purpose for + these queries is to learn information such as address masks + and current times, they can easily be used for host + discovery. A system that replies is up and available. Nmap + does not currently implement information request packets, as + they are not widely supported. RFC 1122 insists that + <quote>a host SHOULD NOT implement these messages</quote>. + Timestamp and address mask queries can be sent with the + <option>-PP</option> and <option>-PM</option> options, + respectively. A timestamp reply (ICMP code 14) or address + mask reply (code 18) discloses that the host is available. + These two queries can be valuable when administrators specifically + block echo request packets while forgetting that other ICMP + queries can be used for the same purpose.</para> + + </listitem> + </varlistentry> + + <varlistentry> + <term> + <option>-PO <replaceable>protocol list</replaceable></option> (IP Protocol Ping) + <indexterm><primary><option>-PO</option></primary></indexterm> + <indexterm><primary>IP protocol ping</primary></indexterm> + </term> + <listitem> + + <para>One of the newer host discovery options is the IP protocol ping, + which sends IP packets with the specified protocol number + set in their IP header. The protocol list + takes the same format as do port lists in the + previously discussed TCP, UDP and SCTP host discovery options. + If no protocols are specified, the default is to send multiple + IP packets for ICMP (protocol 1), IGMP (protocol 2), and + IP-in-IP (protocol 4). The default protocols can be + configured at compile-time by changing + <varname>DEFAULT_PROTO_PROBE_PORT_SPEC</varname><indexterm><primary><varname>DEFAULT_PROTO_PROBE_PORT_SPEC</varname></primary></indexterm> + in <filename>nmap.h</filename>. + Note that for the ICMP, IGMP, TCP (protocol 6), UDP + (protocol 17) and SCTP (protocol 132), the packets are sent + with the proper protocol + headers<indexterm><primary>protocol-specific payloads</primary><secondary>IP</secondary></indexterm> + while other protocols are + sent with no additional data beyond the IP header (unless any of + <option>--data</option>, + <option>--data-string</option>, or + <option>--data-length</option> + options are specified).</para> + + <para>This host discovery method looks for either responses + using the same protocol as a probe, or ICMP protocol + unreachable messages which signify that the given protocol + isn't supported on the destination host. Either type of + response signifies that the target host is alive.</para> + + </listitem> + </varlistentry> + + <varlistentry> + <term> + <option>--disable-arp-ping</option> (No ARP or ND Ping) + <indexterm><primary><option>--disable-arp-ping</option></primary></indexterm> + </term> + <listitem> + + <para>Nmap normally does ARP or IPv6 Neighbor Discovery (ND) + discovery of locally connected ethernet hosts, even if other + host discovery options such as <option>-Pn</option> or + <option>-PE</option> are used. To disable this implicit + behavior, use the <option>--disable-arp-ping</option> + option.</para> + + <para>The default behavior is normally faster, but this option + is useful on networks using proxy ARP, in which a router + speculatively replies to all ARP requests, making every target + appear to be up according to ARP scan.</para> + + </listitem> + </varlistentry> + <varlistentry> + <term> + <option>--discovery-ignore-rst</option> + <indexterm><primary><option>--discovery-ignore-rst</option></primary></indexterm> + </term> + <listitem> + + <para>In some cases, firewalls may spoof TCP reset (RST) replies in + response to probes to unoccupied or disallowed addresses. Since + Nmap ordinarily considers RST replies to be proof that the target + is up, this can lead to wasted time scanning targets that aren't + there. Using the <option>--discovery-ignore-rst</option> will + prevent Nmap from considering these replies during host discovery. + You may need to select extra host discovery options to ensure you + don't miss targets in this case.</para> + </listitem> + </varlistentry> + +<varlistentry> + <term> + <option>--traceroute</option> (Trace path to host) + <indexterm significance="preferred"><primary><option>--traceroute</option></primary></indexterm> + <indexterm significance="preferred"><primary>traceroute</primary></indexterm> + </term> + <listitem> + +<para> +Traceroutes are performed post-scan using information from the scan results to determine the port and protocol most likely to reach the target. It works with all scan types except connect scans (<option>-sT</option>) and idle scans (<option>-sI</option>). All traces use Nmap's dynamic timing model and are performed in parallel. +</para> + +<para> +Traceroute works by sending packets with a low TTL (time-to-live) in an attempt to elicit ICMP Time Exceeded messages from intermediate hops between the scanner and the target host. Standard traceroute implementations start with a TTL of 1 and increment the TTL until the destination host is reached. Nmap's traceroute starts with a high TTL and then decrements the TTL until it reaches zero. Doing it backwards lets Nmap employ clever caching algorithms to speed up traces over multiple hosts. On average Nmap sends 5–10 fewer packets per host, depending on network conditions. If a single subnet is being scanned (i.e. 192.168.0.0/24) Nmap may only have to send two packets to most hosts. +</para> +</listitem> +</varlistentry> + </variablelist> + <indexterm class="endofrange" startref="man-host-discovery-indexterm"/> + </refsect1> + + <refsect1 id='man-port-scanning-basics'> + <title>Port Scanning Basics</title> + + <para>While Nmap has grown in functionality over the years, + it began as an efficient port scanner, and that remains its + core function. The simple command <command>nmap + <replaceable>target</replaceable></command> scans + 1,000 TCP ports on the host + <replaceable>target</replaceable>. While many port scanners + have traditionally lumped all ports into the open or closed + states, Nmap is much more granular. It divides ports into + six states: <literal>open</literal>, + <literal>closed</literal>, <literal>filtered</literal>, + <literal>unfiltered</literal>, + <literal>open|filtered</literal>, or + <literal>closed|filtered</literal>.</para> + +<para>These states are not intrinsic +properties of the port itself, but describe how Nmap sees them. For +example, an Nmap scan from the same network as the target may show +port <literal>135/tcp</literal> as open, while a scan at the same time with the same +options from across the Internet might show that port as <literal>filtered</literal>.</para> + +<variablelist><title>The six port states recognized by Nmap</title> + + <varlistentry><term>open + <indexterm><primary><literal>open</literal> port state</primary></indexterm> + </term> + <listitem><para>An application is actively accepting TCP + connections, UDP datagrams or SCTP associations on this port. + Finding these is often the primary goal of port scanning. + Security-minded people know that each open port is an avenue for attack. + Attackers and pen-testers want to exploit the open ports, while + administrators try to close or protect them with firewalls without + thwarting legitimate users. + Open ports are also interesting for non-security scans because they show + services available for use on the network. + </para></listitem></varlistentry> + + <varlistentry><term>closed + <indexterm><primary><literal>closed</literal> port state</primary></indexterm> + </term> + + <listitem><para>A closed port is accessible (it receives and + responds to Nmap probe packets), but there is no application + listening on it. They can be helpful in showing that a host is up + on an IP address (host discovery, or ping scanning), and as part + of OS detection. Because closed ports are reachable, it may be + worth scanning later in case some open up. Administrators may want + to consider blocking such ports with a firewall. Then they would + appear in the filtered state, discussed next. + </para></listitem></varlistentry> + + <varlistentry><term>filtered + <indexterm><primary><literal>filtered</literal> port state</primary></indexterm> + </term> + + <listitem><para>Nmap cannot determine whether the port is open + because packet filtering prevents its probes from reaching the port. + The filtering could be from a dedicated firewall device, router + rules, or host-based firewall software. These ports frustrate + attackers because they provide so little information. Sometimes + they respond with ICMP error messages such as type 3 code 13 + (destination unreachable: communication administratively + prohibited), but filters that simply drop probes without responding + are far more common. This forces Nmap to retry several times just + in case the probe was dropped due to network congestion rather than + filtering. This slows down the scan dramatically.</para></listitem></varlistentry> + + <varlistentry><term>unfiltered + <indexterm><primary><literal>unfiltered</literal> port state</primary></indexterm> + </term> + <listitem><para>The unfiltered state means that a port is accessible, + but Nmap is unable to determine whether it is open or closed. Only + the ACK scan, which is used to map firewall rulesets, classifies + ports into this state. Scanning unfiltered ports with other scan + types such as Window scan, SYN scan, or FIN scan, may help resolve + whether the port is open. + </para></listitem></varlistentry> + + <varlistentry><term>open|filtered + <indexterm><primary><literal>open|filtered</literal> port state</primary></indexterm> + </term> + <listitem><para>Nmap places ports in this state when it is unable to + determine whether a port is open or filtered. This occurs for scan + types in which open ports give no response. The lack of + response could also mean that a packet filter dropped the probe or + any response it elicited. So Nmap does not know for sure whether + the port is open or being filtered. The UDP, IP protocol, + FIN, NULL, and Xmas scans classify ports this + way.</para></listitem></varlistentry> + + <varlistentry><term>closed|filtered + <indexterm><primary><literal>closed|filtered</literal> port state</primary></indexterm> + </term> + <listitem><para>This state is used when Nmap is unable to determine + whether a port is closed or filtered. It is only used for the IP ID + idle scan.</para></listitem></varlistentry> + </variablelist> +</refsect1> + +<refsect1 id='man-port-scanning-techniques'> + <title>Port Scanning Techniques</title> + +<para>As a novice performing automotive repair, I can struggle +for hours trying to fit my rudimentary tools (hammer, duct tape, +wrench, etc.) to the task at hand. When I fail miserably and tow my +jalopy to a real mechanic, he invariably fishes around in a huge tool chest until +pulling out the perfect gizmo which makes the job seem effortless. The +art of port scanning is similar. Experts understand the dozens of +scan techniques and choose the appropriate one (or combination) for a +given task. Inexperienced users and +script kiddies,<indexterm><primary>script kiddies</primary></indexterm> +on the other +hand, try to solve every problem with the default SYN scan. Since Nmap is +free, the only barrier to port scanning mastery is knowledge. That +certainly beats the automotive world, where it may take great skill to +determine that you need a strut spring compressor, then you still +have to pay thousands of dollars for it.</para> + +<para>Most of the scan types are only available to +privileged users.<indexterm><primary>privileged users</primary></indexterm> +This is because they send and receive +raw packets,<indexterm><primary>raw packets</primary></indexterm> +which requires root +access on Unix systems. Using an administrator account on Windows is +recommended, though Nmap sometimes works for unprivileged users on that +platform when Npcap has already been loaded into the OS. Requiring +root privileges was a serious limitation when Nmap was released in +1997, as many users only had access to shared shell accounts. Now, +the world is different. Computers are cheaper, far more people have +always-on direct Internet access, and desktop Unix systems (including +Linux and Mac OS X) are prevalent. A Windows version of Nmap is now +available, allowing it to run on even more desktops. For all these +reasons, users have less need to run Nmap from limited shared shell accounts. +This is fortunate, as the privileged options make Nmap far more +powerful and flexible.</para> + +<para>While Nmap attempts to produce accurate results, keep in mind +that all of its insights are based on packets returned by the target +machines (or firewalls in front of them). Such hosts may be +untrustworthy and send responses intended to confuse or mislead Nmap. +Much more common are non-RFC-compliant hosts that do not respond as +they should to Nmap probes. FIN, NULL, and Xmas scans are +particularly susceptible to this problem. Such issues are specific to +certain scan types and so are +discussed in the individual scan type entries.</para> + +<para>This section documents the dozen or so port scan +techniques supported by Nmap. Only one method may be used at a time, +except that UDP scan (<option>-sU</option>) and any one of the +SCTP scan types (<option>-sY</option>, <option>-sZ</option>) +may be combined with any one of the TCP scan types. +As a memory aid, port scan type options +are of the form <option>-s<replaceable>C</replaceable></option>, where +<replaceable>C</replaceable> is a prominent character in the scan +name, usually the first. The one exception to this is the deprecated +FTP bounce scan (<option>-b</option>). By default, Nmap performs a +SYN Scan, though it substitutes a connect scan if the user does not +have proper privileges to send raw packets (requires root access on +Unix). Of the scans listed in this +section, unprivileged users can only execute connect and FTP bounce +scans.</para> + + <variablelist> + <varlistentry> + <term> + <option>-sS</option> (TCP SYN scan) + <indexterm><primary><option>-sS</option></primary></indexterm> + <indexterm><primary>SYN scan</primary></indexterm> + </term> + <listitem> + +<para>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. It is also +relatively unobtrusive and stealthy since it never completes TCP +connections. SYN scan 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 <literal>open</literal>, +<literal>closed</literal>, and <literal>filtered</literal> +states.</para> + +<para>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 0, 1, 2, 3, 9, 10, or 13) is received. The port is also considered open if a SYN packet (without the ACK flag) is received in response. This can be due to an extremely rare TCP feature known as a simultaneous open or split handshake connection (see <ulink url="https://nmap.org/misc/split-handshake.pdf"/>).</para> + + </listitem> + </varlistentry> + + <varlistentry> + <term> + <option>-sT</option> (TCP connect scan) + <indexterm><primary><option>-sT</option></primary></indexterm> + <indexterm><primary>connect scan</primary></indexterm> + </term> + <listitem> +<para>TCP connect scan is the default TCP scan type when SYN scan is +not an option. This is the case when a user does not have raw packet +privileges. Instead of writing raw +packets as most other scan types do, Nmap asks the underlying +operating system to establish a connection with the target machine and +port by issuing the <function>connect</function> system call. This is +the same high-level system call that web browsers, P2P clients, and +most other network-enabled applications use to establish a connection. +It is part of a programming interface known as the Berkeley Sockets +API. Rather than read raw packet responses off the wire, Nmap uses +this API to obtain status information on each connection attempt. +</para> + +<para>When SYN scan is available, it is usually a better choice. Nmap +has less control over the high level <function>connect</function> call +than with raw packets, making it less efficient. The system call +completes connections to open target ports rather than performing the +half-open reset that SYN scan does. Not only does this take longer +and require more packets to obtain the same information, but target +machines are more likely to log the connection. A decent IDS will +catch either, but most machines have no such alarm system. Many +services on your average Unix system will add a note to syslog, and +sometimes a cryptic error message, when Nmap connects and then closes +the connection without sending data. Truly pathetic services crash +when this happens, though that is uncommon. An administrator who sees +a bunch of connection attempts in her logs from a single system should +know that she has been connect scanned.</para> + + </listitem> + </varlistentry> + + <varlistentry> + <term> + <option>-sU</option> (UDP scans) +<indexterm><primary><option>-sU</option></primary></indexterm> +<indexterm><primary>UDP scan</primary></indexterm> +</term> + <listitem> + +<para>While most popular services on the Internet run over the TCP +protocol, <ulink +role="hidepdf" url="http://www.rfc-editor.org/rfc/rfc768.txt">UDP</ulink> services +are widely deployed. DNS, SNMP, and DHCP +(registered ports 53, 161/162, and 67/68) are three of the most +common. Because UDP scanning is generally slower and more difficult +than TCP, some security auditors ignore these ports. This is a mistake, as +exploitable UDP services are quite common and attackers certainly +don't ignore the whole protocol. Fortunately, Nmap can help inventory +UDP ports.</para> + +<para>UDP scan is activated with the <option>-sU</option> option. It +can be combined with a TCP scan type such as SYN scan +(<option>-sS</option>) to check both protocols during the same +run.</para> + +<para>UDP scan works by sending a UDP packet to every +targeted port. For some common ports such as 53 and 161, a +protocol-specific payload is sent to increase response rate, but for most ports the packet is +empty unless the <option>--data</option>, +<option>--data-string</option>, or <option>--data-length</option> +options are specified. +If an ICMP port unreachable error (type 3, code 3) is +returned, the port is <literal>closed</literal>. Other ICMP unreachable errors (type 3, +codes 0, 1, 2, 9, 10, or 13) mark the port as <literal>filtered</literal>. Occasionally, a +service will respond with a UDP packet, proving that it is <literal>open</literal>. If +no response is received after retransmissions, the port is classified +as <literal>open|filtered</literal>. This means that the port could be open, or perhaps +packet filters are blocking the communication. Version detection +(<option>-sV</option>) can be used to help differentiate the truly +open ports from the filtered ones.</para> + +<para>A big challenge with UDP scanning is doing it quickly. +Open and filtered ports rarely send any response, leaving Nmap to time +out and then conduct retransmissions just in case the probe or +response were lost. Closed ports are often an even bigger problem. +They usually send back an ICMP port unreachable error. But unlike the +RST packets sent by closed TCP ports in response to a SYN or connect +scan, many hosts rate limit<indexterm><primary>rate limiting</primary></indexterm> +ICMP port unreachable messages by default. +Linux and Solaris are particularly strict about this. For example, the +Linux 2.4.20 kernel limits destination unreachable messages to one per +second (in <filename>net/ipv4/icmp.c</filename>).</para> + +<para>Nmap detects rate limiting and slows down accordingly to avoid +flooding the network with useless packets that the target machine will +drop. Unfortunately, a Linux-style limit of one packet per second +makes a 65,536-port scan take more than 18 hours. Ideas for speeding +your UDP scans up include scanning more hosts in parallel, doing a +quick scan of just the popular ports first, scanning from behind the +firewall, and using <option>--host-timeout</option> to skip slow +hosts.</para> + + </listitem> + </varlistentry> + + <varlistentry> + <term> + <option>-sY</option> (SCTP INIT scan) +<indexterm><primary><option>-sY</option></primary></indexterm> +<indexterm><primary>SCTP INIT scan</primary></indexterm> +</term> + <listitem> + +<para> + <ulink role="hidepdf" url="http://www.rfc-editor.org/rfc/rfc4960.txt">SCTP</ulink> +is a relatively new alternative to the TCP and UDP protocols, +combining most characteristics of TCP and UDP, and also adding +new features like multi-homing and multi-streaming. It is mostly +being used for SS7/SIGTRAN related services but has the potential +to be used for other applications as well. + +SCTP INIT scan is the SCTP equivalent of a TCP SYN scan. +It can be performed quickly, scanning thousands of ports per +second on a fast network not hampered by restrictive firewalls. +Like SYN scan, INIT scan is relatively unobtrusive and stealthy, +since it never completes SCTP associations. It also allows clear, +reliable differentiation between the <literal>open</literal>, +<literal>closed</literal>, and <literal>filtered</literal> +states.</para> + +<para>This technique is often referred to as half-open scanning, +because you don't open a full SCTP association. You send an INIT +chunk, as if you are going to open a real association and then wait +for a response. An INIT-ACK chunk indicates the port is listening +(open), while an ABORT chunk 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 0, 1, 2, 3, 9, 10, or 13) is +received.</para> + + </listitem> + </varlistentry> + + <varlistentry> + <term> + <option>-sN</option>; <option>-sF</option>; <option>-sX</option> (TCP NULL, FIN, and Xmas scans) +<indexterm><primary><option>-sN</option></primary></indexterm> +<indexterm><primary><option>-sF</option></primary></indexterm> +<indexterm><primary><option>-sX</option></primary></indexterm> +<indexterm><primary>NULL scan</primary></indexterm> +<indexterm><primary>FIN scan</primary></indexterm> +<indexterm><primary>Xmas scan</primary></indexterm> +</term> + <listitem> + +<para>These three scan types (even more are possible with the +<option>--scanflags</option> option described in the next section) +exploit a subtle loophole in the <ulink +role="hidepdf" url="http://www.rfc-editor.org/rfc/rfc793.txt">TCP RFC</ulink> to +differentiate between <literal>open</literal> and +<literal>closed</literal> ports. Page 65 of RFC 793 says that <quote>if the +[destination] port state is CLOSED .... an incoming segment not +containing a RST causes a RST to be sent in response.</quote> Then the next +page discusses packets sent to open ports without the SYN, RST, or ACK +bits set, stating that: <quote>you are unlikely to get here, but if you do, drop the +segment, and return.</quote></para> + +<para>When scanning systems compliant with this RFC text, any packet +not containing SYN, RST, or ACK bits will result in a returned RST if +the port is closed and no response at all if the port is open. As +long as none of those three bits are included, any combination of the +other three (FIN, PSH, and URG) are OK. Nmap exploits this with three +scan types:</para> + +<variablelist> + <varlistentry><term>Null scan (<option>-sN</option>)</term> + <listitem><para>Does not set any bits (TCP flag header is 0)</para></listitem></varlistentry> + + <varlistentry><term>FIN scan (<option>-sF</option>)</term> + <listitem><para>Sets just the TCP FIN bit.</para></listitem></varlistentry> + + <varlistentry><term>Xmas scan (<option>-sX</option>)</term> + <listitem><para>Sets the FIN, PSH, and URG flags, lighting the + packet up like a Christmas tree.</para></listitem></varlistentry> +</variablelist> + +<para>These three scan types are exactly the same in behavior except +for the TCP flags set in probe packets. If a RST packet is received, +the port is considered <literal>closed</literal>, while no response +means it is <literal>open|filtered</literal>. The port is marked +<literal>filtered</literal> if an ICMP unreachable error (type 3, code +0, 1, 2, 3, 9, 10, or 13) is received.</para> + +<para>The key advantage to these scan types is that they can sneak +through certain non-stateful firewalls and packet filtering +routers. Another advantage is that these scan types are a little more +stealthy than even a SYN scan. Don't count on this though—most +modern IDS products can be configured to detect them. The big +downside is that not all systems follow RFC 793 to the letter. A +number of systems send RST responses to the probes regardless of +whether the port is open or not. This causes all of the ports to be +labeled <literal>closed</literal>. Major operating systems that do +this are Microsoft Windows, many Cisco devices, BSDI, and IBM OS/400. +This scan does work against most Unix-based systems though. Another +downside of these scans is that they can't distinguish <literal>open</literal> ports from +certain <literal>filtered</literal> ones, leaving you with the response +<literal>open|filtered</literal>.</para> + + </listitem> + </varlistentry> + + <varlistentry> + <term> + <option>-sA</option> (TCP ACK scan) + <indexterm><primary><option>-sA</option></primary></indexterm> + <indexterm><primary>ACK scan</primary></indexterm> + </term> + <listitem> + +<para>This scan is different than the others discussed so far in that +it never determines <literal>open</literal> (or even +<literal>open|filtered</literal>) ports. It is used to map out +firewall rulesets, determining whether they are stateful or not and +which ports are filtered.</para> + +<para>The ACK scan probe packet has only the ACK flag set (unless you +use <option>--scanflags</option>). When scanning unfiltered systems, +<literal>open</literal> and <literal>closed</literal> ports will both +return a RST packet. Nmap then labels them as +<literal>unfiltered</literal>, meaning that they are reachable by the +ACK packet, but whether they are <literal>open</literal> or +<literal>closed</literal> is undetermined. Ports that don't respond, +or send certain ICMP error messages back (type 3, code 0, 1, 2, 3, 9, 10, +or 13), are labeled <literal>filtered</literal>.</para> + + </listitem> + </varlistentry> + + <varlistentry> + <term> + <option>-sW</option> (TCP Window scan) +<indexterm><primary><option>-sW</option></primary></indexterm> +<indexterm><primary>window scan</primary></indexterm> +</term> + <listitem> + +<para>Window scan is exactly the same as ACK scan except that it +exploits an implementation detail of certain systems to differentiate +open ports from closed ones, rather than always printing +<literal>unfiltered</literal> when a RST is returned. It does this by +examining the TCP Window field of the RST packets returned. On some +systems, open ports use a positive window size (even for RST packets) +while closed ones have a zero window. So instead of always listing a +port as <literal>unfiltered</literal> when it receives a RST back, +Window scan lists the port as <literal>open</literal> or +<literal>closed</literal> if the TCP Window value in that reset is +positive or zero, respectively.</para> + +<para>This scan relies on an implementation detail of a minority of +systems out on the Internet, so you can't always trust it. Systems +that don't support it will usually return all ports +<literal>closed</literal>. Of course, it is possible that the machine +really has no open ports. If most scanned ports are +<literal>closed</literal> but a few common port numbers (such as 22, +25, 53) are <literal>filtered</literal>, the system is most likely +susceptible. Occasionally, systems will even show the exact opposite +behavior. If your scan shows 1,000 open ports and three closed or filtered +ports, then those three may very well be the truly open ones.</para> + + </listitem> + </varlistentry> + + <varlistentry> + <term> + <option>-sM</option> (TCP Maimon scan) +<indexterm><primary><option>-sM</option></primary></indexterm> +<indexterm><primary>Maimon scan</primary></indexterm> +</term> + <listitem> + +<para>The Maimon scan is named after its discoverer, +Uriel Maimon.<indexterm><primary>Maimon, Uriel</primary></indexterm> +He described the technique in +<citetitle>Phrack</citetitle> Magazine issue #49 (November 1996).<indexterm><primary><citetitle>Phrack</citetitle></primary></indexterm> +Nmap, which included this technique, was released two issues later. +This technique is exactly the same as NULL, FIN, and Xmas scans, except +that the probe is FIN/ACK. According to <ulink role="hidepdf" url="http://www.rfc-editor.org/rfc/rfc793.txt">RFC 793</ulink> (TCP), a RST packet +should be generated in response to such a probe whether the port is +open or closed. However, Uriel noticed that many BSD-derived systems +simply drop the packet if the port is open.</para> + + </listitem> + </varlistentry> + + <varlistentry> + <term> + <option>--scanflags</option> (Custom TCP scan) + <indexterm><primary><option>--scanflags</option></primary></indexterm></term> + <listitem> + + +<para>Truly advanced Nmap users need not limit themselves to the +canned scan types offered. The <option>--scanflags</option> option allows +you to design your own scan by specifying arbitrary +TCP flags.<indexterm><primary>TCP flags</primary></indexterm> +Let your creative juices flow, while evading +intrusion detection systems<indexterm><primary>intrusion detection systems</primary><secondary>evading</secondary></indexterm> +whose vendors simply paged through the Nmap man page adding specific rules!</para> + +<para>The <option>--scanflags</option> argument can be a numerical +flag value such as 9 (PSH and FIN), but using symbolic names is +easier. Just mash together any combination of <literal>URG</literal>, +<literal>ACK</literal>, <literal>PSH</literal>, +<literal>RST</literal>, <literal>SYN</literal>, and +<literal>FIN</literal>. For example, <option>--scanflags +URGACKPSHRSTSYNFIN</option> sets everything, though it's not very +useful for scanning. The order these are specified in is +irrelevant.</para> + +<para>In addition to specifying the desired flags, you can specify a +TCP scan type (such as <option>-sA</option> or <option>-sF</option>). +That base type tells Nmap how to interpret responses. For +example, a SYN scan considers no-response to indicate a +<literal>filtered</literal> port, while a FIN scan treats the same as +<literal>open|filtered</literal>. Nmap will behave the same way it +does for the base scan type, except that it will use the TCP flags you +specify instead. If you don't specify a base type, SYN scan is +used.</para> + + </listitem> + </varlistentry> + + <varlistentry> + <term> + <option>-sZ</option> (SCTP COOKIE ECHO scan) +<indexterm><primary><option>-sZ</option></primary></indexterm> +<indexterm><primary>SCTP COOKIE ECHO scan</primary></indexterm> +</term> + <listitem> + +<para> +SCTP COOKIE ECHO scan is a more advanced SCTP scan. It takes +advantage of the fact that SCTP implementations should silently +drop packets containing COOKIE ECHO chunks on open ports, but +send an ABORT if the port is closed. + +The advantage of this scan type is that it is not as obvious a +port scan than an INIT scan. Also, there may be non-stateful +firewall rulesets blocking INIT chunks, but not COOKIE ECHO +chunks. Don't be fooled into thinking that this will make a +port scan invisible; a good IDS will be able to detect SCTP +COOKIE ECHO scans too. + +The downside is that SCTP COOKIE ECHO scans cannot differentiate +between <literal>open</literal> and <literal>filtered</literal> +ports, leaving you with the state <literal>open|filtered</literal> +in both cases.</para> + + </listitem> + </varlistentry> + + <varlistentry> + <term> + <option>-sI <replaceable>zombie host</replaceable><optional>:<replaceable>probeport</replaceable></optional></option> (idle scan) + <indexterm><primary><option>-sI</option></primary></indexterm> + <indexterm><primary>idle scan</primary></indexterm> + </term> + + <listitem> + + <para>This advanced scan method allows for a truly blind TCP + port scan of the target (meaning no packets are sent to the + target from your real IP address). Instead, a unique + side-channel attack exploits predictable IP fragmentation ID + sequence generation on the zombie host to glean information + about the open ports on the target. IDS systems will + display the scan as coming from the zombie machine you + specify (which must be up and meet certain criteria). + <man> + This fascinating scan type is too complex to fully describe in this + reference guide, so I wrote and posted an informal paper with full + details at <ulink url="https://nmap.org/book/idlescan.html" />. + </man> + <notman> + Full details of this fascinating scan type are in + <xref linkend="idlescan"/>. + </notman> + </para> + + <para>Besides being extraordinarily stealthy (due to its + blind nature), this scan type permits mapping out + IP-based trust relationships between machines. The port + listing shows open ports + <emphasis>from the perspective of the zombie + host.</emphasis> So you can try scanning a target using + various zombies that you think might be + trusted<indexterm><primary>trust relationships</primary></indexterm> + (via router/packet filter rules). + </para> + + <para>You can add a colon followed by a port number to the + zombie host if you wish to probe a particular port on the + zombie for IP ID changes. Otherwise Nmap will use the port it + uses by default for TCP pings (80).</para> + </listitem> + </varlistentry> + + <varlistentry> + <term> + <option>-sO</option> (IP protocol scan) + <indexterm><primary><option>-sO</option></primary></indexterm> + <indexterm><primary>IP protocol scan</primary></indexterm> + </term> + <listitem> + +<para>IP protocol scan allows you to determine which IP protocols +(TCP, ICMP, IGMP, etc.) are supported by target machines. This isn't +technically a port scan, since it cycles through IP protocol numbers +rather than TCP or UDP port numbers. Yet it still uses the +<option>-p</option> option to select scanned protocol numbers, reports +its results within the normal port table format, and even uses the same +underlying scan engine as the true port scanning methods. So it is +close enough to a port scan that it belongs here.</para> + +<para>Besides being useful in its own right, protocol scan +demonstrates the power of open-source software. While the fundamental +idea is pretty simple, I had not thought to add it nor received any +requests for such functionality. Then in the summer of 2000, +Gerhard Rieger<indexterm><primary>Rieger, Gerhard</primary></indexterm> +conceived the idea, wrote an excellent patch implementing it, +and sent it to the +<citetitle>announce</citetitle> mailing list<indexterm><primary><citetitle>announce</citetitle> mailing list</primary></indexterm> +(then called <citetitle>nmap-hackers</citetitle>).<indexterm><primary><citetitle>nmap-hackers</citetitle> mailing list</primary><see><citetitle>announce</citetitle> mailing list</see></indexterm> +I incorporated that patch into the Nmap tree and released a new +version the next day. Few pieces of commercial software have users +enthusiastic enough to design and contribute their own +improvements!</para> + +<para>Protocol scan works in a similar fashion to UDP scan. Instead +of iterating through the port number field of a UDP packet, it sends +IP packet headers and iterates through the eight-bit IP protocol field. +The headers are usually empty, containing no data and not even the +proper header for the claimed protocol. The exceptions are TCP, +UDP, ICMP, SCTP, and IGMP. A proper protocol header for those is included since +some systems won't send them otherwise and because Nmap already has +functions to create them. Instead of watching for ICMP port +unreachable messages, protocol scan is on the lookout for ICMP +<emphasis>protocol</emphasis> unreachable messages. If Nmap receives +any response in any protocol from the target host, Nmap marks that +protocol as <literal>open</literal>. An ICMP protocol unreachable +error (type 3, code 2) causes the protocol to be marked as +<literal>closed</literal> while port unreachable (type 3, code 3) +marks the protocol <literal>open</literal>. Other ICMP unreachable errors (type 3, code +0, 1, 9, 10, or 13) cause the protocol to be marked +<literal>filtered</literal> (though they prove that ICMP is +<literal>open</literal> at the same time). If no response is received +after retransmissions, the protocol is marked +<literal>open|filtered</literal></para> + + </listitem> + </varlistentry> + + + + <varlistentry> + <term> + <option>-b <replaceable>FTP relay host</replaceable></option> (FTP bounce scan) + <indexterm><primary><option>-b</option></primary></indexterm> + <indexterm><primary>FTP bounce scan</primary></indexterm> + </term> + <listitem> + +<para>An interesting feature of the FTP protocol (<ulink +role="hidepdf" url="http://www.rfc-editor.org/rfc/rfc959.txt">RFC 959</ulink>) is +support for so-called proxy FTP connections. This allows a user to +connect to one FTP server, then ask that files be sent to a +third-party server. Such a feature is ripe for abuse on many levels, +so most servers have ceased supporting it. One of the abuses this +feature allows is causing the FTP server to port scan other hosts. +Simply ask the FTP server to send a file to each interesting port of a +target host in turn. The error message will describe whether the port +is open or not. This is a good way to bypass firewalls because +organizational FTP servers are often placed where they have +more access to other internal hosts than any old Internet host would. Nmap supports FTP +bounce scan with the <option>-b</option> option. It takes an argument +of the form +<replaceable>username</replaceable>:<replaceable>password</replaceable>@<replaceable>server</replaceable>:<replaceable>port</replaceable>. +<replaceable>Server</replaceable> is the name or IP address of a +vulnerable FTP server. As with a normal URL, you may omit +<replaceable>username</replaceable>:<replaceable>password</replaceable>, +in which case anonymous login credentials (user: +<literal>anonymous</literal> password:<literal>-wwwuser@</literal>) +are used. The port number (and preceding colon) may be omitted as +well, in which case the default FTP port (21) on +<replaceable>server</replaceable> is used.</para> + +<para>This vulnerability was widespread in 1997 when Nmap was +released, but has largely been fixed. Vulnerable servers are still +around, so it is worth trying when all else fails. If bypassing a +firewall is your goal, scan the target network for port 21 (or +even for any FTP services if you scan all ports with version +detection) and use the +<filename>ftp-bounce</filename><indexterm><filename>ftp-bounce</filename> script</indexterm> +NSE script. Nmap will tell you +whether the host is vulnerable or not. If you are just trying to +cover your tracks, you don't need to (and, in fact, shouldn't) limit +yourself to hosts on the target network. Before you go scanning +random Internet addresses for vulnerable FTP servers, consider that +sysadmins may not appreciate you abusing their servers in this +way.</para> + + </listitem> + </varlistentry> + </variablelist> + </refsect1> + + <refsect1 id='man-port-specification'> + <title>Port Specification and Scan Order</title> + <indexterm><primary>port specification</primary></indexterm> + + <para>In addition to all of the scan methods discussed previously, + Nmap offers options for specifying which ports are scanned and + whether the scan order is randomized or sequential. By default, Nmap scans the most common 1,000 ports for each protocol. + <indexterm><primary>default ports</primary></indexterm> + </para> + + <variablelist> + <varlistentry> + <term> + <option>-p <replaceable>port ranges</replaceable></option> (Only scan specified ports) + <indexterm><primary><option>-p</option></primary></indexterm> + </term> + <listitem> + + + <para>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. <literal>1-1023</literal>). The + beginning and/or end values of a range may be omitted, + causing Nmap to use 1 and 65535, respectively. So you can + specify <option>-p-</option> to scan ports from 1 through + 65535. Scanning + port zero<indexterm><primary>port zero</primary></indexterm> + is allowed if you specify it + explicitly. For IP protocol scanning (<option>-sO</option>), this option + specifies the protocol numbers you wish to scan for + (0–255).</para> + + <para>When scanning a combination of protocols (e.g. TCP and UDP), you can + specify a particular protocol by preceding the port numbers by + <literal>T:</literal> for TCP, <literal>U:</literal> for UDP, + <literal>S:</literal> for SCTP, or <literal>P:</literal> for IP Protocol. + The qualifier lasts until you specify another + qualifier. For example, the argument <option>-p + U:53,111,137,T:21-25,80,139,8080</option> 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 + <option>-sU</option> and at least one TCP scan type (such as + <option>-sS</option>, <option>-sF</option>, or + <option>-sT</option>). If no protocol qualifier is given, + the port numbers are added to all protocol lists.</para> + + + <indexterm><primary>port specification</primary><secondary>wildcards in</secondary></indexterm> + <indexterm><primary>wildcards</primary><see>port selection, wildcards in</see></indexterm> + <para> + Ports can also be specified by name according to what the + port is referred to in the <filename>nmap-services</filename>. You + can even use the wildcards <literal>*</literal> and + <literal>?</literal> with the names. For example, to scan + FTP and all ports whose names begin with <quote>http</quote>, use <option>-p ftp,http*</option>. + Be careful about shell expansions and quote the argument to <option>-p</option> if unsure.</para> + + <para>Ranges of ports can be surrounded by square brackets to indicate + ports inside that range that appear in <filename>nmap-services</filename>. + For example, the following will scan all ports in <filename>nmap-services</filename> + equal to or below 1024: <option>-p [-1024]</option>. Be careful with shell + expansions and quote the argument to <option>-p</option> if unsure.</para> + </listitem> + </varlistentry> + + <varlistentry> + <term> + <option>--exclude-ports <replaceable>port ranges</replaceable></option> (Exclude the specified ports from scanning) + <indexterm><primary><option>--exclude-ports</option></primary></indexterm> + </term> + <listitem> + + <para>This option specifies which ports you do want Nmap to exclude + from scanning. The <replaceable>port ranges</replaceable> + are specified similar to <option>-p</option>. For IP protocol + scanning (<option>-sO</option>), this option specifies the protocol + numbers you wish to exclude (0–255).</para> + + <para>When ports are asked to be excluded, they are excluded from all + types of scans (i.e. they will not be scanned under any circumstances). + This also includes the discovery phase.</para> + + </listitem> + </varlistentry> + + <varlistentry> + <term> + <option>-F</option> (Fast (limited port) scan) + <indexterm significance="preferred"><primary><option>-F</option></primary></indexterm> + <indexterm><primary>fast scan</primary><see><option>-F</option></see></indexterm> + </term> + <listitem> + <para>Specifies that you wish to scan fewer ports than the + default. Normally Nmap scans the most common 1,000 ports for + each scanned protocol. With <option>-F</option>, this is + reduced to 100.</para> + + <para>Nmap needs an <filename>nmap-services</filename> file + with frequency information in order to know which ports are + the most common<notman> (see <xref linkend="nmap-services"/> + for more about port frequencies)</notman>. If port frequency + information isn't available, perhaps because of the use of a + custom <filename>nmap-services</filename> file, Nmap scans + all named ports plus ports 1-1024. In that case, + <option>-F</option> means to scan only ports that are named + in the services file.</para> + + </listitem> + </varlistentry> + + <varlistentry> + <term> + <option>-r</option> (Don't randomize ports) + <indexterm><primary><option>-r</option></primary></indexterm> + <indexterm><primary>randomization of ports</primary></indexterm> + </term> + <listitem> + <para>By default, Nmap randomizes the scanned port order + (except that certain commonly accessible ports are moved + near the beginning for efficiency reasons). This + randomization is normally desirable, but you can specify + <option>-r</option> for sequential (sorted from lowest to highest) port scanning + instead.</para> + </listitem> + </varlistentry> + + <varlistentry> + <term> + <option>--port-ratio <replaceable>ratio</replaceable><decimal number between 0 and 1></option> + </term> + <listitem> + <indexterm><primary>--port-ratio</primary></indexterm> + <para>Scans all ports in <filename>nmap-services</filename> file + with a ratio greater than the one given. + <replaceable>ratio</replaceable> must be between 0.0 and 1.0.</para> + </listitem> + </varlistentry> + + <varlistentry> + <term> + <option>--top-ports <replaceable>n</replaceable></option> + </term> + <listitem> + <indexterm><primary>--top-ports</primary></indexterm> + <para>Scans the <replaceable>n</replaceable> highest-ratio ports + found in <filename>nmap-services</filename> file after excluding all + ports specified by <option>--exclude-ports</option>. + <replaceable>n</replaceable> must be 1 or greater.</para> + </listitem> + </varlistentry> + + </variablelist> + +</refsect1> + + + <refsect1 id='man-version-detection'> + <title>Service and Version Detection</title> + <indexterm class="startofrange" id="man-version-detection-indexterm"><primary>version detection</primary></indexterm> + + + <para>Point Nmap at a remote machine and it might tell you + that ports <literal>25/tcp</literal>, <literal>80/tcp</literal>, and <literal>53/udp</literal> are open. Using its + <filename>nmap-services</filename><indexterm><primary><filename>nmap-services</filename></primary></indexterm> + database of about 2,200 + well-known services,<indexterm><primary>well-known ports</primary></indexterm> + Nmap would report that those ports probably correspond to a + mail server (SMTP), web server (HTTP), and name server (DNS) + respectively. This lookup is usually accurate—the vast + majority of daemons listening on TCP port 25 are, in fact, mail + servers. However, you should not bet your security on this! + People can and do run services on + strange ports.<indexterm><primary>non-standard ports</primary></indexterm> + </para> + + <para>Even if Nmap is right, and the hypothetical server above is + running SMTP, HTTP, and DNS servers, that is not a lot of + information. When doing vulnerability assessments (or even simple + network inventories) of your companies or clients, you really want + to know which mail and DNS servers and versions are + running. Having an accurate version number helps dramatically in + determining which exploits a server is vulnerable to. Version + detection helps you obtain this information. +</para> + + <para>After TCP and/or UDP ports are discovered using one of the + other scan methods, version detection interrogates those ports to + determine more about what is actually running. The + <filename>nmap-service-probes</filename><indexterm><primary><filename>nmap-service-probes</filename></primary></indexterm> + database contains probes + for querying various services and match expressions to recognize + and parse responses. Nmap tries to determine the service protocol + (e.g. FTP, SSH, Telnet, HTTP), the application name (e.g. ISC + BIND, Apache httpd, Solaris telnetd), the version number, + hostname, device type (e.g. printer, router), the OS family + (e.g. Windows, Linux). When possible, Nmap also gets the + Common Platform Enumeration (CPE)<indexterm><primary>Common Platform Enumeration</primary><secondary>service</secondary></indexterm> + representation of this information. Sometimes miscellaneous details like + whether an X server is open to connections, the SSH protocol + version, or the KaZaA user name, are available. Of course, most services don't + provide all of this information. If Nmap was compiled with + OpenSSL support, it will connect to SSL servers to deduce the + service listening behind that encryption layer.<indexterm><primary>SSL</primary><secondary>in version detection</secondary></indexterm> + Some UDP ports are left in the + <literal>open|filtered</literal> state after a UDP port scan is + unable to determine whether the port is open or filtered. Version + detection will try to elicit a response from these ports (just as + it does with open ports), and change the state to open if it + succeeds. <literal>open|filtered</literal> TCP ports are treated + the same way. Note that the Nmap <option>-A</option> option + enables version detection among other things. + <man> + A paper documenting the workings, usage, and customization of version + detection is available at + <ulink url="https://nmap.org/book/vscan.html" />. + </man> + <notman> + Version detection is described in detail in <xref linkend="vscan"/>. + </notman> + </para> + + <para>When RPC services are discovered, the Nmap RPC + grinder<indexterm><primary>RPC grinder</primary></indexterm> + is automatically used to determine the RPC program and version + numbers. It takes all the TCP/UDP ports detected as RPC and floods + them with SunRPC program NULL commands in an attempt to determine + whether they are RPC ports, and if so, what program and version + number they serve up. Thus you can effectively obtain the same info + as <command>rpcinfo -p</command> even if the target's portmapper is + behind a firewall (or protected by TCP wrappers). Decoys do not + currently work with + RPC scan.<indexterm><primary>decoys</primary><secondary>which scans use</secondary></indexterm> + </para> + + <para>When Nmap receives responses from a service but cannot match + them to its database, it prints out a special fingerprint and + a URL for you to submit it to if you know for sure what is running + on the port. Please take a couple minutes to make the submission + so that your find can benefit everyone. Thanks to these + submissions, Nmap has about 6,500 pattern matches for more than + 650 protocols such as SMTP, FTP, HTTP, etc.<indexterm><primary>submission of service fingerprints</primary></indexterm> + </para> + + <para>Version detection is enabled and controlled with the + following options:</para> + + + <variablelist> + + <varlistentry> + <term> + <option>-sV</option> (Version detection) + <indexterm><primary><option>-sV</option></primary></indexterm></term> + <listitem> + + + <para>Enables version detection, as discussed above. + Alternatively, you can use <option>-A</option>, which enables + version detection among other things.</para> + + <para><option>-sR</option><indexterm><primary><option>-sR</option></primary></indexterm> + is an alias for <option>-sV</option>. Prior to March 2011, it + was used to active the RPC grinder separately from version + detection, but now these options are always combined.</para> + </listitem> + </varlistentry> + + <varlistentry> + <term> + <option>--allports</option> (Don't exclude any ports from + version detection) + <indexterm><primary><option>--allports</option></primary></indexterm> + </term> + <listitem> + + <para>By default, Nmap version detection skips TCP port 9100 + because some printers simply print anything sent to that + port, leading to dozens of pages of HTTP GET requests, binary + SSL session requests, etc. This behavior can be changed by + modifying or removing the <literal>Exclude</literal> + directive in <filename>nmap-service-probes</filename>, or + you can specify <option>--allports</option> to scan all + ports regardless of any <literal>Exclude</literal> + directive. + <indexterm><primary><literal>Exclude</literal> directive (<filename>nmap-service-probes</filename>)</primary></indexterm> + </para> + </listitem> + </varlistentry> + + <varlistentry> + <term> + <option>--version-intensity <replaceable>intensity</replaceable></option> (Set + version scan intensity) + <indexterm><primary><option>--version-intensity</option></primary></indexterm> + </term> + <listitem> + + + <para>When performing a version scan (<option>-sV</option>), Nmap sends a + series of probes, each of which is assigned a rarity value + between one and nine. The lower-numbered probes are effective + against a wide variety of common services, while the higher-numbered + ones are rarely useful. The intensity level + specifies which probes should be applied. The higher the + number, the more likely it is the service will be correctly + identified. However, high intensity scans take longer. The + intensity must be between 0 and 9.<indexterm><primary>version detection</primary><secondary>intensity</secondary></indexterm> + The default is 7.<indexterm><primary>version detection</primary><secondary>default intensity</secondary></indexterm> + When a probe is registered to the target port via the + <filename>nmap-service-probes</filename> <literal>ports</literal> directive, that probe is tried + regardless of intensity level. This ensures that the DNS + probes will always be attempted against any open port 53, + the SSL probe will be done against 443, etc.</para> + + </listitem> + </varlistentry> + + <varlistentry> + <term> + <option>--version-light</option> (Enable light mode) + <indexterm><primary><option>--version-light</option></primary></indexterm> + </term> + <listitem> + + <para>This is a convenience alias for + <option>--version-intensity 2</option>. This light mode + makes version scanning much faster, but it is slightly less + likely to identify services.</para> + </listitem> + </varlistentry> + + <varlistentry> + <term> + <option>--version-all</option> (Try every single probe) + <indexterm><primary><option>--version-all</option></primary></indexterm> + </term> + <listitem> + + <para>An alias for <option>--version-intensity 9</option>, + ensuring that every single probe is attempted against each + port.</para> + </listitem> + </varlistentry> + + <varlistentry> + <term> + <option>--version-trace</option> (Trace version scan activity) + <indexterm significance="preferred"><primary><option>--version-trace</option></primary></indexterm> + </term> + <listitem> + <para>This causes Nmap to print out extensive debugging info + about what version scanning is doing. It is a subset of + what you get with <option>--packet-trace</option>.</para> + </listitem> + </varlistentry> + + </variablelist> + <indexterm class="endofrange" startref="man-version-detection-indexterm"/> + </refsect1> + + <refsect1 id='man-os-detection'> + + <title>OS Detection</title> + <indexterm class="startofrange" id="man-os-detection-indexterm"><primary>OS detection</primary></indexterm> + + <indexterm><primary>CPE</primary><see>Common Platform Enumeration</see></indexterm> + <para>One of Nmap's best-known features is remote OS detection + using TCP/IP stack fingerprinting. Nmap sends a series of TCP and + UDP packets to the remote host and examines practically every bit + in the responses. After performing dozens of tests such as TCP + ISN sampling, TCP options support and ordering, IP ID sampling, and + the initial window size check, Nmap compares the results to its + <filename>nmap-os-db</filename><indexterm><primary><filename>nmap-os-db</filename></primary></indexterm> + database of more than 2,600 known + OS fingerprints and prints out the OS details if there is a match. + Each fingerprint includes a freeform textual description of the + OS, and a classification which provides the vendor name + (e.g. Sun), underlying OS (e.g. Solaris), OS generation (e.g. 10), + and device type (general purpose, router, switch, game console, + etc). Most fingerprints also have a Common Platform Enumeration + (CPE)<indexterm><primary>Common Platform Enumeration</primary><secondary>operating system</secondary></indexterm> + representation, like + <literal>cpe:/o:linux:linux_kernel:2.6</literal>.</para> + + <para>If Nmap is unable to guess the OS of a machine, and + conditions are good (e.g. at least one open port and one closed + port were found), Nmap will + provide a URL you can use to submit the fingerprint if you know + (for sure) the OS running on the machine. By doing this you + contribute to the pool of operating systems known to Nmap and thus + it will be more accurate for everyone.</para> + + <para>OS detection enables some other tests which make use + of information that is gathered during the process anyway. + One of these is + TCP Sequence Predictability Classification. This measures + approximately how hard it is to establish a forged + TCP connection against the remote host. It is useful for + exploiting source-IP based trust relationships (rlogin, firewall + filters, etc) or for hiding the source of an attack. This sort of + spoofing is rarely performed any more, but many machines are still + vulnerable to it. The actual + difficulty number is based on statistical sampling and may + fluctuate. It is generally better to use the English + classification such as <quote>worthy challenge</quote> or <quote>trivial joke</quote>. This + is only reported in normal output in verbose (<option>-v</option>) + mode. When verbose mode is enabled along with <option>-O</option>, IP ID sequence + generation is also reported. Most machines are in the + <quote>incremental</quote> class, which means that they increment the ID + field in the IP header for each packet they send. This makes them + vulnerable to several advanced information gathering and + spoofing attacks.</para> + + <indexterm><primary>uptime guess</primary></indexterm> + <para> + Another bit of extra information enabled by OS detection is a guess + at a target's uptime. This uses the TCP timestamp option (<ulink role="hidepdf" url="http://www.rfc-editor.org/rfc/rfc1323.txt">RFC 1323</ulink>) to guess when a machine was last rebooted. + The guess can be inaccurate due to the timestamp counter not being + initialized to zero or the counter overflowing and wrapping around, + so it is printed only in verbose mode. + </para> + + <para> + <man> + A paper documenting the workings, usage, and customization of OS + detection is available at + <ulink url="https://nmap.org/book/osdetect.html" />. + </man> + <notman> + OS detection is covered in <xref linkend="osdetect"/>. + </notman> + </para> + + <para>OS detection is enabled and controlled with the following options:</para> + + <variablelist> + <varlistentry> + <term> + <option>-O</option> (Enable OS detection) + <indexterm significance="preferred"><primary><option>-O</option></primary></indexterm> + </term> + <listitem> + + + <para>Enables OS detection, as discussed above. + Alternatively, you can use <option>-A</option> to enable + OS detection along with other things.</para> + + </listitem> + </varlistentry> + + <varlistentry> + <term> + <option>--osscan-limit</option> (Limit OS detection to + promising targets) + <indexterm significance="preferred"><primary><option>--osscan-limit</option></primary></indexterm> + </term> + <listitem> + + <para>OS detection is far more effective if at least one + open and one closed TCP port are found. Set this option + and Nmap will not even try OS detection against hosts + that do not meet this criteria. This can save substantial + time, particularly on <option>-Pn</option> scans against many hosts. It + only matters when OS detection is requested with <option>-O</option> or <option>-A</option>.</para> + </listitem> + </varlistentry> + + <varlistentry> + <term> + <option>--osscan-guess</option>; <option>--fuzzy</option> (Guess OS detection results) + <indexterm significance="preferred"><primary><option>--osscan-guess</option></primary></indexterm> + <indexterm><primary><option>--fuzzy</option></primary><see><option>--osscan-guess</option></see></indexterm> + </term> + <listitem> + + <para>When Nmap is unable to detect a perfect OS match, it + sometimes offers up near-matches as possibilities. The + match has to be very close for Nmap to do this by default. + Either of these (equivalent) options make Nmap guess more + aggressively. Nmap will still tell you when an imperfect + match is printed and display its confidence level + (percentage) for each guess.</para> + </listitem> + </varlistentry> + + <varlistentry> + <term> + <option>--max-os-tries</option> (Set the maximum number of OS detection tries against a target) + <indexterm significance="preferred"><primary><option>--max-os-tries</option></primary></indexterm> + </term> + <listitem> + + + <para>When Nmap performs OS detection against a target and + fails to find a perfect match, it usually repeats the + attempt. By default, Nmap tries five times if conditions + are favorable for OS fingerprint submission, and twice when + conditions aren't so good. Specifying a lower + <option>--max-os-tries</option> value (such as 1) speeds + Nmap up, though you miss out on retries which could + potentially identify the OS. Alternatively, a high value + may be set to allow even more retries when conditions are + favorable. This is rarely done, except to generate better + fingerprints for submission and integration into the Nmap OS + database.</para> + + </listitem> + </varlistentry> + + </variablelist> + <indexterm class="endofrange" startref="man-os-detection-indexterm"/> + </refsect1> + <refsect1 id='man-nse'> + <title>Nmap Scripting Engine (NSE)</title> + <indexterm class="startofrange" id="man-nse-indexterm"><primary>Nmap Scripting Engine (NSE)</primary></indexterm> + + <para>The Nmap Scripting Engine (NSE) is one of Nmap's most + powerful and flexible features. It allows users to write (and + share) simple scripts (using the <ulink url="https://lua.org">Lua programming language</ulink> + <indexterm><primary>Lua programming language</primary></indexterm> + ) to automate a wide variety of + networking tasks. Those scripts are executed in parallel with the + speed and efficiency you expect from Nmap. Users can rely on the + growing and diverse set of scripts distributed with Nmap, or write + their own to meet custom needs.</para> + + <para>Tasks we had in mind when creating the system include + network discovery, more sophisticated version detection, + vulnerability detection. NSE can even be used for vulnerability + exploitation.</para> + + <para> + To reflect those different uses and to simplify the choice of which + scripts to run, each script contains a field associating it with one or more categories. Currently defined categories are + <literal>auth</literal>, + <literal>broadcast</literal>, + <literal>default</literal>. + <literal>discovery</literal>, + <literal>dos</literal>, + <literal>exploit</literal>, + <literal>external</literal>, + <literal>fuzzer</literal>, + <literal>intrusive</literal>, + <literal>malware</literal>, + <literal>safe</literal>, + <literal>version</literal>, and + <literal>vuln</literal>. + These are all described + <man>at <ulink url="https://nmap.org/book/nse-usage.html#nse-categories" />.</man> + <notman>in <xref linkend="nse-categories"/>.</notman></para> + + <para> + Scripts are not run in a sandbox and thus could accidentally or + maliciously damage your system or invade your privacy. Never run + scripts from third parties unless you trust the authors or have + carefully audited the scripts yourself. + </para> + + <para>The Nmap Scripting Engine is described in detail +<man>at <ulink url="https://nmap.org/book/nse.html" /></man> +<notman>in <xref linkend="nse"/></notman> and is controlled by the following options:</para> + + <variablelist> + <varlistentry> + <term><option>-sC</option> + <indexterm significance="preferred"> + <primary><option>-sC</option></primary> + </indexterm> + </term> + + <listitem> + + <para>Performs a script scan using the default set of scripts. It is + equivalent to <option>--script=default</option>. Some of the + scripts in this category are considered intrusive and should + not be run against a target network without permission. </para> + </listitem> + </varlistentry> + + <varlistentry> + <term> + <option>--script <replaceable>filename</replaceable>|<replaceable>category</replaceable>|<replaceable>directory</replaceable>/|<replaceable>expression</replaceable><optional>,...</optional></option> + <indexterm><primary><option>--script</option></primary></indexterm> + </term> + +<listitem> + +<para> +Runs a script scan using the comma-separated list of filenames, script +categories, and directories. Each element in the list may also be a +Boolean expression describing a more complex set of scripts. Each +element is interpreted first as an expression, then as a category, and +finally as a file or directory name.</para> + +<para>There are two special features for advanced users only. +One is to prefix script names and expressions with +<literal>+</literal> to force them to run even if they normally +wouldn't (e.g. the relevant service wasn't detected on the target +port). The other is that the argument <literal>all</literal> may be +used to specify every script in Nmap's database. Be cautious with +this because NSE contains dangerous scripts such as exploits, brute +force authentication crackers, and denial of service attacks. +</para> + +<para> +File and directory names may be relative or absolute. Absolute names are +used directly. Relative paths are looked for in the +<filename>scripts</filename> of each of the following places until +found: +<indexterm><primary>data files</primary><secondary>directory search order</secondary></indexterm><indexterm><primary>scripts, location of</primary></indexterm> +<simplelist> +<member><option>--datadir</option></member> +<member><envar>$NMAPDIR</envar><indexterm><primary><envar>NMAPDIR</envar> environment variable</primary></indexterm></member> +<member><filename>~/.nmap</filename> (not searched on Windows)<indexterm><primary sortas="nmap directory"><filename>.nmap</filename> directory</primary></indexterm></member> +<member><filename><replaceable>APPDATA</replaceable>\nmap</filename> (only on Windows)<indexterm><primary sortas="nmap directory"><filename>.nmap</filename> directory</primary></indexterm></member> +<member>the directory containing the <filename>nmap</filename> +executable</member> +<member>the directory containing the <filename>nmap</filename> +executable, followed by <filename>../share/nmap</filename> (not searched on Windows)</member> +<member><varname>NMAPDATADIR</varname><indexterm><primary><varname>NMAPDATADIR</varname></primary></indexterm> (not searched on Windows)</member> +<member>the current directory.</member> +</simplelist> +</para> + +<para> +When a directory name ending in <literal>/</literal> is given, Nmap loads every file in the directory +whose name ends with <filename>.nse</filename>. All other files are +ignored and directories are not searched recursively. When a filename is +given, it does not have to have the <filename>.nse</filename> extension; +it will be added automatically if necessary. +</para> + +<indexterm><primary>script database</primary><see><filename>script.db</filename></see></indexterm> +<indexterm><primary>scripts, location of</primary></indexterm> + +<para>Nmap scripts are stored in a <filename>scripts</filename> +subdirectory of the Nmap data directory by default +<man>(see <ulink url="https://nmap.org/book/data-files.html"/>).</man> +<notman>(see <xref linkend="data-files"/>).</notman> +For efficiency, scripts are indexed in +a database stored +in <filename>scripts/script.db</filename>,<indexterm><primary><filename>script.db</filename></primary></indexterm> +which lists the category or categories in which each script belongs.</para> + + <indexterm><primary>wildcards</primary><secondary>in script selection</secondary></indexterm> + <para> + When referring to scripts from <filename>script.db</filename> by + name, you can use a shell-style ‘<literal>*</literal>’ + wildcard. + </para> + + <variablelist> + <varlistentry> + <term><command>nmap --script "http-*"</command></term> + <listitem> + <para>Loads all scripts whose name starts with + <filename>http-</filename>, such as + <filename>http-auth</filename> and + <filename>http-open-proxy</filename>. The argument to + <option>--script</option> had to be in quotes to protect the + wildcard from the shell.</para> + </listitem> + </varlistentry> + </variablelist> + + <indexterm><primary>Boolean expressions in script selection</primary></indexterm> + <para> + More complicated script selection can be done using the + <literal>and</literal>, <literal>or</literal>, and + <literal>not</literal> operators to build Boolean expressions. The + operators have the same + <ulink role="hidepdf" url="http://www.lua.org/manual/5.4/manual.html#3.4.8">precedence</ulink> + as in Lua: <literal>not</literal> is the highest, followed by + <literal>and</literal> and then <literal>or</literal>. You can + alter precedence by using parentheses. Because expressions contain + space characters it is necessary to quote + them. + </para> + + <variablelist> + <varlistentry> + <term><command>nmap --script "not intrusive"</command></term> + <listitem> + <para>Loads every script except for those in the + <literal>intrusive</literal> category.</para> + </listitem> + </varlistentry> + <varlistentry> + <term><command>nmap --script "default or safe"</command></term> + <listitem> + <para>This is functionally equivalent to + <command>nmap --script "default,safe"</command>. It loads all + scripts that are in the <literal>default</literal> category or + the <literal>safe</literal> category or both.</para> + </listitem> + </varlistentry> + <varlistentry> + <term><command>nmap --script "default and safe"</command></term> + <listitem> + <para>Loads those scripts that are in + <emphasis>both</emphasis> the <literal>default</literal> and + <literal>safe</literal> categories.</para> + </listitem> + </varlistentry> + <varlistentry> + <term><command>nmap --script "(default or safe or intrusive) and not http-*"</command></term> + <listitem> + <para>Loads scripts in the <literal>default</literal>, + <literal>safe</literal>, or <literal>intrusive</literal> + categories, except for those whose names start with + <filename>http-</filename>.</para> + </listitem> + </varlistentry> + </variablelist> + +</listitem> +</varlistentry> + + <varlistentry> + <term><option>--script-args <replaceable>n1</replaceable>=<replaceable>v1</replaceable>,<replaceable>n2</replaceable>={<replaceable>n3</replaceable>=<replaceable>v3</replaceable>},<replaceable>n4</replaceable>={<replaceable>v4</replaceable>,<replaceable>v5</replaceable>}</option> + <indexterm significance="preferred"><primary><option>--script-args</option></primary></indexterm> + <indexterm><primary>script arguments</primary><seealso><option>--script-args</option></seealso></indexterm></term> + +<listitem> +<para> +Lets you provide arguments to NSE scripts. Arguments are a comma-separated list +of <literal>name=value</literal> pairs. Names and values may be strings not +containing whitespace or the characters +‘<literal>{</literal>’, +‘<literal>}</literal>’, +‘<literal>=</literal>’, or +‘<literal>,</literal>’. +To include one of these characters in a string, enclose the string in single or +double quotes. Within a quoted string, ‘<literal>\</literal>’ +escapes a quote. A backslash is only used to escape quotation marks in this +special case; in all other cases a backslash is interpreted literally. Values +may also be tables enclosed in <literal>{}</literal>, just as in Lua. A table +may contain simple string values or more name-value pairs, including nested +tables. Many scripts qualify their arguments with the script name, as in <literal>xmpp-info.server_name</literal>. You may use that full qualified version to affect just the specified script, or you may pass the unqualified version (<literal>server_name</literal> in this case) to affect all scripts using that argument name. A script will first check for its fully qualified argument name (the name specified in its documentation) before it accepts an unqualified argument name. A complex example of script arguments is +<option>--script-args 'user=foo,pass=",{}=bar",whois={whodb=nofollow+ripe},xmpp-info.server_name=localhost'</option>. The online NSE Documentation Portal at <ulink url="https://nmap.org/nsedoc/"/> +lists the arguments that each script accepts. +</para> +</listitem> +</varlistentry> + + <varlistentry> + <term><option>--script-args-file <replaceable>filename</replaceable></option> + <indexterm significance="preferred"><primary><option>--script-args-file</option></primary></indexterm> + <indexterm><primary>script arguments from file</primary><seealso><option>--script-args-file</option></seealso></indexterm></term> + +<listitem> +<para> + Lets you load arguments to NSE scripts from a file. Any arguments on the + command line supersede ones in the file. The file can be an absolute path, + or a path relative to Nmap's usual search path (NMAPDIR, etc.) + Arguments can be comma-separated or newline-separated, but otherwise follow + the same rules as for <option>--script-args</option>, without requiring + special quoting and escaping, since they are not parsed by the shell. +</para> +</listitem> +</varlistentry> + <varlistentry> + <term> + <option>--script-help <replaceable>filename</replaceable>|<replaceable>category</replaceable>|<replaceable>directory</replaceable>|<replaceable>expression</replaceable>|all<optional>,...</optional></option> + <indexterm><primary><option>--script-help</option></primary></indexterm> + </term> + + <listitem> + <para> + Shows help about scripts. For each script matching the given + specification, Nmap prints the script name, its categories, and its + description. The specifications are the same as those accepted by + <option>--script</option>; so for example if you want help about + the <literal>ftp-anon</literal> script, you would run + <command>nmap --script-help ftp-anon</command>. In addition to getting + help for individual scripts, you can use this as a preview of what + scripts will be run for a specification, for example with <command>nmap + --script-help default</command>. + </para> + </listitem> + </varlistentry> + + <varlistentry> + <term><option>--script-trace</option> + <indexterm significance="preferred"><primary><option>--script-trace</option></primary></indexterm></term> + + <listitem> + <para> + This option does what <option>--packet-trace</option> does, + just one ISO layer higher. If this option is specified all incoming + and outgoing communication performed by a script is printed. The + displayed information includes the communication protocol, the + source, the target and the transmitted data. If more than 5% of all + transmitted data is not printable, then the trace output is in a hex + dump format. Specifying <option>--packet-trace</option> enables script + tracing too. + </para> + </listitem> + </varlistentry> + + <varlistentry> + <term><option>--script-updatedb</option> + <indexterm significance="preferred"><primary><option>--script-updatedb</option></primary></indexterm></term> + + <listitem> + + <para>This option updates the script database found + in <filename>scripts/script.db</filename> which is used by + Nmap to determine the available default scripts and + categories. It is only necessary to update the database if + you have added or removed NSE scripts from the + default <filename>scripts</filename> directory or if you + have changed the categories of any script. This option is + generally used by + itself: <command>nmap --script-updatedb</command>.</para> + + </listitem> + </varlistentry> + </variablelist> + + <indexterm class="endofrange" startref="man-nse-indexterm"/> + </refsect1> + + <refsect1 id='man-performance'> + <title>Timing and Performance</title> + <indexterm class="startofrange" id="man-performance-timing-indexterm"><primary>timing</primary></indexterm> + <indexterm class="startofrange" id="man-performance-indexterm"><primary>performance</primary></indexterm> + <para>One of my highest Nmap development priorities has always been +performance. A default scan (<command>nmap +<replaceable>hostname</replaceable></command>) of a host on my local +network takes a fifth of a second. That is barely enough time to +blink, but adds up when you are scanning hundreds or thousands +of hosts. Moreover, certain scan options such as UDP scanning and +version detection can increase scan times substantially. So can +certain firewall configurations, particularly response rate limiting. +While Nmap utilizes parallelism and many advanced algorithms to +accelerate these scans, the user has ultimate control over how Nmap +runs. Expert users carefully craft Nmap commands to obtain only the +information they care about while meeting their time +constraints.</para> + +<para>Techniques for improving scan times include omitting +non-critical tests, and upgrading to the latest version of Nmap +(performance enhancements are made frequently). Optimizing timing +parameters can also make a substantial difference. Those options are +listed below.</para> + +<para>Some options accept a <literal>time</literal> parameter. This +is specified in seconds by default, though you can append +‘ms’, ‘s’, ‘m’, or ‘h’ to the value to +specify milliseconds, seconds, minutes, or hours. So the +<option>--host-timeout</option> arguments <literal>900000ms</literal>, +<literal>900</literal>, <literal>900s</literal>, and <literal>15m</literal> all do the same thing.</para> + + + <variablelist> + + <varlistentry> + <term> + <option>--min-hostgroup <replaceable>numhosts</replaceable></option>; + <option>--max-hostgroup + <replaceable>numhosts</replaceable></option> (Adjust parallel scan group sizes) + <indexterm><primary><option>--min-hostgroup</option></primary></indexterm> + <indexterm><primary><option>--max-hostgroup</option></primary></indexterm> + </term> + <listitem> +<para>Nmap has the ability to port scan or version scan multiple hosts +in parallel. Nmap does this by dividing the target IP space into +groups and then scanning one group at a time. In general, larger +groups are more efficient. The downside is that host results can't be +provided until the whole group is finished. So if Nmap started out +with a group size of 50, the user would not receive any reports +(except for the updates offered in verbose mode) until the first 50 +hosts are completed.</para> + +<para>By default, Nmap takes a compromise approach to this conflict. +It starts out with a group size as low as five so the first results +come quickly and then increases the groupsize to as high as 1024. The +exact default numbers depend on the options given. For efficiency +reasons, Nmap uses larger group sizes for UDP or few-port TCP +scans.</para> + +<para>When a maximum group size is specified with +<option>--max-hostgroup</option>, Nmap will never exceed that size. +Specify a minimum size with <option>--min-hostgroup</option> and Nmap +will try to keep group sizes above that level. Nmap may have to use +smaller groups than you specify if there are not enough target hosts +left on a given interface to fulfill the specified minimum. Both may +be set to keep the group size within a specific range, though this is +rarely desired.</para> + +<para>These options do not have an effect during the host discovery +phase of a scan. This includes plain ping scans (<option>-sn</option>). +Host discovery always works in large groups of hosts to improve speed +and accuracy.</para> + +<para>The primary use of these options is to specify a large minimum +group size so that the full scan runs more quickly. A common choice +is 256 to scan a network in /24 sized chunks. For a scan with +many ports, exceeding that number is unlikely to help much. For scans +of just a few port numbers, host group sizes of 2048 or more may be +helpful.</para> + + </listitem> + </varlistentry> + + <varlistentry> + <term> + <option>--min-parallelism <replaceable>numprobes</replaceable></option>; + <option>--max-parallelism + <replaceable>numprobes</replaceable></option> (Adjust probe parallelization) + <indexterm><primary><option>--min-parallelism</option></primary></indexterm> + <indexterm><primary><option>--max-parallelism</option></primary></indexterm> + </term> + <listitem> + +<para>These options control the total number of probes that may +be outstanding for a host group. They are used for port scanning and +host discovery. By default, Nmap calculates an ever-changing ideal +parallelism based on network performance. If packets are being dropped, +Nmap slows down and allows fewer outstanding probes. The ideal probe +number slowly rises as the network proves itself worthy. These +options place minimum or maximum bounds on that variable. By default, +the ideal parallelism can drop to one if the network proves unreliable +and rise to several hundred in perfect conditions.</para> + +<para>The most common usage is to set +<option>--min-parallelism</option> to a number higher than one to +speed up scans of poorly performing hosts or networks. This is a +risky option to play with, as setting it too high may affect accuracy. +Setting this also reduces Nmap's ability to control parallelism +dynamically based on network conditions. A value of 10 might be +reasonable, though I only adjust this value as a last resort.</para> + +<para>The <option>--max-parallelism</option> option is sometimes set to one +to prevent Nmap from sending more than one probe at a time to hosts. +The <option>--scan-delay</option> option, discussed later, is another +way to do this.</para> + + </listitem> + </varlistentry> + + <varlistentry> + <term> + <option>--min-rtt-timeout <replaceable>time</replaceable></option>, + <option>--max-rtt-timeout <replaceable>time</replaceable></option>, + <option>--initial-rtt-timeout + <replaceable>time</replaceable></option> (Adjust probe timeouts) + <indexterm><primary><option>--min-rtt-timeout</option></primary></indexterm> + <indexterm><primary><option>--max-rtt-timeout</option></primary></indexterm> + <indexterm><primary><option>--initial-rtt-timeout</option></primary></indexterm> + </term> + <listitem> + +<para>Nmap maintains a +running timeout value for determining how long it will wait for a +probe response before giving up or retransmitting the probe. This is +calculated based on the response times of previous probes. +<notman>The exact formula is given in <xref linkend="port-scanning-algorithms" />.</notman> +If the network latency shows itself to be significant and variable, +this timeout can grow to several seconds. It also starts at a +conservative (high) level and may stay that way for a while when Nmap +scans unresponsive hosts.</para> + +<para> +Specifying a lower <option>--max-rtt-timeout</option> and +<option>--initial-rtt-timeout</option> than the defaults can cut scan +times significantly. This is particularly true for pingless +(<option>-Pn</option>) scans, and those against heavily filtered +networks. Don't get too aggressive though. The scan can end up +taking longer if you specify such a low value that many probes are +timing out and retransmitting while the response is in transit.</para> + +<para>If all the hosts are on a local network, 100 milliseconds +(<option>--max-rtt-timeout 100ms</option>) is a +reasonable aggressive value. If +routing is involved, ping a host on the network first with the ICMP +ping utility, or with a custom packet crafter such as +Nping<indexterm><primary>Nping</primary></indexterm> +that is +more likely to get through a firewall. Look at the maximum round trip +time out of ten packets or so. You might want to double that for the +<option>--initial-rtt-timeout</option> and triple or quadruple it for +the <option>--max-rtt-timeout</option>. I generally do not set the +maximum RTT below 100 ms, no matter what the ping times are. Nor do I +exceed 1000 ms.</para> + +<para><option>--min-rtt-timeout</option> is a rarely used option that +could be useful when a network is so unreliable that even Nmap's +default is too aggressive. Since Nmap only reduces the timeout down to +the minimum when the network seems to be reliable, this need is +unusual and should be reported as a bug to the +<citetitle>nmap-dev</citetitle> mailing list.<indexterm><primary><citetitle>nmap-dev</citetitle> mailing list</primary></indexterm> +</para> + + </listitem> + </varlistentry> + + + <varlistentry> + <term> + <option>--max-retries <replaceable>numtries</replaceable></option> (Specify the + maximum number of port scan probe retransmissions) + <indexterm><primary><option>--max-retries</option></primary></indexterm> + </term> + <listitem> + + +<para>When Nmap receives no response to a port scan probe, it could +mean the port is filtered. Or maybe the probe or response was simply +lost on the network. It is also possible that the target host has +rate limiting enabled that temporarily blocked the response. So Nmap +tries again by retransmitting the initial probe. If Nmap detects poor +network reliability, it may try many more times before giving up on a +port. While this benefits accuracy, it also lengthens scan times. +When performance is critical, scans may be sped up by limiting the +number of retransmissions allowed. You can even specify +<option>--max-retries 0</option> to prevent any retransmissions, +though that is only recommended for situations such as informal +surveys where occasional missed ports and hosts are acceptable. +</para> + +<para>The default (with no <option>-T</option> template) is to allow +ten retransmissions. If a network seems reliable and the target hosts +aren't rate limiting, Nmap usually only does one retransmission. So +most target scans aren't even affected by dropping +<option>--max-retries</option> to a low value such as three. Such +values can substantially speed scans of slow (rate limited) hosts. +You usually lose some information when Nmap gives up on ports early, +though that may be preferable to letting the +<option>--host-timeout</option> expire and losing all information +about the target.</para> + + </listitem> + </varlistentry> + + <varlistentry> + <term> + <option>--host-timeout <replaceable>time</replaceable></option> (Give + up on slow target hosts) + <indexterm><primary><option>--host-timeout</option></primary></indexterm> + </term> + <listitem> + + +<para>Some hosts simply take a <emphasis>long</emphasis> time to scan. +This may be due to poorly performing or unreliable networking hardware +or software, packet rate limiting, or a restrictive firewall. The +slowest few percent of the scanned hosts can eat up a majority of the +scan time. Sometimes it is best to cut your losses and skip those +hosts initially. Specify +<option>--host-timeout</option> with the maximum amount of time you +are willing to wait. For example, +specify <literal>30m</literal> to ensure that Nmap doesn't waste +more than half an hour on a single host. Note that Nmap may be +scanning other hosts at the same time during that half an hour, so it isn't a complete loss. A host that times out is skipped. +No port table, OS detection, or version detection results are printed +for that host.</para> + +<para>The special value <literal>0</literal> can be used to mean <quote>no + timeout</quote>, which can be used to override the <option>T5</option> + timing template, which sets the host timeout to 15 minutes.</para> + + </listitem> + </varlistentry> + + <varlistentry> + <term> + <option>--script-timeout <replaceable>time</replaceable></option> + <indexterm><primary><option>--script-timeout</option></primary></indexterm> + </term> + <listitem> + + <para>While some scripts complete in fractions of a second, + others can take hours or more depending on the nature of the + script, arguments passed in, network and application + conditions, and more. The <option>--script-timeout</option> + option sets a ceiling on script execution time. Any script + instance which exceeds that time will be terminated and no + output will be shown. If debugging (<option>-d</option>) is + enabled, Nmap will report on each timeout. For host and + service scripts, a script instance only scans a single + target host or port and the timeout period will be reset for + the next instance.</para> + +<para>The special value <literal>0</literal> can be used to mean <quote>no + timeout</quote>, which can be used to override the <option>T5</option> + timing template, which sets the script timeout to 10 minutes.</para> + + </listitem> + </varlistentry> + + <varlistentry> + <term> + <option>--scan-delay <replaceable>time</replaceable></option>; + <option>--max-scan-delay + <replaceable>time</replaceable></option> (Adjust delay between probes) + <indexterm><primary><option>--scan-delay</option></primary></indexterm> + <indexterm><primary><option>--max-scan-delay</option></primary></indexterm> + </term> + <listitem> + +<para>This option causes Nmap to wait at least the given amount of +time between each probe it sends to a given host. This is +particularly useful in the case of rate limiting.<indexterm><primary>rate limiting</primary></indexterm> Solaris machines +(among many others) will usually respond to UDP scan probe packets +with only one ICMP message per second. Any more than that sent by +Nmap will be wasteful. A <option>--scan-delay</option> of +<literal>1s</literal> will keep Nmap at that slow rate. Nmap tries to +detect rate limiting and adjust the scan delay accordingly, but it +doesn't hurt to specify it explicitly if you already know what rate +works best.</para> + +<para>When Nmap adjusts the scan delay upward to cope with rate +limiting, the scan slows down dramatically. The +<option>--max-scan-delay</option> option specifies the largest delay +that Nmap will allow. A low <option>--max-scan-delay</option> +can speed up Nmap, but it is risky. Setting this value too low can lead to wasteful +packet retransmissions and possible missed ports when the target +implements strict rate limiting.</para> + +<para>Another use of <option>--scan-delay</option> is to evade +threshold based intrusion detection and prevention systems +(IDS/IPS).<indexterm><primary>intrusion detection +systems</primary><secondary>evading</secondary></indexterm> <notman>This +technique is used in <xref linkend="defeating-ids-snort-portscan" /> +to defeat the default port scan detector in Snort IDS. Most other +intrusion detection systems can be defeated in the same way.</notman> +</para> + + </listitem> + </varlistentry> + + <varlistentry> + <term> + <option>--min-rate <replaceable>number</replaceable></option>; <option>--max-rate <replaceable>number</replaceable></option> + (Directly control the scanning rate) + <indexterm><primary><option>--min-rate</option></primary></indexterm> + <indexterm><primary><option>--max-rate</option></primary></indexterm> + </term> + <listitem> + +<para>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 <option>--min-rate</option> and +<option>--max-rate</option> options are designed for these +situations.</para> + +<para>When the +<option>--min-rate</option> 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 <option>--min-rate 300</option> 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.</para> + +<para>Likewise, <option>--max-rate</option> limits a scan's sending rate to a +given maximum. Use <option>--max-rate 100</option>, for example, to +limit sending to 100 packets per second on a fast network. Use +<option>--max-rate 0.1</option> for a slow scan of one packet every ten +seconds. Use <option>--min-rate</option> and <option>--max-rate</option> +together to keep the rate inside a certain range.</para> + +<para>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.</para> + +<para>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.</para> + +<para>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 +<emphasis>longer</emphasis> than it would with a slower rate. This is +because Nmap's <man>adaptive retransmission</man> +<notman><link linkend="scan-methods-adaptive-retransmission">adaptive +retransmission</link><indexterm><primary>adaptive retransmission</primary><see>retransmission</see></indexterm><indexterm><primary>retransmission</primary></indexterm> +</notman>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 +<option>--max-retries</option> option if you need to set an upper limit on total scan +time.</para> + + </listitem> + </varlistentry> + + <varlistentry> + <term><option>--defeat-rst-ratelimit</option> + <indexterm><primary><option>--defeat-rst-ratelimit</option></primary></indexterm></term> + <listitem> + +<para>Many hosts have long used +rate limiting<indexterm><primary>rate limiting</primary></indexterm> +to reduce the number +of ICMP error messages (such as port-unreachable errors) they send. +Some systems now apply similar rate limits to the RST (reset) +packets they generate. This can slow Nmap down dramatically as it +adjusts its timing to reflect those rate limits. You can tell Nmap to +ignore those rate limits (for port scans such as SYN scan which +<emphasis>don't</emphasis> treat non-responsive ports as +<literal>open</literal>) by specifying +<option>--defeat-rst-ratelimit</option>.</para> + +<para>Using this option can reduce accuracy, as some ports will appear +non-responsive because Nmap didn't wait long enough for a rate-limited +RST response. With a SYN +scan, the non-response results in the port being labeled +<literal>filtered</literal> rather than the <literal>closed</literal> +state we see when RST packets are received. This option is useful +when you only care about open ports, and distinguishing between +<literal>closed</literal> and <literal>filtered</literal> ports isn't +worth the extra time.</para> + </listitem> + </varlistentry> + + <varlistentry> + <term><option>--defeat-icmp-ratelimit</option> + <indexterm><primary><option>--defeat-icmp-ratelimit</option></primary></indexterm></term> + <listitem> + +<para>Similar to <option>--defeat-rst-ratelimit</option>, the + <option>--defeat-icmp-ratelimit</option> option trades accuracy for speed, + increasing UDP scanning speed against hosts that rate-limit ICMP error + messages. Because this option causes Nmap to not delay in order to receive + the port unreachable messages, a non-responsive port will be labeled + <literal>closed|filtered</literal> instead of the default + <literal>open|filtered</literal>. This has the effect of only treating ports + which actually respond via UDP as <literal>open</literal>. Since many UDP + services do not respond in this way, the chance for inaccuracy is greater + with this option than with <option>--defeat-rst-ratelimit</option>.</para> + + </listitem> + </varlistentry> + + <varlistentry> + <term><option>--nsock-engine + iocp|epoll|kqueue|poll|select</option> + <indexterm><primary><option>--nsock-engine</option></primary></indexterm> + <indexterm><primary>Nsock IO engine</primary></indexterm> + </term> + <listitem> + +<para>Enforce use of a given nsock IO multiplexing engine. Only the +<literal>select(2)</literal>-based fallback engine is guaranteed to be +available on your system. Engines are named after the name of the IO +management facility they leverage. Engines currently implemented are +<literal>epoll</literal>, <literal>kqueue</literal>, <literal>poll</literal>, +and <literal>select</literal>, but not all will be present on any platform. +By default, Nmap will use the "best" engine, i.e. the first one in this list that is supported. +Use <command>nmap -V</command> to see which engines are supported on your platform.</para> + + </listitem> + </varlistentry> + + <varlistentry> + <term> + <option>-T + paranoid|sneaky|polite|normal|aggressive|insane</option> + (Set a timing template) + <indexterm><primary><option>-T</option></primary></indexterm> + <indexterm><primary>timing templates</primary><seealso><literal>paranoid</literal>, <literal>sneaky</literal>, <literal>polite</literal>, <literal>normal</literal>, <literal>aggressive</literal>, and <literal>insane</literal></seealso></indexterm> + </term> + <listitem> +<indexterm><primary><option>-T0</option></primary><see><literal>paranoid</literal> timing template</see></indexterm> +<indexterm><primary><option>-T1</option></primary><see><literal>sneaky</literal> timing template</see></indexterm> +<indexterm><primary><option>-T2</option></primary><see><literal>polite</literal> timing template</see></indexterm> +<indexterm><primary><option>-T3</option></primary><see><literal>normal</literal> timing template</see></indexterm> +<indexterm><primary><option>-T4</option></primary><see><literal>aggressive</literal> timing template</see></indexterm> +<indexterm><primary><option>-T5</option></primary><see><literal>insane</literal> timing template</see></indexterm> + + +<para>While the fine-grained timing controls discussed in the previous +section are powerful and effective, some people find them confusing. +Moreover, choosing the appropriate values can sometimes take more time +than the scan you are trying to optimize. Fortunately, Nmap offers a simpler +approach, with six timing templates. You can specify them with the +<option>-T</option> option and their number (0–5) or their name. +The template names are +<option>paranoid</option> (<option>0</option>), +<option>sneaky</option> (<option>1</option>), +<option>polite</option> (<option>2</option>), +<option>normal</option> (<option>3</option>), +<option>aggressive</option> (<option>4</option>), +and <option>insane</option> (<option>5</option>). +The first two are for IDS evasion. +Polite mode slows down the scan to use less bandwidth +and target machine resources. Normal mode is the default and so +<option>-T3</option> does nothing. Aggressive mode speeds scans up by +making the assumption that you are on a reasonably fast and reliable +network. Finally +insane mode<indexterm><primary><literal>insane</literal> (<option>-T5</option>) timing template</primary></indexterm> +assumes that you are on an +extraordinarily fast network or are willing to sacrifice some accuracy +for speed.</para> + +<para>These templates allow the user to specify how aggressive they +wish to be, while leaving Nmap to pick the exact timing values. The +templates also make some minor speed adjustments for which +fine-grained control options do not currently exist. For example, +<option>-T4</option><indexterm><primary><literal>aggressive</literal> (<option>-T4</option>) timing template</primary></indexterm> +prohibits the dynamic scan delay from exceeding +10 ms for TCP ports and <option>-T5</option> caps that value at 5 ms. +Templates can be used in combination with fine-grained +controls, and the fine-grained controls that you specify will take +precedence over the timing template default for that parameter. I +recommend using <option>-T4</option> when scanning reasonably modern +and reliable networks. Keep that option even when you add +fine-grained controls so that you benefit from those extra minor +optimizations that it enables.</para> + +<para>If you are on a decent broadband or ethernet connection, I would +recommend always using <option>-T4</option>. Some people love +<option>-T5</option> though it is too aggressive for my taste. People +sometimes specify <option>-T2</option> because they think it is less +likely to crash hosts or because they consider themselves to be polite +in general. They often don't realize just how slow <option>-T +polite</option><indexterm><primary><literal>polite</literal> (<option>-T2</option>) timing template</primary></indexterm> +really is. Their scan may take ten times longer than a +default scan. +Machine crashes and bandwidth problems are rare with the +default timing options (<option>-T3</option>) and so I normally +recommend that for cautious scanners. Omitting version detection is +far more effective than playing with timing values at reducing these +problems.</para> + +<para>While +<option>-T0</option><indexterm><primary><literal>paranoid</literal> (<option>-T0</option>) timing template</primary></indexterm> +and <option>-T1</option><indexterm><primary><literal>sneaky</literal> (<option>-T1</option>) timing template</primary></indexterm> +may be +useful for avoiding IDS alerts, they will take an extraordinarily long +time to scan thousands of machines or ports. For such a long scan, +you may prefer to set the exact timing values you need rather than +rely on the canned <option>-T0</option> and <option>-T1</option> +values.</para> + +<para>The main effects of <option>T0</option> are serializing the scan +so only one port is scanned at a time, and waiting five minutes +between sending each probe. <option>T1</option> and +<option>T2</option> are similar but they only wait 15 seconds and 0.4 +seconds, respectively, between probes. <option>T3</option><indexterm><primary><literal>normal</literal> (<option>-T3</option>) timing template</primary></indexterm> is Nmap's +default behavior, which includes parallelization. +<option>-T4</option> +does the equivalent of <option> + --max-rtt-timeout 1250ms + --min-rtt-timeout 100ms + --initial-rtt-timeout 500ms + --max-retries 6 +</option> and sets the maximum TCP and SCTP scan delay +to 10ms. <option>T5</option> +does the equivalent of +<option> + --max-rtt-timeout 300ms + --min-rtt-timeout 50ms + --initial-rtt-timeout 250ms + --max-retries 2 + --host-timeout 15m + --script-timeout 10m +</option> as well as +setting the maximum TCP and SCTP scan delay to 5ms. +Maximum UDP scan delay is not set by <option>T4</option> or <option>T5</option>, but it can be set with the <option>--max-scan-delay</option> option. +</para> + + </listitem> + </varlistentry> + </variablelist> + <indexterm class="endofrange" startref="man-performance-indexterm"/> + <indexterm class="endofrange" startref="man-performance-timing-indexterm"/> + </refsect1> + + <refsect1 id='man-bypass-firewalls-ids'> + <title>Firewall/IDS Evasion and Spoofing</title> + <indexterm class="startofrange" id="man-bypass-filewalls-indexterm"><primary>firewalls</primary><secondary>bypassing</secondary></indexterm> + <indexterm class="startofrange" id="man-bypass-ids-indexterm"><primary>intrusion detection systems</primary><secondary>evading</secondary></indexterm> + +<para>Many Internet pioneers envisioned a global open network with a +universal IP address space allowing virtual connections between any +two nodes. This allows hosts to act as true peers, serving and +retrieving information from each other. People could access all of +their home systems from work, changing the climate control settings or +unlocking the doors for early guests. This vision of universal +connectivity has been stifled by address space shortages and security +concerns. In the early 1990s, organizations began deploying +firewalls for the express purpose of reducing connectivity. Huge +networks were cordoned off from the unfiltered Internet by application +proxies, network address translation, and packet filters. The +unrestricted flow of information gave way to tight regulation of +approved communication channels and the content that passes over +them.</para> + +<para>Network obstructions such as firewalls can make mapping a +network exceedingly difficult. It will not get any easier, as +stifling casual reconnaissance is often a key goal of implementing the +devices. Nevertheless, Nmap offers many features to help understand these +complex networks, and to verify that filters are working as intended. +It even supports mechanisms for bypassing poorly implemented +defenses. One of the best methods of understanding your +network security posture is to try to defeat it. Place yourself in +the mind-set of an attacker, and deploy techniques from this section +against your networks. Launch an FTP bounce scan, idle scan, +fragmentation attack, or try to tunnel through one of your own +proxies.</para> + +<para>In addition to restricting network activity, companies are +increasingly monitoring traffic with intrusion detection systems +(IDS). All of the major IDSs ship with rules designed to detect Nmap +scans because scans are sometimes a precursor to attacks. Many of +these products have recently morphed into intrusion +<emphasis>prevention</emphasis> systems +(IPS)<indexterm><primary>intrusion prevention systems</primary><seealso>intrusion detection systems</seealso></indexterm> +that actively block +traffic deemed malicious. Unfortunately for network administrators +and IDS vendors, reliably detecting bad intentions by analyzing packet +data is a tough problem. Attackers with patience, skill, and the help +of certain Nmap options can usually pass by IDSs undetected. +Meanwhile, administrators must cope with large numbers of false +positive results where innocent activity is misdiagnosed and alerted +on or blocked.</para> + +<para>Occasionally people suggest that Nmap should not offer features +for evading firewall rules or sneaking past IDSs. They argue +that these features are just as likely to be misused by attackers as +used by administrators to enhance security. The problem with this +logic is that these methods would still be used by attackers, who +would just find other tools or patch the functionality into Nmap. +Meanwhile, administrators would find it that much harder to do their +jobs. Deploying only modern, patched FTP servers is a far more +powerful defense than trying to prevent the distribution of tools +implementing the FTP bounce attack. +</para> + +<para>There is no magic bullet (or Nmap option) for detecting and +subverting firewalls and IDS systems. It takes skill and experience. +A tutorial is beyond the scope of this reference guide, which only +lists the relevant options and describes what they do.</para> + +<variablelist> + <varlistentry> + <term> + <option>-f</option> (fragment packets); + <option>--mtu</option> (using the specified MTU) + <indexterm significance="preferred"><primary><option>-f</option></primary></indexterm> + <indexterm significance="preferred"><primary><option>--mtu</option></primary></indexterm> + </term> + + <listitem> + <para>The <option>-f</option> option causes the requested scan (including + host discovery scans) to use tiny fragmented IP packets. The idea + is to split up the TCP header over several packets to + make it harder for packet filters, intrusion detection + systems, and other annoyances to detect what you are + doing. Be careful with this! Some programs have trouble + handling these tiny packets. The old-school sniffer named + Sniffit segmentation faulted immediately upon receiving + the first fragment. Specify this option once, and Nmap + splits the packets into eight bytes or less after the IP + header. So a 20-byte TCP header would be split into three + packets. Two with eight bytes of the TCP header, and one + with the final four. Of course each fragment also has an + IP header. Specify <option>-f</option> again to use 16 bytes per fragment + (reducing the number of fragments).<indexterm><primary><option>-f</option></primary><secondary>giving twice</secondary></indexterm> + Or you can specify + your own offset size with the <option>--mtu</option> option. Don't also + specify <option>-f</option> if you use <option>--mtu</option>. The offset must be a + multiple of eight. While fragmented packets won't get by + packet filters and firewalls that queue all IP fragments, + such as the <varname>CONFIG_IP_ALWAYS_DEFRAG</varname> option in the Linux + kernel, some networks can't afford the performance hit + this causes and thus leave it disabled. Others can't enable + this because fragments may take different routes into their + networks. Some source + systems defragment outgoing packets in the kernel. Linux + with the + iptables<indexterm><primary>iptables</primary></indexterm> + connection tracking module is one such + example. Do a scan while a sniffer such as + <application>Wireshark</application><indexterm><primary><application>Wireshark</application></primary></indexterm> + is running to ensure that sent packets are fragmented. If your host + OS is causing problems, try the + <option>--send-eth</option><indexterm><primary><option>--send-eth</option></primary></indexterm> + option to bypass the IP layer and send raw ethernet frames.</para> + +<para>Fragmentation is only supported for Nmap's raw packet features, +which includes TCP and UDP port scans (except connect scan and FTP +bounce scan) and OS detection. Features such as version detection and +the Nmap Scripting Engine generally don't support fragmentation +because they rely on your host's TCP stack to communicate with target +services.</para> + + </listitem> + </varlistentry> + + <varlistentry> + <term> + <option>-D <replaceable>decoy1</replaceable><optional>,<replaceable>decoy2</replaceable></optional><optional>,ME</optional><optional>,...</optional></option> + (Cloak a scan with decoys) + <indexterm><primary><option>-D</option></primary></indexterm> + <indexterm><primary>decoys</primary></indexterm> + </term> + <listitem> + <para>Causes a decoy scan to be performed, which makes it + appear to the remote host that the host(s) you specify as + decoys are scanning the target network too. Thus their IDS + might report 5–10 port scans from unique IP addresses, but + they won't know which IP was scanning them and which were + innocent decoys. While this can be defeated through router + path tracing, response-dropping, and other active + mechanisms, it is generally an effective technique for + hiding your IP address.</para> + + <para>Separate each decoy host with commas, and you can + optionally use + <literal>ME</literal><indexterm><primary><literal>ME</literal> (decoy address)</primary></indexterm> + as one of the decoys to + represent the position for your real IP address. If you put + <literal>ME</literal> in the sixth position or later, some + common port scan detectors (such as + Solar Designer's<indexterm><primary>Solar Designer</primary></indexterm> + excellent Scanlogd)<indexterm><primary><application>Scanlogd</application></primary></indexterm> + are unlikely to show your IP address at + all. If you don't use <literal>ME</literal>, Nmap will put + you in a random position. You can also use + <literal>RND</literal><indexterm><primary><literal>RND</literal> (decoy address)</primary></indexterm> + to generate + a random, non-reserved IP address, or <literal>RND:<replaceable>number</replaceable></literal> to + generate <replaceable>number</replaceable> addresses.</para> <para>Note that the hosts + you use as decoys should be up or you might accidentally SYN + flood your targets. Also it will be pretty easy to determine + which host is scanning if only one is actually up on the + network. You might want to use IP addresses instead of names + (so the decoy networks don't see you in their nameserver + logs). Right now random IP address generation is only supported with IPv4</para> + + <para>Decoys are used both in the initial host discovery scan (using + ICMP, SYN, ACK, or whatever) and during the actual port + scanning phase. Decoys are also used during remote OS + detection (<option>-O</option>). Decoys do not work with + version detection or TCP connect scan. When a scan delay is + in effect, the delay is enforced between each batch of + spoofed probes, not between each individual probe. Because + decoys are sent as a batch all at once, they may temporarily + violate congestion control limits.</para> + + <para>It is worth noting that using too many decoys may + slow your scan and potentially even make it less + accurate. Also, some ISPs will filter out your spoofed + packets, but many do not restrict + spoofed IP packets at all.</para> + </listitem> + </varlistentry> + + <varlistentry> + <term> + <option>-S <replaceable>IP_Address</replaceable></option> (Spoof source address) + <indexterm><primary><option>-S</option></primary></indexterm> + <indexterm><primary>spoofing source address</primary></indexterm> + </term> + <listitem> + + <para>In some circumstances, + Nmap may not be able to determine your + source address (Nmap will tell you if this is the + case). In this situation, use <option>-S</option> with the IP address of + the interface you wish to send packets through.</para> + + <para>Another possible use of this flag is to spoof the scan + to make the targets think that <emphasis>someone + else</emphasis> is scanning them. Imagine a company being + repeatedly port scanned by a competitor! The + <option>-e</option> option and <option>-Pn</option> are + generally required for this sort of usage. Note that you + usually won't receive reply packets back (they will be + addressed to the IP you are spoofing), so Nmap won't produce + useful reports.</para> + + </listitem> + </varlistentry> + + <varlistentry> + <term> + <option>-e <replaceable>interface</replaceable></option> (Use specified interface) + <indexterm><primary><option>-e</option></primary></indexterm> + <indexterm><primary>interface</primary><seealso><option>-e</option></seealso></indexterm> + </term> + <listitem> + + <para>Tells Nmap what interface to send and receive + packets on. Nmap should be able to detect this + automatically, but it + will tell you if it cannot.</para> + </listitem> + </varlistentry> + + <varlistentry> + <term> + <option>--source-port <replaceable>portnumber</replaceable>;</option> + <option>-g <replaceable>portnumber</replaceable></option> (Spoof source port number) + <indexterm significance="preferred"><primary><option>--source-port</option></primary></indexterm> + <indexterm significance="preferred"><primary><option>-g</option></primary></indexterm> + <indexterm><primary>source port number</primary></indexterm> + </term> + <listitem> + +<para>One surprisingly common misconfiguration is to trust traffic +based only on the source port number. It is easy to understand how +this comes about. An administrator will set up a shiny new firewall, +only to be flooded with complaints from ungrateful users whose +applications stopped working. In particular, DNS may be broken +because the UDP DNS replies from external servers can no longer enter +the network. FTP is another common example. In active FTP transfers, +the remote server tries to establish a connection back to the client +to transfer the requested file.</para> + +<para>Secure solutions to these problems exist, often in the form of +application-level proxies or protocol-parsing firewall modules. +Unfortunately there are also easier, insecure solutions. Noting that +DNS replies come from port 53 and active FTP from port 20, many administrators +have fallen into the trap of simply allowing incoming traffic from +those ports. They often assume that no attacker would notice and +exploit such firewall holes. In other cases, administrators consider this a +short-term stop-gap measure until they can implement a more secure +solution. Then they forget the security upgrade. +</para> + +<para>Overworked network administrators are not the only ones to fall +into this trap. Numerous products have shipped with these insecure +rules. Even Microsoft has been guilty. The IPsec filters that +shipped with Windows 2000 and Windows XP contain an implicit rule that +allows all TCP or UDP traffic from port 88 (Kerberos). In another well-known +case, versions of the Zone Alarm personal firewall up to 2.1.25 +allowed any incoming UDP packets with the source port 53 (DNS) or 67 +(DHCP).</para> + +<para>Nmap offers the <option>-g</option> and +<option>--source-port</option> options (they are equivalent) to exploit these +weaknesses. Simply provide a port number and Nmap will send packets +from that port where possible. Most scanning operations that use raw sockets, +including SYN and UDP scans, support the option completely. The option notably +doesn't have an effect for any operations that use normal operating system +sockets, including DNS requests, TCP <function>connect</function> +scan,<indexterm><primary>connect scan</primary></indexterm> version detection, +and script scanning. Setting the source port also doesn't work for OS detection, +because Nmap must use different port numbers for certain OS detection tests to +work properly.</para> + + </listitem> + </varlistentry> + + <varlistentry> + <term> + <option>--data <replaceable>hex string</replaceable></option> (Append custom binary data to sent packets) + <indexterm><primary><option>--data</option></primary></indexterm> + </term> + <listitem> + <para> + This option lets you include binary data as payload in sent packets. + <replaceable>hex string</replaceable> may be specified in any of + the following formats: <literal>0xAABBCCDDEEFF<replaceable>...</replaceable></literal>, + <literal>AABBCCDDEEFF<replaceable>...</replaceable></literal> or + <literal>\xAA\xBB\xCC\xDD\xEE\xFF<replaceable>...</replaceable></literal>. + Examples of use are <option>--data 0xdeadbeef</option> and + <option>--data \xCA\xFE\x09</option>. Note that if you specify a + number like <literal>0x00ff</literal> + no byte-order conversion is performed. Make sure you specify + the information in the byte order expected by the receiver. + </para> + </listitem> + </varlistentry> + + + <varlistentry> + <term> + <option>--data-string <replaceable>string</replaceable></option> (Append custom string to sent packets) + <indexterm><primary><option>--data-string</option></primary></indexterm> + </term> + <listitem> + <para> + This option lets you include a regular string as payload in + sent packets. <replaceable>string</replaceable> can + contain any string. However, note that some characters + may depend on your system's locale and the receiver may not + see the same information. Also, make sure you enclose the string + in double quotes and escape any special characters from the shell. + Examples: <option>--data-string "Scan conducted by Security Ops, extension 7192"</option> + or <option>--data-string "Ph34r my l33t skills"</option>. + Keep in mind that nobody is likely to actually see any comments left by this option + unless they are carefully monitoring the network with a sniffer or custom IDS rules. + </para> + </listitem> + </varlistentry> + + <varlistentry> + <term> + <option>--data-length <replaceable>number</replaceable></option> (Append random + data to sent packets) + <indexterm><primary><option>--data-length</option></primary></indexterm> + </term> + <listitem> + <para>Normally Nmap sends minimalist packets containing only + a header. So its TCP packets are generally 40 + bytes and ICMP echo requests are just 28. Some + UDP ports<indexterm><primary>protocol-specific payloads</primary><secondary>UDP</secondary></indexterm> + and IP protocols<indexterm><primary>protocol-specific payloads</primary><secondary>IP</secondary></indexterm> + get a custom payload by default. + This option + tells Nmap to append the given number of random bytes to + most of the packets it sends, and not to use any + protocol-specific payloads. (Use <option>--data-length 0</option> + for no random or protocol-specific + payloads.<indexterm><primary>protocol-specific payloads</primary><secondary>disabling with <option>--data-length</option></secondary></indexterm> + OS detection (<option>-O</option>) packets + are not affected<indexterm><primary><option>--data-length</option></primary><secondary>no effect in OS detection</secondary></indexterm> + because accuracy there requires probe consistency, but most pinging and portscan packets + support this. It slows things down a little, but can make a scan slightly less + conspicuous.</para> + </listitem> + </varlistentry> + + <varlistentry> + <term> + <option>--ip-options <replaceable>R|S [route]|L [route]|T|U ... </replaceable>;</option> + <option>--ip-options <replaceable>hex string</replaceable></option> (Send packets with specified ip options) + <indexterm><primary><option>--ip-options</option></primary></indexterm> + <indexterm><primary>IP options</primary></indexterm> + </term> + <listitem> + <para>The <ulink role="hidepdf" url="http://www.rfc-editor.org/rfc/rfc791.txt">IP + protocol</ulink> offers several options which may be placed in + packet headers. Unlike the ubiquitous TCP options, IP options + are rarely seen due to practicality and security concerns. In + fact, many Internet routers block the most dangerous options + such as source routing. Yet options can still be useful in some + cases for determining and manipulating the network route to + target machines. For example, you may be able to use the record + route option to determine a path to a target even when more + traditional traceroute-style approaches fail. Or if your + packets are being dropped by a certain firewall, you may be able + to specify a different route with the strict or loose source + routing options.</para> + + <para>The most powerful way to specify IP options is to simply + pass in values as the argument to + <option>--ip-options</option>. Precede each hex number with + <literal>\x</literal> then the two digits. You may repeat + certain characters by following them with an asterisk and then + the number of times you wish them to repeat. For example, + <literal>\x01\x07\x04\x00*36\x01</literal> is a hex string + containing 36 NUL bytes.</para> + + <para>Nmap also offers a shortcut mechanism for specifying + options. Simply pass the letter <literal>R</literal>, + <literal>T</literal>, or <literal>U</literal> to request + record-route,<indexterm><primary>record route IP option</primary></indexterm> + record-timestamp,<indexterm><primary>record timestamp IP option</primary></indexterm> + or both options together, + respectively. + Loose or strict source routing<indexterm><primary>source routing</primary></indexterm> + may be specified + with an <literal>L</literal> or <literal>S</literal> followed by + a space and then a space-separated list of IP addresses.</para> + + <para>If you wish to see the options in packets sent and + received, specify <option>--packet-trace</option>. For more + information and examples of using IP options with Nmap, see + <ulink url="https://seclists.org/nmap-dev/2006/q3/52"/>. + </para> + + </listitem> + </varlistentry> + + <varlistentry> + <term> + <option>--ttl <replaceable>value</replaceable></option> (Set IP time-to-live field) + <indexterm><primary><option>--ttl</option></primary></indexterm> + <indexterm><primary>time to live (TTL)</primary></indexterm> + </term> + <listitem> + + <para>Sets the IPv4 time-to-live field in sent packets to + the given value.</para> + </listitem> + </varlistentry> + + <varlistentry> + <term> + <option>--randomize-hosts</option> (Randomize target host order) + <indexterm significance="preferred"><primary><option>--randomize-hosts</option></primary></indexterm> + <indexterm><primary>randomization of hosts</primary></indexterm> + </term> + <listitem> + + <para>Tells Nmap to shuffle each group of up to 16384 hosts + before it scans them. This can make the scans less obvious + to various network monitoring systems, especially when you + combine it with slow timing options. If you + want to randomize over larger group sizes, increase + <varname>PING_GROUP_SZ</varname><indexterm><primary><varname>PING_GROUP_SZ</varname></primary></indexterm> + in <filename>nmap.h</filename><indexterm><primary><filename>nmap.h</filename></primary></indexterm> + and recompile. + An alternative solution is to generate the target IP list + with a list scan (<option>-sL -n -oN + <replaceable>filename</replaceable></option>), randomize it + with a Perl script, then provide the whole list to Nmap with + <option>-iL</option>.<indexterm><primary><option>-iL</option></primary><secondary>randomizing hosts with</secondary></indexterm> + </para> + </listitem> + </varlistentry> + + <varlistentry> + <term> + <option>--spoof-mac <replaceable>MAC address, prefix, or vendor + name</replaceable></option> (Spoof MAC address) + <indexterm significance="preferred"><primary><option>--spoof-mac</option></primary></indexterm> + <indexterm><primary>spoofing MAC address</primary></indexterm> + </term> + <listitem> + + <para>Asks Nmap to use the given MAC address + <indexterm><primary>MAC address</primary></indexterm> + for all of the raw ethernet frames it sends. This option implies + <option>--send-eth</option><indexterm><primary><option>--send-eth</option></primary><secondary>implied by <option>--spoof-mac</option></secondary></indexterm> + to ensure that Nmap actually sends + ethernet-level packets. The MAC given can take several formats. If + it is simply the number <literal>0</literal>, Nmap chooses a completely random MAC address + for the session. If the given string is an even number of hex + digits (with the pairs optionally separated by a colon), Nmap will + use those as the MAC. If fewer than 12 hex digits are provided, Nmap + fills in the remainder of the six bytes with random values. If the + argument isn't a zero or hex string, Nmap looks through + <filename>nmap-mac-prefixes</filename> to find a vendor name containing the given string + (it is case insensitive). If a match is found, Nmap uses the + vendor's OUI (three-byte prefix)<indexterm><primary>organizationally unique identifier (OUI)</primary><seealso><filename>nmap-mac-prefixes</filename></seealso></indexterm> + and fills out the remaining three bytes + randomly. Valid <option>--spoof-mac</option> argument examples are <literal>Apple</literal>, <literal>0</literal>, + <literal>01:02:03:04:05:06</literal>, <literal>deadbeefcafe</literal>, <literal>0020F2</literal>, and <literal>Cisco</literal>. This option only affects raw packet scans such as SYN scan or OS detection, not connection-oriented features such as version detection or the Nmap Scripting Engine.</para> + + </listitem> + </varlistentry> + + <varlistentry> + <term> + <option>--proxies <replaceable>Comma-separated list of proxy + URLs</replaceable></option> (Relay TCP connections through a chain of + proxies) + + <indexterm significance="preferred"><primary><option>--proxies</option></primary></indexterm> + <indexterm><primary>proxy</primary></indexterm> + <indexterm><primary>proxies</primary></indexterm> + </term> + <listitem> + + <para>Asks Nmap to establish TCP connections with a final + target through supplied chain of one or more HTTP or SOCKS4 + proxies<indexterm><primary>proxies</primary></indexterm>. Proxies + can help hide the true source of a scan or evade certain + firewall restrictions, but they can hamper scan performance + by increasing latency. Users may need to adjust Nmap + timeouts and other scan parameters accordingly. In + particular, a lower <option>--max-parallelism</option> may + help because some proxies refuse to handle as many + concurrent connections as Nmap opens by default.</para> + + <para>This option takes a list of proxies as argument, expressed as + URLs in the format <literal>proto://host:port</literal>. Use commas to separate + node URLs in a chain. No authentication is supported yet. Valid + protocols are <literal>HTTP</literal> and <literal>SOCKS4</literal>. + </para> + + <para>Warning: this feature is still under development and has + limitations. It is implemented within the nsock library and thus has + no effect on the ping, port scanning and OS discovery phases + of a scan. Only NSE and version scan benefit from this + option so far—other features may disclose your true address. SSL + connections are not yet supported, nor is proxy-side DNS + resolution (hostnames are always resolved by Nmap).</para> + </listitem> + </varlistentry> + + <varlistentry> + <term> + <option>--badsum</option> (Send packets with bogus TCP/UDP checksums) + <indexterm><primary><option>--badsum</option></primary></indexterm> + <indexterm><primary>TCP checksum</primary></indexterm> + <indexterm><primary>checksums</primary></indexterm> + </term> + <listitem> + + + <para>Asks Nmap to use an invalid TCP, UDP or SCTP checksum for + packets sent to target hosts. Since virtually all + host IP stacks properly drop these packets, any responses received + are likely coming from a firewall or IDS that didn't bother to + verify the checksum. For more details on this technique, see <ulink + url="https://nmap.org/p60-12.html"/></para> + </listitem> + </varlistentry> + + <varlistentry> + <term> + <option>--adler32</option> (Use deprecated Adler32 instead of CRC32C for SCTP checksums) + <indexterm><primary><option>--adler32</option></primary></indexterm> + <indexterm><primary>CRC32C checksum</primary></indexterm> + <indexterm><primary>Adler32 checksum</primary></indexterm> + <indexterm><primary>SCTP checksum</primary></indexterm> + </term> + <listitem> + + + <para>Asks Nmap to use the deprecated Adler32 algorithm + for calculating the SCTP checksum. If <option>--adler32</option> + is not given, CRC-32C (Castagnoli) is used. + <ulink role="hidepdf" url="http://www.rfc-editor.org/rfc/rfc2960.txt">RFC 2960</ulink> + originally defined Adler32 as checksum algorithm for SCTP; + <ulink role="hidepdf" url="http://www.rfc-editor.org/rfc/rfc4960.txt">RFC 4960</ulink> + later redefined the SCTP checksums to use CRC-32C. Current SCTP + implementations should be using CRC-32C, but in order to elicit + responses from old, legacy SCTP implementations, it may be + preferable to use Adler32.</para> + </listitem> + </varlistentry> + + </variablelist> + + <indexterm class="endofrange" startref="man-bypass-ids-indexterm"/> + <indexterm class="endofrange" startref="man-bypass-filewalls-indexterm"/> + </refsect1> + + <refsect1 id='man-output'> + <title>Output</title> + <indexterm class="startofrange" id="man-output-indexterm"><primary>output formats</primary></indexterm> + + <para>Any security tool is only as useful as the output it + generates. Complex tests and algorithms are of little value if + they aren't presented in an organized and comprehensible fashion. + Given the number of ways Nmap is used by people and other + software, no single format can please everyone. So Nmap offers + several formats, including the interactive mode for humans to read + directly and XML for easy parsing by software.</para> + +<para>In addition to offering different output formats, Nmap provides +options for controlling the verbosity of output as well as debugging +messages. Output types may be sent to standard output or to named +files, which Nmap can append to or clobber. Output files may also be +used to resume aborted scans.</para> + +<para>Nmap makes output available in five different formats. +The default is called +<firstterm>interactive output</firstterm>,<indexterm><primary>interactive output</primary></indexterm> +and it is sent to +standard output (stdout).<indexterm><primary>standard output</primary></indexterm> +There is also +<firstterm>normal output</firstterm>,<indexterm><primary>normal output</primary></indexterm> +which is similar to interactive except that it +displays less runtime information and warnings since it is expected to +be analyzed after the scan completes rather than interactively.</para> + +<para><firstterm>XML output</firstterm><indexterm><primary>XML output</primary></indexterm> +is one of the most important output types, as it can +be converted to HTML, easily parsed by programs such as Nmap graphical +user interfaces, or imported into databases.</para> + +<para>The two remaining output types are the simple +<firstterm>grepable output</firstterm><indexterm><primary>grepable output</primary></indexterm> +which includes most information for a target host on +a single line, and +<firstterm>sCRiPt KiDDi3 0utPUt</firstterm><indexterm><primary sortas="script kiddie output">scR1pT kIddI3 output</primary></indexterm> +for users +who consider themselves |<-r4d.</para> + +<para>While interactive output is the default and has no associated +command-line options, the other four format options use the same +syntax. They take one argument, which is the filename that results +should be stored in. Multiple formats may be specified, but each +format may only be specified once. For example, you may wish to save +normal output for your own review while saving XML of the same scan +for programmatic analysis. You might do this with the options +<option>-oX myscan.xml -oN myscan.nmap</option>. While this chapter +uses the simple names like <literal>myscan.xml</literal> for brevity, +more descriptive names are generally recommended. The names chosen +are a matter of personal preference, though I use long ones that +incorporate the scan date and a word or two describing the scan, placed +in a directory named after the company I'm scanning.</para> + +<para>While these options save results to files, Nmap still prints +interactive output to stdout as usual. For example, the command +<command>nmap -oX myscan.xml target</command> prints XML to +<filename>myscan.xml</filename> and fills standard output with the same interactive results it would have printed if <option>-oX</option> +wasn't specified at all. You can change this by passing a hyphen +character as the argument to one of the format types. This causes +Nmap to deactivate interactive output, and instead print +results in the format you specified to the standard output stream. So the +command <command>nmap -oX - target</command> will send only XML output to +stdout.<indexterm><primary>output</primary><secondary>to stdout with <literal>-</literal></secondary></indexterm> +Serious errors may still be printed to the normal error +stream, stderr.<indexterm><primary>standard error</primary></indexterm> +</para> + +<para>Unlike some Nmap arguments, the space between the logfile option +flag (such as <option>-oX</option>) and the filename or hyphen is +mandatory. If you omit the flags and give arguments such as +<option>-oG-</option> or <option>-oXscan.xml</option>, a backwards +compatibility feature of Nmap will cause the creation of +<emphasis>normal format</emphasis> output files named +<filename>G-</filename> and <filename>Xscan.xml</filename> +respectively.</para> + +<para>All of these arguments support +<function>strftime</function>-like<indexterm><primary><function>strftime</function> conversions in filenames</primary></indexterm> +conversions in the filename. <literal>%H</literal>, <literal>%M</literal>, +<literal>%S</literal>, <literal>%m</literal>, <literal>%d</literal>, +<literal>%y</literal>, and <literal>%Y</literal> are all exactly the same +as in <function>strftime</function>. <literal>%T</literal> is the same +as <literal>%H%M%S</literal>, <literal>%R</literal> is the same as +<literal>%H%M</literal>, and <literal>%D</literal> is the same as +<literal>%m%d%y</literal>. A <literal>%</literal> followed by any other +character just yields that character (<literal>%%</literal> gives you a +percent symbol). So <option>-oX 'scan-%T-%D.xml'</option> will use an XML +file with a name in the form of <filename>scan-144840-121307.xml</filename>.</para> + +<para>Nmap also offers options to control scan verbosity and to append +to output files rather than clobbering them. All of these options are +described below.</para> + +<variablelist><title>Nmap Output Formats</title> + <varlistentry> + <term> + <option>-oN <replaceable>filespec</replaceable></option> (normal output) + <indexterm><primary><option>-oN</option></primary></indexterm> + <indexterm><primary>normal output</primary></indexterm></term> + <listitem> + + <para>Requests that normal output be + directed to the given filename. As discussed above, this + differs slightly from <literal>interactive output</literal>.</para> + </listitem> + </varlistentry> + + <varlistentry> + <term> + <option>-oX <replaceable>filespec</replaceable></option> (XML output) + <indexterm><primary><option>-oX</option></primary></indexterm> + <indexterm><primary>XML output</primary></indexterm></term> + <listitem> + + + <para>Requests that XML output be + directed to the given filename. Nmap includes a document + type definition (DTD) which allows XML parsers to validate + Nmap XML output. While it is primarily intended for + programmatic use, it can also help humans interpret Nmap XML + output. The DTD defines the legal elements of the format, + and often enumerates the attributes and values they can take + on. The latest version is always available from <ulink + url="https://svn.nmap.org/nmap/docs/nmap.dtd"/>.</para> + + <para>XML offers a stable format that is easily parsed by + software. Free XML parsers are available for all major + computer languages, including C/C++, Perl, Python, and + Java. People have even written bindings for most of these + languages to handle Nmap output and execution specifically. + Examples are + <ulink url="http://sourceforge.net/projects/nmap-scanner/">Nmap::Scanner</ulink><indexterm><primary>Nmap::Scanner</primary></indexterm> + and + <ulink url="http://nmapparser.wordpress.com/">Nmap::Parser</ulink><indexterm><primary>Nmap::Parser</primary></indexterm> + in Perl + CPAN. In almost all cases that a non-trivial application + interfaces with Nmap, XML is the preferred format.</para> + + <para>The XML output references an XSL stylesheet which can + be used to format the results as HTML. The easiest way to + use this is simply to load the XML output in a web browser + such as Firefox or IE. By default, this will only work on + the machine you ran Nmap on (or a similarly configured one) + due to the hard-coded <filename>nmap.xsl</filename> + filesystem path. Use the <option>--webxml</option> or + <option>--stylesheet</option> options to create portable XML + files that render as HTML on any web-connected + machine.</para> + + </listitem> + </varlistentry> + + <varlistentry> + <term> + <option>-oS <replaceable>filespec</replaceable></option> (ScRipT KIdd|3 oUTpuT) + <indexterm><primary><option>-oS</option></primary></indexterm> + <indexterm><primary sortas="script kiddie output">scR1pT kIddI3 output</primary></indexterm></term> + <listitem> + + <para>Script kiddie output is like interactive output, except that + it is post-processed to better suit the l33t HaXXorZ who + previously looked down on Nmap due to its consistent capitalization + and spelling. Humor impaired people should note that this option + is making fun of the script kiddies before flaming me for + supposedly <quote>helping them</quote>.</para> + </listitem> + </varlistentry> + + <varlistentry> + <term> + <option>-oG <replaceable>filespec</replaceable></option> (grepable output) + <indexterm><primary><option>-oG</option></primary></indexterm> + <indexterm><primary>grepable output</primary></indexterm></term> + <listitem> + + +<para>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.</para> + +<para>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.</para> + +<para>Grepable output consists of comments (lines starting with a +pound (#))<indexterm><primary>grepable output</primary><secondary>comments in</secondary></indexterm> +and target lines. A target line includes a combination +of six labeled fields, separated by tabs and followed with a colon. +The fields are <literal>Host</literal>, <literal>Ports</literal>, +<literal>Protocols</literal>, <literal>Ignored State</literal>, +<literal>OS</literal>, <literal>Seq Index</literal>, +<literal>IP ID</literal>, and <literal>Status</literal>.</para> + +<para>The most important of these fields is generally +<literal>Ports</literal>, 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: <literal>Port +number</literal>, <literal>State</literal>, <literal>Protocol</literal>, +<literal>Owner</literal>, <literal>Service</literal>, <literal>SunRPC +info</literal>, and <literal>Version info</literal>.</para> + +<para>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 +<man>from <ulink url="https://nmap.org/book/output-formats-grepable-output.html" />.</man> +<notman>in <xref linkend="output-formats-grepable-output"/>.</notman> +</para> + </listitem> + </varlistentry> + + <varlistentry> + <term> + <option>-oA <replaceable>basename</replaceable></option> (Output to all formats) + <indexterm significance="preferred"><primary><option>-oA</option></primary></indexterm></term> + <listitem><para> + + As a convenience, you may specify <option>-oA + <replaceable>basename</replaceable></option> to store scan + results in normal, XML, and grepable formats at once. They + are stored in + <filename><replaceable>basename</replaceable>.nmap</filename>, + <filename><replaceable>basename</replaceable>.xml</filename>, and + <filename><replaceable>basename</replaceable>.gnmap</filename>, + respectively. As with most programs, you can prefix the filenames + with a directory path, such as + <filename>~/nmaplogs/foocorp/</filename> on Unix or + <filename>c:\hacking\sco</filename> on Windows.</para> + </listitem> + </varlistentry> + + </variablelist> + + <variablelist><title>Verbosity and debugging options</title> + <varlistentry> + <term> + <option>-v</option> (Increase verbosity level) + <indexterm><primary><option>-v</option></primary></indexterm> + <indexterm><primary>verbosity</primary></indexterm> + </term> + <term> + <option>-v<replaceable>level</replaceable></option> (Set verbosity level) + </term> + <listitem> + + <para>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: <option>-vv</option>, or give a verbosity level + directly, for example <option>-v3</option>.<indexterm><primary><option>-v</option></primary><secondary>giving more than once</secondary></indexterm> + </para> + + <para>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.</para> + + </listitem> + </varlistentry> + + <varlistentry> + <term> + <option>-d</option> (Increase debugging level) + <indexterm><primary><option>-d</option></primary></indexterm> + <indexterm><primary>debugging</primary></indexterm> + </term> + <term> + <option>-d<replaceable>level</replaceable></option> (Set debugging level) + </term> + <listitem> + + +<para>When even verbose mode doesn't provide sufficient data for you, +debugging is available to flood you with much more! As with the +verbosity option (<option>-v</option>), debugging is enabled with a +command-line flag (<option>-d</option>) and the debug level can be +increased by specifying it +multiple times,<indexterm><primary><option>-d</option></primary><secondary>giving more than once</secondary></indexterm> +as in <option>-dd</option>, or by setting a level directly. For +example, <option>-d9</option> sets level nine. That is the highest +effective level and will produce thousands of lines unless you run a +very simple scan with very few ports and targets.</para> + +<para>Debugging output is useful when a bug is suspected in Nmap, +or if you are simply confused as to what Nmap is doing and why. As this +feature is mostly intended for developers, debug lines aren't always +self-explanatory. You may get something like: <computeroutput>Timeout +vals: srtt: -1 rttvar: -1 to: 1000000 delta 14987 ==> srtt: 14987 +rttvar: 14987 to: 100000</computeroutput>. If you don't understand a line, your only recourses +are to ignore it, look it up in the source code, or request help from +the development list +(<citetitle>nmap-dev</citetitle>).<indexterm><primary><citetitle>nmap-dev</citetitle> mailing list</primary></indexterm> +Some lines are self explanatory, but +the messages become more obscure as the debug level is +increased.</para> + + </listitem> + </varlistentry> + +<varlistentry> + <term> + <option>--reason</option> (Host and port state reasons) + <indexterm><primary><option>--reason</option></primary></indexterm> + <indexterm><primary>reason reporting</primary><see><option>--reason</option></see></indexterm> + </term> + <listitem> + +<para> +Shows the reason each port is set to a specific state and the reason +each host is up or down. This option displays the type of the packet +that determined a port or hosts state. For example, A <literal>RST</literal> packet from +a closed port or an echo reply from an alive host. The information +Nmap can provide is determined by the type of scan or ping. The SYN +scan and SYN ping (<option>-sS</option> and <option>-PS</option>) are very detailed, but the +TCP connect scan (<option>-sT</option>) is limited by the +implementation of the <function>connect</function> system call. This feature is automatically enabled by +the debug option +(<option>-d</option>)<indexterm><primary><option>--reason</option></primary><secondary>implied by <option>-d</option></secondary></indexterm> +and the results are stored in XML log files +even if this option is not specified. + +</para> +</listitem> +</varlistentry> + + <varlistentry> + <term> + <option>--stats-every <replaceable>time</replaceable></option> (Print periodic timing stats) + <indexterm><primary><option>--stats-every</option></primary></indexterm> + </term> + <listitem> + <para> + Periodically prints a timing status message after each + interval of <replaceable>time</replaceable>. The time is a + specification of the kind described in + <xref linkend="man-performance"/>; so for example, use + <option>--stats-every 10s</option> to get a status update + every 10 seconds. Updates are printed to interactive output + (the screen) and XML output. + </para> + </listitem> + </varlistentry> + + <varlistentry> + <term> + <option>--packet-trace</option> (Trace packets and data sent and received) + <indexterm><primary><option>--packet-trace</option></primary></indexterm> + </term> + <listitem> + + <para>Causes Nmap to print a summary of every packet sent + or received. This is often used for debugging, but is + also a valuable way for new users to understand exactly + what Nmap is doing under the covers. To avoid printing + thousands of lines, you may want to specify a limited + number of ports to scan, such as <option>-p20-30</option>. If you only care + about the goings on of the version detection subsystem, use + <option>--version-trace</option> instead. If you only care about script tracing, + specify <option>--script-trace</option>. With <option>--packet-trace</option>, you get + all of the above.</para> + </listitem> + </varlistentry> + + <varlistentry> + <term> + <option>--open</option> (Show only open (or possibly open) ports) + <indexterm><primary><option>--open</option></primary></indexterm> + </term> + <listitem> + +<para>Sometimes you only care about ports you can actually connect to +(<literal>open</literal> ones), and don't want results cluttered with +<literal>closed</literal>, <literal>filtered</literal>, and +<literal>closed|filtered</literal> ports. Output customization is +normally done after the scan using tools such as +<application>grep</application>, <application>awk</application>, and +<application>Perl</application>, but this feature was added due to +overwhelming requests. Specify <option>--open</option> to only see +hosts with at least one +<literal>open</literal>, <literal>open|filtered</literal>, or +<literal>unfiltered</literal> port, and only see ports in those states. These three states are treated just as they normally are, which means that <literal>open|filtered</literal> and <literal>unfiltered</literal> may be condensed into counts if there are an overwhelming number of them. +</para> + +<para>Beginning with Nmap 7.40, the <option>--open</option> option implies + <indexterm><primary><option>--defeat-rst-ratelimit</option></primary></indexterm> + <option>--defeat-rst-ratelimit</option>, because that option only affects + <literal>closed</literal> and <literal>filtered</literal> ports, which are + hidden by <option>--open</option>. +</para> + + </listitem> + </varlistentry> + + <varlistentry> + <term> + <option>--iflist</option> (List interfaces and routes) + <indexterm><primary><option>--iflist</option></primary></indexterm> + </term><listitem> + <para>Prints the interface list and system routes as detected + by Nmap and quits. This is useful for debugging routing problems or + device mischaracterization (such as Nmap treating a PPP + connection as ethernet).</para> </listitem> </varlistentry> + + </variablelist> + + <variablelist><title>Miscellaneous output options</title> + + <varlistentry> + <term> + <option>--append-output</option> (Append to rather than clobber output files) + <indexterm><primary><option>--append-output</option></primary></indexterm> + </term> + <listitem> + + <para>When you specify a filename to an output format flag + such as <option>-oX</option> or <option>-oN</option>, that + file is overwritten by default. If you prefer to keep the + existing content of the file and append the new results, + specify the <option>--append-output</option> option. All + output filenames specified in that Nmap execution will then + be appended to rather than clobbered. This doesn't work + well for XML (<option>-oX</option>) scan data as the + resultant file generally won't parse properly until you fix + it up by hand.</para> + </listitem> + </varlistentry> + + <varlistentry> + <term> + <option>--resume <replaceable>filename</replaceable></option> (Resume aborted scan) + <indexterm><primary><option>--resume</option></primary></indexterm> + <indexterm><primary>resuming scans</primary></indexterm> + </term> + <listitem> + + + <para>Some extensive Nmap runs take a very long time—on + the order of days. Such scans don't always run to + completion. Restrictions may prevent Nmap from being run + during working hours, the network could go down, the machine + Nmap is running on might suffer a planned or unplanned + reboot, or Nmap itself could crash. The administrator running Nmap + could cancel it for any other reason as well, by pressing + <keycap>ctrl-C</keycap>. Restarting the whole scan from the + beginning may be undesirable. Fortunately, if scan output + files were kept, the user can ask Nmap to resume scanning + with the target it was working on when execution ceased. + Simply specify the <option>--resume</option> option and pass + the output file as its argument. No other + arguments are permitted, as Nmap parses the output file to + use the same ones specified previously. Simply call Nmap as + <command>nmap --resume + <replaceable>logfilename</replaceable></command>. Nmap will + append new results to the data files specified in the + previous execution. Scans can be resumed from any of the 3 major + output formats: Normal, Grepable, or XML</para> + </listitem> + </varlistentry> + + <varlistentry> + <term> + <option>--noninteractive</option> (Disable runtime interactions) + <indexterm><primary><option>--noninteractive</option></primary></indexterm> + <indexterm><primary>runtime interaction</primary><secondary>disabling</secondary></indexterm> + </term> + <listitem> + + <para>At times, such as when running Nmap in a shell background, + it might be undesirable for Nmap to monitor and respond to user + keyboard input when running. (See + <xref linkend="man-runtime-interaction"/> about how to control + Nmap during a scan.) Use option <option>--noninteractive</option> + to prevent Nmap taking control of the terminal.</para> + </listitem> + </varlistentry> + + <varlistentry> + <term> + <option>--stylesheet <replaceable>path or URL</replaceable></option> (Set XSL stylesheet to transform XML output) + <indexterm significance="preferred"><primary><option>--stylesheet</option></primary></indexterm> + </term> + <listitem> + + <para>Nmap ships with an XSL<indexterm><primary>XSL</primary></indexterm> + stylesheet<indexterm><primary>stylesheet</primary></indexterm> + named <filename>nmap.xsl</filename><indexterm><primary><filename>nmap.xsl</filename></primary></indexterm> + for viewing or translating XML output to HTML.<indexterm><primary>HTML from XML output</primary></indexterm> + The XML output includes an <literal>xml-stylesheet</literal> + directive which points to <filename>nmap.xml</filename> + where it was initially installed by Nmap. Run the XML file + through an XSLT processor such as + <ulink url="http://xmlsoft.org/XSLT/">xsltproc</ulink><indexterm><primary>xsltproc</primary></indexterm> + to produce an HTML file. Directly opening the XML file in a + browser no longer works well because modern browsers limit the + locations a stylesheet may be loaded from. + If you wish to use a different + stylesheet, specify it as the argument to + <option>--stylesheet</option>. You must pass the full + pathname or URL. One common invocation is + <option>--stylesheet + https://nmap.org/svn/docs/nmap.xsl</option>. This + tells an XSLT processor to load the latest version of the stylesheet + from Nmap.Org. The <option>--webxml</option> option + does the same thing with less typing and memorization. + Loading the XSL from Nmap.Org makes it easier to view results on + a machine that doesn't have Nmap (and thus + <filename>nmap.xsl</filename>) installed. So the URL is + often more useful, but the local filesystem location of + <filename>nmap.xsl</filename> is used by default for privacy reasons.</para> + </listitem> + </varlistentry> + + <varlistentry> + <term> + <option>--webxml</option> (Load stylesheet from Nmap.Org) + <indexterm significance="preferred"><primary><option>--webxml</option></primary></indexterm> + </term> + <listitem> + + <para>This is a convenience option, nothing more than an alias for + <option significance="preferred">--stylesheet https://nmap.org/svn/docs/nmap.xsl</option>.</para> + </listitem> + </varlistentry> + + <varlistentry> + <term> + <option significance="preferred">--no-stylesheet</option> (Omit XSL stylesheet declaration from XML) + <indexterm significance="preferred"><primary><option>--no-stylesheet</option></primary></indexterm> + </term> + <listitem> + + <para>Specify this option to prevent Nmap from associating any XSL + stylesheet with its XML output. The <literal>xml-stylesheet</literal> directive + is omitted.</para> + </listitem> + </varlistentry> + + + + </variablelist> + <indexterm class="endofrange" startref="man-output-indexterm"/> + </refsect1> + + <refsect1 id='man-misc-options'> + <title>Miscellaneous Options</title> + <para>This section describes some important (and not-so-important) + options that don't really fit anywhere else.</para> + + <variablelist> + <varlistentry> + <term> + <option>-6</option> (Enable IPv6 scanning) + <indexterm significance="preferred"><primary><option>-6</option></primary></indexterm> + <indexterm><primary>IPv6</primary></indexterm> + </term> + <listitem> + + <para>Nmap has IPv6 support for its most + popular features. Ping scanning, + port scanning, version detection, and the Nmap Scripting + Engine all support IPv6. The command syntax is the same as + usual except that you also add the <option>-6</option> + option. Of course, you must use IPv6 syntax if you specify + an address rather than a hostname. An address might look + like + <literal>3ffe:7501:4819:2000:210:f3ff:fe03:14d0</literal>, + so hostnames are recommended. The output looks the same as + usual, with the IPv6 address on the <quote>interesting + ports</quote> line being the only IPv6 giveaway.</para> + + <para>While IPv6 hasn't exactly taken the world by storm, it + gets significant use in some (usually Asian) countries and + most modern operating systems support it. To use Nmap with + IPv6, both the source and target of your scan must be + configured for IPv6. If your ISP (like most of them) does + not allocate IPv6 addresses to you, free tunnel brokers are + widely available and work fine with Nmap. I use the free + IPv6 tunnel broker<indexterm><primary>IPv6 tunnel broker</primary></indexterm> + service at <ulink url="http://www.tunnelbroker.net"/>. + Other tunnel brokers are + <ulink url="http://en.wikipedia.org/wiki/List_of_IPv6_tunnel_brokers">listed + at Wikipedia</ulink>. 6to4 tunnels are another popular, + free approach.</para> + + <para>On Windows, raw-socket IPv6 scans are supported only on + ethernet devices (not tunnels), and only on Windows + Vista<indexterm><primary>Windows Vista</primary></indexterm> + and later. Use the + <option>--unprivileged</option><indexterm><primary><option>--unprivileged</option></primary></indexterm> + option in other situations.</para> + + </listitem> + </varlistentry> + + <varlistentry> + <term> + <option>-A</option> (Aggressive scan options) + <indexterm significance="preferred"><primary><option>-A</option></primary></indexterm> + </term> + <listitem> + <para>This option enables additional advanced and aggressive + options. Presently this enables OS detection + (<option>-O</option>), version scanning + (<option>-sV</option>), script scanning + (<option>-sC</option>) and traceroute + (<option>--traceroute</option>).<indexterm><primary><option>-A</option></primary><secondary>features + enabled by</secondary></indexterm> More features may be + added in the future. The point is to enable a comprehensive + set of scan options without people having to remember a + large set of flags. However, because script scanning with + the default set is considered intrusive, you should not use + <option>-A</option> against target networks without + permission. This option only enables features, and not + timing options (such as <option>-T4</option>) or verbosity + options (<option>-v</option>) that you might want as + well. Options which require privileges (e.g. root access) + such as OS detection and traceroute will only be enabled + if those privileges are available.</para> + </listitem> + </varlistentry> + + <varlistentry> + <term> + <option>--datadir <replaceable>directoryname</replaceable></option> (Specify custom Nmap data file location) + <indexterm significance="preferred"><primary><option>--datadir</option></primary></indexterm> + </term> + <listitem> + + <para>Nmap obtains some special data at runtime in files + named <filename>nmap-service-probes</filename>, + <filename>nmap-services</filename>, + <filename>nmap-protocols</filename>, + <filename>nmap-rpc</filename>, + <filename>nmap-mac-prefixes</filename>, and + <filename>nmap-os-db</filename>. If the + location of any of these files has been specified (using the + <option>--servicedb</option> or <option>--versiondb</option> options), + that location is used for that file. After that, Nmap + searches these files in the directory specified with the + <option>--datadir</option> option (if any). Any files not + found there, are searched for in the directory specified by + the + <envar>NMAPDIR</envar><indexterm><primary><envar>NMAPDIR</envar> environment variable</primary></indexterm> + environment variable. + Next comes + <filename>~/.nmap</filename><indexterm><primary sortas="nmap directory"><filename>.nmap</filename> directory</primary></indexterm> + for real and effective UIDs; or on Windows, + <filename><replaceable>HOME</replaceable>\AppData\Roaming\nmap</filename> + (where <replaceable>HOME</replaceable> is the user's home directory, + like <filename>C:\Users\user</filename>). This is + followed by the location of the <filename>nmap</filename> + executable and the same location with + <code>../share/nmap</code> appended. Then a compiled-in + location such as <filename>/usr/local/share/nmap</filename> or <filename>/usr/share/nmap</filename>. + </para> + </listitem> + </varlistentry> + + <varlistentry> + <term> + <option>--servicedb <replaceable>services file</replaceable></option> (Specify custom services file) + <indexterm significance="preferred"><primary><option>--servicedb</option></primary></indexterm> + </term> + <listitem> + + <para>Asks Nmap to use the specified services file rather than + the <filename>nmap-services</filename> data file that + comes with Nmap. Using this option also causes a fast scan + (<option>-F</option>) to be used. See the description for + <option>--datadir</option> for more information on Nmap's data + files.</para> + </listitem> + </varlistentry> + + <varlistentry> + <term> + <option>--versiondb <replaceable>service probes file</replaceable></option> (Specify custom service probes file) + <indexterm significance="preferred"><primary><option>--versiondb</option></primary></indexterm> + </term> + <listitem> + + <para>Asks Nmap to use the specified service probes file rather than + the <filename>nmap-service-probes</filename> data file + that comes with Nmap. See the description for + <option>--datadir</option> for more information on Nmap's data + files.</para> + </listitem> + </varlistentry> + + <varlistentry> + <term> + <option>--send-eth</option> (Use raw ethernet sending) + <indexterm significance="preferred"><primary><option>--send-eth</option></primary></indexterm> + </term> + <listitem> + + <para>Asks Nmap to send packets at the raw ethernet (data + link) layer rather than the higher IP (network) layer. By + default, Nmap chooses the one which is generally best for + the platform it is running on. + Raw sockets (IP layer)<indexterm><primary>raw sockets</primary></indexterm> + are + generally most efficient for Unix machines, while ethernet + frames are required for Windows operation since Microsoft + disabled raw socket support. Nmap still uses raw IP packets + on Unix despite this option when there is no other choice + (such as non-ethernet connections).</para> + + </listitem> + </varlistentry> + + <varlistentry> + <term> + <option>--send-ip</option> (Send at raw IP level) + <indexterm significance="preferred"><primary><option>--send-ip</option></primary></indexterm> + </term> + <listitem> + + <para>Asks Nmap to send packets via raw IP sockets rather + than sending lower level ethernet frames. It is the + complement to the <option>--send-eth</option> option discussed + previously.</para> + </listitem> + </varlistentry> + + <varlistentry> + <term> + <option>--privileged</option> (Assume that the user is fully privileged) + <indexterm significance="preferred"><primary><option>--privileged</option></primary></indexterm> + </term> + <listitem> + + <para>Tells Nmap to simply assume that it is privileged + enough to perform raw socket sends, packet sniffing, and + similar operations that usually require + root privileges<indexterm><primary>privileged users</primary></indexterm><indexterm><primary>authorized users</primary><see>privileged users</see></indexterm> + on Unix systems. By default Nmap quits if such operations are + requested but <function>geteuid</function> is not + zero. <option>--privileged</option> is useful with Linux + kernel capabilities and similar systems that may be + configured to allow unprivileged users to perform raw-packet + scans. Be sure to provide this option flag before any flags + for options that require privileges (SYN scan, OS detection, + etc.). The + <envar>NMAP_PRIVILEGED</envar><indexterm><primary><envar>NMAP_PRIVILEGED</envar> environment variable</primary></indexterm> + environment variable + may be set as an equivalent alternative to + <option>--privileged</option>.</para> + </listitem> + </varlistentry> + + <varlistentry> + <term> + <option>--unprivileged</option> (Assume that the user lacks raw socket privileges) + <indexterm significance="preferred"><primary><option>--unprivileged</option></primary></indexterm> + <indexterm><primary>unprivileged users</primary></indexterm> + </term> + <listitem> + + + <para>This option is the opposite of + <option>--privileged</option>. It tells Nmap to treat the + user as lacking network raw socket and sniffing privileges. + This is useful for testing, debugging, or when the raw + network functionality of your operating system is somehow + broken. The + <envar>NMAP_UNPRIVILEGED</envar><indexterm><primary><envar>NMAP_UNPRIVILEGED</envar> environment variable</primary></indexterm> + environment variable + may be set as an equivalent alternative to + <option>--unprivileged</option>.</para> + + + </listitem> + </varlistentry> + + <varlistentry> + <term> + <option>--release-memory</option> (Release memory before quitting) + <indexterm><primary><option>--release-memory</option></primary></indexterm> + </term> + <listitem> + + <para>This option is only useful for memory-leak debugging. + It causes Nmap to release allocated memory just before it + quits so that actual memory leaks are easier to spot. + Normally Nmap skips this as the OS does this anyway upon + process termination.</para> + </listitem> + </varlistentry> + + + <varlistentry> + <term> + <option>-V</option>; <option>--version</option> (Print version number) + <indexterm><primary><option>-V</option></primary></indexterm> + <indexterm><primary><option>--version</option></primary></indexterm> + </term> + <listitem> + <para>Prints the Nmap version number and exits.</para> + </listitem> + </varlistentry> + + <varlistentry> + <term> + <option>-h</option>; <option>--help</option> (Print help summary page) + <indexterm><primary><option>-h</option></primary></indexterm> + <indexterm><primary><option>--help</option></primary></indexterm> + </term> + <listitem> + <para>Prints a short help screen with the most common + command flags. Running Nmap without any arguments does the + same thing.</para> + </listitem> + </varlistentry> + + </variablelist> + </refsect1> + + <refsect1 id='man-runtime-interaction'> + <title>Runtime Interaction<indexterm><primary>runtime interaction</primary></indexterm></title> + + <para>During the execution of Nmap, all key presses are + captured. This allows you to interact with the program + without aborting and restarting it. Certain special + keys will change options, while any other keys will print out a + status message telling you about the scan. The convention is + that + <emphasis>lowercase letters increase</emphasis> the + amount of printing, and + <emphasis>uppercase letters decrease</emphasis> the + printing. You may also press ‘<emphasis>?</emphasis>’ for help.</para> + <variablelist> + <varlistentry> + <term> + <option>v</option> / <option>V</option> + </term> + <listitem> + <para>Increase / decrease the verbosity level</para> + </listitem> + </varlistentry> + <varlistentry> + <term> + <option>d</option> / <option>D</option> + </term> + <listitem> + <para>Increase / decrease the debugging Level</para> + </listitem> + </varlistentry> + <varlistentry> + <term> + <option>p</option> / <option>P</option> + </term> + <listitem> + <para>Turn on / off packet tracing</para> + </listitem> + </varlistentry> + <varlistentry> + <term> + <option>?</option> + </term> + <listitem> + <para>Print a runtime interaction help screen</para> + </listitem> + </varlistentry> + <varlistentry> + <term> + Anything else + </term> + <listitem> + <para>Print out a status message like this:</para> +<screen> +Stats: 0:00:07 elapsed; 20 hosts completed (1 up), 1 undergoing Service Scan +Service scan Timing: About 33.33% done; ETC: 20:57 (0:00:12 remaining) +</screen> + </listitem> + </varlistentry> + </variablelist> + </refsect1> + + <refsect1 id='man-examples'> + <title>Examples</title> + <para>Here are some Nmap usage examples, from the simple and + routine to a little more complex and esoteric. Some actual + IP addresses and domain names are used to make things + more concrete. In their place you should substitute + addresses/names from + <emphasis>your own network</emphasis>. While I don't think + port scanning other networks is or should be illegal, some network + administrators don't appreciate unsolicited scanning of their networks and may + complain. Getting permission first is the best approach.</para> + + <para>For testing purposes, you have permission to scan the host + scanme.nmap.org.<indexterm><primary>scanme.nmap.org</primary></indexterm> + This permission only includes + scanning via Nmap and not testing exploits or denial of service + attacks. To conserve bandwidth, please do not initiate more than + a dozen scans against that host per day. If this free scanning + target service is abused, it will be taken down and Nmap will + report <computeroutput>Failed to resolve given hostname/IP: + scanme.nmap.org</computeroutput>. These permissions also apply to + the hosts scanme2.nmap.org, + scanme3.nmap.org, and so on, though those hosts + do not currently exist.</para> + + <para> + <command>nmap -v scanme.nmap.org</command> + <indexterm><primary><option>-v</option></primary><secondary>example of</secondary></indexterm> + </para> + <para>This option scans all reserved TCP ports on the machine + <literal>scanme.nmap.org</literal> . The <option>-v</option> + option enables verbose mode.</para> + <para> + <command>nmap -sS -O scanme.nmap.org/24</command> + <indexterm><primary><option>-sS</option></primary><secondary>example of</secondary></indexterm> + <indexterm><primary><option>-O</option></primary><secondary>example of</secondary></indexterm> + </para> + <para>Launches a stealth SYN scan against each machine that is + up out of the 256 IPs on the /24 sized network where + Scanme resides. It also tries to determine what + operating system is running on each host that is up and + running. This requires root privileges because of the SYN scan + and OS detection.</para> + <para> + <command>nmap -sV -p 22,53,110,143,4564 + 198.116.0-255.1-127</command> + <indexterm><primary><option>-p</option></primary><secondary>example of</secondary></indexterm> + </para> + + <para>Launches host enumeration and a TCP scan at the first half + of each of the 255 possible eight-bit subnets in the 198.116.0.0/16 + address space. This tests whether the systems run SSH, DNS, POP3, + or IMAP on their standard ports, or anything on port 4564. For any + of these ports found open, version detection is used to determine + what application is running.</para> + + <para> + <command>nmap -v -iR 100000 -Pn -p 80</command> + <indexterm><primary><option>-iR</option></primary><secondary>example of</secondary></indexterm> + <indexterm><primary><option>-Pn</option></primary><secondary>example of</secondary></indexterm> + </para> + + <para>Asks Nmap to choose 100,000 hosts at random and scan them + for web servers (port 80). Host enumeration is disabled with + <option>-Pn</option> since first sending a couple probes to + determine whether a host is up is wasteful when you are only + probing one port on each target host anyway.</para> + + <para> + <command>nmap -Pn -p80 -oX logs/pb-port80scan.xml -oG + logs/pb-port80scan.gnmap 216.163.128.20/20</command> + <indexterm><primary><option>-oX</option></primary><secondary>example of</secondary></indexterm> + <indexterm><primary><option>-oG</option></primary><secondary>example of</secondary></indexterm> + </para> + <para>This scans 4096 IPs for any web servers (without pinging + them) and saves the output in grepable and XML formats.</para> + + </refsect1> + +<notbook> +<refsect1 id='man-book'> + <title>Nmap Book</title> + <!-- This paragraph is a bit jumbled together for man page rendering purposes, where extra newlines were causing problems --> + <para>While this reference guide details all material Nmap + options, it can't fully demonstrate how to apply those features to + quickly solve real-world tasks. For that, we + released <notweb><citetitle>Nmap Network Scanning: The Official + Nmap Project Guide to Network Discovery and Security + Scanning</citetitle>.</notweb><web><ulink url="https://nmap.org/book/"><citetitle>Nmap + Network Scanning: The Official Nmap Project Guide to Network + Discovery and Security Scanning</citetitle></ulink>.</web> Topics + include subverting firewalls and intrusion detection systems, + optimizing Nmap performance, and automating common networking + tasks with the Nmap Scripting Engine. Hints and instructions are + provided for common Nmap tasks such as taking network inventory, + penetration testing, detecting rogue wireless access points, and + quashing network worm outbreaks. Examples and diagrams show + actual communication on the wire. More than half of the book is + available free online. See <ulink url="https://nmap.org/book"/> + for more information.</para> + +</refsect1> +</notbook> + + <refsect1 id='man-bugs'> + <title>Bugs</title> + <indexterm><primary>bugs, reporting</primary></indexterm> + + <para>Like its author, Nmap isn't perfect. But you can help make + it better by sending bug reports or even writing patches. If Nmap + doesn't behave the way you expect, first upgrade to the latest + version available from <ulink + url="https://nmap.org"/>. If the problem persists, + do some research to determine whether it has already been + discovered and addressed. Try searching for the problem or error message on + Google since that aggregates so many forums. If nothing comes of this, create an Issue on our tracker + (<ulink url="http://issues.nmap.org"/>) and/or mail a bug report to + <email>dev@nmap.org</email>. If you subscribe to the nmap-dev + list before posting, your message will bypass moderation and get + through more quickly. Subscribe at <ulink + url="https://nmap.org/mailman/listinfo/dev"/>. Please include everything + you have learned about the problem, as well as what version of + Nmap you are using and what operating system version it is + running on. Other suggestions for improving Nmap may be sent to + the Nmap dev mailing list as well.</para> + + <para>If you are able to write a patch improving Nmap or fixing a + bug, that is even better! Instructions for submitting patches or + git pull requests are available from <ulink + url="https://github.com/nmap/nmap/blob/master/CONTRIBUTING.md"/></para> + + <para>Particularly sensitive issues such as a security reports may + be sent directly to Nmap's author Fyodor directly at + <email>fyodor@nmap.org</email>. All other reports and comments + should use the dev list or issue tracker instead because more + people read, follow, and respond to those.</para> + + </refsect1> + + <refsect1 id='man-author'> + <title>Authors</title> + + <para>Gordon <quote>Fyodor</quote> Lyon + <email>fyodor@nmap.org</email> wrote and released Nmap in 1997. Since then, hundreds + of people have made valuable contributions, as detailed in the + <filename>CHANGELOG</filename><indexterm><primary>changelog</primary></indexterm> + file distributed with Nmap and also available from <ulink + url="https://nmap.org/changelog.html" />. David Fifield and + Daniel Miller deserve special recognition for their enormous + multi-year contributions! + </para> + </refsect1> + + <refsect1 id='man-legal'> + &legal-notices; + </refsect1> +</refentry> +<indexterm class="endofrange" startref="man-nmap1-indexterm"/> |