端口扫描神器 - Nmap的基本使用

搜索公众号:白帽子左一,领配套练手靶场,全套安全课程及工具 

一、Nmap简介

Nmap是一款网络扫描和主机检测的非常有用的工具。

可以用于收集信息和枚举,同时可以用来作为一个漏洞探测器或安全扫描器。

主要功能有:

检测活在网络上的主机(主机发现)

检测主机上开放的端口(端口发现或枚举)

检测到相应的端口(服务发现)的软件和版本

检测操作系统,硬件地址,以及软件版本

检测脆弱性的漏洞(Nmap的脚本)

下载地址:https://nmap.org/download.html

(也可文末扫码找助教领取安装包)

环境:Windows、Linux、Mac OS

二、常用命令

-A:综合性扫描



-T4:指定扫描过程使用的时序,总有6个级别(0-5),级别越高,扫描速度越快,但也容易被防火墙或IDS检测并屏蔽掉,在网络通讯状况较好的情况下推荐使用T4



-O : 指定Nmap进行系统版本扫描



-sV: 指定让Nmap进行服务版本扫描



-p <port ranges>: 扫描指定的端口



-script <script name> : 指定扫描脚本



-Pn :不进行ping扫描

-iL 1.txt : 批量扫描1.txt中的目标地址

-PO : 使用IP协议包探测对方主机是6否开启

-PE/PP/PM : 使用ICMP echo、 ICMP timestamp、ICMP netmask 请求包发现主机



-PS/PA/PU/PY : 使用TCP SYN/TCP ACK或SCTP INIT/ECHO方式进行发现



-e eth0:指定使用eth0网卡进行探测



-f : —mtu <val>: 指定使用分片、指定数据包的 MTU.



-b <FTP relay host>: 使用FTP bounce scan扫描方式



-g:指定发送的端口号



-r: 不进行端口随机打乱的操作(如无该参数,nmap会将要扫描的端口以随机顺序方式扫描,以让nmap的扫描不易被对方防火墙检测到)

-v 表示显示冗余信息,在扫描过程中显示扫描的细节,从而让用户了解当前的扫描状态



-n : 表示不进行DNS解析;



-D <decoy1,decoy2[,ME],...>: 用一组 IP 地址掩盖真实地址,其中 ME 填入自己的 IP 地址



-R :表示总是进行DNS解析。



-F : 快速模式,仅扫描TOP 100的端口



-S <IP_Address>: 伪装成其他 IP 地址



—ttl <val>: 设置 time-to-live 时间



—badsum: 使用错误的 checksum 来发送数据包(正常情况下,该类数据包被抛弃,如果收到回复,说明回复来自防火墙或 IDS/IPS)



—dns-servers : 指定DNS服务器



—system-dns : 指定使用系统的DNS服务器



—traceroute : 追踪每个路由节点



—scanflags <flags>: 定制TCP包的flags



—top-ports <number> :扫描开放概率最高的number个端口



—port-ratio <ratio>: 扫描指定频率以上的端口。与上述—top-ports类似,这里以概率作为参数



—version-trace: 显示出详细的版本侦测过程信息



—osscan-limit: 限制Nmap只对确定的主机的进行OS探测(至少需确知该主机分别有一个open和closed的端口)



—osscan-guess: 大胆猜测对方的主机的系统类型。由此准确性会下降不少,但会尽可能多为用户提供潜在的操作系统



—data-length <num>: 填充随机数据让数据包长度达到 Num



—ip-options <options>: 使用指定的 IP 选项来发送数据包

—spoof-mac <mac address/prefix/vendor name> : 伪装 MAC 地址



—version-intensity <level>: 指定版本侦测强度(0-9),默认为7。



数值越高,探测出的服务越准确,但是运行时间会比较长。



—version-light: 指定使用轻量侦测方式 (intensity 2)



—version-all: 尝试使用所有的probes进行侦测 (intensity 9)



