SlideShare a Scribd company logo
Cross Site Scripting
Detection and Prevention
~Aman Kumar
Cross Site Scripting
Detection and
Prevention
What is cross-site scripting?
• Cross-Site Scripting (referred to as XSS) is a type of web application attack
where malicious client-side script is injected into the application output and
subsequently executed by the user’s browser.
• It can be used to take over a user’s browser in a variety of ways
2
Why should I care about cross-site scripting?
•There was a time not too long ago when XSS was considered a low-risk
type of security issue, because when compared to a server-side exploit, it
seemed relatively low.
•As other issues like PHP remote file inclusions have become harder to
exploit, XSS attacks have increased in prominence and sophistication.
3
Who’s affected by cross-site scripting?
Everyone. No, really – almost every site you can think of has had XSS problems
at one time or another (and probably still does)
Don’t believe me?
• Universal XSS in Internet Explorer (2015) [1]
• Tweetdeck (2014) [2]
• PayPal (2013) – BONUS: discovered by a 17 year old kid [3]
• Google Finance (2013) [4]
• 25 “Verasign-secured” online stores (2012) [5]
• McAfee (2011) [6]
• Visa (2010) [7]
4
5
Some sites you might recognize
http://www.xssed.com/files/image/News/paypalevsslxss.PNG
Object Placeholder
6www.rackspace.com
Some sites you might recognize
http://3.bp.blogspot.com/-IpLMWEVPnRc/UmYV_19hnNI/AAAAAAAADfc/caJdmBEsyaE/s1600/1.png
Object Placeholder
7
Some sites you might recognize
https://isc.sans.edu/diaryimages/youtube.png
Boooooring…
The classic proof-of-concept for XSS is a little alert box with some arbitrary text in
it, or a picture of something silly. This doesn’t seem nearly dangerous enough to
warrant concern.
What else you got?
8
•Steal cookies
•Play a sound
•Get user-agent string
•See enabled plugins (e.g. Chrome PDF viewer, Java, etc.)
9
Basic Client-side Attacks
•Man-in-the-browser
•Forge user requests
•Get form values / HTML contents
•Fake notifications (Chrome plugin bar, LastPass login, etc.)
•Tabnabbing
10
More Advanced Client-Side Attacks
www.rackspace.com
•Man-in-the-browser
•Forge user requests
•Get form values / HTML contents
•Fake notifications (Chrome plugin bar, LastPass login, etc.)
•Tabnabbing
11
More Advanced Client-Side Attacks
www.rackspace.com
• Never trust the user
• Never trust the user
• Never trust the user
• Never trust the user
• Never trust the user
• Never trust the user
• Never trust the user
• Never trust the user
So what should I do to prevent XSS?
12
• Almost all client-side script injection comes down to the following characters:
< > ( ) { } [ ] " ' ; / 
• There are various ways to take care of these characters, but it is too context-
dependent to give a one-size-fits-all answer
• The shortest answer is, make sure you’re only getting characters you expect
when a user enters any kind of information - make sure you never display a
user-entered string without properly encoding it.
So what should I do to prevent XSS? (No, really)
13www.rackspace.com
Here’s some sample vulnerable JavaScript.
<html>
<script>
var lol = function () {
var a = document.getElementById('a').value;
document.write(a);
}
</script>
<input type="text" name="a" id="a">
<input type="submit" onclick="lol();">
</html>
14
Examples of XSS in code
Hmm, there’s the problem…
<html>
<script>
var lol = function () {
var a = document.getElementById('a').value;
document.write(a); // Too easy
}
</script>
<input type="text" name="a" id="a">
<input type="submit" onclick="lol();">
</html>
15
Examples of XSS in code
Now for something a little more interesting. Remember, we also have to
remember the third-party libraries you’re using.
Some innocent-looking jQuery code:
$(location.hash) // Wait, that’s it?
16
Examples of XSS in code
But you’re not only securing the code you write, but all the code you used…
$(location.hash) // WHERE’S THE VULNERABLE PART?!
Well, if we’re using jQuery 1.6.1 and we visit the page
http://app/#<img src=/ onerror=alert(1)>
…this will pop up one of those alert boxes [8].
17
Examples of XSS in code
Here are some examples of how to filter HTML characters in a few simple
scenarios in PHP (there should be similar functions in any language; check the
links at the end of the PPT)
$int = intval($_GET['a']); // This will never return anything other than an integer
$str = htmlentities($_GET['b']); // This will encode any character for which there is
// an HTML entity equivalent (e.g. &gt; &lt; &quot;)
// This is NOT always enough! [9]
18
Tips for filtering XSS
Pop quiz! What’s wrong with this PHP code:
echo('<a href="' . htmlentities($_GET['var']) . '">link</a>');
19
Getting around prevention measures
Pop quiz! What’s wrong with this PHP code:
echo('<a href="' . htmlentities($_GET['var']) . '">link</a>');
What if we set $_GET['var'] to javascript:alert(/xss/);
20
Getting around prevention measures
21
• OWASP Links
– Guide to Cross-site Scripting - https://www.owasp.org/index.php/Cross-site_Scripting_(XSS)
– XSS Prevention Cheat Sheet - https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet
– DOM based XSS Prevention Cheat Sheet - https://www.owasp.org/index.php/DOM_based_XSS_Prevention_Cheat_Sheet
22
Resources
• [1] http://seclists.org/fulldisclosure/2015/Feb/0
• [2] http://techcrunch.com/2014/06/11/tweetdeck-fixes-xss-vulnerability/
• [3] http://threatpost.com/paypal-site-vulnerable-to-xss-attack
• [4] http://miki.it/blog/2013/7/30/xss-in-google-finance/
• [5] http://nakedsecurity.sophos.com/2012/02/28/verisign-xss-holes/
• [6] http://www.scmagazine.com/mcafee-working-to-fix-xss-information-disclosure-flaws/article/199505/
• [7] http://news.softpedia.com/news/XSS-Weakness-Found-on-Visa-USA-Website-157115.shtml
• [8] http://ma.la/jquery_xss/
• [9] http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references
23
References
Thank You

