Cross Site Scripting (XSS)

Slides:



Advertisements
Similar presentations
Cross-Site Scripting Issues and Defenses Ed Skoudis Predictive Systems © 2002, Predictive Systems.
Advertisements

Nick Feamster CS 6262 Spring 2009
Past, Present and Future By Eoin Keary and Jim Manico
Hossain Shahriar Mohammad Zulkernine. One of the worst vulnerabilities in web applications It involves the generation of dynamic HTML contents with invalidated.
Appeared in 30 th IEEE Symposium on Security and Privacy, May Authors: Mike Ter Louw and V.N. Venkatakrishnan Dept. of Computer Science: University.
Web Security Never, ever, trust user inputs Supankar.
What is code injection? Code injection is the exploitation of a computer bug that is caused by processing invalid data. Code injection can be used by.
The OWASP Foundation Web Application Security Host Apps Firewall Host Apps Database Host Web serverApp serverDB server Securing the.
© 2008 Security Compass inc. 1 Firefox Plug-ins for Application Penetration Testing Exploit-Me.
Copyright © The OWASP Foundation Permission is granted to copy, distribute and/or modify this document under the terms of the OWASP License. The OWASP.
HI-TEC 2011 SQL Injection. Client’s Browser HTTP or HTTPS Web Server Apache or IIS HTML Forms CGI Scripts Database SQL Server or Oracle or MySQL ODBC.
Copyright © The OWASP Foundation Permission is granted to copy, distribute and/or modify this document under the terms of the OWASP License. The OWASP.
JavaScript FaaDoOEngineers.com FaaDoOEngineers.com.
Don’t get Stung (An introduction to the OWASP Top Ten Project) Barry Dorrans Microsoft Information Security Tools NEW AND IMPROVED!
The XSS Files Find, Exploit, and Eliminate. Josh Little Security Engineer at global vertical market business intelligence company. 9 years in application.
A NTI S AMY J AVA I NTRODUCTION Wang Wenjun June 2011.
©2009 Justin C. Klein Keane PHP Code Auditing Session 5 XSS & XSRF Justin C. Klein Keane
Cross Site Scripting & SQL injection
EECS 354 Network Security Cross Site Scripting (XSS)
Team Members: Brad Stancel,
COMP 321 Week 12. Overview Web Application Security  Authentication  Authorization  Confidentiality Cross-Site Scripting Lab 12-1 Introduction.
Blackbox Reversing of XSS Filters Alexander Sotirov ekoparty 2008.
Chapter 9 Web Applications. Web Applications are public and available to the entire world. Easy access to the application means also easy access for malicious.
Introduction to the OWASP Top 10. Cross Site Scripting (XSS)  Comes in several flavors:  Stored  Reflective  DOM-Based.
CROSS SITE SCRIPTING..! (XSS). Overview What is XSS? Types of XSS Real world Example Impact of XSS How to protect against XSS?
Handling Security Threats in Kentico CMS Karol Jarkovsky Sr. Solution Architect Kentico Software
WEB SECURITY WORKSHOP TEXSAW 2013 Presented by Joshua Hammond Prepared by Scott Hand.
Introduction to InfoSec – Recitation 10 Nir Krakowski (nirkrako at post.tau.ac.il) Itamar Gilad (itamargi at post.tau.ac.il)
Presented by…. Group 2 1. Programming language 2Introduction.
Workshop 3 Web Application Security Li Weichao March
Cookies Cross site scripting
JavaScript & jQuery the missing manual Chapter 11
Cosc 4765 Server side Web security. Web security issues From Cenzic Vulnerability report
Cross-Site Scripting Vulnerabilities Adam Doupé 11/24/2014.
Prevent Cross-Site Scripting (XSS) attack
+ Websites Vulnerabilities. + Content Expand of The Internet Use of the Internet Examples Importance of the Internet How to find Security Vulnerabilities.
WEB SECURITY WEEK 3 Computer Security Group University of Texas at Dallas.
CSCI 6962: Server-side Design and Programming Secure Web Programming.
BLUEPRINT: Robust Prevention of Cross-site Scripting Attacks for Existing Browsers Mike Ter Louw, V.N. Venkatakrishnan University of Illinois at Chicago.
Chapter 9 Web Applications. Web Applications are public and available to the entire world. Easy access to the application means also easy access for malicious.
Copyright 2007 © The OWASP Foundation Permission is granted to copy, distribute and/or modify this document under the terms of the OWASP License. The OWASP.
Cross Site Scripting (XSS) Chaitanya Lakshmi
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
Srikar Nadipally. Outline Finding and Exploiting XSS Vulnerabilities Standard Reflected XSS Stored XSS DOM based XSS Prevention of XSS attack Reflect.
Top Five Web Application Vulnerabilities Vebjørn Moen Selmersenteret/NoWires.org Norsk Kryptoseminar Trondheim
© Copyright 2013 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice. 1 RubyJax Brent Morris/
Web Applications Testing By Jamie Rougvie Supported by.
Cross Site Scripting and its Issues By Odion Oisamoje.
Presented By: Chandra Kollipara. Cross-Site Scripting: Cross-Site Scripting attacks are a type of injection problem, in which malicious scripts are injected.
Web Security Lesson Summary ●Overview of Web and security vulnerabilities ●Cross Site Scripting ●Cross Site Request Forgery ●SQL Injection.
PHP Error Handling & Reporting. Error Handling Never allow a default error message or error number returned by the mysql_error() and mysql_errno() functions.
Introduction of XSS:-- Cross-Site Scripting (XSS) attacks are a type of injection, in which malicious scripts are injected into otherwise benign and trusted.
By Collin Donaldson. Hacking is only legal under the following circumstances: 1.You hack (penetration test) a device/network you own. 2.You gain explicit,
The OWASP Foundation OWASP XSS Remediation Cassia Martin Romain Gaucher April 7 th, 2011.
SlideSet #20: Input Validation and Cross-site Scripting Attacks (XSS) SY306 Web and Databases for Cyber Operations.
Javascript worms By Benjamin Mossé SecPro
Google’s Gruyere1 : An XSS Example Presented by: Terry Gregory
Group 18: Chris Hood Brett Poche
Building Secure ColdFusion Applications
CSCE 548 Student Presentation Ryan Labrador
An Introduction to Web Application Security
Web Application Vulnerabilities, Detection Mechanisms, and Defenses
Cross-Site Scripting Travis Deyarmin.
Cross Sight scripting: Type-2
CSC 495/583 Topics of Software Security Intro to Web Security
WWW安全 國立暨南國際大學 資訊管理學系 陳彥錚.
Cross-Site Scripting Issues and Defenses Ed Skoudis Predictive Systems
Exploring DOM-Based Cross Site Attacks
Cross-Site Scripting Attack (XSS)
Mike Ter Louw, V.N. Venkatakrishnan University of Illinois at Chicago
Presentation transcript:

