mirror of
https://github.com/HackTricks-wiki/hacktricks.git
synced 2025-10-10 18:36:50 +00:00
82 lines
5.9 KiB
Markdown
82 lines
5.9 KiB
Markdown
# 域名/子域名接管
|
||
|
||
{{#include ../banners/hacktricks-training.md}}
|
||
|
||
|
||
## 域名接管
|
||
|
||
如果你发现某个域名 (domain.tld) **被某个服务使用在范围内**,但该 **公司** 已经 **失去** 了对它的 **所有权**,你可以尝试 **注册** 它(如果价格足够便宜)并通知公司。如果这个域名接收一些 **敏感信息**,比如通过 **GET** 参数或 **Referer** 头部的会话 cookie,这肯定是一个 **漏洞**。
|
||
|
||
### 子域名接管
|
||
|
||
公司的一个子域名指向一个 **未注册名称的第三方服务**。如果你可以在这个 **第三方服务** 中 **创建** 一个 **账户** 并 **注册** 正在使用的 **名称**,你就可以执行子域名接管。
|
||
|
||
有几个工具带有字典来检查可能的接管:
|
||
|
||
- [https://github.com/EdOverflow/can-i-take-over-xyz](https://github.com/EdOverflow/can-i-take-over-xyz)
|
||
- [https://github.com/blacklanternsecurity/bbot](https://github.com/blacklanternsecurity/bbot)
|
||
- [https://github.com/punk-security/dnsReaper](https://github.com/punk-security/dnsReaper)
|
||
- [https://github.com/haccer/subjack](https://github.com/haccer/subjack)
|
||
- [https://github.com/anshumanbh/tko-sub](https://github.com/anshumanbh/tko-subs)
|
||
- [https://github.com/ArifulProtik/sub-domain-takeover](https://github.com/ArifulProtik/sub-domain-takeover)
|
||
- [https://github.com/SaadAhmedx/Subdomain-Takeover](https://github.com/SaadAhmedx/Subdomain-Takeover)
|
||
- [https://github.com/Ice3man543/SubOver](https://github.com/Ice3man543/SubOver)
|
||
- [https://github.com/antichown/subdomain-takeover](https://github.com/antichown/subdomain-takeover)
|
||
- [https://github.com/musana/mx-takeover](https://github.com/musana/mx-takeover)
|
||
- [https://github.com/PentestPad/subzy](https://github.com/PentestPad/subzy)
|
||
- [https://github.com/Stratus-Security/Subdominator](https://github.com/Stratus-Security/Subdominator)
|
||
- [https://github.com/NImaism/takeit](https://github.com/NImaism/takeit)
|
||
|
||
### 通过 DNS 通配符生成子域名接管
|
||
|
||
当在一个域名中使用 DNS 通配符时,任何请求的子域名如果没有明确的不同地址,将会 **解析为相同的信息**。这可以是 A IP 地址,CNAME...
|
||
|
||
例如,如果 `*.testing.com` 被通配符指向 `1.1.1.1`。那么,`not-existent.testing.com` 将指向 `1.1.1.1`。
|
||
|
||
然而,如果系统管理员不是指向一个 IP 地址,而是通过 CNAME 指向一个 **第三方服务**,比如一个 G**ithub 子域名**(例如 `sohomdatta1.github.io`)。攻击者可以 **创建他自己的第三方页面**(在 Gihub 中)并声称 `something.testing.com` 指向那里。因为,**CNAME 通配符** 将允许攻击者 **为受害者的域名生成任意子域名指向他的页面**。
|
||
|
||
你可以在 CTF 文章中找到这个漏洞的例子:[https://ctf.zeyu2001.com/2022/nitectf-2022/undocumented-js-api](https://ctf.zeyu2001.com/2022/nitectf-2022/undocumented-js-api)
|
||
|
||
## 利用子域名接管
|
||
|
||
子域名接管本质上是在互联网上对特定域名的 DNS 欺骗,允许攻击者为一个域名设置 A 记录,使浏览器显示来自攻击者服务器的内容。这种浏览器中的 **透明性** 使域名容易受到网络钓鱼攻击。攻击者可能会使用 [_typosquatting_](https://en.wikipedia.org/wiki/Typosquatting) 或 [_Doppelganger domains_](https://en.wikipedia.org/wiki/Doppelg%C3%A4nger) 来实现这一目的。特别容易受到攻击的是那些在网络钓鱼邮件中看似合法的 URL,欺骗用户并由于域名的固有信任而逃避垃圾邮件过滤器。
|
||
|
||
查看这个 [帖子以获取更多细节](https://0xpatrik.com/subdomain-takeover/)
|
||
|
||
### **SSL 证书**
|
||
|
||
如果攻击者通过像 [_Let's Encrypt_](https://letsencrypt.org/) 这样的服务生成 SSL 证书,会增加这些假域名的合法性,使网络钓鱼攻击更具说服力。
|
||
|
||
### **Cookie 安全性和浏览器透明性**
|
||
|
||
浏览器透明性还扩展到 cookie 安全性,受 [同源策略](https://en.wikipedia.org/wiki/Same-origin_policy) 的管理。Cookie 通常用于管理会话和存储登录令牌,可以通过子域名接管进行利用。攻击者可以 **收集会话 cookie**,只需将用户引导到一个被攻陷的子域名,危及用户数据和隐私。
|
||
|
||
### **电子邮件和子域名接管**
|
||
|
||
子域名接管的另一个方面涉及电子邮件服务。攻击者可以操纵 **MX 记录** 从合法子域名接收或发送电子邮件,从而增强网络钓鱼攻击的有效性。
|
||
|
||
### **更高的风险**
|
||
|
||
进一步的风险包括 **NS 记录接管**。如果攻击者控制了一个域名的 NS 记录,他们可以将部分流量引导到他们控制的服务器。如果攻击者为 DNS 记录设置了高 **TTL(生存时间)**,则这种风险会加剧,延长攻击的持续时间。
|
||
|
||
### CNAME 记录漏洞
|
||
|
||
攻击者可能会利用指向不再使用或已停用的外部服务的未声明 CNAME 记录。这使他们能够在受信任的域名下创建一个页面,进一步促进网络钓鱼或恶意软件分发。
|
||
|
||
### **缓解策略**
|
||
|
||
缓解策略包括:
|
||
|
||
1. **删除易受攻击的 DNS 记录** - 如果子域名不再需要,这种方法有效。
|
||
2. **声明域名** - 在相应的云提供商处注册资源或重新购买过期域名。
|
||
3. **定期监控漏洞** - 像 [aquatone](https://github.com/michenriksen/aquatone) 这样的工具可以帮助识别易受攻击的域名。组织还应修订其基础设施管理流程,确保 DNS 记录的创建是资源创建的最后一步,而资源销毁的第一步。
|
||
|
||
对于云提供商,验证域名所有权对于防止子域名接管至关重要。一些提供商,如 [GitLab](https://about.gitlab.com/2018/02/05/gitlab-pages-custom-domain-validation/),已经认识到这个问题并实施了域名验证机制。
|
||
|
||
## 参考文献
|
||
|
||
- [https://0xpatrik.com/subdomain-takeover/](https://0xpatrik.com/subdomain-takeover/)
|
||
- [https://www.stratussecurity.com/post/subdomain-takeover-guide](https://www.stratussecurity.com/post/subdomain-takeover-guide)
|
||
|
||
{{#include ../banners/hacktricks-training.md}}
|