mcpField
P
performing-dns-enumeration-and-zone-transfer

performing-dns-enumeration-and-zone-transfer

github.com/mukul975安全35.2k91 次安装8 周前更新
代码仓库

关于 performing-dns-enumeration-and-zone-transfer

面向获授权渗透测试人员的 DNS 枚举与区域传送测试技能,可发现子域名、主机和 DNS 配置问题,并强调仅在授权范围内进行测试。

主要功能

  1. 01查询常见 DNS 记录
  2. 02尝试 AXFR 区域传送
  3. 03通过字典枚举子域名
  4. 04执行反向 DNS 查询
  5. 05检查 DNSSEC、SPF、DKIM 和 DMARC
  6. 06解析并映射发现的子域名

适用场景

  1. 01绘制目标组织的外部攻击面
  2. 02查找暴露的主机名与 IP 地址
  3. 03验证 DNS 区域传送访问控制
  4. 04检查 DNS 与邮件认证配置

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/mukul975/anthropic-cybersecurity-skills --skill performing-dns-enumeration-and-zone-transfer

安装后在 Claude Code 中输入/performing-dns-enumeration-and-zone-transfer确认已加载。

包含的文件

除 SKILL.md 外,安装时一起下载的参考资料和脚本。

LICENSE
references/
api-reference.md
scripts/
agent.py

详细介绍

执行 DNS 枚举与区域传输

何时使用

  • 在获得授权的渗透测试中,绘制目标组织的外部攻击面
  • 发现通过 DNS 记录暴露的隐藏子域、内部主机名和 IP 地址
  • 测试 DNS 服务器是否允许未经授权的区域传输,从而泄露整个区域文件
  • 识别邮件服务器、名称服务器和服务记录,以便进一步开展针对性测试
  • 验证 DNS 安全配置,包括 DNSSEC、SPF、DKIM 和 DMARC

请勿对未获得测试授权的域使用,也请勿用于 DNS 放大或反射攻击,或通过过大的查询量压垮 DNS 服务器。

前置条件

  • 获得对目标域执行 DNS 枚举的书面授权
  • 已安装 DNS 枚举工具:dig、nslookup、host、dnsrecon、dnsenum、subfinder、amass
  • 可访问目标 DNS 服务器的网络(UDP/TCP 端口 53)
  • 用于子域暴力破解的字典(SecLists dns-wordlist 或类似字典)
  • 了解 DNS 记录类型(A、AAAA、CNAME、MX、NS、TXT、SOA、SRV、PTR)

工作流

第 1 步:识别 DNS 服务器和基本记录
# Find authoritative name servers
dig NS example.com +short
# ns1.example.com.
# ns2.example.com.

# Get SOA record for zone metadata
dig SOA example.com +short
# ns1.example.com. admin.example.com. 2024031501 3600 900 604800 86400

# Enumerate all common record types
dig example.com ANY +noall +answer

# Get MX records (mail servers)
dig MX example.com +short
# 10 mail.example.com.
# 20 mail-backup.example.com.

# Get TXT records (SPF, DKIM, DMARC, verification)
dig TXT example.com +short

# Check for DMARC policy
dig TXT _dmarc.example.com +short

# Check for DKIM selectors
dig TXT default._domainkey.example.com +short
dig TXT selector1._domainkey.example.com +short
dig TXT google._domainkey.example.com +short

# Get SRV records for common services
dig SRV _sip._tcp.example.com +short
dig SRV _ldap._tcp.example.com +short
dig SRV _kerberos._tcp.example.com +short
第 2 步:尝试区域传输
# Attempt AXFR zone transfer against each name server
dig AXFR example.com @ns1.example.com
dig AXFR example.com @ns2.example.com

# Use host command for zone transfer
host -t axfr example.com ns1.example.com

# Use dnsrecon for automated zone transfer attempts
dnsrecon -d example.com -t axfr

# If zone transfer succeeds, save the output
dig AXFR example.com @ns1.example.com > zone_transfer_results.txt

