Nuclei 漏洞扫描工具使用教程
Nuclei 是由 ProjectDiscovery 开发的快速、可定制的漏洞扫描工具。它基于 YAML 模板驱动,社区维护了数千个扫描模板,覆盖 CVE 漏洞、错误配置、暴露面检测等多种场景。Nuclei 轻量高效,非常适合在搬瓦工 VPS 上运行,对自己的服务器或授权目标进行安全检测。
一、Nuclei 特点
- 模板驱动:所有扫描逻辑都定义在 YAML 模板中,易于理解和自定义。
- 高性能:Go 语言编写,支持并发扫描,速度极快。
- 社区模板:官方维护超过 8000 个模板,覆盖最新 CVE 和常见漏洞。
- 多协议支持:支持 HTTP、DNS、TCP、SSL、文件等多种协议的检测。
- 低误报率:模板经过社区验证,误报率较低。
二、安装 Nuclei
2.1 使用 Go 安装
# 安装 Go(如果尚未安装)
wget https://go.dev/dl/go1.22.0.linux-amd64.tar.gz
tar -C /usr/local -xzf go1.22.0.linux-amd64.tar.gz
export PATH=$PATH:/usr/local/go/bin
echo 'export PATH=$PATH:/usr/local/go/bin:~/go/bin' >> ~/.bashrc
source ~/.bashrc
# 安装 Nuclei
go install -v github.com/projectdiscovery/nuclei/v3/cmd/nuclei@latest
2.2 使用二进制包安装
# 下载最新版本
wget https://github.com/projectdiscovery/nuclei/releases/latest/download/nuclei_linux_amd64.zip
unzip nuclei_linux_amd64.zip
mv nuclei /usr/local/bin/
chmod +x /usr/local/bin/nuclei
2.3 验证安装
nuclei -version
2.4 更新模板
nuclei -update-templates
模板默认存储在 ~/nuclei-templates/ 目录中。
三、基础扫描
3.1 扫描单个目标
# 对目标运行所有模板
nuclei -u https://example.com
# 仅使用 CVE 模板扫描
nuclei -u https://example.com -t cves/
# 仅使用关键和高危模板
nuclei -u https://example.com -severity critical,high
3.2 扫描多个目标
# 从文件读取目标列表
cat > targets.txt << 'EOF'
https://target1.com
https://target2.com
http://192.168.1.100
EOF
nuclei -l targets.txt
3.3 指定扫描类型
# 技术检测(识别使用的技术栈)
nuclei -u https://example.com -t technologies/
# 错误配置检测
nuclei -u https://example.com -t misconfiguration/
# 暴露面检测(敏感文件、接口等)
nuclei -u https://example.com -t exposures/
# DNS 相关检测
nuclei -u example.com -t dns/
# SSL/TLS 检测
nuclei -u https://example.com -t ssl/
四、高级用法
4.1 速率控制
# 限制每秒请求数
nuclei -u https://example.com -rate-limit 50
# 限制并发数
nuclei -u https://example.com -concurrency 10
# 设置超时时间
nuclei -u https://example.com -timeout 10
4.2 输出格式
# 输出到文件
nuclei -u https://example.com -o results.txt
# JSON 格式输出
nuclei -u https://example.com -jsonl -o results.json
# Markdown 报告
nuclei -u https://example.com -me report/
4.3 使用标签过滤模板
# 按标签筛选
nuclei -u https://example.com -tags cve,rce,sqli
# 排除特定标签
nuclei -u https://example.com -exclude-tags dos,fuzz
# 按作者筛选
nuclei -u https://example.com -author pdteam
4.4 使用工作流
# 运行 WordPress 工作流
nuclei -u https://example.com -w workflows/wordpress-workflow.yaml
# 运行所有工作流
nuclei -u https://example.com -t workflows/
五、自定义模板
5.1 模板基本结构
cat > ~/nuclei-templates/custom/check-admin.yaml << 'EOF'
id: admin-panel-detect
info:
name: Admin Panel Detection
author: custom
severity: info
description: Detect common admin panel paths
tags: admin,panel
http:
- method: GET
path:
- "{{BaseURL}}/admin"
- "{{BaseURL}}/admin/login"
- "{{BaseURL}}/wp-admin"
- "{{BaseURL}}/administrator"
matchers-condition: or
matchers:
- type: status
status:
- 200
- 302
- type: word
words:
- "admin"
- "login"
- "dashboard"
condition: or
EOF
5.2 带提取器的模板
cat > ~/nuclei-templates/custom/version-detect.yaml << 'EOF'
id: server-version-detect
info:
name: Server Version Detection
author: custom
severity: info
tags: tech
http:
- method: GET
path:
- "{{BaseURL}}"
extractors:
- type: regex
part: header
name: server
regex:
- "Server: ([^\r\n]+)"
- type: regex
part: header
name: x-powered-by
regex:
- "X-Powered-By: ([^\r\n]+)"
EOF
5.3 验证自定义模板
nuclei -t ~/nuclei-templates/custom/ -validate
六、与其他工具集成
# 配合 subfinder 进行子域名扫描
subfinder -d example.com -silent | httpx -silent | nuclei -t cves/
# 配合 naabu 进行端口发现后扫描
naabu -host example.com -silent | httpx -silent | nuclei
# 配合 katana 爬虫进行深度扫描
katana -u https://example.com -silent | nuclei -t exposures/
七、定时扫描脚本
cat > /opt/nuclei-scan.sh << 'SCRIPT'
#!/bin/bash
DATE=$(date +%Y%m%d)
TARGETS="/opt/scan-targets.txt"
OUTPUT="/opt/nuclei-reports/${DATE}"
mkdir -p "$OUTPUT"
# 更新模板
nuclei -update-templates
# 执行扫描
nuclei -l "$TARGETS" \
-severity critical,high,medium \
-rate-limit 100 \
-o "${OUTPUT}/results.txt" \
-jsonl -o "${OUTPUT}/results.json" \
-stats
echo "Scan completed: ${DATE}" >> /var/log/nuclei-scan.log
SCRIPT
chmod +x /opt/nuclei-scan.sh
设置 Crontab 每周执行:
crontab -e
# 每周一凌晨 3 点执行扫描
0 3 * * 1 /opt/nuclei-scan.sh
八、注意事项
- 仅扫描授权目标:未经授权扫描他人系统是违法行为,务必确保有合法授权。
- 控制扫描速率:过高的扫描速率可能导致目标服务不稳定,合理设置 rate-limit。
- 定期更新模板:新漏洞不断出现,定期更新模板库以保持检测能力。
- 验证扫描结果:自动化扫描可能存在误报,重要发现需要手动验证。
九、常见问题
扫描速度慢
调整并发参数和超时设置:
nuclei -u https://example.com -concurrency 25 -rate-limit 150 -timeout 5
模板更新失败
检查网络连接并手动克隆模板仓库:
git clone https://github.com/projectdiscovery/nuclei-templates.git ~/nuclei-templates
总结
Nuclei 是一款轻量而强大的漏洞扫描工具,基于模板驱动的设计使其既简单易用又高度可定制。在搬瓦工 VPS 上部署 Nuclei,可以方便地对自有服务器进行定期安全检测。结合 Nmap 网络扫描和 OWASP ZAP Web 安全测试,可以构建全面的安全检测体系。选购搬瓦工 VPS 请查看全部方案,使用优惠码 NODESEEK2026 可享受折扣。相关问题可通过搬瓦工官网提交工单咨询。