-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathnmap.1
2727 lines (2709 loc) · 170 KB
/
nmap.1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
'\" t
.\" Title: nmap
.\" Author: [see the "Authors" section]
.\" Generator: DocBook XSL Stylesheets v1.79.1 <http://docbook.sf.net/>
.\" Date: 10/05/2020
.\" Manual: Nmap Reference Guide
.\" Source: Nmap
.\" Language: English
.\"
.TH "NMAP" "1" "10/05/2020" "Nmap" "Nmap Reference Guide"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.\" http://bugs.debian.org/507673
.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.\" -----------------------------------------------------------------
.\" * set default formatting
.\" -----------------------------------------------------------------
.\" disable hyphenation
.nh
.\" disable justification (adjust text to left margin only)
.ad l
.\" -----------------------------------------------------------------
.\" * MAIN CONTENT STARTS HERE *
.\" -----------------------------------------------------------------
.SH "NAME"
nmap \- Network exploration tool and security / port scanner
.SH "SYNOPSIS"
.HP \w'\fBnmap\fR\ 'u
\fBnmap\fR [\fIScan\ Type\fR...] [\fIOptions\fR] {\fItarget\ specification\fR}
.SH "DESCRIPTION"
.PP
Nmap (\(lqNetwork Mapper\(rq) is an open source tool for network exploration and security auditing\&. It was designed to rapidly scan large networks, although it works fine against single hosts\&. Nmap uses raw IP packets in novel ways to determine what hosts are available on the network, what services (application name and version) those hosts are offering, what operating systems (and OS versions) they are running, what type of packet filters/firewalls are in use, and dozens of other characteristics\&. While Nmap is commonly used for security audits, many systems and network administrators find it useful for routine tasks such as network inventory, managing service upgrade schedules, and monitoring host or service uptime\&.
.PP
The output from Nmap is a list of scanned targets, with supplemental information on each depending on the options used\&. Key among that information is the
\(lqinteresting ports table\(rq\&.
That table lists the port number and protocol, service name, and state\&. The state is either
open,
filtered,
closed, or
unfiltered\&.
Open
means that an application on the target machine is listening for connections/packets on that port\&.
Filtered
means that a firewall, filter, or other network obstacle is blocking the port so that Nmap cannot tell whether it is
open
or
closed\&.
Closed
ports have no application listening on them, though they could open up at any time\&. Ports are classified as
unfiltered
when they are responsive to Nmap\*(Aqs probes, but Nmap cannot determine whether they are open or closed\&. Nmap reports the state combinations
open|filtered
and
closed|filtered
when it cannot determine which of the two states describe a port\&. The port table may also include software version details when version detection has been requested\&. When an IP protocol scan is requested (\fB\-sO\fR), Nmap provides information on supported IP protocols rather than listening ports\&.
.PP
In addition to the interesting ports table, Nmap can provide further information on targets, including reverse DNS names, operating system guesses, device types, and MAC addresses\&.
.PP
A typical Nmap scan is shown in
Example\ \&1\&. The only Nmap arguments used in this example are
\fB\-A\fR, to enable OS and version detection, script scanning, and traceroute;
\fB\-T4\fR
for faster execution; and then the hostname\&.
.PP
\fBExample\ \&1.\ \&A representative Nmap scan\fR
.sp
.if n \{\
.RS 4
.\}
.nf
# \fBnmap \-A \-T4 scanme\&.nmap\&.org\fR
Nmap scan report for scanme\&.nmap\&.org (74\&.207\&.244\&.221)
Host is up (0\&.029s latency)\&.
rDNS record for 74\&.207\&.244\&.221: li86\-221\&.members\&.linode\&.com
Not shown: 995 closed ports
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 5\&.3p1 Debian 3ubuntu7 (protocol 2\&.0)
| ssh\-hostkey: 1024 8d:60:f1:7c:ca:b7:3d:0a:d6:67:54:9d:69:d9:b9:dd (DSA)
|_2048 79:f8:09:ac:d4:e2:32:42:10:49:d3:bd:20:82:85:ec (RSA)
80/tcp open http Apache httpd 2\&.2\&.14 ((Ubuntu))
|_http\-title: Go ahead and ScanMe!
646/tcp filtered ldp
1720/tcp filtered H\&.323/Q\&.931
9929/tcp open nping\-echo Nping echo
Device type: general purpose
Running: Linux 2\&.6\&.X
OS CPE: cpe:/o:linux:linux_kernel:2\&.6\&.39
OS details: Linux 2\&.6\&.39
Network Distance: 11 hops
Service Info: OS: Linux; CPE: cpe:/o:linux:kernel
TRACEROUTE (using port 53/tcp)
HOP RTT ADDRESS
[Cut first 10 hops for brevity]
11 17\&.65 ms li86\-221\&.members\&.linode\&.com (74\&.207\&.244\&.221)
Nmap done: 1 IP address (1 host up) scanned in 14\&.40 seconds
.fi
.if n \{\
.RE
.\}
.PP
The newest version of Nmap can be obtained from
\m[blue]\fB\%https://nmap.org\fR\m[]\&. The newest version of this man page is available at
\m[blue]\fB\%https://nmap.org/book/man.html\fR\m[]\&.
It is also included as a chapter of Nmap Network Scanning: The Official Nmap Project Guide to Network Discovery and Security Scanning (see \m[blue]\fB\%https://nmap.org/book/\fR\m[])\&.
.SH "OPTIONS SUMMARY"
.PP
This options summary is printed when Nmap is run with no arguments, and the latest version is always available at
\m[blue]\fB\%https://svn.nmap.org/nmap/docs/nmap.usage.txt\fR\m[]\&. It helps people remember the most common options, but is no substitute for the in\-depth documentation in the rest of this manual\&. Some obscure options aren\*(Aqt even included here\&.
.sp
.if n \{\
.RS 4
.\}
.nf
Nmap 7\&.90SVN ( https://nmap\&.org )
Usage: nmap [Scan Type(s)] [Options] {target specification}
TARGET SPECIFICATION:
Can pass hostnames, IP addresses, networks, etc\&.
Ex: scanme\&.nmap\&.org, microsoft\&.com/24, 192\&.168\&.0\&.1; 10\&.0\&.0\-255\&.1\-254
\-iL <inputfilename>: Input from list of hosts/networks
\-iR <num hosts>: Choose random targets
\-\-exclude <host1[,host2][,host3],\&.\&.\&.>: Exclude hosts/networks
\-\-excludefile <exclude_file>: Exclude list from file
HOST DISCOVERY:
\-sL: List Scan \- simply list targets to scan
\-sn: Ping Scan \- disable port scan
\-Pn: Treat all hosts as online \-\- skip host discovery
\-PS/PA/PU/PY[portlist]: TCP SYN/ACK, UDP or SCTP discovery to given ports
\-PE/PP/PM: ICMP echo, timestamp, and netmask request discovery probes
\-PO[protocol list]: IP Protocol Ping
\-n/\-R: Never do DNS resolution/Always resolve [default: sometimes]
\-\-dns\-servers <serv1[,serv2],\&.\&.\&.>: Specify custom DNS servers
\-\-system\-dns: Use OS\*(Aqs DNS resolver
\-\-traceroute: Trace hop path to each host
SCAN TECHNIQUES:
\-sS/sT/sA/sW/sM: TCP SYN/Connect()/ACK/Window/Maimon scans
\-sU: UDP Scan
\-sN/sF/sX: TCP Null, FIN, and Xmas scans
\-\-scanflags <flags>: Customize TCP scan flags
\-sI <zombie host[:probeport]>: Idle scan
\-sY/sZ: SCTP INIT/COOKIE\-ECHO scans
\-sO: IP protocol scan
\-b <FTP relay host>: FTP bounce scan
PORT SPECIFICATION AND SCAN ORDER:
\-p <port ranges>: Only scan specified ports
Ex: \-p22; \-p1\-65535; \-p U:53,111,137,T:21\-25,80,139,8080,S:9
\-\-exclude\-ports <port ranges>: Exclude the specified ports from scanning
\-F: Fast mode \- Scan fewer ports than the default scan
\-r: Scan ports consecutively \- don\*(Aqt randomize
\-\-top\-ports <number>: Scan <number> most common ports
\-\-port\-ratio <ratio>: Scan ports more common than <ratio>
SERVICE/VERSION DETECTION:
\-sV: Probe open ports to determine service/version info
\-\-version\-intensity <level>: Set from 0 (light) to 9 (try all probes)
\-\-version\-light: Limit to most likely probes (intensity 2)
\-\-version\-all: Try every single probe (intensity 9)
\-\-version\-trace: Show detailed version scan activity (for debugging)
SCRIPT SCAN:
\-sC: equivalent to \-\-script=default
\-\-script=<Lua scripts>: <Lua scripts> is a comma separated list of
directories, script\-files or script\-categories
\-\-script\-args=<n1=v1,[n2=v2,\&.\&.\&.]>: provide arguments to scripts
\-\-script\-args\-file=filename: provide NSE script args in a file
\-\-script\-trace: Show all data sent and received
\-\-script\-updatedb: Update the script database\&.
\-\-script\-help=<Lua scripts>: Show help about scripts\&.
<Lua scripts> is a comma\-separated list of script\-files or
script\-categories\&.
OS DETECTION:
\-O: Enable OS detection
\-\-osscan\-limit: Limit OS detection to promising targets
\-\-osscan\-guess: Guess OS more aggressively
TIMING AND PERFORMANCE:
Options which take <time> are in seconds, or append \*(Aqms\*(Aq (milliseconds),
\*(Aqs\*(Aq (seconds), \*(Aqm\*(Aq (minutes), or \*(Aqh\*(Aq (hours) to the value (e\&.g\&. 30m)\&.
\-T<0\-5>: Set timing template (higher is faster)
\-\-min\-hostgroup/max\-hostgroup <size>: Parallel host scan group sizes
\-\-min\-parallelism/max\-parallelism <numprobes>: Probe parallelization
\-\-min\-rtt\-timeout/max\-rtt\-timeout/initial\-rtt\-timeout <time>: Specifies
probe round trip time\&.
\-\-max\-retries <tries>: Caps number of port scan probe retransmissions\&.
\-\-host\-timeout <time>: Give up on target after this long
\-\-scan\-delay/\-\-max\-scan\-delay <time>: Adjust delay between probes
\-\-min\-rate <number>: Send packets no slower than <number> per second
\-\-max\-rate <number>: Send packets no faster than <number> per second
FIREWALL/IDS EVASION AND SPOOFING:
\-f; \-\-mtu <val>: fragment packets (optionally w/given MTU)
\-D <decoy1,decoy2[,ME],\&.\&.\&.>: Cloak a scan with decoys
\-S <IP_Address>: Spoof source address
\-e <iface>: Use specified interface
\-g/\-\-source\-port <portnum>: Use given port number
\-\-proxies <url1,[url2],\&.\&.\&.>: Relay connections through HTTP/SOCKS4 proxies
\-\-data <hex string>: Append a custom payload to sent packets
\-\-data\-string <string>: Append a custom ASCII string to sent packets
\-\-data\-length <num>: Append random data to sent packets
\-\-ip\-options <options>: Send packets with specified ip options
\-\-ttl <val>: Set IP time\-to\-live field
\-\-spoof\-mac <mac address/prefix/vendor name>: Spoof your MAC address
\-\-badsum: Send packets with a bogus TCP/UDP/SCTP checksum
OUTPUT:
\-oN/\-oX/\-oS/\-oG <file>: Output scan in normal, XML, s|<rIpt kIddi3,
and Grepable format, respectively, to the given filename\&.
\-oA <basename>: Output in the three major formats at once
\-v: Increase verbosity level (use \-vv or more for greater effect)
\-d: Increase debugging level (use \-dd or more for greater effect)
\-\-reason: Display the reason a port is in a particular state
\-\-open: Only show open (or possibly open) ports
\-\-packet\-trace: Show all packets sent and received
\-\-iflist: Print host interfaces and routes (for debugging)
\-\-append\-output: Append to rather than clobber specified output files
\-\-resume <filename>: Resume an aborted scan
\-\-stylesheet <path/URL>: XSL stylesheet to transform XML output to HTML
\-\-webxml: Reference stylesheet from Nmap\&.Org for more portable XML
\-\-no\-stylesheet: Prevent associating of XSL stylesheet w/XML output
MISC:
\-6: Enable IPv6 scanning
\-A: Enable OS detection, version detection, script scanning, and traceroute
\-\-datadir <dirname>: Specify custom Nmap data file location
\-\-send\-eth/\-\-send\-ip: Send using raw ethernet frames or IP packets
\-\-privileged: Assume that the user is fully privileged
\-\-unprivileged: Assume the user lacks raw socket privileges
\-V: Print version number
\-h: Print this help summary page\&.
EXAMPLES:
nmap \-v \-A scanme\&.nmap\&.org
nmap \-v \-sn 192\&.168\&.0\&.0/16 10\&.0\&.0\&.0/8
nmap \-v \-iR 10000 \-Pn \-p 80
SEE THE MAN PAGE (https://nmap\&.org/book/man\&.html) FOR MORE OPTIONS AND EXAMPLES
.fi
.if n \{\
.RE
.\}
.SH "TARGET SPECIFICATION"
.PP
Everything on the Nmap command\-line that isn\*(Aqt an option (or option argument) is treated as a target host specification\&. The simplest case is to specify a target IP address or hostname for scanning\&.
.PP
When a hostname is given as a target, it is
resolved
via the Domain Name System (DNS) to determine the IP address to scan\&. If the name resolves to more than one IP address, only the first one will be scanned\&. To make Nmap scan all the resolved addresses instead of only the first one, use the
\fB\-\-resolve\-all\fR
option\&.
.PP
Sometimes you wish to scan a whole network of adjacent hosts\&. For this, Nmap supports CIDR\-style
addressing\&. You can append
/\fInumbits\fR
to an IP address or hostname and Nmap will scan every IP address for which the first
\fInumbits\fR
are the same as for the reference IP or hostname given\&. For example,
192\&.168\&.10\&.0/24
would scan the 256 hosts between 192\&.168\&.10\&.0 (binary:
11000000 10101000 00001010 00000000) and 192\&.168\&.10\&.255 (binary:
11000000 10101000 00001010 11111111), inclusive\&.
192\&.168\&.10\&.40/24
would scan exactly the same targets\&. Given that the host scanme\&.nmap\&.org
is at the IP address 64\&.13\&.134\&.52, the specification
scanme\&.nmap\&.org/16
would scan the 65,536 IP addresses between 64\&.13\&.0\&.0 and 64\&.13\&.255\&.255\&. The smallest allowed value is
/0, which targets the whole Internet\&. The largest value for IPv4 is
/32, which scans just the named host or IP address because all address bits are fixed\&. The largest value for IPv6 is
/128, which does the same thing\&.
.PP
CIDR notation is short but not always flexible enough\&. For example, you might want to scan 192\&.168\&.0\&.0/16 but skip any IPs ending with \&.0 or \&.255 because they may be used as subnet network and broadcast addresses\&. Nmap supports this through octet range addressing\&. Rather than specify a normal IP address, you can specify a comma\-separated list of numbers or ranges for each octet\&. For example,
192\&.168\&.0\-255\&.1\-254
will skip all addresses in the range that end in \&.0 or \&.255, and
192\&.168\&.3\-5,7\&.1
will scan the four addresses 192\&.168\&.3\&.1, 192\&.168\&.4\&.1, 192\&.168\&.5\&.1, and 192\&.168\&.7\&.1\&. Either side of a range may be omitted; the default values are 0 on the left and 255 on the right\&. Using
\-
by itself is the same as
0\-255, but remember to use
0\-
in the first octet so the target specification doesn\*(Aqt look like a command\-line option\&. Ranges need not be limited to the final octets: the specifier
0\-255\&.0\-255\&.13\&.37
will perform an Internet\-wide scan for all IP addresses ending in 13\&.37\&. This sort of broad sampling can be useful for Internet surveys and research\&.
.PP
IPv6 addresses can be specified by their fully qualified IPv6 address or hostname or with CIDR notation for subnets\&. Octet ranges aren\*(Aqt yet supported for IPv6\&.
.PP
IPv6 addresses with non\-global scope need to have a zone ID suffix\&. On Unix systems, this is a percent sign followed by an interface name; a complete address might be
fe80::a8bb:ccff:fedd:eeff%eth0\&. On Windows, use an interface index number in place of an interface name:
fe80::a8bb:ccff:fedd:eeff%1\&. You can see a list of interface indexes by running the command
\fBnetsh\&.exe interface ipv6 show interface\fR\&.
.PP
Nmap accepts multiple host specifications on the command line, and they don\*(Aqt need to be the same type\&. The command
\fBnmap scanme\&.nmap\&.org 192\&.168\&.0\&.0/8 10\&.0\&.0,1,3\-7\&.\-\fR
does what you would expect\&.
.PP
While targets are usually specified on the command lines, the following options are also available to control target selection:
.PP
\fB\-iL \fR\fB\fIinputfilename\fR\fR (Input from list)
.RS 4
Reads target specifications from
\fIinputfilename\fR\&. Passing a huge list of hosts is often awkward on the command line, yet it is a common desire\&. For example, your DHCP server might export a list of 10,000 current leases that you wish to scan\&. Or maybe you want to scan all IP addresses
\fIexcept\fR
for those to locate hosts using unauthorized static IP addresses\&. Simply generate the list of hosts to scan and pass that filename to Nmap as an argument to the
\fB\-iL\fR
option\&. Entries can be in any of the formats accepted by Nmap on the command line (IP address, hostname, CIDR, IPv6, or octet ranges)\&. Each entry must be separated by one or more spaces, tabs, or newlines\&. You can specify a hyphen (\-) as the filename if you want Nmap to read hosts from standard input rather than an actual file\&.
.sp
The input file may contain comments that start with
#
and extend to the end of the line\&.
.RE
.PP
\fB\-iR \fR\fB\fInum hosts\fR\fR (Choose random targets)
.RS 4
For Internet\-wide surveys and other research, you may want to choose targets at random\&. The
\fInum hosts\fR
argument tells Nmap how many IPs to generate\&. Undesirable IPs such as those in certain private, multicast, or unallocated address ranges are automatically skipped\&. The argument
0
can be specified for a never\-ending scan\&. Keep in mind that some network administrators bristle at unauthorized scans of their networks and may complain\&. Use this option at your own risk! If you find yourself really bored one rainy afternoon, try the command
\fBnmap \-Pn \-sS \-p 80 \-iR 0 \-\-open\fR
to locate random web servers for browsing\&.
.RE
.PP
\fB\-\-exclude \fR\fB\fIhost1\fR\fR\fB[,\fIhost2\fR[,\&.\&.\&.]]\fR (Exclude hosts/networks)
.RS 4
Specifies a comma\-separated list of targets to be excluded from the scan even if they are part of the overall network range you specify\&. The list you pass in uses normal Nmap syntax, so it can include hostnames, CIDR netblocks, octet ranges, etc\&. This can be useful when the network you wish to scan includes untouchable mission\-critical servers, systems that are known to react adversely to port scans, or subnets administered by other people\&.
.RE
.PP
\fB\-\-excludefile \fR\fB\fIexclude_file\fR\fR (Exclude list from file)
.RS 4
This offers the same functionality as the
\fB\-\-exclude\fR
option, except that the excluded targets are provided in a newline\-, space\-, or tab\-delimited
\fIexclude_file\fR
rather than on the command line\&.
.sp
The exclude file may contain comments that start with
#
and extend to the end of the line\&.
.RE
.SH "HOST DISCOVERY"
.PP
One of the very first steps in any network reconnaissance mission is to reduce a (sometimes huge) set of IP ranges into a list of active or interesting hosts\&. Scanning every port of every single IP address is slow and usually unnecessary\&. Of course what makes a host interesting depends greatly on the scan purposes\&. Network administrators may only be interested in hosts running a certain service, while security auditors may care about every single device with an IP address\&. An administrator may be comfortable using just an ICMP ping to locate hosts on his internal network, while an external penetration tester may use a diverse set of dozens of probes in an attempt to evade firewall restrictions\&.
.PP
Because host discovery needs are so diverse, Nmap offers a wide variety of options for customizing the techniques used\&. Host discovery is sometimes called ping scan, but it goes well beyond the simple ICMP echo request packets associated with the ubiquitous
ping
tool\&. Users can skip the discovery step entirely with a list scan (\fB\-sL\fR) or by disabling host discovery (\fB\-Pn\fR), or engage the network with arbitrary combinations of multi\-port TCP SYN/ACK, UDP, SCTP INIT and ICMP probes\&. The goal of these probes is to solicit responses which demonstrate that an IP address is actually active (is being used by a host or network device)\&. On many networks, only a small percentage of IP addresses are active at any given time\&. This is particularly common with private address space such as 10\&.0\&.0\&.0/8\&. That network has 16 million IPs, but I have seen it used by companies with less than a thousand machines\&. Host discovery can find those machines in a sparsely allocated sea of IP addresses\&.
.PP
If no host discovery options are given, Nmap sends an ICMP echo request, a TCP SYN packet to port 443, a TCP ACK packet to port 80, and an ICMP timestamp request\&. (For IPv6, the ICMP timestamp request is omitted because it is not part of ICMPv6\&.) These defaults are equivalent to the
\fB\-PE \-PS443 \-PA80 \-PP\fR
options\&. The exceptions to this are the ARP
(for IPv4) and Neighbor Discovery
(for IPv6) scans which are used for any targets on a local ethernet network\&. For unprivileged Unix shell users, the default probes are a SYN packet to ports 80 and 443 using the
\fBconnect\fR
system call\&.
This host discovery is often sufficient when scanning local networks, but a more comprehensive set of discovery probes is recommended for security auditing\&.
.PP
The
\fB\-P*\fR
options (which select ping types) can be combined\&. You can increase your odds of penetrating strict firewalls by sending many probe types using different TCP ports/flags and ICMP codes\&. Also note that ARP/Neighbor Discovery
is done by default against targets on a local Ethernet network even if you specify other
\fB\-P*\fR
options, because it is almost always faster and more effective\&.
.PP
By default, Nmap does host discovery and then performs a port scan against each host it determines is online\&. This is true even if you specify non\-default host discovery types such as UDP probes (\fB\-PU\fR)\&. Read about the
\fB\-sn\fR
option to learn how to perform only host discovery, or use
\fB\-Pn\fR
to skip host discovery and port scan all target addresses\&. The following options control host discovery:
.PP
\fB\-sL\fR (List Scan)
.RS 4
The list scan is a degenerate form of host discovery that simply lists each host of the network(s) specified, without sending any packets to the target hosts\&. By default, Nmap still does reverse\-DNS resolution on the hosts to learn their names\&. It is often surprising how much useful information simple hostnames give out\&. For example,
fw\&.chi
is the name of one company\*(Aqs Chicago firewall\&.
Nmap also reports the total number of IP addresses at the end\&. The list scan is a good sanity check to ensure that you have proper IP addresses for your targets\&. If the hosts sport domain names you do not recognize, it is worth investigating further to prevent scanning the wrong company\*(Aqs network\&.
.sp
Since the idea is to simply print a list of target hosts, options for higher level functionality such as port scanning, OS detection, or host discovery cannot be combined with this\&. If you wish to disable host discovery while still performing such higher level functionality, read up on the
\fB\-Pn\fR
(skip host discovery) option\&.
.RE
.PP
\fB\-sn\fR (No port scan)
.RS 4
This option tells Nmap not to do a port scan after host discovery, and only print out the available hosts that responded to the host discovery probes\&. This is often known as a
\(lqping scan\(rq, but you can also request that traceroute and NSE host scripts be run\&. This is by default one step more intrusive than the list scan, and can often be used for the same purposes\&. It allows light reconnaissance of a target network without attracting much attention\&. Knowing how many hosts are up is more valuable to attackers than the list provided by list scan of every single IP and host name\&.
.sp
Systems administrators often find this option valuable as well\&. It can easily be used to count available machines on a network or monitor server availability\&. This is often called a ping sweep, and is more reliable than pinging the broadcast address because many hosts do not reply to broadcast queries\&.
.sp
The default host discovery done with
\fB\-sn\fR
consists of an ICMP echo request, TCP SYN to port 443, TCP ACK to port 80, and an ICMP timestamp request by default\&. When executed by an unprivileged user, only SYN packets are sent (using a
\fBconnect\fR
call) to ports 80 and 443 on the target\&. When a privileged user tries to scan targets on a local ethernet network, ARP requests are used unless
\fB\-\-send\-ip\fR
was specified\&. The
\fB\-sn\fR
option can be combined with any of the discovery probe types (the
\fB\-P*\fR
options) for greater flexibility\&. If any of those probe type and port number options are used, the default probes are overridden\&. When strict firewalls are in place between the source host running Nmap and the target network, using those advanced techniques is recommended\&. Otherwise hosts could be missed when the firewall drops probes or their responses\&.
.sp
In previous releases of Nmap,
\fB\-sn\fR
was known as
\fB\-sP\fR\&.
.RE
.PP
\fB\-Pn\fR (No ping)
.RS 4
This option skips the host discovery stage altogether\&. Normally, Nmap uses this stage to determine active machines for heavier scanning and to gauge the speed of the network\&. By default, Nmap only performs heavy probing such as port scans, version detection, or OS detection against hosts that are found to be up\&. Disabling host discovery with
\fB\-Pn\fR
causes Nmap to attempt the requested scanning functions against
\fIevery\fR
target IP address specified\&. So if a /16 sized network is specified on the command line, all 65,536 IP addresses are scanned\&. Proper host discovery is skipped as with the list scan, but instead of stopping and printing the target list, Nmap continues to perform requested functions as if each target IP is active\&. Default timing parameters are used, which may result in slower scans\&. To skip host discovery
\fIand\fR
port scan, while still allowing NSE to run, use the two options
\fB\-Pn \-sn\fR
together\&.
.sp
For machines on a local ethernet network, ARP scanning will still be performed (unless
\fB\-\-disable\-arp\-ping\fR
or
\fB\-\-send\-ip\fR
is specified) because Nmap needs MAC addresses to further scan target hosts\&. In previous versions of Nmap,
\fB\-Pn\fR
was
\fB\-P0\fR
and
\fB\-PN\fR\&.
.RE
.PP
\fB\-PS \fR\fB\fIport list\fR\fR (TCP SYN Ping)
.RS 4
This option sends an empty TCP packet with the SYN flag set\&. The default destination port is 80 (configurable at compile time by changing
\fIDEFAULT_TCP_PROBE_PORT_SPEC\fR
in
nmap\&.h)\&.
Alternate ports can be specified as a parameter\&. The syntax is the same as for the
\fB\-p\fR
except that port type specifiers like
T:
are not allowed\&. Examples are
\fB\-PS22\fR
and
\fB\-PS22\-25,80,113,1050,35000\fR\&. Note that there can be no space between
\fB\-PS\fR
and the port list\&. If multiple probes are specified they will be sent in parallel\&.
.sp
The SYN flag suggests to the remote system that you are attempting to establish a connection\&. Normally the destination port will be closed, and a RST (reset) packet sent back\&. If the port happens to be open, the target will take the second step of a TCP three\-way\-handshake
by responding with a SYN/ACK TCP packet\&. The machine running Nmap then tears down the nascent connection by responding with a RST rather than sending an ACK packet which would complete the three\-way\-handshake and establish a full connection\&. The RST packet is sent by the kernel of the machine running Nmap in response to the unexpected SYN/ACK, not by Nmap itself\&.
.sp
Nmap does not care whether the port is open or closed\&. Either the RST or SYN/ACK response discussed previously tell Nmap that the host is available and responsive\&.
.sp
On Unix boxes, only the privileged user
root
is generally able to send and receive raw TCP packets\&.
For unprivileged users, a workaround is automatically employed
whereby the
\fBconnect\fR
system call is initiated against each target port\&. This has the effect of sending a SYN packet to the target host, in an attempt to establish a connection\&. If
\fBconnect\fR
returns with a quick success or an ECONNREFUSED failure, the underlying TCP stack must have received a SYN/ACK or RST and the host is marked available\&. If the connection attempt is left hanging until a timeout is reached, the host is marked as down\&.
.RE
.PP
\fB\-PA \fR\fB\fIport list\fR\fR (TCP ACK Ping)
.RS 4
The TCP ACK ping is quite similar to the just\-discussed SYN ping\&. The difference, as you could likely guess, is that the TCP ACK flag is set instead of the SYN flag\&. Such an ACK packet purports to be acknowledging data over an established TCP connection, but no such connection exists\&. So remote hosts should always respond with a RST packet, disclosing their existence in the process\&.
.sp
The
\fB\-PA\fR
option uses the same default port as the SYN probe (80) and can also take a list of destination ports in the same format\&. If an unprivileged user tries this, the
\fBconnect\fR
workaround discussed previously is used\&. This workaround is imperfect because
\fBconnect\fR
is actually sending a SYN packet rather than an ACK\&.
.sp
The reason for offering both SYN and ACK ping probes is to maximize the chances of bypassing firewalls\&. Many administrators configure routers and other simple firewalls to block incoming SYN packets except for those destined for public services like the company web site or mail server\&. This prevents other incoming connections to the organization, while allowing users to make unobstructed outgoing connections to the Internet\&. This non\-stateful approach takes up few resources on the firewall/router and is widely supported by hardware and software filters\&. The Linux Netfilter/iptables
firewall software offers the
\fB\-\-syn\fR
convenience option to implement this stateless approach\&. When stateless firewall rules such as this are in place, SYN ping probes (\fB\-PS\fR) are likely to be blocked when sent to closed target ports\&. In such cases, the ACK probe shines as it cuts right through these rules\&.
.sp
Another common type of firewall uses stateful rules that drop unexpected packets\&. This feature was initially found mostly on high\-end firewalls, though it has become much more common over the years\&. The Linux Netfilter/iptables system supports this through the
\fB\-\-state\fR
option, which categorizes packets based on connection state\&. A SYN probe is more likely to work against such a system, as unexpected ACK packets are generally recognized as bogus and dropped\&. A solution to this quandary is to send both SYN and ACK probes by specifying
\fB\-PS\fR
and
\fB\-PA\fR\&.
.RE
.PP
\fB\-PU \fR\fB\fIport list\fR\fR (UDP Ping)
.RS 4
Another host discovery option is the UDP ping, which sends a UDP packet to the given ports\&. For most ports, the packet will be empty, though some use a protocol\-specific payload that is more likely to elicit a response\&.
The payload database is described at \m[blue]\fB\%https://nmap.org/book/nmap-payloads.html\fR\m[]\&.
Packet content can also be affected with the
\fB\-\-data\fR,
\fB\-\-data\-string\fR, and
\fB\-\-data\-length\fR
options\&.
.sp
The port list takes the same format as with the previously discussed
\fB\-PS\fR
and
\fB\-PA\fR
options\&. If no ports are specified, the default is 40125\&.
This default can be configured at compile\-time by changing
\fIDEFAULT_UDP_PROBE_PORT_SPEC\fR
in
nmap\&.h\&.
A highly uncommon port is used by default because sending to open ports is often undesirable for this particular scan type\&.
.sp
Upon hitting a closed port on the target machine, the UDP probe should elicit an ICMP port unreachable packet in return\&. This signifies to Nmap that the machine is up and available\&. Many other types of ICMP errors, such as host/network unreachables or TTL exceeded are indicative of a down or unreachable host\&. A lack of response is also interpreted this way\&. If an open port is reached, most services simply ignore the empty packet and fail to return any response\&. This is why the default probe port is 40125, which is highly unlikely to be in use\&. A few services, such as the Character Generator (chargen) protocol, will respond to an empty UDP packet, and thus disclose to Nmap that the machine is available\&.
.sp
The primary advantage of this scan type is that it bypasses firewalls and filters that only screen TCP\&. For example, I once owned a Linksys BEFW11S4 wireless broadband router\&. The external interface of this device filtered all TCP ports by default, but UDP probes would still elicit port unreachable messages and thus give away the device\&.
.RE
.PP
\fB\-PY \fR\fB\fIport list\fR\fR (SCTP INIT Ping)
.RS 4
This option sends an SCTP packet containing a minimal INIT chunk\&. The default destination port is 80 (configurable at compile time by changing
\fIDEFAULT_SCTP_PROBE_PORT_SPEC\fR
in
nmap\&.h)\&. Alternate ports can be specified as a parameter\&. The syntax is the same as for the
\fB\-p\fR
except that port type specifiers like
S:
are not allowed\&. Examples are
\fB\-PY22\fR
and
\fB\-PY22,80,179,5060\fR\&. Note that there can be no space between
\fB\-PY\fR
and the port list\&. If multiple probes are specified they will be sent in parallel\&.
.sp
The INIT chunk suggests to the remote system that you are attempting to establish an association\&. Normally the destination port will be closed, and an ABORT chunk will be sent back\&. If the port happens to be open, the target will take the second step of an SCTP four\-way\-handshake
by responding with an INIT\-ACK chunk\&. If the machine running Nmap has a functional SCTP stack, then it tears down the nascent association by responding with an ABORT chunk rather than sending a COOKIE\-ECHO chunk which would be the next step in the four\-way\-handshake\&. The ABORT packet is sent by the kernel of the machine running Nmap in response to the unexpected INIT\-ACK, not by Nmap itself\&.
.sp
Nmap does not care whether the port is open or closed\&. Either the ABORT or INIT\-ACK response discussed previously tell Nmap that the host is available and responsive\&.
.sp
On Unix boxes, only the privileged user
root
is generally able to send and receive raw SCTP packets\&.
Using SCTP INIT Pings is currently not possible for unprivileged users\&.
.RE
.PP
\fB\-PE\fR; \fB\-PP\fR; \fB\-PM\fR (ICMP Ping Types)
.RS 4
In addition to the unusual TCP, UDP and SCTP host discovery types discussed previously, Nmap can send the standard packets sent by the ubiquitous
ping
program\&. Nmap sends an ICMP type 8 (echo request) packet to the target IP addresses, expecting a type 0 (echo reply) in return from available hosts\&.
Unfortunately for network explorers, many hosts and firewalls now block these packets, rather than responding as required by
\m[blue]\fBRFC 1122\fR\m[]\&\s-2\u[2]\d\s+2\&.
For this reason, ICMP\-only scans are rarely reliable enough against unknown targets over the Internet\&. But for system administrators monitoring an internal network, they can be a practical and efficient approach\&. Use the
\fB\-PE\fR
option to enable this echo request behavior\&.
.sp
While echo request is the standard ICMP ping query, Nmap does not stop there\&. The ICMP standards (\m[blue]\fBRFC 792\fR\m[]\&\s-2\u[3]\d\s+2
and
\m[blue]\fBRFC 950\fR\m[]\&\s-2\u[4]\d\s+2
) also specify timestamp request, information request, and address mask request packets as codes 13, 15, and 17, respectively\&. While the ostensible purpose for these queries is to learn information such as address masks and current times, they can easily be used for host discovery\&. A system that replies is up and available\&. Nmap does not currently implement information request packets, as they are not widely supported\&. RFC 1122 insists that
\(lqa host SHOULD NOT implement these messages\(rq\&. Timestamp and address mask queries can be sent with the
\fB\-PP\fR
and
\fB\-PM\fR
options, respectively\&. A timestamp reply (ICMP code 14) or address mask reply (code 18) discloses that the host is available\&. These two queries can be valuable when administrators specifically block echo request packets while forgetting that other ICMP queries can be used for the same purpose\&.
.RE
.PP
\fB\-PO \fR\fB\fIprotocol list\fR\fR (IP Protocol Ping)
.RS 4
One of the newer host discovery options is the IP protocol ping, which sends IP packets with the specified protocol number set in their IP header\&. The protocol list takes the same format as do port lists in the previously discussed TCP, UDP and SCTP host discovery options\&. If no protocols are specified, the default is to send multiple IP packets for ICMP (protocol 1), IGMP (protocol 2), and IP\-in\-IP (protocol 4)\&. The default protocols can be configured at compile\-time by changing
\fIDEFAULT_PROTO_PROBE_PORT_SPEC\fR
in
nmap\&.h\&. Note that for the ICMP, IGMP, TCP (protocol 6), UDP (protocol 17) and SCTP (protocol 132), the packets are sent with the proper protocol headers
while other protocols are sent with no additional data beyond the IP header (unless any of
\fB\-\-data\fR,
\fB\-\-data\-string\fR, or
\fB\-\-data\-length\fR
options are specified)\&.
.sp
This host discovery method looks for either responses using the same protocol as a probe, or ICMP protocol unreachable messages which signify that the given protocol isn\*(Aqt supported on the destination host\&. Either type of response signifies that the target host is alive\&.
.RE
.PP
\fB\-\-disable\-arp\-ping\fR (No ARP or ND Ping)
.RS 4
Nmap normally does ARP or IPv6 Neighbor Discovery (ND) discovery of locally connected ethernet hosts, even if other host discovery options such as
\fB\-Pn\fR
or
\fB\-PE\fR
are used\&. To disable this implicit behavior, use the
\fB\-\-disable\-arp\-ping\fR
option\&.
.sp
The default behavior is normally faster, but this option is useful on networks using proxy ARP, in which a router speculatively replies to all ARP requests, making every target appear to be up according to ARP scan\&.
.RE
.PP
\fB\-\-discovery\-ignore\-rst\fR
.RS 4
In some cases, firewalls may spoof TCP reset (RST) replies in response to probes to unoccupied or disallowed addresses\&. Since Nmap ordinarily considers RST replies to be proof that the target is up, this can lead to wasted time scanning targets that aren\*(Aqt there\&. Using the
\fB\-\-discovery\-ignore\-rst\fR
will prevent Nmap from considering these replies during host discovery\&. You may need to select extra host discovery options to ensure you don\*(Aqt miss targets in this case\&.
.RE
.PP
\fB\-\-traceroute\fR (Trace path to host)
.RS 4
Traceroutes are performed post\-scan using information from the scan results to determine the port and protocol most likely to reach the target\&. It works with all scan types except connect scans (\fB\-sT\fR) and idle scans (\fB\-sI\fR)\&. All traces use Nmap\*(Aqs dynamic timing model and are performed in parallel\&.
.sp
Traceroute works by sending packets with a low TTL (time\-to\-live) in an attempt to elicit ICMP Time Exceeded messages from intermediate hops between the scanner and the target host\&. Standard traceroute implementations start with a TTL of 1 and increment the TTL until the destination host is reached\&. Nmap\*(Aqs traceroute starts with a high TTL and then decrements the TTL until it reaches zero\&. Doing it backwards lets Nmap employ clever caching algorithms to speed up traces over multiple hosts\&. On average Nmap sends 5\(en10 fewer packets per host, depending on network conditions\&. If a single subnet is being scanned (i\&.e\&. 192\&.168\&.0\&.0/24) Nmap may only have to send two packets to most hosts\&.
.RE
.PP
\fB\-n\fR (No DNS resolution)
.RS 4
Tells Nmap to
\fInever\fR
do reverse DNS resolution on the active IP addresses it finds\&. Since DNS can be slow even with Nmap\*(Aqs built\-in parallel stub resolver, this option can slash scanning times\&.
.RE
.PP
\fB\-R\fR (DNS resolution for all targets)
.RS 4
Tells Nmap to
\fIalways\fR
do reverse DNS resolution on the target IP addresses\&. Normally reverse DNS is only performed against responsive (online) hosts\&.
.RE
.PP
\fB\-\-resolve\-all\fR (Scan each resolved address)
.RS 4
If a hostname target resolves to more than one address, scan all of them\&. The default behavior is to only scan the first resolved address\&. Regardless, only addresses in the appropriate address family will be scanned: IPv4 by default, IPv6 with
\fB\-6\fR\&.
.RE
.PP
\fB\-\-system\-dns\fR (Use system DNS resolver)
.RS 4
By default, Nmap reverse\-resolves IP addresses by sending queries directly to the name servers configured on your host and then listening for responses\&. Many requests (often dozens) are performed in parallel to improve performance\&. Specify this option to use your system resolver instead (one IP at a time via the
\fBgetnameinfo\fR
call)\&. This is slower and rarely useful unless you find a bug in the Nmap parallel resolver (please let us know if you do)\&. The system resolver is always used for forward lookups (getting an IP address from a hostname)\&.
.RE
.PP
\fB\-\-dns\-servers \fR\fB\fIserver1\fR\fR\fB[,\fIserver2\fR[,\&.\&.\&.]]\fR\fB \fR (Servers to use for reverse DNS queries)
.RS 4
By default, Nmap determines your DNS servers (for rDNS resolution) from your resolv\&.conf file (Unix) or the Registry (Win32)\&. Alternatively, you may use this option to specify alternate servers\&. This option is not honored if you are using
\fB\-\-system\-dns\fR\&. Using multiple DNS servers is often faster, especially if you choose authoritative servers for your target IP space\&. This option can also improve stealth, as your requests can be bounced off just about any recursive DNS server on the Internet\&.
.sp
This option also comes in handy when scanning private networks\&. Sometimes only a few name servers provide proper rDNS information, and you may not even know where they are\&. You can scan the network for port 53 (perhaps with version detection), then try Nmap list scans (\fB\-sL\fR) specifying each name server one at a time with
\fB\-\-dns\-servers\fR
until you find one which works\&.
.sp
This option might not be honored if the DNS response exceeds the size of a UDP packet\&. In such a situation our DNS resolver will make the best effort to extract a response from the truncated packet, and if not successful it will fall back to using the system resolver\&. Also, responses that contain CNAME aliases will fall back to the system resolver\&.
.RE
.SH "PORT SCANNING BASICS"
.PP
While Nmap has grown in functionality over the years, it began as an efficient port scanner, and that remains its core function\&. The simple command
\fBnmap \fR\fB\fItarget\fR\fR
scans 1,000 TCP ports on the host
\fItarget\fR\&. While many port scanners have traditionally lumped all ports into the open or closed states, Nmap is much more granular\&. It divides ports into six states:
open,
closed,
filtered,
unfiltered,
open|filtered, or
closed|filtered\&.
.PP
These states are not intrinsic properties of the port itself, but describe how Nmap sees them\&. For example, an Nmap scan from the same network as the target may show port
135/tcp
as open, while a scan at the same time with the same options from across the Internet might show that port as
filtered\&.
.PP
\fBThe six port states recognized by Nmap\fR
.PP
open
.RS 4
An application is actively accepting TCP connections, UDP datagrams or SCTP associations on this port\&. Finding these is often the primary goal of port scanning\&. Security\-minded people know that each open port is an avenue for attack\&. Attackers and pen\-testers want to exploit the open ports, while administrators try to close or protect them with firewalls without thwarting legitimate users\&. Open ports are also interesting for non\-security scans because they show services available for use on the network\&.
.RE
.PP
closed
.RS 4
A closed port is accessible (it receives and responds to Nmap probe packets), but there is no application listening on it\&. They can be helpful in showing that a host is up on an IP address (host discovery, or ping scanning), and as part of OS detection\&. Because closed ports are reachable, it may be worth scanning later in case some open up\&. Administrators may want to consider blocking such ports with a firewall\&. Then they would appear in the filtered state, discussed next\&.
.RE
.PP
filtered
.RS 4
Nmap cannot determine whether the port is open because packet filtering prevents its probes from reaching the port\&. The filtering could be from a dedicated firewall device, router rules, or host\-based firewall software\&. These ports frustrate attackers because they provide so little information\&. Sometimes they respond with ICMP error messages such as type 3 code 13 (destination unreachable: communication administratively prohibited), but filters that simply drop probes without responding are far more common\&. This forces Nmap to retry several times just in case the probe was dropped due to network congestion rather than filtering\&. This slows down the scan dramatically\&.
.RE
.PP
unfiltered
.RS 4
The unfiltered state means that a port is accessible, but Nmap is unable to determine whether it is open or closed\&. Only the ACK scan, which is used to map firewall rulesets, classifies ports into this state\&. Scanning unfiltered ports with other scan types such as Window scan, SYN scan, or FIN scan, may help resolve whether the port is open\&.
.RE
.PP
open|filtered
.RS 4
Nmap places ports in this state when it is unable to determine whether a port is open or filtered\&. This occurs for scan types in which open ports give no response\&. The lack of response could also mean that a packet filter dropped the probe or any response it elicited\&. So Nmap does not know for sure whether the port is open or being filtered\&. The UDP, IP protocol, FIN, NULL, and Xmas scans classify ports this way\&.
.RE
.PP
closed|filtered
.RS 4
This state is used when Nmap is unable to determine whether a port is closed or filtered\&. It is only used for the IP ID idle scan\&.
.RE
.SH "PORT SCANNING TECHNIQUES"
.PP
As a novice performing automotive repair, I can struggle for hours trying to fit my rudimentary tools (hammer, duct tape, wrench, etc\&.) to the task at hand\&. When I fail miserably and tow my jalopy to a real mechanic, he invariably fishes around in a huge tool chest until pulling out the perfect gizmo which makes the job seem effortless\&. The art of port scanning is similar\&. Experts understand the dozens of scan techniques and choose the appropriate one (or combination) for a given task\&. Inexperienced users and script kiddies,
on the other hand, try to solve every problem with the default SYN scan\&. Since Nmap is free, the only barrier to port scanning mastery is knowledge\&. That certainly beats the automotive world, where it may take great skill to determine that you need a strut spring compressor, then you still have to pay thousands of dollars for it\&.
.PP
Most of the scan types are only available to privileged users\&.
This is because they send and receive raw packets,
which requires root access on Unix systems\&. Using an administrator account on Windows is recommended, though Nmap sometimes works for unprivileged users on that platform when Npcap has already been loaded into the OS\&. Requiring root privileges was a serious limitation when Nmap was released in 1997, as many users only had access to shared shell accounts\&. Now, the world is different\&. Computers are cheaper, far more people have always\-on direct Internet access, and desktop Unix systems (including Linux and Mac OS X) are prevalent\&. A Windows version of Nmap is now available, allowing it to run on even more desktops\&. For all these reasons, users have less need to run Nmap from limited shared shell accounts\&. This is fortunate, as the privileged options make Nmap far more powerful and flexible\&.
.PP
While Nmap attempts to produce accurate results, keep in mind that all of its insights are based on packets returned by the target machines (or firewalls in front of them)\&. Such hosts may be untrustworthy and send responses intended to confuse or mislead Nmap\&. Much more common are non\-RFC\-compliant hosts that do not respond as they should to Nmap probes\&. FIN, NULL, and Xmas scans are particularly susceptible to this problem\&. Such issues are specific to certain scan types and so are discussed in the individual scan type entries\&.
.PP
This section documents the dozen or so port scan techniques supported by Nmap\&. Only one method may be used at a time, except that UDP scan (\fB\-sU\fR) and any one of the SCTP scan types (\fB\-sY\fR,
\fB\-sZ\fR) may be combined with any one of the TCP scan types\&. As a memory aid, port scan type options are of the form
\fB\-s\fR\fB\fIC\fR\fR, where
\fIC\fR
is a prominent character in the scan name, usually the first\&. The one exception to this is the deprecated FTP bounce scan (\fB\-b\fR)\&. By default, Nmap performs a SYN Scan, though it substitutes a connect scan if the user does not have proper privileges to send raw packets (requires root access on Unix)\&. Of the scans listed in this section, unprivileged users can only execute connect and FTP bounce scans\&.
.PP
\fB\-sS\fR (TCP SYN scan)
.RS 4
SYN scan is the default and most popular scan option for good reasons\&. It can be performed quickly, scanning thousands of ports per second on a fast network not hampered by restrictive firewalls\&. It is also relatively unobtrusive and stealthy since it never completes TCP connections\&. SYN scan works against any compliant TCP stack rather than depending on idiosyncrasies of specific platforms as Nmap\*(Aqs FIN/NULL/Xmas, Maimon and idle scans do\&. It also allows clear, reliable differentiation between the
open,
closed, and
filtered
states\&.
.sp
This technique is often referred to as half\-open scanning, because you don\*(Aqt open a full TCP connection\&. You send a SYN packet, as if you are going to open a real connection and then wait for a response\&. A SYN/ACK indicates the port is listening (open), while a RST (reset) is indicative of a non\-listener\&. If no response is received after several retransmissions, the port is marked as filtered\&. The port is also marked filtered if an ICMP unreachable error (type 3, code 0, 1, 2, 3, 9, 10, or 13) is received\&. The port is also considered open if a SYN packet (without the ACK flag) is received in response\&. This can be due to an extremely rare TCP feature known as a simultaneous open or split handshake connection (see
\m[blue]\fB\%https://nmap.org/misc/split-handshake.pdf\fR\m[])\&.
.RE
.PP
\fB\-sT\fR (TCP connect scan)
.RS 4
TCP connect scan is the default TCP scan type when SYN scan is not an option\&. This is the case when a user does not have raw packet privileges\&. Instead of writing raw packets as most other scan types do, Nmap asks the underlying operating system to establish a connection with the target machine and port by issuing the
\fBconnect\fR
system call\&. This is the same high\-level system call that web browsers, P2P clients, and most other network\-enabled applications use to establish a connection\&. It is part of a programming interface known as the Berkeley Sockets API\&. Rather than read raw packet responses off the wire, Nmap uses this API to obtain status information on each connection attempt\&.
.sp
When SYN scan is available, it is usually a better choice\&. Nmap has less control over the high level
\fBconnect\fR
call than with raw packets, making it less efficient\&. The system call completes connections to open target ports rather than performing the half\-open reset that SYN scan does\&. Not only does this take longer and require more packets to obtain the same information, but target machines are more likely to log the connection\&. A decent IDS will catch either, but most machines have no such alarm system\&. Many services on your average Unix system will add a note to syslog, and sometimes a cryptic error message, when Nmap connects and then closes the connection without sending data\&. Truly pathetic services crash when this happens, though that is uncommon\&. An administrator who sees a bunch of connection attempts in her logs from a single system should know that she has been connect scanned\&.
.RE
.PP
\fB\-sU\fR (UDP scans)
.RS 4
While most popular services on the Internet run over the TCP protocol,
\m[blue]\fBUDP\fR\m[]\&\s-2\u[5]\d\s+2
services are widely deployed\&. DNS, SNMP, and DHCP (registered ports 53, 161/162, and 67/68) are three of the most common\&. Because UDP scanning is generally slower and more difficult than TCP, some security auditors ignore these ports\&. This is a mistake, as exploitable UDP services are quite common and attackers certainly don\*(Aqt ignore the whole protocol\&. Fortunately, Nmap can help inventory UDP ports\&.
.sp
UDP scan is activated with the
\fB\-sU\fR
option\&. It can be combined with a TCP scan type such as SYN scan (\fB\-sS\fR) to check both protocols during the same run\&.
.sp
UDP scan works by sending a UDP packet to every targeted port\&. For some common ports such as 53 and 161, a protocol\-specific payload is sent to increase response rate, but for most ports the packet is empty unless the
\fB\-\-data\fR,
\fB\-\-data\-string\fR, or
\fB\-\-data\-length\fR
options are specified\&. If an ICMP port unreachable error (type 3, code 3) is returned, the port is
closed\&. Other ICMP unreachable errors (type 3, codes 0, 1, 2, 9, 10, or 13) mark the port as
filtered\&. Occasionally, a service will respond with a UDP packet, proving that it is
open\&. If no response is received after retransmissions, the port is classified as
open|filtered\&. This means that the port could be open, or perhaps packet filters are blocking the communication\&. Version detection (\fB\-sV\fR) can be used to help differentiate the truly open ports from the filtered ones\&.
.sp
A big challenge with UDP scanning is doing it quickly\&. Open and filtered ports rarely send any response, leaving Nmap to time out and then conduct retransmissions just in case the probe or response were lost\&. Closed ports are often an even bigger problem\&. They usually send back an ICMP port unreachable error\&. But unlike the RST packets sent by closed TCP ports in response to a SYN or connect scan, many hosts rate limit
ICMP port unreachable messages by default\&. Linux and Solaris are particularly strict about this\&. For example, the Linux 2\&.4\&.20 kernel limits destination unreachable messages to one per second (in
net/ipv4/icmp\&.c)\&.
.sp
Nmap detects rate limiting and slows down accordingly to avoid flooding the network with useless packets that the target machine will drop\&. Unfortunately, a Linux\-style limit of one packet per second makes a 65,536\-port scan take more than 18 hours\&. Ideas for speeding your UDP scans up include scanning more hosts in parallel, doing a quick scan of just the popular ports first, scanning from behind the firewall, and using
\fB\-\-host\-timeout\fR
to skip slow hosts\&.
.RE
.PP
\fB\-sY\fR (SCTP INIT scan)
.RS 4
\m[blue]\fBSCTP\fR\m[]\&\s-2\u[6]\d\s+2
is a relatively new alternative to the TCP and UDP protocols, combining most characteristics of TCP and UDP, and also adding new features like multi\-homing and multi\-streaming\&. It is mostly being used for SS7/SIGTRAN related services but has the potential to be used for other applications as well\&. SCTP INIT scan is the SCTP equivalent of a TCP SYN scan\&. It can be performed quickly, scanning thousands of ports per second on a fast network not hampered by restrictive firewalls\&. Like SYN scan, INIT scan is relatively unobtrusive and stealthy, since it never completes SCTP associations\&. It also allows clear, reliable differentiation between the
open,
closed, and
filtered
states\&.
.sp
This technique is often referred to as half\-open scanning, because you don\*(Aqt open a full SCTP association\&. You send an INIT chunk, as if you are going to open a real association and then wait for a response\&. An INIT\-ACK chunk indicates the port is listening (open), while an ABORT chunk is indicative of a non\-listener\&. If no response is received after several retransmissions, the port is marked as filtered\&. The port is also marked filtered if an ICMP unreachable error (type 3, code 0, 1, 2, 3, 9, 10, or 13) is received\&.
.RE
.PP
\fB\-sN\fR; \fB\-sF\fR; \fB\-sX\fR (TCP NULL, FIN, and Xmas scans)
.RS 4
These three scan types (even more are possible with the
\fB\-\-scanflags\fR
option described in the next section) exploit a subtle loophole in the
\m[blue]\fBTCP RFC\fR\m[]\&\s-2\u[7]\d\s+2
to differentiate between
open
and
closed
ports\&. Page 65 of RFC 793 says that
\(lqif the [destination] port state is CLOSED \&.\&.\&.\&. an incoming segment not containing a RST causes a RST to be sent in response\&.\(rq
Then the next page discusses packets sent to open ports without the SYN, RST, or ACK bits set, stating that:
\(lqyou are unlikely to get here, but if you do, drop the segment, and return\&.\(rq
.sp
When scanning systems compliant with this RFC text, any packet not containing SYN, RST, or ACK bits will result in a returned RST if the port is closed and no response at all if the port is open\&. As long as none of those three bits are included, any combination of the other three (FIN, PSH, and URG) are OK\&. Nmap exploits this with three scan types:
.PP
Null scan (\fB\-sN\fR)
.RS 4
Does not set any bits (TCP flag header is 0)
.RE
.PP
FIN scan (\fB\-sF\fR)
.RS 4
Sets just the TCP FIN bit\&.
.RE
.PP
Xmas scan (\fB\-sX\fR)
.RS 4
Sets the FIN, PSH, and URG flags, lighting the packet up like a Christmas tree\&.
.RE
.sp
These three scan types are exactly the same in behavior except for the TCP flags set in probe packets\&. If a RST packet is received, the port is considered
closed, while no response means it is
open|filtered\&. The port is marked
filtered
if an ICMP unreachable error (type 3, code 0, 1, 2, 3, 9, 10, or 13) is received\&.
.sp
The key advantage to these scan types is that they can sneak through certain non\-stateful firewalls and packet filtering routers\&. Another advantage is that these scan types are a little more stealthy than even a SYN scan\&. Don\*(Aqt count on this though\(emmost modern IDS products can be configured to detect them\&. The big downside is that not all systems follow RFC 793 to the letter\&. A number of systems send RST responses to the probes regardless of whether the port is open or not\&. This causes all of the ports to be labeled
closed\&. Major operating systems that do this are Microsoft Windows, many Cisco devices, BSDI, and IBM OS/400\&. This scan does work against most Unix\-based systems though\&. Another downside of these scans is that they can\*(Aqt distinguish
open
ports from certain
filtered
ones, leaving you with the response
open|filtered\&.
.RE
.PP
\fB\-sA\fR (TCP ACK scan)
.RS 4
This scan is different than the others discussed so far in that it never determines
open
(or even
open|filtered) ports\&. It is used to map out firewall rulesets, determining whether they are stateful or not and which ports are filtered\&.
.sp
The ACK scan probe packet has only the ACK flag set (unless you use
\fB\-\-scanflags\fR)\&. When scanning unfiltered systems,
open
and
closed
ports will both return a RST packet\&. Nmap then labels them as
unfiltered, meaning that they are reachable by the ACK packet, but whether they are
open
or
closed
is undetermined\&. Ports that don\*(Aqt respond, or send certain ICMP error messages back (type 3, code 0, 1, 2, 3, 9, 10, or 13), are labeled
filtered\&.
.RE
.PP
\fB\-sW\fR (TCP Window scan)
.RS 4
Window scan is exactly the same as ACK scan except that it exploits an implementation detail of certain systems to differentiate open ports from closed ones, rather than always printing
unfiltered
when a RST is returned\&. It does this by examining the TCP Window field of the RST packets returned\&. On some systems, open ports use a positive window size (even for RST packets) while closed ones have a zero window\&. So instead of always listing a port as
unfiltered
when it receives a RST back, Window scan lists the port as
open
or
closed
if the TCP Window value in that reset is positive or zero, respectively\&.
.sp
This scan relies on an implementation detail of a minority of systems out on the Internet, so you can\*(Aqt always trust it\&. Systems that don\*(Aqt support it will usually return all ports
closed\&. Of course, it is possible that the machine really has no open ports\&. If most scanned ports are
closed
but a few common port numbers (such as 22, 25, 53) are
filtered, the system is most likely susceptible\&. Occasionally, systems will even show the exact opposite behavior\&. If your scan shows 1,000 open ports and three closed or filtered ports, then those three may very well be the truly open ones\&.
.RE
.PP
\fB\-sM\fR (TCP Maimon scan)
.RS 4
The Maimon scan is named after its discoverer, Uriel Maimon\&.
He described the technique in
Phrack
Magazine issue #49 (November 1996)\&.
Nmap, which included this technique, was released two issues later\&. This technique is exactly the same as NULL, FIN, and Xmas scans, except that the probe is FIN/ACK\&. According to
\m[blue]\fBRFC 793\fR\m[]\&\s-2\u[7]\d\s+2
(TCP), a RST packet should be generated in response to such a probe whether the port is open or closed\&. However, Uriel noticed that many BSD\-derived systems simply drop the packet if the port is open\&.
.RE
.PP
\fB\-\-scanflags\fR (Custom TCP scan)
.RS 4
Truly advanced Nmap users need not limit themselves to the canned scan types offered\&. The
\fB\-\-scanflags\fR
option allows you to design your own scan by specifying arbitrary TCP flags\&.
Let your creative juices flow, while evading intrusion detection systems
whose vendors simply paged through the Nmap man page adding specific rules!
.sp
The
\fB\-\-scanflags\fR
argument can be a numerical flag value such as 9 (PSH and FIN), but using symbolic names is easier\&. Just mash together any combination of
URG,
ACK,
PSH,
RST,
SYN, and
FIN\&. For example,
\fB\-\-scanflags URGACKPSHRSTSYNFIN\fR
sets everything, though it\*(Aqs not very useful for scanning\&. The order these are specified in is irrelevant\&.
.sp
In addition to specifying the desired flags, you can specify a TCP scan type (such as
\fB\-sA\fR
or
\fB\-sF\fR)\&. That base type tells Nmap how to interpret responses\&. For example, a SYN scan considers no\-response to indicate a
filtered
port, while a FIN scan treats the same as
open|filtered\&. Nmap will behave the same way it does for the base scan type, except that it will use the TCP flags you specify instead\&. If you don\*(Aqt specify a base type, SYN scan is used\&.
.RE
.PP
\fB\-sZ\fR (SCTP COOKIE ECHO scan)
.RS 4
SCTP COOKIE ECHO scan is a more advanced SCTP scan\&. It takes advantage of the fact that SCTP implementations should silently drop packets containing COOKIE ECHO chunks on open ports, but send an ABORT if the port is closed\&. The advantage of this scan type is that it is not as obvious a port scan than an INIT scan\&. Also, there may be non\-stateful firewall rulesets blocking INIT chunks, but not COOKIE ECHO chunks\&. Don\*(Aqt be fooled into thinking that this will make a port scan invisible; a good IDS will be able to detect SCTP COOKIE ECHO scans too\&. The downside is that SCTP COOKIE ECHO scans cannot differentiate between
open
and
filtered
ports, leaving you with the state
open|filtered
in both cases\&.
.RE
.PP
\fB\-sI \fR\fB\fIzombie host\fR\fR\fB[:\fIprobeport\fR]\fR (idle scan)
.RS 4
This advanced scan method allows for a truly blind TCP port scan of the target (meaning no packets are sent to the target from your real IP address)\&. Instead, a unique side\-channel attack exploits predictable IP fragmentation ID sequence generation on the zombie host to glean information about the open ports on the target\&. IDS systems will display the scan as coming from the zombie machine you specify (which must be up and meet certain criteria)\&.
This fascinating scan type is too complex to fully describe in this reference guide, so I wrote and posted an informal paper with full details at \m[blue]\fB\%https://nmap.org/book/idlescan.html\fR\m[]\&.
.sp
Besides being extraordinarily stealthy (due to its blind nature), this scan type permits mapping out IP\-based trust relationships between machines\&. The port listing shows open ports
\fIfrom the perspective of the zombie host\&.\fR
So you can try scanning a target using various zombies that you think might be trusted
(via router/packet filter rules)\&.
.sp
You can add a colon followed by a port number to the zombie host if you wish to probe a particular port on the zombie for IP ID changes\&. Otherwise Nmap will use the port it uses by default for TCP pings (80)\&.
.RE
.PP
\fB\-sO\fR (IP protocol scan)
.RS 4
IP protocol scan allows you to determine which IP protocols (TCP, ICMP, IGMP, etc\&.) are supported by target machines\&. This isn\*(Aqt technically a port scan, since it cycles through IP protocol numbers rather than TCP or UDP port numbers\&. Yet it still uses the
\fB\-p\fR
option to select scanned protocol numbers, reports its results within the normal port table format, and even uses the same underlying scan engine as the true port scanning methods\&. So it is close enough to a port scan that it belongs here\&.
.sp
Besides being useful in its own right, protocol scan demonstrates the power of open\-source software\&. While the fundamental idea is pretty simple, I had not thought to add it nor received any requests for such functionality\&. Then in the summer of 2000, Gerhard Rieger
conceived the idea, wrote an excellent patch implementing it, and sent it to the
announce
mailing list
(then called
nmap\-hackers)\&.
I incorporated that patch into the Nmap tree and released a new version the next day\&. Few pieces of commercial software have users enthusiastic enough to design and contribute their own improvements!
.sp
Protocol scan works in a similar fashion to UDP scan\&. Instead of iterating through the port number field of a UDP packet, it sends IP packet headers and iterates through the eight\-bit IP protocol field\&. The headers are usually empty, containing no data and not even the proper header for the claimed protocol\&. The exceptions are TCP, UDP, ICMP, SCTP, and IGMP\&. A proper protocol header for those is included since some systems won\*(Aqt send them otherwise and because Nmap already has functions to create them\&. Instead of watching for ICMP port unreachable messages, protocol scan is on the lookout for ICMP
\fIprotocol\fR
unreachable messages\&. If Nmap receives any response in any protocol from the target host, Nmap marks that protocol as
open\&. An ICMP protocol unreachable error (type 3, code 2) causes the protocol to be marked as
closed
while port unreachable (type 3, code 3) marks the protocol
open\&. Other ICMP unreachable errors (type 3, code 0, 1, 9, 10, or 13) cause the protocol to be marked
filtered
(though they prove that ICMP is
open
at the same time)\&. If no response is received after retransmissions, the protocol is marked
open|filtered
.RE
.PP
\fB\-b \fR\fB\fIFTP relay host\fR\fR (FTP bounce scan)
.RS 4
An interesting feature of the FTP protocol (\m[blue]\fBRFC 959\fR\m[]\&\s-2\u[8]\d\s+2) is support for so\-called proxy FTP connections\&. This allows a user to connect to one FTP server, then ask that files be sent to a third\-party server\&. Such a feature is ripe for abuse on many levels, so most servers have ceased supporting it\&. One of the abuses this feature allows is causing the FTP server to port scan other hosts\&. Simply ask the FTP server to send a file to each interesting port of a target host in turn\&. The error message will describe whether the port is open or not\&. This is a good way to bypass firewalls because organizational FTP servers are often placed where they have more access to other internal hosts than any old Internet host would\&. Nmap supports FTP bounce scan with the
\fB\-b\fR
option\&. It takes an argument of the form
\fIusername\fR:\fIpassword\fR@\fIserver\fR:\fIport\fR\&.
\fIServer\fR
is the name or IP address of a vulnerable FTP server\&. As with a normal URL, you may omit
\fIusername\fR:\fIpassword\fR, in which case anonymous login credentials (user:
anonymous
password:\-wwwuser@) are used\&. The port number (and preceding colon) may be omitted as well, in which case the default FTP port (21) on
\fIserver\fR
is used\&.
.sp
This vulnerability was widespread in 1997 when Nmap was released, but has largely been fixed\&. Vulnerable servers are still around, so it is worth trying when all else fails\&. If bypassing a firewall is your goal, scan the target network for port 21 (or even for any FTP services if you scan all ports with version detection) and use the
ftp\-bounce
NSE script\&. Nmap will tell you whether the host is vulnerable or not\&. If you are just trying to cover your tracks, you don\*(Aqt need to (and, in fact, shouldn\*(Aqt) limit yourself to hosts on the target network\&. Before you go scanning random Internet addresses for vulnerable FTP servers, consider that sysadmins may not appreciate you abusing their servers in this way\&.
.RE
.SH "PORT SPECIFICATION AND SCAN ORDER"
.PP
In addition to all of the scan methods discussed previously, Nmap offers options for specifying which ports are scanned and whether the scan order is randomized or sequential\&. By default, Nmap scans the most common 1,000 ports for each protocol\&.
.PP
\fB\-p \fR\fB\fIport ranges\fR\fR (Only scan specified ports)
.RS 4
This option specifies which ports you want to scan and overrides the default\&. Individual port numbers are OK, as are ranges separated by a hyphen (e\&.g\&.
1\-1023)\&. The beginning and/or end values of a range may be omitted, causing Nmap to use 1 and 65535, respectively\&. So you can specify
\fB\-p\-\fR
to scan ports from 1 through 65535\&. Scanning port zero
is allowed if you specify it explicitly\&. For IP protocol scanning (\fB\-sO\fR), this option specifies the protocol numbers you wish to scan for (0\(en255)\&.
.sp
When scanning a combination of protocols (e\&.g\&. TCP and UDP), you can specify a particular protocol by preceding the port numbers by
T:
for TCP,
U:
for UDP,
S:
for SCTP, or
P:
for IP Protocol\&. The qualifier lasts until you specify another qualifier\&. For example, the argument
\fB\-p U:53,111,137,T:21\-25,80,139,8080\fR
would scan UDP ports 53, 111,and 137, as well as the listed TCP ports\&. Note that to scan both UDP and TCP, you have to specify
\fB\-sU\fR
and at least one TCP scan type (such as
\fB\-sS\fR,
\fB\-sF\fR, or
\fB\-sT\fR)\&. If no protocol qualifier is given, the port numbers are added to all protocol lists\&.
Ports can also be specified by name according to what the port is referred to in the