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

# 认证 API

## API 身份验证

登录：

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

```

这会返回一个身份验证令牌（`auth-token`). `eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI2NzIxZjE5ZmQ4YWMzZTA0NjMxZjc4NmQiLCJuYW1lIjoiam9yZGFuIiwiZW1haWwiOiJqb3JkYW5AaHRiLmNvbSIsImlhdCI6MTczMDI3ODEyM30.z6quBZ6bTMSrkl7NxIfLEL0gUw6Wjvm3HWdnlhZBUoQ`

<figure><img src="/files/56985b82c965803ff874076b4c93c450120d0972" alt=""><figcaption></figcaption></figure>

### 默认会验证 JSON 正文

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

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

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

### 验证漏洞 [JSON Web 令牌](/zh/web-vulnerabilities/json-web-token-jwt-attack.md)

使用网站解码 JWT，以读取并修改其内容。

> **注意**：JWT 令牌应当是无效的。通过将字段 "name" 和 "email" 修改为管理员值：

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

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

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

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

### 尝试访问私有 API：

使用修改后的 JWT 尝试访问私有 API：

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

我们收到一条消息“invalid token”。

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

使用我们自己的 JWT，我们以普通用户身份获得访问权限：

{% code overflow="wrap" %}

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

```

{% endcode %}

我们收到一条消息“You are normal user”。

<figure><img src="/files/7934dda7720d2fc49d626e71cdc3e9c9d725f073" 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/zh/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.
