> For the complete documentation index, see [llms.txt](https://writeups.adityadindi.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://writeups.adityadindi.com/tryhackme/walkthroughs-easy/cross-site-scripting.md).

# Cross-site Scripting

![](/files/-Mf_O6OPTCTfeBJZNuSg)

## Introduction

![](/files/-Mf_Ty1OjESJEy2f1oUe)

## Stored XSS

![](/files/-Mf_UDRzI0gfguTO350b)

Lets go to the Stored XSS Webpage

![](/files/-Mf_UdGnEVtIN9lVlxjK)

Lets try to add a comment on the page, first we have to create a user and login.

![](/files/-Mf_V6Ro9_x4RWnNL4SH)

Lets now try to add a comment.

![](/files/-Mf_VGHvtltFmSV4WgTz)

![](/files/-Mf_VJC7tcwosxoPbquD)

Now lets create an alert popup box appear on the web page with the document cookie.

![](/files/-Mf_VcWXwM0UdIan7SDr)

![](/files/-Mf_VfXRU8L8osoBsWFx)

Lets click ok

![](/files/-Mf_ViLMSGVS3_J2QrFR)

Now lets change the XSS Playground heading to I am a hacker.

![](/files/-Mf_W0sl1R810ixeQ9r-)

![](/files/-Mf_W7Zj1AJODHH-Wdkr)

![](/files/-Mf_WDH0kzrS6Nyt0LJS)

Lets now try to take over the user Jack's account by stealing his cookie.

![](/files/-MfdNL84yzRW-eT7Td0q)

Now lets go to the log page

![](/files/-MfdNXWjoZS_buvdE1vY)

We have the cookie

Lets change users to Jack and post a comment

First lets go to the developer tools and change the cookie to Jacks.

![](/files/-MfdNzhYh2Ep2K-u8Z1Q)

Now lets reload the page

![](/files/-MfdO4dln7BRpLVAQtuG)

We are now the user Jack, lets post a comment

![](/files/-MfdOA0IMcLQK0H_Ge6b)

## Reflected XSS

![](/files/-MfdOjpz-fIhFBHSKxw6)

Lets craft a reflected XSS payload that will cause a popup saying "hello"

```
<script>alert("hello")</script>
```

![](/files/-MfdPHPt1BTxSdtnjv8J)

![](/files/-MfdPJEbzuN6-2GF7zom)

For getting the IP address of the machine we can use this payload

```
<script>alert(window.location.hostname)</script>
```

![](/files/-MfdPcJGqmd-WAob-do8)

![](/files/-MfdPhBSbA67MM75SoPK)

## DOM-Based XSS

![](/files/-MfdPzUMzowluFbGcGPO)

Lets go to the DOM-Based XSS page and look at the source code

![](/files/-MfdQFs2PHy2VsAk0E_G)

This is interesting, looks like there are no checks on the input we give

Now lets exploit it and get the cookie.

```
test" onmouseover="aletest" onmouseover="alert('document.cookies')"rt(document.cookie)"
```

![](/files/-MfdRABpmOdNxI9Cq3as)

Now hover over the Image not found text

![](/files/-MfdRHB6gauNCi2Y46NZ)

![](/files/-MfdRJqRQsDoXS93S_NM)

Next lets create an `onhover` event on an image tag, that change the background color of the website to red.

```
test" onmouseover="document.body.style.backgroundColor='red'"
```

![](/files/-MfdRdhV5bFwa7hhPv6j)

Make sure to hover over the Image not found text

## Using XSS for IP and Port Scanning

![](/files/-MfdS1-LsR-AV7cb3Qm5)

![](/files/-MfdS3J5J6uoZdk2hvbX)

## XSS Keylogger

![](/files/-MfdSA7jwBkhcdLDw4xZ)

![](/files/-MfdSCT5HcvpcIhg4njv)

## Filter Evasion

![](/files/-MfdSKV4NnbSBYumlKLx)

Lets do the first challenge

![](/files/-MfdSlZw6QNRe8VNTgHZ)

![](/files/-MfdSnLTD53JAb1Kp3_I)

![](/files/-MfdSpY_p81hy36D61BQ)

Lets do challenge 2

```
0\"autofocus/onfocus=alert(1)--><video/poster/onerror=prompt(2)>"-confirm(3)-"
```

![](/files/-MfdTHgfd53VfKEGPkHN)

Lets do challenge 3

![](/files/-MfdTVSW1UVigVybmQCo)

![](/files/-MfdTZaM_Ujne3D2tOwl)

![](/files/-MfdTb0hYz9dF-KAJQcD)

Challenge 4

![](/files/-MfdThA_CHNHUPEtmx_7)

```
<style>@keyframes slidein {}</style><xss style="animation-duration:1s;animation-name:slidein;animation-iteration-count:2" onanimationiteration="alert('Hello')"></xss>
```

![](/files/-MfdTy9nRw2eupmKjpmu)

## Protection Methods and Other Exploits

![](/files/-MfdU8q42ZTWDiFczS8T)
