If the website is vulnerable it will display the attacker's image into the result
webpage.
Try then to write some JavaScript code:
http:///www.example.com/search.php?text=
Probably the website will return an alert popup with the current Cookie for the
site itself.
That's not good at all ;)
As you will see the vulnerable website will execute any JavaScript code you
want to be run: sometimes you can find that the website make some filters on " "
and ' ', but that's not really a big problem for us :D
This vulnerability can be used by the attacker to steal informations to users
of the victim website providing them for example an email with an URL like:
http://www.victim.com/search.php?text=MALICIOUSCODE
To make that url less suspicious it will be useful to encode the code in URL Hex value.
You can apply this tecnique using our Playhack - Encoder service reachable at
http://encoder.playhack.net
(Beware that it's created for informational purpose only :P).
For example the code:
Encoded will look like:
%3C%73%63%72%69%70%74%3E%61%6C%65%72%74%28%22%58%53%53%22%29%3B%3C
%2F%73%63%72%69%70%74%3E
And as comes the malicious url will turn from:
http://www.victim.com/search.php?text=
Into:
http://www.victim.com/search.php?text=%3C%73%63%72%69%70%74%3E%61%6C%65%72%74%28%22
%58%53%53%22%29%3B%3C%2F%73%63%72%69%70%74%3E
Which, for a clueless user, it's lot less suspicious than the first one.
Let's analize an example attack.
- The attacker realizes that the victim website is vulnerable to XSS
- The attacker creates on his website an ad-hoc page which is studied to steal
sensible informations like cookies or to make a fake login of the victim website.
- The attacker provides to a user a crafted url which contains a malicious
code like:
http://www.victim.com/search.php?text=
Encoded in Hex.
- The user visits the webpage and is obscurely redirect the attacker's fakelogin
- The user is invited to log into the system and he does.
- The fakelogin steals the username and password of the victim.
Solution:
The solution to this issue is simply to make a check to the input code in the website
avoiding HTML tags or accepting alpha-numerical characters only, with for example
codes like:
- Python: cgi.escape($code)
- PHP: eregi("[^a-zA-Z0-9_]", $code)
$code = htmlentities($code)
And many others.
-----------------------------------------------------------------------------[/]
------[ 0x03c: Persistent ]
The persistent XSS vulnerabilities are similar to the second type (Non-persistent XSS),
because both works on a victim site and tries to hack users informations;
the difference is that in websites vulnerables to Persistent XSS the attacker
doesn't need to provide the crafted url to the users, because the website
itself permits to users to insert fixed data into the system: this is the case
for example of "guestbooks" (what an awful item !!)
Usually the users uses that kind of tool to leave messages to the owned of the
website and at a first look it doesn't seems something dangerous, but if an attacker
discover that the system is vulnerable can insert some malicious code in his message
and let ALL visitors to be victim of that.
This works when the tool provided (the guestbook in the example) doesn't do any check
on the content of the inserted message: it just inserts the data provided from the user
into the result page.
The attacker could easily insert as much code as he wants into the tool, for example: