# Parameter Pollution

## 参数污染

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

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

{% embed url="<https://websec.nl/>" %}

## HTTP参数污染（HPP）概述

HTTP参数污染（HPP）是一种攻击技术，攻击者通过操纵HTTP参数以意外方式改变Web应用程序的行为。这种操纵是通过添加、修改或复制HTTP参数来实现的。这些操纵的效果对用户来说并不直接可见，但可以显着改变服务器端应用程序的功能，在客户端端产生可观察的影响。

### HTTP参数污染（HPP）示例

银行应用程序的交易URL：

* **原始URL：** `https://www.victim.com/send/?from=accountA&to=accountB&amount=10000`

通过插入额外的`from`参数：

* **操纵后的URL：** `https://www.victim.com/send/?from=accountA&to=accountB&amount=10000&from=accountC`

交易可能会错误地计入`accountC`而不是`accountA`，展示了HPP操纵交易或其他功能（如密码重置、2FA设置或API密钥请求）的潜力。

#### **特定技术的参数解析**

* 参数的解析和优先级取决于底层Web技术，影响HPP的利用方式。
* 像[Wappalyzer](https://addons.mozilla.org/en-US/firefox/addon/wappalyzer/)这样的工具有助于识别这些技术及其解析行为。

### PHP和HPP利用

**OTP操纵案例：**

* **背景：** 一个需要一次性密码（OTP）的登录机制被利用。
* **方法：** 通过使用Burp Suite等工具拦截OTP请求，攻击者复制了HTTP请求中的`email`参数。
* **结果：** OTP原本应发送到初始电子邮件，但却发送到了操纵请求中指定的第二个电子邮件地址。这个漏洞允许绕过预期的安全措施，未经授权地访问。

这种情况突显了应用程序后端的一个关键疏忽，该后端处理第一个`email`参数以生成OTP，但使用最后一个参数进行传递。

**API密钥操纵案例：**

* **场景：** 一个应用程序允许用户通过配置文件设置页面更新其API密钥。
* **攻击向量：** 攻击者发现通过向POST请求附加额外的`api_key`参数，可以操纵API密钥更新功能的结果。
* **技术：** 利用Burp Suite等工具，攻击者构造了一个请求，其中包括两个`api_key`参数：一个合法的，一个恶意的。服务器只处理最后一个出现的参数，将API密钥更新为攻击者提供的值。
* **结果：** 攻击者控制了受害者的API功能，可能未经授权地访问或修改私人数据。

这个例子进一步强调了安全参数处理的必要性，特别是在像API密钥管理这样关键的功能中。

### 参数解析：Flask vs. PHP

Web技术处理重复的HTTP参数的方式不同，影响它们对HPP攻击的易受性：

* **Flask：** 采用遇到的第一个参数值，例如在查询字符串`a=1&a=2`中优先考虑初始实例`a=1`而不是后续的重复。
* **PHP（在Apache HTTP服务器上）：** 相反，优先考虑最后一个参数值，在给定示例中选择`a=2`。这种行为可能无意中促进了HPP攻击，通过优先考虑攻击者操纵的参数而不是原始参数。

### 参考资料

* <https://medium.com/@shahjerry33/http-parameter-pollution-its-contaminated-85edc0805654>
* <https://github.com/google/google-ctf/tree/master/2023/web-under-construction/solution>

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

{% embed url="<https://websec.nl/>" %}

<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/parameter-pollution.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.
