漏洞扫描与自动化发现
漏洞扫描是大规模资产发现与基线检查的核心能力,本指南系统讲解常见扫描器及使用。
一、漏洞扫描器分类
| 类型 | 工具 |
|---|---|
| 网络漏洞 | Nessus、AWVS、OpenVAS |
| Web 漏洞 | Burp Suite、Xray、AWVS |
| 主机漏洞 | Nessus、OpenVAS |
| 应用漏洞 | OWASP ZAP、Arachni |
| 代码审计 | SonarQube、CodeQL |
| 容器 | Trivy、Clair |
| 依赖 | Snyk、OWASP Dependency-Check |
| 资产发现 | Nuclei、Shodan、Censys |
二、Nessus 实战
1. 安装
BASH
# Linux
sudo dpkg -i Nessus-10.x.deb
sudo /opt/nessus/sbin/nessuscli fetch --register <activation_code>
sudo systemctl start nessusd
# 访问 https://localhost:8834
2. 扫描配置
CODE
1. New Scan -> Advanced Scan
2. General:
- Name: 内部网络扫描
- Targets: 192.168.1.0/24
3. Discovery:
- Port Scanning: 全部
- Service Discovery: 全
4. Assessment:
- Web Application: Scan web apps
5. Credentials:
- SSH / Windows / Database
6. Plugins:
- 全选
3. 实战经验
- 优先用 Credential 扫描
- 凌晨跑全量扫描
- 报告按严重性筛选
三、AWVS 实战
1. 安装
BASH
# Docker
docker pull secfa/docker-awvs
docker run -it -d -p 13443:3443 secfa/docker-awvs
# 访问 https://localhost:13443
2. 扫描配置
CODE
1. Targets -> Add Target
2. 输入 URL -> Scan
3. 配置 Scan Profile:
- Default
- High Risk
- SQL 注入专项
4. Scan Type:
- Crawl + Audit
3. 报告输出
- HTML
- JSON
四、Nuclei 实战
1. 安装
BASH
go install -v github.com/projectdiscovery/nuclei/v3/cmd/nuclei@latest
2. 基础用法
BASH
# 1. 扫描
nuclei -u https://target.com
# 2. 多目标
nuclei -l urls.txt
# 3. 模板分类
nuclei -u target.com -t cves/
nuclei -u target.com -t technologies/
nuclei -u target.com -t exposures/
# 4. 严重性
nuclei -u target.com -s critical,high
# 5. 输出
nuclei -u target.com -o results.txt
# 6. 并发
nuclei -u target.com -c 100
# 7. 速率限制
nuclei -u target.com -rl 100
3. 模板编写
YAML
id: custom-detect
info:
name: Custom detection
author: pentester
severity: high
description: Detect custom endpoint
tags: exposure,custom
requests:
- method: GET
path:
- "{{BaseURL}}/api/admin/users"
matchers:
- type: word
words:
- "admin"
- "password"
condition: and
part: body
- type: status
status:
- 200
五、Xray 实战
1. 安装
BASH
wget https://github.com/chaitin/xray/releases/latest/download/xray_linux_amd64.zip
unzip xray_linux_amd64.zip
chmod +x xray
2. 主动扫描
BASH
# 1. 基础扫描
./xray webscan --url http://target.com
# 2. 爬虫模式
./xray webscan --basic-crawler http://target.com
# 3. 插件选择
./xray webscan --plugins sqldet,ssrf,upload,cmd_injection --url http://target.com
# 4. 输出
./xray webscan --url http://target.com --json-output result.json
3. 联动 Burp
BASH
# 1. Burp 代理转给 xray
# Burp -> User Options -> Upstream Proxy -> 127.0.0.1:7777
# 2. xray 监听
./xray webscan --listen 127.0.0.1:7777 --html-output result.html
六、OpenVAS 实战
1. 安装
BASH
# Docker
docker run -d -p 9390:9390 -p 9391:9391 mikesplain/openvas
2. 扫描流程
CODE
1. 创建 Target
2. 创建 Task
3. 选择 Scan Config (Full and fast)
4. 运行 Task
5. 导出 Report
七、OWASP ZAP
1. 模式
- Baseline:基础扫描
- Full Scan:完整扫描
- API Scan:API 专项
- AJAX Spider:AJAX 爬虫
2. 命令行
BASH
# 1. Docker
docker run -t owasp/zap2docker-stable zap-baseline.py -t https://target.com
# 2. 完整扫描
docker run -t owasp/zap2docker-stable zap-full-scan.py -t https://target.com -r report.html
八、Sn1per 自动化
BASH
# 安装
git clone https://github.com/1N3/Sn1per
cd Sn1per
./install.sh
# 扫描
sniper -t target.com -m normal # 正常
sniper -t target.com -m stealth # 隐蔽
sniper -t target.com -m recon # 侦察
sniper -t target.com -m full # 完整
sniper -t target.com -m web # Web
九、自动化扫描平台
1. 云扫描
- 阿里云云安全中心
- 腾讯云漏洞扫描
- AWS Inspector
- 知道创宇 ZoomEye
2. 自建平台
- Faraday(开源协作平台)
- Archery(SQL 审计)
- Viper(红队平台)
十、漏洞库与情报
1. CVE 库
BASH
# 1. NVD
https://nvd.nist.gov
# 2. CVE Details
https://www.cvedetails.com
# 3. CNVD(国家信息安全漏洞共享平台)
https://www.cnvd.org.cn
# 4. CNNVD
http://www.cnnvd.org.cn
2. 工具
BASH
# 1. searchsploit
searchsploit apache 2.4
searchsploit -m 42966 # 拷贝 EXP
# 2. nvd-cli
nvd-cli search --keyword "Apache Struts"
# 3. vulners
vulners --query "Apache 2.4.49"
十一、扫描策略
1. 资产清点
BASH
# 1. 主域 + 子域
subfinder -d target.com -o subs.txt
# 2. IP 段
echo "1.1.1.0/24" > cidrs.txt
# 3. 整合目标
cat subs.txt | httpx -status-code | awk '{print $1}' > targets.txt
2. 分层扫描
MERMAID
115%
Ctrl + 滚轮缩放 · 拖动查看完整流程图
3. 报告整合
BASH
# 1. 多工具报告合并
- Nessus: nessus.csv
- AWVS: awvs.csv
- Nuclei: nuclei.json
- Xray: xray.json
# 2. 去重
- 工具:DefectDojo(开源漏洞管理平台)
- 字段:CVE、URL、严重性
十二、防御方案
- 定期扫描:至少季度全量,月度增量
- CI/CD 集成:Snyk、Trivy 嵌入流水线
- 基线检查:CIS Benchmarks
- 补丁管理:90 天内高危漏洞必须修复
- 虚拟补丁:WAF / RASP 临时缓解
- 漏洞跟踪:Jira / 禅道跟进
十三、实战经验
- 扫描器不是万能:业务逻辑漏洞扫不到。
- 误报过滤:Nessus 误报率 10-30%,需手工验证。
- 多工具交叉:AWVS + Burp + 手工 = 最佳。
- 凭证扫描 > 黑盒:配置 SSH/RDP 凭据后扫描更准。
- 不要影响业务:分时段扫描,限速。
- CVE 时间差:从 CVE 公开到 POC 出现只需数小时。