> 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/ar/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/f90efefcae3d9353d65abd86f69e66bde966e869" alt=""><figcaption></figcaption></figure>

### التحقق من جسم JSON افتراضيًا

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

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

<figure><img src="/files/9225b697c0a3fceb148d7a99fff83a379338650c" alt=""><figcaption></figcaption></figure>

### ثغرة في التحقق [رمز ويب JSON](/ar/web-vulnerabilities/json-web-token-jwt-attack.md)

استخدم موقعًا لفك ترميز JWT لقراءة محتواه والتلاعب به.

> **ملاحظة**: يجب أن يكون رمز JWT غير صالح. من خلال تعديل الحقلين "name" و"email" إلى قيم المدير:

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

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

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

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

### محاولة الوصول إلى واجهة API خاصة:

محاولة الوصول إلى واجهة API خاصة باستخدام JWT المعدّل:

{% 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/59d4a18acf292211786af34c8e16d5cd254e8fbc" 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 %}

نحصل على رسالة "أنت مستخدم عادي".

<figure><img src="/files/4190f73e2967312b8d1ba5427236bb85b115408f" 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/ar/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.
