信息收集与资产测绘:命令链与误报判断¶
资产收集的目标不是“跑完全部工具”,而是得到一份可验证、可归属、可去重的清单。工具输出 3 万个域名,不如 30 个确认在用的系统。
1. 被动收集:不碰目标¶
证书透明度¶
curl -s "https://crt.sh/?q=%25.example.com&output=json" \
| jq -r '.[].name_value' \
| sed 's/\*\.//g' \
| sort -u > subs_crt.txt
crt.sh 偶尔超时,备用:
curl -s "https://api.certspotter.com/v1/issuances?domain=example.com&include_subdomains=true&expand=dns_names" \
| jq -r '.[].dns_names[]' | sort -u
被动 DNS 与历史记录¶
subfinder -d example.com -all -silent > subs_subfinder.txt
amass enum -passive -d example.com -o subs_amass.txt
cat subs_*.txt | sort -u > subs_all.txt
历史解析(找已下线但可能仍存活的老系统):
搜索引擎与代码仓库¶
site:example.com -www
site:example.com inurl:admin
site:example.com filetype:env
site:github.com "example.com" "password"
site:github.com "example.com" AKID
GitHub 泄露重点看:application.yml、.env、docker-compose.yml、CI 配置里的密钥。
2. 主动探测:先确认存活再扫¶
把域名解析、HTTP 存活、指纹合成一条流水线:
subfinder -d example.com -all -silent \
| dnsx -silent -a -resp -o resolved.txt
cut -d' ' -f1 resolved.txt \
| httpx -silent -status-code -title -tech-detect -web-server \
-follow-redirects -o live.txt
live.txt 示例:
https://api.example.com [200] [订单服务] [Spring Boot,Nginx]
https://old.example.com [403] [Forbidden] [IIS 8.5]
http://203.0.113.10:8080 [200] [Jenkins] [Jetty]
这一步就能发现“公网暴露的 Jenkins/Redis/Actuator”,比盲目目录扫描价值高。
CDN 与真实 IP¶
常见的错误判断:把 CDN 节点 IP 当源站做端口扫描,既违规又无意义。判断方式:
# 证书 SAN 与响应头(Server、Via、X-Cache)
curl -sI https://api.example.com | grep -iE "server|via|x-cache|cf-ray"
只有拿到源站 IP 才做端口扫描,且必须在授权范围内。
3. 端口与服务¶
nmap -sS -Pn -T4 --min-rate 1000 -p- 203.0.113.10 -oN ports.txt
nmap -sV -Pn -p 22,80,443,3306,6379,8080,9200 203.0.113.10 -oN services.txt
判据与注意:
-Pn:禁 ping,避免被防火墙误判下线--min-rate过高会触发防护,授权测试也要控制- UDP 扫描慢且噪音大,只对 DNS/SNMP 等必要端口做
- 看到
6379 Redis、9200 Elasticsearch、27017 MongoDB,优先验证未授权访问,而不是继续扫
4. 目录与接口¶
ffuf -u https://target/FUZZ \
-w /usr/share/seclists/Discovery/Web-Content/raft-medium-directories.txt \
-mc 200,204,301,302,401,403 \
-fc 404 -fs 0 \
-ac -rate 50 \
-o dirs.json -of json
-ac自动校准,能过滤“所有路径都返回同一页”的软 404-fs 0过滤空响应-rate 50控制速率,避免打挂业务
优先看:
/admin /actuator /actuator/env /swagger-ui.html /v2/api-docs
/.git/config /backup.zip /debug /console /druid/index.html
Spring Boot 的 /actuator/env 若可访问,可能泄露数据库连接串;/actuator/heapdump 甚至能直接下堆转储。
5. JS 里的隐藏接口¶
现代前端把接口写在打包后的 JS 里,爬虫抓不到。方法:
# 1. 收集 URL(历史与爬取)
cat urls.txt | grep -E '\.js(\?|$)' | sort -u > js.txt
# 2. 下载并提取接口路径
while read -r u; do
curl -s "$u" >> all.js
done < js.txt
grep -oE '"/(api|v[0-9]+)/[a-zA-Z0-9_/{}\-]+"' all.js | tr -d '"' | sort -u
常见遗漏:
sourceMappingURL指向.map文件,可直接还原源码- GraphQL 端点
/graphql,需要 introspection 查询 - WebSocket 地址
wss://,常在配置里
curl -s https://target/graphql -H 'Content-Type: application/json' \
-d '{"query":"{__schema{types{name}}}"}' | jq '.data.__schema.types[].name'
6. 云存储与对象桶¶
# 常见命名:公司名-环境、公司名-backup、公司名-static
for b in example-prod example-backup example-static example-dev; do
code=$(curl -s -o /dev/null -w "%{http_code}" "https://$b.s3.amazonaws.com/")
echo "$b $code"
done
| 返回 | 含义 |
|---|---|
| 200 | 公开可列目录 |
| 403 | 存在但不可列(AccessDenied) |
| 404 | 不存在 |
| 301 | 区域不对,跟随 Location |
授权范围内,200 时只列出前几个对象证明可访问,不要批量下载。
7. 去重与归属¶
# 统一小写、去端口、去 www
cat live.txt | awk '{print $1}' \
| sed -E 's#https?://##; s#:.*##; s#^www\.##' \
| sort -u > hosts.txt
归属判断:
- ICP 备案主体
- 页面版权、Logo、客服电话
- 证书组织名(O=)
- 与已知业务域名的证书/解析关联
不属于目标的资产不要测,哪怕它解析到同一 IP。
8. 误报判断清单¶
| 现象 | 可能的真相 | 验证 |
|---|---|---|
| 所有路径 200 | 软 404 / SPA 兜底路由 | 对比随机路径响应体哈希 |
| 403 遍地 | WAF 拦截或统一鉴权 | 换 UA/IP,看响应头 |
| 子域解析到 CDN | 非源站 | 看证书与 CNAME |
| “开放” Redis | 实际是蜜罐/防护 | 只读 PING,不要写 |
.git 可访问 |
可能只是 404 页面 | 检查响应是否真含 [core] |
用哈希对比软 404:
curl -s https://target/this-path-should-not-exist-12345 | md5sum
curl -s https://target/admin | md5sum
9. 资产清单模板¶
| 资产 | 类型 | 归属 | 状态 | 风险线索 |
|---|---|---|---|---|
| api.example.com | API | 订单组 | 在用 | Spring Boot,暴露 actuator |
| old.example.com | Web | 未知 | 疑似废弃 | IIS 8.5,403 |
| 203.0.113.10:6379 | Redis | 运维 | 公网暴露 | 未授权(待验证) |
10. 合规底线¶
- 只做授权范围内的被动与主动收集
- 控制速率,避免影响业务
- 不下载真实用户数据
- 收集结果加密保存,测试结束销毁
- 跨境资产注意数据出境与当地法律