<?xml version="1.0"?>
<!-- $Id: manhtml.xml 6184 2007-11-10 01:55:40Z fyodor $ -->
<article id="man">
<artheader>
  <title>Nmap Reference Guide (Man Page)</title>
</artheader>
<indexterm significance="normal"><primary>man page</primary><see>reference guide</see></indexterm>
<indexterm class="startofrange" id="man-nmap1-indexterm" significance="normal"><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 sepchar=" ">
      <command moreinfo="none">nmap</command>
      <arg choice="opt" rep="repeat">
        <replaceable>Scan Type</replaceable>
      </arg>
      <arg choice="opt" rep="norepeat">
        <replaceable>Options</replaceable>
      </arg>
      <arg choice="req" rep="norepeat">
        <replaceable>target specification</replaceable>
      </arg>
    </cmdsynopsis>
  </refsynopsisdiv>
  <refsect1 id="man-description">
    <title>Description</title>
    <indexterm significance="normal"><primary>Nmap</primary><secondary>description of</secondary></indexterm>
    <web>
    <note><para>This document describes the very latest version of
    Nmap available from <ulink url="http://nmap.org/download.html"/> or <ulink url="http://nmap.org/dist/?C=M&amp;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 significance="normal"><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 moreinfo="none">open</literal>, <literal moreinfo="none">filtered</literal>,
    <literal moreinfo="none">closed</literal>, or <literal moreinfo="none">unfiltered</literal>.
    <literal moreinfo="none">Open</literal><indexterm significance="normal"><primary><literal moreinfo="none">open</literal> port state</primary></indexterm>
    means that an application on the target machine is listening for
    connections/packets on that port.
    <literal moreinfo="none">Filtered</literal><indexterm significance="normal"><primary><literal moreinfo="none">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 moreinfo="none">open</literal> or <literal moreinfo="none">closed</literal>.
    <literal moreinfo="none">Closed</literal><indexterm significance="normal"><primary><literal moreinfo="none">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 moreinfo="none">unfiltered</literal><indexterm significance="normal"><primary><literal moreinfo="none">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 moreinfo="none">open|filtered</literal><indexterm significance="normal"><primary><literal moreinfo="none">open|filtered</literal> port state</primary></indexterm>
    and <literal moreinfo="none">closed|filtered</literal><indexterm significance="normal"><primary><literal moreinfo="none">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 two target hostnames.</para>

<example id="man-ex-repscan"><title>A representative Nmap scan</title>
<indexterm significance="normal"><primary><option>-A</option></primary><secondary>example of</secondary></indexterm>
<screen format="linespecific">
# nmap -A -T4 scanme.nmap.org

