挖掘SRC时如何编写信息收集脚本
字数 1120 2025-08-22 12:22:30
信息收集脚本编写指南:SRC挖掘中的资产收集技术
0x01 前言
在SRC挖掘过程中,高效的信息收集是成功的关键。本文详细介绍了如何编写自定义信息收集脚本,以克服现有工具的局限性,实现高度定制化的资产收集。
0x02 脚本开发框架
基础框架构建
首先创建一个名为scan.sh的脚本文件,构建基本框架:
#!/bin/bash
# 设置变量
id="$1"
ppath="$(pwd)"
scope_path="$ppath/scope/$id"
timestamp="$(date +%s)"
scan_path="$ppath/scans/$id-$timestamp"
# 检查范围目录是否存在
if [ ! -d "$scope_path" ]; then
echo "Path doesn't exist"
exit 1
fi
# 创建扫描目录
mkdir -p "$scan_path"
cd "$scan_path"
### 扫描开始 ###
echo "Starting scan against roots:"
cat "$scope_path/roots.txt"
cp -v "$scope_path/roots.txt" "$scan_path/roots.txt"
sleep 3
## 扫描模块将在此处添加 ##
# 计算扫描时间
end_time=$(date +%s)
seconds="$(expr $end_time - $timestamp)"
time=""
if [[ "$seconds" -gt 59 ]]; then
minutes=$(expr $seconds / 60)
time="$minutes minutes"
else
time="$seconds seconds"
fi
echo "Scan $id took $time"
框架特点
- 模块化设计:便于添加新功能
- 目录管理:每次扫描创建独立目录
- 时间统计:记录扫描耗时
- 错误检查:验证输入路径有效性
0x03 资产枚举技术
资产发现方法
- 手动核实:确认企业SRC公布的资产范围
- 自动化辅助工具:
- Whoxy API (https://whoxy.com)
- Fofa/Shodan搜索
- 反向DNS查找
关键步骤
- 通过搜索引擎识别IP地址
- 执行反向DNS查找
- 验证未知URL链接
- 确认企业基础设施资产
0x04 子域名枚举技术
工具选择
-
DNS暴力破解工具:
- puredns
- shuffledns (Massdns的Golang包装器)
-
所需资源:
- 暴力破解单词列表 (如pry-dns.txt)
- DNS解析器列表
脚本实现
## DNS枚举 - 查找子域名
cat "$scan_path/roots.txt" | subfinder | anew subs.txt
cat "$scan_path/roots.txt" | shuffledns -w "$ppath/lists/pry-dns.txt" -r "$ppath/lists/resolvers.txt" | anew subs.txt
通配符DNS处理
使用puredns进行通配符检测和过滤:
puredns resolve "$scan_path/subs.txt" -r "$ppath/lists/resolvers.txt" -w "$scan_path/resolved.txt"
增强枚举
添加更多被动源:
cat "$scan_path/roots.txt" | haktrails subdomains | anew subs.txt
0x05 HTTP服务器枚举
工具链
-
Nmap扫描:
nmap -T4 -vv -iL "$scan_path/ips.txt" --top-ports 3000 -n --open -oX "$scan_path/nmap.xml" -
Tew工具:
tew -x "$scan_path/nmap.xml" -dnsx "$scan_path/dns.json" --vhost -o "$scan_path/hostport.txt" -
HTTPx验证:
cat "$scan_path/hostport.txt" | httpx -json -o "$scan_path/http.json"
结果处理
提取URL并清理端口号:
cat http.json | jq -r '.url' | sed -e 's/:80$//g' -e 's/:443$//g' | anew http.txt
0x06 HTTP爬虫技术
爬取工具选择
-
Gospider:
gospider -S http.txt --json | grep "{" | jq -r '.output' -
替代方案:
- hakrawler
- xnLinkFinder
0x07 HTTP响应捕获
响应存储
使用HTTPx存储响应:
httpx -sr -srd "$scan_path/response" -json -o "$scan_path/http.json"
响应分析
- 创建"responses"目录存储所有HTTP响应
- 使用grep检查响应内容
- 分析响应头获取有价值信息
0x08 JavaScript分析
JS文件收集
cat "$scan_path/crawl.txt" | grep "\.js" | httpx -sr -srd js
分析工具
- grep:搜索敏感信息
- trufflehog:检测密钥和凭证
0x09 完整脚本示例
#!/bin/bash
## SETUP
echo "Starting scan against roots:"
cat "$scope_path/roots.txt"
cp -v "$scope_path/roots.txt" "$scan_path/roots.txt"
## DNS枚举 - 查找子域名
cat "$scan_path/roots.txt" | haktrails subdomains | anew subs.txt | wc -l
cat "$scan_path/roots.txt" | subfinder | anew subs.txt | wc -l
cat "$scan_path/roots.txt" | shuffledns -w "$ppath/lists/pry-dns.txt" -r "$ppath/lists/resolvers.txt" | anew subs.txt | wc -l
## DNS解析 - 解析发现的子域名
puredns resolve "$scan_path/subs.txt" -r "$ppath/lists/resolvers.txt" -w "$scan_path/resolved.txt" | wc -l
dnsx -l "$scan_path/resolved.txt" -json -o "$scan_path/dns.json" | jq -r '.a?[]?' | anew "$scan_path/ips.txt" | wc -l
## 端口扫描和HTTP服务器发现
nmap -T4 -vv -iL "$scan_path/ips.txt" --top-ports 3000 -n --open -oX "$scan_path/nmap.xml"
tew -x "$scan_path/nmap.xml" -dnsx "$scan_path/dns.json" --vhost -o "$scan_path/hostport.txt" | httpx -sr -srd "$scan_path/response" -json -o "$scan_path/http.json"
cat "$scan_path/http.json" | jq -r '.url' | sed -e 's/:80$//g' -e 's/:443$//g' | sort -u > "$scan_path/http.txt"
## 爬取
gospider -s "$scan_path/http.txt" --json | grep "{" | jq -r '.output?' | tee "$scan_path/crawl.txt"
## JavaScript文件抓取
cat "$scan_path/crawl.txt" | grep "\.js" | httpx -sr -srd js
0x0A 挑战与解决方案
常见挑战
- 脚本维护:需要定期更新以保持准确性
- 外部依赖:API和工具可能变更或不可用
- 性能问题:目标规模和复杂性影响脚本性能
- 虚拟主机:需要特殊处理
解决方案
- 模块化设计便于维护
- 使用稳定的API和工具
- 添加性能监控和优化
- 使用
--vhost标志处理虚拟主机
0x0B 总结
本文详细介绍了SRC挖掘中信息收集脚本的编写方法,包括:
- 开发框架构建
- 资产枚举技术
- 子域名发现方法
- HTTP服务器识别
- 网页爬取技术
- 响应分析和JS文件检查
通过自定义脚本,安全研究人员可以:
- 实现高度定制化的信息收集
- 提高SRC挖掘效率
- 发现更多潜在漏洞
- 保持工具的灵活性和可维护性