subdomain-takeover
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSKILL: Subdomain Takeover — Detection & Exploitation Playbook
SKILL: 子域名接管 —— 检测与利用手册
AI LOAD INSTRUCTION: Covers CNAME/NS/MX takeover, per-provider fingerprint matching, claim procedures, and defensive monitoring. Base models often confuse "CNAME exists" with "takeover possible" — the key is whether the resource behind the CNAME is unclaimed and claimable.
AI加载说明:覆盖CNAME/NS/MX接管、各服务商指纹匹配、认领流程和防御监控。基础模型常将「存在CNAME记录」与「可被接管」混淆,核心判断标准是CNAME背后的资源是否处于未认领且可认领的状态。
0. RELATED ROUTING
0. 相关关联技能
- ssrf-server-side-request-forgery when a subdomain takeover is used to bypass SSRF allowlists trusting
*.target.com - cors-cross-origin-misconfiguration when CORS trusts — takeover → full cross-origin read
*.target.com - xss-cross-site-scripting takeover gives you script execution under target origin (cookie theft, OAuth redirect abuse)
- http-host-header-attacks when Host routing leads to subdomain-scoped cache or auth issues
- web-cache-deception when a taken-over subdomain shares cache with the main domain
- 当子域名接管被用于绕过信任的SSRF白名单时,参考ssrf-server-side-request-forgery
*.target.com - 当CORS信任时,参考cors-cross-origin-misconfiguration——接管后可实现完整跨域读取
*.target.com - 接管后可在目标源下执行脚本(Cookie窃取、OAuth重定向滥用),参考xss-cross-site-scripting
- 当Host路由导致子域名范围的缓存或认证问题时,参考http-host-header-attacks
- 当被接管的子域名与主域名共享缓存时,参考web-cache-deception
1. CORE CONCEPT
1. 核心概念
Subdomain takeover occurs when:
- has a DNS record (CNAME, NS, A) pointing to an external service
sub.target.com - The external resource is no longer provisioned (deleted S3 bucket, removed Heroku app, etc.)
- The attacker can register/claim that exact resource name on the provider
- The attacker now controls content served under
sub.target.com
Impact: cookie theft (parent domain cookies), OAuth token interception, phishing under trusted domain, CORS bypass, CSP bypass via whitelisted subdomain.
子域名接管发生需满足以下条件:
- 存在指向外部服务的DNS记录(CNAME、NS、A)
sub.target.com - 对应外部资源已被释放(如删除的S3存储桶、移除的Heroku应用等)
- 攻击者可在对应服务商处注册/认领完全同名的资源
- 攻击者由此可控制下提供的所有内容
sub.target.com
影响:Cookie窃取(父域Cookie)、OAuth令牌拦截、可信域名下钓鱼、CORS绕过、通过白名单子域名绕过CSP。
2. DETECTION METHODOLOGY
2. 检测方法
2.1 CNAME Enumeration
2.1 CNAME枚举
1. Collect subdomains (amass, subfinder, assetfinder, crt.sh, SecurityTrails)
2. Resolve DNS for each:
dig CNAME sub.target.com +short
3. For each CNAME → check if the CNAME target returns NXDOMAIN or a provider error
4. Match error response against fingerprint table (Section 3)1. 收集子域名(amass、subfinder、assetfinder、crt.sh、SecurityTrails)
2. 解析每个子域名的DNS记录:
dig CNAME sub.target.com +short
3. 对每个CNAME,检查其目标是否返回NXDOMAIN或服务商错误
4. 将错误响应与指纹对照表(第3节)匹配2.2 Key Signals
2.2 关键信号
| Signal | Meaning |
|---|---|
CNAME → | S3 bucket deleted, claimable |
CNAME → | Heroku app deleted |
CNAME → | GitHub Pages unclaimed |
| NXDOMAIN on the CNAME target domain itself | Target domain expired or never existed |
| CNAME → provider but HTTP 200 with default parking page | May or may not be claimable — verify |
| 信号 | 含义 |
|---|---|
CNAME指向 | S3存储桶已删除,可认领 |
CNAME指向 | Heroku应用已删除 |
CNAME指向 | GitHub Pages未被认领 |
| CNAME目标域名本身返回NXDOMAIN | 目标域名已到期或从未注册 |
| CNAME指向服务商但HTTP 200返回默认停放页 | 可能可认领,需进一步验证 |
2.3 Automated Tools
2.3 自动化工具
| Tool | Purpose |
|---|---|
| Automated CNAME takeover checking |
| Nuclei takeover detection templates |
| Reference for which services are vulnerable |
| Multi-provider takeover scanner |
| Fast subdomain takeover verification |
| 工具 | 用途 |
|---|---|
| 自动化CNAME接管检查 |
| Nuclei接管检测模板 |
| 各服务脆弱性参考手册 |
| 多服务商接管扫描器 |
| 快速子域名接管验证工具 |
3. SERVICE PROVIDER FINGERPRINT TABLE
3. 服务商指纹对照表
| Provider | CNAME Pattern | Fingerprint (HTTP Response) | Claimable? |
|---|---|---|---|
| AWS S3 | | | Yes — create bucket with matching name |
| GitHub Pages | | | Yes — create repo + enable Pages |
| Heroku | | | Yes — create app with matching name |
| Azure | | Various default pages, NXDOMAIN | Yes — register matching resource |
| Shopify | | | Yes — create shop, add custom domain |
| Fastly | CNAME to Fastly edge | | Yes — add domain to Fastly service |
| Pantheon | | | Yes |
| Tumblr | | | Yes |
| WordPress.com | CNAME to | | Yes — claim domain in WP.com |
| Zendesk | | | Yes — create matching subdomain |
| Unbounce | | | Yes |
| Ghost | | | Yes |
| Surge.sh | | | Yes |
| Fly.io | CNAME to | Fly.io default 404 | Yes |
| 服务商 | CNAME匹配规则 | 指纹(HTTP响应) | 可认领? |
|---|---|---|---|
| AWS S3 | | | 是——创建同名存储桶即可 |
| GitHub Pages | | | 是——创建仓库并开启Pages即可 |
| Heroku | | | 是——创建同名应用即可 |
| Azure | | 各类默认页面、NXDOMAIN | 是——注册同名资源即可 |
| Shopify | | | 是——创建店铺,添加自定义域名即可 |
| Fastly | CNAME指向Fastly边缘节点 | | 是——在Fastly服务中添加域名即可 |
| Pantheon | | 带Pantheon品牌标识的 | 是 |
| Tumblr | | | 是 |
| WordPress.com | CNAME指向 | | 是——在WP.com认领域名即可 |
| Zendesk | | | 是——创建同子域名即可 |
| Unbounce | | | 是 |
| Ghost | | | 是 |
| Surge.sh | | | 是 |
| Fly.io | CNAME指向 | Fly.io默认404页 | 是 |
4. TAKEOVER PROCEDURE — COMMON PROVIDERS
4. 接管流程——常见服务商
4.1 AWS S3
4.1 AWS S3
1. Confirm: curl -s http://sub.target.com → "NoSuchBucket"
2. Extract bucket name from CNAME (e.g., sub.target.com.s3.amazonaws.com → bucket = "sub.target.com")
3. aws s3 mb s3://sub.target.com --region <region>
4. Upload index.html proving control
5. Enable static website hosting1. 确认:curl -s http://sub.target.com → 返回"NoSuchBucket"
2. 从CNAME中提取存储桶名称(例如sub.target.com.s3.amazonaws.com → 存储桶名= "sub.target.com")
3. aws s3 mb s3://sub.target.com --region <region>
4. 上传证明控制权的index.html
5. 开启静态网站托管4.2 GitHub Pages
4.2 GitHub Pages
1. Confirm: curl -s https://sub.target.com → "There isn't a GitHub Pages site here"
2. Create GitHub repo (any name)
3. Add CNAME file containing "sub.target.com"
4. Enable GitHub Pages in repo settings
5. Wait for DNS propagation (GitHub verifies CNAME match)1. 确认:curl -s https://sub.target.com → 返回"There isn't a GitHub Pages site here"
2. 创建GitHub仓库(名称任意)
3. 添加内容为"sub.target.com"的CNAME文件
4. 在仓库设置中开启GitHub Pages
5. 等待DNS传播(GitHub会验证CNAME匹配)4.3 Heroku
4.3 Heroku
1. Confirm: curl -s http://sub.target.com → "No such app"
2. heroku create <app-name-from-cname>
3. heroku domains:add sub.target.com
4. Deploy proof-of-concept page1. 确认:curl -s http://sub.target.com → 返回"No such app"
2. heroku create <从CNAME提取的应用名>
3. heroku domains:add sub.target.com
4. 部署验证页面5. NS TAKEOVER — HIGH SEVERITY
5. NS记录接管——高风险
NS takeover is far more dangerous than CNAME takeover: you control all DNS resolution for the zone.
NS记录接管的危险性远高于CNAME接管:你可以控制整个域名解析区的所有DNS解析。
How It Happens
发生原理
target.com NS → ns1.expireddomain.com
↓
attacker registers expireddomain.com
↓
attacker now controls ALL DNS for target.com
(A records, MX records, TXT records — everything)target.com NS → ns1.expireddomain.com
↓
攻击者注册expireddomain.com
↓
攻击者现在控制target.com的所有DNS记录
(A记录、MX记录、TXT记录——所有内容)Detection
检测方法
1. Enumerate NS records: dig NS target.com +short
2. Check each NS domain: whois ns1.example.com → is the domain expired or available?
3. Also check: dig A ns1.example.com → NXDOMAIN/SERVFAIL?
4. Subdelegated zones: check NS for sub.target.com specifically1. 枚举NS记录:dig NS target.com +short
2. 检查每个NS域名:whois ns1.example.com → 域名是否到期或可注册?
3. 额外检查:dig A ns1.example.com → 是否返回NXDOMAIN/SERVFAIL?
4. 子委派区域:专门检查sub.target.com的NS记录Impact
影响
- Full domain takeover (serve any content, intercept email, issue TLS certs via DNS-01)
- Issue DV certificates from any CA using DNS challenge
- Modify SPF/DKIM/DMARC → send authenticated email as target
- 完整域名接管(提供任意内容、拦截邮件、通过DNS-01颁发TLS证书)
- 可通过DNS挑战向任意CA申请DV证书
- 修改SPF/DKIM/DMARC → 以目标域名名义发送认证邮件
6. MX TAKEOVER — EMAIL INTERCEPTION
6. MX记录接管——邮件拦截
When MX records point to deprovisioned mail services:
target.com MX → mail.deadservice.com (service discontinued)If attacker can claim or the mail tenant:
mail.deadservice.com- Receive password reset emails
- Intercept sensitive communications
- Potentially reset accounts that use email-based auth
当MX记录指向已注销的邮件服务时:
target.com MX → mail.deadservice.com(服务已停用)如果攻击者可认领或邮件租户:
mail.deadservice.com- 接收密码重置邮件
- 拦截敏感通信
- 可重置依赖邮箱认证的账户
Common Scenario
常见场景
Expired Google Workspace / Microsoft 365 tenant → MX still points to Google/Microsoft → attacker creates new tenant and claims the domain.
到期的Google Workspace / Microsoft 365租户 → MX记录仍指向Google/Microsoft → 攻击者创建新租户并认领域名。
7. WILDCARD DNS RISKS
7. 通配符DNS风险
If has a wildcard CNAME to a claimable service:
*.target.com- Every undefined subdomain is vulnerable
- can be taken over
anything.target.com - Massively increases attack surface
Detection: — if it resolves, wildcard exists.
dig A random1234567.target.com如果有指向可认领服务的通配符CNAME:
*.target.com- 所有未定义的子域名都存在漏洞
- 都可被接管
任意字符.target.com - 攻击面被大幅扩大
检测方法: —— 如果能解析,说明存在通配符记录。
dig A random1234567.target.com8. DETECTION & EXPLOITATION DECISION TREE
8. 检测与利用决策树
Subdomain discovered (sub.target.com)?
├── Resolve DNS records
│ ├── Has CNAME → external service?
│ │ ├── HTTP response matches known fingerprint? (Section 3)
│ │ │ ├── YES → Attempt claim on provider (Section 4)
│ │ │ │ ├── Claim successful → TAKEOVER CONFIRMED
│ │ │ │ └── Claim blocked (name reserved, region locked) → document, try variations
│ │ │ └── NO → Service active, no takeover
│ │ └── CNAME target NXDOMAIN?
│ │ ├── Target is a registrable domain? → Register it → full control
│ │ └── Target is a subdomain of active provider → check provider claim process
│ │
│ ├── Has NS records → external nameserver?
│ │ ├── NS domain expired/available? → Register → FULL ZONE TAKEOVER
│ │ └── NS domain active → no takeover
│ │
│ ├── Has MX → external mail service?
│ │ ├── Mail service deprovisioned/claimable? → Claim tenant → EMAIL INTERCEPTION
│ │ └── Active mail service → no takeover
│ │
│ └── Has A record → IP address?
│ ├── IP belongs to elastic cloud (AWS EIP, Azure, GCP)?
│ │ ├── IP unassigned? → Claim IP → serve content
│ │ └── IP assigned to another customer → no takeover
│ └── IP belongs to dedicated server → no takeover
│
└── Post-takeover impact assessment
├── Shared cookies with parent domain? → Session hijacking
├── CORS trusts *.target.com? → Cross-origin data theft
├── CSP whitelists *.target.com? → XSS via taken-over subdomain
├── OAuth redirect_uri allows sub.target.com? → Token theft
└── Can issue TLS cert for sub.target.com? → Full MITM发现子域名(sub.target.com)?
├── 解析DNS记录
│ ├── 存在指向外部服务的CNAME?
│ │ ├── HTTP响应匹配已知指纹?(第3节)
│ │ │ ├── 是 → 尝试在服务商处认领(第4节)
│ │ │ │ ├── 认领成功 → 确认接管
│ │ │ │ └── 认领被阻止(名称保留、区域锁定)→ 记录,尝试变体
│ │ │ └── 否 → 服务正常,无法接管
│ │ └── CNAME目标返回NXDOMAIN?
│ │ ├── 目标是可注册域名? → 注册 → 完全控制
│ │ └── 目标是活跃服务商的子域名 → 检查服务商认领流程
│ │
│ ├── 存在指向外部域名服务器的NS记录?
│ │ ├── NS域名到期/可注册? → 注册 → 完整区域接管
│ │ └── NS域名活跃 → 无法接管
│ │
│ ├── 存在指向外部邮件服务的MX记录?
│ │ ├── 邮件服务已注销/可认领? → 认领租户 → 邮件拦截
│ │ └── 邮件服务活跃 → 无法接管
│ │
│ └── 存在指向IP地址的A记录?
│ ├── IP属于弹性云服务(AWS EIP、Azure、GCP)?
│ │ ├── IP未分配? → 认领IP → 提供内容
│ │ └── IP已分配给其他客户 → 无法接管
│ └── IP属于专用服务器 → 无法接管
│
└── 接管后影响评估
├── 与父域共享Cookie? → 会话劫持
├── CORS信任*.target.com? → 跨域数据窃取
├── CSP白名单包含*.target.com? → 通过被接管子域名实现XSS
├── OAuth redirect_uri允许sub.target.com? → 令牌窃取
└── 可为sub.target.com颁发TLS证书? → 完整中间人攻击9. DEFENSE & REMEDIATION
9. 防御与修复方案
| Action | Priority |
|---|---|
| Remove DNS records when deprovisioning cloud resources | Critical |
| Monitor CNAME targets for NXDOMAIN responses | High |
| Use DNS monitoring tools (SecurityTrails, DNSHistory) | High |
| Claim/reserve resource names before deleting DNS records | High |
| Audit NS delegations — ensure NS domains are owned and renewed | Critical |
| Avoid wildcard CNAMEs to third-party services | Medium |
| Implement Certificate Transparency monitoring | Medium |
| 措施 | 优先级 |
|---|---|
| 释放云资源时同步删除对应DNS记录 | 严重 |
| 监控CNAME目标是否返回NXDOMAIN响应 | 高 |
| 使用DNS监控工具(SecurityTrails、DNSHistory) | 高 |
| 删除DNS记录前先认领/预留资源名称 | 高 |
| 审计NS委派——确保NS域名归己方所有且按时续费 | 严重 |
| 避免使用指向第三方服务的通配符CNAME | 中 |
| 部署证书透明度监控 | 中 |
10. TRICK NOTES — WHAT AI MODELS MISS
10. 技巧说明——AI模型容易遗漏的点
- CNAME ≠ takeover: A CNAME to S3 that returns 403 (bucket exists, private) is NOT vulnerable. Only (404) is.
NoSuchBucket - Region matters for S3: Bucket names are global, but website endpoints are regional. Try matching the region from the CNAME.
- GitHub Pages verification: GitHub added domain verification — org-verified domains cannot be claimed by others. Check if target uses this.
- Edge cases: Some providers (e.g., Cloudfront) require specific distribution configuration, not just domain claiming.
- Second-order takeover: — the chain must be followed fully.
sub.target.com CNAME → other.target.com CNAME → dead-service.com - SPF subdomain takeover: If SPF includes and you take over
include:sub.target.com, you can modify its SPF TXT record to authorize your mail server → send spoofed email assub.target.com.target.com
- 有CNAME≠可接管:指向S3的CNAME返回403(存储桶存在、私有)时不存在漏洞,只有返回(404)时才可能被接管。
NoSuchBucket - S3的区域要求:存储桶名称是全局唯一的,但网站端点是区域专属的,尝试匹配CNAME对应的区域。
- GitHub Pages验证:GitHub已新增域名验证功能,组织验证过的域名无法被其他人认领,需检查目标是否启用该功能。
- 边缘场景:部分服务商(如Cloudfront)需要特定的分发配置,仅认领域名不够。
- 二阶接管:—— 需要完整追溯整个解析链。
sub.target.com CNAME → other.target.com CNAME → dead-service.com - SPF子域名接管:如果SPF包含,你接管
include:sub.target.com后可修改其SPF TXT记录授权你的邮件服务器 → 可伪造sub.target.com名义发送邮件。target.com