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

# Authentifizierungs-API

## API-Authentifizierung

Zum Einloggen:

```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

```

Dies gibt ein Authentifizierungs-Token zurück (`auth-token`). `eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI2NzIxZjE5ZmQ4YWMzZTA0NjMxZjc4NmQiLCJuYW1lIjoiam9yZGFuIiwiZW1haWwiOiJqb3JkYW5AaHRiLmNvbSIsImlhdCI6MTczMDI3ODEyM30.z6quBZ6bTMSrkl7NxIfLEL0gUw6Wjvm3HWdnlhZBUoQ`

<figure><img src="/files/61210032e19bed07e6c6265948586d381c69b20a" alt=""><figcaption></figcaption></figure>

### Standardmäßige Überprüfung des JSON-Body

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

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

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

### Überprüfungsschwachstelle [JSON-Web-Token](/de/web-vulnerabilities/json-web-token-jwt-attack.md)

Verwenden Sie eine Website, um das JWT zu dekodieren und seinen Inhalt zu lesen und zu manipulieren.

> **Hinweis**: Das JWT-Token sollte ungültig sein. Durch das Ändern der Felder "name" und "email" auf Administratorwerte:

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

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

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

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

### Zugriffsversuch auf eine private API:

Versuch, mit dem modifizierten JWT auf eine private API zuzugreifen:

{% 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 %}

Wir erhalten die Meldung "invalid token".

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

Mit unserem eigenen JWT haben wir als normaler Benutzer Zugriff:

{% code overflow="wrap" %}

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

```

{% endcode %}

Wir erhalten die Meldung "You are normal user".

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