Nmap
以其著名的端口扫描而广为人知。尽管如此,将 Nmap 只看作是端口扫描器感觉有点大材小用。因为它还可以扫描目标的漏洞。

使用NSE脚本进行Nmap漏洞扫描
CVE
代表Common Vulnerabilities and Exposures
。用简单的英语来说,这只是意味着它是一种组织和分类软件漏洞的方法。这些信息对于安全研究人员和渗透测试人员的日常任务非常有用。
我们真正喜欢该工具的一点是它能够通过使用 Nmap 脚本扩展其核心功能。您可能想知道 Nmap 是否可以找到漏洞。是的,它可以!通过将这些Nmap 命令与一些 NSE 脚本相结合,我们能够从任何目标中获取最流行的 CVE。
在 Nmap NSE
上发现的两个最流行的漏洞/CVE 检测脚本是 nmap-vulners
和 vulscan
,它们将使您能够检测来自远程或本地主机的相关 CVE 信息。
Nmap vulscan
Vulscan查询自己的本地 CVE 数据库,该数据库托管在执行扫描的客户端上。这些本地数据库包括以下文件:scipvuldb
.csv
cve.csv
securityfocus.csv
xforce.csv
explootdb.csv
openvas.csv
securitytracker.csv
osvdb.csv
。
为了使用这个 NSE 脚本,我们需要以与之前几乎相同的方式克隆它的 github 存储库。
安装
以下命令将安装 vulscan 脚本以及所有提到的数据库:
git clone https://github.com/scipag/vulscan scipag_vulscan
ln -s `pwd`/scipag_vulscan /usr/share/nmap/scripts/vulscan
现在让我们使用以下语法使用 vulscan 对漏洞执行 Nmap 扫描:
nmap -sV --script=vulscan/vulscan.nse www.bbskali.com
效果如下
[root@bbskali.cn ~]# nmap -sV --script=vulscan/vulscan.nse 192.168.123.105
Starting Nmap 7.70 ( https://nmap.org ) at 2021-12-29 09:24 -03
Nmap scan report for 192.168.1.105 (192.168.1.105)
Host is up (0.000061s latency).
Not shown: 999 closed ports
PORT STATE SERVICE VERSION
53/tcp open domain dnsmasq 2.80
| vulscan: VulDB - https://vuldb.com:
| [49778] Thekelleys dnsmasq up to 2.32 tftp.c tftp_request memory corruption
| [43410] The Kelleys dnsmasq 2.43 Crash denial of service
| [43287] Thekelleys dnsmasq 2.25 Crash denial of service
| MITRE CVE - https://cve.mitre.org:
| [CVE-2013-0198] Dnsmasq before 2.66test2, when used with certain libvirt configurations, replies to queries from prohibited interfaces, which allows remote attackers to cause a denial of service (traffic amplification) via spoofed TCP based DNS queries. NOTE: this vulnerability exists because of an incomplete fix for CVE-2012-3411.
| [CVE-2012-3411] Dnsmasq before 2.63test1, when used with certain libvirt configurations, replies to requests from prohibited interfaces, which allows remote attackers to cause a denial of service (traffic amplification) via a spoofed DNS query.
| [CVE-2009-2958] The tftp_request function in tftp.c in dnsmasq before 2.50, when --enable-tftp is used, allows remote attackers to cause a denial of service (NULL pointer dereference and daemon crash) via a TFTP read (aka RRQ) request with a malformed blksize option.
| SecurityFocus - https://www.securityfocus.com/bid/:
| [31017] Dnsmasq DCHP Lease Multiple Remote Denial Of Service Vulnerabilities
| [17662] DNSmasq Broadcast Reply Denial Of Service Vulnerability
| [12897] Dnsmasq Multiple Remote Vulnerabilities
Nmap done: 1 IP address (1 host up) scanned in 11.25 seconds
提示:您还可以通过使用 vulscandb
参数来使用您自己的 CVE
本地数据库:
--script-args vulscandb=your_own_database
Nmap-vulners
Nmap-vulners
是最著名的漏洞扫描器之一。让我们探索如何安装此工具,以及如何执行简单的 CVE 扫描。
安装
复制并粘贴以下两行以安装 nmap-vulners:
cd /usr/share/nmap/scripts/
git clone https://github.com/vulnersCom/nmap-vulners.git
测试
我们将使用的语法非常简单,通过使用 –script 并指定漏洞引擎来调用脚本,如下所示:
nmap --script nmap-vulners/ -sV 192.168.123.1
如果要针对特定端口,只需在末尾添加 -p80
,当然,将 192.168.123.1
替换为您想要的 IP
。
使用 Nmap 运行特定的漏洞扫描
查找易受测试的 PHP 版本
现在我们来看 2 个 PHP 脚本。第一个检查正在运行的 PHP 版本(仅响应最高 5.5.0 的版本),第二个检查 PHP-CGI 安装是否容易受到 CVE-2012-1823 的测试。
像这样运行第一个命令:
nmap -sV --script=http-php-version testphp.vulnweb.com
此命令的输出将是:
Starting Nmap 7.80 ( https://nmap.org ) at 2021-12-29 09:37 UTC
Nmap scan report for testphp.vulnweb.com (18.192.172.30)
Host is up (0.34s latency).
rDNS record for 18.192.172.30: ec2-18-192-172-30.eu-central-1.compute.amazonaws.com
Not shown: 999 filtered ports
PORT STATE SERVICE VERSION
80/tcp open http nginx 1.19.0
|_http-php-version: Version from header x-powered-by: PHP/5.6.40-38+ubuntu20.04.1+deb.sury.org+1
Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 47.61 seconds
如上,我们仍然能够获得 PHP > 5.5.0
的版本。
PHP-CGI 是否易受 CVE-2012-1823 测试
nmap -sV --script http-vuln-cve2012-1823 testphp.vulnweb.com
结果输出
Starting Nmap 7.80 ( https://nmap.org ) at 2021-12-29 10:14 UTC
Nmap scan report for testphp.vulnweb.com (18.192.172.30)
Host is up (0.34s latency).
rDNS record for 18.192.172.30: ec2-18-192-172-30.eu-central-1.compute.amazonaws.com
PORT STATE SERVICE
80/tcp open http
Nmap done: 1 IP address (1 host up) scanned in 3.10 seconds