# Test for IXFR (incremental zone transfer)
dig IXFR=2024031500 example.com @ns1.example.com
第 3 步:通过暴力破解进行子域枚举
# Use dnsenum for comprehensive enumeration
dnsenum --dnsserver ns1.example.com --enum -f /usr/share/seclists/Discovery/DNS/subdomains-top1million-5000.txt -r example.com -o dnsenum_output.xml

# Use dnsrecon with brute force
dnsrecon -d example.com -t brt -D /usr/share/seclists/Discovery/DNS/subdomains-top1million-5000.txt

# Use gobuster for fast DNS brute forcing
gobuster dns -d example.com -w /usr/share/seclists/Discovery/DNS/subdomains-top1million-20000.txt -t 50 -o gobuster_dns.txt

# Use subfinder for passive subdomain discovery
subfinder -d example.com -all -o subfinder_results.txt

# Use amass for comprehensive enumeration (passive + active)
amass enum -d example.com -passive -o amass_passive.txt
amass enum -d example.com -active -brute -o amass_active.txt

# Combine and deduplicate results
cat subfinder_results.txt amass_passive.txt amass_active.txt gobuster_dns.txt | sort -u > all_subdomains.txt
第 4 步:反向 DNS 和 PTR 枚举
# Reverse DNS lookup on discovered IP ranges
dnsrecon -d example.com -t rvl -r 10.10.0.0/24

# PTR record enumeration for IP range
for ip in $(seq 1 254); do
  result=$(dig -x 10.10.1.$ip +short 2>/dev/null)
  if [ -n "$result" ]; then
    echo "10.10.1.$ip -> $result"
  fi
done

# Use Nmap for reverse DNS on a subnet
nmap -sL 10.10.0.0/24 | grep "(" | awk '{print $5, $6}'

# Check for DNS cache snooping (information about queried domains)
dig @ns1.example.com www.competitor.com +norecurse
第 5 步:分析 DNS 安全配置
# Check DNSSEC validation
dig example.com +dnssec +short
dig DNSKEY example.com +short
dig DS example.com +short

# Test for DNS rebinding vulnerability
# Check if the DNS server has a short TTL that could enable rebinding
dig example.com +noall +answer | grep -i ttl

# Check for open recursive resolver (misconfiguration)
dig @ns1.example.com google.com +recurse
# If it resolves, the server is an open resolver

# Check for wildcard DNS records
dig nonexistent-subdomain-xyz123.example.com +short
# If it resolves, a wildcard record exists

# Test DNS over HTTPS/TLS support
# DoH test
curl -s -H 'accept: application/dns-json' 'https://dns.google/resolve?name=example.com&type=A'

# Verify SPF record for email security
dig TXT example.com +short | grep "v=spf1"
# Check for overly permissive SPF (+all, ?all)
第 6 步:解析并映射所有发现的子域
# Resolve all discovered subdomains to IP addresses
while read subdomain; do
  ip=$(dig +short A "$subdomain" | head -1)
  if [ -n "$ip" ]; then
    echo "$subdomain,$ip"
  fi
done < all_subdomains.txt > resolved_subdomains.csv

# Identify unique IP addresses and their locations
cut -d',' -f2 resolved_subdomains.csv | sort -u > unique_ips.txt

# Check for internal IP addresses leaked via DNS
grep -E "^10\.|^172\.(1[6-9]|2[0-9]|3[01])\.|^192\.168\." resolved_subdomains.csv > internal_ip_leaks.txt

# Use httpx to probe web services on discovered subdomains
cat all_subdomains.txt | httpx -title -status-code -tech-detect -o httpx_results.txt

# Screenshot web services for documentation
cat all_subdomains.txt | httpx -screenshot -o screenshots/

关键概念

