禁用 DNS 查找以加速 Nikto 扫描

Kali LinuxBeginner
立即练习

引言

Nikto 是一个流行的开源 Web 服务器扫描器,它针对 Web 服务器进行全面的测试,检查超过 6700 个潜在危险文件/程序,检查超过 1250 个服务器的过时版本,以及超过 270 个服务器的版本特定问题。

默认情况下,Nikto 会对在 Web 服务器内容中找到的 IP 地址执行反向 DNS 查找。虽然这有助于发现相关的托管名称 (hostnames),但它也会显著减慢扫描速度,尤其是在扫描大型网络或无响应目标时。

在本实验 (lab) 中,你将学习如何使用 -nolookup 选项禁用此功能,并比较扫描时间以了解其性能优势。

理解 -nolookup 选项的用途

在此步骤中,你将了解 Nikto 中的 -nolookup 选项。

当 Nikto 扫描 Web 服务器时,它可能会在服务器的配置文件、日志或网页中找到 IP 地址。默认情况下,Nikto 会尝试为每个 IP 地址执行反向 DNS 查找,以找到其关联的托管名称 (hostnames)。此过程可能非常耗时。

-nolookup 选项指示 Nikto 完全跳过此步骤。这可以显著加快扫描速度,但你将错过关于与目标关联的其他托管名称 (hostnames) 的潜在有价值信息。

你可以通过查看 Nikto 的帮助菜单来查看此选项及其他选项。我们现在就来做这件事。

在你的终端中执行以下命令:

nikto -Help

滚动输出并找到 -nolookup 选项。它将附带简短描述列出。

...
-nolookup           Skip name lookups
...

现在你已经了解了 -nolookup 的作用,我们可以继续实际操作来查看它。

使用 IP 地址对目标运行基线扫描

在此步骤中,你将对本地 Web 服务器执行标准的 Nikto 扫描。我们将使用 time 命令来衡量扫描所需的时间。这将作为我们进行比较的基线。

实验 (lab) 环境已启动一个简单的 Nginx Web 服务器,运行在 127.0.0.1 上。我们将以此作为我们的目标。

要运行扫描并计时,请执行以下命令:

time nikto -h 127.0.0.1

扫描将开始,你将看到类似以下的输出。请耐心等待,因为它可能需要一分钟才能完成。

- Nikto v2.5.0
---------------------------------------------------------------------------
+ Target IP:          127.0.0.1
+ Target Hostname:    localhost
+ Target Port:        80
+ Start Time:         ...
---------------------------------------------------------------------------
+ Server: nginx/1.18.0 (Ubuntu)
+ The anti-clickjacking X-Frame-Options header is not present.
+ The X-XSS-Protection header is not defined. This header can hint to the user agent to protect against some forms of XSS
+ The X-Content-Type-Options header is not set. This could allow the user agent to render the content of the site in a different fashion to the MIME type
+ No CGI directories found (use '-C all' to force check all possible dirs)
+ Retrieved x-powered-by header: PHP/8.1.2
+ Allowed HTTP Methods: GET, HEAD
+ Public HTTP Methods: GET, HEAD
+ OSVDB-3233: /index.html: Server may leak inodes via ETags, header found with file /var/www/html/index.html inode 262204, size 612, mtime ...
+ 7554 requests: 0 error(s) and 7 item(s) reported on remote host
+ End Time:           ... (15 seconds)
---------------------------------------------------------------------------
+ 1 host(s) tested

real    0m15.543s
user    0m14.987s
sys     0m0.312s

请密切关注最后三行,这是 time 命令的输出。real 时间是经过的总挂钟时间。请记下这个值,以便在下一步使用。

再次运行相同的扫描,并添加 -nolookup 标志

现在你已经有了基线执行时间,让我们运行完全相同的扫描,但添加 -nolookup 标志。这将阻止 Nikto 执行任何反向 DNS 查找。

在你的终端中执行以下命令:

time nikto -h 127.0.0.1 -nolookup

扫描将再次运行。Nikto 的输出本身将与之前的扫描非常相似,但你应该会注意到 time 命令报告的执行时间有所不同。

