Cross-Site-Scripting

sanket narawadesanket narawade
4 min read

Here we will understand what is cross-site-scripting ? , what are the different types of cross-site-scripting ? , where we can find cross-site-scripting and Bypass ?, what are the impact and mitigation ?

Defination

When an attacker inject malicious JavaScript code into the different part of the application.

Types of XSS:

  1. Stored XSS : when an attacker inject JavaScript code into the application and it get stored into the database and whenver client interacting with database all the time JavaScript get executed.

  2. Reflected XSS : When an attacker inject the malicious JS into the application specifically into the URL Parameter of the application . Whenever some one clicked on that part automatically JS get executed.

  3. DOM XSS : When an application update the DOM with untrusted data. Untrusted data is controlled by an attacker so malicious JS get executed.

  4. Blind XSS : When an attacker inject JS into the application but it is not get fired into the application directly but in the backend application it get executed (Admin page , customer-support page).

What are the different parts in the application where we can find XSS ?

  1. If the application is using Form then check every parameter like (username , password etc ) field into the application wherever user need to provide there input .

  2. Attacker can be inject the malicious JS into the URL Parameter .

  3. Malicious JS can be executed into the HTTP Header.

  4. If application has a functionality to upload a file then attacker inject JS into that field.

  5. If the application is using Third Party Integration.

  6. If the application is sending a POST request and body consist of JSON/XML then attacker can change the Content-Type and attacker can inject the JS.

  7. If the application has some hidden parameters and in that if it using Callback function there we can inject the malicious JS.

  8. If the application is using MarkDown( MarkDown is used to add the special character into the application if we want into into website). Attacker can inject and exeute JS.

  9. Inside the application having tag like “Title“,“Style”,”Textarea” tag we can inject the javascript into the application.

Different Bypass used to execute to get XSS

  1. Firewall block the “script“ tag insted of that used “<ScRipt>alert()<ScRipt>“ in case insensitive.

  2. Script tag used Second Occurence “<u> test123<script>alert()</script><script>alert()</script)“.

  3. If Firewall blocks the script tag used Event Handler like ( onclick , onload , onerror etc).

  4. If any Tag is used Attribute Paramter there used to add JS payload (<u> test123<iframe src=javascript:alert()>).

  5. To check the reflection into the website don’t close the Tag.

  6. Sending JS payload all the parameter put it into the “Encoded“ form like (Octal , Unicode ,Base64, HTML encoding) so that easily bypass.

  7. Remove the closing tag (<script>alert()//).

  8. Payload <aAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa href= javascript:alert()>XSS</a>.

  9. Using Backtick insted of parenethess (<script>alert XSS </script>).

  10. Prepending an additional “<“ ( «script>alert()</script>).

Vulnerability that can be chain with XSS

  1. XSS + CSRF : If the attacker can inject the JS into the application then it can easy for them to grab the CSRF token with the help of that token attacker can do the any changes into that account ( Account Takeover)

  2. XSS + privilege escalation : Attacker can be used XSS to get the session token of the user to escalate privilege escalation.

Impact

  1. Trust issue : if application is compromised to XSS it might be flagged as unsafe . This can lead to loss of reputation , user trust .

  2. Phishing Attack : If application is compromised to XSS . user is tricked into providing sensitive information like usernames, password , payment details.

  3. Malaware Distribution : Scripts can be used to automatically download or excute a malware into users device this can lead to attacker get access to personal device , cameras etc.

Mitigation

  1. Always Check if user providing correct input or not . if not restrict.

  2. To mitigate XSS use CSP (Content-Security-Policy) value “strict and self“

  3. use Header “X-XSS-Protection“ to mitigate XSS vulnerability.

  4. Protect the cookies from being accessed by JavaScript by setting “HTTP-Only“ flag and additional use flag “Secure“ cookies transfer over “HTTPS“

  5. Use JavaScript library to help to mitigate XSS (DOMpurify , XSS, Jsoup)

0
Subscribe to my newsletter

Read articles from sanket narawade directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

sanket narawade
sanket narawade