Starting Nmap ( http://nmap.org )
Interesting ports on scanme.nmap.org (64.13.134.52):
Not shown: 994 filtered ports
PORT    STATE  SERVICE VERSION
22/tcp  open   ssh     OpenSSH 4.3 (protocol 2.0)
25/tcp  closed smtp
53/tcp  open   domain  ISC BIND 9.3.4
70/tcp  closed gopher
80/tcp  open   http    Apache httpd 2.2.2 ((Fedora))
|_ HTML title: Go ahead and ScanMe!
113/tcp closed auth
Device type: general purpose
Running: Linux 2.6.X
OS details: Linux 2.6.20-1 (Fedora Core 5)

TRACEROUTE (using port 80/tcp)
HOP RTT   ADDRESS
[Cut first seven hops for brevity]
8   10.59 so-4-2-0.mpr3.pao1.us.above.net (64.125.28.142)
9   11.00 metro0.sv.svcolo.com (208.185.168.173)
10  9.93  scanme.nmap.org (64.13.134.52)

Nmap done: 1 IP address (1 host up) scanned in 17.00 seconds
</screen>
</example>

<para>The newest version of Nmap can be obtained from <ulink url="http://nmap.org"/>.  The newest version of the man
page is available at <ulink url="http://nmap.org/book/man.html"/>.</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="http://nmap.org/data/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" significance="normal"><primary sortas="#">summary of options</primary></indexterm>
<indexterm class="startofrange" id="nmap-usage-nmap-indexterm" significance="normal"><primary>command-line options</primary><secondary>of Nmap</secondary></indexterm>
<?dbfo-need height="1in"?>
<literallayout format="linespecific" class="normal">Nmap 4.76 ( http://nmap.org )
Usage: nmap [Scan Type(s)] [Options] {target specification}
TARGET SPECIFICATION:
  Can pass hostnames, IP addresses, networks, etc.
  Ex: scanme.nmap.org, microsoft.com/24, 192.168.0.1; 10.0.0-255.1-254
  -iL &lt;inputfilename&gt;: Input from list of hosts/networks
  -iR &lt;num hosts&gt;: Choose random targets
  --exclude &lt;host1[,host2][,host3],...&gt;: Exclude hosts/networks
  --excludefile &lt;exclude_file&gt;: Exclude list from file
HOST DISCOVERY:
  -sL: List Scan - simply list targets to scan
  -sP: Ping Scan - go no further than determining if host is online
  -PN: Treat all hosts as online -- skip host discovery
  -PS/PA/PU [portlist]: TCP SYN/ACK or UDP discovery to given ports
  -PE/PP/PM: ICMP echo, timestamp, and netmask request discovery probes
  -PO [protocol list]: IP Protocol Ping
  -n/-R: Never do DNS resolution/Always resolve [default: sometimes]
  --dns-servers &lt;serv1[,serv2],...&gt;: Specify custom DNS servers
  --system-dns: Use OS's DNS resolver
SCAN TECHNIQUES:
  -sS/sT/sA/sW/sM: TCP SYN/Connect()/ACK/Window/Maimon scans
  -sU: UDP Scan
  -sN/sF/sX: TCP Null, FIN, and Xmas scans
  --scanflags &lt;flags&gt;: Customize TCP scan flags
  -sI &lt;zombie host[:probeport]&gt;: Idle scan
  -sO: IP protocol scan
  -b &lt;FTP relay host&gt;: FTP bounce scan
  --traceroute: Trace hop path to each host
  --reason: Display the reason a port is in a particular state
PORT SPECIFICATION AND SCAN ORDER:
  -p &lt;port ranges&gt;: Only scan specified ports
    Ex: -p22; -p1-65535; -p U:53,111,137,T:21-25,80,139,8080
  -F: Fast mode - Scan fewer ports than the default scan
  -r: Scan ports consecutively - don't randomize
  --top-ports &lt;number&gt;: Scan &lt;number&gt; most common ports
  --port-ratio &lt;ratio&gt;: Scan ports more common than &lt;ratio&gt;
SERVICE/VERSION DETECTION:
  -sV: Probe open ports to determine service/version info
  --version-intensity &lt;level&gt;: Set from 0 (light) to 9 (try all probes)
  --version-light: Limit to most likely probes (intensity 2)
  --version-all: Try every single probe (intensity 9)
  --version-trace: Show detailed version scan activity (for debugging)
SCRIPT SCAN:
  -sC: equivalent to --script=default
  --script=&lt;Lua scripts&gt;: &lt;Lua scripts&gt; is a comma separated list of 
           directories, script-files or script-categories
  --script-args=&lt;n1=v1,[n2=v2,...]&gt;: provide arguments to scripts
  --script-trace: Show all data sent and received
  --script-updatedb: Update the script database.
OS DETECTION:
  -O: Enable OS detection
  --osscan-limit: Limit OS detection to promising targets
  --osscan-guess: Guess OS more aggressively
TIMING AND PERFORMANCE:
  Options which take &lt;time&gt; are in milliseconds, unless you append 's'
  (seconds), 'm' (minutes), or 'h' (hours) to the value (e.g. 30m).
  -T[0-5]: Set timing template (higher is faster)
  --min-hostgroup/max-hostgroup &lt;size&gt;: Parallel host scan group sizes
  --min-parallelism/max-parallelism &lt;time&gt;: Probe parallelization
  --min-rtt-timeout/max-rtt-timeout/initial-rtt-timeout &lt;time&gt;: Specifies
      probe round trip time.
  --max-retries &lt;tries&gt;: Caps number of port scan probe retransmissions.
  --host-timeout &lt;time&gt;: Give up on target after this long
  --scan-delay/--max-scan-delay &lt;time&gt;: Adjust delay between probes
  --min-rate &lt;number&gt;: Send packets no slower than &lt;number&gt; per second
  --max-rate &lt;number&gt;: Send packets no faster than &lt;number&gt; per second
FIREWALL/IDS EVASION AND SPOOFING:
  -f; --mtu &lt;val&gt;: fragment packets (optionally w/given MTU)
  -D &lt;decoy1,decoy2[,ME],...&gt;: Cloak a scan with decoys
  -S &lt;IP_Address&gt;: Spoof source address
  -e &lt;iface&gt;: Use specified interface
  -g/--source-port &lt;portnum&gt;: Use given port number
  --data-length &lt;num&gt;: Append random data to sent packets
  --ip-options &lt;options&gt;: Send packets with specified ip options
  --ttl &lt;val&gt;: Set IP time-to-live field
  --spoof-mac &lt;mac address/prefix/vendor name&gt;: Spoof your MAC address
  --badsum: Send packets with a bogus TCP/UDP checksum
OUTPUT:
  -oN/-oX/-oS/-oG &lt;file&gt;: Output scan in normal, XML, s|&lt;rIpt kIddi3,
     and Grepable format, respectively, to the given filename.
  -oA &lt;basename&gt;: Output in the three major formats at once
  -v: Increase verbosity level (use twice or more for greater effect)
  -d[level]: Set or increase debugging level (Up to 9 is meaningful)
  --open: Only show open (or possibly open) ports
  --packet-trace: Show all packets sent and received
  --iflist: Print host interfaces and routes (for debugging)
  --log-errors: Log errors/warnings to the normal-format output file
  --append-output: Append to rather than clobber specified output files
  --resume &lt;filename&gt;: Resume an aborted scan
  --stylesheet &lt;path/URL&gt;: XSL stylesheet to transform XML output to HTML
  --webxml: Reference stylesheet from Nmap.Org for more portable XML
  --no-stylesheet: Prevent associating of XSL stylesheet w/XML output
MISC:
  -6: Enable IPv6 scanning
  -A: Enables OS detection and Version detection, Script scanning and Traceroute
  --datadir &lt;dirname&gt;: Specify custom Nmap data file location
  --send-eth/--send-ip: Send using raw ethernet frames or IP packets
  --privileged: Assume that the user is fully privileged
  --unprivileged: Assume the user lacks raw socket privileges
  -V: Print version number
  -h: Print this help summary page.
EXAMPLES:
  nmap -v -A scanme.nmap.org
  nmap -v -sP 192.168.0.0/16 10.0.0.0/8
  nmap -v -iR 10000 -PN -p 80
SEE THE MAN PAGE FOR MANY MORE OPTIONS, DESCRIPTIONS, AND EXAMPLES
</literallayout>

<indexterm class="endofrange" startref="nmap-usage-nmap-indexterm" significance="normal"/>
<indexterm class="endofrange" startref="nmap-usage-indexterm" significance="normal"/>

  </refsect1>

  <refsect1 id="man-target-specification">
    <title>Target Specification</title>
    <indexterm significance="normal"><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>Sometimes you wish to scan a whole network of adjacent hosts.
For this, Nmap supports
CIDR-style addressing.<indexterm significance="normal"><primary>CIDR (Classless Inter-Domain Routing)</primary></indexterm>
You can append
/<replaceable>numbits</replaceable> 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, 192.168.10.0/24 would scan the 256
hosts between 192.168.10.0 (binary: <literal moreinfo="none">11000000 10101000
00001010 00000000</literal>) and 192.168.10.255 (binary: <literal moreinfo="none">11000000 10101000
00001010 11111111</literal>), inclusive.
192.168.10.40/24 would do exactly the same thing.  Given that the host
scanme.nmap.org is at the IP address 64.13.134.52, the specification
scanme.nmap.org/16 would scan the 65,536 IP addresses between
64.13.0.0 and 64.13.255.255.  The smallest allowed value is /0,
which scans the whole Internet.  The largest value is /32, which scans
just the named host or IP address because all address bits are fixed.</para>

<indexterm significance="normal"><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 are commonly 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, 192.168.0-255.1-254 will skip all
addresses in the range that end in .0 and or .255.  Ranges need not be
limited to the final octets: the specifier
0-255.0-255.13.37 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>

<para>IPv6 addresses can only be specified by their fully qualified IPv6
address or hostname.  CIDR and octet ranges aren't supported for
IPv6 because they are rarely useful.</para>

<para>Nmap accepts multiple host specifications on the command line,
and they don't need to be the same type.  The command <command moreinfo="none">nmap
scanme.nmap.org 192.168.0.0/16 10.0.0,1,3-7.0-255</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 significance="normal"><primary><option>-iL</option></primary></indexterm>
          <indexterm significance="normal"><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 moreinfo="none">-</literal>)
          as the filename if you want Nmap to read hosts from standard
          input rather than an actual file.</para>
        </listitem>
      </varlistentry>

      <varlistentry>
        <term>
          <option>-iR <replaceable>num hosts</replaceable></option> (Choose random targets)
          <indexterm significance="normal"><primary><option>-iR</option></primary></indexterm>
          <indexterm significance="normal"><primary>random targets</primary></indexterm>
          <indexterm significance="normal"><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 moreinfo="none">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 moreinfo="none">nmap -sS -PS80 -iR 0 -p 80</command>
          <indexterm significance="normal"><primary><option>-sS</option></primary><secondary>example of</secondary></indexterm>
          <indexterm significance="normal"><primary><option>-PS</option></primary><secondary>example of</secondary></indexterm>
          <indexterm significance="normal"><primary><option>-iR</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 significance="normal"><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>
        </listitem>
      </varlistentry>
    </variablelist>
  </refsect1>

  <refsect1 id="man-host-discovery">
    <title>Host Discovery</title>
    <indexterm class="startofrange" id="man-host-discovery-indexterm" significance="normal"><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 moreinfo="none">ping</application> tool. Users can skip
    the ping step entirely with a list scan (<option>-sL</option>) or
    by disabling ping (<option>-PN</option>), or engage the network
    with arbitrary combinations of multi-port TCP SYN/ACK, UDP, 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 a TCP ACK
          packet destined for port 80 and an ICMP echo request query
          to each target machine.  An exception to this is that an ARP scan is
          used for any targets which are on a local ethernet network.
          For unprivileged Unix shell users, a SYN packet is sent
          instead of the ACK using the <function moreinfo="none">connect</function>
          system call.<indexterm significance="normal"><primary>unprivileged users</primary><secondary>limitations of</secondary></indexterm>
          These defaults are equivalent to the
          <option>-PA -PE</option> options.  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
    discovery
    (<option>-PR</option>)<indexterm significance="normal"><primary><option>-PR</option></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>-sP</option> option to learn how to perform
    only host discovery, or use <option>-PN</option> to skip host
    discovery and port scan all target hosts.  The following options
    control host discovery:</para>

    <variablelist>

      <varlistentry>
        <term>
        <option>-sL</option> (List Scan)
          <indexterm significance="normal"><primary><option>-sL</option></primary></indexterm>
          <indexterm significance="normal"><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 moreinfo="none">fw.chi</literal> is the name of one company's Chicago firewall. 
          <indexterm significance="normal"><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 ping scanning cannot be combined
          with this.  If you wish to disable ping scanning while still
          performing such higher level functionality, read up on the
          <option>-PN</option> option.</para>
        </listitem>
      </varlistentry>

      <varlistentry>
        <term>
        <option>-sP</option> (Ping Scan)
        <indexterm significance="normal"><primary><option>-sP</option></primary></indexterm>
        <indexterm significance="normal"><primary>ping scan</primary></indexterm>
        </term>
        <listitem>
           <para>This option tells Nmap to only perform a ping scan
           (host discovery), then print out the available hosts that
           responded to the scan.  Traceroute and NSE host scripts are
           also run if requested, but no further testing (such as port
           scanning or OS detection) is performed.  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 <option>-sP</option> option sends an ICMP echo
           request and a TCP ACK packet to port 80 by default.  When
           executed by an unprivileged user, only a SYN packet is sent
           (using a <function moreinfo="none">connect</function> call) to port 80 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>-sP</option> option can be combined with any of the
           discovery probe types (the <option>-P*</option> options,
           excluding <option>-PN</option>) for greater flexibility.
           If any of those probe type and port number options are
           used, the default probes (ACK and echo request) 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>

        </listitem>
      </varlistentry>


      <varlistentry>
        <term>
          <option>-PN</option> (No ping)
          <indexterm significance="normal"><primary><option>-PN</option></primary></indexterm>
          <indexterm significance="normal"><primary>host discovery</primary><secondary>disabling</secondary></indexterm>
        </term>
        <listitem>
          <para>This option skips the Nmap discovery stage altogether.
          Normally, Nmap uses this stage to determine active machines
          for heavier scanning.  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 class B sized target address space (/16) 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.  For machines on a local ethernet network, ARP
          scanning will still be performed (unless
          <option>--send-ip</option> is specified) because Nmap needs
          MAC addresses to further scan target hosts.  This option flag used to be <option>P0</option> (uses zero), but was renamed to avoid confusion with protocol ping's <option>PO</option> (uses the letter O) flag.</para>
        </listitem>
      </varlistentry>

      <varlistentry>
        <term>
        <option>-PS <replaceable>port list</replaceable></option> (TCP SYN Ping)
          <indexterm significance="normal"><primary><option>-PS</option></primary></indexterm>
          <indexterm significance="normal"><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 significance="normal"><primary><varname>DEFAULT_TCP_PROBE_PORT_SPEC</varname></primary></indexterm>
          in <filename moreinfo="none">nmap.h</filename>).
          <indexterm significance="normal"><primary><filename moreinfo="none">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 moreinfo="none">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 significance="normal"><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 moreinfo="none">root</literal><indexterm significance="normal"><primary>privileged users</primary></indexterm>
	  is generally able to send and receive
	  raw TCP packets.<indexterm significance="normal"><primary>raw packets</primary></indexterm>
          For unprivileged users, a
          workaround is automatically employed<indexterm significance="normal"><primary>unprivileged users</primary><secondary>limitations of</secondary></indexterm>
	  whereby the <function moreinfo="none">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 moreinfo="none">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.  This workaround is also used for IPv6
          connections, as raw IPv6 packet building support is not yet
          available in Nmap.<indexterm significance="normal"><primary>IPv6</primary><secondary>limitations of</secondary></indexterm>
          </para>

        </listitem>
      </varlistentry>

      <varlistentry>
        <term>
        <option>-PA <replaceable>port list</replaceable></option> (TCP ACK Ping)
          <indexterm significance="normal"><primary><option>-PA</option></primary></indexterm>
          <indexterm significance="normal"><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, or an IPv6 target is specified, the
          <function moreinfo="none">connect</function> workaround discussed previously is used.  This
          workaround is imperfect because <function moreinfo="none">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 significance="normal"><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 significance="normal"><primary><option>-PU</option></primary></indexterm>
          <indexterm significance="normal"><primary>UDP ping</primary></indexterm>
        </term>
        <listitem>

          <para>Another host discovery option is the UDP ping, which
          sends an empty (unless <option>--data-length</option> is
          specified) UDP packet to the given ports.  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 31338.  This default
          can be configured at compile-time by changing
          <varname>DEFAULT_UDP_PROBE_PORT_SPEC</varname><indexterm significance="normal"><primary><varname>DEFAULT_UDP_PROBE_PORT_SPEC</varname></primary></indexterm>
          in <filename moreinfo="none">nmap.h</filename>.<indexterm significance="normal"><primary><filename moreinfo="none">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 31338,
          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>-PE</option>;
        <option>-PP</option>;
        <option>-PM</option> (ICMP Ping Types)
          <indexterm significance="normal"><primary><option>-PE</option></primary></indexterm>
          <indexterm significance="normal"><primary><option>-PP</option></primary></indexterm>
          <indexterm significance="normal"><primary><option>-PM</option></primary></indexterm>
          <indexterm significance="normal"><primary>ICMP ping</primary></indexterm>
        </term>
        <listitem>

          <para>In addition to the unusual TCP and UDP host discovery
          types discussed previously, Nmap can send the standard
          packets sent by the ubiquitous
          <application moreinfo="none">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 significance="normal"><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>.  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 standard (<ulink role="hidepdf" url="http://www.rfc-editor.org/rfc/rfc792.txt">RFC
          792</ulink>) also specifies 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 significance="normal"><primary><option>-PO</option></primary></indexterm>
          <indexterm significance="normal"><primary>IP protocol ping</primary></indexterm>
        </term>
        <listitem>

          <para>The newest host discovery option 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 and UDP 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 significance="normal"><primary><varname>DEFAULT_PROTO_PROBE_PORT_SPEC</varname></primary></indexterm>
          in <filename moreinfo="none">nmap.h</filename>.
          Note that for the ICMP, IGMP, TCP (protocol 6), and UDP
          (protocol 17), the packets are sent with the proper protocol
          headers while other protocols are sent with no additional data
          beyond the IP header (unless the
          <option>--data-length</option> option is 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>-PR</option> (ARP Ping)
          <indexterm significance="normal"><primary><option>-PR</option></primary></indexterm>
          <indexterm significance="normal"><primary>ARP ping</primary></indexterm>
        </term>
        <listitem>

          <para>One of the most common Nmap usage scenarios is to scan
          an ethernet LAN. On most LANs, especially those using
          private address ranges specified by <ulink role="hidepdf" url="http://www.rfc-editor.org/rfc/rfc1918.txt">RFC 1918</ulink>, the vast majority of
          IP addresses are unused at any given time.  When Nmap tries
          to send a raw IP packet such as an ICMP echo request, the
          operating system must determine the destination hardware
          (ARP) address corresponding to the target IP so that it can
          properly address the ethernet frame.  This is often slow and
          problematic, since operating systems weren't written with
          the expectation that they would need to do millions of ARP
          requests against unavailable hosts in a short time
          period.</para>

          <para>ARP scan puts Nmap and its optimized algorithms in
          charge of ARP requests.  And if it gets a response back,
          Nmap doesn't even need to worry about the IP-based ping
          packets since it already knows the host is up.  This makes
          ARP scan much faster and more reliable than IP-based scans.
          So it is done by default when scanning ethernet hosts that Nmap
          detects are on a local ethernet network.  Even if different
          ping types (such as <option>-PE</option> or
          <option>-PS</option>) are specified, Nmap uses ARP instead
          for any of the targets which are on the same LAN.  If you
          absolutely don't want to do an ARP scan, specify
          <option>--send-ip</option>.</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 a single packet to most hosts.
</para>
</listitem>
</varlistentry>

      <varlistentry>
        <term>
          <option>-n</option> (No DNS resolution)
          <indexterm significance="normal"><primary><option>-n</option></primary></indexterm>
        </term>
        <listitem>

          <para>Tells Nmap to <emphasis>never</emphasis> do reverse
          DNS
          <indexterm significance="normal"><primary>reverse DNS</primary><secondary>disabling with <option>-n</option></secondary></indexterm>
          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 significance="normal"><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>--system-dns</option> (Use system DNS resolver)
          <indexterm significance="preferred"><primary><option>--system-dns</option></primary></indexterm>
        </term>
        <listitem>

          <para>By default, Nmap 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 moreinfo="none">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 IPv6 scans.
          <indexterm significance="normal"><primary>IPv6</primary><secondary>limitations of</secondary></indexterm>
          </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> or an
          IPv6 scan. 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>


        </listitem>
      </varlistentry>
    </variablelist>
    <indexterm class="endofrange" startref="man-host-discovery-indexterm" significance="normal"/>
  </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 moreinfo="none">nmap
          <replaceable>target</replaceable></command> scans more than
          1660 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 moreinfo="none">open</literal>,
          <literal moreinfo="none">closed</literal>, <literal moreinfo="none">filtered</literal>,
          <literal moreinfo="none">unfiltered</literal>,
          <literal moreinfo="none">open|filtered</literal>, or
          <literal moreinfo="none">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 moreinfo="none">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 moreinfo="none">filtered</literal>.</para>

<variablelist><title>The six port states recognized by Nmap</title>

  <varlistentry><term>
  <indexterm significance="normal"><primary><literal moreinfo="none">open</literal> port state</primary></indexterm>
  open</term>
  <listitem><para>An application is actively accepting TCP
  connections or UDP packets 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>
  <indexterm significance="normal"><primary><literal moreinfo="none">closed</literal> port state</primary></indexterm>
  closed</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>
  <indexterm significance="normal"><primary><literal moreinfo="none">filtered</literal> port state</primary></indexterm>
  filtered</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>
  <indexterm significance="normal"><primary><literal moreinfo="none">unfiltered</literal> port state</primary></indexterm>
  unfiltered</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>
  <indexterm significance="normal"><primary><literal moreinfo="none">open|filtered</literal> port state</primary></indexterm>
  open|filtered</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>
  <indexterm significance="normal"><primary><literal moreinfo="none">closed|filtered</literal> port state</primary></indexterm>
  closed|filtered</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 significance="normal"><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 significance="normal"><primary>privileged users</primary></indexterm>
This is because they send and receive
raw packets,<indexterm significance="normal"><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 WinPcap 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>) 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) or if IPv6 targets were specified.  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 significance="normal"><primary><option>-sS</option></primary></indexterm>
        <indexterm significance="normal"><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. SYN scan