More Related Content

What's hot (20)

Cross Site Scripting Defense Presentation
Cross Site Scripting Defense Presentation Cross Site Scripting Defense Presentation
Cross Site Scripting Defense Presentation
Ikhade Maro Igbape
 
Security in NodeJS applications
Security in NodeJS applicationsSecurity in NodeJS applications
Security in NodeJS applications
Daniel Garcia (a.k.a cr0hn)
 
Cross site scripting attacks and defenses
Cross site scripting attacks and defensesCross site scripting attacks and defenses
Cross site scripting attacks and defenses
Mohammed A. Imran
 
Reflective and Stored XSS- Cross Site Scripting
Reflective and Stored XSS- Cross Site ScriptingReflective and Stored XSS- Cross Site Scripting
Reflective and Stored XSS- Cross Site Scripting
InMobi Technology
 
Cross Site Scripting (XSS)
Cross Site Scripting (XSS)Cross Site Scripting (XSS)
Cross Site Scripting (XSS)
Barrel Software
 
Cross site scripting (xss)
Cross site scripting (xss)Cross site scripting (xss)
Cross site scripting (xss)
Manish Kumar
 
Cross Site Request Forgery Vulnerabilities
Cross Site Request Forgery VulnerabilitiesCross Site Request Forgery Vulnerabilities
Cross Site Request Forgery Vulnerabilities
Marco Morana
 
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
Sandeep Kumbhar
 
Introduction XSS
Introduction XSSIntroduction XSS
Introduction XSS
Aymeric Lagier
 
XSS - Attacks & Defense
XSS - Attacks & DefenseXSS - Attacks & Defense
XSS - Attacks & Defense
Blueinfy Solutions
 
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
 
Basics of Server Side Template Injection
Basics of Server Side Template InjectionBasics of Server Side Template Injection
Basics of Server Side Template Injection
Vandana Verma
 
Cross site scripting
Cross site scriptingCross site scripting
Cross site scripting
kinish kumar
 
Web vulnerabilities
Web vulnerabilitiesWeb vulnerabilities
Web vulnerabilities
Krishna Gehlot
 
Sql injection - security testing
Sql injection - security testingSql injection - security testing
Sql injection - security testing
Napendra Singh
 
