> 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/authentication-api-pentesting-web.md).

# API d’authentification

## Authentification API

Pour se connecter :

```json
curl -s -X POST http://secret.htb:3000/api/user/login -H "Content-Type: application/json" -d '{
    "email": "jordan@htb.com",
    "password": "jordan"
}' ; echo

```

Cela renvoie un jeton d’authentification (`auth-token`). `eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI2NzIxZjE5ZmQ4YWMzZTA0NjMxZjc4NmQiLCJuYW1lIjoiam9yZGFuIiwiZW1haWwiOiJqb3JkYW5AaHRiLmNvbSIsImlhdCI6MTczMDI3ODEyM30.z6quBZ6bTMSrkl7NxIfLEL0gUw6Wjvm3HWdnlhZBUoQ`

<figure><img src="/files/1b22e5281dd2107c4c4e22b9279f5206b3c4c6d9" alt=""><figcaption></figcaption></figure>

### Vérification du corps JSON par défaut

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

`email: "root@dasith.works"` `password: "Kekc8swFgD6zU"`

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

### Vulnérabilité de vérification [Jeton Web JSON](/fr/web-vulnerabilities/json-web-token-jwt-attack.md)

Utilisez un site pour décoder le JWT afin de lire et manipuler son contenu.

> **Remarque**: Le jeton JWT devrait être invalide. En modifiant les champs "name" et "email" avec des valeurs d’administrateur :

{% embed url="<https://jwt.io/>" %}

<figure><img src="/files/8d90ef856eb565c61b5492b11a9cb71bdeea51f1" alt=""><figcaption></figcaption></figure>

`"name": "theadmin",` `"email": "root@dasith.works",` `eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI2NzIxZjE5ZmQ4YWMzZTA0NjMxZjc4NmQiLCJuYW1lIjoidGhlYWRtaW4iLCJlbWFpbCI6InJvb3RAZGFzaXRoLndvcmtzIiwiaWF0IjoxNzMwMjc4MTIzfQ.yn6hXmpBxrfb5TMDY4_6zirckzlhnQP_L_YWb4wL2Ug`

<figure><img src="/files/3ff69ad5a655223304876ec9816f1616f11391b4" alt=""><figcaption></figcaption></figure>

### Tentative d’accès à une API privée :

Tentative d’accès à une API privée en utilisant le JWT modifié :

{% code overflow="wrap" %}

```bash
curl -s -X GET "http://secret.htb:3000/api/priv" -H "auth-token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI2NzIxZjE5ZmQ4YWMzZTA0NjMxZjc4NmQiLCJuYW1lIjoidGhlYWRtaW4iLCJlbWFpbCI6InJvb3RAZGFzaXRoLndvcmtzIiwiaWF0IjoxNzMwMjc4MTIzfQ.yn6hXmpBxrfb5TMDY4_6zirckzlhnQP_L_YWb4wL2Ug" | jq

```

{% endcode %}

Nous recevons un message « invalid token ».

<figure><img src="/files/77177352b9bd7020934e6649fe913f1e795229b2" alt="" width="563"><figcaption></figcaption></figure>

Avec notre propre JWT, nous avons accès en tant qu’utilisateur normal :

{% code overflow="wrap" %}

```bash
curl -s -X GET "http://secret.htb:3000/api/priv" -H "auth-token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI2NzIxZjE5ZmQ4YWMzZTA0NjMxZjc4NmQiLCJuYW1lIjoiam9yZGFuIiwiZW1haWwiOiJqb3JkYW5AaHRiLmNvbSIsImlhdCI6MTczMDI3ODEyM30.z6quBZ6bTMSrkl7NxIfLEL0gUw6Wjvm3HWdnlhZBUoQ" | jq

```

{% endcode %}

Nous recevons un message « Vous êtes un utilisateur normal ».

<figure><img src="/files/803d0f736588cb282cd80af5b620011748b45641" 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/authentication-api-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.
