Nmap是一个非常强大的工具,今天我们来看一下这30个常用的例子:
Nmap is short for Network Mapper. It is an open source security tool for network exploration, security scanning and auditing. However, nmap command comes with lots of options that can make the utility more robust and difficult to follow for new users.
Nmap是Network Mapper的缩写,他是一个开源的网络检测,扫描,审计工具,然而,nmap有非常多的选项,这让nmap非常的功能强大和健壮,当然这也给新用户造成了一定的困难
这篇文章的目的是介绍如何使用nmap来扫描一个主机或者网络,以发现可能被攻击的地方。你将从本文章中学会如何使用Nmap,无论是用于攻击或者防御
More about nmap
Nmap的更多信息:
From the man page:
从Nmap的说明文档中我们得到:
Nmap (“Network Mapper”) 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.
Nmap(“Network Mapper”)是一个开源的,用来检测网络和审计安全的。它被设计为快速扫描比较大的网络,当然,它在扫描单台主机上表现的也非常号。Nmap使用原始的IP包通过一个中新颖的方式来判断主机是否存活在指定网络,这些主机提供了那些服务及具体服务的版本,以及操作系统的版本,防火墙的版本,还有其它一大堆的东西。虽然nmap是用来做安全审计的,但是很多网络管理员发现nmap在网络的日常任务上也非常又用,例如 管理服务的升级规划,监控主机和服务的启动时间等。
It was originally written by Gordon Lyon and it can answer the following questions easily:
这个是Gordon Lyon写的,这些内容可以很容易的回答如下的问题:
- What computers did you find running on the local network? 本地局域网中的计算器?
- What IP addresses did you find running on the local network?本地局域网中使用的IP?
- What is the operating system of your target machine?目标主机使用的操作系统?
- Find out what ports are open on the machine that you just scanned?目标主机对外开放的端口?
- Find out if the system is infected with malware or virus.目标主机是否被病毒感染
- Search for unauthorized servers or network service on your network.查找未被授权的主机或者服务
- Find and remove computers which don’t meet the organization’s minimum level of security.查找那些没有符合最低安全标准的远程主机
Sample setup (LAB)
测试环境撘建
Port scanning may be illegal in some jurisdictions. So setup a lab as follows:、
端口扫描在某些地区是违规的,所以我们按照下图设置我们的实验环境
1 2 3 4 5 6 7 8 9 10 |
+---------+ +---------+ | Network | +--------+ | server1 |-----------+ swtich +---------|server2 | +---------+ | (sw0) | +--------+ +----+----+ | | +---------+----------+ | wks01 Linux/OSX | +--------------------+ |
Where,
- wks01 is your computer either running Linux/OS X or Unix like operating system. It is used for scanning your local network. The nmap command must be installed on this computer.(wks01是你的主机,安装的系统是linux或者Unix系列的开源系统,这台主机用来扫描本地网络,所以Nmap需要在这台机器上安装好)
- server1 can be powered by Linux / Unix / MS-Windows operating systems. This is an unpatched server. Feel free to install a few services such as a web-server, file server and so on.(server1是目标主机,没有任何的防御开放,你可以随便安装及个服务,例如httpd或者文件服务)
- server2 can be powered by Linux / Unix / MS-Windows operating systems. This is a fully patched server with firewall. Again, feel free to install few services such as a web-server, file server and so on.(server2目标主机2,被防火墙保护,和server1一样,随意安装及个服务)
- All three systems are connected via switch.(所有的机器通过交换器链接)
How do I install nmap?
如何安装Nmap?
See:
具体根据不同版本选择不同大安装方式:
- Debian / Ubuntu Linux: Install nmap Software For Scanning Network
- CentOS / RHEL: Install nmap Network Security Scanner
- OpenBSD: Install nmap Network Security Scanner
#1: Scan a single host or an IP address (IPv4)
#1:扫描一个单独的主机或者一个单独的IP地址(IPv4)
|
Sample outputs:
输出如下:
#2: Scan multiple IP address or subnet (IPv4)
#2:扫描多个IP或者一个子网:
1 2 3 |
nmap 192.168.1.1 192.168.1.2 192.168.1.3 ## works with same subnet i.e. 192.168.1.0/24 nmap 192.168.1.1,2,3 |
You can scan a range of IP address too:
你可以扫描一个ip段
1 |
nmap 192.168.1.1-20 |
You can scan a range of IP address using a wildcard:
你可以使用统配符来指定ip
1 |
nmap 192.168.1.* |
Finally, you scan an entire subnet:
你也可以扫描整个子网段
1 |
nmap 192.168.1.0/24 |
#3: Read list of hosts/networks from a file (IPv4)
从一个文件中读取主机列表或者网络列表
The -iL option allows you to read the list of target systems using a text file. This is useful to scan a large number of hosts/networks. Create a text file as follows:
cat > /tmp/test.txt
Sample outputs:
1 2 3 4 5 |
server1.cyberciti.biz 192.168.1.0/24 192.168.1.1/24 10.1.2.3 localhost |
The syntax is:、
具体的命令:
1 |
nmap -iL /tmp/test.txt |
#4: Excluding hosts/networks (IPv4)
#4排除某些主机或者网段(IPv4)
When scanning a large number of hosts/networks you can exclude hosts from a scan:
当我们扫描一个很大的网段的时候,我们可以排除一些主机
1 2 |
nmap 192.168.1.0/24 --exclude 192.168.1.5 nmap 192.168.1.0/24 --exclude 192.168.1.5,192.168.1.254 |
OR exclude list from a file called /tmp/exclude.txt
我们也可以通过一个文件来读取我们需要排除的主机
1 |
nmap -iL /tmp/scanlist.txt --excludefile /tmp/exclude.txt |
#5: Turn on OS and version detection scanning script (IPv4)
#5打开系统版本检测
1 2 3 |
nmap -A 192.168.1.254 nmap -v -A 192.168.1.1 nmap -A -iL /tmp/scanlist.txt |
#6: Find out if a host/network is protected by a firewall
#6确定主机或者网络是否被防火墙保护
1 2 |
nmap -sA 192.168.1.254 nmap -sA server1.cyberciti.biz |
#7: Scan a host when protected by the firewall
#7:扫描一个主机如果这个主机被防火墙保护
1 2 |
nmap -PN 192.168.1.1 nmap -PN server1.cyberciti.biz |
#8: Scan an IPv6 host/address
#8:扫描IPv6主机/地址
The -6 option enable IPv6 scanning. The syntax is:
-6 选项让我们开启了IPv6的扫描
1 2 3 4 |
nmap -6 IPv6-Address-Here nmap -6 server1.cyberciti.biz nmap -6 2607:f0d0:1002:51::4 nmap -v A -6 2607:f0d0:1002:51::4 |
#9: Scan a network and find out which servers and devices are up and running
#9:扫描一个网络并查找所有存活的设备
This is known as host discovery or ping scan:
通过ping来检查
1 |
nmap -sP 192.168.1.0/24 |
Sample outputs:
输出接过:
1 2 3 4 5 6 7 8 |
Host 192.168.1.1 is up (0.00035s latency). MAC Address: BC:AE:C5:C3:16:93 (Unknown) Host 192.168.1.2 is up (0.0038s latency). MAC Address: 74:44:01:40:57:FB (Unknown) Host 192.168.1.5 is up. Host nas03 (192.168.1.12) is up (0.0091s latency). MAC Address: 00:11:32:11:15:FC (Synology Incorporated) Nmap done: 256 IP addresses (4 hosts up) scanned in 2.80 second |
#10: How do I perform a fast scan?
#10:如何进行一个快速的扫描?
1 |
nmap -F 192.168.1.1 |
#11: Display the reason a port is in a particular state
#11:显示端口处于特殊状态的原因(这个有点奇怪,翻译的感觉有点怪)
1 2 |
nmap --reason 192.168.1.1 nmap --reason server1.cyberciti.biz |
#12: Only show open (or possibly open) ports
#12:紧紧显示开启的端口(可能开启的)
1 2 |
nmap --open 192.168.1.1 nmap --open server1.cyberciti.biz |
#13: Show all packets sent and received
显示所有的发送和接受的包
1 2 |
nmap --packet-trace 192.168.1.1 nmap --packet-trace server1.cyberciti.biz |
14#: Show host interfaces and routes
显示主机的接口和路由
This is useful for debugging (ip command or route command or netstat command like output using nmap)
这个用来debug非常有效
1 |
nmap --iflist |
Sample outputs:
|
#15: How do I scan specific ports?
如何扫描特殊端口
|
Sample outputs:
输出结果
|
#16: The fastest way to scan all your devices/computers for open ports ever
最快的方式来扫描所有的设备打开的端口
1 |
nmap -T5 192.168.1.0/24 |
#17: How do I detect remote operating system?
如何检测一个远端操作系统
You can identify a remote host apps and OS using the -O option:
我们可以通过-O这个选项来检测远端操作系统
|
Sample outputs:
输出:
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 |
Starting Nmap 5.00 ( http://nmap.org ) at 2012-11-27 01:29 IST NSE: Loaded 0 scripts for scanning. Initiating ARP Ping Scan at 01:29 Scanning 192.168.1.1 [1 port] Completed ARP Ping Scan at 01:29, 0.01s elapsed (1 total hosts) Initiating Parallel DNS resolution of 1 host. at 01:29 Completed Parallel DNS resolution of 1 host. at 01:29, 0.22s elapsed Initiating SYN Stealth Scan at 01:29 Scanning 192.168.1.1 [1000 ports] Discovered open port 80/tcp on 192.168.1.1 Discovered open port 22/tcp on 192.168.1.1 Completed SYN Stealth Scan at 01:29, 0.16s elapsed (1000 total ports) Initiating OS detection (try #1) against 192.168.1.1 Retrying OS detection (try #2) against 192.168.1.1 Retrying OS detection (try #3) against 192.168.1.1 Retrying OS detection (try #4) against 192.168.1.1 Retrying OS detection (try #5) against 192.168.1.1 Host 192.168.1.1 is up (0.00049s latency). Interesting ports on 192.168.1.1: Not shown: 998 closed ports PORT STATE SERVICE 22/tcp open ssh 80/tcp open http MAC Address: BC:AE:C5:C3:16:93 (Unknown) Device type: WAP|general purpose|router|printer|broadband router Running (JUST GUESSING) : Linksys Linux 2.4.X (95%), Linux 2.4.X|2.6.X (94%), MikroTik RouterOS 3.X (92%), Lexmark embedded (90%), Enterasys embedded (89%), D-Link Linux 2.4.X (89%), Netgear Linux 2.4.X (89%) Aggressive OS guesses: OpenWrt White Russian 0.9 (Linux 2.4.30) (95%), OpenWrt 0.9 - 7.09 (Linux 2.4.30 - 2.4.34) (94%), OpenWrt Kamikaze 7.09 (Linux 2.6.22) (94%), Linux 2.4.21 - 2.4.31 (likely embedded) (92%), Linux 2.6.15 - 2.6.23 (embedded) (92%), Linux 2.6.15 - 2.6.24 (92%), MikroTik RouterOS 3.0beta5 (92%), MikroTik RouterOS 3.17 (92%), Linux 2.6.24 (91%), Linux 2.6.22 (90%) No exact OS matches for host (If you know what OS is running on it, see http://nmap.org/submit/ ). TCP/IP fingerprint: OS:SCAN(V=5.00%D=11/27%OT=22%CT=1%CU=30609%PV=Y%DS=1%G=Y%M=BCAEC5%TM=50B3CA OS:4B%P=x86_64-unknown-linux-gnu)SEQ(SP=C8%GCD=1%ISR=CB%TI=Z%CI=Z%II=I%TS=7 OS:)OPS(O1=M2300ST11NW2%O2=M2300ST11NW2%O3=M2300NNT11NW2%O4=M2300ST11NW2%O5 OS:=M2300ST11NW2%O6=M2300ST11)WIN(W1=45E8%W2=45E8%W3=45E8%W4=45E8%W5=45E8%W OS:6=45E8)ECN(R=Y%DF=Y%T=40%W=4600%O=M2300NNSNW2%CC=N%Q=)T1(R=Y%DF=Y%T=40%S OS:=O%A=S+%F=AS%RD=0%Q=)T2(R=N)T3(R=N)T4(R=Y%DF=Y%T=40%W=0%S=A%A=Z%F=R%O=%R OS:D=0%Q=)T5(R=Y%DF=Y%T=40%W=0%S=Z%A=S+%F=AR%O=%RD=0%Q=)T6(R=Y%DF=Y%T=40%W= OS:0%S=A%A=Z%F=R%O=%RD=0%Q=)T7(R=N)U1(R=Y%DF=N%T=40%IPL=164%UN=0%RIPL=G%RID OS:=G%RIPCK=G%RUCK=G%RUD=G)IE(R=Y%DFI=N%T=40%CD=S) Uptime guess: 12.990 days (since Wed Nov 14 01:44:40 2012) Network Distance: 1 hop TCP Sequence Prediction: Difficulty=200 (Good luck!) IP ID Sequence Generation: All zeros Read data files from: /usr/share/nmap OS detection performed. Please report any incorrect results at http://nmap.org/submit/ . Nmap done: 1 IP address (1 host up) scanned in 12.38 seconds Raw packets sent: 1126 (53.832KB) | Rcvd: 1066 (46.100KB) |
See also: Fingerprinting a web-server and a dns server command line tools for more information.
#18: How do I detect remote services (server / daemon) version numbers?
如何检测服务的版本号:
1 |
nmap -sV 192.168.1.1 |
Sample outputs:
1 2 3 4 5 6 7 |
Starting Nmap 5.00 ( http://nmap.org ) at 2012-11-27 01:34 IST Interesting ports on 192.168.1.1: Not shown: 998 closed ports PORT STATE SERVICE VERSION 22/tcp open ssh <strong>Dropbear sshd 0.52 (protocol 2.0)</strong> 80/tcp open http? 1 service unrecognized despite returning data. |
#19: Scan a host using TCP ACK (PA) and TCP Syn (PS) ping
通过TCP ACK 和 TCP syn来扫描一个主机
If firewall is blocking standard ICMP pings, try the following host discovery methods:
如果防火墙屏蔽了ICMP ping,我们可以通过下面的方法来发现主机
1 2 3 4 |
nmap -PS 192.168.1.1 nmap -PS 80,21,443 192.168.1.1 nmap -PA 192.168.1.1 nmap -PA 80,21,200-512 192.168.1.1 |
#20: Scan a host using IP protocol ping
通过IP协议ping来扫墓一个主机
1 |
nmap -PO 192.168.1.1 |
#21: Scan a host using UDP ping
通过UDP ping来扫描一个主机
This scan bypasses firewalls and filters that only screen TCP:
1 2 |
nmap -PU 192.168.1.1 nmap -PU 2000.2001 192.168.1.1 |
#22: Find out the most commonly used TCP ports using TCP SYN Scan
通过TCP syn 来查找最常用的TCP端口
|
#23: Scan a host for UDP services (UDP scan)
扫描一个主机的UDP服务(UDP scan)
Most popular services on the Internet run over the TCP protocol. DNS, SNMP, and DHCP are three of the most common UDP services. Use the following syntax to find out UDP services:
最流行的互联网服务都是通过TCP协议,DNS,SNMP,DHCP是三个最常见的UDP服务,通过下面的命令查找UDP服务:
1 2 |
nmap -sU nas03 nmap -sU 192.168.1.1 |
Sample outputs:
|
#24: Scan for IP protocol
扫描IP协议
This type of scan allows you to determine which IP protocols (TCP, ICMP, IGMP, etc.) are supported by target machines:
如下的命令让你可以知道目标主机支持的协议(TCP,ICMP,IGMP)
1 |
nmap -sO 192.168.1.1 |
#25: Scan a firewall for security weakness
查找防火墙的安全漏洞
The following scan types exploit a subtle loophole in the TCP and good for testing security of common attacks:
如下的命令使用了一个Tcp微秒的漏洞来检测安全登记通过这种普通攻击
|
See how to block Xmas packkets, syn-floods and other conman attacks with iptables.
#26: Scan a firewall for packets fragments
The -f option causes the requested scan (including ping scans) to use tiny fragmented IP packets. The idea is to split up the TCP header over
several packets to make it harder for packet filters, intrusion detection systems, and other annoyances to detect what you are doing.
1 2 3 4 5 |
nmap -f 192.168.1.1 nmap -f fw2.nixcraft.net.in nmap -f 15 fw2.nixcraft.net.in ## Set your own offset size with the --mtu option ## nmap --mtu 32 192.168.1.1 |
#27: Cloak a scan with decoys
The -D option it appear to the remote host that the host(s) you specify as decoys are scanning the target network too. Thus their IDS might report 5-10 port scans from unique IP addresses, but they won’t know which IP was scanning them and which were innocent decoys:
1 2 |
nmap -n -Ddecoy-ip1,decoy-ip2,your-own-ip,decoy-ip3,decoy-ip4 remote-host-ip nmap -n -D192.168.1.5,10.5.1.2,172.1.2.4,3.4.2.1 192.168.1.5 |
#28: Scan a firewall for MAC address spoofing
|
#29: How do I save output to a text file?
将扫描接过导出到文件中
The syntax is:
1 2 3 |
nmap 192.168.1.1 > output.txt nmap -oN /path/to/filename 192.168.1.1 nmap -oN output.txt 192.168.1.1 |
#30: Not a fan of command line tools?
不喜欢命令行?
试试zenmap
$ sudo apt-get install zenmap
Sample outputs:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
[sudo] password for vivek: Reading package lists... Done Building dependency tree Reading state information... Done The following NEW packages will be installed: zenmap 0 upgraded, 1 newly installed, 0 to remove and 11 not upgraded. Need to get 616 kB of archives. After this operation, 1,827 kB of additional disk space will be used. Get:1 http://debian.osuosl.org/debian/ squeeze/main zenmap amd64 5.00-3 [616 kB] Fetched 616 kB in 3s (199 kB/s) Selecting previously deselected package zenmap. (Reading database ... 281105 files and directories currently installed.) Unpacking zenmap (from .../zenmap_5.00-3_amd64.deb) ... Processing triggers for desktop-file-utils ... Processing triggers for gnome-menus ... Processing triggers for man-db ... Setting up zenmap (5.00-3) ... Processing triggers for python-central ... |
Type the following command to start zenmap:
$ sudo zenmap
Sample outputs
原文地址:http://www.cyberciti.biz/networking/nmap-command-examples-tutorials/
Latest posts by Zhiming Zhang (see all)
- aws eks node 自动化扩展工具 Karpenter - 8月 10, 2022
- ReplicationController and ReplicaSet in Kubernetes - 12月 20, 2021
- public key fingerprint - 5月 27, 2021