is relatively unobtrusive and stealthy, since it never completes TCP
connections.  It also works against any compliant TCP stack rather
than depending on idiosyncrasies of specific platforms as Nmap's
FIN/NULL/Xmas, Maimon and idle scans do.  It also allows clear,
reliable differentiation between the <literal moreinfo="none">open</literal>,
<literal moreinfo="none">closed</literal>, and <literal moreinfo="none">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 1, 2, 3, 9, 10, or 13) is received.</para>

        </listitem>
      </varlistentry>

      <varlistentry>
        <term>
        <option>-sT</option> (TCP connect scan)
        <indexterm significance="normal"><primary><option>-sT</option></primary></indexterm>
        <indexterm significance="normal"><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 or is scanning IPv6 networks.  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 moreinfo="none">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 moreinfo="none">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 significance="normal"><primary><option>-sU</option></primary></indexterm>
<indexterm significance="normal"><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 an empty (no data) UDP header to every
targeted port.  If an ICMP port unreachable error (type 3, code 3) is
returned, the port is <literal moreinfo="none">closed</literal>.  Other ICMP unreachable errors (type 3,
codes 1, 2, 9, 10, or 13) mark the port as <literal moreinfo="none">filtered</literal>.  Occasionally, a
service will respond with a UDP packet, proving that it is <literal moreinfo="none">open</literal>.  If
no response is received after retransmissions, the port is classified
as <literal moreinfo="none">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 significance="normal"><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 moreinfo="none">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>-sN</option>; <option>-sF</option>; <option>-sX</option> (TCP NULL, FIN, and Xmas scans)
<indexterm significance="normal"><primary><option>-sN</option></primary></indexterm>
<indexterm significance="normal"><primary><option>-sF</option></primary></indexterm>
<indexterm significance="normal"><primary><option>-sX</option></primary></indexterm>
<indexterm significance="normal"><primary>NULL scan</primary></indexterm>
<indexterm significance="normal"><primary>FIN scan</primary></indexterm>
<indexterm significance="normal"><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 moreinfo="none">open</literal> and
<literal moreinfo="none">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 moreinfo="none">closed</literal>, while no response
means it is <literal moreinfo="none">open|filtered</literal>.  The port is marked
<literal moreinfo="none">filtered</literal> if an ICMP unreachable error (type 3, code
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 moreinfo="none">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 moreinfo="none">open</literal> ports from
certain <literal moreinfo="none">filtered</literal> ones, leaving you with the response
<literal moreinfo="none">open|filtered</literal>.</para>

        </listitem>
      </varlistentry>

      <varlistentry>
        <term>
        <option>-sA</option> (TCP ACK scan)
        <indexterm significance="normal"><primary><option>-sA</option></primary></indexterm>
        <indexterm significance="normal"><primary>ACK scan</primary></indexterm>
        </term>
        <listitem>

<para>This scan is different than the others discussed so far in that
it never determines <literal moreinfo="none">open</literal> (or even
<literal moreinfo="none">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 moreinfo="none">open</literal> and <literal moreinfo="none">closed</literal> ports will both
return a RST packet.  Nmap then labels them as
<literal moreinfo="none">unfiltered</literal>, meaning that they are reachable by the
ACK packet, but whether they are <literal moreinfo="none">open</literal> or
<literal moreinfo="none">closed</literal> is undetermined.  Ports that don't respond,
or send certain ICMP error messages back (type 3, code 1, 2, 3, 9, 10,
or 13), are labeled <literal moreinfo="none">filtered</literal>.</para>

        </listitem>
      </varlistentry>

      <varlistentry>
        <term>
        <option>-sW</option> (TCP Window scan)
<indexterm significance="normal"><primary><option>-sW</option></primary></indexterm>
<indexterm significance="normal"><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 moreinfo="none">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 moreinfo="none">unfiltered</literal> when it receives a RST back,
Window scan lists the port as <literal moreinfo="none">open</literal> or
<literal moreinfo="none">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 moreinfo="none">closed</literal>.  Of course, it is possible that the machine
really has no open ports.  If most scanned ports are
<literal moreinfo="none">closed</literal> but a few common port numbers (such as 22,
25, 53) are <literal moreinfo="none">filtered</literal>, the system is most likely
susceptible.  Occasionally, systems will even show the exact opposite
behavior.  If your scan shows 1000 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 significance="normal"><primary><option>-sM</option></primary></indexterm>
<indexterm significance="normal"><primary>Maimon scan</primary></indexterm>
</term>
        <listitem>

<para>The Maimon scan is named after its discoverer,
Uriel Maimon.<indexterm significance="normal"><primary>Maimon, Uriel</primary></indexterm>
He described the technique in
<citetitle>Phrack</citetitle> Magazine issue #49 (November 1996).<indexterm significance="normal"><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 significance="normal"><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 significance="normal"><primary>TCP flags</primary></indexterm>
Let your creative juices flow, while evading
intrusion detection systems<indexterm significance="normal"><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 moreinfo="none">URG</literal>,
<literal moreinfo="none">ACK</literal>, <literal moreinfo="none">PSH</literal>,
<literal moreinfo="none">RST</literal>, <literal moreinfo="none">SYN</literal>, and
<literal moreinfo="none">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 moreinfo="none">filtered</literal> port, while a FIN scan treats the same as
<literal moreinfo="none">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>-sI <replaceable>zombie host</replaceable><optional>:<replaceable>probeport</replaceable></optional></option> (idle scan)
          <indexterm significance="normal"><primary><option>-sI</option></primary></indexterm>
          <indexterm significance="normal"><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="http://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 significance="normal"><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 significance="normal"><primary><option>-sO</option></primary></indexterm>
        <indexterm significance="normal"><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 significance="normal"><primary>Rieger, Gerhard</primary></indexterm>
conceived the idea, wrote an excellent patch implementing it,
and sent it to the
<citetitle>nmap-hackers</citetitle> mailing list.<indexterm significance="normal"><primary><citetitle>nmap-hackers</citetitle> mailing list</primary></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 three exceptions are TCP,
UDP, and ICMP.  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 moreinfo="none">open</literal>.  An ICMP protocol unreachable
error (type 3, code 2) causes the protocol to be marked as
<literal moreinfo="none">closed</literal> Other ICMP unreachable errors (type 3, code
1, 3, 9, 10, or 13) cause the protocol to be marked
<literal moreinfo="none">filtered</literal> (though they prove that ICMP is
<literal moreinfo="none">open</literal> at the same time).  If no response is received
after retransmissions, the protocol is marked
<literal moreinfo="none">open|filtered</literal></para>

        </listitem>
      </varlistentry>



      <varlistentry>
        <term>
        <option>-b <replaceable>FTP relay host</replaceable></option> (FTP bounce scan)
        <indexterm significance="normal"><primary><option>-b</option></primary></indexterm>
        <indexterm significance="normal"><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 moreinfo="none">anonymous</literal> password:<literal moreinfo="none">-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 open port 21 (or
even for any FTP services if you scan all ports with version
detection), then try a bounce scan using each.  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 significance="normal"><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 all ports up to and including 1024 as well as higher numbered ports listed in the <filename moreinfo="none">nmap-services</filename> file for the protocol(s) being scanned.
    <indexterm significance="normal"><primary>default ports</primary></indexterm>
    </para>

    <variablelist>
      <varlistentry>
        <term>
          <option>-p <replaceable>port ranges</replaceable></option> (Only scan specified ports)
          <indexterm significance="normal"><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 moreinfo="none">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 significance="normal"><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 both TCP and UDP ports, you can specify
          a particular protocol by preceding the port numbers by <literal moreinfo="none">T:</literal>
          or <literal moreinfo="none">U:</literal>. 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 significance="normal"><primary>port specification</primary><secondary>wildcards in</secondary></indexterm>
          <indexterm significance="normal"><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 moreinfo="none">nmap-services</filename>. You
          can even use the wildcards * and ? 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 moreinfo="none">nmap-services</filename>.
          For example, the following will scan all ports in <filename moreinfo="none">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>-F</option> (Fast (limited port) scan)
          <indexterm significance="preferred"><primary><option>-F</option></primary></indexterm>
          <indexterm significance="normal"><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 moreinfo="none">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 moreinfo="none">nmap-services</filename> file,
          <option>-F</option> means to scan only ports that are named in
          the services file (normally Nmap scans all named ports plus
          ports 1–1024).</para>
        </listitem>
      </varlistentry>

      <varlistentry>
        <term>
          <option>-r</option> (Don't randomize ports)
          <indexterm significance="normal"><primary><option>-r</option></primary></indexterm>
          <indexterm significance="normal"><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 port scanning
          instead.</para>
        </listitem>
      </varlistentry>

      <varlistentry>
        <term>
          <option>--port-ratio &lt;decimal number between 0 and 1&gt;</option>
        </term>
        <listitem>
        <indexterm significance="normal"><primary>--port-ratio</primary></indexterm>
        <para>Scans all ports in <filename moreinfo="none">nmap-services</filename> file with a ratio greater than the number specified as the argument. (new format <filename moreinfo="none">nmap-services</filename> only.)</para>
        </listitem>
      </varlistentry>

      <varlistentry>
        <term>
          <option>--top-ports &lt;integer of 1 or greater&gt;</option>
        </term>
        <listitem>
        <indexterm significance="normal"><primary>--top-ports</primary></indexterm>
        <para>Scans the N highest-ratio ports found in <filename moreinfo="none">nmap-services</filename> file. (new format <filename moreinfo="none">nmap-services</filename> only.)</para>
        </listitem>
      </varlistentry>

    </variablelist>

</refsect1>


  <refsect1 id="man-version-detection">
    <title>Service and Version Detection</title>
    <indexterm class="startofrange" id="man-version-detection-indexterm" significance="normal"><primary>version detection</primary></indexterm>


    <para>Point Nmap at a remote machine and it might tell you
    that ports <literal moreinfo="none">25/tcp</literal>, <literal moreinfo="none">80/tcp</literal>, and <literal moreinfo="none">53/udp</literal> are open. Using its
    <filename moreinfo="none">nmap-services</filename><indexterm significance="normal"><primary><filename moreinfo="none">nmap-services</filename></primary></indexterm>
    database of about 2,200
    well-known services,<indexterm significance="normal"><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 significance="normal"><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 moreinfo="none">nmap-service-probes</filename><indexterm significance="normal"><primary><filename moreinfo="none">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) and sometimes miscellaneous details like
    whether an X server is open to connections, the SSH protocol
    version, or the KaZaA user name).  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 significance="normal"><primary>SSL</primary><secondary>in version detection</secondary></indexterm>
    When RPC services are
    discovered, the Nmap RPC grinder<indexterm significance="normal"><primary>RPC grinder</primary></indexterm>
    (<option>-sR</option>)<indexterm significance="normal"><primary><option>-sR</option></primary></indexterm>
    is automatically used to determine the RPC program and version
    numbers. Some UDP ports are left in the
    <literal moreinfo="none">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 moreinfo="none">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="http://nmap.org/book/vscan.html"/>.
    </man>
    <notman>
    Version detection is described in detail in <xref linkend="vscan"/>.
    </notman>
    </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 if 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 3,000 pattern matches for more than
    350 protocols such as SMTP, FTP, HTTP, etc.<indexterm significance="normal"><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 significance="normal"><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>

        </listitem>
      </varlistentry>

      <varlistentry>
        <term>
          <option>--allports</option> (Don't exclude any ports from
          version detection)
          <indexterm significance="normal"><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 moreinfo="none">Exclude</literal>
          directive in <filename moreinfo="none">nmap-service-probes</filename>, or
          you can specify <option>--allports</option> to scan all
          ports regardless of any <literal moreinfo="none">Exclude</literal>
          directive.
          <indexterm significance="normal"><primary><literal moreinfo="none">Exclude</literal> directive (<filename moreinfo="none">nmap-service-probes</filename>)</primary></indexterm>
          </para>
        </listitem>
      </varlistentry>

      <varlistentry>
        <term>
          <option>--version-intensity <replaceable>intensity</replaceable></option> (Set
          version scan intensity)
          <indexterm significance="normal"><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 significance="normal"><primary>version detection</primary><secondary>intensity</secondary></indexterm>
          The default is 7.
          <indexterm significance="normal"><primary>version detection</primary><secondary>default intensity</secondary></indexterm>
          When a probe is registered to the target port via the
          <filename moreinfo="none">nmap-service-probes</filename> <literal moreinfo="none">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 significance="normal"><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 significance="normal"><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>

      <varlistentry>
        <term>
        <option>-sR</option> (RPC scan)
          <indexterm significance="preferred"><primary><option>-sR</option></primary></indexterm>
          <indexterm significance="normal"><primary>RPC scan</primary><see>RPC grinder</see></indexterm>
          <indexterm significance="normal"><primary>RPC grinder</primary></indexterm>
          </term>

        <listitem>
          <para>This method works in conjunction with the various port
          scan methods of Nmap. It takes all the TCP/UDP ports found
          open 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 moreinfo="none">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 significance="normal"><primary>decoys</primary><secondary>which scans use</secondary></indexterm>
          This is automatically enabled as part of version scan
          (<option>-sV</option>) if you request that.  As version
          detection includes this and is much more comprehensive,
          <option>-sR</option> is rarely needed.</para>
        </listitem>
      </varlistentry>
  
    </variablelist>
    <indexterm class="endofrange" startref="man-version-detection-indexterm" significance="normal"/>
  </refsect1>

  <refsect1 id="man-os-detection">

    <title>OS Detection</title>
    <indexterm class="startofrange" id="man-os-detection-indexterm" significance="normal"><primary>OS detection</primary></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 moreinfo="none">nmap-os-db</filename><indexterm significance="normal"><primary><filename moreinfo="none">nmap-os-db</filename></primary></indexterm>
    database of more than a thousand 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).</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 significance="normal"><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="http://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 significance="normal"><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" significance="normal"/>
  </refsect1>
	<refsect1 id="man-nse"> 
	<title>Nmap Scripting Engine (NSE)</title>
        <indexterm class="startofrange" id="man-nse-indexterm" significance="normal"><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="http://lua.org">Lua programming language</ulink>, <indexterm significance="normal"><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 moreinfo="none">safe</literal>, <literal moreinfo="none">intrusive</literal>, <literal moreinfo="none">malware</literal>, <literal moreinfo="none">version</literal>, <literal moreinfo="none">discovery</literal>, <literal moreinfo="none">vuln</literal>, <literal moreinfo="none">auth</literal>, and <literal moreinfo="none">default</literal>.  These are all described
    <man>at <ulink url="http://nmap.org/book/nse-usage.html#nse-categories"/>.</man>
    <notman>in <xref linkend="nse-categories"/>.</notman></para>

    
    <para>The Nmap Scripting Engine is described in detail
