Nikto Web 服务器扫描教程

Nikto 是一款经典的开源 Web 服务器扫描工具,能够检测超过 7000 种潜在的安全问题,包括危险文件、过时的服务器版本、不安全的配置以及已知漏洞。它虽然不如 ZAP 那样功能全面,但使用简单、扫描速度快,非常适合快速评估 Web 服务器的安全状况。本文将介绍如何在搬瓦工 VPS 上安装和使用 Nikto。

一、Nikto 检测范围

  • 服务器配置:不安全的 HTTP 头、目录列表、默认文件等。
  • 过时软件:检测已知存在漏洞的服务器和组件版本。
  • 敏感文件:备份文件、配置文件、日志文件等意外暴露的内容。
  • CGI 漏洞:常见的 CGI 脚本安全问题。
  • SSL/TLS 问题:证书配置、弱密码套件等。

二、安装 Nikto

2.1 包管理器安装

# Ubuntu/Debian
apt update
apt install nikto -y

# CentOS
yum install epel-release -y
yum install nikto -y

2.2 从 Git 安装最新版

apt install perl libnet-ssleay-perl -y
git clone https://github.com/sullo/nikto.git /opt/nikto
ln -s /opt/nikto/program/nikto.pl /usr/local/bin/nikto

2.3 验证安装

nikto -Version

2.4 更新数据库

nikto -update

三、基础扫描

3.1 扫描单个目标

nikto -h https://example.com

3.2 指定端口

nikto -h example.com -p 8080

3.3 扫描多个端口

nikto -h example.com -p 80,443,8080,8443

3.4 使用 SSL

nikto -h example.com -ssl

3.5 扫描目标列表

cat > targets.txt << 'EOF'
https://target1.com
https://target2.com
http://192.168.1.100:8080
EOF

nikto -h targets.txt

四、扫描选项

4.1 调优选项

# 只检测特定类型的问题
# 1 - 有趣的文件/日志
# 2 - 错误配置/默认文件
# 3 - 信息泄露
# 4 - 注入(XSS/Script/HTML)
# 5 - 远程文件检索
# 6 - 拒绝服务
# 7 - 远程文件检索(服务器层面)
# 8 - 命令执行
# 9 - SQL 注入
# 0 - 文件上传
# a - 认证绕过
# b - 软件标识
# c - 远程源码包含

nikto -h https://example.com -Tuning 1234

# 排除某些类型
nikto -h https://example.com -Tuning x6

4.2 超时和速度控制

# 设置超时时间(秒)
nikto -h https://example.com -timeout 10

# 设置暂停时间(秒,降低扫描速度)
nikto -h https://example.com -Pause 1

# 限制最大运行时间(秒)
nikto -h https://example.com -maxtime 3600

4.3 代理设置

nikto -h https://example.com -useproxy http://proxy:8080

五、输出格式

# HTML 报告
nikto -h https://example.com -o report.html -Format html

# CSV 格式
nikto -h https://example.com -o report.csv -Format csv

# XML 格式
nikto -h https://example.com -o report.xml -Format xml

# JSON 格式
nikto -h https://example.com -o report.json -Format json

# 纯文本格式
nikto -h https://example.com -o report.txt -Format txt

六、高级用法

6.1 指定 User-Agent

nikto -h https://example.com -useragent "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"

6.2 使用认证

# HTTP Basic 认证
nikto -h https://example.com -id admin:password

# Cookie 认证
nikto -h https://example.com -Cookies "session=abc123; token=xyz789"

6.3 指定根目录

nikto -h https://example.com -root /app/

6.4 只检测指定 CGI 目录

nikto -h https://example.com -Cgidirs /cgi-bin/

6.5 忽略特定状态码

nikto -h https://example.com -no404

七、自动化扫描脚本

cat > /opt/nikto-scan.sh << 'SCRIPT'
#!/bin/bash
DATE=$(date +%Y%m%d-%H%M)
TARGETS="/opt/web-targets.txt"
REPORT_DIR="/opt/nikto-reports"

mkdir -p "$REPORT_DIR"

while IFS= read -r target; do
  HOSTNAME=$(echo "$target" | sed 's|https\?://||;s|/.*||;s|:.*||')
  echo "[$(date)] Scanning: $target"

  nikto -h "$target" \
    -o "${REPORT_DIR}/${HOSTNAME}-${DATE}.html" \
    -Format html \
    -maxtime 1800 \
    -timeout 10 \
    -no404

  echo "[$(date)] Completed: $target"
done < "$TARGETS"

echo "All scans completed."
SCRIPT

chmod +x /opt/nikto-scan.sh

设置定时执行:

crontab -e
# 每周日凌晨 2 点执行
0 2 * * 0 /opt/nikto-scan.sh >> /var/log/nikto-scan.log 2>&1

八、扫描自己的搬瓦工 VPS

# 扫描自己的 Web 服务器
nikto -h https://YOUR_VPS_IP -ssl -o /opt/my-vps-scan.html -Format html

# 扫描特定 Web 应用
nikto -h https://YOUR_DOMAIN -root /wordpress/ -o /opt/wp-scan.html -Format html

定期扫描自己的 VPS 可以发现 Web 服务器的配置问题和潜在漏洞。

九、Nikto 与其他工具对比

  • Nikto vs ZAP:Nikto 专注于服务器层面的检测,ZAP 更侧重应用层漏洞(如 XSS、SQL 注入)。
  • Nikto vs Nuclei:Nikto 检测范围较固定,Nuclei 的模板更灵活且更新更快。
  • 建议组合:先用 Nikto 做服务器层面的快速评估,再用 ZAP 或 Nuclei 做应用层面的深度检测。

十、注意事项

  • 合法授权:只扫描自己拥有或已获授权的 Web 服务器。
  • 误报处理:Nikto 的误报率相对较高,发现的问题需要手动验证。
  • 扫描流量:Nikto 会产生大量 HTTP 请求,可能被 WAF 拦截或触发告警。
  • 定期更新:使用 nikto -update 保持数据库最新。

总结

Nikto 是一款简单高效的 Web 服务器扫描工具,能够快速发现服务器配置问题和已知漏洞。虽然功能不如 ZAP 全面,但其使用简便、扫描速度快的特点使其成为安全评估工具箱中不可缺少的一员。配合 OWASP ZAPNuclei,可以实现全方位的 Web 安全检测。选购搬瓦工 VPS 请查看全部方案,使用优惠码 NODESEEK2026 可享受折扣。如有问题可通过搬瓦工官网提交工单。

关于本站

搬瓦工VPS中文网(bwgvps.com)是非官方中文信息站,整理搬瓦工的方案、优惠和教程。我们不销售主机,不提供技术服务。

新手必读
搬瓦工优惠码

NODESEEK2026(优惠 6.77%)

购买时填入即可抵扣。