> 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="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FGaVpBGCpl5GvXf2V01iq%2Fimage.png?alt=media&amp;token=19670840-3f6a-48df-9298-d9f1e85fcfde" 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="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FVS1ifTYx5o5zHLmlGkTQ%2Fimage.png?alt=media&amp;token=b938a7f6-0274-46fd-af54-a8763009bad8" alt=""><figcaption></figcaption></figure></div>

in the search let's put a normal tag

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2Fo7p1tdTRhZr4INKuwJSc%2Fimage.png?alt=media&amp;token=7efac7a6-9b08-4c7c-9018-da2a59354c82" alt=""><figcaption></figcaption></figure></div>

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

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FENxOw3uREXNy7ES7LbJ4%2Fimage.png?alt=media&amp;token=cee58365-6627-4d80-90a4-3efa8af6b01f" 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="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FkOEOZYmCilKEVMhOR2v2%2Fimage.png?alt=media&amp;token=fcf79e8c-36a9-4ca3-b04d-f76aad27b432" 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="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2F9ib8YOVbKpoIJbB3pKQS%2Fimage.png?alt=media&amp;token=1fe057a1-7e06-4439-8c38-a80ef9c63552" alt=""><figcaption></figcaption></figure></div>

then click on status to find the one with 200 status

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FxHHOktgQkmWw3DczzkYj%2Fimage.png?alt=media&amp;token=4cf18bc1-c47e-4337-8fb5-b9d94e79a6ac" alt=""><figcaption></figcaption></figure></div>

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

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FUB7ckf4HMalKWQ64USTd%2Fimage.png?alt=media&amp;token=40fbd08e-d035-4562-a5cd-7f082b25a382" alt=""><figcaption></figcaption></figure></div>

and the app also blacklists attributes

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2F9huILiX7QRu9hWKmG7GA%2Fimage.png?alt=media&amp;token=7ced452d-4957-4ebf-8cf7-4c46cfbe4b1c" 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="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2Fxdv3WmAnRE8F03GtMAwA%2Fimage.png?alt=media&amp;token=7fe98cd7-3c46-4b23-9697-a0e95e5c931c" alt=""><figcaption></figcaption></figure></div>

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FiwgRy98zxhpgWyLIa71H%2Fimage.png?alt=media&amp;token=9f87ecf2-34fe-4206-9bd5-0fe13dddbd22" 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="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FxiBTxC3otWS2ZCzhWjDt%2Fimage.png?alt=media&amp;token=d42aaef9-1a44-4c52-af11-2d44eb2151ea" 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="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FbhHh08qRtjqwhAwCkjb1%2Fimage.png?alt=media&amp;token=152d9f9f-8571-42dc-987b-9774847ac2ad" alt=""><figcaption></figcaption></figure></div>

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

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FQ9WnRk9oBk9S6ULh8bdm%2Fimage.png?alt=media&amp;token=e043381c-3ddb-4664-8470-b3c69c9d7c41" alt=""><figcaption></figcaption></figure></div>

if we resize the page then this is showed

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FNesgP7WP1weQ1TWoPjEm%2Fimage.png?alt=media&amp;token=2b865810-3a68-4793-896f-9859d8c6a338" 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="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FrCwZtLe9MhcXerbHa4IN%2Fimage.png?alt=media&amp;token=5895d12d-0d73-4885-bfa2-ee55238a1a5e" 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="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FeXnqaGACgBd0423JuZwV%2Fimage.png?alt=media&amp;token=0cf6d755-a1ff-485c-ae25-a5c2a7963bd6" alt=""><figcaption></figcaption></figure></div>

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FPBOxr5zV44Pmk51QzkmU%2Fimage.png?alt=media&amp;token=47294cca-c123-4cb5-bf43-80b8fa33b34f" alt=""><figcaption></figcaption></figure></div>

deliver it now to the victim and the lab is solved

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FIFVVSZb2XlYnwbWnnEXM%2Fimage.png?alt=media&amp;token=0b2b1cef-d437-45c2-b714-103e4ae65fce" alt=""><figcaption></figcaption></figure></div>