<man>at <ulink url="http://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>script-categories</replaceable>|<replaceable>directory</replaceable>|<replaceable>filename</replaceable>|all</option><indexterm significance="preferred"><primary><option>--script</option></primary></indexterm></term>

<listitem>
<para>Runs a script scan (like <option>-sC</option>) using the comma-separated list of
script categories, individual scripts, or directories containing
scripts, rather than the default set. Nmap first tries to interpret the
arguments as categories, then (if that fails) as files or
directories. A script or directory of scripts may be specified as an
absolute or relative path. Absolute paths are used as
supplied. Relative paths are searched for in the following places
until found:<indexterm significance="normal"><primary>data files</primary><secondary>directory search order</secondary></indexterm><indexterm significance="normal"><primary>scripts, location of</primary></indexterm>
<filename moreinfo="none">--datadir/</filename>; 
<filename moreinfo="none">$NMAPDIR/</filename>;<indexterm significance="normal"><primary><envar>NMAPDIR</envar> environment variable</primary></indexterm>
<filename moreinfo="none">~/.nmap/</filename> (not searched on Windows);<indexterm significance="normal"><primary sortas="nmap directory"><filename moreinfo="none">.nmap</filename> directory</primary></indexterm>
NMAPDATADIR/ or<indexterm significance="normal"><primary>NMAPDATADIR</primary></indexterm>
<filename moreinfo="none">./</filename>.  A <filename moreinfo="none">scripts/</filename> subdirectory
is also tried in each of these.</para>

