Cross Site Scripting XSS in Action
Cross Site Scripting XSS in Action
XSS Overview
XSS (Cross Site Scripting) is one of the most common security
threats of the web applications from today. According to the Web Hacking
Incident Database for 2011 [1], XSS is occupying the third place (7.3%)
in the all the time top (1999-2011) of the attack methods, as illustrated
into the chart below.
Page 3 Oeconomics of Knowledge, Volume 4, Issue 3, 3Q, Summer 2012
XSS is a method used to steal data from users by infecting the web
pages with malicious scripts (VBScript, JavaScript, ActiveX, Flash) in
order to collect sensitive content from the victim. XSS is aiming the
dynamic web pages that are interpreted by the web-browsers, so the
malicious scripts will be executed locally on the user’s machine and
sensitive data gathered in this way will be transferred from the victim’s
computer to the attacker’s location. Usually, attackers spread malicious
links over the internet, waiting for the users to click [2].
Page 4 Oeconomics of Knowledge, Volume 4, Issue 3, 3Q, Summer 2012
Most of the XSS attacks are using the <SCRIPT> tag in order to
activate the malicious content on the user’s web page that is interpreted
locally. The tag may activate an embedded script or an external one:
There are other HTML tags where the script can be injected [4], like
BODY, IMG, LINK, INPUT, TABLE, DIV, OBJECT, EMBED, and so on .
The typical example covers the applications that are using queries
with parameters. In order to allow the bookmarking, usually the values of
the parameters are placed inside the URL.
Let’s imagine a very simple search engine where the user is using a
textbox to provide the text to be located and, by pressing the search
button, the application will show the text together with the list of the
results.
http://www.mysearchtool.org/locate.php?searchstring=XSS
http://www.mysearchtool.org/locate.php?searchstring=<script>alert
(―XSS‖)</script>
How to prevent such situations? The answer is very simple: any web
application that is displaying the user input must validate the content
before being included into the output page. Normally, the web server
Page 6 Oeconomics of Knowledge, Volume 4, Issue 3, 3Q, Summer 2012
should filter the user input in order to remove the content that may
create problems.
In the upper-right part of the page, there is a search box that can be
used to quickly locate a specific content. For example, if the user is
interested to find out resources related to european legislation, the
search box could be a very convenient option (Figure 4).
As we can notice, the page contains not only the results, but also the
originally entered string, so it seems to be a very good candidate for an
XSS attack.
We will use the search box located into the upper-right part of the
page in order to inject a java script able to reveal the user’s cookie
content (Figure 5) - <script>alert(document.cookie)</script>.
Page 8 Oeconomics of Knowledge, Volume 4, Issue 3, 3Q, Summer 2012
Conclusions
The XSS attacks are very common today mainly because the
technique is very simple and the results appear quite easy, as we saw in
the example presented above. How to prevent such attacks? The answer
is the validation of the user input.
The first step will be to filter the content by removing any dangerous
keyword, like the <SCRIPT> tag. This can be done by adding some code
to the web application or by using dedicated libraries. Of course the
filters may remove also some valid text, so such filters must be used with
care.
References
[1] Web Hacking Incident Database - http://
projects.webappsec.org/w/page/13246995/Web -Hacking-
Incident-Database