nmap.1
来自「Ubuntu packages of security software。 相」· 1 代码 · 共 736 行 · 第 1/5 页
1
736 行
\fB\-P0\fRcauses Nmap to attempt the requested scanning functions against\fIevery\fRtarget IP address specified. So if a class B sized target address space (/16) is specified on the command line, all 65,536 IP addresses are scanned. That second option character in\fB\-P0\fRis a zero and not the letter O. 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..TP\fB\-PS [portlist]\fR (TCP SYN Ping)This option sends an empty TCP packet with the SYN flag set. The default destination port is 80 (configurable at compile time by changing DEFAULT_TCP_PROBE_PORT in\fInmap.h\fR), but an alternate port can be specified as a parameter. A comma separated list of ports can even be specified (e.g.\fB\-PS22,23,25,80,113,1050,35000\fR), in which case probes will be attempted against each port in parallel..spThe 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 3\-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 3\-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..spNmap 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..spOn UNIX boxes, only the privileged userrootis generally able to send and receive raw TCP packets. For unprivileged users, a workaround is automatically employed whereby the connect() 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 connect() returns with a quick success or an ECONNREFUSED failure, the underlying TCP stack must have received a SYN/ACK or RST and the host is marked available. If the connection attempt is left hanging until a timeout is reached, the host is marked as down. This workaround is also used for IPv6 connections, as raw IPv6 packet building support is not yet available in Nmap..TP\fB\-PA [portlist]\fR (TCP ACK Ping)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..spThe\fB\-PA\fRoption uses the same default port as the SYN probe (80) and can also take a list of destination ports in the same format. If an unprivileged user tries this, or an IPv6 target is specified, the connect() workaround discussed previously is used. This workaround is imperfect because connect() is actually sending a SYN packet rather than an ACK..spThe 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\fRconvenience 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..spAnother 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\fRoption, 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\fRand\fB\-PA\fR..TP\fB\-PU [portlist]\fR (UDP Ping)Another host discovery option is the UDP ping, which sends an empty (unless\fB\-\-data\-length\fRis specified) UDP packet to the given ports. The portlist takes the same format as with the previously discussed\fB\-PS\fRand\fB\-PA\fRoptions. If no ports are specified, the default is 31338. This default can be configured at compile\-time by changing DEFAULT_UDP_PROBE_PORT in\fInmap.h\fR. A highly uncommon port is used by default because sending to open ports is often undesirable for this particular scan type..spUpon hitting a closed port on the target machine, the UDP probe should elicit an ICMP port unreachable packet in return. This signifies to Nmap that the machine is up and available. Many other types of ICMP errors, such as host/network unreachables or TTL exceeded are indicative of a down or unreachable host. A lack of response is also interpreted this way. If an open port is reached, most services simply ignore the empty packet and fail to return any response. This is why the default probe port is 31338, which is highly unlikely to be in use. A few services, such as chargen, will respond to an empty UDP packet, and thus disclose to Nmap that the machine is available..spThe 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..TP\fB\-PE\fR; \fB\-PP\fR; \fB\-PM\fR (ICMP Ping Types)In addition to the unusual TCP and UDP host discovery types discussed previously, Nmap can send the standard packets sent by the ubiquitouspingprogram. 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[1]\&\fIRFC 1122\fR. 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\fRoption to enable this echo request behavior..spWhile echo request is the standard ICMP ping query, Nmap does not stop there. The ICMP standard ([2]\&\fIRFC 792\fR) also specifies timestamp request, information request, and address mask request packets as codes 13, 15, and 17, respectively. While the ostensible purpose for these queries is to learn information such as address masks and current times, they can easily be used for host discovery. A system that replies is up and available. Nmap does not currently implement information request packets, as they are not widely supported. RFC 1122 insists that\(lqa host SHOULD NOT implement these messages\(rq. Timestamp and address mask queries can be sent with the\fB\-PP\fRand\fB\-PM\fRoptions, 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 admins specifically block echo request packets while forgetting that other ICMP queries can be used for the same purpose..TP\fB\-PR\fR (ARP Ping)One of the most common Nmap usage scenarios is to scan an ethernet LAN. On most LANs, especially those using RFC1918\-blessed private address ranges, the vast majority of IP addresses are unused at any given time. When Nmap tries to send a raw IP packet such as an ICMP echo request, the operating system must determine the destination hardware (ARP) address corresponding to the target IP so that it can properly address the ethernet frame. This is often slow and problematic, since operating systems weren't written with the expectation that they would need to do millions of ARP requests against unavailable hosts in a short time period..spARP scan puts Nmap and its optimized algorithms in charge of ARP requests. And if it gets a response back, Nmap doesn't even need to worry about the IP\-based ping packets since it already knows the host is up. This makes ARP scan much faster and more reliable than IP\-based scans. So it is done by default when scanning ethernet hosts that Nmap detects are on a local ethernet network. Even if different ping types (such as\fB\-PE\fRor\fB\-PS\fR) are specified, Nmap uses ARP instead for any of the targets which are on the same LAN. If you absolutely don't want to do an ARP scan, specify\fB\-\-send\-ip\fR..TP\fB\-n\fR (No DNS resolution)Tells Nmap to\fInever\fRdo reverse DNS resolution on the active IP addresses it finds. Since DNS can be slow even with Nmap's built\-in parallel stub resolver, this option can slash scanning times..TP\fB\-R\fR (DNS resolution for all targets)Tells Nmap to\fIalways\fRdo reverse DNS resolution on the target IP addresses. Normally reverse DNS is only performed against responsive (online) hosts..TP\fB\-\-system\-dns\fR (Use system DNS resolver)By default, Nmap resolves IP addresses by sending queries directly to the name servers configured on your host and then listening for responses. Many requests (often dozens) are performed in parallel to improve performance. Specify this option to use your system resolver instead (one IP at a time via the getnameinfo() call). This is slower and rarely useful unless you find a bug in the Nmap parallel resolver (please let us know if you do). The system resolver is always used for IPv6 scans..TP\fB\-\-dns\-servers <server1[,server2],...> \fR (Servers to use for reverse DNS queries)By default Nmap will try to determine 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\fRor an IPv6 scan. Using multiple DNS servers is often faster, especially if you choose authoritative servers for your target IP space. This option can also improve stealth, as your requests can be bounced off just about any recursive DNS server on the internet..spThis 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\fRuntil you find one which works..SH "PORT SCANNING BASICS".PPWhile 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\fRscans more than 1660 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, orclosed|filtered..PPThese 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 asfiltered..PP\fBThe six port states recognized by Nmap\fR.TPopenAn application is actively accepting TCP connections or UDP packets on this port. Finding these is often the primary goal of port scanning. Security\-minded people know that each open port is an avenue for attack. Attackers and pen\-testers want to exploit the open ports, while administrators try to close or protect them with firewalls without thwarting legitimate users. Open ports are also interesting for non\-security scans because they show services available for use on the network..TPclosedA 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..TPfilteredNmap 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..TPunfilteredThe 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..TPopen|filteredNmap 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..TPclosed|filteredThis state is used when Nmap is unable to determine whether a port is closed or filtered. It is only used for the IPID Idle scan..SH "PORT SCANNING TECHNIQUES".PPAs 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..PPMost 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 WinPcap has already been loaded into the OS. Requiring root privileges was a serious limitation when Nmap was released in 1997, as many users only had access to shared shell accounts. Now, the world is different. Computers are cheaper, far more people have always\-on direct Internet access, and desktop UNIX systems (including Linux and MAC OS X) are prevalent. A Windows version of Nmap is now available, allowing it to run on even more desktops. For all these reasons, users have less need to run Nmap from limited shared shell accounts. This is fortunate, as the privileged options make Nmap far more powerful and flexible..PPWhile 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..PPThis 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) 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\fRis 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) or if IPv6 targets were specified. Of the scans listed in this section, unprivileged users can only execute connect and ftp bounce scans..TP\fB\-sS\fR (TCP SYN scan)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 intrusive firewalls. SYN scan is relatively unobtrusive and stealthy, since it never completes TCP connections. It also works against any compliant TCP stack rather than depending on idiosyncrasies of specific platforms as Nmap's Fin/Null/Xmas, Maimon and Idle scans do. It also allows clear, reliable differentiation between theopen,
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?