—version-trace: 显示出详细的版本侦测过程信息

三、常用扫描类型

-sn: 只进行主机发现,不进行端口扫描



-sL: List Scan 列表扫描,仅将指定的目标的IP列举出来,不进行主机发现



-sY/sZ: 使用SCTP INIT/COOKIE-ECHO来扫描SCTP协议端口的开放的情况



-sO: 使用IP protocol 扫描确定目标机支持的协议类型



-sN/sF/sX: 指定使用TCP Null, FIN, and Xmas scans秘密扫描方式来协助探测对方的TCP端口状态



-sS/sT/sA/sW/sM:指定使用 TCP SYN/Connect()/ACK/Window/Maimon scans的方式来对目标主机进行扫描



-sU: 指定使用UDP扫描方式确定目标主机的UDP端口状况



-sP: Ping扫描 快速发现网络



-sR:PRC扫描 定位PRC,对成功扫描的机器记录



-sI: 闲置扫描 僵尸主机扫描,非常隐蔽

基本扫描

我们先尝试扫描一下社区,只进行简单的扫描,确定社区开放了哪些端口,使用-A进行扫描

nmap -A bbs.zkaq.cn

图片

可以发现,社区开放了TCP的80端口,以及443端口。

隐蔽扫描

网络扫描的过程包括发送特殊够早的数据包给目标主机和对返回的结果进行基于某种标准的检查。从扫描结果中,我们可以知道那些主机在线,运行了哪些服务以及这些服务的版本信息等。

在一个安全的网络中,我们有可能根据需要来对抗IDS的异常行为捕捉。发送数据包的数量和速度,流量是否异常等,防火墙一般都会标记。为减少被检测到的概率,我们可以采取一些措施控制时间。

nmap控制扫描时间选项:

-T(0~5):控制扫描进度,避免被检测的最简单形式。0是最温和的,5是最激进的,只能在局域网中使用。

–max_hostgroup:将扫描的主机数量限制在每次一个。

–max_retries:一般不需要修改此选项,如果是紧急情况且不在意扫描过程中可能错过一个包含潜在漏洞的主机,可以将这个选项设为0.

max_parallelism 10:一次仅允许10个探测请求。

scan_delay 两次探测之间停顿。

SYN扫描

使用-sS选项对我们的社区发起一个完全开发的扫描。

结果如下:

图片

从结果来看,社区仍然只开放两个端口,我们实战时要确保使用不同类型的扫描对目标网络扫描,否则可能错失一些重要信息。

NULL扫描

使用NULL扫描,对社区进行扫描,再来看看结果:
图片

很遗憾,没有得到有效信息,我们可以猜测社区应该是安装了防火墙。

ACK扫描

在有防火墙的情况下,如果没从NULL扫描获取到什么信息的话,现在进行ACK扫描
图片

很遗憾,仍然没有扫描到什么有效信息。看来社区防护还是做得很不错。(社区邀请码文末扫码领)

空闲扫描

为了降低被检测到的机率,我们通常需要转嫁责任,这时可以使用空闲扫描(idle scan),让一个僵尸主机承担扫描任务。

nmap.org官网上详细讲述了空闲扫描的原理,

可以在http://nmap.org/book/idlescan.html 了解空闲扫描的所有信息。

使用空闲扫描(-sI)需要注意一个问题,就是要找一台TCP序列预测成功率高的僵尸主机,这个僵尸主机必须尽可能的空闲,比如说网络打印机就是一个很好地选择,因为网络打印机不仅存在着恒定的网络资源,而且很难预测它们的TCP序列。

空闲扫描的原理:

向僵尸主机放松SYN/ACK数据包,获得带有分片ID(IPID)的RST报文。

发送使用僵尸主机IP地址的伪数据包给目标主机。

