> 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-vulnerabilities/api-attack/abus-dapi-pentesting-web.md).

# API 滥用

## 从 GitHub 安装 Web 服务器（API 滥用）

```bash
curl -o docker-compose.yml https://raw.githubusercontent.com/OWASP/crAPI/main/deploy/docker/docker-compose.yml
docker-compose pull
docker-compose -f docker-compose.yml --compatibility up -d

```

* 我们 **注册** 一个新用户： ![](/files/aab2de4ca7cc9aafd3f4a2d787ffb4da1689035f)

## API 侦察

* 要发现 API 漏洞，重要的是从 **良好的侦察**开始。在 Network 部分中，像使用 [Burp Suite](/zh/hacking-tools/web/burpsuite.md) XHR 时那样捕获请求： ![](/files/b207704d46543a453d5e8efde493b354522dd2fb)
* 要 **组织并存储** 所有 API 请求，我们使用 **Postman**:

```javascript
postman & disown &>/dev/null

```

* 创建一个新的 **集合** 其中所有 API 请求都会被分组。对于 **POST** 请求，粘贴 **URL** 以及尤其是原始的 **正文**: ![](/files/9ae50aac7d9f9e9da7e2b6040e8fdb36b0066a6a) ![](/files/124bf35bb49f79ae8194da4448bb4beca055e312)
* 它返回 **结构为 JWT 的令牌** 登录的： ![](/files/95ed7a19ec68ce42614d6d97e33e0be2b24e1467)
* 创建一个名为 **accessToken** 的变量，并赋值为登录令牌： ![](/files/cc7e9d4f957974fa4937dab7fee48034b847bc75)
* 在 **authorization**部分中，将该变量关联到类型 **Bearer Token**: ![](/files/c1319b8e13220061e1281ddbeb654fdc10dbc27f)
* 保存全部 **可能的请求**:

1. 仪表盘： ![](/files/945950d2aaf7e8a5c374d98c6c5c36fd77165a3d)
2. 产品： ![](/files/f78d79eedbaba12260cc2f9534a1b2d1ddbe0420)
3. 命令： ![](/files/812a581d13c423cfb26f5e72848aa26a43741917)

## 与 API 滥用相关的漏洞：

### 暴力破解令牌恢复：

有一个选项可以 **重置密码** 方法是通过电子邮件检索令牌：

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

在端口 *8025*上，有一个 **SMTP** 我们在其中接收令牌：

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

点击 **忘记密码** 使用你想更改密码的账户的电子邮件地址：

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

我们捕获 **query** 到 API：

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

我们将请求发送为 **POST** 使用原始结构：

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

我们使用 **ffuf** 以发起一次 **暴力破解攻击**:

```graphql
ffuf -u http://localhost:8888/identity/api/auth/v2/check-otp -w /usr/share/SecLists/Fuzzing/4-digits-0000-9999.txt -X POST -d '{"email":"jordan@jordan.com","otp":"FUZZ","password":"Password1234*"}' -H "Content-Type: application/json" -p 1 -mc 200

```

该 **确认令牌** 0172 返回了一个 **成功状态码** 并且密码已自动更改：

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

### 修改产品价格并增加可用余额：

我们通过 **ffuf** 请求的可能方法来搜索 **products**:

```bash
ffuf -u http://localhost:8888/workshop/api/shop/products -w /usr/share/SecLists/Fuzzing/http-query-methods.txt -X FUZZ -p 1 -mc 200,401

```

这些都是所有 **可能的方法**:

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

如果我们从 **GET** 更改为 **POST**切换，这就是会发生的情况：

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

这是一个 **批量赋值** 允许通过 **POST** 请求创建产品的漏洞。在这种情况下，我们创建一个带有 **负** 价格的产品：

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

这样，它会被 **解释为** 由 Web 服务器：

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

因为价格是 **负**，每次我们点击 **购买**，就会有 10,000 美元被加到我们的余额中：

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

如果在请求 **订单**中，我们插入例如数量为 100 的产品编号，那么我们的余额将会乘以 **100 x 10 000**:

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

### 找到一个有效的优惠券代码：

我们发送 **validate-coupon**:

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

的请求 **因为优惠券**不正确，服务器不会返回任何内容：

<figure><img src="/files/40ffddd71593a70050349c83aad5c783ffbff5c8" alt="" width="524"><figcaption></figcaption></figure>

如果我们尝试执行注入 [NoSQL ](/zh/web-vulnerabilities/nosql-attack.md)因为数据库是 **MongoDB**，它会响应优惠券代码：

<figure><img src="/files/5ff21e10bd6a4b9baa130ccc346a75bc07b1a3fb" alt="" width="563"><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-vulnerabilities/api-attack/abus-dapi-pentesting-web.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.