Server-side template injection- Slides
Server-side template injection- Slides Server-side template injection- Slides
Server-side template injection- Slides
Amit Dubey
 
Web Application Security and Awareness
Web Application Security and AwarenessWeb Application Security and Awareness
Web Application Security and Awareness
Abdul Rahman Sherzad
 
Xss attack
Xss attackXss attack
Xss attack
Manjushree Mashal
 
SQL INJECTION
SQL INJECTIONSQL INJECTION
SQL INJECTION
Mentorcs
 
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 attacks and defenses
Cross site scripting attacks and defensesCross site scripting attacks and defenses
Cross site scripting attacks and defenses
Mohammed A. Imran
 
Reflective and Stored XSS- Cross Site Scripting
Reflective and Stored XSS- Cross Site ScriptingReflective and Stored XSS- Cross Site Scripting
Reflective and Stored XSS- Cross Site Scripting
InMobi Technology
 
Cross Site Scripting (XSS)
Cross Site Scripting (XSS)Cross Site Scripting (XSS)
Cross Site Scripting (XSS)
Barrel Software
 
Cross site scripting (xss)
Cross site scripting (xss)Cross site scripting (xss)
Cross site scripting (xss)
Manish Kumar
 
Cross Site Request Forgery Vulnerabilities
Cross Site Request Forgery VulnerabilitiesCross Site Request Forgery Vulnerabilities
Cross Site Request Forgery Vulnerabilities
Marco Morana
 
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
Sandeep Kumbhar
 
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
 
Basics of Server Side Template Injection
Basics of Server Side Template InjectionBasics of Server Side Template Injection
Basics of Server Side Template Injection
Vandana Verma
 
Cross site scripting
Cross site scriptingCross site scripting
Cross site scripting
kinish kumar
 
Sql injection - security testing
Sql injection - security testingSql injection - security testing
Sql injection - security testing
Napendra Singh
 
Server-side template injection- Slides
Server-side template injection- Slides Server-side template injection- Slides
Server-side template injection- Slides
Amit Dubey
 
Web Application Security and Awareness
Web Application Security and AwarenessWeb Application Security and Awareness
Web Application Security and Awareness
Abdul Rahman Sherzad
 
SQL INJECTION
SQL INJECTIONSQL INJECTION
SQL INJECTION
Mentorcs
 

Similar to Cross Site Scripting: Prevention and Detection(XSS) (20)

CROSS SITE SCRIPTING.ppt
CROSS SITE SCRIPTING.pptCROSS SITE SCRIPTING.ppt
CROSS SITE SCRIPTING.ppt
yashvirsingh48
 
Pantallas escaneo Sitio Web
Pantallas escaneo Sitio WebPantallas escaneo Sitio Web
Pantallas escaneo Sitio Web
andres1422
 
XSS.pdf
XSS.pdfXSS.pdf
XSS.pdf
Okan YILDIZ
 
XSS.pdf
XSS.pdfXSS.pdf
XSS.pdf
Okan YILDIZ
 
Owasp Top 10 A3: Cross Site Scripting (XSS)
Owasp Top 10 A3: Cross Site Scripting (XSS)Owasp Top 10 A3: Cross Site Scripting (XSS)
Owasp Top 10 A3: Cross Site Scripting (XSS)
Michael Hendrickx
 
Cross site scripting
Cross site scripting Cross site scripting
Cross site scripting
Bilal Mazhar MS(IS)Cyber Security II Privacy Professional
 
Cross-Site Scripting course made by Cristian Alexandrescu
Cross-Site Scripting course made by Cristian Alexandrescu Cross-Site Scripting course made by Cristian Alexandrescu
Cross-Site Scripting course made by Cristian Alexandrescu
Cristian Alexandrescu
 
Xss 101
Xss 101Xss 101
Xss 101
n|u - The Open Security Community
 
Xss 101 by-sai-shanthan
Xss 101 by-sai-shanthanXss 101 by-sai-shanthan
Xss 101 by-sai-shanthan
Raghunath G
 
Cross Site Scripting (XSS)
Cross Site Scripting (XSS)Cross Site Scripting (XSS)
Cross Site Scripting (XSS)
Avi Aryan
 
