Cross Site Scripting (XSS) Attack Types & Prevention

Cross Site Scripting (XSS) Attack Types & Prevention

Introduction :

Cross Site Scripting(XSS) is the popular and vulnerable attack which is known by every advanced tester. It is considered as one of the adventurous attacks for web applications and can bring harmful results also. This attack is considered adventurous, because of its ability to damage even less vulnerable technologies.

How XSS Being Performed :

Cross Site Scripting attack means sending and injecting malicious script or code. Javascript and HTML are mostly used to perform this attack, the main reason for such type of attack is inappropriate user’s input validation. A malicious user can enter scripts, which will be injected into the website’s code then browser is not able to identify if the executed code is malicious or not.

Common cause of XSS :

  • Cross Site Scripting can occur at client side by executing malicious script.
  • Fake page or form or advertisement displayed to the users (where the victim type credentials or clicks a malicious link).
  • Malicious emails sent to the victim with malicious link.

Example :

If the below search field is vulnerable then user can enter any script and it will be executed.

For example consider user enters very simple script as shown below:

<script>alert(‘XSS’)</script>

xss

As in this Example, the script typed into the search field gets executed. This just shows the

vulnerability of the XSS attack. However, a more harmful script may be typed as well.

Types of Cross-Site Scripting Attacks :

This attack is divided into three main categories which are shown below:

1) Reflected XSS – This attack occurs when malicious scripts are not being saved on the web server but reflected in the website’s results.

2) Stored XSS – This attack occurs when malicious scripts are being saved on the web server permanently.

3) DOM – This occurs, when the DOM environment is being changed without any actual change in DOM itself.

How to Test Against XSS :

In order to test against XSS attack, black box testing can be performed. That means it can be tested without a code review. However, code review is always a recommended practice and it brings up more credible results. From our testing experience, We would like to add that if a good black box testing technique is selected and performed accurately, then we will also be able to identify maximum vulnerabilities.

For Example, a tester may try to type in the browser script

Like: <script>alert(document.cookie)</script>

xss1

If this script is being executed, then there is a huge possibility that means XSS is possible. Also while testing manually for possible Cross-Site Scripting attacks, it is important to remember, that encoded brackets should also be tried.

XSS Testing Tools :

As Cross Site Scripting attack is one of the most popular risky attacks, there are many tools to test it automatically. We can find various scanners to check for possible XSS attack vulnerabilities – like, Nessus and Nikto. Both of which are considered quite reliable.

From our experience, we would like to recommend ZAP (Zed Attack Proxy) tool.

Comparison with Other Attacks :

XSS is considered to be one of the risky attacks, as its main purpose is to hack the website’s or system’s user identities. Also, the XSS attack can be performed with different client-side languages like Javascript, HTML, VBScript, Flash, etc. and this makes it more noxious and widespread than the other possible attacks.

Another thing that makes this attack risky is the possibility to be stored in the web service – this way it can affect many users for a longer period of time. XSS sometimes can be performed to even less vulnerable system and its vulnerabilities are sometimes difficult to be found.

Ways to Prevent XSS :

Though such type of attack is considered to be one of the most dangerous and risky one, so preventing plan should be prepared. Because of the popularity of this attack, there are many ways to prevent it.

Commonly used below prevention methods include:

  • Data validation
  • Filtering
  • Escaping

XSS Cheat Sheets

XSS Cheat Sheets can be very useful for cross-site scripting prevention. It is a simple guideline for the developers on how to prevent XSS attacks. The rules are very helpful and should not be forgotten while developing the application. XSS Cheat Sheets can be found in internet communities such as OWASP (The Open Web Application Security Project).

https://cheatsheetseries.owasp.org/cheatsheets/Cross_Site_Scripting_Prevention_Cheat_Sheet.html

Conclusion :

While testing, it is highly recommended to evaluate the risks that bring up possible XSS attacks. XSS attack can affect many web applications that seem to be secure as well. While performing test against XSS, it is important to have good understanding about this attack. It is important to choose the appropriate testing tool and to analyze testing results correctly.

Share this post