Cross Site Scripting (XSS) David Wharton Intrusion Detection & Prevention Regions Financial Corp.

Overview Introduction What is XSS? Is XSS Important? Exploiting XSS Preventing XSS BeEF Demo Conclusion Questions

Introduction

What is XSS? XSS is a vulnerability that allows an attacker to run arbitrary JavaScript in the context of the vulnerable website. XSS bypasses same-origin policy protection “The policy permits scripts running on pages originating from the same site to access each other's methods and properties with no specific restrictions, but prevents access to most methods and properties across pages on different sites.“ “The term ‘origin’ is defined using the domain name, application layer protocol, and (in most browsers) TCP port” http://en.wikipedia.org/wiki/Same_origin_policy Requires some sort of social engineering to exploit. Compared URL Outcome Reason http://www.example.com/dir/page.html Success Same protocol and host http://www.example.com/dir2/other.html Success Same protocol and host

Types of XSS Reflected XSS Stored XSS (a.k.a. “Persistent XSS”) DOM Based XSS

Reflected XSS

Reflected XSS Example Exploit URL: HTML returned to victim: http://www.nikebiz.com/search/?q=<script>alert('XSS')</script>&x=0&y=0 HTML returned to victim: <div id="pageTitleTxt"> <h2><span class="highlight">Search Results</span><br /> Search: "<script>alert('XSS')</script>"</h2>

Reflected XSS Example Reflected cross-site scripting vulnerabilities arise when data is copied from a request and echoed into the application's immediate response in an unsafe way. An attacker can use the vulnerability to construct a request which, if issued by another application user, will cause JavaScript code supplied by the attacker to execute within the user's browser in the context of that user's session with the application. The attacker-supplied code can perform a wide variety of actions, such as stealing the victim's session token or login credentials, performing arbitrary actions on the victim's behalf, and logging their keystrokes.

Stored XSS JavaScript supplied by the attacker is stored by the website (e.g. in a database) Doesn’t require the victim to supply the JavaScript somehow, just visit the exploited web page More dangerous than Reflected XSS Has resulted in many XSS worms on high profile sites like MySpace and Twitter (discussed later)

DOM Based XSS http://www.some.site/page.html?default=ASP.NET Occur in the content processing stages performed by the client <select><script> document.write("<OPTION value=1>"+document.location.href.substring(document.location.href.indexOf("default=")+8)+"</OPTION>"); </script></select> http://www.some.site/page.html?default=ASP.NET /page.html?default=<script>alert(document.cookie)</script> Source: http://en.wikipedia.org/wiki/Cross-site_scripting Source: http://www.owasp.org/index.php/DOM_Based_XSS

Is XSS Dangerous? Yes OWASP Top 2 Defeats Same Origin Policy Just think, any JavaScript you want will be run in the victim’s browser in the context of the vulnerable web page Hmmm, what can you do with JavaScript?

What can you do with JavaScript? Pop-up alerts and prompts Access/Modify DOM Access cookies/session tokens “Circumvent” same-origin policy Virtually deface web page Detect installed programs Detect browser history Capture keystrokes (and other trojan functionality) Port scan the local network

What can you do with JavaScript? (cont) Induce user actions Redirect to a different web site Determine if they are logged on to a particular site Capture clipboard content Detect if the browser is being run in a virtual machine Rewrite the status bar Exploit browser vulnerabilities Launch executable files (in some cases)

Example: Form Injection

Example: Virtual Defacement

Example: Pop-Up Alert

Example: Cookie Stealing

Example: XSS Worms Samy Worm Affected MySpace Leveraged Stored XSS vulnerability so that for every visitor to Samy’s MySpace page, the following would silently happen: The visitor would be added as Sammy’s friend The visitor would get an update to their page that infected it with the same JavaScript and left a message saying, “but most of all, Samy is my hero”. Worm spread exponentially Over 1 million friend requests in less than 20 hours Twitter XSS worm this week, affected 500K accounts!

Cause of Injection Vulnerabilities: Improper Handling of User-Supplied Data >= 80% of web security issues caused by this! NEVER Trust User/Client Input! Client-side checks/controls have to be invoked on the server too. Improper Input Validation Improper Output Validation More details in next section

Preventing Injection Vulnerabilities In Your Apps Validate Input Letters in a number field? 10 digits for 4 digit year field? Often only need alphanumeric Careful with < > " ' and = Whitelist (e.g. /[a-zA-Z0-9]{0,20}/) Reject, don’t try and sanitize

Preventing XSS In Your Applications Validate Output Encode HTML Output If data came from user input, a database, or a file Response.Write(HttpUtility.HtmlEncode(Request.Form["name"])); Not 100% effective but prevents most vulnerabilities Encode URL Output If returning URL strings Response.Write(HttpUtility.UrlEncode(urlString)); How To: Prevent Cross-Site Scripting in ASP.NET http://msdn.microsoft.com/en-us/library/ms998274.aspx XSS Prevention Cheat Sheet: http://www.owasp.org/index.php/XSS_%28Cross_Site_Scripting%29_Prevention_Cheat_Sheet

RULE #0 - Never Insert Untrusted Data Except in Allowed Locations (see rules 1-5) <script>...NEVER PUT UNTRUSTED DATA HERE...</script> directly in a script <!--...NEVER PUT UNTRUSTED DATA HERE...--> inside an HTML comment <div ...NEVER PUT UNTRUSTED DATA HERE...=test /> in an attribute name <...NEVER PUT UNTRUSTED DATA HERE... href="/test" /> in a tag name

RULE #1 - HTML Escape Before Inserting Untrusted Data into HTML Element Content <body>...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE…</body> <div>…ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE…</div> any other normal HTML elements

RULE #1 (continued) Escape these characters: & --> & < --> < > --> > " --> " ' --> ' &apos; is not recommended / --> / forward slash is included as it helps end an HTML entity Remember HttpUtility.HtmlEncode()

RULE #2 - Attribute Escape Before Inserting Untrusted Data into HTML Common Attributes <div attr=…ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE…>content</div> inside UNquoted attribute <div attr='…ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE…'>content</div> inside single quoted attribute <div attr="…ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE…">content</div> inside double quoted attribute Except for alphanumeric characters, escape all characters with ASCII values less than 256 with the &#xHH; format or named entity if available. Examples: " '

RULE #3 - JavaScript Escape Before Inserting Untrusted Data into HTML JavaScript Data Values The only safe place to put untrusted data into these event handlers as a quoted "data value.“ <script>alert('...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...')</script> inside a quoted string <script>x='...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'</script> one side of a quoted expression <div onmouseover="x='...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'"</div> inside quoted event handler Except for alphanumeric characters, escape all characters less than 256 with the \xHH format. Example: \x22 not \”

RULE #3 (continued) But be careful! <script> window.setInterval('...EVEN IF YOU ESCAPE UNTRUSTED DATA YOU ARE XSSED HERE...'); </script>

RULE #4 - CSS Escape Before Inserting Untrusted Data into HTML Style Property Values <style>selector { property : ...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...; } </style> property value <span style=property : ...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...;>text</style> property value Except for alphanumeric characters, escape all characters with ASCII values less than 256 with the \HH escaping format. Example: \22 not \”

RULE #5 - URL Escape Before Inserting Untrusted Data into HTML URL Parameter Values <a href="http://www.somesite.com?test=...URL ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...">link</a > Except for alphanumeric characters, escape all characters with ASCII values less than 256 with the %HH escaping format. Example: %22 Remember HttpUtility.UrlEncode()

Reduce Impact of XSS Vulnerabilities If Cookies Are Used: Scope as strict as possible Set ‘secure’ flag Set ‘HttpOnly’ flag On the client, consider disabling JavaScript (if possible) or use something like the NoScript Firefox extension.

Further Resources XSS Prevention Cheat Sheet XSS Attacker Cheat Sheet http://www.owasp.org/index.php/XSS_%28Cross_Site_Scripting%29_Prevention_Cheat_Sheet XSS Attacker Cheat Sheet http://ha.ckers.org/xss.html OWASP Enterprise Security APIs http://www.owasp.org/index.php/Category:OWASP_Enterprise_Security_API OWASP XSS Page http://www.owasp.org/index.php/Cross-site_Scripting_%28XSS%29

Demo: BeEF Browser Exploitation Framework Written by Wade Alcorn http://www.bindshell.net/tools/beef/ Architecture:

Conclusion XSS vulnerabilities are bad. Avoid introducing XSS vulnerabilities in your code. Please. They will only cause delays in getting your apps into production. Give me your email, I have a link you *really* need to see. 

Questions? Contact info: David Wharton david.r.wharton@regions.com 205.261.5219