Complete xss walkthrough
Complete xss walkthroughComplete xss walkthrough
Complete xss walkthrough
Ahmed Elhady Mohamed
 
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
Michael Coates
 
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
 
XSS
XSSXSS
XSS
Hrishikesh Mishra
 
XSS Primer - Noob to Pro in 1 hour
XSS Primer - Noob to Pro in 1 hourXSS Primer - Noob to Pro in 1 hour
XSS Primer - Noob to Pro in 1 hour
snoopythesecuritydog
 
Web Hacking Series Part 4
Web Hacking Series Part 4Web Hacking Series Part 4
Web Hacking Series Part 4
Aditya Kamat
 
Lec4-WebClientSideExploitation.pptxdslkjhgfkjdshgfkjfhdkjg
Lec4-WebClientSideExploitation.pptxdslkjhgfkjdshgfkjfhdkjgLec4-WebClientSideExploitation.pptxdslkjhgfkjdshgfkjfhdkjg
Lec4-WebClientSideExploitation.pptxdslkjhgfkjdshgfkjfhdkjg
arfaouisalim
 
Cross Site scripting Attacks - by Adam Nurudini
Cross Site scripting Attacks - by Adam NurudiniCross Site scripting Attacks - by Adam Nurudini
Cross Site scripting Attacks - by Adam Nurudini
Adam Nurudini
 
XSS Exploitation
XSS ExploitationXSS Exploitation
XSS Exploitation
Hacking Articles
 
Cross site scripting
Cross site scriptingCross site scripting
Cross site scripting
ashutosh rai
 
CROSS SITE SCRIPTING.ppt
CROSS SITE SCRIPTING.pptCROSS SITE SCRIPTING.ppt
CROSS SITE SCRIPTING.ppt
yashvirsingh48
 
Pantallas escaneo Sitio Web
Pantallas escaneo Sitio WebPantallas escaneo Sitio Web
Pantallas escaneo Sitio Web
andres1422
 
Owasp Top 10 A3: Cross Site Scripting (XSS)
Owasp Top 10 A3: Cross Site Scripting (XSS)Owasp Top 10 A3: Cross Site Scripting (XSS)
Owasp Top 10 A3: Cross Site Scripting (XSS)
Michael Hendrickx
 
Cross-Site Scripting course made by Cristian Alexandrescu
Cross-Site Scripting course made by Cristian Alexandrescu Cross-Site Scripting course made by Cristian Alexandrescu
Cross-Site Scripting course made by Cristian Alexandrescu
Cristian Alexandrescu
 
Xss 101 by-sai-shanthan
Xss 101 by-sai-shanthanXss 101 by-sai-shanthan
Xss 101 by-sai-shanthan
Raghunath G
 
Cross Site Scripting (XSS)
Cross Site Scripting (XSS)Cross Site Scripting (XSS)
Cross Site Scripting (XSS)
Avi Aryan
 
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
Michael Coates
 
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
 
XSS Primer - Noob to Pro in 1 hour
XSS Primer - Noob to Pro in 1 hourXSS Primer - Noob to Pro in 1 hour
XSS Primer - Noob to Pro in 1 hour
snoopythesecuritydog
 
Web Hacking Series Part 4
Web Hacking Series Part 4Web Hacking Series Part 4
Web Hacking Series Part 4
Aditya Kamat
 
Lec4-WebClientSideExploitation.pptxdslkjhgfkjdshgfkjfhdkjg
Lec4-WebClientSideExploitation.pptxdslkjhgfkjdshgfkjfhdkjgLec4-WebClientSideExploitation.pptxdslkjhgfkjdshgfkjfhdkjg
Lec4-WebClientSideExploitation.pptxdslkjhgfkjdshgfkjfhdkjg
arfaouisalim
 
Cross Site scripting Attacks - by Adam Nurudini
Cross Site scripting Attacks - by Adam NurudiniCross Site scripting Attacks - by Adam Nurudini
Cross Site scripting Attacks - by Adam Nurudini
Adam Nurudini
 
Cross site scripting
Cross site scriptingCross site scripting
Cross site scripting
ashutosh rai
 

