# Unicode Normalization

<details>

<summary><strong>从零开始学习AWS黑客技术，成为专家</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTE（HackTricks AWS红队专家）</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>

### [WhiteIntel](https://whiteintel.io)

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

[**WhiteIntel**](https://whiteintel.io)是一个以**暗网**为基础的搜索引擎，提供免费功能，用于检查公司或其客户是否受到**窃取恶意软件**的**侵害**。

WhiteIntel的主要目标是打击由信息窃取恶意软件导致的账户劫持和勒索软件攻击。

您可以访问他们的网站并免费尝试他们的引擎：

{% embed url="<https://whiteintel.io>" %}

***

**这是一个摘要：** [**https://appcheck-ng.com/unicode-normalization-vulnerabilities-the-special-k-polyglot/**](https://appcheck-ng.com/unicode-normalization-vulnerabilities-the-special-k-polyglot/)。查看更多详细信息（图片取自该网站）。

## 理解Unicode和规范化

Unicode规范化是一种确保字符的不同二进制表示标准化为相同二进制值的过程。这个过程在处理编程和数据处理中的字符串时至关重要。Unicode标准定义了两种字符等价性：

1. **规范等价性**：如果字符在打印或显示时具有相同的外观和含义，则被视为规范等价。
2. **兼容等价性**：一种较弱的等价性形式，其中字符可能表示相同的抽象字符，但显示方式可能不同。

有**四种Unicode规范化算法**：NFC、NFD、NFKC和NFKD。每种算法以不同的方式应用规范和兼容规范化技术。要更深入地了解这些技术，您可以在[Unicode.org](https://unicode.org/)上探索这些技术。

### Unicode编码的关键要点

理解Unicode编码至关重要，特别是在处理不同系统或语言之间的互操作性问题时。以下是主要要点：

* **代码点和字符**：在Unicode中，每个字符或符号都被分配一个称为“代码点”的数值。
* **字节表示**：代码点（或字符）在内存中由一个或多个字节表示。例如，拉丁-1字符（在讲英语的国家中很常见）使用一个字节表示。然而，具有更大字符集的语言需要更多字节来表示。
* **编码**：这个术语指的是如何将字符转换为一系列字节。UTF-8是一种流行的编码标准，其中ASCII字符使用一个字节表示，其他字符最多使用四个字节。
* **处理数据**：处理数据的系统必须了解所使用的编码，以正确地将字节流转换为字符。
* **UTF的变体**：除了UTF-8，还有其他编码标准，如UTF-16（使用至少2个字节，最多4个）和UTF-32（对所有字符使用4个字节）。

理解这些概念对于有效处理和减轻由Unicode的复杂性及其各种编码方法引起的潜在问题至关重要。

一个示例，说明Unicode如何规范化表示同一字符的两个不同字节：

```python
unicodedata.normalize("NFKD","chloe\u0301") == unicodedata.normalize("NFKD", "chlo\u00e9")
```

**Unicode等效字符列表可在此找到：** <https://appcheck-ng.com/wp-content/uploads/unicode_normalization.html> 和 <https://0xacb.com/normalization_table>

### 探索

如果您可以在web应用程序中找到一个被回显的值，您可以尝试发送\*\*“开尔文符号”（U+0212A）**，它**规范化为“K”**（您可以将其发送为`%e2%84%aa`）。如果回显了“K”，那么可能正在执行某种**Unicode规范化\*\*。

另一个**示例**：`%F0%9D%95%83%E2%85%87%F0%9D%99%A4%F0%9D%93%83%E2%85%88%F0%9D%94%B0%F0%9D%94%A5%F0%9D%99%96%F0%9D%93%83` 经过**unicode**后为`Leonishan`。

## **易受攻击的示例**

### **SQL注入过滤器绕过**

想象一个网页正在使用字符`'`来使用用户输入创建SQL查询。这个网页作为安全措施，**删除**用户输入中所有出现的字符\*\*`'`**，但在**删除**之后和**创建**查询之前，它使用**Unicode**对用户输入进行**规范化\*\*。

然后，恶意用户可以插入一个等效于`' (0x27)`的不同Unicode字符，如`%ef%bc%87`，当输入被规范化时，会创建一个单引号，从而出现**SQL注入漏洞**：

![https://appcheck-ng.com/unicode-normalization-vulnerabilities-the-special-k-polyglot/](/files/c7piXFXHSVxOzgcRF2yh)

**一些有趣的Unicode字符**

* `o` -- %e1%b4%bc
* `r` -- %e1%b4%bf
* `1` -- %c2%b9
* `=` -- %e2%81%bc
* `/` -- %ef%bc%8f
* `-`-- %ef%b9%a3
* `#`-- %ef%b9%9f
* `*`-- %ef%b9%a1
* `'` -- %ef%bc%87
* `"` -- %ef%bc%82
* `|` -- %ef%bd%9c

```
' or 1=1-- -
%ef%bc%87+%e1%b4%bc%e1%b4%bf+%c2%b9%e2%81%bc%c2%b9%ef%b9%a3%ef%b9%a3+%ef%b9%a3

" or 1=1-- -
%ef%bc%82+%e1%b4%bc%e1%b4%bf+%c2%b9%e2%81%bc%c2%b9%ef%b9%a3%ef%b9%a3+%ef%b9%a3

' || 1==1//
%ef%bc%87+%ef%bd%9c%ef%bd%9c+%c2%b9%e2%81%bc%e2%81%bc%c2%b9%ef%bc%8f%ef%bc%8f

" || 1==1//
%ef%bc%82+%ef%bd%9c%ef%bd%9c+%c2%b9%e2%81%bc%e2%81%bc%c2%b9%ef%bc%8f%ef%bc%8f
```

#### sqlmap 模板

{% embed url="<https://github.com/carlospolop/sqlmap_to_unicode_template>" %}

### XSS（跨站脚本）

您可以使用以下字符来欺骗 Web 应用程序并利用 XSS：

![https://appcheck-ng.com/unicode-normalization-vulnerabilities-the-special-k-polyglot/](/files/RsU2wAMzwQTRyDKaNvsr)

请注意，例如，第一个提出的 Unicode 字符可以发送为：`%e2%89%ae` 或 `%u226e`

![https://appcheck-ng.com/unicode-normalization-vulnerabilities-the-special-k-polyglot/](/files/fvZM7VxSy6qaJQgq4jJf)

### 模糊正则表达式

当后端**使用正则表达式检查用户输入**时，可能会出现**输入**被**规范化**用于**正则表达式**，但**未**用于其**使用**的情况。例如，在开放重定向或 SSRF 中，正则表达式可能会**规范化发送的 URL**，但然后**按原样访问**它。

工具 [**recollapse**](https://github.com/0xacb/recollapse) 允许**生成输入的变体**以对后端进行模糊测试。有关更多信息，请查看**github**和此[**文章**](https://0xacb.com/2022/11/21/recollapse/)。

## 参考资料

* [**https://labs.spotify.com/2013/06/18/creative-usernames/**](https://labs.spotify.com/2013/06/18/creative-usernames/)
* [**https://security.stackexchange.com/questions/48879/why-does-directory-traversal-attack-c0af-work**](https://security.stackexchange.com/questions/48879/why-does-directory-traversal-attack-c0af-work)
* [**https://jlajara.gitlab.io/posts/2020/02/19/Bypass\_WAF\_Unicode.html**](https://jlajara.gitlab.io/posts/2020/02/19/Bypass_WAF_Unicode.html)

### [WhiteIntel](https://whiteintel.io)

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

[**WhiteIntel**](https://whiteintel.io) 是一个由暗网推动的搜索引擎，提供免费功能，用于检查公司或其客户是否受到**窃取恶意软件**的**侵害**。

WhiteIntel 的主要目标是打击由信息窃取恶意软件导致的账户劫持和勒索软件攻击。

您可以在以下网址检查他们的网站并尝试他们的引擎，**免费**：

{% embed url="<https://whiteintel.io>" %}

<details>

<summary><strong>从零开始学习 AWS 黑客技术，成为专家</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTE（HackTricks AWS 红队专家）</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/unicode-injection/unicode-normalization.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.
