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

# API de Autenticação

## Autenticação da API

Para fazer login:

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

```

Isso retorna um token de autenticação (`auth-token`). `eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI2NzIxZjE5ZmQ4YWMzZTA0NjMxZjc4NmQiLCJuYW1lIjoiam9yZGFuIiwiZW1haWwiOiJqb3JkYW5AaHRiLmNvbSIsImlhdCI6MTczMDI3ODEyM30.z6quBZ6bTMSrkl7NxIfLEL0gUw6Wjvm3HWdnlhZBUoQ`

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

### Verificação do corpo JSON por padrão

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

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

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

### Vulnerabilidade de verificação [JSON Web Token](/pt-br/web-vulnerabilities/json-web-token-jwt-attack.md)

Use um site para decodificar o JWT e ler e manipular seu conteúdo.

> **Observação**: O token JWT deve ser inválido. Ao modificar os campos "name" e "email" para valores de administrador:

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

<figure><img src="/files/53a608625933a131a0c62e98e14acf14c29f32c3" alt=""><figcaption></figcaption></figure>

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

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

### Tentativa de acesso a uma API privada:

Tentativa de acessar uma API privada usando o JWT modificado:

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

Recebemos uma mensagem "token inválido".

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

Com nosso próprio JWT, temos acesso como um usuário normal:

{% code overflow="wrap" %}

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

```

{% endcode %}

Recebemos uma mensagem "Você é um usuário normal".

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