Recently uploaded (20)

Scilab Chemical Engineering application.pptx
Scilab Chemical Engineering  application.pptxScilab Chemical Engineering  application.pptx
Scilab Chemical Engineering application.pptx
OmPandey85
 
Comprehensive Guide to Distribution Line Design
Comprehensive Guide to Distribution Line DesignComprehensive Guide to Distribution Line Design
Comprehensive Guide to Distribution Line Design
Radharaman48
 
elastic-plasticfracturemechanics-170722055208.pdf
elastic-plasticfracturemechanics-170722055208.pdfelastic-plasticfracturemechanics-170722055208.pdf
elastic-plasticfracturemechanics-170722055208.pdf
lsolanoni
 
Software_Engineering_in_6_Hours_lyst1728638742594.pdf
Software_Engineering_in_6_Hours_lyst1728638742594.pdfSoftware_Engineering_in_6_Hours_lyst1728638742594.pdf
Software_Engineering_in_6_Hours_lyst1728638742594.pdf
VanshMunjal7
 
MS Project - Pelaksanaan Proyek Fisik 2020
MS Project - Pelaksanaan Proyek Fisik 2020MS Project - Pelaksanaan Proyek Fisik 2020
MS Project - Pelaksanaan Proyek Fisik 2020
Bagus ardian
 
Air Filter Flat Sheet Media-Catalouge-Final.pdf
Air Filter Flat Sheet Media-Catalouge-Final.pdfAir Filter Flat Sheet Media-Catalouge-Final.pdf
Air Filter Flat Sheet Media-Catalouge-Final.pdf
FILTRATION ENGINEERING & CUNSULTANT
 
ResearchTalks #4. Have you been listening ? Because we have !
ResearchTalks #4. Have you been listening ? Because we have !ResearchTalks #4. Have you been listening ? Because we have !
ResearchTalks #4. Have you been listening ? Because we have !
ResearchTalks Conferences
 
1.9 Class,Object,Class Scope,Accessing Class members and Controlling access t...
1.9 Class,Object,Class Scope,Accessing Class members and Controlling access t...1.9 Class,Object,Class Scope,Accessing Class members and Controlling access t...
1.9 Class,Object,Class Scope,Accessing Class members and Controlling access t...
VikasNirgude2
 
Introduction to Machine Vision by Cognex
Introduction to Machine Vision by CognexIntroduction to Machine Vision by Cognex
Introduction to Machine Vision by Cognex
RicardoCunha203173
 
Department of Environment (DOE) Mix Design with Fly Ash.
Department of Environment (DOE) Mix Design with Fly Ash.Department of Environment (DOE) Mix Design with Fly Ash.
Department of Environment (DOE) Mix Design with Fly Ash.
MdManikurRahman
 
Ceramic Multichannel Membrane Structure with Tunable Properties by Sol-Gel Me...
Ceramic Multichannel Membrane Structure with Tunable Properties by Sol-Gel Me...Ceramic Multichannel Membrane Structure with Tunable Properties by Sol-Gel Me...
Ceramic Multichannel Membrane Structure with Tunable Properties by Sol-Gel Me...
DanyalNaseer3
 
ENERGY STORING DEVICES-Primary Battery.pdf
ENERGY STORING DEVICES-Primary Battery.pdfENERGY STORING DEVICES-Primary Battery.pdf
ENERGY STORING DEVICES-Primary Battery.pdf
TAMILISAI R
 
world subdivision.pdf...................
world subdivision.pdf...................world subdivision.pdf...................
world subdivision.pdf...................
bmmederos10
 
Dr. Shivu___Machine Learning_Module 2pdf
Dr. Shivu___Machine Learning_Module 2pdfDr. Shivu___Machine Learning_Module 2pdf
Dr. Shivu___Machine Learning_Module 2pdf
Dr. Shivashankar
 
Filters for Electromagnetic Compatibility Applications
Filters for Electromagnetic Compatibility ApplicationsFilters for Electromagnetic Compatibility Applications
Filters for Electromagnetic Compatibility Applications
Mathias Magdowski
 
