Let's see this laboratory using the VVWA project, downloadable from GitHub.
It is a project developed in ASP.NET that provides various laboratories to test vulnerabilities and
understand how to mitigate them.
So we select the third menu item, Cross Site Scripting (XSS) lab.
Press the link.
OK, so press XSS lab
And OK, we can now experience the cross scripting vulnerability.
Suppose you enter a text in the text box and send it to the next page, the next page, will receive the
entered text and simply displayed it.
We can see on this page that the previous text is displayed.
Now, let's try now to insert something different, a very simple JavaScript code.
That's the malicious pattern enclosed in tag script, which executes the alert() function.
Which will display a window on the screen when executed.
OK.
So on the next page, I should see now, if the application is vulnerable, the execution of the JavaScript
code.
And that's it.
And here is the javascript code not blocked in input is sent in execution.
Let's see now how to mitigate the cross site scripting vulnerability in the code.
Let's go to the page that receives
the data sent in Post, is the page named xss_elab_aspx.cs
in C Sharp
Currently, the code does not validate the data that comes from the previous page
And I'm going to
fix with a solution that implements a validation through a regular expression.
The solution also normalize the data before submitting it to the regex
In order to avoid bypass, by transcoding the input in a different charset of characters.
Then the regular expression
defines a pattern to be searched
And then if at least one occurrence of the pattern is found the error message is printed.
vice versa the validated data is printed.
OK.
We should also.
Comment this line of code.
OK, and now.
Let's start again the application.
And inject the same pattern, malicious pattern, and the injection was blocked.