- Nikto v2.5.0
---------------------------------------------------------------------------
+ Target IP:          127.0.0.1
+ Target Hostname:    127.0.0.1
+ Target Port:        80
+ Start Time:         ...
---------------------------------------------------------------------------
+ Server: nginx/1.18.0 (Ubuntu)
+ The anti-clickjacking X-Frame-Options header is not present.
+ The X-XSS-Protection header is not defined. This header can hint to the user agent to protect against some forms of XSS
+ The X-Content-Type-Options header is not set. This could allow the user agent to render the content of the site in a different fashion to the MIME type
+ No CGI directories found (use '-C all' to force check all possible dirs)
+ Retrieved x-powered-by header: PHP/8.1.2
+ Allowed HTTP Methods: GET, HEAD
+ Public HTTP Methods: GET, HEAD
+ OSVDB-3233: /index.html: Server may leak inodes via ETags, header found with file /var/www/html/index.html inode 262204, size 612, mtime ...
+ 7554 requests: 0 error(s) and 7 item(s) reported on remote host
+ End Time:           ... (8 seconds)
---------------------------------------------------------------------------
+ 1 host(s) tested

real    0m8.123s
user    0m7.890s
sys     0m0.201s

请注意,输出中的 Target Hostname 现在是 127.0.0.1 而不是 localhost。这是因为 Nikto 没有执行反向查找来将 IP 解析为主机名。此外,请记下新的 real 时间。

比较两次扫描的执行时间

在此步骤中,你将分析前两个步骤的结果,以了解 -nolookup 标志对性能的影响。

让我们看一下两次命令的 real 时间。

扫描 1 (基线):
real 0m15.543s (你的时间可能会略有不同)

扫描 2 (带 -nolookup):
real 0m8.123s (你的时间可能会略有不同)

正如你所见,带有 -nolookup 标志的扫描完成得更快。在此示例中,速度几乎快了一倍。当扫描多个主机或在网络缓慢或配置错误的网络上扫描目标时,性能提升可能更为显著,因为 DNS 查找可能会超时。

这个简单的比较展示了在 Nikto 扫描中禁用 DNS 查找所带来的直接性能优势。

分析何时使用此性能优化

在最后一步,我们将讨论权衡,并确定何时适合使用 -nolookup 选项。

虽然 -nolookup 提供了明显的性能提升,但它也可能导致信息丢失。反向 DNS 查找可以帮助你发现与 IP 地址关联的其他主机名和虚拟主机,这对于全面的安全评估至关重要。

那么,你何时应该使用 -nolookup 呢?

  • 初始扫描和分类 (Initial Scans & Triage): 当你扫描大量主机并希望快速了解潜在漏洞时。在此阶段,速度比详尽的细节更重要。
  • 按 IP 地址扫描 (Scanning by IP Address): 如果你的目标列表仅包含 IP 地址,并且你不关心发现关联的域名,那么使用 -nolookup 是一个合乎逻辑的选择。
  • 不可靠的网络 (Unreliable Networks): 当在缓慢或不可靠的网络连接上扫描时,DNS 查询可能会失败或超时,使用 -nolookup 可以防止扫描停滞。
  • 速度至关重要时 (When Speed is Critical): 在时间紧迫的情况下,例如渗透测试竞赛或快速事件响应,此选项带来的速度提升可能非常宝贵。

你何时应该避免使用 -nolookup 呢?

  • 全面评估 (Comprehensive Assessment): 当对特定目标进行全面、深入的安全审计时,你希望获取尽可能多的信息。通过 DNS 查找发现的主机名可能会暴露额外的攻击面。
  • 虚拟主机发现 (Virtual Host Discovery): 如果你怀疑目标 IP 主机托管了多个网站(虚拟主机),你应该允许 Nikto 执行查找以帮助识别它们。

理解速度和详尽性之间的权衡,可以让你针对不同场景更有效地使用 Nikto。

总结

在此实验中,你学习了如何优化 Nikto 扫描的速度。你首先了解了 -nolookup 标志的作用,该标志会禁用反向 DNS 查找。

然后,你执行了两次扫描:一次基线扫描和一次使用 -nolookup 选项的第二次扫描。通过使用 time 命令比较执行时间,你观察到了显著的性能提升。

最后,你分析了权衡,得出结论:-nolookup 非常适合快速、大规模的扫描或速度优先的场景,而全面的评估扫描则应省略此标志,以尽可能多地收集信息。