22PCOAM16 Machine Learning Unit V Full notes & QB
22PCOAM16 Machine Learning Unit V Full notes & QB22PCOAM16 Machine Learning Unit V Full notes & QB
22PCOAM16 Machine Learning Unit V Full notes & QB
Guru Nanak Technical Institutions
 
Introduction-to-Prestressed-Concrete.pdf
Introduction-to-Prestressed-Concrete.pdfIntroduction-to-Prestressed-Concrete.pdf
Introduction-to-Prestressed-Concrete.pdf
Bharti Shinde
 
Video Games and Artificial-Realities.pptx
Video Games and Artificial-Realities.pptxVideo Games and Artificial-Realities.pptx
Video Games and Artificial-Realities.pptx
HadiBadri1
 
DE-UNIT-V MEMORY DEVICES AND DIGITAL INTEGRATED CIRCUITS
DE-UNIT-V MEMORY DEVICES AND DIGITAL INTEGRATED CIRCUITSDE-UNIT-V MEMORY DEVICES AND DIGITAL INTEGRATED CIRCUITS
DE-UNIT-V MEMORY DEVICES AND DIGITAL INTEGRATED CIRCUITS
Sridhar191373
 
Better Builder Magazine, Issue 53 / Spring 2025
Better Builder Magazine, Issue 53 / Spring 2025Better Builder Magazine, Issue 53 / Spring 2025
Better Builder Magazine, Issue 53 / Spring 2025
Better Builder Magazine
 
Scilab Chemical Engineering application.pptx
Scilab Chemical Engineering  application.pptxScilab Chemical Engineering  application.pptx
Scilab Chemical Engineering application.pptx
OmPandey85
 
Comprehensive Guide to Distribution Line Design
Comprehensive Guide to Distribution Line DesignComprehensive Guide to Distribution Line Design
Comprehensive Guide to Distribution Line Design
Radharaman48
 
elastic-plasticfracturemechanics-170722055208.pdf
elastic-plasticfracturemechanics-170722055208.pdfelastic-plasticfracturemechanics-170722055208.pdf
elastic-plasticfracturemechanics-170722055208.pdf
lsolanoni
 
Software_Engineering_in_6_Hours_lyst1728638742594.pdf
Software_Engineering_in_6_Hours_lyst1728638742594.pdfSoftware_Engineering_in_6_Hours_lyst1728638742594.pdf
Software_Engineering_in_6_Hours_lyst1728638742594.pdf
VanshMunjal7
 
MS Project - Pelaksanaan Proyek Fisik 2020
MS Project - Pelaksanaan Proyek Fisik 2020MS Project - Pelaksanaan Proyek Fisik 2020
MS Project - Pelaksanaan Proyek Fisik 2020
Bagus ardian
 
ResearchTalks #4. Have you been listening ? Because we have !
ResearchTalks #4. Have you been listening ? Because we have !ResearchTalks #4. Have you been listening ? Because we have !
ResearchTalks #4. Have you been listening ? Because we have !
ResearchTalks Conferences
 
1.9 Class,Object,Class Scope,Accessing Class members and Controlling access t...
1.9 Class,Object,Class Scope,Accessing Class members and Controlling access t...1.9 Class,Object,Class Scope,Accessing Class members and Controlling access t...
1.9 Class,Object,Class Scope,Accessing Class members and Controlling access t...
VikasNirgude2
 
Introduction to Machine Vision by Cognex
Introduction to Machine Vision by CognexIntroduction to Machine Vision by Cognex
Introduction to Machine Vision by Cognex
RicardoCunha203173
 
Department of Environment (DOE) Mix Design with Fly Ash.
Department of Environment (DOE) Mix Design with Fly Ash.Department of Environment (DOE) Mix Design with Fly Ash.
Department of Environment (DOE) Mix Design with Fly Ash.
MdManikurRahman
 
Ceramic Multichannel Membrane Structure with Tunable Properties by Sol-Gel Me...
Ceramic Multichannel Membrane Structure with Tunable Properties by Sol-Gel Me...Ceramic Multichannel Membrane Structure with Tunable Properties by Sol-Gel Me...
Ceramic Multichannel Membrane Structure with Tunable Properties by Sol-Gel Me...
DanyalNaseer3
 
