渗透测试之子域名探测指南
字数 2191 2025-08-27 12:33:31
渗透测试之子域名探测技术指南
前言
子域名探测是渗透测试和漏洞赏金猎人信息搜集阶段的重要组成部分。通过发现目标组织的各种子域名,可以扩大攻击面,增加发现漏洞的机会。本指南将详细介绍各种子域名探测技术及其实现方法。
什么是子域名探测?
子域名探测是查找一个或多个域的子域名的过程,属于信息搜集阶段的关键环节。
为什么要进行子域名探测?
- 发现更多服务,增加漏洞发现概率
- 查找较少访问、被遗忘的子域名,其上可能运行着易受攻击的应用程序
- 同一组织的不同域名/应用程序中可能存在相同漏洞
- 典型案例:Yahoo! Voices被黑就是因为易受攻击的子域名应用
子域名探测技术详解
1. 搜索引擎技术
Google搜索:
- 使用
site:运算符查找子域名 - 排除特定子域名:
site:*.wikimedia.org -www -store -jobs -uk
Bing搜索:
- 同样支持
site:运算符 - 可获取与Google不同的搜索结果
2. 第三方DNS服务
VirusTotal:
- 通过DNS复制功能构建数据库
- 直接在搜索栏输入域名即可获取子域名信息
DNSdumpster:
- 专门用于发现潜在子域名
- 提供可视化展示
Sublist3r工具:
- 开源工具(https://github.com/aboul3la/Sublist3r)
- 集成多个搜索引擎(Google/Yahoo/Bing/Baidu/Ask)
- 使用多种数据源(Netcraft/Virustotal/ThreatCrowd/DNSdumpster/ReverseDNS)
3. 证书透明(CT)日志技术
CT日志原理:
- 证书颁发机构(CA)必须发布每个SSL/TLS证书到公共日志
- 证书通常包含域名、子域名和邮件地址
CT日志搜索引擎:
- https://crt.sh/
- https://censys.io/
- Facebook CT工具:https://developers.facebook.com/tools/ct/
- Google CT报告:https://google.com/transparencyreport/https/ct/
高级CT查询:
$ psql -h crt.sh -p 5432 -U guest certwatch
自动化工具组合:
# 使用ct.py提取域名(包含在massdns中)
# 使用massdns解析有效域名
./ct.py icann.org | ./bin/massdns -r resolvers.txt -t A -q -a -o -w icann_resolvable_domains.txt
4. 基于字典的枚举
DNSRecon工具:
$ python dnsrecon.py -n ns1.insecuredns.com -d insecuredns.com -D subdomains-top1mil-5000.txt -t brt
- 使用预定义字典进行暴力破解
- 需要指定DNS服务器和目标域名
5. 置换扫描技术
AltDNS工具:
$ python altdns.py -i icann.domains -o data_output -w icann.words -r -s results_output.txt
- 使用已知域/子域名的排列组合发现新子域名
- 生成可能的变体并进行验证
6. 自治系统(AS)号码查询
实施步骤:
- 解析域名的IP地址:
dig或host - 根据IP查找ASN:asn.cymru.com/cgi-bin/whois.cgi
- 根据域名查找ASN:bgp.he.net/
- 使用ASN查找网络块
Nmap脚本实现:
$ nmap --script targets-asn --script-args targets-asn.asn=17012 > netblocks.txt
7. 域传送(DNS Zone Transfer)
检测方法:
$ dig +multi AXFR @ns1.insecuredns.com insecuredns.com
- 如果配置不当,可获取完整的域文件
- 域文件包含大量主机和域名信息
8. DNSSEC枚举
NSEC记录枚举:
$ ldns-walk @ns1.insecuredns.com insecuredns.com
- 利用DNSSEC处理不存在域名的方式遍历所有域名
NSEC3记录破解:
- 收集NSEC3哈希:
$ ./collect icann.org > icann.org.collect
- 破解哈希:
$ ./unhash < icann.org.collect > icann.org.unhash
- 提取子域名:
$ cat icann.org.unhash | grep "icann" | awk '{print $2;}'
工具推荐:
- nsec3walker:https://dnscurve.org/nsec3walker.html
- nsec3map:https://github.com/anonion0/nsec3map
9. 互联网扫描数据集
Forward DNS数据集:
- 来源:https://scans.io/study/sonar.fdns_v2
- 数据格式:gzip压缩的JSON
- 大小:压缩后20+GB,解压后300+GB
查询方法:
$ curl -silent https://scans.io/data/rapid7/sonar.fdns_v2/20170417-fdns.json.gz | pigz -dc | grep ".icann.org" | jq
技术对比
针对icann.org的测试结果显示不同技术的有效性差异:
- CT日志技术发现最多可解析子域名
- 搜索引擎技术次之
- 基于字典和DNSSEC方法效果相对较低
参考资源
工具和来源列表
搜索引擎:
- Google:https://google.com/
- Bing:https://bing.com/
DNS信息搜集:
- VirusTotal:https://www.virustotal.com/
- ViewDNS:https://viewdns.info/
- DNSdumpster:https://dnsdumpster.com/
- Threatcrowd:https://www.threatcrowd.org/
参考资料:
- 演讲资料:https://github.com/appsecco/bugcrowd-levelup-subdomain-enumeration
- OSINT指南:https://blog.appsecco.com/open-source-intelligence-gathering-101-d2861d4429e3
- DNSSEC安全:http://info.menandmice.com/blog/bid/73645/Take-your-DNSSEC-with-a-grain-of-salt
最佳实践建议
- 组合使用多种技术提高覆盖率
- 优先使用CT日志和搜索引擎技术
- 对大型目标考虑使用分布式处理大数据集
- 定期更新字典和工具以应对新发现的子域名模式
- 验证发现的子域名是否可解析和可访问
- 记录探测结果用于后续漏洞扫描和渗透测试