Join us
Cross-site scripting (also known as XSS) is a web security vulnerability that allows an attacker to compromise the interactions that users have with a vulnerable web application. The attacker aims to execute scripts in the victim's web browser by including malicious code on a normal web page.
These flaws that allow these types of attacks are quite widespread in web applications that have user input.
In this tutorial, you will learn how you can write a Python script from scratch to detect this vulnerability.
We gonna need to install these libraries:
Alright, let's get started:
Since this type of web vulnerability is exploited in user inputs and forms, as a result, we need to fill out any form we see with some javascript code. So, let's first make a function to get all the forms from the HTML content of any web page.
Now, this function returns a list of forms as soup objects, we need a way to extract every form's details and attributes (such as action, method, and various input attributes), the below function does exactly that:
After we got the form details, we need another function to submit any given form:
The above function takes form_details which is the output of the get_form_details() function we just wrote as an argument, that contains all form details, it also accepts the URL in which the original HTML form was put, and the value that is set to every text or search input field.
After we extract the form information, we just submit the form using requests. get() or requests.post() methods (depending on the form method).
Now that we have ready functions to extract all form details from a web page and submit them, it is easy now to scan for the XSS vulnerability now:
Here is what the function does:
Let's try this out:
This is an intended XSS vulnerable website, here is the result:
As you may see, the XSS vulnerability is successfully detected, now this code isn't perfect for any XSS vulnerable website, if you want to detect XSS for a specific website, you may need to refactor this code for your needs. The goal of this tutorial is to make you aware of this kind of attack and to basically learn how to detect XSS vulnerabilities.
Here is the source code of the article:- https://github.com/KoderKumar/Xss-Scanner
Thank you for reading my article
And if you like it give me a follow.
Join other developers and claim your FAUN account now!
Author
@arth_kumar11Influence
Total Hits
Posts
Only registered users can post comments. Please, login or signup.