ENERGY STORING DEVICES-Primary Battery.pdf
ENERGY STORING DEVICES-Primary Battery.pdfENERGY STORING DEVICES-Primary Battery.pdf
ENERGY STORING DEVICES-Primary Battery.pdf
TAMILISAI R
 
world subdivision.pdf...................
world subdivision.pdf...................world subdivision.pdf...................
world subdivision.pdf...................
bmmederos10
 
Dr. Shivu___Machine Learning_Module 2pdf
Dr. Shivu___Machine Learning_Module 2pdfDr. Shivu___Machine Learning_Module 2pdf
Dr. Shivu___Machine Learning_Module 2pdf
Dr. Shivashankar
 
Filters for Electromagnetic Compatibility Applications
Filters for Electromagnetic Compatibility ApplicationsFilters for Electromagnetic Compatibility Applications
Filters for Electromagnetic Compatibility Applications
Mathias Magdowski
 
Introduction-to-Prestressed-Concrete.pdf
Introduction-to-Prestressed-Concrete.pdfIntroduction-to-Prestressed-Concrete.pdf
Introduction-to-Prestressed-Concrete.pdf
Bharti Shinde
 
Video Games and Artificial-Realities.pptx
Video Games and Artificial-Realities.pptxVideo Games and Artificial-Realities.pptx
Video Games and Artificial-Realities.pptx
HadiBadri1
 
DE-UNIT-V MEMORY DEVICES AND DIGITAL INTEGRATED CIRCUITS
DE-UNIT-V MEMORY DEVICES AND DIGITAL INTEGRATED CIRCUITSDE-UNIT-V MEMORY DEVICES AND DIGITAL INTEGRATED CIRCUITS
DE-UNIT-V MEMORY DEVICES AND DIGITAL INTEGRATED CIRCUITS
Sridhar191373
 
Better Builder Magazine, Issue 53 / Spring 2025
Better Builder Magazine, Issue 53 / Spring 2025Better Builder Magazine, Issue 53 / Spring 2025
Better Builder Magazine, Issue 53 / Spring 2025
Better Builder Magazine
 

