Target Specification
Everything on the command-line that isn't an option (or option argument) is treated as a target host specification. The simplest case is to specify a target IP address or hostname for scanning.
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 --resolve-all
option
#
$ nmap -iL <inputfilename> # (Input from list)
#
$ nmap -iR <num hosts> # (Choose random targets)
#
$ nmap --exclude <host1>[,<host2>[,...]] # (Exclude hosts/networks)
#
$ nmap --excludefile <exclude_file> # (Exclude list from file)
Host Discovery
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.
$
$
$ nmap -sL 192.168.178.1 # (List Scan)
$
$ nmap -sn 192.168.178.1 # (No port scan)
$
$ nmap -Pn # (No ping)
$
$ nmap -PS <port list> # (TCP SYN Ping)
$
$ nmap -PA <port list> # (TCP ACK Ping)
$
$ nmap -PU <port list> # (UDP Ping)
$
$ nmap -PY <port list> # (SCTP INIT Ping)
$
$ nmap -PE; -PP; -PM # (ICMP Ping Types)
$
$ nmap -PO <protocol list> # (IP Protocol Ping)
$
$ nmap --disable-arp-ping # (No ARP or ND Ping)
$
$ nmap --traceroute # (Trace path to host)
$
$ nmap -n # (No DNS resolution)
$
$ nmap -R # (DNS resolution for all targets)
$
$ nmap --resolve-all # (Scan each resolved address)
$
$ nmap --system-dns # (Use system DNS resolver)
$ nmap --dns-servers <server1>[,<server2>[,...]] # (Servers to use for reverse DNS queries)
TCP Port Scanning Basics
While Network mapper has grown in functionality over the years, it began as an efficient port scanner, and that remains its core function. The simple command nmap <target>
scans 1,000 TCP ports on the host <target>
. While many port scanners have traditionally lumped all ports into the open or closed states, Network mapper is much more granular. It divides ports into six states: open
, closed
, filtered
, unfiltered
, open|filtered
, or closed|filtered
.
The six states recognized by Network Mapper
- open 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
- closed A closed port is accessible (it receives and responds to 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.
- filtered 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 a retry several times just in case the probe was dropped due to network congestion rather than filtering. This slows down the scan dramatically.
- unfiltered The unfiltered state means that a port is accessible, but Network mapper 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.
-
open|filtered 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 Network nmapper 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.
-
closed|filtered This state is used when Network nmmapper is unable to determine whether a port is closed or filtered. It is only used for the IP ID idle scan.
TCP Scanning Techniques Used by Network Mapper
While 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 the scanner. 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.
-
-sS
(TCP SYN scan)
-
-sT
(TCP connect scan)
-
-sU
(UDP scans)
-
-sY
(SCTP INIT scan)
-
-sN
; -sF
; -sX
(TCP NULL, FIN, and Xmas scans)
-
-sA
(TCP ACK scan)
-
-sW
(TCP Window scan)
-
-sM
(TCP Maimon scan)
-
--scanflags
(Custom TCP scan)
-
-sZ
(SCTP COOKIE ECHO scan)
-
-sI <zombie host>
[:<probeport>
]
(idle scan)
-
-sO
(IP protocol scan)
-
-b <FTP relay host>
(FTP bounce scan)