<para>If a directory is specified and found, Nmap loads all NSE
scripts (any filenames ending with <literal moreinfo="none">.nse</literal>) from that
directory. Filenames without the <literal moreinfo="none">nse</literal> extension are
ignored. Nmap does not search recursively into subdirectories to find
scripts.  If individual file names are specified, the file extension
does not have to be <literal moreinfo="none">nse</literal>.</para>

<para>Nmap scripts are stored in a <filename moreinfo="none">scripts</filename>
subdirectory of the Nmap data directory by default
<man>(see <ulink url="http://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 moreinfo="none">scripts/script.db</filename>.<indexterm significance="normal"><primary><filename moreinfo="none">script.db</filename></primary></indexterm>
which lists the category or categories in which each script belongs.
Give the argument <literal moreinfo="none">all</literal> to execute all scripts in the
Nmap script database.</para>

<para>Malicious scripts are not run in a sandbox and thus could 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>

</listitem>
</varlistentry>
      
	  <varlistentry>
        <term><option>--script-args <replaceable>name1</replaceable>=<replaceable>value1</replaceable>,<replaceable>name2</replaceable>={<replaceable>name3</replaceable>=<replaceable>value3</replaceable>},<replaceable>name4</replaceable>=<replaceable>value4</replaceable></option>
        <indexterm significance="preferred"><primary><option>--script-args</option></primary></indexterm>
        <indexterm significance="normal"><primary>script arguments</primary><seealso><option>--script-args</option></seealso></indexterm></term>

<listitem>
<para>Lets you provide arguments to NSE scripts. Arguments are passed
as <literal moreinfo="none">name=value</literal> pairs. The provided argument is
processed and stored inside a Lua table, to which all scripts have
access. The names are taken as strings (which must be alphanumeric
values) and used as keys inside the
<literal moreinfo="none">argument-table</literal>. Values are either strings or tables
themselves (surrounded by ‘<literal moreinfo="none">{</literal>’ and
‘<literal moreinfo="none">}</literal>’).
For example, you could pass the comma-separated arguments:
<literal moreinfo="none">user=bar,pass=foo,whois={whodb=nofollow+ripe}</literal>.
String arguments are potentially used by several scripts; subtables are
normally used by only one script. In scripts that take a subtable, the
subtable is usually named after the script (like
<literal moreinfo="none">whois</literal> in this example).</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 moreinfo="none">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 moreinfo="none">scripts</filename> directory or if you
            have changed the categories of any script.  This option is
            generally used by
            itself: <command moreinfo="none">nmap --script-updatedb</command>.</para>

        </listitem>
      </varlistentry>
    </variablelist>

    <indexterm class="endofrange" startref="man-nse-indexterm" significance="normal"/>
  </refsect1>

   <refsect1 id="man-performance">
    <title>Timing and Performance</title>
    <indexterm class="startofrange" id="man-performance-timing-indexterm" significance="normal"><primary>timing</primary></indexterm>
    <indexterm class="startofrange" id="man-performance-indexterm" significance="normal"><primary>performance</primary></indexterm>
    <para>One of my highest Nmap development priorities has always been
performance.  A default scan (<command moreinfo="none">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 moreinfo="none">time</literal> parameter.  This
is specified in milliseconds by default, though you can append
‘s’, ‘m’, or ‘h’ to the value to
specify seconds, minutes, or hours. So the
<option>--host-timeout</option> arguments <literal moreinfo="none">900000</literal>,
<literal moreinfo="none">900s</literal>, and <literal moreinfo="none">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 significance="normal"><primary><option>--min-hostgroup</option></primary></indexterm>
        <indexterm significance="normal"><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>-sP</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 Class C 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 significance="normal"><primary><option>--min-parallelism</option></primary></indexterm>
        <indexterm significance="normal"><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 ten 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.
This can be useful in combination with <option>--scan-delay</option>
(discussed later), although the latter usually serves the purpose well
enough by itself.</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 significance="normal"><primary><option>--min-rtt-timeout</option></primary></indexterm>
        <indexterm significance="normal"><primary><option>--max-rtt-timeout</option></primary></indexterm>
        <indexterm significance="normal"><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 is a
reasonable aggressive <option>--max-rtt-timeout</option> 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
<command moreinfo="none">hping2</command><indexterm significance="normal"><primary><command moreinfo="none">hping2</command></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 significance="normal"><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 significance="normal"><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