> For the complete documentation index, see [llms.txt](https://sayonara.gitbook.io/writeups/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://sayonara.gitbook.io/writeups/portswigger/xss/14-reflected-xss-into-html-context-with-most-tags-and-attributes-blocked.md).

# 14) Reflected XSS into HTML context with most tags and attributes blocked

<div align="left"><figure><img src="/files/JjQkeeDUDhSOdJ3UZHp8" alt=""><figcaption></figcaption></figure></div>

#### Locate possible injection points

As usual the first step is to analyse the application, we have a search functionnality so let's search for random string and then open the developer tools and find where the user input is located in the html

<div align="left"><figure><img src="/files/Vv0aJJqCTg3axPRJaMQK" alt=""><figcaption></figcaption></figure></div>

in the search let's put a normal tag

<div align="left"><figure><img src="/files/1ZzlYFTDzctdkQ61p7u5" alt=""><figcaption></figcaption></figure></div>

when we click on search we get `tag is not allowed`&#x20;

<div align="left"><figure><img src="/files/xXVKykm8nOuYFOyaFZrH" alt=""><figcaption></figcaption></figure></div>

so there is a blacklist mechnisme that blacklists tags

send the search request to burp and send it to intruder

* In Burp Intruder, in the Positions tab, replace the value of the search term with: `<>`
* Place the cursor between the angle brackets and click "Add §" twice, to create a payload position. The value of the search term should now look like: `<§§>`

<div align="left"><figure><img src="/files/qduH1ZAmKZfCjeFauMpQ" alt=""><figcaption></figcaption></figure></div>

* Visit the [XSS cheat sheet](https://portswigger.net/web-security/cross-site-scripting/cheat-sheet) and click "Copy tags to clipboard".
* In Burp Intruder, in the Payloads tab, click "Paste" to paste the list of tags into the payloads list. click `start attack`

<div align="left"><figure><img src="/files/RkD3lWQIB1e4yKz3mifM" alt=""><figcaption></figcaption></figure></div>

then click on status to find the one with 200 status

<div align="left"><figure><img src="/files/EauEEcjjFMESKnd296gb" alt=""><figcaption></figcaption></figure></div>

now let's try to use the body tag to trigger an xss

<div align="left"><figure><img src="/files/OuWCUMpu6bf39aTH3vmV" alt=""><figcaption></figcaption></figure></div>

and the app also blacklists attributes

<div align="left"><figure><img src="/files/thJ68aCxZn1sMCDWgksi" alt=""><figcaption></figcaption></figure></div>

again doing the same thing let's find the allowed attribute

* Visit the [XSS cheat sheet](https://portswigger.net/web-security/cross-site-scripting/cheat-sheet) and click "copy events to clipboard".
* In Burp Intruder, in the Payloads tab, click "Clear" to remove the previous payloads. Then click "Paste" to paste the list of attributes into the payloads list. Click "Start attack".

<div align="left"><figure><img src="/files/0sJXfFpr9161ns9GmVuT" alt=""><figcaption></figcaption></figure></div>

<div align="left"><figure><img src="/files/vRw25D5cBzPTNPpPor0k" alt=""><figcaption></figcaption></figure></div>

When the attack is finished, review the results. Note that all payloads caused an HTTP 400 response

<div align="left"><figure><img src="/files/qQHCzcYUoKlE2FneS5WE" alt=""><figcaption></figcaption></figure></div>

now using the allowed tag and attribues let's construct a xss payload

searching in the [portswigger xss cheat sheet list](https://portswigger.net/web-security/cross-site-scripting/cheat-sheet) i found a payload using onresize attribute which is allowed

<div align="left"><figure><img src="/files/AWS5CWPaIZTkSZpL5SIu" alt=""><figcaption></figcaption></figure></div>

```
xxxx"<body onresize="print()">
```

<div align="left"><figure><img src="/files/lBL62Yh5QVHzjThwMv1F" alt=""><figcaption></figcaption></figure></div>

if we resize the page then this is showed

<div align="left"><figure><img src="/files/gNs253WIOW21ugBeQ6Fn" alt=""><figcaption></figcaption></figure></div>

so the payload is triggered succesfully

now let's go to the exploit server and deliver this payload to the victim

<div align="left"><figure><img src="/files/UlmNtgKyF2VoFX3becFk" alt=""><figcaption></figcaption></figure></div>

we need to put our payload in an iframe and send it to the victim

The print command needs to be performed automatically without any user interaction. Therefore I need a way to enforce the `resize` event without requiring the victim to do it.

For this I use an iframe that contains the search that resizes on load

```
<iframe src="https://0a5e00a603f682d58171d9c200cb004c.web-security-academy.net/?search=xxxx"<body onresize="print()">" onload=this.style.width='250px'></iframe>
```

I URL-encode the entire search term to ensure nothing goes amiss inside the iframe:

```
<iframe src="https://0a5e00a603f682d58171d9c200cb004c.web-security-academy.net/?search=%78%78%78%78%22%3c%62%6f%64%79%20%6f%6e%72%65%73%69%7a%65%3d%22%70%72%69%6e%74%28%29%22%3e" onload=this.style.width='250px'></iframe>
```

<div align="left"><figure><img src="/files/ibxYy1R0SoQnHbG2mNQP" alt=""><figcaption></figcaption></figure></div>

<div align="left"><figure><img src="/files/GB4sYzZ2tknsh2kTGSXL" alt=""><figcaption></figcaption></figure></div>

deliver it now to the victim and the lab is solved

<div align="left"><figure><img src="/files/Bm5gLFIUxecvuGe85DZE" alt=""><figcaption></figcaption></figure></div>
