Out of most penetration tests I do, XSS vulnerabilities are still probably the most common ones we encounter (if I don’t count missing Secure and HttpOnly flags on cookies :)).
Even web application vulnerability scanners have become increasingly successful in finding XSS vulnerabilities so the next question (besides why do we still see them) is related to their exploitation.
I recently encountered a simple, but interesting XSS vulnerability, which demonstrated yet again how standardization is important. So, let’s see what this is about.
However, there was a simple catch – here is what the resulting HTML code looks like and where the user supplied parameter is injected:
The contents of the injected parameter are highlighted in the HTML code shown above (also there should be < at the beginning and > at the end of the line, but ISC diary editor is giving me issues so just imagine those two characters). So, when the user submits a GET HTTP request such as this one:
The vulnerable application creates the following HTML code:
Ok – hopefully all of you see where this is going to. If we insert the " character we will close the action parameter and are practically free to do whatever we want. If we can insert the > character it’s game over.
The vulnerability shown is very simple and in most cases even web application vulnerability scanners will detect is as such.
So what’s the story here you might ask? Well, the tricky thing is in getting the victim to click on a link which will exploit the vulnerability. Remember how we need to send the " character? Well, that turns out not to be all that straightforward with modern browser. If our attacker link looks like this:
the browsers will send the following GET requests (you can test it with your own browser easily):
Mozilla Firefox: GET /myform/action/post?myparam=%22%3E%20Test
Say whaat (insert image from Anchorman 2 here)? Interesting! So, in other words, Internet Explorer is the only browser (of those three I tested) that will not encode the "> characters. This effectively allows the attacker to launch a reflected XSS attack against Internet Explorer users, while those using Mozilla Firefox and Google Chrome will be safe(r)! (so Internet Explorer is indeed less secure ….. /me ducks).
Jokes aside, why is this happening? In order to dig that out we need to check URI syntax, which is specified in RFC 3986 (https://tools.ietf.org/html/rfc3986). The RFC splits characters into several groups: unreserved characters ( ALPHA / DIGIT / "-" / "." / "_" / "~" ), reserved characters ( ":" / "/" / "?" / "#" / "[" / "]" / "@" and "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "=) and all the others.
We can see that ", < and > are in neither of the lists above! However, the RFC says the following:
“When a new URI scheme defines a component that represents textual data consisting of characters from the Universal Character Set [UCS], the data should first be encoded as octets according to the UTF-8 character encoding [STD63]; then only those octets that do not correspond to characters in the unreserved set should be percent-encoded.”
One would probably read this as the following: *everything* apart from unreserved characters should be encoded. However, while reading the RFC I missed what really “a new URI scheme” is?
In any case, it looks as Internet Explorer developers decided that they will strictly encode only reserved characters (plus some extras), but they left couple of important ones such as ", < and >.
I had a lively discussion with my colleague Marin about reporting such vulnerabilities in penetration tests. Our conclusion was to always report it (of course), even though exploitability might be more or less difficult (or even impractical) with some browsers – the underlying vulnerability is still here and should be fixed.
How does your browser behave? Let us know!Web App Penetration Testing and Ethical Hacking - SANS Pen Test Hackfest Europe 2022 - Berlin
Oct 20th 2015
|Thread locked Subscribe||
Oct 20th 2015
6 years ago