Best 5 Cross Site Scripting Attacks

Cross site scripting is a great notable kind of assault that is conceivable on the grounds that some product applications take client contribution to an unreliable way. This happens by means of search fields, review structures, treats, and online web structures.

So, we know cross site scripting itself is a very big topic to discuss and it has various way of exploiting any sites but today we will focus more on this three types DOM XSS, Stored XSS, and Reflected XSS.

Cross Site Scripting

1. Stored XSS

The vindictive information is put away forever on a database and is later gotten to and run by the casualties without having any information on the assault. The great case of put away XSS is a pernicious content embedded by an assailant in a remark field on a blog, Online networking, or in a gathering post.
If you see the following XSS payload it’s very clear that this payload is requesting image or loading the image from the attacker’s server with the help of the victim cookies data which can be seen within the URL.


After a request for the image has taken place the attacker can extract the victim’s session identifier from the web server log files.
So if your more interested to know in depth well I’ll tell you my fav. documentary by Samy if you watch that I know you guys will like it too click here.

2. Reflected XSS

Reflected XSS attacks, also known as non-persistent attacks, occur when a malicious script is reflected off of a web application to the victim’s browser.
Now here we can see how this simple looking javascript is used by an attacker who gives your web application JavaScript tags on input.

(<script type=’text/javascript’>alert(‘Possible XSS’);</script>

Cross Site Scripting

At the point when this information is come back to the client unsanitized, the client’s program will execute it. It very well may be as straightforward as making a connection and inciting a client to click it, or it very well may be something considerably more risky. On page load, the content runs and, can be utilized to present your cookies on the hacker.
Let’s look in something more in common which we do everyday, when we visit any kind of forum site
which ask for your login to access your account (eg. facebook), so a person might execute this similar kind of query which may lead to this following things to occur:
  • The query produces an alert box saying: “possible XSS”.
  • The page displays: “<script type=’text/javascript’>alert(‘XSS’);</script > not found.”
  • The page’s URL reads https://abcd?q=<script type=”text/javascript”>alert(‘XSS’); </script>


Before we begin let’s understand What is DOM?.

What is DOM?

DOM Based XSS basically implies a Cross-site scripting weakness that shows up in the DOM (Report Item Model) rather than part of the HTML. In stored and reflected Cross-site scripting assaults you can see the weakness payload in the reaction page yet in DOM based cross-site scripting, the HTML source code and reaction of the assault will be actually the equivalent, for example the payload can’t be found in the reaction. It must be seen on runtime or by examining the DOM of the page.
DOM Based XSS wherein the hackers payload is executed because of adjusting the DOM “condition” in the casualty’s program utilized by the first customer side content with the goal that the customer side code runs in a “sudden” way. 
That is, the HTTP reaction that doesn’t change, yet the customer side code contained in the page executes contrastingly because of the vindictive adjustments that have happened in the DOM condition.
Assume, there is a site page with URL As we probably aware, “administrator” is a boundary and “1” is its worth. On the off chance that we need to play out a XSS DOM attack, we would send a content as the boundary. 

Cross Site Scripting<script>alert(document.cookie)</script>

In this model/example, the request is sent for the page home.html?admin=<script>alert(document.cookie)</script> to Accordingly for that page, a DOM object is being made by the program, where the archive area article will contain the proper string.

Cross Site Scripting<script>alert(document.cookie)</script>

Thusly the DOM condition is being influenced. Obviously, rather than this basic content, something more destructive may likewise be entered.
So now let’s talk about how can we reduce or minimize the damage caused by XSS(cross site scripting).

1. HttpOnly Flag

So, you guys might think http? why not https?, to clear this let’s under what is httponly flag?.

What is HttpOnly Flag?

As indicated by the Microsoft Developer Network, HttpOnly is an extra flag remembered for a Set-Cookie HTTP reaction header. Utilizing the HttpOnly banner while producing a cookie mitigates the danger of customer side content getting to the secured treat (if the program bolsters it).
So, mostly the attackers try to steal the document.cookie from the user/victim, then the httponly attribute blocks the  access to cookie values via JavaScript
Set httponly via Set-Cookie HTTP response header so lets see more in detail.
Set-Cookie: USER=ABC; expires=Tuesday, 15-Jul-2020 22:11:35 GMT; HttpOnly.
HttpOnly Flag Cross site scripting
This gave a lot of adaptability to engineers yet in addition permitted pernicious(malicious) scripts to read cookies esteems and send them anyplace on the Internet. In the event that an assailant had the option to abuse a XSS weakness, the principal thing they is taking any treats they could be perused. This would permit them to increase moment authoritative level access.

2. Input Validation 

It is essential where the site takes something from the clients such us boundary from URL or information from text post you can restrain the client contributions by utilizing known blacklist.
Some Examples,
  • <script> alert(1)</script>
  • <sCRipT>alert(1)</sCRiPt>
  • <scr<script>ipt>alert(1);</scr</script>ipt>
Even blocking the tags alone can’t promise that we are safe, if your trying to block all sorts of payloads and what type of string should not be allowed to enter can’t give us 100% guarantee that your data is safe, as we all know people keeps finding ways to break into system and steal data everytime new payloads are made if old one’s are not working anymore. So, how to long you are going to keep updating your input validation , so make it more effective we must do some output encoding even if someone manage to pass certain script still the output will not be shown and it can be encoded.

3. Output Encoding

Output encoding is changing input so that it cannot be interpreted as code
In HTML for some, characters can be utilized to control page characters like this should be encoded with the goal that they are not executed by the program this done using HTML
Character elements are strings of non special characters that relate to the extraordinary image. Every exceptional image that enables the program to decide the contrast between real code on the site and the client inputs therefore expelling the danger of infusions untrusted to javascript and CSS must be gotten away.

HTML Encoding

Breaks HTML document evacuating hints of culpable characters that could be unjustly deciphered as markup. The accompanying characters are saved in HTML and must be supplanted with their comparing HTML elements:
  • “ is replaced with &quot;
  • & is replaced with &amp;
  • < is replaced with &lt;
  • > is replaced with &gt; URL Encoding
e.g. & = &amp; < = &lt; > = &rt; “ = &quot;

URL Encoding

There’s another method to encode certain characters which are to type the percent sign followed by the hexadecimal portrayal for the character. This is known as Percent encoding or URL encoding. Utilizing this technique, in the event that you need to advise the PC to peruse a forward slice as information, at that point you would type in %2F. On the off chance that you need to advise the PC to peruse a solitary statement, at that point you would type in %27.

4. Enable CSP

Content Security Policy is set by the application worker to the program’s approach, where its contents and different assets are required to originate from, If the site loads assets or contents from elsewhere the program squares it right away. 
The Idea is if the aggressor attempts to stack his contents if the content won’t be on the site strategy and the program will stop it and there will be no assault. It’s a sort of white rundown approach where you whitelist the content source. 
Would we be able to consider just use CSP as relief of XSS? The appropriate response is no! CSP is an extra layer of protection from XSS assaults. The principal line of resistance is consistently a yield encoding and info approval.
Step by step instructions to set CSP, 
Set CSP by means of HTTP header, by the web worker, for the program to authorize content-Security-Policy: default-src ‘self’ * 
This will train the internet browsers to stack all assets just from the page’s beginning and JavaScript source code records also from *****

Cross Site Scripting

CSP Evaluator


If you guys want to know more about cross site scripting and how to perform them then subscribe to my website cause soon I’m going to share tools for cross site scripting and How to perform XSS attacks, do share your thoughts in the comment section and let me know what else  you guys want to see in the upcoming post suggest us some good ideas so see you guys in the next time till then goodbye.

Leave a Comment

seventeen − 8 =