引言
Nikto 是一个流行的开源 Web 服务器扫描器,它对 Web 服务器进行全面的测试,检查超过 6700 个潜在危险文件/程序,检查超过 1250 个服务器的过时版本,以及超过 270 个服务器的版本特定问题。
它的一个关键功能是扫描通用网关接口 (CGI) 目录。如果 CGI 脚本没有得到妥善保护,可能会成为重大漏洞的来源。默认情况下,Nikto 会扫描预定义的常见 CGI 目录列表。然而,为了更高效和有针对性的扫描,了解如何控制这种行为至关重要。
在本实验中,你将学习如何使用 Nikto 的 -Cgidirs 选项来管理 CGI 目录扫描,包括禁用它、扫描所有可能的目录以及指定要测试的自定义目录。
理解 Nikto 的默认 CGI 目录扫描行为
在此步骤中,你将启动一个简单的 Web 服务器并运行一次默认的 Nikto 扫描,以观察其查找 CGI 目录的标准行为。
首先,让我们设置一个简单的 Web 服务器进行扫描。我们将为此使用 Python 内置的 http.server 模块。
导航到我们为你准备的 webroot 目录。
cd ~/project/webroot
现在,在端口 8000 上启动 Web 服务器。命令末尾的 & 会在后台运行服务器,让你能够继续使用终端。
python3 -m http.server 8000 &
你应该会看到一条指示服务器正在运行的消息。
Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ...
服务器运行后,让我们对其执行一次基本的 Nikto 扫描。-h 选项用于指定目标主机。
nikto -h http://localhost:8000
扫描完成后,请查看输出。Nikto 会检查许多内容,但你应该会找到一行指示它发现了 /cgi-bin/ 目录。这是因为 /cgi-bin/ 是 Nikto 默认检查的常见目录之一。
- Nikto v2.x
---------------------------------------------------------------------------
+ Target IP: 127.0.0.1
+ Target Hostname: localhost
+ Target Port: 8000
+ Start Time: ...
---------------------------------------------------------------------------
+ Server: SimpleHTTP/0.6 Python/3.10.6
+ 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)
+ "robots.txt" not found.
+ OSVDB-3233: /: HTTP TRACE method is active, suggesting the host is vulnerable to XST
+ OSVDB-3092: /: This might be interesting...
+ /index.html: This might be interesting...
+ 7 items found on remote host
+ End Time: ...
---------------------------------------------------------------------------
+ 1 host(s) tested
注意:在某些较新的 Nikto 版本或配置中,默认扫描可能不会报告
/cgi-bin/,除非特定的测试触发了它。关键在于理解正在检查一组默认路径。我们将在后续步骤中强制进行这些检查以查看更清晰的结果。
使用 -Cgidirs none 禁用所有 CGI 目录扫描
在此步骤中,你将学习如何完全禁用 CGI 目录扫描。当你想要执行一次快速扫描并专注于其他漏洞,或者当你确定目标服务器不使用 CGI 脚本时,这将非常有用。
-Cgidirs 选项控制 CGI 扫描。通过将其值设置为 none,你指示 Nikto 完全跳过此测试部分。
运行以下命令再次扫描服务器,但这次禁用 CGI 扫描:
nikto -h http://localhost:8000 -Cgidirs none
检查输出。你会发现它与之前的扫描非常相似,但它明确确认 CGI 目录未被扫描。No CGI directories found(未找到 CGI 目录)这一行仍然会存在,但这次是因为我们告诉 Nikto 不要查找它们。这使得扫描速度略有提升。
- Nikto v2.x
---------------------------------------------------------------------------
+ Target IP: 127.0.0.1
+ Target Hostname: localhost
+ Target Port: 8000
+ Start Time: ...
---------------------------------------------------------------------------
+ Server: SimpleHTTP/0.6 Python/3.10.6
+ 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
+ CGI directory scanning has been disabled.
+ "robots.txt" not found.
+ OSVDB-3233: /: HTTP TRACE method is active, suggesting the host is vulnerable to XST
+ OSVDB-3092: /: This might be interesting...
+ /index.html: This might be interesting...
+ 7 items found on remote host
+ End Time: ...
---------------------------------------------------------------------------
+ 1 host(s) tested
注意 + CGI directory scanning has been disabled.(CGI 目录扫描已禁用。)这一行,它证实了我们的命令按预期工作。
使用 -Cgidirs all 扫描所有配置的 CGI 目录
在此步骤中,你将为 -Cgidirs 选项使用 all 值。这会强制 Nikto 通过检查其内部配置中列出的每个目录来执行最全面的 CGI 扫描。这比默认扫描更彻底。
使用 -Cgidirs all 选项运行 Nikto 扫描:
nikto -h http://localhost:8000 -Cgidirs all
现在,仔细检查输出。这次,Nikto 将明确报告 /cgi-bin/ 目录,因为我们的测试服务器拥有它,并且 all 标志确保它被检查。
- Nikto v2.x
---------------------------------------------------------------------------
+ Target IP: 127.0.0.1
+ Target Hostname: localhost
+ Target Port: 8000
+ Start Time: ...
---------------------------------------------------------------------------
+ Server: SimpleHTTP/0.6 Python/3.10.6
+ 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
+ OSVDB-3233: /cgi-bin/: Directory indexing found.
+ OSVDB-3092: /cgi-bin/: This might be interesting...
+ "robots.txt" not found.
+ OSVDB-3233: /: HTTP TRACE method is active, suggesting the host is vulnerable to XST
+ OSVDB-3092: /: This might be interesting...
+ /index.html: This might be interesting...
+ 8 items found on remote host
+ End Time: ...
---------------------------------------------------------------------------
+ 1 host(s) tested
你可以看到两个与 /cgi-bin/ 相关的新发现,这证实了强制扫描是成功的。
指定自定义 CGI 目录路径进行扫描
在此步骤中,你将学习如何扫描特定的、非标准的 CGI 目录。当你评估一个将脚本放置在独特位置的自定义 Web 应用程序时,这会非常有用。
我们的设置包含一个名为 /cgi-custom/ 的目录。默认的 Nikto 扫描不会找到它。我们可以通过将路径传递给 -Cgidirs 选项来指示 Nikto 专门检查它。
运行以下命令仅扫描 /cgi-custom/ 目录:
nikto -h http://localhost:8000 -Cgidirs /cgi-custom/
查看输出。Nikto 现在将报告它已找到 /cgi-custom/。它将 不会 报告 /cgi-bin/,因为我们将扫描限制在我们指定的路径上。
- Nikto v2.x
---------------------------------------------------------------------------
+ Target IP: 127.0.0.1
+ Target Hostname: localhost
+ Target Port: 8000
+ Start Time: ...
---------------------------------------------------------------------------
+ Server: SimpleHTTP/0.6 Python/3.10.6
+ 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
+ OSVDB-3233: /cgi-custom/: Directory indexing found.
+ OSVDB-3092: /cgi-custom/: This might be interesting...
+ "robots.txt" not found.
+ OSVDB-3233: /: HTTP TRACE method is active, suggesting the host is vulnerable to XST
+ OSVDB-3092: /: This might be interesting...
+ /index.html: This might be interesting...
+ 8 items found on remote host
+ End Time: ...
---------------------------------------------------------------------------
+ 1 host(s) tested
如你所见,扫描成功识别了自定义目录,这展示了你如何根据特定需求定制 Nikto 的 CGI 扫描。
比较不同 CGI 扫描策略的结果
在最后一步,让我们回顾并比较你使用的不同扫描策略的结果。这将有助于巩固你对如何控制 Nikto CGI 扫描的理解。
你已经执行了四种不同的扫描类型:
- 默认扫描 (
nikto -h ...): 扫描了默认的常用目录列表。在我们的例子中,它最初没有标记/cgi-bin/,但该目录是存在的。此扫描提供了一个良好的基线。 - 无 CGI 扫描 (
-Cgidirs none): 完全跳过了所有 CGI 目录检查。输出确认了CGI directory scanning has been disabled。如果你不需要检查 CGI,这是最快的选项。 - 所有 CGI 扫描 (
-Cgidirs all): 强制检查 Nikto 已知的 pujin CGI 目录。此扫描成功找到并报告了我们的/cgi-bin/目录。这是最彻底但也是最慢的选项。 - 自定义 CGI 扫描 (
-Cgidirs /cgi-custom/): 仅扫描了特定的/cgi-custom/目录并成功找到它,忽略了所有其他目录,如/cgi-bin/。这是最具针对性的方法。
选择正确的策略取决于你的目标:
- 为了快速概览,默认扫描通常足够了。
- 为了绝对彻底,请使用 **
all**。 - 要在已知非 CGI 服务器上节省时间,请使用 **
none**。 - 对于自定义应用程序,指定 自定义路径 是最高效的方法。
最后,让我们通过停止 Python Web 服务器来清理。由于它是你启动的第一个也是唯一一个后台作业,你可以使用 kill %1 命令停止它。
kill %1
你将看到一条 "Terminated" 消息,确认服务器已关闭。
总结
在此次实验中,你获得了控制 Nikto CGI 目录扫描的实践经验。你学会了如何启动一个简单的 Web 服务器用于测试目的,然后使用 -Cgidirs 选项应用了不同的扫描策略。
你已成功:
- 执行了默认的 Nikto 扫描。
- 使用
-Cgidirs none完全禁用了 CGI 扫描。 - 使用
-Cgidirs all对所有已知的 CGI 目录进行了全面扫描。 - 通过提供自定义路径,针对了一个特定的、非标准的目录。
通过掌握这些选项,你现在可以运行更高效、更有针对性且有效的 Web 服务器漏洞扫描,并根据目标的具体特征定制你的测试。