术语定义
区域传输(AXFR)将完整区域文件从主服务器复制到辅助服务器的 DNS 机制;未经授权的传输会暴露区域中的所有记录
子域枚举通过暴力破解、证书透明度日志、搜索引擎和被动 DNS 数据库发现有效子域的过程
DNSSECDNS 安全扩展,为 DNS 响应添加加密签名,防止缓存投毒和欺骗攻击
SPF/DKIM/DMARC在 DNS TXT 记录中定义的电子邮件认证协议,用于防止电子邮件欺骗和域冒充
通配符 DNS使用星号(*)的 DNS 记录,可匹配对不存在子域的任何查询,可能掩盖枚举结果
PTR 记录将 IP 地址映射到主机名的反向 DNS 记录,通常会揭示内部命名约定和服务器角色

工具与系统

  • dig:标准 DNS 查询工具,完全支持所有记录类型、DNSSEC 验证和区域传输查询
  • dnsrecon:全面的 DNS 枚举工具,支持区域传输、暴力破解、反向查询、缓存侦听和 Google dork 查询
  • subfinder:快速的被动子域发现工具,可查询证书透明度日志、搜索引擎和 DNS 数据库
  • Amass (OWASP):高级攻击面映射工具,具备被动和主动 DNS 枚举、图分析和数据源集成功能
  • gobuster:快速的暴力破解工具,使用可配置字典和并发线程进行 DNS 子域枚举

常见场景

场景:Web 应用渗透测试的外部侦察

背景:一名安全顾问正在为 Web 应用渗透测试执行外部侦察。客户的主域名是 example.com,范围包括所有子域名及相关基础设施。该顾问已获得授权,可枚举 DNS 记录并探测发现的 Web 服务。

方法:

  1. 查询 example.com 的 NS、MX、TXT 和 SOA 记录,以梳理 DNS 基础设施
  2. 对两台名称服务器尝试区域传送——ns2 成功,泄露了 347 条 DNS 记录,其中包括内部预发布环境
  3. 以被动模式运行 subfinder 和 amass,从证书透明度日志中发现另外 89 个子域名
  4. 使用 gobuster 以 20,000 词的字典暴力枚举子域名,发现另外 12 个被动来源未找到的子域名
  5. 解析所有子域名,并识别出 15 个解析到内部 RFC1918 地址的子域名(信息泄露)
  6. 使用 httpx 探测所有可通过 Web 访问的子域名,发现一个使用默认凭据的预发布环境(staging.example.com)
  7. 向客户报告区域传送漏洞、内部 IP 泄露以及暴露的预发布环境

陷阱:

  • 每秒发送数千次 DNS 查询,触发速率限制或基于 DNS 的 DDoS 防护
  • 未检查通配符 DNS 记录,导致误报子域名发现
  • 遗漏使用独立 DNS 提供商或 CDN 专用 CNAME 记录的子域名
  • 忽视包含 API 密钥、验证令牌或内部注释的 TXT 记录

Output Format

## DNS Enumeration Report

**Target Domain**: example.com
**Authorized Nameservers**: ns1.example.com (203.0.113.10), ns2.example.com (203.0.113.11)

### Zone Transfer Status
| Nameserver | AXFR Result | Records Obtained |
|------------|-------------|------------------|
| ns1.example.com | REFUSED | 0 |
| ns2.example.com | SUCCESS | 347 records |

### Subdomain Discovery Summary
| Method | Subdomains Found |
|--------|-----------------|
| Zone Transfer | 347 |
| Passive (subfinder + amass) | 89 |
| Active Brute Force | 12 |
| **Total Unique** | **412** |

### Critical Findings
1. **Zone Transfer Allowed** (High): ns2.example.com allows AXFR from any source
2. **Internal IP Disclosure** (Medium): 15 subdomains resolve to RFC1918 addresses
3. **Exposed Staging Environment** (High): staging.example.com accessible with default credentials
4. **Missing DMARC Policy** (Medium): No DMARC record found, enabling email spoofing
5. **Weak SPF Record** (Low): SPF uses ~all (soft fail) instead of -all (hard fail)

评论

支持 Markdown