如果目标主机端口关闭,就会向僵尸主机响应RST报文。如果目标端口开放,目标主机向僵尸主机响应SYN/ACK报文,僵尸主机发现这个非法连接响应,并向目标主机发送RST报文,此时IPID号开始增长。

通过向僵尸主机发送另一个SYN/ACK报文已退出上述循环并检查将是主机RST报文中的IPID是否每次增长2,同时目标主机的RST每次增长1。

重复上述步骤直到检测完所有的端口。

寻找僵尸主机

空闲扫描的第一步就是寻找僵尸主机

我们可以通过下面这条命令(-v 详细信息,-O 系统检测,-Pn 无ping,-n 无域名解析)来获得主机的TCP序列预测率。

·# nmap -v -O -Pn -n .***.***.

idle扫描应用

使用以下命令扫描,并启动wireshark抓包。

··# nmap -p 22,23,53,80,443,8888,3960 -Pn -sI ***.***.***.***(僵尸主机IP)
***.***.***.***(目标主机IP)

使用-p启动已知TCP端口的扫描,节省时间;

通过-Pn强调不适用ping(默认是使用的),-sI启动空闲扫描,后面依次是僵尸主机和目标主机的ip地址。

四、常用命令组合

扫描一个小范围

nmap 192.168.230.120-128

