nmap 使用详解

Posted on Posted in nmap
Tips: 本文创建于2015年11月11日,已超过 2 年,内容或图片可能已经失效!

nmap 使用详解

sitelogo.png

nmap 官网

  1. 安装
bzip2 -cd nmap-6.49BETA6.tar.bz2 | tar xvf -
cd nmap-6.49BETA6
./configure
make
su root
make install
  1. 使用

1). nmap目标主机

nmap 192.168.2.7
Starting Nmap 6.49BETA6 ( https://nmap.org ) at 2015-10-28 23:30 CST
Warning: File ./nmap-services exists, but Nmap is using /usr/local/bin/../share/nmap/nmap-services for security and consistency reasons.  set NMAPDIR=. to give priority to files in your local directory (may affect the other data files too).
Nmap scan report for 192.168.2.7
Host is up (0.32s latency).
Not shown: 996 closed ports
PORT     STATE SERVICE
21/tcp   open  ftp
22/tcp   open  ssh
53/tcp   open  domain
1723/tcp open  pptp
MAC Address: C8:3A:35:C7:72:F1 (Tenda Technology)
Nmap done: 1 IP address (1 host up) scanned in 3.97 seconds

目标主机192.168.2.7 处于 up 状态,开放了21,22,53,1723端口,最后给出了网卡信息

2). nmap -T4 -A -v 目标主机

-T4是指定扫描过程中使用的时序模板,总共有6个等级,等级越高,扫描速度越快,但也容易被防火墙或者入侵检测设备发现