Cross Site Scripting: Prevention and Detection(XSS)

  • 1. Cross Site Scripting Detection and Prevention ~Aman Kumar Cross Site Scripting Detection and Prevention
  • 2. What is cross-site scripting? • Cross-Site Scripting (referred to as XSS) is a type of web application attack where malicious client-side script is injected into the application output and subsequently executed by the user’s browser. • It can be used to take over a user’s browser in a variety of ways 2
  • 3. Why should I care about cross-site scripting? •There was a time not too long ago when XSS was considered a low-risk type of security issue, because when compared to a server-side exploit, it seemed relatively low. •As other issues like PHP remote file inclusions have become harder to exploit, XSS attacks have increased in prominence and sophistication. 3
  • 4. Who’s affected by cross-site scripting? Everyone. No, really – almost every site you can think of has had XSS problems at one time or another (and probably still does) Don’t believe me? • Universal XSS in Internet Explorer (2015) [1] • Tweetdeck (2014) [2] • PayPal (2013) – BONUS: discovered by a 17 year old kid [3] • Google Finance (2013) [4] • 25 “Verasign-secured” online stores (2012) [5] • McAfee (2011) [6] • Visa (2010) [7] 4
  • 5. 5 Some sites you might recognize http://www.xssed.com/files/image/News/paypalevsslxss.PNG
  • 6. Object Placeholder 6www.rackspace.com Some sites you might recognize http://3.bp.blogspot.com/-IpLMWEVPnRc/UmYV_19hnNI/AAAAAAAADfc/caJdmBEsyaE/s1600/1.png
  • 7. Object Placeholder 7 Some sites you might recognize https://isc.sans.edu/diaryimages/youtube.png
  • 8. Boooooring… The classic proof-of-concept for XSS is a little alert box with some arbitrary text in it, or a picture of something silly. This doesn’t seem nearly dangerous enough to warrant concern. What else you got? 8
  • 9. •Steal cookies •Play a sound •Get user-agent string •See enabled plugins (e.g. Chrome PDF viewer, Java, etc.) 9 Basic Client-side Attacks
  • 10. •Man-in-the-browser •Forge user requests •Get form values / HTML contents •Fake notifications (Chrome plugin bar, LastPass login, etc.) •Tabnabbing 10 More Advanced Client-Side Attacks www.rackspace.com
  • 11. •Man-in-the-browser •Forge user requests •Get form values / HTML contents •Fake notifications (Chrome plugin bar, LastPass login, etc.) •Tabnabbing 11 More Advanced Client-Side Attacks www.rackspace.com
  • 12. • Never trust the user • Never trust the user • Never trust the user • Never trust the user • Never trust the user • Never trust the user • Never trust the user • Never trust the user So what should I do to prevent XSS? 12
  • 13. • Almost all client-side script injection comes down to the following characters: < > ( ) { } [ ] " ' ; / • There are various ways to take care of these characters, but it is too context- dependent to give a one-size-fits-all answer • The shortest answer is, make sure you’re only getting characters you expect when a user enters any kind of information - make sure you never display a user-entered string without properly encoding it. So what should I do to prevent XSS? (No, really) 13www.rackspace.com
  • 14. Here’s some sample vulnerable JavaScript. <html> <script> var lol = function () { var a = document.getElementById('a').value; document.write(a); } </script> <input type="text" name="a" id="a"> <input type="submit" onclick="lol();"> </html> 14 Examples of XSS in code
  • 15. Hmm, there’s the problem… <html> <script> var lol = function () { var a = document.getElementById('a').value; document.write(a); // Too easy } </script> <input type="text" name="a" id="a"> <input type="submit" onclick="lol();"> </html> 15 Examples of XSS in code
  • 16. Now for something a little more interesting. Remember, we also have to remember the third-party libraries you’re using. Some innocent-looking jQuery code: $(location.hash) // Wait, that’s it? 16 Examples of XSS in code
  • 17. But you’re not only securing the code you write, but all the code you used… $(location.hash) // WHERE’S THE VULNERABLE PART?! Well, if we’re using jQuery 1.6.1 and we visit the page http://app/#<img src=/ onerror=alert(1)> …this will pop up one of those alert boxes [8]. 17 Examples of XSS in code
  • 18. Here are some examples of how to filter HTML characters in a few simple scenarios in PHP (there should be similar functions in any language; check the links at the end of the PPT) $int = intval($_GET['a']); // This will never return anything other than an integer $str = htmlentities($_GET['b']); // This will encode any character for which there is // an HTML entity equivalent (e.g. &gt; &lt; &quot;) // This is NOT always enough! [9] 18 Tips for filtering XSS
  • 19. Pop quiz! What’s wrong with this PHP code: echo('<a href="' . htmlentities($_GET['var']) . '">link</a>'); 19 Getting around prevention measures
  • 20. Pop quiz! What’s wrong with this PHP code: echo('<a href="' . htmlentities($_GET['var']) . '">link</a>'); What if we set $_GET['var'] to javascript:alert(/xss/); 20 Getting around prevention measures
  • 21. 21
  • 22. • OWASP Links – Guide to Cross-site Scripting - https://www.owasp.org/index.php/Cross-site_Scripting_(XSS) – XSS Prevention Cheat Sheet - https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet – DOM based XSS Prevention Cheat Sheet - https://www.owasp.org/index.php/DOM_based_XSS_Prevention_Cheat_Sheet 22 Resources
  • 23. • [1] http://seclists.org/fulldisclosure/2015/Feb/0 • [2] http://techcrunch.com/2014/06/11/tweetdeck-fixes-xss-vulnerability/ • [3] http://threatpost.com/paypal-site-vulnerable-to-xss-attack • [4] http://miki.it/blog/2013/7/30/xss-in-google-finance/ • [5] http://nakedsecurity.sophos.com/2012/02/28/verisign-xss-holes/ • [6] http://www.scmagazine.com/mcafee-working-to-fix-xss-information-disclosure-flaws/article/199505/ • [7] http://news.softpedia.com/news/XSS-Weakness-Found-on-Visa-USA-Website-157115.shtml • [8] http://ma.la/jquery_xss/ • [9] http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references 23 References