Nmap port scan Configuration

Source: Internet
Author: User
Tags domain name server ftp protocol nmap port scan
Document directory
  • I. Software Packages
I. Software Packages

1. nmap-5.21.tar.bz2

Ii. Installation Steps

1. tar xvf nmap-5.21.tar.bz2

2. cd nmap-5.21


4. make

5. su root

6. make install

7. nmap www.sina.com

Starting Nmap 5.21 (http://nmap.org) at 2010-07-15 CST

Nmap scan report for www.sina.com (

Host is up (0.0042 s latency ).

Hostname www.sina.com resolves to 16 IPs. Only scanned

Not shown: 999 filtered ports


80/tcp open http

Nmap done: 1 IP address (1 host up) scanned in 4.86 seconds

8. Port 80 is enabled for the portal.

Iii. References

Nmap is a network detection and security scanning program. System Administrators and individuals can use this software to scan a large network and obtain information about the host running and what services it provides. Nmap supports many scanning technologies, such as UDP, TCP connect (), tcp syn (half-open scan), and ftp Proxy (bounce Attack), reverse flag, ICMP, FIN, ACK Scan, Christmas Tree (Xmas Tree), SYN scan, and null scan. Details can be obtained from the scan type section. Nmap also provides some advanced features, such as detecting operating system types, secretly scanning, dynamic latency and retransmission computing, and parallel scanning through TCP/IP protocol stack features, detects closed hosts by Using ping scanning in parallel, and uses bait scanning to avoid port filtering detection, direct RPC scanning (no need for port injection), fragment scanning, and flexible target and port settings.
To improve nmap performance in the non-root state, software designers have made great efforts. Unfortunately, some kernel interfaces (such as raw socket) need to be used in the root state. Therefore, try to use nmap as root.
Run nmap to obtain the list of host ports to be scanned. Nmap always provides the service name (if possible), port number, status, and Protocol of the well known port. Each port has the following statuses: open, filtered, and unfiltered. The open state means that the target host can use the accept () system call on this port to accept the connection. The filtered status indicates that the firewall, packet filtering, and other network security software mask the port and disable nmap to detect whether it is enabled. Unfiltered indicates that the port is disabled and no firewall/package filtering software is available to isolate nmap detection attempts. Generally, the port is in the unfiltered state. Only when most of the ports being scanned are in the filtered state will the port in the unfiltered State be displayed.
Nmap can also report the following features of a remote host based on the function options used: the operating system used, the TCP sequence, and the user name, DNS name, host address, and other things of the application bound to each port.
4. Function options
Function options can be used in combination. Some feature options can only be used in some scan mode. Nmap automatically identifies invalid or unsupported combinations of function options and sends a warning to the user.
If you are an experienced user, you can skip the example section at the end. You can use nmap-h to quickly list feature options.
4.1 scan type
TCP connect () scan: This is the most basic TCP scan method. Connect () is a system call provided by the operating system to open a connection. If the target port has a program listener, connect () will return a successful result; otherwise, this port is inaccessible. The biggest advantage of this technology is that you do not need root permissions. Any UNIX user can use this system for calling. This kind of scan can easily be detected. A large number of connection requests and error messages are recorded in the logs of the target host.
TCP Synchronous Scan (tcp syn): Because you do not need to open a TCP connection, this technology is generally called half-open scan ). You can send a TCP synchronization packet (SYN) and wait for a response. If the other party returns SYN | ACK (response) packet, it indicates that the target port is listening; If RST packet is returned, it indicates that the target port does not have a listener; if it receives a SYN | ACK packet, the source host will immediately issue an RST (reset) packet to disconnect from the target host, which is actually automatically completed by our operating system kernel. The biggest benefit of this technology is that few systems are able to record this in system logs. However, you need the root permission to customize SYN packets.
Private FIN packet scanning, Christmas Tree (Xmas Tree), Null scan mode: used even if SYN scan is uncertain. Some firewall and packet filtering software can monitor SYN packets sent to restricted ports, and some programs such as synlogger and courtney can detect those scans. These advanced scanning methods can escape these interference. The Theoretical Basis of These scanning methods is: the closed port needs to respond to your test package to the RST package, and the opened port must ignore the problematic package (refer to RFC 793 64th page ). FIN scan uses exposed FIN data packets for detection, while Christmas tree scan opens the FIN, URG, and PUSH flag of the data packets. Unfortunately, Microsoft decided to completely ignore this standard and set it up again. Therefore, this scan method is invalid for Windows95/NT. However, from another perspective, you can use this method to separate two different platforms. If you use this scan method to find the opened port, you can determine that the target is not running Windows. If-sF,-sX, or-sN scan is used to show that all ports are closed, and SYN scan is used to display opened ports, you can determine that the target host may run the Windwos system. This method is not very useful because nmap has embedded operating system detection functions. Several other systems use the same processing methods as windows, including Cisco, BSDI, HP/UX, MYS, and IRIX. When data packets should be discarded, all the above systems send reset data packets from open ports.
Ping scan: Sometimes you just want to know which hosts on the network are running at this time. By sending an ICMP echo request packet to each IP address in your specified network, nmap can complete this task. If the host is running, it will respond. Unfortunately, some sites such as microsoft.com Block ICMP echo request packets. However, by default, nmap can also send TCP ack packets to port 80. If you receive an RST packet, it indicates that the host is running. The third technique used by nmap is to send a SYN Packet and wait for an RST or SYN/ACK packet. For non-root users, nmap uses the connect () method.
By default, nmap uses ICMP and ACK technologies in parallel.
Note that nmap performs ping scanning under any circumstances. Only when the target host is running will it perform subsequent scanning. This option is only used if you want to know whether the target host is running and do not want to perform other scans.
UDP scan: If you want to know which UDP (User Datagram Protocol, RFC768) services are provided on a host, you can use this scan method. Nmap first sends a 0-byte UDP packet to each port of the target host. If we receive an ICMP message that is inaccessible to the port, the port is closed. Otherwise, we assume it is open.
Some may think that UDP scanning is meaningless. However, I often think of the recent solaris rpcbind defect. Rpcbind is hidden on an undisclosed UDP port. The port number is greater than 32770. Therefore, even if port 111 is blocked by the firewall. But can you find that a program is listening on any port over 30000? Use UDP scan! The cDc Back orifice backdoor program is hidden in a configurable UDP port on a Windows host. Some common security defects are not considered. Some services such as snmp, tftp, and NFS use UDP protocol. Unfortunately, UDP scanning is sometimes very slow because most hosts limit the proportion of ICMP error messages (recommended in RFC1812 ). For example, in the Linux kernel (in net/ipv4/icmp. in h文) only 80 ICMP messages that cannot be reached by the target can be displayed every 4 seconds. If this proportion is exceeded, a penalty of 1/4 seconds will be given. Solaris is more restrictive. Only about two ICMP inaccessibility messages are allowed per second, which slows down scanning. Nmap detects the proportion of this limit and slows down the sending speed, instead of sending a large number of useless data packets discarded by the target host.
However, Micro $ oft ignores the RFC1812 suggestion and does not impose any restrictions on this ratio. Therefore, we can quickly scan all the 65K ports on the host running Win95/NT.
ACK Scan: This advanced scan method is usually used to pass through the firewall rule set. In general, this helps determine whether a firewall is fully functional or a simple package filtering program, just blocking the SYN packets that enter.
This scan sends an ACK packet to a specific port (using a Random Response/serial number ). If an RST packet is returned, the port is marked as unfiltered. If nothing is returned, or a non-reachable ICMP message is returned, this port is classified into the filtered class. Note: nmap usually does not output the unfiltered port, so it usually does not display all the ports to be tested in the output. Obviously, this scan method cannot find the port in the open state.
Scan a sliding window: This advanced scan technique is very similar to ACK scan, except that it can sometimes detect open ports because the size of the sliding window is irregular, some operating systems can report its size. These systems include at least: some versions of AIX, Amiga, BeOS, BSDI, Cray, Tru64 UNIX, DG/UX, OpenVMS, Digital UNIX, OpenBSD, OpenStep, QNX, Rhapsody, SunOS 4.X, Ultrix, VAX, and VXWORKS. You can obtain the complete list from the documents in the nmap-hackers mail 3 list.
RPC scan. This method is used in combination with other nmap port scanning methods. Select all open ports and issue the SunRPC program's NULL command to them to determine whether they are RPC ports. If so, determine the software and version number. Therefore, you can obtain some information about the firewall. Bait scanning cannot be used with RPC scanning now.
FTP bounce attack (bounce attack): the FTP protocol (RFC 959) has an interesting feature that supports proxy FTP connections. That is to say, I can connect to the FTP server target.com from evil.com, And I can ask this FTP server to send files anywhere on the Internet for myself! This feature worked well when RFC959 was completed in 1985. However, in today's Internet, we cannot allow people to hijack the FTP server and send data to any node on the Internet. As Hobbit said in an article written in 1995, this Protocol "can be used to deliver virtual inaccessibility emails and news, enter the servers of various sites, fill the hard disk, and skip the firewall, and other harassment activities, and it is difficult to track ". We can use this feature to scan TCP ports on a proxy FTP server. Therefore, you need to connect to an FTP server behind the firewall and then perform port scanning. If there is a readable directory on this FTP server, you can also send data to the target port (but nmap cannot do this for you ).
The parameter passed to the-B function option is the FTP server you want to act as the proxy. Syntax format:
-B username: password @ server: port.
Except server, the rest are optional. If you want to know which server has such defects, refer to my article on Phrack 51. You can also get the latest version of this article at the nmap site.
4.2 general options
These contents are not required, but are useful.
You do not need to ping the host before scanning. Some network firewalls Do Not Allow ICMP echo requests to pass through. You can use this option to scan these networks. Microsoft.com is an example. Therefore, you should always use the-P0 or-PT 80 option when scanning this site.
Before scanning, use TCP ping to determine which hosts are running. Nmap does not implement this function by sending an ICMP echo request packet and then waiting for a response. Instead, it sends a tcp ack packet to the target network (or a single host) and waits for a response. If the host is running, the RST package is returned. This option is valid only when the target network/host blocks the ping packet and still allows you to scan it. For non-root users, we use the connect () system call to implement this function. Use-PT <port number> to set the target port. The default port number is 80, because this port is usually not filtered.
For root users, this option allows nmap to use SYN packets instead of ACK packets to scan the target host. If the host is running, an RST package (or a SYN/ACK package) is returned ).
Set this option to enable nmap to use the real ping (ICMP echo request) to scan whether the target host is running. If you use this option to enable nmap to discover a running host, nmap will also observe your direct subnet broadcast address. Direct subnet broadcast address some externally accessible IP addresses, convert the external package into an inner IP address broadcast package, and send it to a computer subnet. These IP broadcast packages should be deleted because they may cause DoS attacks (such as smurf ).
This is the default ping scan option. It uses ACK (-PT) and ICMP (-PI) Scanning types for parallel scanning. If the firewall can filter one of the packages, you can use this method to pass through the firewall.
This option enables scanning of the TCP/IP fingerprint feature (fingerprinting) to obtain the remote host flag. In other words, nmap uses some techniques to detect the characteristics of the network protocol stack of the target host operating system. Nmap uses this information to establish the fingerprint feature of the remote host, and compares it with the known operating system fingerprint feature database to know the type of the target host's operating system.
This option enables nmap reverse flag scanning. Dave Goldsmith noted this protocol in an email sent to the bugtap on April 9, 1996. The ident protocol (rfc 1413) allows the user name of any process owner to be given using a TCP connection even if the process has not initialized the connection. For example, you can connect to the HTTP port and use identd to determine whether the server is run by the root user. This scan can be successful only when a full TCP connection is established with the target port (for example, the-sT scan option. With the-I option, the identd genie process of the remote host queries the owner of the process listening on each opened port. Apparently, this scan method is ineffective if the remote host does not run the identd program.
This option enables nmap to send SYN, FIN, XMAS, and NULL packets using fragmented IP packets. Using fragmented data packets increases the difficulty of packet filtering and intrusion detection systems so that they do not know your attempt. However, use this option with caution! Some programs may have trouble processing these fragment packets. When my favorite sniffer receives the first 36 bytes of the fragment packet, segmentation faulted occurs. Therefore, 24 bytes of fragmented data packets are used in nmap. Although the packet filter and firewall cannot prevent this method, many networks disable packet sharding for performance considerations.
Note that this option cannot be used on all platforms. It works well in Linux, FreeBSD, OpenBSD, and other UNIX systems.
Redundancy mode. We strongly recommend that you use this option to provide detailed information during the scan process. With this option, you can get twice the result with half the effort. Use the-d option to obtain more detailed information.
Quick Reference options.
Redirects the scan result to a readable file logfilename.
Redirects the scan result to the logfilename file, which uses the host-ready parsing syntax. You can use-oM-to replace logfilename, so that the output is redirected to the standard output stdout. In this case, the normal output will be overwritten, and the error message "stderr" can be output to the standard error stderr. Note that if the-v option is used at the same time, other information will be printed on the screen.
-OS thIs l0gz th3 r3suLtS of YouR ScanZ iN a s | THe fiL3 U sPecfy 4S an arGuMEnT! U kAn gIv3 the 4 rgument-
(WItHOUt qUOteZ) to sh00t output iNT0 stDouT! @!! Inexplicably, the following is what I guess is translated. What is the phase character?
Redirects the scan result to the logfilename file. This file uses a "hacker dialect" syntax (the author's joke ?). Similarly, the-OS-will redirect the result to the standard output.
A network scan may be interrupted due to control-C or network loss. This option can be used for subsequent scans. Logfilename is a log file that is unscanned. It must be in the readable form or the form that can be parsed by machines. In addition, you cannot add new options for subsequent scans. You can only use the same options as the interrupted scans. Nmap then performs the last successful scan in the log file for a new scan.
Read the scan target from the inputfilename file. In this file, you must have a host or network list. The space key, tabulation key, or enter key is used as the delimiter. If-iL-is used, nmap reads the host name from the standard input stdin. You can get more detailed information from the specified target section.
Enable nmap to randomly select hosts for scanning.
-P <port range>
This option allows you to select the range of port numbers to be scanned. For example,-p 23 indicates that only port 23 of the target host is scanned. -P 20-30,139,600 00-scan Port 20 to port 30, port 139, and all ports greater than 60000. By default, nmap scans the files from 1 to 1024 and nmap-services (if RPM packages are used, they are generally in the/usr/share/nmap/directory).
In quick scan mode, only the ports listed in the nmap-services file are scanned. It is faster than scanning all 65535 ports.
Use the bait scan method to scan the target network/host. If nmap uses this method to scan the target network, from the perspective of the target host/network, the scan is sent from other hosts (such as decoy1. Therefore, even if the IDS (Intrusion Detection System) of the target host sends an alarm to the port scan, it is impossible for them to know which address actually initiates the scan and which one is innocent. This scanning method can effectively deal with active defense mechanisms, such as route tracking and response-dropping, to effectively hide your IP address.
Each bait host name is separated by commas. You can also use the ME option, which represents your own host and is mixed with the bait host name. If you place ME in the sixth or back-to-back position, some port scan detection software will hardly display your IP address. If you do not use the ME option, nmap will randomly include your IP address in the bait host.
Note: The host you use as bait should be running or you only occasionally send SYN packets to the target. Obviously, if only one host runs on the network, the target will easily determine which host to scan. Maybe you need to directly use the IP address of the bait instead of its domain name, so that the logs on the domain name server of the bait network will not leave records about you.
Note: Some silly Port Scan detection software will reject the host that the route attempts to perform port scan. Therefore, you need to disconnect the target host from some bait. If the bait is the gateway of the target host or it is its own, it will cause a great problem to the target host. Therefore, you must use this option with caution.
Bait scanning can be used either in the initial ping scan or in the real scan status. It can also be used in combination with the-O option.
Using too many bait scans can slow down your scan speed and even cause incorrect scan results. At the same time, some ISPs will filter out your spoofing packets. Although most ISPs do not limit this currently.
-S <IP_Address>
In some cases, nmap may not be able to determine your source address (nmap will tell you ). In this case, you can use this option to give your IP address.
This option is also used for spoofing scanning. This option allows the target host to scan itself.
The interface used by nmap to send and receive data packets. Nmap can automatically detect this interface. If it is invalid, it will tell you.
Set the source port for the scan. The rule set for some naive firewalls and package filters allows source ports to be connected through and to packages for DNS (53) or FTP-DATA (20. Apparently, if attackers modify the source port to 20 or 53, they can destroy firewall protection. When using UDP scanning, use port 53 first; when using TCP scanning, use port 20 first. Note that nmap only uses this port for scanning. For example, if you cannot perform a TCP scan, nmap automatically changes the source port even if you use the-g option.
For some scans, using this option can cause minor performance losses, because I sometimes save some useful information about a specific source port.
Tell nmap not to disrupt the order of ports being scanned.
-- Randomize_hosts
Enable nmap to disrupt the host sequence in each group before scanning. Each group of nmap can scan up to 2048 hosts. In this way, scanning is more difficult to be detected by network monitors, especially when combined with the -- scan_delay option, which can effectively avoid being detected.
Sets the maximum number of sockets used for parallel scanning during TCP connect () scanning. This option can reduce the scanning speed and avoid remote target downtime.
4.3 Timely Options
Generally, nmap can be well adjusted according to network characteristics during runtime. During scanning, nmap will minimize the chances of being detected by the target and speed up scanning as much as possible. However, nmap's default timing policy is sometimes not suitable for your goals. Use the following options to control nmap scanning timing:
Set nmap's timely policy. Paranoid: in order to avoid IDS detection, the scanning speed is extremely slow. nmap sends a packet every five minutes for all the scans; Sneaky: similar, but the packet sending interval is 15 seconds; polite: does not add too much network load to avoid downtime of the target host, serial each probe, and each probe has a 0.4-second interval; Normal: nmap default option, scan as quickly as possible without network overload or host/port loss; Aggressive: Set a 5-minute timeout limit so that the scanning time for each host cannot exceed 5 minutes, in addition, the waiting time for each detection response should not exceed 1.5 seconds. B> Insane: only suitable for fast networks or you don't care about losing some information. The timeout limit for each host is 75 seconds, wait for only 0.3 seconds for each test. You can also use numbers to replace these modes. For example,-T 0 equals-T Paranoid and-T 5 equals-T Insane.
These timely modes cannot be combined with the following timely options.
-- Host_timeout
Sets the time for scanning a host in milliseconds. By default, there is no timeout limit.
-- Max_rtt_timeout
Sets the wait time for each test, in milliseconds. If the time limit is exceeded, retransmission or timeout occurs. The default value is about 9000 milliseconds.
-- Min_rtt_timeout
When the target host responds quickly, nmap shortens the time-out time for each test. This will increase the scanning speed, but may lose some packets with long response time. With this option, nmap can wait for at least the specified time for each test, in milliseconds.
-- Initial_rtt_timeout
Set the timeout value for the initial test. Generally, this option is only useful when the-P0 option is used to scan hosts with firewall protection. The default value is 6000 milliseconds.
-- Max_parallelism
Set the maximum number of parallel scans. -- Max_parallelism 1 indicates that only one port is scanned at the same time. This option is also valid for other parallel scans, such as ping sweep and RPC scan.
-- Scan_delay
Set the time that nmap must wait between the two probes. This option is mainly used to reduce the network load.
4.4 target setting
Among all nmap parameters, only the target parameter is required. The simplest form is to directly enter a host name or an IP address in the command line. If you want to scan a subnet of an IP address, you can add a/mask to the host name or IP address. The mask ranges from 0 (scanning the entire network) to 32 (only scanning this host ). Use/24 to scan for Class C addresses and/16 to scan for Class B addresses.
In addition, nmap provides a more powerful representation that allows you to specify IP addresses more flexibly. For example, if you want to scan the Class B network 128. 210. *. * You can use the following three methods to specify these addresses: 128. 210. *. * 128.21 -. 0-00000-255 or are equivalent.
5. Example
This section provides an example of how to use nmap.
Nmap-v target.example.com
Scan all TCP ports of the host target.example.com. -V enables the redundancy mode.
Nmap-sS-O target.example.com/24
Initiates a secret SYN scan for all 255 IP addresses on the network where target.example.com is located. It also detects the fingerprint features of the operating system of each host. Root permission is required.
Nmap-sX-p 110,143,456, 128 4 210. 127. *. 1-
Launch a Christmas tree scan for the first half of the 128.210 possible 8-bit subnet in Class B IP address 255. Check whether ports sshd, DNS, pop3d, imapd, and 4564 are enabled for these systems. Note that the Christmas tree scan is invalid for the Micro $ oft system because the TCP layer of its Protocol Stack has a defect.
Nmap-v -- randomize_hosts-p 80 *. *. 2.3-5
Scan only the specified IP address range. Sometimes it is used for sampling and analysis on this Internet. Nmap will look for the WEB servers on the Internet with the IP addresses of. 2.3,. 2.4, and. 2.5 in the last two bytes. If you want to find more interesting hosts, you can use 127-222, because the interesting host density in this range is greater.
Host-l company.com | cut-d-f 4 |./nmap-v-iL-
Lists All hosts in the company.com network and enables nmap to scan. Note: This command is used in GNU/Linux. If you are on another platform, you may need to use other commands/options.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.