nmap -T4 -A -v 192.168.2.7
Starting Nmap 5.51 ( http://nmap.org ) at 2015-10-28 21:48 CST
NSE: Loaded 57 scripts for scanning.
Initiating ARP Ping Scan at 21:48
Scanning 192.168.2.7 [1 port]
Completed ARP Ping Scan at 21:48, 0.11s elapsed (1 total hosts)
Initiating Parallel DNS resolution of 1 host. at 21:48
Completed Parallel DNS resolution of 1 host. at 21:48, 0.00s elapsed
Initiating SYN Stealth Scan at 21:48
Scanning 192.168.2.7 [1000 ports]
Discovered open port 22/tcp on 192.168.2.7
Discovered open port 1723/tcp on 192.168.2.7
Discovered open port 53/tcp on 192.168.2.7
Discovered open port 21/tcp on 192.168.2.7
Completed SYN Stealth Scan at 21:48, 3.12s elapsed (1000 total ports)
Initiating Service scan at 21:48
Scanning 4 services on 192.168.2.7
Completed Service scan at 21:48, 6.64s elapsed (4 services on 1 host)
Initiating OS detection (try #1) against 192.168.2.7
Retrying OS detection (try #2) against 192.168.2.7
Retrying OS detection (try #3) against 192.168.2.7
Retrying OS detection (try #4) against 192.168.2.7
Retrying OS detection (try #5) against 192.168.2.7
NSE: Script scanning 192.168.2.7.
Initiating NSE at 21:49
Completed NSE at 21:49, 3.75s elapsed
Nmap scan report for 192.168.2.7
#对主机是否在线进行扫描
Host is up (0.017s latency).
#端口扫描以及应用程序
Not shown: 996 closed ports
PORT     STATE SERVICE VERSION
21/tcp   open  ftp     vsftpd 2.3.5
22/tcp   open  ssh     OpenSSH 6.0p1 Debian 4+deb7u2 (protocol 2.0)
| ssh-hostkey: 1024 8e:f3:3c:eb:07:3b:96:91:ff:29:22:cb:97:91:38:fd (DSA)
|_2048 e0:f8:5e:3e:a0:c1:28:bc:8d:81:3e:79:cf:b9:90:d3 (RSA)
53/tcp   open  domain  dnsmasq 2.62
1723/tcp open  pptp    linux (Firmware: 1)
MAC Address: C8:3A:35:C7:72:F1 (Tenda Technology Co.)
#操作系统版本,没扫出来,哈哈
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.51%D=10/28%OT=21%CT=1%CU=35731%PV=Y%DS=1%DC=D%G=Y%M=C83A35%TM=5
OS:630D25B%P=x86_64-redhat-linux-gnu)SEQ(SP=107%GCD=2%ISR=10D%TI=Z%CI=I%II=
OS:I%TS=7)SEQ(SP=107%GCD=1%ISR=10D%TI=Z%CI=I%II=I%TS=7)SEQ(SP=107%GCD=1%ISR
OS:=10D%TI=Z%CI=I%II=I%TS=5)OPS(O1=M5B4ST11NW7%O2=M5B4ST11NW7%O3=M5B4NNT11N
OS:W7%O4=M5B4ST11NW7%O5=M5B4ST11NW7%O6=M5B4ST11)WIN(W1=7120%W2=7120%W3=7120
OS:%W4=7120%W5=7120%W6=7120)ECN(R=Y%DF=Y%T=40%W=7210%O=M5B4NNSNW7%CC=Y%Q=)T  
OS:1(R=Y%DF=Y%T=40%S=O%A=S+%F=AS%RD=0%Q=)T2(R=N)T3(R=N)T4(R=Y%DF=Y%T=40%W=0
OS:%S=A%A=Z%F=R%O=%RD=0%Q=)T5(R=Y%DF=Y%T=40%W=0%S=Z%A=S+%F=AR%O=%RD=0%Q=)T6
OS:(R=Y%DF=Y%T=40%W=0%S=A%A=Z%F=R%O=%RD=0%Q=)T7(R=Y%DF=Y%T=40%W=0%S=Z%A=S+%
OS:F=AR%O=%RD=0%Q=)U1(R=Y%DF=N%T=40%IPL=164%UN=0%RIPL=G%RID=G%RIPCK=G%RUCK=
OS:G%RUD=G)IE(R=Y%DFI=N%T=40%CD=S)
Uptime guess: 53.983 days (since Fri Sep  4 22:13:33 2015)
Network Distance: 1 hop
TCP Sequence Prediction: Difficulty=263 (Good luck!)
IP ID Sequence Generation: All zeros
Service Info: Host: local; OSs: Unix, Linux
TRACEROUTE
HOP RTT      ADDRESS
1   17.09 ms 192.168.2.7
Read data files from: /usr/share/nmap
OS and Service detection performed. Please report any incorrect results at http://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 26.07 seconds
           Raw packets sent: 1147 (54.550KB) | Rcvd: 1091 (47.158KB)

3). nmap 常用参数

-sn : 只进行主机发现扫描,不进行端口扫描
-Pn : 跳过主机发现扫描,将所有指定的主机都视为在线状态,进行端口扫描
-sL : 仅仅列出指定的目标主机 IP,不进行主机发现扫描
-PS/PA/PU/PU[portlist] : 指定使用 TCP SYN/TCP ACK/ UDP/SCTP方式进行主机发现,例如 nmap -PS80,2
-PE/PP/PM : 指定 nmap 使用 ICMP echo、timestamp、network 请求报文方式发现主机
-PO : 使用 IP 协议包探测目标主机是否在线
-n/-R : 指定是否使用 dns 解析,其中,-n 表示不进行 dns 解析,-R 表示总进行 dns 解析

例如

nmap -sn -PE -PS22,80 -PU53 192.168.2.7
Starting Nmap 5.51 ( http://nmap.org ) at 2015-10-28 22:00 CST
Note: Host seems down. If it is really up, but blocking our ping probes, try -Pn
Nmap done: 1 IP address (0 hosts up) scanned in 0.43 seconds

4). nmap 端口扫描

nmap 扫描端口状态分为6类

  • open : 表示端口是开放的
  • closed : 表示端口是关闭的
  • filtered : 表示端口被防火墙屏蔽,无法进一步确认状态
  • unfiltered : 表示端口没有被屏蔽,但是否处于开放状态,还需要进一步确定
  • open|filtered : 表示不确定状态,端口可能开放可能关闭
  • closed|filtered : 表示不确定状态,端口可能关闭,可能屏蔽

端口扫描的用法

  • -sS/sT/sA/sW/sM : 指定使用 TCP SYN/Connect()/ACK/Window/Maimon scans 来对目标主机进行端口扫描
  • -sU : 指定使用 UDP 扫描方式扫描目标主机的 UDP 端口状况
  • -sN/sF/sX : 指定使用 TCP Null/FIN/Xmas sans 秘密扫描方式来协助侦测目标主机的 TCP 端口状态
  • -p : 仅仅扫描指定的一个或一批端口。例如 -p80/-p1-100/-p T:80-88,8000,U:53,111,S:9,其中 T 表示 TCP 协议,U 表示 UDP 协议,S 表示 SCTP 协议
  • -F : 快速扫描模式,仅仅扫描开放率高的100个端口
  • --top-ports : 仅扫描开放率高的 number 个端口

例子

nmap -sU -sS -F 192.168.2.7
Starting Nmap 5.51 ( http://nmap.org ) at 2015-10-28 22:04 CST
Nmap scan report for 192.168.2.7
Host is up (0.019s latency).
Not shown: 194 closed ports
PORT     STATE         SERVICE
21/tcp   open          ftp
22/tcp   open          ssh
53/tcp   open          domain
1723/tcp open          pptp
53/udp   open|filtered domain
68/udp   open|filtered dhcpc
MAC Address: C8:3A:35:C7:72:F1 (Tenda Technology Co.)
Nmap done: 1 IP address (1 host up) scanned in 107.10 seconds

5). nmap 程序版本侦测

nmap 选项或参数 目标主机

  • -sV : 设置 nmap 进行版本侦测
  • --version-intensity 设置版本侦测的强度值,0-9,默认是7。这个数值越高,探测出的版本越精确,但扫描时间也更长
  • --version-light : 设置使用轻量级的侦测方式,相当于侦测强度为2
  • --version-trace : 显示版本侦测的详细过程

例子


nmap -sV 192.168.2.7
Starting Nmap 5.51 ( http://nmap.org ) at 2015-10-28 22:13 CST
Nmap scan report for 192.168.2.7
Host is up (0.073s latency).
Not shown: 996 closed ports
PORT     STATE SERVICE VERSION
21/tcp   open  ftp     vsftpd 2.3.5
22/tcp   open  ssh     OpenSSH 6.0p1 Debian 4+deb7u2 (protocol 2.0)
53/tcp   open  domain  dnsmasq 2.62
1723/tcp open  pptp    linux (Firmware: 1)
MAC Address: C8:3A:35:C7:72:F1 (Tenda Technology Co.)
Service Info: Host: local; OSs: Unix, Linux
Service detection performed. Please report any incorrect results at http://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 13.26 seconds

6). nmap 操作系统的侦测

nmap 选项或参数

  • -O : 设置 nmap 进行操作系统侦测
  • --osscan-guess : 猜测目标主机的操作系统类型,nmmap 会给出可能性的比率,用户可以根据提供的比率综合判断操作系统类型

例子

nmap -O --osscan-guess 192.168.2.7
Starting Nmap 5.51 ( http://nmap.org ) at 2015-10-28 22:18 CST
Nmap scan report for 192.168.2.7
Host is up (0.0029s latency).
Not shown: 996 closed ports
PORT     STATE SERVICE
21/tcp   open  ftp
22/tcp   open  ssh
53/tcp   open  domain
1723/tcp open  pptp
MAC Address: C8:3A:35:C7:72:F1 (Tenda Technology Co.)
Device type: WAP|general purpose|specialized|firewall|webcam
Running (JUST GUESSING): Netgear embedded (96%), Linux 2.6.X|2.4.X (93%), Crestron 2-Series (91%), Citrix Linux 2.6.X (90%), Check Point embedded (90%), Check Point Linux 2.4.X (90%), Linksys embedded (90%), AXIS Linux 2.6.X (89%)
Aggressive OS guesses: Netgear DG834G WAP (96%), Linux 2.6.32 (93%), Crestron XPanel control system (91%), Linux 2.6.19 - 2.6.35 (91%), Linux 2.4.26 (Slackware 10.0.0) (91%), Linux 2.6.31 - 2.6.34 (91%), Citrix XenServer (Linux 2.6.18) (90%), Linux 2.6.24 (90%), Check Point SBox-200 firewall (90%), Check Point VPN-1 UTM appliance (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.51%D=10/28%OT=21%CT=1%CU=42150%PV=Y%DS=1%DC=D%G=Y%M=C83A35%TM=5
OS:630D948%P=x86_64-redhat-linux-gnu)SEQ(SP=FF%GCD=1%ISR=106%TI=Z%CI=I%II=I
OS:%TS=7)SEQ(SP=FF%GCD=1%ISR=106%TI=Z%CI=I%II=I%TS=6)OPS(O1=M5B4ST11NW7%O2=
OS:M5B4ST11NW7%O3=M5B4NNT11NW7%O4=M5B4ST11NW7%O5=M5B4ST11NW7%O6=M5B4ST11)WI
OS:N(W1=7120%W2=7120%W3=7120%W4=7120%W5=7120%W6=7120)ECN(R=Y%DF=Y%T=40%W=72
OS:10%O=M5B4NNSNW7%CC=Y%Q=)T1(R=Y%DF=Y%T=40%S=O%A=S+%F=AS%RD=0%Q=)T2(R=N)T3
OS:(R=N)T4(R=Y%DF=Y%T=40%W=0%S=A%A=Z%F=R%O=%RD=0%Q=)T5(R=Y%DF=Y%T=40%W=0%S=
OS:Z%A=S+%F=AR%O=%RD=0%Q=)T6(R=Y%DF=Y%T=40%W=0%S=A%A=Z%F=R%O=%RD=0%Q=)T7(R=
OS:Y%DF=Y%T=40%W=0%S=Z%A=S+%F=AR%O=%RD=0%Q=)U1(R=Y%DF=N%T=40%IPL=164%UN=0%R
OS:IPL=G%RID=G%RIPCK=G%RUCK=G%RUD=G)IE(R=Y%DFI=N%T=40%CD=S)
Network Distance: 1 hop
OS detection performed. Please report any incorrect results at http://nmap.org/submit/ .&n
bsp;
Nmap done: 1 IP address (1 host up) scanned in 14.07 seconds

进行ping扫描,打印出对扫描做出响应的主机:

nmap -sP 192.168.1.0/24

仅列出指定网络上的每台主机,不发送任何报文到目标主机:

nmap -sL 192.168.1.0/24
» 转载请注明来源:若我若鱼 » nmap 使用详解

Leave a Reply

Your email address will not be published. Required fields are marked *

20 − 5 =