XSS in Theory: Cross-Site Scripting
XSS in Theory: Cross-Site Scripting
XSS in Theory: Cross-Site Scripting
Cross-site scripting
XSS in theory
Cross-site scripting (or XSS) is the Godfather of attacks against other users. It is by
some measure the most prevalent web application vulnerability found in the wild,
afflicting literally the vast majority of live applications, including some of the most
security-critical applications on the Internet, such as those used by online banks.
Opinions vary as to the seriousness of XSS vulnerabilities.
Note that:
There are two important differences in the attack process between reflected and
stored XSS:
1. In the case of reflected XSS, to exploit vulnerability the attacker must use
some means of inducing victims to visit his crafted URL. In the case of
stored XSS, this requirement is avoided. Having deployed his attack within
the application, the attacker simply needs to wait for victims to browse to
the page or function that has been compromised. In general, this will be a
regular page of the application that normal users will access of their own
accord.
2. The attacker’s objectives in exploiting an XSS bug are usually achieved
much more easily if the victim is using the application at the time of the
attack. For example, if the user has an existing session, this can be
immediately hijacked. In a reflected XSS attack, the attacker may try to
engineer this situation by persuading the user to log in and then click on a
link that he supplies, or he may attempt to deploy a persistent payload that
waits until the user logs in. However, in a stored XSS attack, it is usually
guaranteed that victim users will be already accessing the application at the
time that the attack strikes. Because the attack payload is stored within a
page of the application that users access of their own accord, any victim of
the attack will by definition be using the application at the moment the
payload executes. Further, if the page concerned is within the authenticated
area of the application, then any victim of the attack must in addition be
logged in at the time.
The client-side JavaScript can access the browser’s document object model
(DOM), and so can determine the URL used to load the current page.
A script issued by the application may extract data from the URL, perform some
processing on this data, and then use it to dynamically update the contents of the
page
The ways to test the Cross Site Scripting will be different according to the type of
the Cross site scripting Here is the steps to test the Reflected Cross Site Scripting
1. Detect input vectors. The tester must determine the web application's variables
and how to input them in the web application.
The tester must suspect that every data entry point can result in an XSS attack. To
analyze it, the tester will play with the user variable and try to trigger the vulnerability.
Let's try to click on the following link and see what happens:
http://example.com/index.php?user=<script>alert(123)</script>
If no sanitization is applied this will result in the following popup:
This indicates that there is an XSS vulnerability and it appears that the tester can execute
code of his choice in anybody's browser if he clicks on the tester's link.
There are a lot of automated tools which can discover XSS like
HP Web Inspect, Nessus, Nikto, and some other available tools, but can only
scratch the surface. If one part of a website is vulnerable, there is a high likelihood
that there are other problems as well.
XSS tools
OWASP CAL9000: CAL9000 is a collection of web application security
testing tools that complement the feature set of current web proxies and
automated scanners.
PHP Charset Encoder (PCE) - http://h4k.in/encoding This tool helps you
encode arbitrary texts to and from 65 kinds of charsets. Also some
encoding functions featured by JavaScript are provided.
WebScarab is a framework for analysing applications that communicate
using the HTTP and HTTPS protocols.
XSS-Proxy - http://xss-proxy.sourceforge.net/ XSS-Proxy is an advanced
Cross-Site-Scripting (XSS) attack tool.
ratproxy - http://code.google.com/p/ratproxy/ A semi-automated, largely
passive web application security audit tool, optimized for an accurate and
sensitive detection, and automatic annotation, of potential problems and
security-relevant design patterns based on the observation of existing, user-
initiated traffic in complex web 2.0 environments.
Burp Proxy - http://portswigger.net/proxy/ Burp Proxy is an interactive
HTTP/S proxy server for attacking and testing web applications.
Hackvertor http://www.businessinfo.co.uk/labs/hackvertor/hackvertor.php
Hackvertor is an online tool which allows many types of encoding and
obfuscation of JavaScript (or any string input).
If the user click the link and they would be lead to the CNN News Article,
but at the same time the attacker would of been able to also direct the user
towards his specially crafted URL, he now has the users cookie.
Using the Firefox cookie editor the attacker copies and pastes the victims
cookie and uses it for himself.
o eBay
Security researcher "Side3ffects" has contacted us regarding a critical persistent
XSS that he discovered on eBay:
"Once you login to your account on eBay, edit the option "About me".
http://cgi3.ebay.com/ws/eBayISAPI.dll?AboutMeLogin
Now go to : http://members.ebay.com/ws/eBayISAPI.dll?EditUserPageHTMLSource and edit
with HTML enabled.
Demo URL
http://members.ebay.com/ws/eBayISAPI.dll?ViewUserPage&userid=shell2h4ck
It is also vulnerable to redirection with the following XSS attack vector:
'"--><script>alert(/Xss2ro07 aKa Side3ffects)</script>
<script>document.onload=location.href='http://www.xssed.com</script>"
members.ebay.com Persistent XSS mirror
One of the possible exploitation scenarios is malicious people stealing cleartext
credentials from registered users by injecting an iframe tag that retrieves another
rogue eBay login page from a remote server.
Screenshot:
Protection mechanisms
o Protect yourself as a vendor
It is a simple. Never trust user input and always filter metacharacters. This will
eliminate the majority of XSS attacks. Converting < and > to < and > is also
suggested when it comes to script output. Filtering < and > alone will not solve all
cross site scripting attacks.
It is suggested you also attempt to filter out ( and ) by translating them to (
and ) , " to " , ' to ' , and also # and & by translating them to
#(#) and & (&). A more complete list of entities can be found at
http://tntluoma.com/sidebars/codes/ .
Sometimes XSS can be executed automatically when you open an email, email
attachment, read a guestbook, or bulletin board post. If you plan on opening an
email, or reading a post on a public board from a person you don't know BE
CAREFUL. One of the best ways to protect yourself is to turn off Javascript in
your browser settings. In IE turn your security settings to high. This can prevent
cookie theft, and in general is a safer thing to do.
http://www.owasp.org/index.php/XSS_%28Cross_Site_Scripting%29_Prevention_
Cheat_Sheet
References:
The Web Application Hacker’s Handbook
OWASP TESTING GUIDE 2008 V3.0
http://www.owasp.org/index.php/Talk:Testing_for_Cross_site_scr
ipting
http://www.xssed.com/
http://www.acunetix.com/websitesecurity/cross-site-scripting.htm