# Domain/Subdomain takeover

<details>

<summary><strong>从零开始学习AWS黑客技术，成为专家</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTE（HackTricks AWS Red Team Expert）</strong></a><strong>！</strong></summary>

支持HackTricks的其他方式：

* 如果您想看到您的**公司在HackTricks中做广告**或**下载PDF格式的HackTricks**，请查看[**订阅计划**](https://github.com/sponsors/carlospolop)!
* 获取[**官方PEASS & HackTricks周边产品**](https://peass.creator-spring.com)
* 探索[**PEASS家族**](https://opensea.io/collection/the-peass-family)，我们的独家[**NFTs**](https://opensea.io/collection/the-peass-family)收藏品
* **加入** 💬 [**Discord群**](https://discord.gg/hRep4RUj7f) 或 [**电报群**](https://t.me/peass) 或在**Twitter**上关注我们 🐦 [**@carlospolopm**](https://twitter.com/hacktricks_live)**。**
* 通过向[**HackTricks**](https://github.com/carlospolop/hacktricks)和[**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github仓库提交PR来分享您的黑客技巧。

</details>

<figure><img src="/files/PcmnOBrpXxCjYC5y3bif" alt=""><figcaption></figcaption></figure>

\
使用[**Trickest**](https://trickest.com/?utm_campaign=hacktrics\&utm_medium=banner\&utm_source=hacktricks)可以轻松构建和**自动化工作流程**，使用世界上**最先进**的社区工具。\
立即获取访问权限：

{% embed url="<https://trickest.com/?utm_campaign=hacktrics&utm_medium=banner&utm_source=hacktricks>" %}

## 域接管

如果您发现某个域名（domain.tld）**被某个服务在范围内使用**，但**公司**已经**失去了对其的所有权**，您可以尝试**注册**它（如果便宜的话），并通知公司。如果该域名通过**GET**参数或**Referer**标头接收到一些**敏感信息**，比如会话cookie，那么这肯定是一个**漏洞**。

### 子域接管

公司的一个子域指向一个**未注册名称的第三方服务**。如果您可以在这个**第三方服务**中**创建**一个**帐户**并**注册**正在使用的**名称**，则可以执行子域接管。

有几种带有字典的工具可用于检查可能的接管：

* <https://github.com/EdOverflow/can-i-take-over-xyz>
* <https://github.com/blacklanternsecurity/bbot>
* <https://github.com/punk-security/dnsReaper>
* <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/SaadAhmedx/Subdomain-Takeover>
* <https://github.com/Ice3man543/SubOver>
* <https://github.com/m4ll0k/takeover>
* <https://github.com/antichown/subdomain-takeover>
* <https://github.com/musana/mx-takeover>
* <https://github.com/PentestPad/subzy>

#### 使用[BBOT](https://github.com/blacklanternsecurity/bbot)扫描可劫持的子域：

BBOT的默认子域枚举中包含子域接管检查。签名直接从<https://github.com/EdOverflow/can-i-take-over-xyz>获取。

```bash
bbot -t evilcorp.com -f subdomain-enum
```

### 通过DNS通配符生成子域接管

当在一个域中使用DNS通配符时，该域的任何请求的子域，如果没有明确指定不同的地址，将被**解析为相同的信息**。这可以是一个A ip地址，一个CNAME...

例如，如果`*.testing.com`被通配到`1.1.1.1`。那么，`not-existent.testing.com`将指向`1.1.1.1`。

然而，如果管理员将其指向**第三方服务通过CNAME**，比如一个**github子域**，例如(`sohomdatta1.github.io`)。攻击者可以**创建自己的第三方页面**（在这种情况下是Github），并表示`something.testing.com`指向那里。因为**CNAME通配符**将同意，攻击者将能够**为受害者的域生成任意子域指向他的页面**。

您可以在CTF解密中找到这种漏洞的示例：<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/>

<figure><img src="/files/PcmnOBrpXxCjYC5y3bif" alt=""><figcaption></figcaption></figure>

\
使用[**Trickest**](https://trickest.com/?utm_campaign=hacktrics\&utm_medium=banner\&utm_source=hacktricks)可以轻松构建和**自动化工作流程**，使用全球**最先进**的社区工具。\
立即获取访问权限：

{% embed url="<https://trickest.com/?utm_campaign=hacktrics&utm_medium=banner&utm_source=hacktricks>" %}

<details>

<summary><strong>从零开始学习AWS黑客技术，成为专家</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTE（HackTricks AWS Red Team Expert）</strong></a><strong>！</strong></summary>

支持HackTricks的其他方式：

* 如果您想在HackTricks中看到您的**公司广告**或**下载PDF格式的HackTricks**，请查看[**订阅计划**](https://github.com/sponsors/carlospolop)!
* 获取[**官方PEASS & HackTricks周边产品**](https://peass.creator-spring.com)
* 探索[**PEASS家族**](https://opensea.io/collection/the-peass-family)，我们的独家[NFTs](https://opensea.io/collection/the-peass-family)收藏品
* **加入** 💬 [**Discord群**](https://discord.gg/hRep4RUj7f) 或 [**电报群**](https://t.me/peass) 或在**Twitter** 🐦 [**@carlospolopm**](https://twitter.com/hacktricks_live)**上关注**我们。
* 通过向[**HackTricks**](https://github.com/carlospolop/hacktricks)和[**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github仓库提交PR来分享您的黑客技巧。

</details>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://hacktricks.xsx.tw/pentesting-web/domain-subdomain-takeover.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
