1NMAP(1) Nmap Reference Guide NMAP(1)
2
3
4
6 nmap - Network exploration tool and security / port scanner
7
9 nmap [Scan Type...] [Options] {target specification}
10
12 Nmap (“Network Mapper”) is an open source tool for network exploration
13 and security auditing. It was designed to rapidly scan large networks,
14 although it works fine against single hosts. Nmap uses raw IP packets
15 in novel ways to determine what hosts are available on the network,
16 what services (application name and version) those hosts are offering,
17 what operating systems (and OS versions) they are running, what type of
18 packet filters/firewalls are in use, and dozens of other
19 characteristics. While Nmap is commonly used for security audits, many
20 systems and network administrators find it useful for routine tasks
21 such as network inventory, managing service upgrade schedules, and
22 monitoring host or service uptime.
23
24 The output from Nmap is a list of scanned targets, with supplemental
25 information on each depending on the options used. Key among that
26 information is the “interesting ports table”.. That table lists the
27 port number and protocol, service name, and state. The state is either
28 open, filtered, closed, or unfiltered. Open. means that an
29 application on the target machine is listening for connections/packets
30 on that port. Filtered. means that a firewall, filter, or other
31 network obstacle is blocking the port so that Nmap cannot tell whether
32 it is open or closed. Closed. ports have no application listening on
33 them, though they could open up at any time. Ports are classified as
34 unfiltered. when they are responsive to Nmap´s probes, but Nmap cannot
35 determine whether they are open or closed. Nmap reports the state
36 combinations open|filtered. and closed|filtered. when it cannot
37 determine which of the two states describe a port. The port table may
38 also include software version details when version detection has been
39 requested. When an IP protocol scan is requested (-sO), Nmap provides
40 information on supported IP protocols rather than listening ports.
41
42 In addition to the interesting ports table, Nmap can provide further
43 information on targets, including reverse DNS names, operating system
44 guesses, device types, and MAC addresses.
45
46 A typical Nmap scan is shown in Example 1. The only Nmap arguments used
47 in this example are -A, to enable OS and version detection, script
48 scanning, and traceroute; -T4 for faster execution; and then the two
49 target hostnames.
50
51 Example 1. A representative Nmap scan
52
53 # nmap -A -T4 scanme.nmap.org
54
55 Starting Nmap ( http://nmap.org )
56 Interesting ports on scanme.nmap.org (64.13.134.52):
57 Not shown: 994 filtered ports
58 PORT STATE SERVICE VERSION
59 22/tcp open ssh OpenSSH 4.3 (protocol 2.0)
60 25/tcp closed smtp
61 53/tcp open domain ISC BIND 9.3.4
62 70/tcp closed gopher
63 80/tcp open http Apache httpd 2.2.2 ((Fedora))
64 |_ HTML title: Go ahead and ScanMe!
65 113/tcp closed auth
66 Device type: general purpose
67 Running: Linux 2.6.X
68 OS details: Linux 2.6.20-1 (Fedora Core 5)
69
70 TRACEROUTE (using port 80/tcp)
71 HOP RTT ADDRESS
72 [Cut first seven hops for brevity]
73 8 10.59 so-4-2-0.mpr3.pao1.us.above.net (64.125.28.142)
74 9 11.00 metro0.sv.svcolo.com (208.185.168.173)
75 10 9.93 scanme.nmap.org (64.13.134.52)
76
77 Nmap done: 1 IP address (1 host up) scanned in 17.00 seconds
78
79 The newest version of Nmap can be obtained from http://nmap.org. The
80 newest version of this man page is available at
81 http://nmap.org/book/man.html. It is also included as a chapter of
82 Nmap Network Scanning: The Official Nmap Project Guide to Network
83 Discovery and Security Scanning (see http://nmap.org/book/).
84
86 This options summary is printed when Nmap is run with no arguments, and
87 the latest version is always available at
88 http://nmap.org/data/nmap.usage.txt. It helps people remember the most
89 common options, but is no substitute for the in-depth documentation in
90 the rest of this manual. Some obscure options aren´t even included
91 here.
92
93 Nmap 5.21 ( http://nmap.org )
94 Usage: nmap [Scan Type(s)] [Options] {target specification}
95 TARGET SPECIFICATION:
96 Can pass hostnames, IP addresses, networks, etc.
97 Ex: scanme.nmap.org, 192.168.0.1; 10.0.0-255.1-254
98 -iL <inputfilename>: Input from list of hosts/networks
99 -iR <num hosts>: Choose random targets
100 --exclude <host1[,host2][,host3],...>: Exclude hosts/networks
101 --excludefile <exclude_file>: Exclude list from file
102 HOST DISCOVERY:
103 -sL: List Scan - simply list targets to scan
104 -sP: Ping Scan - go no further than determining if host is online
105 -PN: Treat all hosts as online -- skip host discovery
106 -PS/PA/PU/PY[portlist]: TCP SYN/ACK, UDP or SCTP discovery to given ports
107 -PE/PP/PM: ICMP echo, timestamp, and netmask request discovery probes
108 -PO[protocol list]: IP Protocol Ping
109 -n/-R: Never do DNS resolution/Always resolve [default: sometimes]
110 --dns-servers <serv1[,serv2],...>: Specify custom DNS servers
111 --system-dns: Use OS´s DNS resolver
112 --traceroute: Trace hop path to each host
113 SCAN TECHNIQUES:
114 -sS/sT/sA/sW/sM: TCP SYN/Connect()/ACK/Window/Maimon scans
115 -sU: UDP Scan
116 -sN/sF/sX: TCP Null, FIN, and Xmas scans
117 --scanflags <flags>: Customize TCP scan flags
118 -sI <zombie host[:probeport]>: Idle scan
119 -sY/sZ: SCTP INIT/COOKIE-ECHO scans
120 -sO: IP protocol scan
121 -b <FTP relay host>: FTP bounce scan
122 PORT SPECIFICATION AND SCAN ORDER:
123 -p <port ranges>: Only scan specified ports
124 Ex: -p22; -p1-65535; -p U:53,111,137,T:21-25,80,139,8080
125 -F: Fast mode - Scan fewer ports than the default scan
126 -r: Scan ports consecutively - don´t randomize
127 --top-ports <number>: Scan <number> most common ports
128 --port-ratio <ratio>: Scan ports more common than <ratio>
129 SERVICE/VERSION DETECTION:
130 -sV: Probe open ports to determine service/version info
131 --version-intensity <level>: Set from 0 (light) to 9 (try all probes)
132 --version-light: Limit to most likely probes (intensity 2)
133 --version-all: Try every single probe (intensity 9)
134 --version-trace: Show detailed version scan activity (for debugging)
135 SCRIPT SCAN:
136 -sC: equivalent to --script=default
137 --script=<Lua scripts>: <Lua scripts> is a comma separated list of
138 directories, script-files or script-categories
139 --script-args=<n1=v1,[n2=v2,...]>: provide arguments to scripts
140 --script-trace: Show all data sent and received
141 --script-updatedb: Update the script database.
142 OS DETECTION:
143 -O: Enable OS detection
144 --osscan-limit: Limit OS detection to promising targets
145 --osscan-guess: Guess OS more aggressively
146 TIMING AND PERFORMANCE:
147 Options which take <time> are in milliseconds, unless you append ´s´
148 (seconds), ´m´ (minutes), or ´h´ (hours) to the value (e.g. 30m).
149 -T<0-5>: Set timing template (higher is faster)
150 --min-hostgroup/max-hostgroup <size>: Parallel host scan group sizes
151 --min-parallelism/max-parallelism <time>: Probe parallelization
152 --min-rtt-timeout/max-rtt-timeout/initial-rtt-timeout <time>: Specifies
153 probe round trip time.
154 --max-retries <tries>: Caps number of port scan probe retransmissions.
155 --host-timeout <time>: Give up on target after this long
156 --scan-delay/--max-scan-delay <time>: Adjust delay between probes
157 --min-rate <number>: Send packets no slower than <number> per second
158 --max-rate <number>: Send packets no faster than <number> per second
159 FIREWALL/IDS EVASION AND SPOOFING:
160 -f; --mtu <val>: fragment packets (optionally w/given MTU)
161 -D <decoy1,decoy2[,ME],...>: Cloak a scan with decoys
162 -S <IP_Address>: Spoof source address
163 -e <iface>: Use specified interface
164 -g/--source-port <portnum>: Use given port number
165 --data-length <num>: Append random data to sent packets
166 --ip-options <options>: Send packets with specified ip options
167 --ttl <val>: Set IP time-to-live field
168 --spoof-mac <mac address/prefix/vendor name>: Spoof your MAC address
169 --badsum: Send packets with a bogus TCP/UDP/SCTP checksum
170 --adler32: Use deprecated Adler32 instead of CRC32C for SCTP checksums
171 OUTPUT:
172 -oN/-oX/-oS/-oG <file>: Output scan in normal, XML, s|<rIpt kIddi3,
173 and Grepable format, respectively, to the given filename.
174 -oA <basename>: Output in the three major formats at once
175 -v: Increase verbosity level (use twice or more for greater effect)
176 -d[level]: Set or increase debugging level (Up to 9 is meaningful)
177 --reason: Display the reason a port is in a particular state
178 --open: Only show open (or possibly open) ports
179 --packet-trace: Show all packets sent and received
180 --iflist: Print host interfaces and routes (for debugging)
181 --log-errors: Log errors/warnings to the normal-format output file
182 --append-output: Append to rather than clobber specified output files
183 --resume <filename>: Resume an aborted scan
184 --stylesheet <path/URL>: XSL stylesheet to transform XML output to HTML
185 --webxml: Reference stylesheet from Nmap.Org for more portable XML
186 --no-stylesheet: Prevent associating of XSL stylesheet w/XML output
187 MISC:
188 -6: Enable IPv6 scanning
189 -A: Enables OS detection and Version detection, Script scanning and Traceroute
190 --datadir <dirname>: Specify custom Nmap data file location
191 --send-eth/--send-ip: Send using raw ethernet frames or IP packets
192 --privileged: Assume that the user is fully privileged
193 --unprivileged: Assume the user lacks raw socket privileges
194 -V: Print version number
195 -h: Print this help summary page.
196 EXAMPLES:
197 nmap -v -A scanme.nmap.org
198 nmap -v -sP 192.168.0.0/16 10.0.0.0/8
199 nmap -v -iR 10000 -PN -p 80
200 SEE THE MAN PAGE (http://nmap.org/book/man.html) FOR MORE OPTIONS AND EXAMPLES
201
203 Everything on the Nmap command-line that isn´t an option (or option
204 argument) is treated as a target host specification. The simplest case
205 is to specify a target IP address or hostname for scanning.
206
207 Sometimes you wish to scan a whole network of adjacent hosts. For this,
208 Nmap supports CIDR-style. addressing. You can append /numbits to an
209 IPv4 address or hostname and Nmap will scan every IP address for which
210 the first numbits are the same as for the reference IP or hostname
211 given. For example, 192.168.10.0/24 would scan the 256 hosts between
212 192.168.10.0 (binary: 11000000 10101000 00001010 00000000) and
213 192.168.10.255 (binary: 11000000 10101000 00001010 11111111),
214 inclusive. 192.168.10.40/24 would scan exactly the same targets. Given
215 that the host scanme.nmap.org. is at the IP address 64.13.134.52, the
216 specification scanme.nmap.org/16 would scan the 65,536 IP addresses
217 between 64.13.0.0 and 64.13.255.255. The smallest allowed value is /0,
218 which scans the whole Internet. The largest value is /32, which scans
219 just the named host or IP address because all address bits are fixed.
220
221 CIDR notation is short but not always flexible enough. For example, you
222 might want to scan 192.168.0.0/16 but skip any IPs ending with .0 or
223 .255 because they may be used as subnet network and broadcast
224 addresses. Nmap supports this through octet range addressing. Rather
225 than specify a normal IP address, you can specify a comma-separated
226 list of numbers or ranges for each octet. For example,
227 192.168.0-255.1-254 will skip all addresses in the range that end in .0
228 or .255, and 192.168.3-5,7.1 will scan the four addresses 192.168.3.1,
229 192.168.4.1, 192.168.5.1, and 192.168.7.1. Either side of a range may
230 be omitted; the default values are 0 on the left and 255 on the right.
231 Using - by itself is the same as 0-255, but remember to use 0- in the
232 first octet so the target specification doesn´t look like a
233 command-line option. Ranges need not be limited to the final octets:
234 the specifier 0-255.0-255.13.37 will perform an Internet-wide scan for
235 all IP addresses ending in 13.37. This sort of broad sampling can be
236 useful for Internet surveys and research.
237
238 IPv6 addresses can only be specified by their fully qualified IPv6
239 address or hostname. CIDR and octet ranges aren´t supported for IPv6
240 because they are rarely useful.
241
242 Nmap accepts multiple host specifications on the command line, and they
243 don´t need to be the same type. The command nmap scanme.nmap.org
244 192.168.0.0/8 10.0.0,1,3-7.- does what you would expect.
245
246 While targets are usually specified on the command lines, the following
247 options are also available to control target selection:
248
249 -iL inputfilename (Input from list) .
250 Reads target specifications from inputfilename. Passing a huge list
251 of hosts is often awkward on the command line, yet it is a common
252 desire. For example, your DHCP server might export a list of 10,000
253 current leases that you wish to scan. Or maybe you want to scan all
254 IP addresses except for those to locate hosts using unauthorized
255 static IP addresses. Simply generate the list of hosts to scan and
256 pass that filename to Nmap as an argument to the -iL option.
257 Entries can be in any of the formats accepted by Nmap on the
258 command line (IP address, hostname, CIDR, IPv6, or octet ranges).
259 Each entry must be separated by one or more spaces, tabs, or
260 newlines. You can specify a hyphen (-) as the filename if you want
261 Nmap to read hosts from standard input rather than an actual file.
262
263 The input file may contain comments that start with # and extend to
264 the end of the line.
265
266 -iR num hosts (Choose random targets) .
267 For Internet-wide surveys and other research, you may want to
268 choose targets at random. The num hosts argument tells Nmap how
269 many IPs to generate. Undesirable IPs such as those in certain
270 private, multicast, or unallocated address ranges are automatically
271 skipped. The argument 0 can be specified for a never-ending scan.
272 Keep in mind that some network administrators bristle at
273 unauthorized scans of their networks and may complain. Use this
274 option at your own risk! If you find yourself really bored one
275 rainy afternoon, try the command nmap -sS -PS80 -iR 0 -p 80 to
276 locate random web servers for browsing.
277
278 --exclude host1[,host2[,...]] (Exclude hosts/networks) .
279 Specifies a comma-separated list of targets to be excluded from the
280 scan even if they are part of the overall network range you
281 specify. The list you pass in uses normal Nmap syntax, so it can
282 include hostnames, CIDR netblocks, octet ranges, etc. This can be
283 useful when the network you wish to scan includes untouchable
284 mission-critical servers, systems that are known to react adversely
285 to port scans, or subnets administered by other people.
286
287 --excludefile exclude_file (Exclude list from file) .
288 This offers the same functionality as the --exclude option, except
289 that the excluded targets are provided in a newline, space, or tab
290 delimited exclude_file rather than on the command line.
291
292 The exclude file may contain comments that start with # and extend
293 to the end of the line.
294
296 One of the very first steps in any network reconnaissance mission is to
297 reduce a (sometimes huge) set of IP ranges into a list of active or
298 interesting hosts. Scanning every port of every single IP address is
299 slow and usually unnecessary. Of course what makes a host interesting
300 depends greatly on the scan purposes. Network administrators may only
301 be interested in hosts running a certain service, while security
302 auditors may care about every single device with an IP address. An
303 administrator may be comfortable using just an ICMP ping to locate
304 hosts on his internal network, while an external penetration tester may
305 use a diverse set of dozens of probes in an attempt to evade firewall
306 restrictions.
307
308 Because host discovery needs are so diverse, Nmap offers a wide variety
309 of options for customizing the techniques used. Host discovery is
310 sometimes called ping scan, but it goes well beyond the simple ICMP
311 echo request packets associated with the ubiquitous ping tool. Users
312 can skip the ping step entirely with a list scan (-sL) or by disabling
313 ping (-PN), or engage the network with arbitrary combinations of
314 multi-port TCP SYN/ACK, UDP, SCTP INIT and ICMP probes. The goal of
315 these probes is to solicit responses which demonstrate that an IP
316 address is actually active (is being used by a host or network device).
317 On many networks, only a small percentage of IP addresses are active at
318 any given time. This is particularly common with private address space
319 such as 10.0.0.0/8. That network has 16 million IPs, but I have seen it
320 used by companies with less than a thousand machines. Host discovery
321 can find those machines in a sparsely allocated sea of IP addresses.
322
323 If no host discovery options are given, Nmap sends an ICMP echo
324 request, a TCP SYN packet to port 443, and TCP ACK packet to port 80,
325 and an ICMP timestamp request. These defaults are equivalent to the -PE
326 -PS443 -PA80 -PP options. An exception to this is that an ARP scan is
327 used for any targets which are on a local ethernet network. For
328 unprivileged Unix shell users, the default probes are a SYN packet to
329 ports 80 and 443 using the connect system call.. This host discovery
330 is often sufficient when scanning local networks, but a more
331 comprehensive set of discovery probes is recommended for security
332 auditing.
333
334 The -P* options (which select ping types) can be combined. You can
335 increase your odds of penetrating strict firewalls by sending many
336 probe types using different TCP ports/flags and ICMP codes. Also note
337 that ARP discovery (-PR). is done by default against targets on a
338 local ethernet network even if you specify other -P* options, because
339 it is almost always faster and more effective.
340
341 By default, Nmap does host discovery and then performs a port scan
342 against each host it determines is online. This is true even if you
343 specify non-default host discovery types such as UDP probes (-PU). Read
344 about the -sP option to learn how to perform only host discovery, or
345 use -PN to skip host discovery and port scan all target hosts. The
346 following options control host discovery:
347
348 -sL (List Scan) .
349 The list scan is a degenerate form of host discovery that simply
350 lists each host of the network(s) specified, without sending any
351 packets to the target hosts. By default, Nmap still does
352 reverse-DNS resolution on the hosts to learn their names. It is
353 often surprising how much useful information simple hostnames give
354 out. For example, fw.chi is the name of one company´s Chicago
355 firewall. Nmap also reports the total number of IP addresses at
356 the end. The list scan is a good sanity check to ensure that you
357 have proper IP addresses for your targets. If the hosts sport
358 domain names you do not recognize, it is worth investigating
359 further to prevent scanning the wrong company´s network.
360
361 Since the idea is to simply print a list of target hosts, options
362 for higher level functionality such as port scanning, OS detection,
363 or ping scanning cannot be combined with this. If you wish to
364 disable ping scanning while still performing such higher level
365 functionality, read up on the -PN (skip ping) option.
366
367 -sP (Skip port scan) .
368 This option tells Nmap not to do a port scan after host discovery,
369 and only print out the available hosts that responded to the scan.
370 This is often known as a “ping scan”, but you can also request that
371 traceroute and NSE host scripts be run. This is by default one step
372 more intrusive than the list scan, and can often be used for the
373 same purposes. It allows light reconnaissance of a target network
374 without attracting much attention. Knowing how many hosts are up is
375 more valuable to attackers than the list provided by list scan of
376 every single IP and host name.
377
378 Systems administrators often find this option valuable as well. It
379 can easily be used to count available machines on a network or
380 monitor server availability. This is often called a ping sweep, and
381 is more reliable than pinging the broadcast address because many
382 hosts do not reply to broadcast queries.
383
384 The -sP option sends an ICMP echo request, TCP SYN to port 443, TCP
385 ACK to port 80, and an ICMP timestamp request by default. When
386 executed by an unprivileged user, only SYN packets are sent (using
387 a connect call) to ports 80 and 443 on the target. When a
388 privileged user tries to scan targets on a local ethernet network,
389 ARP requests are used unless --send-ip was specified. The -sP
390 option can be combined with any of the discovery probe types (the
391 -P* options, excluding -PN) for greater flexibility. If any of
392 those probe type and port number options are used, the default
393 probes are overridden. When strict firewalls are in place between
394 the source host running Nmap and the target network, using those
395 advanced techniques is recommended. Otherwise hosts could be missed
396 when the firewall drops probes or their responses.
397
398 -PN (No ping) .
399 This option skips the Nmap discovery stage altogether. Normally,
400 Nmap uses this stage to determine active machines for heavier
401 scanning. By default, Nmap only performs heavy probing such as port
402 scans, version detection, or OS detection against hosts that are
403 found to be up. Disabling host discovery with -PN causes Nmap to
404 attempt the requested scanning functions against every target IP
405 address specified. So if a class B sized target address space (/16)
406 is specified on the command line, all 65,536 IP addresses are
407 scanned. Proper host discovery is skipped as with the list scan,
408 but instead of stopping and printing the target list, Nmap
409 continues to perform requested functions as if each target IP is
410 active. To skip ping scan and port scan, while still allowing NSE
411 to run, use the two options -PN -sP together.
412
413 For machines on a local ethernet network, ARP scanning will still
414 be performed (unless --send-ip is specified) because Nmap needs MAC
415 addresses to further scan target hosts. This option flag used to be
416 P0 (uses zero), but was renamed to avoid confusion with protocol
417 ping´s PO (uses the letter O) flag.
418
419 -PS port list (TCP SYN Ping) .
420 This option sends an empty TCP packet with the SYN flag set. The
421 default destination port is 80 (configurable at compile time by
422 changing DEFAULT_TCP_PROBE_PORT_SPEC in nmap.h). Alternate ports
423 can be specified as a parameter. The syntax is the same as for the
424 -p except that port type specifiers like T: are not allowed.
425 Examples are -PS22 and -PS22-25,80,113,1050,35000. Note that there
426 can be no space between -PS and the port list. If multiple probes
427 are specified they will be sent in parallel.
428
429 The SYN flag suggests to the remote system that you are attempting
430 to establish a connection. Normally the destination port will be
431 closed, and a RST (reset) packet sent back. If the port happens to
432 be open, the target will take the second step of a TCP
433 three-way-handshake. by responding with a SYN/ACK TCP packet. The
434 machine running Nmap then tears down the nascent connection by
435 responding with a RST rather than sending an ACK packet which would
436 complete the three-way-handshake and establish a full connection.
437 The RST packet is sent by the kernel of the machine running Nmap in
438 response to the unexpected SYN/ACK, not by Nmap itself.
439
440 Nmap does not care whether the port is open or closed. Either the
441 RST or SYN/ACK response discussed previously tell Nmap that the
442 host is available and responsive.
443
444 On Unix boxes, only the privileged user root. is generally able to
445 send and receive raw TCP packets.. For unprivileged users, a
446 workaround is automatically employed. whereby the connect system
447 call is initiated against each target port. This has the effect of
448 sending a SYN packet to the target host, in an attempt to establish
449 a connection. If connect returns with a quick success or an
450 ECONNREFUSED failure, the underlying TCP stack must have received a
451 SYN/ACK or RST and the host is marked available. If the connection
452 attempt is left hanging until a timeout is reached, the host is
453 marked as down. This workaround is also used for IPv6 connections,
454 as raw IPv6 packet building support is not yet available in Nmap..
455
456 -PA port list (TCP ACK Ping) .
457 The TCP ACK ping is quite similar to the just-discussed SYN ping.
458 The difference, as you could likely guess, is that the TCP ACK flag
459 is set instead of the SYN flag. Such an ACK packet purports to be
460 acknowledging data over an established TCP connection, but no such
461 connection exists. So remote hosts should always respond with a RST
462 packet, disclosing their existence in the process.
463
464 The -PA option uses the same default port as the SYN probe (80) and
465 can also take a list of destination ports in the same format. If an
466 unprivileged user tries this, or an IPv6 target is specified, the
467 connect workaround discussed previously is used. This workaround is
468 imperfect because connect is actually sending a SYN packet rather
469 than an ACK.
470
471 The reason for offering both SYN and ACK ping probes is to maximize
472 the chances of bypassing firewalls. Many administrators configure
473 routers and other simple firewalls to block incoming SYN packets
474 except for those destined for public services like the company web
475 site or mail server. This prevents other incoming connections to
476 the organization, while allowing users to make unobstructed
477 outgoing connections to the Internet. This non-stateful approach
478 takes up few resources on the firewall/router and is widely
479 supported by hardware and software filters. The Linux
480 Netfilter/iptables. firewall software offers the --syn convenience
481 option to implement this stateless approach. When stateless
482 firewall rules such as this are in place, SYN ping probes (-PS) are
483 likely to be blocked when sent to closed target ports. In such
484 cases, the ACK probe shines as it cuts right through these rules.
485
486 Another common type of firewall uses stateful rules that drop
487 unexpected packets. This feature was initially found mostly on
488 high-end firewalls, though it has become much more common over the
489 years. The Linux Netfilter/iptables system supports this through
490 the --state option, which categorizes packets based on connection
491 state. A SYN probe is more likely to work against such a system, as
492 unexpected ACK packets are generally recognized as bogus and
493 dropped. A solution to this quandary is to send both SYN and ACK
494 probes by specifying -PS and -PA.
495
496 -PU port list (UDP Ping) .
497 Another host discovery option is the UDP ping, which sends a UDP
498 packet to the given ports. For most ports, the packet will be
499 empty, though for a few a protocol-specific payload will be sent
500 that is more likely to get a response.. See the file payload.cc.
501 for exactly which ports have payloads. The --data-length. option
502 sends a fixed-length random payload for all ports.
503
504 The port list takes the same format as with the previously
505 discussed -PS and -PA options. If no ports are specified, the
506 default is 40125. This default can be configured at compile-time by
507 changing DEFAULT_UDP_PROBE_PORT_SPEC. in nmap.h.. A highly
508 uncommon port is used by default because sending to open ports is
509 often undesirable for this particular scan type.
510
511 Upon hitting a closed port on the target machine, the UDP probe
512 should elicit an ICMP port unreachable packet in return. This
513 signifies to Nmap that the machine is up and available. Many other
514 types of ICMP errors, such as host/network unreachables or TTL
515 exceeded are indicative of a down or unreachable host. A lack of
516 response is also interpreted this way. If an open port is reached,
517 most services simply ignore the empty packet and fail to return any
518 response. This is why the default probe port is 40125, which is
519 highly unlikely to be in use. A few services, such as the Character
520 Generator (chargen) protocol, will respond to an empty UDP packet,
521 and thus disclose to Nmap that the machine is available.
522
523 The primary advantage of this scan type is that it bypasses
524 firewalls and filters that only screen TCP. For example, I once
525 owned a Linksys BEFW11S4 wireless broadband router. The external
526 interface of this device filtered all TCP ports by default, but UDP
527 probes would still elicit port unreachable messages and thus give
528 away the device.
529
530 -PY port list (SCTP INIT Ping) .
531 This option sends an SCTP packet containing a minimal INIT chunk.
532 The default destination port is 80 (configurable at compile time by
533 changing DEFAULT_SCTP_PROBE_PORT_SPEC in nmap.h). Alternate ports
534 can be specified as a parameter. The syntax is the same as for the
535 -p except that port type specifiers like S: are not allowed.
536 Examples are -PY22 and -PY22,80,179,5060. Note that there can be no
537 space between -PY and the port list. If multiple probes are
538 specified they will be sent in parallel.
539
540 The INIT chunk suggests to the remote system that you are
541 attempting to establish an association. Normally the destination
542 port will be closed, and an ABORT chunk will be sent back. If the
543 port happens to be open, the target will take the second step of an
544 SCTP four-way-handshake. by responding with an INIT-ACK chunk. If
545 the machine running Nmap has a functional SCTP stack, then it tears
546 down the nascent association by responding with an ABORT chunk
547 rather than sending a COOKIE-ECHO chunk which would be the next
548 step in the four-way-handshake. The ABORT packet is sent by the
549 kernel of the machine running Nmap in response to the unexpected
550 INIT-ACK, not by Nmap itself.
551
552 Nmap does not care whether the port is open or closed. Either the
553 ABORT or INIT-ACK response discussed previously tell Nmap that the
554 host is available and responsive.
555
556 On Unix boxes, only the privileged user root. is generally able to
557 send and receive raw SCTP packets.. Using SCTP INIT Pings is
558 currently not possible for unprivileged users.. The same
559 limitation applies to IPv6, which is currently not supported for
560 SCTP INIT Ping..
561
562 -PE; -PP; -PM (ICMP Ping Types) .
563 In addition to the unusual TCP, UDP and SCTP host discovery types
564 discussed previously, Nmap can send the standard packets sent by
565 the ubiquitous ping program. Nmap sends an ICMP type 8 (echo
566 request) packet to the target IP addresses, expecting a type 0
567 (echo reply) in return from available hosts.. Unfortunately for
568 network explorers, many hosts and firewalls now block these
569 packets, rather than responding as required by RFC 1122[2]. For
570 this reason, ICMP-only scans are rarely reliable enough against
571 unknown targets over the Internet. But for system administrators
572 monitoring an internal network, they can be a practical and
573 efficient approach. Use the -PE option to enable this echo request
574 behavior.
575
576 While echo request is the standard ICMP ping query, Nmap does not
577 stop there. The ICMP standards (RFC 792[3]. and RFC 950[4]. “a
578 host SHOULD NOT implement these messages”. Timestamp and address
579 mask queries can be sent with the -PP and -PM options,
580 respectively. A timestamp reply (ICMP code 14) or address mask
581 reply (code 18) discloses that the host is available. These two
582 queries can be valuable when administrators specifically block echo
583 request packets while forgetting that other ICMP queries can be
584 used for the same purpose.
585
586 -PO protocol list (IP Protocol Ping) .
587 The newest host discovery option is the IP protocol ping, which
588 sends IP packets with the specified protocol number set in their IP
589 header. The protocol list takes the same format as do port lists in
590 the previously discussed TCP, UDP and SCTP host discovery options.
591 If no protocols are specified, the default is to send multiple IP
592 packets for ICMP (protocol 1), IGMP (protocol 2), and IP-in-IP
593 (protocol 4). The default protocols can be configured at
594 compile-time by changing DEFAULT_PROTO_PROBE_PORT_SPEC. in nmap.h.
595 Note that for the ICMP, IGMP, TCP (protocol 6), UDP (protocol 17)
596 and SCTP (protocol 132), the packets are sent with the proper
597 protocol headers. while other protocols are sent with no
598 additional data beyond the IP header (unless the --data-length.
599 option is specified).
600
601 This host discovery method looks for either responses using the
602 same protocol as a probe, or ICMP protocol unreachable messages
603 which signify that the given protocol isn´t supported on the
604 destination host. Either type of response signifies that the target
605 host is alive.
606
607 -PR (ARP Ping) .
608 One of the most common Nmap usage scenarios is to scan an ethernet
609 LAN. On most LANs, especially those using private address ranges
610 specified by RFC 1918[5], the vast majority of IP addresses are
611 unused at any given time. When Nmap tries to send a raw IP packet
612 such as an ICMP echo request, the operating system must determine
613 the destination hardware (ARP) address corresponding to the target
614 IP so that it can properly address the ethernet frame. This is
615 often slow and problematic, since operating systems weren´t written
616 with the expectation that they would need to do millions of ARP
617 requests against unavailable hosts in a short time period.
618
619 ARP scan puts Nmap and its optimized algorithms in charge of ARP
620 requests. And if it gets a response back, Nmap doesn´t even need to
621 worry about the IP-based ping packets since it already knows the
622 host is up. This makes ARP scan much faster and more reliable than
623 IP-based scans. So it is done by default when scanning ethernet
624 hosts that Nmap detects are on a local ethernet network. Even if
625 different ping types (such as -PE or -PS) are specified, Nmap uses
626 ARP instead for any of the targets which are on the same LAN. If
627 you absolutely don´t want to do an ARP scan, specify --send-ip.
628
629 --traceroute (Trace path to host) .
630 Traceroutes are performed post-scan using information from the scan
631 results to determine the port and protocol most likely to reach the
632 target. It works with all scan types except connect scans (-sT) and
633 idle scans (-sI). All traces use Nmap´s dynamic timing model and
634 are performed in parallel.
635
636 Traceroute works by sending packets with a low TTL (time-to-live)
637 in an attempt to elicit ICMP Time Exceeded messages from
638 intermediate hops between the scanner and the target host. Standard
639 traceroute implementations start with a TTL of 1 and increment the
640 TTL until the destination host is reached. Nmap´s traceroute starts
641 with a high TTL and then decrements the TTL until it reaches zero.
642 Doing it backwards lets Nmap employ clever caching algorithms to
643 speed up traces over multiple hosts. On average Nmap sends 5–10
644 fewer packets per host, depending on network conditions. If a
645 single subnet is being scanned (i.e. 192.168.0.0/24) Nmap may only
646 have to send a single packet to most hosts.
647
648 -n (No DNS resolution) .
649 Tells Nmap to never do reverse DNS resolution on the active IP
650 addresses it finds. Since DNS can be slow even with Nmap´s built-in
651 parallel stub resolver, this option can slash scanning times.
652
653 -R (DNS resolution for all targets) .
654 Tells Nmap to always do reverse DNS resolution on the target IP
655 addresses. Normally reverse DNS is only performed against
656 responsive (online) hosts.
657
658 --system-dns (Use system DNS resolver) .
659 By default, Nmap resolves IP addresses by sending queries directly
660 to the name servers configured on your host and then listening for
661 responses. Many requests (often dozens) are performed in parallel
662 to improve performance. Specify this option to use your system
663 resolver instead (one IP at a time via the getnameinfo call). This
664 is slower and rarely useful unless you find a bug in the Nmap
665 parallel resolver (please let us know if you do). The system
666 resolver is always used for IPv6 scans.
667
668 --dns-servers server1[,server2[,...]] (Servers to use for reverse DNS
669 queries) .
670 By default, Nmap determines your DNS servers (for rDNS resolution)
671 from your resolv.conf file (Unix) or the Registry (Win32).
672 Alternatively, you may use this option to specify alternate
673 servers. This option is not honored if you are using --system-dns
674 or an IPv6 scan. Using multiple DNS servers is often faster,
675 especially if you choose authoritative servers for your target IP
676 space. This option can also improve stealth, as your requests can
677 be bounced off just about any recursive DNS server on the Internet.
678
679 This option also comes in handy when scanning private networks.
680 Sometimes only a few name servers provide proper rDNS information,
681 and you may not even know where they are. You can scan the network
682 for port 53 (perhaps with version detection), then try Nmap list
683 scans (-sL) specifying each name server one at a time with
684 --dns-servers until you find one which works.
685
687 While Nmap has grown in functionality over the years, it began as an
688 efficient port scanner, and that remains its core function. The simple
689 command nmap target scans more than 1660 TCP ports on the host target.
690 While many port scanners have traditionally lumped all ports into the
691 open or closed states, Nmap is much more granular. It divides ports
692 into six states: open, closed, filtered, unfiltered, open|filtered, or
693 closed|filtered.
694
695 These states are not intrinsic properties of the port itself, but
696 describe how Nmap sees them. For example, an Nmap scan from the same
697 network as the target may show port 135/tcp as open, while a scan at
698 the same time with the same options from across the Internet might show
699 that port as filtered.
700
701 The six port states recognized by Nmap
702
703 An application is actively accepting TCP connections, UDP datagrams
704 or SCTP associations on this port. Finding these is often the
705 primary goal of port scanning. Security-minded people know that
706 each open port is an avenue for attack. Attackers and pen-testers
707 want to exploit the open ports, while administrators try to close
708 or protect them with firewalls without thwarting legitimate users.
709 Open ports are also interesting for non-security scans because they
710 show services available for use on the network.
711
712 A closed port is accessible (it receives and responds to Nmap probe
713 packets), but there is no application listening on it. They can be
714 helpful in showing that a host is up on an IP address (host
715 discovery, or ping scanning), and as part of OS detection. Because
716 closed ports are reachable, it may be worth scanning later in case
717 some open up. Administrators may want to consider blocking such
718 ports with a firewall. Then they would appear in the filtered
719 state, discussed next.
720
721 Nmap cannot determine whether the port is open because packet
722 filtering prevents its probes from reaching the port. The filtering
723 could be from a dedicated firewall device, router rules, or
724 host-based firewall software. These ports frustrate attackers
725 because they provide so little information. Sometimes they respond
726 with ICMP error messages such as type 3 code 13 (destination
727 unreachable: communication administratively prohibited), but
728 filters that simply drop probes without responding are far more
729 common. This forces Nmap to retry several times just in case the
730 probe was dropped due to network congestion rather than filtering.
731 This slows down the scan dramatically.
732
733 The unfiltered state means that a port is accessible, but Nmap is
734 unable to determine whether it is open or closed. Only the ACK
735 scan, which is used to map firewall rulesets, classifies ports into
736 this state. Scanning unfiltered ports with other scan types such as
737 Window scan, SYN scan, or FIN scan, may help resolve whether the
738 port is open.
739
740 Nmap places ports in this state when it is unable to determine
741 whether a port is open or filtered. This occurs for scan types in
742 which open ports give no response. The lack of response could also
743 mean that a packet filter dropped the probe or any response it
744 elicited. So Nmap does not know for sure whether the port is open
745 or being filtered. The UDP, IP protocol, FIN, NULL, and Xmas scans
746 classify ports this way.
747
748 This state is used when Nmap is unable to determine whether a port
749 is closed or filtered. It is only used for the IP ID idle scan.
750
752 As a novice performing automotive repair, I can struggle for hours
753 trying to fit my rudimentary tools (hammer, duct tape, wrench, etc.) to
754 the task at hand. When I fail miserably and tow my jalopy to a real
755 mechanic, he invariably fishes around in a huge tool chest until
756 pulling out the perfect gizmo which makes the job seem effortless. The
757 art of port scanning is similar. Experts understand the dozens of scan
758 techniques and choose the appropriate one (or combination) for a given
759 task. Inexperienced users and script kiddies,. on the other hand, try
760 to solve every problem with the default SYN scan. Since Nmap is free,
761 the only barrier to port scanning mastery is knowledge. That certainly
762 beats the automotive world, where it may take great skill to determine
763 that you need a strut spring compressor, then you still have to pay
764 thousands of dollars for it.
765
766 Most of the scan types are only available to privileged users.. This
767 is because they send and receive raw packets,. which requires root
768 access on Unix systems. Using an administrator account on Windows is
769 recommended, though Nmap sometimes works for unprivileged users on that
770 platform when WinPcap has already been loaded into the OS. Requiring
771 root privileges was a serious limitation when Nmap was released in
772 1997, as many users only had access to shared shell accounts. Now, the
773 world is different. Computers are cheaper, far more people have
774 always-on direct Internet access, and desktop Unix systems (including
775 Linux and Mac OS X) are prevalent. A Windows version of Nmap is now
776 available, allowing it to run on even more desktops. For all these
777 reasons, users have less need to run Nmap from limited shared shell
778 accounts. This is fortunate, as the privileged options make Nmap far
779 more powerful and flexible.
780
781 While Nmap attempts to produce accurate results, keep in mind that all
782 of its insights are based on packets returned by the target machines
783 (or firewalls in front of them). Such hosts may be untrustworthy and
784 send responses intended to confuse or mislead Nmap. Much more common
785 are non-RFC-compliant hosts that do not respond as they should to Nmap
786 probes. FIN, NULL, and Xmas scans are particularly susceptible to this
787 problem. Such issues are specific to certain scan types and so are
788 discussed in the individual scan type entries.
789
790 This section documents the dozen or so port scan techniques supported
791 by Nmap. Only one method may be used at a time, except that UDP scan
792 (-sU) and any one of the SCTP scan types (-sY, -sZ) may be combined
793 with any one of the TCP scan types. As a memory aid, port scan type
794 options are of the form -sC, where C is a prominent character in the
795 scan name, usually the first. The one exception to this is the
796 deprecated FTP bounce scan (-b). By default, Nmap performs a SYN Scan,
797 though it substitutes a connect scan if the user does not have proper
798 privileges to send raw packets (requires root access on Unix) or if
799 IPv6 targets were specified. Of the scans listed in this section,
800 unprivileged users can only execute connect and FTP bounce scans.
801
802 -sS (TCP SYN scan) .
803 SYN scan is the default and most popular scan option for good
804 reasons. It can be performed quickly, scanning thousands of ports
805 per second on a fast network not hampered by restrictive firewalls.
806 SYN scan is relatively unobtrusive and stealthy, since it never
807 completes TCP connections. It also works against any compliant TCP
808 stack rather than depending on idiosyncrasies of specific platforms
809 as Nmap´s FIN/NULL/Xmas, Maimon and idle scans do. It also allows
810 clear, reliable differentiation between the open, closed, and
811 filtered states.
812
813 This technique is often referred to as half-open scanning, because
814 you don´t open a full TCP connection. You send a SYN packet, as if
815 you are going to open a real connection and then wait for a
816 response. A SYN/ACK indicates the port is listening (open), while a
817 RST (reset) is indicative of a non-listener. If no response is
818 received after several retransmissions, the port is marked as
819 filtered. The port is also marked filtered if an ICMP unreachable
820 error (type 3, code 1, 2, 3, 9, 10, or 13) is received.
821
822 -sT (TCP connect scan) .
823 TCP connect scan is the default TCP scan type when SYN scan is not
824 an option. This is the case when a user does not have raw packet
825 privileges or is scanning IPv6 networks. Instead of writing raw
826 packets as most other scan types do, Nmap asks the underlying
827 operating system to establish a connection with the target machine
828 and port by issuing the connect system call. This is the same
829 high-level system call that web browsers, P2P clients, and most
830 other network-enabled applications use to establish a connection.
831 It is part of a programming interface known as the Berkeley Sockets
832 API. Rather than read raw packet responses off the wire, Nmap uses
833 this API to obtain status information on each connection attempt.
834
835 When SYN scan is available, it is usually a better choice. Nmap has
836 less control over the high level connect call than with raw
837 packets, making it less efficient. The system call completes
838 connections to open target ports rather than performing the
839 half-open reset that SYN scan does. Not only does this take longer
840 and require more packets to obtain the same information, but target
841 machines are more likely to log the connection. A decent IDS will
842 catch either, but most machines have no such alarm system. Many
843 services on your average Unix system will add a note to syslog, and
844 sometimes a cryptic error message, when Nmap connects and then
845 closes the connection without sending data. Truly pathetic services
846 crash when this happens, though that is uncommon. An administrator
847 who sees a bunch of connection attempts in her logs from a single
848 system should know that she has been connect scanned.
849
850 -sU (UDP scans) .
851 While most popular services on the Internet run over the TCP
852 protocol, UDP[6] services are widely deployed. DNS, SNMP, and DHCP
853 (registered ports 53, 161/162, and 67/68) are three of the most
854 common. Because UDP scanning is generally slower and more difficult
855 than TCP, some security auditors ignore these ports. This is a
856 mistake, as exploitable UDP services are quite common and attackers
857 certainly don´t ignore the whole protocol. Fortunately, Nmap can
858 help inventory UDP ports.
859
860 UDP scan is activated with the -sU option. It can be combined with
861 a TCP scan type such as SYN scan (-sS) to check both protocols
862 during the same run.
863
864 UDP scan works by sending a UDP packet to every targeted port. For
865 some common ports such as 53 and 161, a protocol-specific payload
866 is sent, but for most ports the packet is empty.. The
867 --data-length option can be used to send a fixed-length random
868 payload to every port. If an ICMP port unreachable error (type 3,
869 code 3) is returned, the port is closed. Other ICMP unreachable
870 errors (type 3, codes 1, 2, 9, 10, or 13) mark the port as
871 filtered. Occasionally, a service will respond with a UDP packet,
872 proving that it is open. If no response is received after
873 retransmissions, the port is classified as open|filtered. This
874 means that the port could be open, or perhaps packet filters are
875 blocking the communication. Version detection (-sV) can be used to
876 help differentiate the truly open ports from the filtered ones.
877
878 A big challenge with UDP scanning is doing it quickly. Open and
879 filtered ports rarely send any response, leaving Nmap to time out
880 and then conduct retransmissions just in case the probe or response
881 were lost. Closed ports are often an even bigger problem. They
882 usually send back an ICMP port unreachable error. But unlike the
883 RST packets sent by closed TCP ports in response to a SYN or
884 connect scan, many hosts rate limit. ICMP port unreachable
885 messages by default. Linux and Solaris are particularly strict
886 about this. For example, the Linux 2.4.20 kernel limits destination
887 unreachable messages to one per second (in net/ipv4/icmp.c).
888
889 Nmap detects rate limiting and slows down accordingly to avoid
890 flooding the network with useless packets that the target machine
891 will drop. Unfortunately, a Linux-style limit of one packet per
892 second makes a 65,536-port scan take more than 18 hours. Ideas for
893 speeding your UDP scans up include scanning more hosts in parallel,
894 doing a quick scan of just the popular ports first, scanning from
895 behind the firewall, and using --host-timeout to skip slow hosts.
896
897 -sY (SCTP INIT scan) .
898
899 SCTP[7] is a relatively new alternative to the TCP and UDP
900 protocols, combining most characteristics of TCP and UDP, and also
901 adding new features like multi-homing and multi-streaming. It is
902 mostly being used for SS7/SIGTRAN related services but has the
903 potential to be used for other applications as well. SCTP INIT scan
904 is the SCTP equivalent of a TCP SYN scan. It can be performed
905 quickly, scanning thousands of ports per second on a fast network
906 not hampered by restrictive firewalls. Like SYN scan, INIT scan is
907 relatively unobtrusive and stealthy, since it never completes SCTP
908 associations. It also allows clear, reliable differentiation
909 between the open, closed, and filtered states.
910
911 This technique is often referred to as half-open scanning, because
912 you don´t open a full SCTP association. You send an INIT chunk, as
913 if you are going to open a real association and then wait for a
914 response. An INIT-ACK chunk indicates the port is listening (open),
915 while an ABORT chunk is indicative of a non-listener. If no
916 response is received after several retransmissions, the port is
917 marked as filtered. The port is also marked filtered if an ICMP
918 unreachable error (type 3, code 1, 2, 3, 9, 10, or 13) is received.
919
920 -sN; -sF; -sX (TCP NULL, FIN, and Xmas scans) .
921 These three scan types (even more are possible with the --scanflags
922 option described in the next section) exploit a subtle loophole in
923 the TCP RFC[8] to differentiate between open and closed ports. Page
924 65 of RFC 793 says that “if the [destination] port state is CLOSED
925 .... an incoming segment not containing a RST causes a RST to be
926 sent in response.” Then the next page discusses packets sent to
927 open ports without the SYN, RST, or ACK bits set, stating that:
928 “you are unlikely to get here, but if you do, drop the segment, and
929 return.”
930
931 When scanning systems compliant with this RFC text, any packet not
932 containing SYN, RST, or ACK bits will result in a returned RST if
933 the port is closed and no response at all if the port is open. As
934 long as none of those three bits are included, any combination of
935 the other three (FIN, PSH, and URG) are OK. Nmap exploits this with
936 three scan types:
937
938 Null scan (-sN)
939 Does not set any bits (TCP flag header is 0)
940
941 FIN scan (-sF)
942 Sets just the TCP FIN bit.
943
944 Xmas scan (-sX)
945 Sets the FIN, PSH, and URG flags, lighting the packet up like a
946 Christmas tree.
947
948 These three scan types are exactly the same in behavior except for
949 the TCP flags set in probe packets. If a RST packet is received,
950 the port is considered closed, while no response means it is
951 open|filtered. The port is marked filtered if an ICMP unreachable
952 error (type 3, code 1, 2, 3, 9, 10, or 13) is received.
953
954 The key advantage to these scan types is that they can sneak
955 through certain non-stateful firewalls and packet filtering
956 routers. Another advantage is that these scan types are a little
957 more stealthy than even a SYN scan. Don´t count on this though—most
958 modern IDS products can be configured to detect them. The big
959 downside is that not all systems follow RFC 793 to the letter. A
960 number of systems send RST responses to the probes regardless of
961 whether the port is open or not. This causes all of the ports to be
962 labeled closed. Major operating systems that do this are Microsoft
963 Windows, many Cisco devices, BSDI, and IBM OS/400. This scan does
964 work against most Unix-based systems though. Another downside of
965 these scans is that they can´t distinguish open ports from certain
966 filtered ones, leaving you with the response open|filtered.
967
968 -sA (TCP ACK scan) .
969 This scan is different than the others discussed so far in that it
970 never determines open (or even open|filtered) ports. It is used to
971 map out firewall rulesets, determining whether they are stateful or
972 not and which ports are filtered.
973
974 The ACK scan probe packet has only the ACK flag set (unless you use
975 --scanflags). When scanning unfiltered systems, open and closed
976 ports will both return a RST packet. Nmap then labels them as
977 unfiltered, meaning that they are reachable by the ACK packet, but
978 whether they are open or closed is undetermined. Ports that don´t
979 respond, or send certain ICMP error messages back (type 3, code 1,
980 2, 3, 9, 10, or 13), are labeled filtered.
981
982 -sW (TCP Window scan) .
983 Window scan is exactly the same as ACK scan except that it exploits
984 an implementation detail of certain systems to differentiate open
985 ports from closed ones, rather than always printing unfiltered when
986 a RST is returned. It does this by examining the TCP Window field
987 of the RST packets returned. On some systems, open ports use a
988 positive window size (even for RST packets) while closed ones have
989 a zero window. So instead of always listing a port as unfiltered
990 when it receives a RST back, Window scan lists the port as open or
991 closed if the TCP Window value in that reset is positive or zero,
992 respectively.
993
994 This scan relies on an implementation detail of a minority of
995 systems out on the Internet, so you can´t always trust it. Systems
996 that don´t support it will usually return all ports closed. Of
997 course, it is possible that the machine really has no open ports.
998 If most scanned ports are closed but a few common port numbers
999 (such as 22, 25, 53) are filtered, the system is most likely
1000 susceptible. Occasionally, systems will even show the exact
1001 opposite behavior. If your scan shows 1000 open ports and three
1002 closed or filtered ports, then those three may very well be the
1003 truly open ones.
1004
1005 -sM (TCP Maimon scan) .
1006 The Maimon scan is named after its discoverer, Uriel Maimon.. He
1007 described the technique in Phrack Magazine issue #49 (November
1008 1996).. Nmap, which included this technique, was released two
1009 issues later. This technique is exactly the same as NULL, FIN, and
1010 Xmas scans, except that the probe is FIN/ACK. According to RFC
1011 793[8] (TCP), a RST packet should be generated in response to such
1012 a probe whether the port is open or closed. However, Uriel noticed
1013 that many BSD-derived systems simply drop the packet if the port is
1014 open.
1015
1016 --scanflags (Custom TCP scan) .
1017 Truly advanced Nmap users need not limit themselves to the canned
1018 scan types offered. The --scanflags option allows you to design
1019 your own scan by specifying arbitrary TCP flags.. Let your
1020 creative juices flow, while evading intrusion detection systems.
1021 whose vendors simply paged through the Nmap man page adding
1022 specific rules!
1023
1024 The --scanflags argument can be a numerical flag value such as 9
1025 (PSH and FIN), but using symbolic names is easier. Just mash
1026 together any combination of URG, ACK, PSH, RST, SYN, and FIN. For
1027 example, --scanflags URGACKPSHRSTSYNFIN sets everything, though
1028 it´s not very useful for scanning. The order these are specified in
1029 is irrelevant.
1030
1031 In addition to specifying the desired flags, you can specify a TCP
1032 scan type (such as -sA or -sF). That base type tells Nmap how to
1033 interpret responses. For example, a SYN scan considers no-response
1034 to indicate a filtered port, while a FIN scan treats the same as
1035 open|filtered. Nmap will behave the same way it does for the base
1036 scan type, except that it will use the TCP flags you specify
1037 instead. If you don´t specify a base type, SYN scan is used.
1038
1039 -sZ (SCTP COOKIE ECHO scan) .
1040 SCTP COOKIE ECHO scan is a more advanced SCTP scan. It takes
1041 advantage of the fact that SCTP implementations should silently
1042 drop packets containing COOKIE ECHO chunks on open ports, but send
1043 an ABORT if the port is closed. The advantage of this scan type is
1044 that it is not as obvious a port scan than an INIT scan. Also,
1045 there may be non-stateful firewall rulesets blocking INIT chunks,
1046 but not COOKIE ECHO chunks. Don´t be fooled into thinking that this
1047 will make a port scan invisible; a good IDS will be able to detect
1048 SCTP COOKIE ECHO scans too. The downside is that SCTP COOKIE ECHO
1049 scans cannot differentiate between open and filtered ports, leaving
1050 you with the state open|filtered in both cases.
1051
1052 -sI zombie host[:probeport] (idle scan) .
1053 This advanced scan method allows for a truly blind TCP port scan of
1054 the target (meaning no packets are sent to the target from your
1055 real IP address). Instead, a unique side-channel attack exploits
1056 predictable IP fragmentation ID sequence generation on the zombie
1057 host to glean information about the open ports on the target. IDS
1058 systems will display the scan as coming from the zombie machine you
1059 specify (which must be up and meet certain criteria). This
1060 fascinating scan type is too complex to fully describe in this
1061 reference guide, so I wrote and posted an informal paper with full
1062 details at http://nmap.org/book/idlescan.html.
1063
1064 Besides being extraordinarily stealthy (due to its blind nature),
1065 this scan type permits mapping out IP-based trust relationships
1066 between machines. The port listing shows open ports from the
1067 perspective of the zombie host. So you can try scanning a target
1068 using various zombies that you think might be trusted. (via
1069 router/packet filter rules).
1070
1071 You can add a colon followed by a port number to the zombie host if
1072 you wish to probe a particular port on the zombie for IP ID
1073 changes. Otherwise Nmap will use the port it uses by default for
1074 TCP pings (80).
1075
1076 -sO (IP protocol scan) .
1077 IP protocol scan allows you to determine which IP protocols (TCP,
1078 ICMP, IGMP, etc.) are supported by target machines. This isn´t
1079 technically a port scan, since it cycles through IP protocol
1080 numbers rather than TCP or UDP port numbers. Yet it still uses the
1081 -p option to select scanned protocol numbers, reports its results
1082 within the normal port table format, and even uses the same
1083 underlying scan engine as the true port scanning methods. So it is
1084 close enough to a port scan that it belongs here.
1085
1086 Besides being useful in its own right, protocol scan demonstrates
1087 the power of open-source software. While the fundamental idea is
1088 pretty simple, I had not thought to add it nor received any
1089 requests for such functionality. Then in the summer of 2000,
1090 Gerhard Rieger. conceived the idea, wrote an excellent patch
1091 implementing it, and sent it to the nmap-hackers mailing list.. I
1092 incorporated that patch into the Nmap tree and released a new
1093 version the next day. Few pieces of commercial software have users
1094 enthusiastic enough to design and contribute their own
1095 improvements!
1096
1097 Protocol scan works in a similar fashion to UDP scan. Instead of
1098 iterating through the port number field of a UDP packet, it sends
1099 IP packet headers and iterates through the eight-bit IP protocol
1100 field. The headers are usually empty, containing no data and not
1101 even the proper header for the claimed protocol. The exceptions are
1102 TCP, UDP, ICMP, SCTP, and IGMP. A proper protocol header for those
1103 is included since some systems won´t send them otherwise and
1104 because Nmap already has functions to create them. Instead of
1105 watching for ICMP port unreachable messages, protocol scan is on
1106 the lookout for ICMP protocol unreachable messages. If Nmap
1107 receives any response in any protocol from the target host, Nmap
1108 marks that protocol as open. An ICMP protocol unreachable error
1109 (type 3, code 2) causes the protocol to be marked as closed Other
1110 ICMP unreachable errors (type 3, code 1, 3, 9, 10, or 13) cause the
1111 protocol to be marked filtered (though they prove that ICMP is open
1112 at the same time). If no response is received after
1113 retransmissions, the protocol is marked open|filtered
1114
1115 -b FTP relay host (FTP bounce scan) .
1116 An interesting feature of the FTP protocol (RFC 959[9]) is support
1117 for so-called proxy FTP connections. This allows a user to connect
1118 to one FTP server, then ask that files be sent to a third-party
1119 server. Such a feature is ripe for abuse on many levels, so most
1120 servers have ceased supporting it. One of the abuses this feature
1121 allows is causing the FTP server to port scan other hosts. Simply
1122 ask the FTP server to send a file to each interesting port of a
1123 target host in turn. The error message will describe whether the
1124 port is open or not. This is a good way to bypass firewalls because
1125 organizational FTP servers are often placed where they have more
1126 access to other internal hosts than any old Internet host would.
1127 Nmap supports FTP bounce scan with the -b option. It takes an
1128 argument of the form username:password@server:port. Server is the
1129 name or IP address of a vulnerable FTP server. As with a normal
1130 URL, you may omit username:password, in which case anonymous login
1131 credentials (user: anonymous password:-wwwuser@) are used. The port
1132 number (and preceding colon) may be omitted as well, in which case
1133 the default FTP port (21) on server is used.
1134
1135 This vulnerability was widespread in 1997 when Nmap was released,
1136 but has largely been fixed. Vulnerable servers are still around, so
1137 it is worth trying when all else fails. If bypassing a firewall is
1138 your goal, scan the target network for open port 21 (or even for
1139 any FTP services if you scan all ports with version detection),
1140 then try a bounce scan using each. Nmap will tell you whether the
1141 host is vulnerable or not. If you are just trying to cover your
1142 tracks, you don´t need to (and, in fact, shouldn´t) limit yourself
1143 to hosts on the target network. Before you go scanning random
1144 Internet addresses for vulnerable FTP servers, consider that
1145 sysadmins may not appreciate you abusing their servers in this way.
1146
1148 In addition to all of the scan methods discussed previously, Nmap
1149 offers options for specifying which ports are scanned and whether the
1150 scan order is randomized or sequential. By default, Nmap scans the most
1151 common 1,000 ports for each protocol.
1152
1153 -p port ranges (Only scan specified ports) .
1154 This option specifies which ports you want to scan and overrides
1155 the default. Individual port numbers are OK, as are ranges
1156 separated by a hyphen (e.g. 1-1023). The beginning and/or end
1157 values of a range may be omitted, causing Nmap to use 1 and 65535,
1158 respectively. So you can specify -p- to scan ports from 1 through
1159 65535. Scanning port zero. is allowed if you specify it
1160 explicitly. For IP protocol scanning (-sO), this option specifies
1161 the protocol numbers you wish to scan for (0–255).
1162
1163 When scanning both TCP and UDP ports, you can specify a particular
1164 protocol by preceding the port numbers by T: or U:. The qualifier
1165 lasts until you specify another qualifier. For example, the
1166 argument -p U:53,111,137,T:21-25,80,139,8080 would scan UDP ports
1167 53, 111,and 137, as well as the listed TCP ports. Note that to scan
1168 both UDP and TCP, you have to specify -sU and at least one TCP scan
1169 type (such as -sS, -sF, or -sT). If no protocol qualifier is given,
1170 the port numbers are added to all protocol lists. Ports can also
1171 be specified by name according to what the port is referred to in
1172 the nmap-services. You can even use the wildcards * and ? with the
1173 names. For example, to scan FTP and all ports whose names begin
1174 with “http”, use -p ftp,http*. Be careful about shell expansions
1175 and quote the argument to -p if unsure.
1176
1177 Ranges of ports can be surrounded by square brackets to indicate
1178 ports inside that range that appear in nmap-services. For example,
1179 the following will scan all ports in nmap-services equal to or
1180 below 1024: -p [-1024]. Be careful with shell expansions and quote
1181 the argument to -p if unsure.
1182
1183 -F (Fast (limited port) scan) .
1184 Specifies that you wish to scan fewer ports than the default.
1185 Normally Nmap scans the most common 1,000 ports for each scanned
1186 protocol. With -F, this is reduced to 100.
1187
1188 Nmap needs an nmap-services file with frequency information in
1189 order to know which ports are the most common. If port frequency
1190 information isn´t available, perhaps because of the use of a custom
1191 nmap-services file, -F means to scan only ports that are named in
1192 the services file (normally Nmap scans all named ports plus ports
1193 1–1024).
1194
1195 -r (Don´t randomize ports) .
1196 By default, Nmap randomizes the scanned port order (except that
1197 certain commonly accessible ports are moved near the beginning for
1198 efficiency reasons). This randomization is normally desirable, but
1199 you can specify -r for sequential (sorted from lowest to highest)
1200 port scanning instead.
1201
1202 --port-ratio <decimal number between 0 and 1>
1203 Scans all ports in nmap-services file with a ratio greater than the
1204 number specified as the argument.
1205
1206 --top-ports <integer of 1 or greater>
1207 Scans the N highest-ratio ports found in nmap-services file.
1208
1210 Point Nmap at a remote machine and it might tell you that ports 25/tcp,
1211 80/tcp, and 53/udp are open. Using its nmap-services. database of
1212 about 2,200 well-known services,. Nmap would report that those ports
1213 probably correspond to a mail server (SMTP), web server (HTTP), and
1214 name server (DNS) respectively. This lookup is usually accurate—the
1215 vast majority of daemons listening on TCP port 25 are, in fact, mail
1216 servers. However, you should not bet your security on this! People can
1217 and do run services on strange ports..
1218
1219 Even if Nmap is right, and the hypothetical server above is running
1220 SMTP, HTTP, and DNS servers, that is not a lot of information. When
1221 doing vulnerability assessments (or even simple network inventories) of
1222 your companies or clients, you really want to know which mail and DNS
1223 servers and versions are running. Having an accurate version number
1224 helps dramatically in determining which exploits a server is vulnerable
1225 to. Version detection helps you obtain this information.
1226
1227 After TCP and/or UDP ports are discovered using one of the other scan
1228 methods, version detection interrogates those ports to determine more
1229 about what is actually running. The nmap-service-probes. database
1230 contains probes for querying various services and match expressions to
1231 recognize and parse responses. Nmap tries to determine the service
1232 protocol (e.g. FTP, SSH, Telnet, HTTP), the application name (e.g. ISC
1233 BIND, Apache httpd, Solaris telnetd), the version number, hostname,
1234 device type (e.g. printer, router), the OS family (e.g. Windows, Linux)
1235 and sometimes miscellaneous details like whether an X server is open to
1236 connections, the SSH protocol version, or the KaZaA user name). Of
1237 course, most services don´t provide all of this information. If Nmap
1238 was compiled with OpenSSL support, it will connect to SSL servers to
1239 deduce the service listening behind that encryption layer.. When RPC
1240 services are discovered, the Nmap RPC grinder. (-sR). is
1241 automatically used to determine the RPC program and version numbers.
1242 Some UDP ports are left in the open|filtered state after a UDP port
1243 scan is unable to determine whether the port is open or filtered.
1244 Version detection will try to elicit a response from these ports (just
1245 as it does with open ports), and change the state to open if it
1246 succeeds. open|filtered TCP ports are treated the same way. Note that
1247 the Nmap -A option enables version detection among other things. A
1248 paper documenting the workings, usage, and customization of version
1249 detection is available at http://nmap.org/book/vscan.html.
1250
1251 When Nmap receives responses from a service but cannot match them to
1252 its database, it prints out a special fingerprint and a URL for you to
1253 submit if to if you know for sure what is running on the port. Please
1254 take a couple minutes to make the submission so that your find can
1255 benefit everyone. Thanks to these submissions, Nmap has about 3,000
1256 pattern matches for more than 350 protocols such as SMTP, FTP, HTTP,
1257 etc..
1258
1259 Version detection is enabled and controlled with the following options:
1260
1261 -sV (Version detection) .
1262 Enables version detection, as discussed above. Alternatively, you
1263 can use -A, which enables version detection among other things.
1264
1265 --allports (Don´t exclude any ports from version detection) .
1266 By default, Nmap version detection skips TCP port 9100 because some
1267 printers simply print anything sent to that port, leading to dozens
1268 of pages of HTTP GET requests, binary SSL session requests, etc.
1269 This behavior can be changed by modifying or removing the Exclude
1270 directive in nmap-service-probes, or you can specify --allports to
1271 scan all ports regardless of any Exclude directive.
1272
1273 --version-intensity intensity (Set version scan intensity) .
1274 When performing a version scan (-sV), Nmap sends a series of
1275 probes, each of which is assigned a rarity value between one and
1276 nine. The lower-numbered probes are effective against a wide
1277 variety of common services, while the higher numbered ones are
1278 rarely useful. The intensity level specifies which probes should be
1279 applied. The higher the number, the more likely it is the service
1280 will be correctly identified. However, high intensity scans take
1281 longer. The intensity must be between 0 and 9. The default is 7.
1282 When a probe is registered to the target port via the
1283 nmap-service-probes ports directive, that probe is tried regardless
1284 of intensity level. This ensures that the DNS probes will always be
1285 attempted against any open port 53, the SSL probe will be done
1286 against 443, etc.
1287
1288 --version-light (Enable light mode) .
1289 This is a convenience alias for --version-intensity 2. This light
1290 mode makes version scanning much faster, but it is slightly less
1291 likely to identify services.
1292
1293 --version-all (Try every single probe) .
1294 An alias for --version-intensity 9, ensuring that every single
1295 probe is attempted against each port.
1296
1297 --version-trace (Trace version scan activity) .
1298 This causes Nmap to print out extensive debugging info about what
1299 version scanning is doing. It is a subset of what you get with
1300 --packet-trace.
1301
1302 -sR (RPC scan) .
1303 This method works in conjunction with the various port scan methods
1304 of Nmap. It takes all the TCP/UDP ports found open and floods them
1305 with SunRPC program NULL commands in an attempt to determine
1306 whether they are RPC ports, and if so, what program and version
1307 number they serve up. Thus you can effectively obtain the same info
1308 as rpcinfo -p even if the target´s portmapper is behind a firewall
1309 (or protected by TCP wrappers). Decoys do not currently work with
1310 RPC scan.. This is automatically enabled as part of version scan
1311 (-sV) if you request that. As version detection includes this and
1312 is much more comprehensive, -sR is rarely needed.
1313
1315 One of Nmap´s best-known features is remote OS detection using TCP/IP
1316 stack fingerprinting. Nmap sends a series of TCP and UDP packets to the
1317 remote host and examines practically every bit in the responses. After
1318 performing dozens of tests such as TCP ISN sampling, TCP options
1319 support and ordering, IP ID sampling, and the initial window size
1320 check, Nmap compares the results to its nmap-os-db. database of more
1321 than a thousand known OS fingerprints and prints out the OS details if
1322 there is a match. Each fingerprint includes a freeform textual
1323 description of the OS, and a classification which provides the vendor
1324 name (e.g. Sun), underlying OS (e.g. Solaris), OS generation (e.g. 10),
1325 and device type (general purpose, router, switch, game console, etc).
1326
1327 If Nmap is unable to guess the OS of a machine, and conditions are good
1328 (e.g. at least one open port and one closed port were found), Nmap will
1329 provide a URL you can use to submit the fingerprint if you know (for
1330 sure) the OS running on the machine. By doing this you contribute to
1331 the pool of operating systems known to Nmap and thus it will be more
1332 accurate for everyone.
1333
1334 OS detection enables some other tests which make use of information
1335 that is gathered during the process anyway. One of these is TCP
1336 Sequence Predictability Classification. This measures approximately how
1337 hard it is to establish a forged TCP connection against the remote
1338 host. It is useful for exploiting source-IP based trust relationships
1339 (rlogin, firewall filters, etc) or for hiding the source of an attack.
1340 This sort of spoofing is rarely performed any more, but many machines
1341 are still vulnerable to it. The actual difficulty number is based on
1342 statistical sampling and may fluctuate. It is generally better to use
1343 the English classification such as “worthy challenge” or “trivial
1344 joke”. This is only reported in normal output in verbose (-v) mode.
1345 When verbose mode is enabled along with -O, IP ID sequence generation
1346 is also reported. Most machines are in the “incremental” class, which
1347 means that they increment the ID field in the IP header for each packet
1348 they send. This makes them vulnerable to several advanced information
1349 gathering and spoofing attacks.
1350
1351 Another bit of extra information enabled by OS detection is a guess at
1352 a target´s uptime. This uses the TCP timestamp option (RFC 1323[10]) to
1353 guess when a machine was last rebooted. The guess can be inaccurate due
1354 to the timestamp counter not being initialized to zero or the counter
1355 overflowing and wrapping around, so it is printed only in verbose mode.
1356
1357 A paper documenting the workings, usage, and customization of OS
1358 detection is available at http://nmap.org/book/osdetect.html.
1359
1360 OS detection is enabled and controlled with the following options:
1361
1362 -O (Enable OS detection) .
1363 Enables OS detection, as discussed above. Alternatively, you can
1364 use -A to enable OS detection along with other things.
1365
1366 --osscan-limit (Limit OS detection to promising targets) .
1367 OS detection is far more effective if at least one open and one
1368 closed TCP port are found. Set this option and Nmap will not even
1369 try OS detection against hosts that do not meet this criteria. This
1370 can save substantial time, particularly on -PN scans against many
1371 hosts. It only matters when OS detection is requested with -O or
1372 -A.
1373
1374 --osscan-guess; --fuzzy (Guess OS detection results) .
1375 When Nmap is unable to detect a perfect OS match, it sometimes
1376 offers up near-matches as possibilities. The match has to be very
1377 close for Nmap to do this by default. Either of these (equivalent)
1378 options make Nmap guess more aggressively. Nmap will still tell you
1379 when an imperfect match is printed and display its confidence level
1380 (percentage) for each guess.
1381
1382 --max-os-tries (Set the maximum number of OS detection tries against a
1383 target) .
1384 When Nmap performs OS detection against a target and fails to find
1385 a perfect match, it usually repeats the attempt. By default, Nmap
1386 tries five times if conditions are favorable for OS fingerprint
1387 submission, and twice when conditions aren´t so good. Specifying a
1388 lower --max-os-tries value (such as 1) speeds Nmap up, though you
1389 miss out on retries which could potentially identify the OS.
1390 Alternatively, a high value may be set to allow even more retries
1391 when conditions are favorable. This is rarely done, except to
1392 generate better fingerprints for submission and integration into
1393 the Nmap OS database.
1394
1396 The Nmap Scripting Engine (NSE) is one of Nmap´s most powerful and
1397 flexible features. It allows users to write (and share) simple scripts
1398 (using the Lua programming language[11],
1399
1400 Tasks we had in mind when creating the system include network
1401 discovery, more sophisticated version detection, vulnerability
1402 detection. NSE can even be used for vulnerability exploitation.
1403
1404 To reflect those different uses and to simplify the choice of which
1405 scripts to run, each script contains a field associating it with one or
1406 more categories. Currently defined categories are safe, intrusive,
1407 malware, version, discovery, vuln, auth, and default. These are all
1408 described at http://nmap.org/book/nse-usage.html#nse-categories.
1409
1410 Scripts are not run in a sandbox and thus could accidentally or
1411 maliciously damage your system or invade your privacy. Never run
1412 scripts from third parties unless you trust the authors or have
1413 carefully audited the scripts yourself.
1414
1415 The Nmap Scripting Engine is described in detail at
1416 http://nmap.org/book/nse.html
1417
1418 and is controlled by the following options:
1419
1420 -sC .
1421 Performs a script scan using the default set of scripts. It is
1422 equivalent to --script=default. Some of the scripts in this
1423 category are considered intrusive and should not be run against a
1424 target network without permission.
1425
1426 --script filename|category|directory|expression|all[,...] .
1427 Runs a script scan using the comma-separated list of filenames,
1428 script categories, and directories. Each element in the list may
1429 also be a Boolean expression describing a more complex set of
1430 scripts. Each element is interpreted first as an expression, then
1431 as a category, and finally as a file or directory name. The special
1432 argument all makes every script in Nmap´s script database eligible
1433 to run. The all argument should be used with caution as NSE may
1434 contain dangerous scripts including exploits, brute force
1435 authentication crackers, and denial of service attacks.
1436
1437 File and directory names may be relative or absolute. Absolute
1438 names are used directly. Relative paths are looked for in the
1439 following places until found:
1440 --datadir
1441 $NMAPDIR
1442 ~/.nmap (not searched on Windows)
1443 NMAPDATADIR
1444 the current directory
1445 A scripts subdirectory is also tried in each of these.
1446
1447 When a directory name is given, Nmap loads every file in the
1448 directory whose name ends with .nse. All other files are ignored
1449 and directories are not searched recursively. When a filename is
1450 given, it does not have to have the .nse extension; it will be
1451 added automatically if necessary. Nmap scripts are stored in a
1452 scripts subdirectory of the Nmap data directory by default (see
1453 http://nmap.org/book/data-files.html).
1454
1455 For efficiency, scripts are indexed in a database stored in
1456 scripts/script.db,. which lists the category or categories in
1457 which each script belongs. When referring to scripts from
1458 script.db by name, you can use a shell-style ‘*’ wildcard.
1459
1460 nmap --script "http-*"
1461 Loads all scripts whose name starts with http-, such as
1462 http-auth.nse and http-open-proxy.nse. The argument to --script
1463 had to be in quotes to protect the wildcard from the shell.
1464
1465 More complicated script selection can be done using the and, or,
1466 and not operators to build Boolean expressions. The operators have
1467 the same precedence[12] as in Lua: not is the highest, followed by
1468 and and then or. You can alter precedence by using parentheses.
1469 Because expressions contain space characters it is necessary to
1470 quote them.
1471
1472 nmap --script "not intrusive"
1473 Loads every script except for those in the intrusive category.
1474
1475 nmap --script "default or safe"
1476 This is functionally equivalent to nmap --script
1477 "default,safe". It loads all scripts that are in the default
1478 category or the safe category or both.
1479
1480 nmap --script "default and safe"
1481 Loads those scripts that are in both the default and safe
1482 categories.
1483
1484 nmap --script "(default or safe or intrusive) and not http-*"
1485 Loads scripts in the default, safe, or intrusive categories,
1486 except for those whose names start with http-.
1487
1488 --script-args name1=value1,name2={name3=value3},name4={value4,value5} .
1489 Lets you provide arguments to NSE scripts. Arguments are a
1490 comma-separated list of name=value pairs. Names and values may be
1491 strings not containing whitespace or the characters ‘{’, ‘}’, ‘=’,
1492 or ‘,’. To include one of these characters in a string, enclose the
1493 string in single or double quotes. Within a quoted string, ‘\’
1494 escapes a quote. A backslash is only used to escape quotation marks
1495 in this special case; in all other cases a backslash is interpreted
1496 literally. Values may also be tables enclosed in {}, just as in
1497 Lua. A table may contain simple string values or more name-value
1498 pairs, including nested tables. An example of script arguments:
1499 --script-args
1500 auth={user=foo,pass=´,{}=bar´},userdb=C:\Path\To\File. The online
1501 NSE Documentation Portal at http://nmap.org/nsedoc/ lists the
1502 arguments that each script accepts.
1503
1504 --script-trace .
1505 This option does what --packet-trace does, just one ISO layer
1506 higher. If this option is specified all incoming and outgoing
1507 communication performed by a script is printed. The displayed
1508 information includes the communication protocol, the source, the
1509 target and the transmitted data. If more than 5% of all transmitted
1510 data is not printable, then the trace output is in a hex dump
1511 format. Specifying --packet-trace enables script tracing too.
1512
1513 --script-updatedb .
1514 This option updates the script database found in scripts/script.db
1515 which is used by Nmap to determine the available default scripts
1516 and categories. It is only necessary to update the database if you
1517 have added or removed NSE scripts from the default scripts
1518 directory or if you have changed the categories of any script. This
1519 option is generally used by itself: nmap --script-updatedb.
1520
1522 One of my highest Nmap development priorities has always been
1523 performance. A default scan (nmap hostname) of a host on my local
1524 network takes a fifth of a second. That is barely enough time to blink,
1525 but adds up when you are scanning hundreds or thousands of hosts.
1526 Moreover, certain scan options such as UDP scanning and version
1527 detection can increase scan times substantially. So can certain
1528 firewall configurations, particularly response rate limiting. While
1529 Nmap utilizes parallelism and many advanced algorithms to accelerate
1530 these scans, the user has ultimate control over how Nmap runs. Expert
1531 users carefully craft Nmap commands to obtain only the information they
1532 care about while meeting their time constraints.
1533
1534 Techniques for improving scan times include omitting non-critical
1535 tests, and upgrading to the latest version of Nmap (performance
1536 enhancements are made frequently). Optimizing timing parameters can
1537 also make a substantial difference. Those options are listed below.
1538
1539 Some options accept a time parameter. This is specified in milliseconds
1540 by default, though you can append ‘s’, ‘m’, or ‘h’ to the value to
1541 specify seconds, minutes, or hours. So the --host-timeout arguments
1542 900000, 900s, and 15m all do the same thing.
1543
1544 --min-hostgroup numhosts; --max-hostgroup numhosts (Adjust parallel
1545 scan group sizes) .
1546 Nmap has the ability to port scan or version scan multiple hosts in
1547 parallel. Nmap does this by dividing the target IP space into
1548 groups and then scanning one group at a time. In general, larger
1549 groups are more efficient. The downside is that host results can´t
1550 be provided until the whole group is finished. So if Nmap started
1551 out with a group size of 50, the user would not receive any reports
1552 (except for the updates offered in verbose mode) until the first 50
1553 hosts are completed.
1554
1555 By default, Nmap takes a compromise approach to this conflict. It
1556 starts out with a group size as low as five so the first results
1557 come quickly and then increases the groupsize to as high as 1024.
1558 The exact default numbers depend on the options given. For
1559 efficiency reasons, Nmap uses larger group sizes for UDP or
1560 few-port TCP scans.
1561
1562 When a maximum group size is specified with --max-hostgroup, Nmap
1563 will never exceed that size. Specify a minimum size with
1564 --min-hostgroup and Nmap will try to keep group sizes above that
1565 level. Nmap may have to use smaller groups than you specify if
1566 there are not enough target hosts left on a given interface to
1567 fulfill the specified minimum. Both may be set to keep the group
1568 size within a specific range, though this is rarely desired.
1569
1570 These options do not have an effect during the host discovery phase
1571 of a scan. This includes plain ping scans (-sP). Host discovery
1572 always works in large groups of hosts to improve speed and
1573 accuracy.
1574
1575 The primary use of these options is to specify a large minimum
1576 group size so that the full scan runs more quickly. A common choice
1577 is 256 to scan a network in Class C sized chunks. For a scan with
1578 many ports, exceeding that number is unlikely to help much. For
1579 scans of just a few port numbers, host group sizes of 2048 or more
1580 may be helpful.
1581
1582 --min-parallelism numprobes; --max-parallelism numprobes (Adjust probe
1583 parallelization) .
1584 These options control the total number of probes that may be
1585 outstanding for a host group. They are used for port scanning and
1586 host discovery. By default, Nmap calculates an ever-changing ideal
1587 parallelism based on network performance. If packets are being
1588 dropped, Nmap slows down and allows fewer outstanding probes. The
1589 ideal probe number slowly rises as the network proves itself
1590 worthy. These options place minimum or maximum bounds on that
1591 variable. By default, the ideal parallelism can drop to one if the
1592 network proves unreliable and rise to several hundred in perfect
1593 conditions.
1594
1595 The most common usage is to set --min-parallelism to a number
1596 higher than one to speed up scans of poorly performing hosts or
1597 networks. This is a risky option to play with, as setting it too
1598 high may affect accuracy. Setting this also reduces Nmap´s ability
1599 to control parallelism dynamically based on network conditions. A
1600 value of ten might be reasonable, though I only adjust this value
1601 as a last resort.
1602
1603 The --max-parallelism option is sometimes set to one to prevent
1604 Nmap from sending more than one probe at a time to hosts. The
1605 --scan-delay option, discussed later, is another way to do this.
1606
1607 --min-rtt-timeout time, --max-rtt-timeout time, --initial-rtt-timeout
1608 time (Adjust probe timeouts) .
1609 Nmap maintains a running timeout value for determining how long it
1610 will wait for a probe response before giving up or retransmitting
1611 the probe. This is calculated based on the response times of
1612 previous probes.
1613
1614 If the network latency shows itself to be significant and variable,
1615 this timeout can grow to several seconds. It also starts at a
1616 conservative (high) level and may stay that way for a while when
1617 Nmap scans unresponsive hosts.
1618
1619 Specifying a lower --max-rtt-timeout and --initial-rtt-timeout than
1620 the defaults can cut scan times significantly. This is particularly
1621 true for pingless (-PN) scans, and those against heavily filtered
1622 networks. Don´t get too aggressive though. The scan can end up
1623 taking longer if you specify such a low value that many probes are
1624 timing out and retransmitting while the response is in transit.
1625
1626 If all the hosts are on a local network, 100 milliseconds is a
1627 reasonable aggressive --max-rtt-timeout value. If routing is
1628 involved, ping a host on the network first with the ICMP ping
1629 utility, or with a custom packet crafter such as hping2. that is
1630 more likely to get through a firewall. Look at the maximum round
1631 trip time out of ten packets or so. You might want to double that
1632 for the --initial-rtt-timeout and triple or quadruple it for the
1633 --max-rtt-timeout. I generally do not set the maximum RTT below
1634 100 ms, no matter what the ping times are. Nor do I exceed 1000 ms.
1635
1636 --min-rtt-timeout is a rarely used option that could be useful when
1637 a network is so unreliable that even Nmap´s default is too
1638 aggressive. Since Nmap only reduces the timeout down to the minimum
1639 when the network seems to be reliable, this need is unusual and
1640 should be reported as a bug to the nmap-dev mailing list..
1641
1642 --max-retries numtries (Specify the maximum number of port scan probe
1643 retransmissions) .
1644 When Nmap receives no response to a port scan probe, it could mean
1645 the port is filtered. Or maybe the probe or response was simply
1646 lost on the network. It is also possible that the target host has
1647 rate limiting enabled that temporarily blocked the response. So
1648 Nmap tries again by retransmitting the initial probe. If Nmap
1649 detects poor network reliability, it may try many more times before
1650 giving up on a port. While this benefits accuracy, it also lengthen
1651 scan times. When performance is critical, scans may be sped up by
1652 limiting the number of retransmissions allowed. You can even
1653 specify --max-retries 0 to prevent any retransmissions, though that
1654 is only recommended for situations such as informal surveys where
1655 occasional missed ports and hosts are acceptable.
1656
1657 The default (with no -T template) is to allow ten retransmissions.
1658 If a network seems reliable and the target hosts aren´t rate
1659 limiting, Nmap usually only does one retransmission. So most target
1660 scans aren´t even affected by dropping --max-retries to a low value
1661 such as three. Such values can substantially speed scans of slow
1662 (rate limited) hosts. You usually lose some information when Nmap
1663 gives up on ports early, though that may be preferable to letting
1664 the --host-timeout expire and losing all information about the
1665 target.
1666
1667 --host-timeout time (Give up on slow target hosts) .
1668 Some hosts simply take a long time to scan. This may be due to
1669 poorly performing or unreliable networking hardware or software,
1670 packet rate limiting, or a restrictive firewall. The slowest few
1671 percent of the scanned hosts can eat up a majority of the scan
1672 time. Sometimes it is best to cut your losses and skip those hosts
1673 initially. Specify --host-timeout with the maximum amount of time
1674 you are willing to wait. For example, specify 30m to ensure that
1675 Nmap doesn´t waste more than half an hour on a single host. Note
1676 that Nmap may be scanning other hosts at the same time during that
1677 half an hour, so it isn´t a complete loss. A host that times out is
1678 skipped. No port table, OS detection, or version detection results
1679 are printed for that host.
1680
1681 --scan-delay time; --max-scan-delay time (Adjust delay between probes)
1682 .
1683 This option causes Nmap to wait at least the given amount of time
1684 between each probe it sends to a given host. This is particularly
1685 useful in the case of rate limiting.. Solaris machines (among many
1686 others) will usually respond to UDP scan probe packets with only
1687 one ICMP message per second. Any more than that sent by Nmap will
1688 be wasteful. A --scan-delay of 1s will keep Nmap at that slow rate.
1689 Nmap tries to detect rate limiting and adjust the scan delay
1690 accordingly, but it doesn´t hurt to specify it explicitly if you
1691 already know what rate works best.
1692
1693 When Nmap adjusts the scan delay upward to cope with rate limiting,
1694 the scan slows down dramatically. The --max-scan-delay option
1695 specifies the largest delay that Nmap will allow. A low
1696 --max-scan-delay can speed up Nmap, but it is risky. Setting this
1697 value too low can lead to wasteful packet retransmissions and
1698 possible missed ports when the target implements strict rate
1699 limiting.
1700
1701 Another use of --scan-delay is to evade threshold based intrusion
1702 detection and prevention systems (IDS/IPS)..
1703
1704 --min-rate number; --max-rate number (Directly control the scanning
1705 rate) .
1706 Nmap´s dynamic timing does a good job of finding an appropriate
1707 speed at which to scan. Sometimes, however, you may happen to know
1708 an appropriate scanning rate for a network, or you may have to
1709 guarantee that a scan will be finished by a certain time. Or
1710 perhaps you must keep Nmap from scanning too quickly. The
1711 --min-rate and --max-rate options are designed for these
1712 situations.
1713
1714 When the --min-rate option is given Nmap will do its best to send
1715 packets as fast as or faster than the given rate. The argument is a
1716 positive real number representing a packet rate in packets per
1717 second. For example, specifying --min-rate 300 means that Nmap will
1718 try to keep the sending rate at or above 300 packets per second.
1719 Specifying a minimum rate does not keep Nmap from going faster if
1720 conditions warrant.
1721
1722 Likewise, --max-rate limits a scan´s sending rate to a given
1723 maximum. Use --max-rate 100, for example, to limit sending to 100
1724 packets per second on a fast network. Use --max-rate 0.1 for a slow
1725 scan of one packet every ten seconds. Use --min-rate and --max-rate
1726 together to keep the rate inside a certain range.
1727
1728 These two options are global, affecting an entire scan, not
1729 individual hosts. They only affect port scans and host discovery
1730 scans. Other features like OS detection implement their own timing.
1731
1732 There are two conditions when the actual scanning rate may fall
1733 below the requested minimum. The first is if the minimum is faster
1734 than the fastest rate at which Nmap can send, which is dependent on
1735 hardware. In this case Nmap will simply send packets as fast as
1736 possible, but be aware that such high rates are likely to cause a
1737 loss of accuracy. The second case is when Nmap has nothing to send,
1738 for example at the end of a scan when the last probes have been
1739 sent and Nmap is waiting for them to time out or be responded to.
1740 It´s normal to see the scanning rate drop at the end of a scan or
1741 in between hostgroups. The sending rate may temporarily exceed the
1742 maximum to make up for unpredictable delays, but on average the
1743 rate will stay at or below the maximum.
1744
1745 Specifying a minimum rate should be done with care. Scanning faster
1746 than a network can support may lead to a loss of accuracy. In some
1747 cases, using a faster rate can make a scan take longer than it
1748 would with a slower rate. This is because Nmap´s
1749
1750 adaptive retransmission algorithms will detect the network
1751 congestion caused by an excessive scanning rate and increase the
1752 number of retransmissions in order to improve accuracy. So even
1753 though packets are sent at a higher rate, more packets are sent
1754 overall. Cap the number of retransmissions with the --max-retries
1755 option if you need to set an upper limit on total scan time.
1756
1757 --defeat-rst-ratelimit .
1758 Many hosts have long used rate limiting. to reduce the number of
1759 ICMP error messages (such as port-unreachable errors) they send.
1760 Some systems now apply similar rate limits to the RST (reset)
1761 packets they generate. This can slow Nmap down dramatically as it
1762 adjusts its timing to reflect those rate limits. You can tell Nmap
1763 to ignore those rate limits (for port scans such as SYN scan which
1764 don´t treat non-responsive ports as open) by specifying
1765 --defeat-rst-ratelimit.
1766
1767 Using this option can reduce accuracy, as some ports will appear
1768 non-responsive because Nmap didn´t wait long enough for a
1769 rate-limited RST response. With a SYN scan, the non-response
1770 results in the port being labeled filtered rather than the closed
1771 state we see when RST packets are received. This option is useful
1772 when you only care about open ports, and distinguishing between
1773 closed and filtered ports isn´t worth the extra time.
1774
1775 -T paranoid|sneaky|polite|normal|aggressive|insane (Set a timing
1776 template) .
1777 While the fine-grained timing controls discussed in the previous
1778 section are powerful and effective, some people find them
1779 confusing. Moreover, choosing the appropriate values can sometimes
1780 take more time than the scan you are trying to optimize. So Nmap
1781 offers a simpler approach, with six timing templates. You can
1782 specify them with the -T option and their number (0–5) or their
1783 name. The template names are paranoid (0), sneaky (1), polite (2),
1784 normal (3), aggressive (4), and insane (5). The first two are for
1785 IDS evasion. Polite mode slows down the scan to use less bandwidth
1786 and target machine resources. Normal mode is the default and so -T3
1787 does nothing. Aggressive mode speeds scans up by making the
1788 assumption that you are on a reasonably fast and reliable network.
1789 Finally insane mode. assumes that you are on an extraordinarily
1790 fast network or are willing to sacrifice some accuracy for speed.
1791
1792 These templates allow the user to specify how aggressive they wish
1793 to be, while leaving Nmap to pick the exact timing values. The
1794 templates also make some minor speed adjustments for which
1795 fine-grained control options do not currently exist. For example,
1796 -T4. prohibits the dynamic scan delay from exceeding 10 ms for TCP
1797 ports and -T5 caps that value at 5 ms. Templates can be used in
1798 combination with fine-grained controls, and the fine-grained
1799 controls will you specify will take precedence over the timing
1800 template default for that parameter. I recommend using -T4 when
1801 scanning reasonably modern and reliable networks. Keep that option
1802 even when you add fine-grained controls so that you benefit from
1803 those extra minor optimizations that it enables.
1804
1805 If you are on a decent broadband or ethernet connection, I would
1806 recommend always using -T4. Some people love -T5 though it is too
1807 aggressive for my taste. People sometimes specify -T2 because they
1808 think it is less likely to crash hosts or because they consider
1809 themselves to be polite in general. They often don´t realize just
1810 how slow -T polite. really is. Their scan may take ten times
1811 longer than a default scan. Machine crashes and bandwidth problems
1812 are rare with the default timing options (-T3) and so I normally
1813 recommend that for cautious scanners. Omitting version detection is
1814 far more effective than playing with timing values at reducing
1815 these problems.
1816
1817 While -T0. and -T1. may be useful for avoiding IDS alerts, they
1818 will take an extraordinarily long time to scan thousands of
1819 machines or ports. For such a long scan, you may prefer to set the
1820 exact timing values you need rather than rely on the canned -T0 and
1821 -T1 values.
1822
1823 The main effects of T0 are serializing the scan so only one port is
1824 scanned at a time, and waiting five minutes between sending each
1825 probe. T1 and T2 are similar but they only wait 15 seconds and 0.4
1826 seconds, respectively, between probes. T3 is Nmap´s default
1827 behavior, which includes parallelization.. -T4 does the equivalent
1828 of --max-rtt-timeout 1250 --initial-rtt-timeout 500 --max-retries 6
1829 and sets the maximum TCP scan delay to 10 milliseconds. T5 does
1830 the equivalent of --max-rtt-timeout 300 --min-rtt-timeout 50
1831 --initial-rtt-timeout 250 --max-retries 2 --host-timeout 15m as
1832 well as setting the maximum TCP scan delay to 5 ms.
1833
1835 Many Internet pioneers envisioned a global open network with a
1836 universal IP address space allowing virtual connections between any two
1837 nodes. This allows hosts to act as true peers, serving and retrieving
1838 information from each other. People could access all of their home
1839 systems from work, changing the climate control settings or unlocking
1840 the doors for early guests. This vision of universal connectivity has
1841 been stifled by address space shortages and security concerns. In the
1842 early 1990s, organizations began deploying firewalls for the express
1843 purpose of reducing connectivity. Huge networks were cordoned off from
1844 the unfiltered Internet by application proxies, network address
1845 translation, and packet filters. The unrestricted flow of information
1846 gave way to tight regulation of approved communication channels and the
1847 content that passes over them.
1848
1849 Network obstructions such as firewalls can make mapping a network
1850 exceedingly difficult. It will not get any easier, as stifling casual
1851 reconnaissance is often a key goal of implementing the devices.
1852 Nevertheless, Nmap offers many features to help understand these
1853 complex networks, and to verify that filters are working as intended.
1854 It even supports mechanisms for bypassing poorly implemented defenses.
1855 One of the best methods of understanding your network security posture
1856 is to try to defeat it. Place yourself in the mind-set of an attacker,
1857 and deploy techniques from this section against your networks. Launch
1858 an FTP bounce scan, idle scan, fragmentation attack, or try to tunnel
1859 through one of your own proxies.
1860
1861 In addition to restricting network activity, companies are increasingly
1862 monitoring traffic with intrusion detection systems (IDS). All of the
1863 major IDSs ship with rules designed to detect Nmap scans because scans
1864 are sometimes a precursor to attacks. Many of these products have
1865 recently morphed into intrusion prevention systems (IPS). that
1866 actively block traffic deemed malicious. Unfortunately for network
1867 administrators and IDS vendors, reliably detecting bad intentions by
1868 analyzing packet data is a tough problem. Attackers with patience,
1869 skill, and the help of certain Nmap options can usually pass by IDSs
1870 undetected. Meanwhile, administrators must cope with large numbers of
1871 false positive results where innocent activity is misdiagnosed and
1872 alerted on or blocked.
1873
1874 Occasionally people suggest that Nmap should not offer features for
1875 evading firewall rules or sneaking past IDSs. They argue that these
1876 features are just as likely to be misused by attackers as used by
1877 administrators to enhance security. The problem with this logic is that
1878 these methods would still be used by attackers, who would just find
1879 other tools or patch the functionality into Nmap. Meanwhile,
1880 administrators would find it that much harder to do their jobs.
1881 Deploying only modern, patched FTP servers is a far more powerful
1882 defense than trying to prevent the distribution of tools implementing
1883 the FTP bounce attack.
1884
1885 There is no magic bullet (or Nmap option) for detecting and subverting
1886 firewalls and IDS systems. It takes skill and experience. A tutorial is
1887 beyond the scope of this reference guide, which only lists the relevant
1888 options and describes what they do.
1889
1890 -f (fragment packets); --mtu (using the specified MTU) .
1891 The -f option causes the requested scan (including ping scans) to
1892 use tiny fragmented IP packets. The idea is to split up the TCP
1893 header over several packets to make it harder for packet filters,
1894 intrusion detection systems, and other annoyances to detect what
1895 you are doing. Be careful with this! Some programs have trouble
1896 handling these tiny packets. The old-school sniffer named Sniffit
1897 segmentation faulted immediately upon receiving the first fragment.
1898 Specify this option once, and Nmap splits the packets into eight
1899 bytes or less after the IP header. So a 20-byte TCP header would be
1900 split into three packets. Two with eight bytes of the TCP header,
1901 and one with the final four. Of course each fragment also has an IP
1902 header. Specify -f again to use 16 bytes per fragment (reducing the
1903 number of fragments).. Or you can specify your own offset size
1904 with the --mtu option. Don´t also specify -f if you use --mtu. The
1905 offset must be a multiple of eight. While fragmented packets won´t
1906 get by packet filters and firewalls that queue all IP fragments,
1907 such as the CONFIG_IP_ALWAYS_DEFRAG option in the Linux kernel,
1908 some networks can´t afford the performance hit this causes and thus
1909 leave it disabled. Others can´t enable this because fragments may
1910 take different routes into their networks. Some source systems
1911 defragment outgoing packets in the kernel. Linux with the iptables.
1912 connection tracking module is one such example. Do a scan while a
1913 sniffer such as Wireshark. is running to ensure that sent packets
1914 are fragmented. If your host OS is causing problems, try the
1915 --send-eth. option to bypass the IP layer and send raw ethernet
1916 frames.
1917
1918 Fragmentation is only supported for Nmap´s raw packet features,
1919 which includes TCP and UDP port scans (except connect scan and FTP
1920 bounce scan) and OS detection. Features such as version detection
1921 and the Nmap Scripting Engine generally don´t support fragmentation
1922 because they rely on your host´s TCP stack to communicate with
1923 target services.
1924
1925 -D decoy1[,decoy2][,ME][,...] (Cloak a scan with decoys) .
1926 Causes a decoy scan to be performed, which makes it appear to the
1927 remote host that the host(s) you specify as decoys are scanning the
1928 target network too. Thus their IDS might report 5–10 port scans
1929 from unique IP addresses, but they won´t know which IP was scanning
1930 them and which were innocent decoys. While this can be defeated
1931 through router path tracing, response-dropping, and other active
1932 mechanisms, it is generally an effective technique for hiding your
1933 IP address.
1934
1935 Separate each decoy host with commas, and you can optionally use
1936 ME. as one of the decoys to represent the position for your real
1937 IP address. If you put ME in the sixth position or later, some
1938 common port scan detectors (such as Solar Designer´s. excellent
1939 Scanlogd). are unlikely to show your IP address at all. If you
1940 don´t use ME, Nmap will put you in a random position. You can also
1941 use RND. to generate a random, non-reserved IP address, or
1942 RND:number to generate number addresses.
1943
1944 Note that the hosts you use as decoys should be up or you might
1945 accidentally SYN flood your targets. Also it will be pretty easy to
1946 determine which host is scanning if only one is actually up on the
1947 network. You might want to use IP addresses instead of names (so
1948 the decoy networks don´t see you in their nameserver logs).
1949
1950 Decoys are used both in the initial ping scan (using ICMP, SYN,
1951 ACK, or whatever) and during the actual port scanning phase. Decoys
1952 are also used during remote OS detection (-O). Decoys do not work
1953 with version detection or TCP connect scan. When a scan delay is in
1954 effect, the delay is enforced between each batch of spoofed probes,
1955 not between each individual probe. Because decoys are sent as a
1956 batch all at once, they may temporarily violate congestion control
1957 limits.
1958
1959 It is worth noting that using too many decoys may slow your scan
1960 and potentially even make it less accurate. Also, some ISPs will
1961 filter out your spoofed packets, but many do not restrict spoofed
1962 IP packets at all.
1963
1964 -S IP_Address (Spoof source address) .
1965 In some circumstances, Nmap may not be able to determine your
1966 source address (Nmap will tell you if this is the case). In this
1967 situation, use -S with the IP address of the interface you wish to
1968 send packets through.
1969
1970 Another possible use of this flag is to spoof the scan to make the
1971 targets think that someone else is scanning them. Imagine a company
1972 being repeatedly port scanned by a competitor! The -e option and
1973 -PN are generally required for this sort of usage. Note that you
1974 usually won´t receive reply packets back (they will be addressed to
1975 the IP you are spoofing), so Nmap won´t produce useful reports.
1976
1977 -e interface (Use specified interface) .
1978 Tells Nmap what interface to send and receive packets on. Nmap
1979 should be able to detect this automatically, but it will tell you
1980 if it cannot.
1981
1982 --source-port portnumber; -g portnumber (Spoof source port number) .
1983 One surprisingly common misconfiguration is to trust traffic based
1984 only on the source port number. It is easy to understand how this
1985 comes about. An administrator will set up a shiny new firewall,
1986 only to be flooded with complains from ungrateful users whose
1987 applications stopped working. In particular, DNS may be broken
1988 because the UDP DNS replies from external servers can no longer
1989 enter the network. FTP is another common example. In active FTP
1990 transfers, the remote server tries to establish a connection back
1991 to the client to transfer the requested file.
1992
1993 Secure solutions to these problems exist, often in the form of
1994 application-level proxies or protocol-parsing firewall modules.
1995 Unfortunately there are also easier, insecure solutions. Noting
1996 that DNS replies come from port 53 and active FTP from port 20,
1997 many administrators have fallen into the trap of simply allowing
1998 incoming traffic from those ports. They often assume that no
1999 attacker would notice and exploit such firewall holes. In other
2000 cases, administrators consider this a short-term stop-gap measure
2001 until they can implement a more secure solution. Then they forget
2002 the security upgrade.
2003
2004 Overworked network administrators are not the only ones to fall
2005 into this trap. Numerous products have shipped with these insecure
2006 rules. Even Microsoft has been guilty. The IPsec filters that
2007 shipped with Windows 2000 and Windows XP contain an implicit rule
2008 that allows all TCP or UDP traffic from port 88 (Kerberos). In
2009 another well-known case, versions of the Zone Alarm personal
2010 firewall up to 2.1.25 allowed any incoming UDP packets with the
2011 source port 53 (DNS) or 67 (DHCP).
2012
2013 Nmap offers the -g and --source-port options (they are equivalent)
2014 to exploit these weaknesses. Simply provide a port number and Nmap
2015 will send packets from that port where possible. Nmap must use
2016 different port numbers for certain OS detection tests to work
2017 properly, and DNS requests ignore the --source-port flag because
2018 Nmap relies on system libraries to handle those. Most TCP scans,
2019 including SYN scan, support the option completely, as does UDP
2020 scan.
2021
2022 --data-length number (Append random data to sent packets) .
2023 Normally Nmap sends minimalist packets containing only a header. So
2024 its TCP packets are generally 40 bytes and ICMP echo requests are
2025 just 28. Some UDP ports. and IP protocols. get a custom payload
2026 by default. This option tells Nmap to append the given number of
2027 random bytes to most of the packets it sends, and not to use any
2028 protocol-specific payloads. (Use --data-length 0 for no random or
2029 protocol-specific payloads.. OS detection (-O) packets are not
2030 affected. because accuracy there requires probe consistency, but
2031 most pinging and portscan packets support this. It slows things
2032 down a little, but can make a scan slightly less conspicuous.
2033
2034 --ip-options S|R [route]|L [route]|T|U ... ; --ip-options hex string
2035 (Send packets with specified ip options) .
2036 The IP protocol[13] offers several options which may be placed in
2037 packet headers. Unlike the ubiquitous TCP options, IP options are
2038 rarely seen due to practicality and security concerns. In fact,
2039 many Internet routers block the most dangerous options such as
2040 source routing. Yet options can still be useful in some cases for
2041 determining and manipulating the network route to target machines.
2042 For example, you may be able to use the record route option to
2043 determine a path to a target even when more traditional
2044 traceroute-style approaches fail. Or if your packets are being
2045 dropped by a certain firewall, you may be able to specify a
2046 different route with the strict or loose source routing options.
2047
2048 The most powerful way to specify IP options is to simply pass in
2049 values as the argument to --ip-options. Precede each hex number
2050 with \x then the two digits. You may repeat certain characters by
2051 following them with an asterisk and then the number of times you
2052 wish them to repeat. For example, \x01\x07\x04\x00*36\x01 is a hex
2053 string containing 36 NUL bytes.
2054
2055 Nmap also offers a shortcut mechanism for specifying options.
2056 Simply pass the letter R, T, or U to request record-route,.
2057 record-timestamp,. or both options together, respectively. Loose
2058 or strict source routing. may be specified with an L or S followed
2059 by a space and then a space-separated list of IP addresses.
2060
2061 If you wish to see the options in packets sent and received,
2062 specify --packet-trace. For more information and examples of using
2063 IP options with Nmap, see
2064 http://seclists.org/nmap-dev/2006/q3/0052.html.
2065
2066 --ttl value (Set IP time-to-live field) .
2067 Sets the IPv4 time-to-live field in sent packets to the given
2068 value.
2069
2070 --randomize-hosts (Randomize target host order) .
2071 Tells Nmap to shuffle each group of up to 16384 hosts before it
2072 scans them. This can make the scans less obvious to various network
2073 monitoring systems, especially when you combine it with slow timing
2074 options. If you want to randomize over larger group sizes, increase
2075 PING_GROUP_SZ. in nmap.h. and recompile. An alternative solution
2076 is to generate the target IP list with a list scan (-sL -n -oN
2077 filename), randomize it with a Perl script, then provide the whole
2078 list to Nmap with -iL..
2079
2080 --spoof-mac MAC address, prefix, or vendor name (Spoof MAC address) .
2081 Asks Nmap to use the given MAC address for all of the raw ethernet
2082 frames it sends. This option implies --send-eth. to ensure that
2083 Nmap actually sends ethernet-level packets. The MAC given can take
2084 several formats. If it is simply the number 0, Nmap chooses a
2085 completely random MAC address for the session. If the given string
2086 is an even number of hex digits (with the pairs optionally
2087 separated by a colon), Nmap will use those as the MAC. If fewer
2088 than 12 hex digits are provided, Nmap fills in the remainder of the
2089 six bytes with random values. If the argument isn´t a zero or hex
2090 string, Nmap looks through nmap-mac-prefixes to find a vendor name
2091 containing the given string (it is case insensitive). If a match is
2092 found, Nmap uses the vendor´s OUI (three-byte prefix). and fills
2093 out the remaining three bytes randomly. Valid --spoof-mac argument
2094 examples are Apple, 0, 01:02:03:04:05:06, deadbeefcafe, 0020F2, and
2095 Cisco. This option only affects raw packet scans such as SYN scan
2096 or OS detection, not connection-oriented features such as version
2097 detection or the Nmap Scripting Engine.
2098
2099 --badsum (Send packets with bogus TCP/UDP checksums) .
2100 Asks Nmap to use an invalid TCP, UDP or SCTP checksum for packets
2101 sent to target hosts. Since virtually all host IP stacks properly
2102 drop these packets, any responses received are likely coming from a
2103 firewall or IDS that didn´t bother to verify the checksum. For more
2104 details on this technique, see http://nmap.org/p60-12.html
2105
2106 --adler32 (Use deprecated Adler32 instead of CRC32C for SCTP checksums)
2107 .
2108 Asks Nmap to use the deprecated Adler32 algorithm for calculating
2109 the SCTP checksum. If --adler32 is not given, CRC-32C (Castagnoli)
2110 is used. RFC 2960[14] originally defined Adler32 as checksum
2111 algorithm for SCTP; RFC 4960[7] later redefined the SCTP checksums
2112 to use CRC-32C. Current SCTP implementations should be using
2113 CRC-32C, but in order to elicit responses from old, legacy SCTP
2114 implementations, it may be preferrable to use Adler32.
2115
2117 Any security tool is only as useful as the output it generates. Complex
2118 tests and algorithms are of little value if they aren´t presented in an
2119 organized and comprehensible fashion. Given the number of ways Nmap is
2120 used by people and other software, no single format can please
2121 everyone. So Nmap offers several formats, including the interactive
2122 mode for humans to read directly and XML for easy parsing by software.
2123
2124 In addition to offering different output formats, Nmap provides options
2125 for controlling the verbosity of output as well as debugging messages.
2126 Output types may be sent to standard output or to named files, which
2127 Nmap can append to or clobber. Output files may also be used to resume
2128 aborted scans.
2129
2130 Nmap makes output available in five different formats. The default is
2131 called interactive output,. and it is sent to standard output
2132 (stdout).. There is also normal output,. which is similar to
2133 interactive except that it displays less runtime information and
2134 warnings since it is expected to be analyzed after the scan completes
2135 rather than interactively.
2136
2137 XML output. is one of the most important output types, as it can be
2138 converted to HTML, easily parsed by programs such as Nmap graphical
2139 user interfaces, or imported into databases.
2140
2141 The two remaining output types are the simple grepable output. which
2142 includes most information for a target host on a single line, and
2143 sCRiPt KiDDi3 0utPUt. for users who consider themselves |<-r4d.
2144
2145 While interactive output is the default and has no associated
2146 command-line options, the other four format options use the same
2147 syntax. They take one argument, which is the filename that results
2148 should be stored in. Multiple formats may be specified, but each format
2149 may only be specified once. For example, you may wish to save normal
2150 output for your own review while saving XML of the same scan for
2151 programmatic analysis. You might do this with the options -oX
2152 myscan.xml -oN myscan.nmap. While this chapter uses the simple names
2153 like myscan.xml for brevity, more descriptive names are generally
2154 recommended. The names chosen are a matter of personal preference,
2155 though I use long ones that incorporate the scan date and a word or two
2156 describing the scan, placed in a directory named after the company I´m
2157 scanning.
2158
2159 While these options save results to files, Nmap still prints
2160 interactive output to stdout as usual. For example, the command nmap
2161 -oX myscan.xml target prints XML to myscan.xml and fills standard
2162 output with the same interactive results it would have printed if -oX
2163 wasn´t specified at all. You can change this by passing a hyphen
2164 character as the argument to one of the format types. This causes Nmap
2165 to deactivate interactive output, and instead print results in the
2166 format you specified to the standard output stream. So the command nmap
2167 -oX - target will send only XML output to stdout.. Serious errors may
2168 still be printed to the normal error stream, stderr..
2169
2170 Unlike some Nmap arguments, the space between the logfile option flag
2171 (such as -oX) and the filename or hyphen is mandatory. If you omit the
2172 flags and give arguments such as -oG- or -oXscan.xml, a backwards
2173 compatibility feature of Nmap will cause the creation of normal format
2174 output files named G- and Xscan.xml respectively.
2175
2176 All of these arguments support strftime-like. conversions in the
2177 filename. %H, %M, %S, %m, %d, %y, and %Y are all exactly the same as
2178 in strftime. %T is the same as %H%M%S, %R is the same as %H%M, and %D
2179 is the same as %m%d%y. A % followed by any other character just yields
2180 that character (%% gives you a percent symbol). So -oX ´scan-%T-%D.xml´
2181 will use an XML file in the form of scan-144840-121307.xml.
2182
2183 Nmap also offers options to control scan verbosity and to append to
2184 output files rather than clobbering them. All of these options are
2185 described below.
2186
2187 Nmap Output Formats
2188
2189 -oN filespec (normal output) .
2190 Requests that normal output be directed to the given filename. As
2191 discussed above, this differs slightly from interactive output.
2192
2193 -oX filespec (XML output) .
2194 Requests that XML output be directed to the given filename. Nmap
2195 includes a document type definition (DTD) which allows XML parsers
2196 to validate Nmap XML output. While it is primarily intended for
2197 programmatic use, it can also help humans interpret Nmap XML
2198 output. The DTD defines the legal elements of the format, and often
2199 enumerates the attributes and values they can take on. The latest
2200 version is always available from http://nmap.org/data/nmap.dtd.
2201
2202 XML offers a stable format that is easily parsed by software. Free
2203 XML parsers are available for all major computer languages,
2204 including C/C++, Perl, Python, and Java. People have even written
2205 bindings for most of these languages to handle Nmap output and
2206 execution specifically. Examples are Nmap::Scanner[15] and
2207 Nmap::Parser[16] in Perl CPAN. In almost all cases that a
2208 non-trivial application interfaces with Nmap, XML is the preferred
2209 format.
2210
2211 The XML output references an XSL stylesheet which can be used to
2212 format the results as HTML. The easiest way to use this is simply
2213 to load the XML output in a web browser such as Firefox or IE. By
2214 default, this will only work on the machine you ran Nmap on (or a
2215 similarly configured one) due to the hard-coded nmap.xsl filesystem
2216 path. Use the --webxml or --stylesheet options to create portable
2217 XML files that render as HTML on any web-connected machine.
2218
2219 -oS filespec (ScRipT KIdd|3 oUTpuT) .
2220 Script kiddie output is like interactive output, except that it is
2221 post-processed to better suit the l33t HaXXorZ who previously
2222 looked down on Nmap due to its consistent capitalization and
2223 spelling. Humor impaired people should note that this option is
2224 making fun of the script kiddies before flaming me for supposedly
2225 “helping them”.
2226
2227 -oG filespec (grepable output) .
2228 This output format is covered last because it is deprecated. The
2229 XML output format is far more powerful, and is nearly as convenient
2230 for experienced users. XML is a standard for which dozens of
2231 excellent parsers are available, while grepable output is my own
2232 simple hack. XML is extensible to support new Nmap features as they
2233 are released, while I often must omit those features from grepable
2234 output for lack of a place to put them.
2235
2236 Nevertheless, grepable output is still quite popular. It is a
2237 simple format that lists each host on one line and can be trivially
2238 searched and parsed with standard Unix tools such as grep, awk,
2239 cut, sed, diff, and Perl. Even I usually use it for one-off tests
2240 done at the command line. Finding all the hosts with the SSH port
2241 open or that are running Solaris takes only a simple grep to
2242 identify the hosts, piped to an awk or cut command to print the
2243 desired fields.
2244
2245 Grepable output consists of comments (lines starting with a pound
2246 (#)). and target lines. A target line includes a combination of
2247 six labeled fields, separated by tabs and followed with a colon.
2248 The fields are Host, Ports, Protocols, Ignored State, OS, Seq
2249 Index, IP ID, and Status.
2250
2251 The most important of these fields is generally Ports, which gives
2252 details on each interesting port. It is a comma separated list of
2253 port entries. Each port entry represents one interesting port, and
2254 takes the form of seven slash (/) separated subfields. Those
2255 subfields are: Port number, State, Protocol, Owner, Service, SunRPC
2256 info, and Version info.
2257
2258 As with XML output, this man page does not allow for documenting
2259 the entire format. A more detailed look at the Nmap grepable output
2260 format is available from
2261 http://nmap.org/book/output-formats-grepable-output.html.
2262
2263 -oA basename (Output to all formats) .
2264 As a convenience, you may specify -oA basename to store scan
2265 results in normal, XML, and grepable formats at once. They are
2266 stored in basename.nmap, basename.xml, and basename.gnmap,
2267 respectively. As with most programs, you can prefix the filenames
2268 with a directory path, such as ~/nmaplogs/foocorp/ on Unix or
2269 c:\hacking\sco on Windows.
2270
2271 Verbosity and debugging options
2272
2273 -v (Increase verbosity level) .
2274 Increases the verbosity level, causing Nmap to print more
2275 information about the scan in progress. Open ports are shown as
2276 they are found and completion time estimates are provided when Nmap
2277 thinks a scan will take more than a few minutes. Use it twice or
2278 more for even greater verbosity.
2279
2280 Most changes only affect interactive output, and some also affect
2281 normal and script kiddie output. The other output types are meant
2282 to be processed by machines, so Nmap can give substantial detail by
2283 default in those formats without fatiguing a human user. However,
2284 there are a few changes in other modes where output size can be
2285 reduced substantially by omitting some detail. For example, a
2286 comment line in the grepable output that provides a list of all
2287 ports scanned is only printed in verbose mode because it can be
2288 quite long.
2289
2290 -d [level] (Increase or set debugging level) .
2291 When even verbose mode doesn´t provide sufficient data for you,
2292 debugging is available to flood you with much more! As with the
2293 verbosity option (-v), debugging is enabled with a command-line
2294 flag (-d) and the debug level can be increased by specifying it
2295 multiple times.. Alternatively, you can set a debug level by
2296 giving an argument to -d. For example, -d9 sets level nine. That is
2297 the highest effective level and will produce thousands of lines
2298 unless you run a very simple scan with very few ports and targets.
2299
2300 Debugging output is useful when a bug is suspected in Nmap, or if
2301 you are simply confused as to what Nmap is doing and why. As this
2302 feature is mostly intended for developers, debug lines aren´t
2303 always self-explanatory. You may get something like: Timeout vals:
2304 srtt: -1 rttvar: -1 to: 1000000 delta 14987 ==> srtt: 14987 rttvar:
2305 14987 to: 100000. If you don´t understand a line, your only
2306 recourses are to ignore it, look it up in the source code, or
2307 request help from the development list (nmap-dev).. Some lines are
2308 self explanatory, but the messages become more obscure as the debug
2309 level is increased.
2310
2311 --reason (Host and port state reasons) .
2312 Shows the reason each port is set to a specific state and the
2313 reason each host is up or down. This option displays the type of
2314 the packet that determined a port or hosts state. For example, A
2315 RST packet from a closed port or an echo reply from an alive host.
2316 The information Nmap can provide is determined by the type of scan
2317 or ping. The SYN scan and SYN ping (-sS and -PS) are very detailed,
2318 but the TCP connect scan (-sT) is limited by the implementation of
2319 the connect system call. This feature is automatically enabled by
2320 the debug option (-d). and the results are stored in XML log files
2321 even if this option is not specified.
2322
2323 --stats-every time (Print periodic timing stats) .
2324 Periodically prints a timing status message after each interval of
2325 time. The time is a specification of the kind described in the
2326 section called “TIMING AND PERFORMANCE”; so for example, use
2327 --stats-every 10s to get a status update every 10 seconds. Updates
2328 are printed to interactive output (the screen) and XML output.
2329
2330 --packet-trace (Trace packets and data sent and received) .
2331 Causes Nmap to print a summary of every packet sent or received.
2332 This is often used for debugging, but is also a valuable way for
2333 new users to understand exactly what Nmap is doing under the
2334 covers. To avoid printing thousands of lines, you may want to
2335 specify a limited number of ports to scan, such as -p20-30. If you
2336 only care about the goings on of the version detection subsystem,
2337 use --version-trace instead. If you only care about script tracing,
2338 specify --script-trace. With --packet-trace, you get all of the
2339 above.
2340
2341 --open (Show only open (or possibly open) ports) .
2342 Sometimes you only care about ports you can actually connect to
2343 (open ones), and don´t want results cluttered with closed,
2344 filtered, and closed|filtered ports. Output customization is
2345 normally done after the scan using tools such as grep, awk, and
2346 Perl, but this feature was added due to overwhelming requests.
2347 Specify --open to only see open, open|filtered, and unfiltered
2348 ports. These three ports are treated just as they normally are,
2349 which means that open|filtered and unfiltered may be condensed into
2350 counts if there are an overwhelming number of them.
2351
2352 --iflist (List interfaces and routes) .
2353 Prints the interface list and system routes as detected by Nmap.
2354 This is useful for debugging routing problems or device
2355 mischaracterization (such as Nmap treating a PPP connection as
2356 ethernet).
2357
2358 --log-errors (Log errors/warnings to normal mode output file) .
2359 Warnings and errors printed by Nmap usually go only to the screen
2360 (interactive output), leaving any normal-format output files
2361 (usually specified with -oN) uncluttered. When you do want to see
2362 those messages in the normal output file you specified, add this
2363 option. It is useful when you aren´t watching the interactive
2364 output or when you want to record errors while debugging a problem.
2365 The error and warning messages will still appear in interactive
2366 mode too. This won´t work for most errors related to bad
2367 command-line arguments because Nmap may not have initialized its
2368 output files yet. In addition, some Nmap error and warning messages
2369 use a different system which does not yet support this option.
2370
2371 An alternative to --log-errors is redirecting interactive output
2372 (including the standard error stream) to a file. Most Unix shells
2373 make this approach easy, though it can be difficult on Windows.
2374
2375 Miscellaneous output options
2376
2377 --append-output (Append to rather than clobber output files) .
2378 When you specify a filename to an output format flag such as -oX or
2379 -oN, that file is overwritten by default. If you prefer to keep the
2380 existing content of the file and append the new results, specify
2381 the --append-output option. All output filenames specified in that
2382 Nmap execution will then be appended to rather than clobbered. This
2383 doesn´t work well for XML (-oX) scan data as the resultant file
2384 generally won´t parse properly until you fix it up by hand.
2385
2386 --resume filename (Resume aborted scan) .
2387 Some extensive Nmap runs take a very long time—on the order of
2388 days. Such scans don´t always run to completion. Restrictions may
2389 prevent Nmap from being run during working hours, the network could
2390 go down, the machine Nmap is running on might suffer a planned or
2391 unplanned reboot, or Nmap itself could crash. The administrator
2392 running Nmap could cancel it for any other reason as well, by
2393 pressing ctrl-C. Restarting the whole scan from the beginning may
2394 be undesirable. Fortunately, if normal (-oN) or grepable (-oG) logs
2395 were kept, the user can ask Nmap to resume scanning with the target
2396 it was working on when execution ceased. Simply specify the
2397 --resume option and pass the normal/grepable output file as its
2398 argument. No other arguments are permitted, as Nmap parses the
2399 output file to use the same ones specified previously. Simply call
2400 Nmap as nmap --resume logfilename. Nmap will append new results to
2401 the data files specified in the previous execution. Resumption does
2402 not support the XML output format because combining the two runs
2403 into one valid XML file would be difficult.
2404
2405 --stylesheet path or URL (Set XSL stylesheet to transform XML output) .
2406 Nmap ships with an XSL stylesheet named nmap.xsl for viewing or
2407 translating XML output to HTML. The XML output includes an
2408 xml-stylesheet directive which points to nmap.xml where it was
2409 initially installed by Nmap (or in the current working directory on
2410 Windows). Simply load Nmap´s XML output in a modern web browser and
2411 it should retrieve nmap.xsl from the filesystem and use it to
2412 render results. If you wish to use a different stylesheet, specify
2413 it as the argument to --stylesheet. You must pass the full pathname
2414 or URL. One common invocation is --stylesheet
2415 http://nmap.org/data/nmap.xsl. This tells a browser to load the
2416 latest version of the stylesheet from Nmap.Org. The --webxml option
2417 does the same thing with less typing and memorization. Loading the
2418 XSL from Nmap.Org makes it easier to view results on a machine that
2419 doesn´t have Nmap (and thus nmap.xsl) installed. So the URL is
2420 often more useful, but the local filesystem location of nmap.xsl is
2421 used by default for privacy reasons.
2422
2423 --webxml (Load stylesheet from Nmap.Org) .
2424 This convenience option is simply an alias for --stylesheet
2425 http://nmap.org/data/nmap.xsl.
2426
2427 --no-stylesheet (Omit XSL stylesheet declaration from XML) .
2428 Specify this option to prevent Nmap from associating any XSL
2429 stylesheet with its XML output. The xml-stylesheet directive is
2430 omitted.
2431
2433 This section describes some important (and not-so-important) options
2434 that don´t really fit anywhere else.
2435
2436 -6 (Enable IPv6 scanning) .
2437 Since 2002, Nmap has offered IPv6 support for its most popular
2438 features. In particular, ping scanning (TCP-only), connect
2439 scanning, and version detection all support IPv6. The command
2440 syntax is the same as usual except that you also add the -6 option.
2441 Of course, you must use IPv6 syntax if you specify an address
2442 rather than a hostname. An address might look like
2443 3ffe:7501:4819:2000:210:f3ff:fe03:14d0, so hostnames are
2444 recommended. The output looks the same as usual, with the IPv6
2445 address on the “interesting ports” line being the only IPv6 give
2446 away.
2447
2448 While IPv6 hasn´t exactly taken the world by storm, it gets
2449 significant use in some (usually Asian) countries and most modern
2450 operating systems support it. To use Nmap with IPv6, both the
2451 source and target of your scan must be configured for IPv6. If your
2452 ISP (like most of them) does not allocate IPv6 addresses to you,
2453 free tunnel brokers are widely available and work fine with Nmap. I
2454 use the free IPv6 tunnel broker. service at
2455 http://www.tunnelbroker.net. Other tunnel brokers are listed at
2456 Wikipedia[17]. 6to4 tunnels are another popular, free approach.
2457
2458 -A (Aggressive scan options) .
2459 This option enables additional advanced and aggressive options. I
2460 haven´t decided exactly which it stands for yet. Presently this
2461 enables OS detection (-O), version scanning (-sV), script scanning
2462 (-sC) and traceroute (--traceroute). More features may be added in
2463 the future. The point is to enable a comprehensive set of scan
2464 options without people having to remember a large set of flags.
2465 However, because script scanning with the default set is considered
2466 intrusive, you should not use -A against target networks without
2467 permission. This option only enables features, and not timing
2468 options (such as -T4) or verbosity options (-v) that you might want
2469 as well.
2470
2471 --datadir directoryname (Specify custom Nmap data file location) .
2472 Nmap obtains some special data at runtime in files named
2473 nmap-service-probes, nmap-services, nmap-protocols, nmap-rpc,
2474 nmap-mac-prefixes, and nmap-os-db. If the location of any of these
2475 files has been specified (using the --servicedb or --versiondb
2476 options), that location is used for that file. After that, Nmap
2477 searches these files in the directory specified with the --datadir
2478 option (if any). Any files not found there, are searched for in the
2479 directory specified by the NMAPDIR environmental variable.
2480 ~/.nmap. for real and effective UIDs (POSIX systems only) or
2481 location of the Nmap executable (Win32 only), and then a
2482 compiled-in location such as /usr/local/share/nmap or
2483 /usr/share/nmap . As a last resort, Nmap will look in the current
2484 directory.
2485
2486 --servicedb services file (Specify custom services file) .
2487 Asks Nmap to use the specified services file rather than the
2488 nmap-services data file that comes with Nmap. Using this option
2489 also causes a fast scan (-F) to be used. See the description for
2490 --datadir for more information on Nmap´s data files.
2491
2492 --versiondb service probes file (Specify custom service probes file) .
2493 Asks Nmap to use the specified service probes file rather than the
2494 nmap-service-probes data file that comes with Nmap. See the
2495 description for --datadir for more information on Nmap´s data
2496 files.
2497
2498 --send-eth (Use raw ethernet sending) .
2499 Asks Nmap to send packets at the raw ethernet (data link) layer
2500 rather than the higher IP (network) layer. By default, Nmap chooses
2501 the one which is generally best for the platform it is running on.
2502 Raw sockets (IP layer). are generally most efficient for Unix
2503 machines, while ethernet frames are required for Windows operation
2504 since Microsoft disabled raw socket support. Nmap still uses raw IP
2505 packets on Unix despite this option when there is no other choice
2506 (such as non-ethernet connections).
2507
2508 --send-ip (Send at raw IP level) .
2509 Asks Nmap to send packets via raw IP sockets rather than sending
2510 lower level ethernet frames. It is the complement to the --send-eth
2511 option discussed previously.
2512
2513 --privileged (Assume that the user is fully privileged) .
2514 Tells Nmap to simply assume that it is privileged enough to perform
2515 raw socket sends, packet sniffing, and similar operations that
2516 usually require root privileges. on Unix systems. By default Nmap
2517 quits if such operations are requested but geteuid is not zero.
2518 --privileged is useful with Linux kernel capabilities and similar
2519 systems that may be configured to allow unprivileged users to
2520 perform raw-packet scans. Be sure to provide this option flag
2521 before any flags for options that require privileges (SYN scan, OS
2522 detection, etc.). The NMAP_PRIVILEGED. environmental variable may
2523 be set as an equivalent alternative to --privileged.
2524
2525 --unprivileged (Assume that the user lacks raw socket privileges) .
2526 This option is the opposite of --privileged. It tells Nmap to treat
2527 the user as lacking network raw socket and sniffing privileges.
2528 This is useful for testing, debugging, or when the raw network
2529 functionality of your operating system is somehow broken. The
2530 NMAP_UNPRIVILEGED. environmental variable may be set as an
2531 equivalent alternative to --unprivileged.
2532
2533 --release-memory (Release memory before quitting) .
2534 This option is only useful for memory-leak debugging. It causes
2535 Nmap to release allocated memory just before it quits so that
2536 actual memory leaks are easier to spot. Normally Nmap skips this as
2537 the OS does this anyway upon process termination.
2538
2539 --interactive (Start in interactive mode) .
2540 Starts Nmap in interactive mode, which offers an interactive Nmap
2541 prompt allowing easy launching of multiple scans (either
2542 synchronously or in the background). This is useful for people who
2543 scan from multi-user systems as they often want to test their
2544 security without letting everyone else on the system know exactly
2545 which systems they are scanning. Use --interactive to activate this
2546 mode and then type h for help. This option is rarely used because
2547 proper shells are usually more familiar and feature-complete. This
2548 option includes a bang (!) operator for executing shell commands,
2549 which is one of many reasons not to install Nmap setuid root..
2550
2551 -V; --version (Print version number) .
2552 Prints the Nmap version number and exits.
2553
2554 -h; --help (Print help summary page) .
2555 Prints a short help screen with the most common command flags.
2556 Running Nmap without any arguments does the same thing.
2557
2559 During the execution of Nmap, all key presses are captured. This allows
2560 you to interact with the program without aborting and restarting it.
2561 Certain special keys will change options, while any other keys will
2562 print out a status message telling you about the scan. The convention
2563 is that lowercase letters increase the amount of printing, and
2564 uppercase letters decrease the printing. You may also press ‘?’ for
2565 help.
2566
2567 v / V
2568 Increase / decrease the verbosity level
2569
2570 d / D
2571 Increase / decrease the debugging Level
2572
2573 p / P
2574 Turn on / off packet tracing
2575
2576 ?
2577 Print a runtime interaction help screen
2578
2579 Anything else
2580 Print out a status message like this:
2581
2582 Stats: 0:00:08 elapsed; 111 hosts completed (5 up), 5 undergoing
2583 Service Scan
2584
2585 Service scan Timing: About 28.00% done; ETC: 16:18 (0:00:15
2586 remaining)
2587
2589 Here are some Nmap usage examples, from the simple and routine to a
2590 little more complex and esoteric. Some actual IP addresses and domain
2591 names are used to make things more concrete. In their place you should
2592 substitute addresses/names from your own network.. While I don´t think
2593 port scanning other networks is or should be illegal, some network
2594 administrators don´t appreciate unsolicited scanning of their networks
2595 and may complain. Getting permission first is the best approach.
2596
2597 For testing purposes, you have permission to scan the host
2598 scanme.nmap.org. This permission only includes scanning via Nmap and
2599 not testing exploits or denial of service attacks. To conserve
2600 bandwidth, please do not initiate more than a dozen scans against that
2601 host per day. If this free scanning target service is abused, it will
2602 be taken down and Nmap will report Failed to resolve given hostname/IP:
2603 scanme.nmap.org. These permissions also apply to the hosts
2604 scanme2.nmap.org, scanme3.nmap.org, and so on, though those hosts do
2605 not currently exist.
2606
2607 nmap -v scanme.nmap.org
2608
2609 This option scans all reserved TCP ports on the machine scanme.nmap.org
2610 . The -v option enables verbose mode.
2611
2612 nmap -sS -O scanme.nmap.org/24
2613
2614 Launches a stealth SYN scan against each machine that is up out of the
2615 256 IPs on “class C” sized network where Scanme resides. It also tries
2616 to determine what operating system is running on each host that is up
2617 and running. This requires root privileges because of the SYN scan and
2618 OS detection.
2619
2620 nmap -sV -p 22,53,110,143,4564 198.116.0-255.1-127
2621
2622 Launches host enumeration and a TCP scan at the first half of each of
2623 the 255 possible eight-bit subnets in the 198.116 class B address
2624 space. This tests whether the systems run SSH, DNS, POP3, or IMAP on
2625 their standard ports, or anything on port 4564. For any of these ports
2626 found open, version detection is used to determine what application is
2627 running.
2628
2629 nmap -v -iR 100000 -PN -p 80
2630
2631 Asks Nmap to choose 100,000 hosts at random and scan them for web
2632 servers (port 80). Host enumeration is disabled with -PN since first
2633 sending a couple probes to determine whether a host is up is wasteful
2634 when you are only probing one port on each target host anyway.
2635
2636 nmap -PN -p80 -oX logs/pb-port80scan.xml -oG logs/pb-port80scan.gnmap
2637 216.163.128.20/20
2638
2639 This scans 4096 IPs for any web servers (without pinging them) and
2640 saves the output in grepable and XML formats.
2641
2643 While this reference guide details all material Nmap options, it can´t
2644 fully demonstrate how to apply those features to quickly solve
2645 real-world tasks. For that, we released Nmap Network Scanning: The
2646 Official Nmap Project Guide to Network Discovery and Security Scanning.
2647 Topics include subverting firewalls and intrusion detection systems,
2648 optimizing Nmap performance, and automating common networking tasks
2649 with the Nmap Scripting Engine. Hints and instructions are provided for
2650 common Nmap tasks such as taking network inventory, penetration
2651 testing, detecting rogue wireless access points, and quashing network
2652 worm outbreaks. Examples and diagrams show actual communication on the
2653 wire. More than half of the book is available free online. See
2654 http://nmap.org/book for more information.
2655
2657 Like its author, Nmap isn´t perfect. But you can help make it better by
2658 sending bug reports or even writing patches. If Nmap doesn´t behave the
2659 way you expect, first upgrade to the latest version available from
2660 http://nmap.org. If the problem persists, do some research to determine
2661 whether it has already been discovered and addressed. Try searching for
2662 the error message on our search page at http://insecure.org/search.html
2663 or at Google. Also try browsing the nmap-dev archives at
2664 http://seclists.org/.. Read this full manual page as well. If nothing
2665 comes of this, mail a bug report to nmap-dev@insecure.org. Please
2666 include everything you have learned about the problem, as well as what
2667 version of Nmap you are running and what operating system version it is
2668 running on. Problem reports and Nmap usage questions sent to
2669 nmap-dev@insecure.org are far more likely to be answered than those
2670 sent to Fyodor directly. If you subscribe to the nmap-dev list before
2671 posting, your message will bypass moderation and get through more
2672 quickly. Subscribe at
2673 http://cgi.insecure.org/mailman/listinfo/nmap-dev.
2674
2675 Code patches to fix bugs are even better than bug reports. Basic
2676 instructions for creating patch files with your changes are available
2677 at http://nmap.org/data/HACKING. Patches may be sent to nmap-dev
2678 (recommended) or to Fyodor directly.
2679
2681 Gordon “Fyodor” Lyon fyodor@insecure.org (http://insecure.org)
2682
2683 Hundreds of people have made valuable contributions to Nmap over the
2684 years. These are detailed in the CHANGELOG. file which is distributed
2685 with Nmap and also available from http://nmap.org/changelog.html.
2686
2688 Nmap Copyright and Licensing
2689 The Nmap Security Scanner is (C) 1996–2009 Insecure.Com LLC. Nmap is
2690 also a registered trademark of Insecure.Com LLC. This program is free
2691 software; you may redistribute and/or modify it under the terms of the
2692 GNU General Public License as published by the Free Software
2693 Foundation; Version 2 with the clarifications and exceptions described
2694 below. This guarantees your right to use, modify, and redistribute this
2695 software under certain conditions. If you wish to embed Nmap technology
2696 into proprietary software, we sell alternative licenses (contact
2697 sales@insecure.com). Dozens of software vendors already license Nmap
2698 technology such as host discovery, port scanning, OS detection, and
2699 version detection.
2700
2701 Note that the GPL places important restrictions on “derived works”, yet
2702 it does not provide a detailed definition of that term. To avoid
2703 misunderstandings, we consider an application to constitute a
2704 “derivative work” for the purpose of this license if it does any of the
2705 following:
2706
2707 · Integrates source code from Nmap
2708
2709 · Reads or includes Nmap copyrighted data files, such as nmap-os-db
2710 or nmap-service-probes.
2711
2712 · Executes Nmap and parses the results (as opposed to typical shell
2713 or execution-menu apps, which simply display raw Nmap output and so
2714 are not derivative works.)
2715
2716 · Integrates/includes/aggregates Nmap into a proprietary executable
2717 installer, such as those produced by InstallShield.
2718
2719 · Links to a library or executes a program that does any of the
2720 above.
2721
2722 The term “Nmap” should be taken to also include any portions or derived
2723 works of Nmap. This list is not exclusive, but is meant to clarify our
2724 interpretation of derived works with some common examples. Our
2725 interpretation applies only to Nmap—we don´t speak for other people´s
2726 GPL works.
2727
2728 If you have any questions about the GPL licensing restrictions on using
2729 Nmap in non-GPL works, we would be happy to help. As mentioned above,
2730 we also offer alternative license to integrate Nmap into proprietary
2731 applications and appliances. These contracts have been sold to many
2732 security vendors, and generally include a perpetual license as well as
2733 providing for priority support and updates as well as helping to fund
2734 the continued development of Nmap technology. Please email
2735 sales@insecure.com for further information.
2736
2737 As a special exception to the GPL terms, Insecure.Com LLC grants
2738 permission to link the code of this program with any version of the
2739 OpenSSL library which is distributed under a license identical to that
2740 listed in the included COPYING.OpenSSL file, and distribute linked
2741 combinations including the two.. You must obey the GNU GPL in all
2742 respects for all of the code used other than OpenSSL. If you modify
2743 this file, you may extend this exception to your version of the file,
2744 but you are not obligated to do so.
2745
2746 If you received these files with a written license agreement or
2747 contract stating terms other than the terms above, then that
2748 alternative license agreement takes precedence over these comments.
2749
2750 Creative Commons License for this Nmap Guide
2751 This Nmap Reference Guide is (C) 2005–2009 Insecure.Com LLC. It is
2752 hereby placed under version 3.0 of the Creative Commons Attribution
2753 License[18]. This allows you redistribute and modify the work as you
2754 desire, as long as you credit the original source. Alternatively, you
2755 may choose to treat this document as falling under the same license as
2756 Nmap itself (discussed previously).
2757
2758 Source Code Availability and Community Contributions
2759 Source is provided to this software because we believe users have a
2760 right to know exactly what a program is going to do before they run it.
2761 This also allows you to audit the software for security holes (none
2762 have been found so far).
2763
2764 Source code also allows you to port Nmap to new platforms, fix bugs,
2765 and add new features. You are highly encouraged to send your changes to
2766 nmap-dev@insecure.org for possible incorporation into the main
2767 distribution. By sending these changes to Fyodor or one of the
2768 Insecure.Org development mailing lists, it is assumed that you are
2769 offering the Nmap Project (Insecure.Com LLC) the unlimited,
2770 non-exclusive right to reuse, modify, and relicense the code. Nmap will
2771 always be available Open Source,. but this is important because the
2772 inability to relicense code has caused devastating problems for other
2773 Free Software projects (such as KDE and NASM). We also occasionally
2774 relicense the code to third parties as discussed above. If you wish to
2775 specify special license conditions of your contributions, just say so
2776 when you send them.
2777
2778 No Warranty.
2779 This program is distributed in the hope that it will be useful, but
2780 WITHOUT ANY WARRANTY; without even the implied warranty of
2781 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2782 General Public License v2.0 for more details at
2783 http://www.gnu.org/licenses/gpl-2.0.html, or in the COPYING file
2784 included with Nmap.
2785
2786 It should also be noted that Nmap has occasionally been known to crash
2787 poorly written applications, TCP/IP stacks, and even operating
2788 systems.. While this is extremely rare, it is important to keep in
2789 mind. Nmap should never be run against mission critical systems unless
2790 you are prepared to suffer downtime. We acknowledge here that Nmap may
2791 crash your systems or networks and we disclaim all liability for any
2792 damage or problems Nmap could cause.
2793
2794 Inappropriate Usage
2795 Because of the slight risk of crashes and because a few black hats like
2796 to use Nmap for reconnaissance prior to attacking systems, there are
2797 administrators who become upset and may complain when their system is
2798 scanned. Thus, it is often advisable to request permission before doing
2799 even a light scan of a network.
2800
2801 Nmap should never be installed with special privileges (e.g. suid root)
2802 for security reasons..
2803
2804 Third-Party Software
2805 This product includes software developed by the Apache Software
2806 Foundation[19]. A modified version of the Libpcap portable packet
2807 capture library[20]. is distributed along with Nmap. The Windows
2808 version of Nmap utilized the Libpcap-derived WinPcap library[21].
2809 instead. Regular expression support is provided by the PCRE
2810 library[22],. which is open-source software, written by Philip Hazel..
2811 Certain raw networking functions use the Libdnet[23]. networking
2812 library, which was written by Dug Song.. A modified version is
2813 distributed with Nmap. Nmap can optionally link with the OpenSSL
2814 cryptography toolkit[24]. for SSL version detection support. The Nmap
2815 Scripting Engine uses an embedded version of the Lua programming
2816 language[25].. All of the third-party software described in this
2817 paragraph is freely redistributable under BSD-style software licenses.
2818
2819 United States Export Control.
2820 Nmap only uses encryption when compiled with the optional OpenSSL
2821 support and linked with OpenSSL. When compiled without OpenSSL support,
2822 Insecure.Com LLC believes that Nmap is not subject to U.S. Export
2823 Administration Regulations (EAR)[26] export control. As such, there is
2824 no applicable ECCN (explort control classification number) and
2825 exportation does not require any special license, permit, or other
2826 governmental authorization.
2827
2828 When compiled with OpenSSL support or distributed as source code,
2829 Insecure.Com LLC believes that Nmap falls under U.S. ECCN 5D002[27]
2830 (“Information Security Software”). We distribute Nmap under the TSU
2831 exception for publicly available encryption software defined in EAR
2832 740.13(e)[28].
2833
2835 1. Nmap Network Scanning: The Official Nmap Project Guide to Network
2836 Discovery and Security Scanning
2837 http://nmap.org/book/
2838
2839 2. RFC 1122
2840 http://www.rfc-editor.org/rfc/rfc1122.txt
2841
2842 3. RFC 792
2843 http://www.rfc-editor.org/rfc/rfc792.txt
2844
2845 4. RFC 950
2846 http://www.rfc-editor.org/rfc/rfc950.txt
2847
2848 5. RFC 1918
2849 http://www.rfc-editor.org/rfc/rfc1918.txt
2850
2851 6. UDP
2852 http://www.rfc-editor.org/rfc/rfc768.txt
2853
2854 7. SCTP
2855 http://www.rfc-editor.org/rfc/rfc4960.txt
2856
2857 8. TCP RFC
2858 http://www.rfc-editor.org/rfc/rfc793.txt
2859
2860 9. RFC 959
2861 http://www.rfc-editor.org/rfc/rfc959.txt
2862
2863 10. RFC 1323
2864 http://www.rfc-editor.org/rfc/rfc1323.txt
2865
2866 11. Lua programming language
2867 http://lua.org
2868
2869 12. precedence
2870 http://www.lua.org/manual/5.1/manual.html#2.5.3
2871
2872 13. IP protocol
2873 http://www.rfc-editor.org/rfc/rfc791.txt
2874
2875 14. RFC 2960
2876 http://www.rfc-editor.org/rfc/rfc2960.txt
2877
2878 15. Nmap::Scanner
2879 http://sourceforge.net/projects/nmap-scanner/
2880
2881 16. Nmap::Parser
2882 http://nmapparser.wordpress.com/
2883
2884 17. listed at Wikipedia
2885 http://en.wikipedia.org/wiki/List_of_IPv6_tunnel_brokers
2886
2887 18. Creative Commons Attribution License
2888 http://creativecommons.org/licenses/by/3.0/
2889
2890 19. Apache Software Foundation
2891 http://www.apache.org
2892
2893 20. Libpcap portable packet capture library
2894 http://www.tcpdump.org
2895
2896 21. WinPcap library
2897 http://www.winpcap.org
2898
2899 22. PCRE library
2900 http://www.pcre.org
2901
2902 23. Libdnet
2903 http://libdnet.sourceforge.net
2904
2905 24. OpenSSL cryptography toolkit
2906 http://www.openssl.org
2907
2908 25. Lua programming language
2909 http://www.lua.org
2910
2911 26. Export Administration Regulations (EAR)
2912 http://www.access.gpo.gov/bis/ear/ear_data.html
2913
2914 27. 5D002
2915 http://www.access.gpo.gov/bis/ear/pdf/ccl5-pt2.pdf
2916
2917 28. EAR 740.13(e)
2918 http://www.access.gpo.gov/bis/ear/pdf/740.pdf
2919
2920
2921
2922Nmap 01/26/2010 NMAP(1)