root@kali:~# nmap 192.168.230.120-128
Starting Nmap 7.80 ( https://nmap.org ) at 2021-08-26 15:33 CST
Nmap scan report for 192.168.230.128
Host is up (0.0019s latency).
Not shown: 988 closed ports
PORT      STATE SERVICE
80/tcp    open  http
135/tcp   open  msrpc
139/tcp   open  netbios-ssn
445/tcp   open  microsoft-ds
3306/tcp  open  mysql
3389/tcp  open  ms-wbt-server
49152/tcp open  unknown
49153/tcp open  unknown
49154/tcp open  unknown
49155/tcp open  unknown
49156/tcp open  unknown
49157/tcp open  unknown
MAC Address: 00:0C:29:6C:5A:C6 (VMware)

Nmap done: 9 IP addresses (1 host up) scanned in 1.77 seconds

这里扫描到了我的另一台虚拟机 192.168.230.128

初步扫描端口信息

我们扫描一下这个虚拟机的 80,443,3306,3389,6379端口

nmap -T4 -A -v -Pn 192.168.230.128 -p 80,443,3306,3389,6379

root@kali:~# nmap -T4 -A -v -Pn 192.168.230.128 -p 80,443,3306,3389,6379
Starting Nmap 7.80 ( https://nmap.org ) at 2021-08-26 15:43 CST
NSE: Loaded 151 scripts for scanning.
NSE: Script Pre-scanning.
Initiating NSE at 15:43
Completed NSE at 15:43, 0.00s elapsed
Initiating NSE at 15:43
Completed NSE at 15:43, 0.00s elapsed
Initiating NSE at 15:43
Completed NSE at 15:43, 0.00s elapsed
Initiating ARP Ping Scan at 15:43
Scanning 192.168.230.128 [1 port]
Completed ARP Ping Scan at 15:43, 0.00s elapsed (1 total hosts)
Initiating Parallel DNS resolution of 1 host. at 15:43
Completed Parallel DNS resolution of 1 host. at 15:43, 0.00s elapsed
Initiating SYN Stealth Scan at 15:43
Scanning 192.168.230.128 [5 ports]
Discovered open port 3306/tcp on 192.168.230.128
Discovered open port 3389/tcp on 192.168.230.128
Discovered open port 80/tcp on 192.168.230.128
Completed SYN Stealth Scan at 15:43, 1.10s elapsed (5 total ports)
Initiating Service scan at 15:43
Scanning 3 services on 192.168.230.128
Completed Service scan at 15:43, 6.01s elapsed (3 services on 1 host)
Initiating OS detection (try #1) against 192.168.230.128
NSE: Script scanning 192.168.230.128.
Initiating NSE at 15:43
Completed NSE at 15:43, 5.02s elapsed
Initiating NSE at 15:43
Completed NSE at 15:43, 0.03s elapsed
Initiating NSE at 15:43
Completed NSE at 15:43, 0.00s elapsed
Nmap scan report for 192.168.230.128
Host is up (0.00029s latency).

PORT     STATE  SERVICE    VERSION
80/tcp   open   http       Apache httpd 2.4.23 ((Win32) OpenSSL/1.0.2j PHP/5.2.17)
| http-methods: 
|   Supported Methods: GET HEAD POST OPTIONS TRACE
|_  Potentially risky methods: TRACE
|_http-server-header: Apache/2.4.23 (Win32) OpenSSL/1.0.2j PHP/5.2.17
|_http-title: Index of /
443/tcp  closed https
3306/tcp open   mysql      MySQL (unauthorized)
3389/tcp open   tcpwrapped
6379/tcp closed redis
MAC Address: 00:0C:29:6C:5A:C6 (VMware)
Device type: general purpose
Running: Microsoft Windows 7|2008|8.1
OS CPE: cpe:/o:microsoft:windows_7::- cpe:/o:microsoft:windows_7::sp1 cpe:/o:microsoft:windows_server_2008::sp1 cpe:/o:microsoft:windows_server_2008:r2 cpe:/o:microsoft:windows_8 cpe:/o:microsoft:windows_8.1
OS details: Microsoft Windows 7 SP0 - SP1, Windows Server 2008 SP1, Windows Server 2008 R2, Windows 8, or Windows 8.1 Update 1
Uptime guess: 0.196 days (since Thu Aug 26 11:00:47 2021)
Network Distance: 1 hop
TCP Sequence Prediction: Difficulty=259 (Good luck!)
IP ID Sequence Generation: Incremental

TRACEROUTE
HOP RTT     ADDRESS
1   0.29 ms 192.168.230.128

NSE: Script Post-scanning.
Initiating NSE at 15:43
Completed NSE at 15:43, 0.00s elapsed
Initiating NSE at 15:43
Completed NSE at 15:43, 0.00s elapsed
Initiating NSE at 15:43
Completed NSE at 15:43, 0.00s elapsed
Read data files from: /usr/bin/../share/nmap
OS and Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 13.65 seconds
           Raw packets sent: 26 (1.842KB) | Rcvd: 22 (1.570KB)

从扫描结果来看,该虚拟机80,3306,3389端口开放,443,6379端口关闭

判断常见的漏洞并扫描端口

--script指定常见漏洞 nmap 192.168.230.128 --script=auth,vuln
扫描信息如下:

root@kali:~# nmap 192.168.230.128 --script=auth,vuln
Starting Nmap 7.80 ( https://nmap.org ) at 2021-08-26 15:50 CST                                                                                                    
Nmap scan report for 192.168.230.128                                                                                                                               
Host is up (0.00065s latency).                                                                                                                                     
Not shown: 988 closed ports                                                                                                                                        
PORT      STATE SERVICE                                                                                                                                            
80/tcp    open  http                                                                                                                                               
|_clamav-exec: ERROR: Script execution failed (use -d to debug)                                                                                                    
| http-csrf:                                                                                                                                                       
| Spidering limited to: maxdepth=3; maxpagecount=20; withinhost=192.168.230.128                                                                                    
|   Found the following possible CSRF vulnerabilities:                                                                                                             
|                                                                                                                                                                  
|     Path: http://192.168.230.128:80/2.php                                                                                                                        
|     Form id:                                                                                                                                                     
|_    Form action: 2.php
|_http-dombased-xss: Couldn't find any DOM based XSS.
| http-enum: 
|   /: Root directory w/ directory listing
|_  /uploads/: Potentially interesting folder
| http-slowloris-check: 
|   VULNERABLE:
|   Slowloris DOS attack
|     State: LIKELY VULNERABLE
|     IDs:  CVE:CVE-2007-6750
|       Slowloris tries to keep many connections to the target web server open and hold
|       them open as long as possible.  It accomplishes this by opening connections to
|       the target web server and sending a partial request. By doing so, it starves
|       the http server's resources causing Denial Of Service.
|       
|     Disclosure date: 2009-09-17
|     References:
|       http://ha.ckers.org/slowloris/
|_      https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2007-6750
| http-sql-injection: 
|   Possible sqli for forms:
|     Form at path: /2.php, form's action: 2.php. Fields that might be vulnerable:
|_      username
|_http-stored-xss: Couldn't find any stored XSS vulnerabilities.
|_http-trace: TRACE is enabled
135/tcp   open  msrpc
|_clamav-exec: ERROR: Script execution failed (use -d to debug)
139/tcp   open  netbios-ssn
|_clamav-exec: ERROR: Script execution failed (use -d to debug)
445/tcp   open  microsoft-ds
|_clamav-exec: ERROR: Script execution failed (use -d to debug)
3306/tcp  open  mysql
|_clamav-exec: ERROR: Script execution failed (use -d to debug)
|_mysql-empty-password: Host '192.168.230.129' is not allowed to connect to this MySQL server
|_mysql-vuln-cve2012-2122: ERROR: Script execution failed (use -d to debug)
3389/tcp  open  ms-wbt-server
|_clamav-exec: ERROR: Script execution failed (use -d to debug)
|_sslv2-drown: 
49152/tcp open  unknown
|_clamav-exec: ERROR: Script execution failed (use -d to debug)
49153/tcp open  unknown
|_clamav-exec: ERROR: Script execution failed (use -d to debug)
49154/tcp open  unknown
|_clamav-exec: ERROR: Script execution failed (use -d to debug)
49155/tcp open  unknown
|_clamav-exec: ERROR: Script execution failed (use -d to debug)
49156/tcp open  unknown
|_clamav-exec: ERROR: Script execution failed (use -d to debug)
49157/tcp open  unknown
|_clamav-exec: ERROR: Script execution failed (use -d to debug)
MAC Address: 00:0C:29:6C:5A:C6 (VMware)

Host script results:
|_samba-vuln-cve-2012-1182: NT_STATUS_ACCESS_DENIED
|_smb-vuln-ms10-054: false
|_smb-vuln-ms10-061: NT_STATUS_ACCESS_DENIED
| smb-vuln-ms17-010: 
|   VULNERABLE:
|   Remote Code Execution vulnerability in Microsoft SMBv1 servers (ms17-010)
|     State: VULNERABLE
|     IDs:  CVE:CVE-2017-0143
|     Risk factor: HIGH
|       A critical remote code execution vulnerability exists in Microsoft SMBv1
|        servers (ms17-010).
|           
|     Disclosure date: 2017-03-14
|     References:
|       https://technet.microsoft.com/en-us/library/security/ms17-010.aspx
|       https://blogs.technet.microsoft.com/msrc/2017/05/12/customer-guidance-for-wannacrypt-attacks/
|_      https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2017-0143

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

典型的 nmap 扫描

nmap -A -T4

扫描信息如下:

root@kali:~# nmap -A -T4 192.168.230.128
Starting Nmap 7.80 ( https://nmap.org ) at 2021-08-26 16:07 CST
Nmap scan report for 192.168.230.128
Host is up (0.00099s latency).
Not shown: 988 closed ports
PORT      STATE SERVICE      VERSION
80/tcp    open  http         Apache httpd 2.4.23 ((Win32) OpenSSL/1.0.2j PHP/5.2.17)
| http-methods: 
|_  Potentially risky methods: TRACE
|_http-server-header: Apache/2.4.23 (Win32) OpenSSL/1.0.2j PHP/5.2.17
|_http-title: Index of /
135/tcp   open  msrpc        Microsoft Windows RPC
139/tcp   open  netbios-ssn  Microsoft Windows netbios-ssn
445/tcp   open  microsoft-ds Windows Server 2008 HPC Edition 7601 Service Pack 1 microsoft-ds
3306/tcp  open  mysql        MySQL (unauthorized)
3389/tcp  open  tcpwrapped
|_ssl-date: 2021-08-26T08:08:29+00:00; 0s from scanner time.
49152/tcp open  msrpc        Microsoft Windows RPC
49153/tcp open  msrpc        Microsoft Windows RPC
49154/tcp open  msrpc        Microsoft Windows RPC
49155/tcp open  msrpc        Microsoft Windows RPC
49156/tcp open  msrpc        Microsoft Windows RPC
49157/tcp open  msrpc        Microsoft Windows RPC
MAC Address: 00:0C:29:6C:5A:C6 (VMware)
Device type: general purpose
Running: Microsoft Windows 7|2008|8.1
OS CPE: cpe:/o:microsoft:windows_7::- cpe:/o:microsoft:windows_7::sp1 cpe:/o:microsoft:windows_server_2008::sp1 cpe:/o:microsoft:windows_server_2008:r2 cpe:/o:microsoft:windows_8 cpe:/o:microsoft:windows_8.1
OS details: Microsoft Windows 7 SP0 - SP1, Windows Server 2008 SP1, Windows Server 2008 R2, Windows 8, or Windows 8.1 Update 1
Network Distance: 1 hop
Service Info: OSs: Windows, Windows Server 2008 R2 - 2012; CPE: cpe:/o:microsoft:windows

Host script results:
|_clock-skew: mean: -1h59m59s, deviation: 3h59m59s, median: 0s
|_nbstat: NetBIOS name: WIN-5QVLF6I9FUL, NetBIOS user: <unknown>, NetBIOS MAC: 00:0c:29:6c:5a:c6 (VMware)
| smb-os-discovery: 
|   OS: Windows Server 2008 HPC Edition 7601 Service Pack 1 (Windows Server 2008 HPC Edition 6.1)
|   OS CPE: cpe:/o:microsoft:windows_server_2008::sp1
|   Computer name: WIN-5QVLF6I9FUL
|   NetBIOS computer name: WIN-5QVLF6I9FUL\x00
|   Workgroup: WORKGROUP\x00
|_  System time: 2021-08-26T16:08:14+08:00
| smb-security-mode: 
|   account_used: guest
|   authentication_level: user
|   challenge_response: supported
|_  message_signing: disabled (dangerous, but default)
| smb2-security-mode: 
|   2.02: 
|_    Message signing enabled but not required
| smb2-time: 
|   date: 2021-08-26T08:08:14
|_  start_date: 2021-07-30T07:34:36

TRACEROUTE
HOP RTT     ADDRESS
1   0.99 ms 192.168.230.128

OS and Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 136.80 seconds

nmap 基本使用方法小结

nmap -sT ip_address #TCP contect()端口扫描
nmap -p 1-65535 -T4 -A -v ip#扫描1-65535(基本覆盖所有端口)
nmap -sU ip_address #UDP端口扫描

五、NSE脚本引擎

NSE脚本引擎(Nmap Scripting Engine)是nmap最强大,最灵活的功能之一

允许用户自己编写脚本来执行自动化的操作或者扩展nmap的功能。

nmap的脚本库的路径:/usr/share/nmap/scripts

该目录下的文件都是nse脚本,NSE使用Lua脚本语言,并且默认提供了丰富的脚本库,目前已经包含了14个类别的350多个脚本。

NSE的设计初衷主要考虑以下几个方面

网络发现(Network Discovery)
更加复杂的版本侦测(例如 skype 软件)
漏洞侦测(Vulnerability Detection)
后门侦测(Backdoor Detection)
漏洞利用(Vulnerability Exploitation)

例如:

nmap -script smb-vuln-ms17-010 192.168.230.128 可以探测该主机是否存在ms17_010漏洞

nmap -p 80 —script http-iis-short-name-brute
+ip(192.168.1.1)[验证iis短文件名泄露]

nmap -sV -p 11211 -script memcached-info +ip[验证Memcached未授权访问漏洞]

nmap -sV -(-)script http-vuln-cve2015-1635 +ip[验证http.sys远程代码执行漏洞]

nmap -sV —script=ssl-heartbleed +ip[验证心脏出血漏洞]

nmap -p 27017 —script mongodb-info +ip[验证Mongodb未授权访问漏洞]

nmap —script=http-vuln-cve2015-1427 —script-args command=‘ls’
+ip[验证Elasticsearch未授权访问漏洞]

nmap -p 873 —script rsync-brute —script-args ‘rsync-brute.module=www’
[验证Rsync未授权访问漏洞]

nmap -p 6379 —script redis-info 192.168.230.128 可以探测该主机是否存在Redis未授权访问
这里我给这台虚拟机安装一下Redis环境,用nmap来测试一下 nmap -p 6379 --script redis-info
192.168.230.128

扫描信息如下:

图片

当然nmap能扫描的漏洞还有很多,有兴趣的可以查阅相关文章,比如:

https://blog.csdn.net/jiangliuzheng/article/details/51992220

六、版本侦测用法

比如目标主机把SSH的22号端口改成了2222端口

那么如果使用普通扫描只会发现2222端口是开启的

并不能知道2222号端口上运行的程序

通过加参数 -sV 进行版本扫描,可以探测到目标主机上2222端口运行的是SSH服务

V: 指定让Nmap进行版本侦测

—version-intensity : 指定版本侦测强度(0-9),默认为7。

数值越高,探测出的服务越准确,但是运行时间会比较长。

—version-light: 指定使用轻量侦测方式 (intensity 2)

—version-all: 尝试使用所有的probes进行侦测 (intensity 9)

—version-trace: 显示出详细的版本侦测过程信息

七、OS侦测

操作系统侦测用于检测目标主机运行的操作系统类型及设备类型等信息。

Nmap拥有丰富的系统数据库nmap-os-db,目前可以识别2600多种操作系统与设备类型。

OS侦测原理
Nmap使用TCP/IP协议栈指纹来识别不同的操作系统和设备。

在RFC规范中,有些地方对TCP/IP的实现并没有强制规定,由此不同的TCP/IP方案中可能都有自己的特定方式。Nmap主要是根据这些细节上的差异来判断操作系统的类型的。

操作指令:
Nmap内部包含了2600多已知系统的指纹特征(在文件nmap-os-db文件中)。将此指纹数据库作为进行指纹对比的样本库。

分别挑选一个open和closed的端口,向其发送经过精心设计的TCP/UDP/ICMP数据包,根据返回的数据包生成一份系统指纹。

将探测生成的指纹与nmap-os-db中指纹进行对比,查找匹配的系统。如果无法匹配,以概率形式列举出可能的系统。

OS侦测用法#

-O: 指定Nmap进行OS侦测。

—osscan-limit: 限制Nmap只对确定的主机的进行OS探测(至少需确知该主机分别有一个open和closed的端口)。

—osscan-guess: 大胆猜测对方的主机的系统类型。由此准确性会下降不少,但会尽可能多为用户提供潜在的操作系统

输出格式
-oX XML:XML格式

nmap -A 192.168.230.128 -oX “/1.xml”

图片

-oG 可检索的: 可检索格式

图片

-oA: 所有: 可检索的、常规的和XML文件

nmap -A 192.168.230.128 -oA “/test”

图片

使用该命令会同时生成三个文件指定名称的文件

-oN: 常规: 常规格式,适合人阅读

nmap -A 192.168.230.128 -oN “/1.txt”

图片

在这里插入图片描述
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/hackzkaq/article/details/121422890