Open In App

DOM-based Cross-Site Scripting Attack in Depth

In this article, we will be understanding one of the types of Cross-Site Scripting in-depth i.e DOM-based XSS. Let’s discuss it one by one as follows.

DOM-based Cross Site Scripting :



Breakdown of a DOM-based XSS attack :
The following is a breakdown of a DOM-based XSS attack as follows.

  1. Attacker discovers the DOM-based XSS vulnerability
  2. The hacker or attacker crafts a malicious script and sends the URL to the target(Email, social media, etc)
  3. Victim clicks on the URL
  4. Victims browser sends a request to the vulnerable site (note: the request does not contain the XSS malicious script)
  5. The web server responds with the web page (note: this response does not contain the XSS malicious script)
  6. Victims web browser renders the page, with the hackers or attackers XSS malicious script

Impact :



  1. Steal another client’s cookies or sessions.
  2. Modify another client’s cookies or sessions.
  3. Steal another client’s submitted form information or some sensitive credentials.
  4. Modify another client’s submitted form data or information by intercepting the request (before it reaches the server).

Note –
Submit a form to your application on the user’s behalf which modifies passwords or sensitive data on server or other application data.

Finding DOM-based Cross Site Scripting :

  1. Most DOM XSS vulnerabilities can be found rapidly and efficiently using Burp Suite’s tool scanner or some other scripts which are available on GitHub.
  2. To test for DOM-based cross-site scripting manually, you generally need to use a web browser with developer tools, such as Chrome or Firefox.
  3. You need to work through each available source or input field in turn and test each one individually.

Understanding DOM-based Attack via Diagram:

DOM XSS Steps

Diagram Description –
From the above fig, “Consider diagram arrow numbers (Step 1 to Step 6) as steps” as follows.

Example :
Example of a DOM-based XSS Attack as follows.

<HTML>
<TITLE>Hello!</TITLE>
<SCRIPT>
var pos=document.URL.indexOf("name=")+5;
document.write(document.URL.substring(pos,document.URL.length));
</SCRIPT>
<BR>
Welcome To Our Website
…
</HTML>

Explanation –
Normally, this HTML page would be used for welcoming the user, e.g –

http://www.victim.site/hello.html?name=Gaurav

However, a request such as the one below would result in an XSS condition as follows.

http://www.victim.site/hello.html?name=alert(document.domain)

Remediation from DOM-based XSS:

Note –   
The following source attributes should be avoided like URL, document URI, location, href, search, hash.

Article Tags :