---
title: "3. XSS Discovery"
date: 2024-10-02
draft: false
---

In web app vulns, detecting them can become as difficult as exploiting them. 
XSS vulns are widespread, many tools

## Automated discovery of XSS 

All web application vulnerability scanners have various capabilities for detecting all 3 types of XSS 
- nessus
- burp
- zap

These scanners do two types: Active and Passive 
- Passive reviews client-side code for potential DOM based vulns 
- Active scan sends various types of payloads to attempt to trigger an XSS through payload injection in page source 

Paid tools have a higher level of accuracy. 
Open source tools are still plenty capable 

Tools usually work by identifying input fields and sending various payloads 
- Comparing rendered page source to see if same payload can be found 
- which /may/ indicate successful XSS injection 
	- this will not always be accurate
	- even if some payload was injected may not lead to success execution due to various reasons, always manually verify

Common OSS tools for XSS discovery
https://github.com/s0md3v/XSStrike
https://github.com/rajeshmajumdar/BruteXSS
https://github.com/epsylon/xsser

#### xsstrike example usage
```bash
git clone https://github.com/s0md3v/XSStrike.git
cd XSStrike
pip install -r requirements.txt
python xsstrike.py
```

```bash
python xsstrike.py -u "http://SERVER_IP:PORT/index.php?task=test" 
```
![](/img/Pasted image 20241002212011.png)

## Manual discovery of XSS

depends on level of security of application
basic XSS vulns usually found through testing various XSS payloads 
identifying advanced XSS vulns requires advanced code review skills 

### XSS Payloads 
most basic method: manually testing various payloads in an input field of a given webpage 

https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/XSS%20Injection/README.md

https://github.com/payloadbox/xss-payload-list

```bash
xss can be injected into any input on an html page which is not exclusive to html input fields
may also be http headers like the cookie or user agent 
	(relevant when their values are displayed on the page)
```

majority of above payloads do not work with our example webpages even though we are dealing with the most basic type of XSS vulns. 
- payloads are written for a wide variety of injection points (like injecting after a single quote for example)
- or designed to evade certain security measures like sanitization filters 
such payloads are using a variety of injection vectors to exec js code 
like `<script>` tags or other html attributes like `<img>` or even `CSS Style` attributes

The above explanation is why its not very efficient to resort to manually copy/pasting xss payloads - even if there's a vulnerability it may take a while to identify the vulnerability especially if we have many input fields to test. 
- May be more efficient to write our own Python script to automate sending these payloads + comparing page source to see how our payloads are being rendered. 
- Helps in advanced cases where basic tools cannot easily send/compare payloads 
- Advantage: Tailoring a tool to target web app

## Code Review

Most reliable method of detecting XSS vuln would be manual code review - covering both back-end and front-end code. 

Understanding exactly how input is handled all the way until it reaches web browser we can write a custom payload that would work with higher confidence 

We are unlikely to find XSS vulns through payload lists or XSS tools for more common web applications.
- Devs are likely running application through vuln assessment tools 
- Patching ID'd vulns 
- Manual code review may identify undetected XSS vulns that survive public release 

