# 4.2.3 Stored XSS

## Stored XSS

{% embed url="https://portswigger.net/web-security/cross-site-scripting/stored" %}

<figure><img src="https://content.gitbook.com/content/RpANgsg91cAWGMlAJ255/blobs/a5w2ywRX7WEfLKAl28IQ/image.png" alt=""><figcaption><p><a href="https://www.geeksforgeeks.org/what-is-cross-site-scripting-xss/">https://www.geeksforgeeks.org/what-is-cross-site-scripting-xss/</a></p></figcaption></figure>

Stored cross-site scripting (also known as second-order or persistent XSS) arises when an application receives data from an untrusted source and includes that data within its later HTTP responses in an unsafe way.

Suppose a website allows users to submit comments on blog posts, which are displayed to other users. Users submit comments using an HTTP request like the following:

`POST /post/comment HTTP/1.1 Host: vulnerable-website.com Content-Length: 100 postId=3&comment=This+post+was+extremely+helpful.&name=Carlos+Montoya&email=carlos%40normal-user.net`

After this comment has been submitted, any user who visits the blog post will receive the following within the application's response:

`<p>This post was extremely helpful.</p>`

Assuming the application doesn't perform any other processing of the data, an attacker can submit a malicious comment like this:

`<script>/* Bad stuff here... */</script>`

Within the attacker's request, this comment would be URL-encoded as:

`comment=%3Cscript%3E%2F*%2BBad%2Bstuff%2Bhere...%2B*%2F%3C%2Fscript%3E`

Any user who visits the blog post will now receive the following within the application's response:

`<p><script>/* Bad stuff here... */</script></p>`

The script supplied by the attacker will then execute in the victim user's browser, in the context of their session with the application.

## Lab

{% embed url="https://attackdefense.com/challengedetailsnoauth?cid=29" %}

Inject a Stored XSS's payload into a Blog's comment field.

<figure><img src="https://content.gitbook.com/content/RpANgsg91cAWGMlAJ255/blobs/pJ9t4gIApK7BVaswz5h5/image.png" alt=""><figcaption></figcaption></figure>

### Exploit Stored XSS Vulnerability in [MyBB Forum](https://github.com/mybb)

<details>

<summary>What is MyBB Forum?</summary>

MyBB, formerly known as MyBulletinBoard, is an open-source forum software written in PHP. It allows users to set up and manage their own online communities where people can post discussions, share information, ask questions, and interact with each other. MyBB provides various features such as user registration and profiles, customizable themes and templates, private messaging, moderation tools, and plugins/extensions for additional functionality. It's popular among website owners who want to create vibrant online communities without extensive programming knowledge, thanks to its user-friendly interface and extensive customization options.

</details>

* Login into MyBB&#x20;
* Download and execute (`./script.py`) python script to enumerate potential [MyBB plugin vulnerable](https://github.com/0xB9/MyBBscan)

{% embed url="https://github.com/0xB9/MyBBscan" %}

<figure><img src="https://content.gitbook.com/content/RpANgsg91cAWGMlAJ255/blobs/N1Wzk9xjWMXPP41Q9aG6/image.png" alt=""><figcaption></figcaption></figure>

{% embed url="https://www.exploit-db.com/exploits/44400" %}

We can exploit it following these steps:

* Go to downloads.php page
* Create a New Download
* Add the following to the title \<BODY ONLOAD=alert('XSS')>
* Now when the admin goes to validate your download he will be alerted

<figure><img src="https://content.gitbook.com/content/RpANgsg91cAWGMlAJ255/blobs/pgkmWyFm36dxlAy5l9uo/image.png" alt=""><figcaption></figcaption></figure>
