Nikto 是一个开源的 Web 服务器与 Web 应用扫描器,测试超过 7,000 个潜在危险文件或程序,检查超过 1,250 种服务器的过时版本,并识别超过 270 种服务器的版本相关特定问题。它执行的全面测试包括 XSS、SQL 注入、服务器错误配置、默认凭据以及已知存在漏洞的 CGI 脚本。
适用时机
- 在开展涉及使用 Nikto 进行 Web 应用扫描的安全评估时
- 在针对相关安全事件遵循事件响应流程时
- 在执行计划性安全测试或审计活动时
- 在通过动手测试验证安全控制时
前提条件
- 已安装 Nikto(基于 Perl,Kali Linux 中已包含)
- 拥有扫描目标 Web 服务器的书面授权
- 具备对目标 Web 应用的网络访问能力
- 理解 HTTP/HTTPS 协议
核心概念
Nikto 能检测的内容
- 服务器错误配置与危险的默认文件
- 存在已知 CVE 的过时服务器软件版本
- 常见 CGI 漏洞与危险脚本
- 默认凭据与管理员页面
- 应被禁用的 HTTP 方法(PUT、DELETE、TRACE)
- SSL/TLS 错误配置与弱加密套件
- 缺失的安全响应头(X-Frame-Options、CSP、HSTS)
- 通过响应头和错误页面造成的信息泄露
Nikto 与其他 Web 扫描器的对比
| 特性 | Nikto | OWASP ZAP | Burp Suite | Nuclei |
|---|---|---|---|---|
| 许可 | 开源 | 开源 | 商业 | 开源 |
| 侧重 | 服务器/配置 | 应用逻辑 | 完整渗透测试 | 基于模板 |
| 速度 | 快 | 中 | 慢 | 非常快 |
| 误报 | 中等 | 低 | 低 | 低 |
| 认证 | 基础 | 完整 | 完整 | 模板 |
| 活跃社区 | 是 | 是 | 是 | 是 |
工作流程
步骤 1:基础扫描
# 针对目标的基础扫描
nikto -h https://target.example.com
# 扫描特定端口
nikto -h target.example.com -p 8443
# 扫描多个端口
nikto -h target.example.com -p 80,443,8080,8443
# 强制使用 SSL 进行扫描
nikto -h target.example.com -ssl
# 从主机列表文件进行扫描
nikto -h targets.txt
步骤 2:高级扫描选项
# 启用全部 tuning 选项的全面扫描
nikto -h https://target.example.com \
-Tuning 123456789abcde \
-timeout 10 \
-Pause 2 \
-Display V \
-output report.html \
-Format htm
Tuning 选项控制测试类型:
- 0 - 文件上传
- 1 - 有趣的文件 / 日志中出现过的文件
- 2 - 错误配置 / 默认文件
- 3 - 信息泄露
- 4 - 注入(XSS/Script/HTML)
- 5 - 远程文件获取 — Web 根目录内
- 6 - 拒绝服务
- 7 - 远程文件获取 — 全服务器范围
- 8 - 命令执行 / 远程 Shell
- 9 - SQL 注入
- a - 认证绕过
- b - 软件识别
- c - 远程源码包含
- d - WebService
- e - 管理控制台
# 使用特定 tuning(XSS + SQL 注入 + 认证绕过)
nikto -h https://target.example.com -Tuning 49a
# 带认证进行扫描
nikto -h https://target.example.com -id admin:password
# 通过代理进行扫描
nikto -h https://target.example.com -useproxy http://proxy:8080
# 使用自定义 User-Agent 进行扫描
nikto -h https://target.example.com -useragent "Mozilla/5.0 (Security Scan)"
# 扫描特定 CGI 目录
nikto -h https://target.example.com -Cgidirs /cgi-bin/,/scripts/
# 规避技术(用于经授权测试的 IDS 规避)
# 1-随机 URI 编码,2-目录自引用
# 3-提前结束 URL,4-前置长随机字符串
nikto -h https://target.example.com -evasion 1234
步骤 3:输出与报告
# 生成多种输出格式
nikto -h https://target.example.com -output scan.csv -Format csv
nikto -h https://target.example.com -output scan.xml -Format xml
nikto -h https://target.example.com -output scan.html -Format htm
nikto -h https://target.example.com -output scan.txt -Format txt
# JSON 输出(较新版本)
nikto -h https://target.example.com -output scan.json -Format json
# 同时保存为多种格式
nikto -h https://target.example.com \
-output scan_report \
-Format htm
步骤 4:扫描多个目标
# 创建目标文件(每行一个)
cat > targets.txt << 'EOF'
https://app1.example.com
https://app2.example.com:8443
http://internal-app.corp.local
192.168.1.100:8080
EOF
# 扫描所有目标
nikto -h targets.txt -output multi_scan.html -Format htm
# 使用 GNU parallel 并行扫描
cat targets.txt | parallel -j 5 "nikto -h {} -output {/}_report.html -Format htm"
步骤 5:SSL/TLS 评估
# 全面的 SSL 扫描
nikto -h https://target.example.com -ssl \
-Tuning b \
-Display V
Nikto 检查的 SSL 相关问题包括:
- 过期证书
- 自签名证书
- 弱加密套件
- 启用 SSLv2/SSLv3
- BEAST、POODLE、Heartbleed 指标
- 缺失 HSTS 响应头
步骤 6:与其他工具集成
# 将 Nmap 结果通过管道传入 Nikto
nmap -p 80,443,8080 --open -oG - 192.168.1.0/24 | \
awk '/open/{print $2}' | \
while read host; do nikto -h "$host" -output "${host}_nikto.html" -Format htm; done
# 导出为 Metasploit 兼容格式
nikto -h target.example.com -output msf_import.xml -Format xml
# 使用 Python 解析 Nikto XML 输出以生成自定义报告
python3 -c "
import xml.etree.ElementTree as ET
tree = ET.parse('scan.xml')
for item in tree.findall('.//item'):
print(f\"[{item.get('id')}] {item.findtext('description', '')[:100]}\")
"
结果解读
严重性分类
- OSVDB/CVE 引用:与 NVD 交叉比对以获取 CVSS 评分
- 服务器信息泄露:版本横幅、技术栈
- 危险的 HTTP 方法:启用 PUT、DELETE、TRACE
- 默认/备份文件:.bak、.old、.swp、web.config.bak
- 管理界面:暴露的 /admin、/manager、/console
- 缺失的安全响应头:CSP、X-Frame-Options、HSTS
常见误报
- 自定义 404 页面触发的通用检查
- 被标记为表单漏洞的反 CSRF 令牌
- 被误判为存在漏洞的 CDN/WAF 响应
- 负载均衡健康检查页面
最佳实践
- 扫描前始终获取书面授权
- 将 Nikto 与应用层扫描器(ZAP、Burp)配合使用
- 使用 -Pause 参数以降低对生产服务器的负载
- 报告前人工验证发现结果
- 结合 SSL 测试工具(testssl.sh、sslyze)以实现全面覆盖
- 将定期扫描纳入持续漏洞管理
- 保持 Nikto 数据库更新以获取最新漏洞检查
- 仅在经授权的 IDS 测试中使用适当的规避设置
常见陷阱
- 未经授权运行 Nikto(法律责任)
- 将 Nikto 当作完整的 Web 应用扫描器(它侧重于服务器/配置问题)
- 不验证结果,导致报告出现误报
- 对生产系统扫描过于激进
- 将 SSL/TLS 发现视为“信息性”问题而忽略
相关技能
- scanning-infrastructure-with-nessus
- scanning-apis-for-security-vulnerabilities
- performing-network-vulnerability-assessment