XSS Horror Show scary XSS vectors About me Researcher for Portswigger (makers of Burp suite) JavaScript XSS hacker I love JavaScript sandboxes Built.

Slides:



Advertisements
Similar presentations
HTML Basics Customizing your site using the basics of HTML.
Advertisements

JavaScript FaaDoOEngineers.com FaaDoOEngineers.com.
1 HTML Standards & Compliance. 2 Minimum Required HTML tags: (must go in this order!)
XHTML Basics.
©2009 Justin C. Klein Keane PHP Code Auditing Session 5 XSS & XSRF Justin C. Klein Keane
Blackbox Reversing of XSS Filters Alexander Sotirov ekoparty 2008.
Links and Comments.
Chapter 2 Introduction to HTML5 Internet & World Wide Web How to Program, 5/e Copyright © Pearson, Inc All Rights Reserved.
Structure Content Presentation Semantics.
DHTML - Introduction Introduction to DHTML, the DOM, JS review.
Javascript and the Web Whys and Hows of Javascript.
4.1 JavaScript Introduction
Headings, Paragraphs, Formatting, Links, Head, CSS, Images
JavaScript & jQuery the missing manual Chapter 11
Prevent Cross-Site Scripting (XSS) attack
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
+ Websites Vulnerabilities. + Content Expand of The Internet Use of the Internet Examples Importance of the Internet How to find Security Vulnerabilities.
CSCI 6962: Server-side Design and Programming Secure Web Programming.
ULI101 – XHTML Basics (Part II) What is Markup Language? XHTML vs. HTML General XHTML Rules Block Level XHTML Tags XHTML Validation.
Mohammed Mohsen Links Links are what make the World Wide Web web-like one document on the Web can link to several other documents, and those.
XP New Perspectives on Browser and Basics Tutorial 1 1 Browser and Basics Tutorial 1.
JavaScript, Fourth Edition
Programming in HTML.  Programming Language  Used to design/create web pages  Hyper Text Markup Language  Markup Language  Series of Markup tags 
Unobtrusive JavaScript
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
Chapter 1 XHTML: Part I The Web Warrior Guide to Web Design Technologies.
Using Html Basics, Text and Links. Objectives  Develop a web page using HTML codes according to specifications and verify that it works prior to submitting.
XP Dreamweaver 8.0 Tutorial 3 1 Adding Text and Formatting Text with CSS Styles.
CSE 190: Internet E-Commerce Lecture 5. Exam Material Lectures 1-4 (Presentation Tier) –3-tier architecture –HTML –Style sheets –Javascript –DOM –HTTP.
 2008 Pearson Education, Inc. All rights reserved Introduction to XHTML.
Tutorial 1: XML Creating an XML Document. 2 Introducing XML XML stands for Extensible Markup Language. A markup language specifies the structure and content.
Chapter 8 Cookies And Security JavaScript, Third Edition.
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
INTRODUCTION TO HTML5 Using jQuery with HTML5. Introducing jQuery  Although it is not a part of any W3C or WHATWG specification, jQuery performs an important.
IS1825: Developing Multimedia Applications for Business Lecture 1: Introduction to CSS Rob Gleasure
Forms and Server Side Includes. What are Forms? Forms are used to get user input We’ve all used them before. For example, ever had to sign up for courses.
ECA 225 Applied Interactive Programming1 ECA 225 Applied Online Programming basics.
XP Tutorial 8 Adding Interactivity with ActionScript.
Tutorial 3 Adding and Formatting Text with CSS Styles.
JQuery JavaScript is a powerful language but it is not always easy to work with. jQuery is a JavaScript library that helps with: – HTML document traversal.
1 CSC160 Chapter 7: Events and Event Handlers. 2 Outline Event and event handlers onClick event handler onMouseOver event handler onMouseOut event handler.
©SoftMoore ConsultingSlide 1 Introduction to HTML: Basic Document Structure.
HTML A brief introduction HTML1. HTML, what is? HTML is a markup language for describing web documents (web pages). HTML stands for Hyper Text Markup.
Objective: To describe the evolution of the Internet and the Web. Explain the need for web standards. Describe universal design. Identify benefits of accessible.
Basic HTML Document Structure. Slide 2 Goals (XHTML HTML5) XHTML Separate document structure and content from document formatting HTML 5 Create a formal.
`. Lecture Overview HTML Body Elements Linking techniques HyperText references Linking images Linking to locations on a page Linking to a fragment on.
JavaScript and Ajax (JavaScript Environment) Week 6 Web site:
HTML5 and CSS3 Illustrated Unit C: Getting Started with CSS.
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.
111 State Management Beginning ASP.NET in C# and VB Chapter 4 Pages
An Introduction to Web Application Security
Getting Started with CSS
Programming Web Pages with JavaScript
Unit 4 Representing Web Data: XML
Unit M Programming Web Pages with
Links and Comments in HTML5
Links and Comments.
Introduction to XHTML.
4. Javascript Pemrograman Web I Program Studi Teknik Informatika
Basic HTML Document Structure
CISC103 Web Development Basics: Web site:
Chapter 7 Representing Web Data: XML
HTML A brief introduction HTML.
Links and Comments.
Introduction to DHTML, the DOM, JS review
Links and Comments.
Links and Comments.
HTML5 and CSS3 Illustrated Unit B: Getting Started with HTML
Presentation transcript:

XSS Horror Show scary XSS vectors

About me Researcher for Portswigger (makers of Burp suite) JavaScript XSS hacker I love JavaScript sandboxes Built MentalJS a JavaScript parser/sandbox Worked for Microsoft for 5 years testing the IE XSS filter

Horror FILMS ARE LIKE SECURITY They both have zombies

Horror FILMS ARE LIKE SECURITY ENDLESS SEQUELS

THE SAW MOMENT Unexpected twist Clever thing you didn’t see coming Nobody thought of it When it happens you enjoy it It explains a lot

Absolute urls Absolute URLs are complete Specify the full URL for the destination There is no guess work for the browser other than resolving the domain or protocol

relative urls Relative URLs are dependent on where you are in the document structure of the site The browser gets a URL based on where it thinks you are in the document structure There is guess work for the browser I consider Relative URLs harmful

relative urls Have you visited a web site AND.... SOMETHING ISNT RIGHT

relative urls

Understanding the problem Relative path references a style sheet We add a slash to the URL that the code isn’t expecting The browser tries to find the style sheet at a different location The browser returns 404 or 302 Your code could be vulnerable

relative path overwrite Overwrite the intended relative path by providing a new path using slash / Provide the expected file with valid data Execute the expected file and take advantage of where you execute CSS is the obvious target but RPO works with any format that uses a relative URL

Exploiting RPO 1.Require some persistent text on the page, such as a subject in a web mail client 2.Require a relative path that references a style sheet 3.Require a browser that will render the style sheet and execute code

Exploiting RPO Quick CSS lesson “In some cases, user agents must ignore part of an illegal style sheet. This specification defines ignore to mean that the user agent parses the illegal part (in order to find its beginning and end), but otherwise acts as if it had not been there.”

Exploiting RPO If we can get the browser to point to a web page that contains CSS maybe we can render it Using CSS selectors we can ignore any invalid CSS (such as HTML) that happened before Expressions are our friend

Exploiting RPO Web page contains relative style sheet to style.css We provide the shortest XSS vector in the world “/” The style sheet loads the web page as the style sheet using the following path “/test.php/styles.css”

Exploiting RPO {}*{xss:expression(alert(1))}

Exploiting RPO What about../ type paths? Luckily you are safe. Actually I lied you are not safe

Exploiting RPO../ the browser tries to go up in the document structure It doesn’t know the actual file on the server If we provide a fake directory then we can send the stylesheet back to our html page “/index.php/fakedirectory/fakedirectory/”

Exploiting RPO Expressions work in IE10 in compat mode Quirks mode or old doctypes enable expressions Iframing can inherit the document mode from the parent

Mutation XSS Mutation XSS was coined by me and Mario Happens when HTML mutates from a safe form into an unsafe form Usually when innerHTML is read and written

Mutation XSS The technique fools the HTML parser to rewrite the code There are many ways to do this Attribute quotes XHTML/HTML confusion CSS strings/urls badly decoded

Mutation XSS Rewritten to Discovered by Yosuke Birth of Mutation XSS Worked in IE7 is now patched in IE 

Mutation XSS Maybe we can confuse the HTML parser using XHTML like vectors Confuse the parser into thinking it’s inside an attribute and therefore render entities </xmp><iframe onload=alert(1)> padding</xmp> Works in <= IE9 compat

Mutation XSS Technique also works for Style Script Comment XML E.g. </style><iframe onload=alert(1)>

Mutation XSS I thought to myself what other tags mutate IE has a non-standard tag <% Behaves like a comment but also renders attributes in different versions of IE padding</%> Works in <=IE9 compat

Real world Mutation XSS Lets search in Google Put IE in IE8 compat mode Click print preview The title mutates in the print preview!

Real world Mutation XSS

Mutation XSS How can we simulate mXSS? All you need is innerHTML+=‘’ Reads and writes HTML causing mutation Multiple read/writes cause multiple levels of mutation Is there a tool for that? Of course:

LEGacy IE bugs Anchors with id’s can be manipulated using the global variable referencing that object E.g. test x=‘javascript:alert(1)’ Global variable causes assignment to the href property of the anchor Anchor contains javascript url Works in compat mode in IE

LEGacy IE bugs You can reassign functions from within the arguments of a javascript function call If XSS occurs within the arguments of a function you can bypass the IE XSS filter someFunc(XSS HERE); someFunct(1,someFunct=alert)

LEGacy IE bugs Frame busters can be attacked using DOM clobbering We can overwrite references to location so that other DOM objects are used Classic frame buster if(top.location!=self.location) { self.location=top.location }

LEGacy IE bugs If we can control the “top” object then we can execute XSS Injection must occur before the frame buster Because the attribute is html decoded and location assignment is also decoded we can double encode our vector!

LEGacy IE bugs If we can control the “top” object then we can execute XSS Injection must occur before the frame buster Because the attribute is html decoded and location assignment is also decoded we can double encode our vector!

XSS Filter bypasses Inside a script block x=“INJECTION” I can bypass the Chrome XSS filter using XSS auditor doesn’t support script based injections however I can inject a HTML based vector that uses a closing block alert(1)+"

XSS Filter bypasses Another XSS auditor bypass If injection occurs within an attribute and a script occurs after the injection I can bypass the filter "><script/src=data:,alert(1)%2b“ y = "abc";

XSS Filter bypasses IE vulnerable to meta charset injection (now patched  ) +ADw-script+AD4- alert(1)+ADw-/script+AD4- Rules didn’t account for charset attribute Allowed injection of UTF-7 or other charsets

XSS Filter bypasses IE blocked anchor based injections Regex looks like <a.*?hr{e}f Could be bypassed using formaction now patched  PWND

XSS Filter bypasses There is a generic method to bypass both IE/Chrome XSS filter Site filters a character such as “ We can inject the character to bypass the filter by hiding the keywords searched for by the filters E.g. ‘abc><sty”le=xss:expression(alert(1)) x=‘

XSS Filter bypasses XSS auditor is easier to bypass and once a character is filtered (removed) you can bypass most checks IE is clever in some instances and can detect if characters like <> are removed Still can be bypassed using quotes in script based injections Other characters can easily bypass the filter where keywords such as style are used

XSS Filter bypasses Site filters “(“ javsc(ript:alert(1) bypasses IE XSS filter Site filters “;” bypasses XSS auditor and IE XSS filter Site filters “ ‘,alert(“1),’ bypasses IE XSS filter

General XSS techniques Srcdoc is awesome for bypassing WAF’s Multiple levels of encoding can bypass filters Data urls inherit origins on Firefox Nested iframes can mix urlencoding and HTML entities

General XSS techniques URLs look like JavaScript (label) (comment) IE treats it as valid JavaScript abc: Valid JavaScript in IE If we can inject new lines then we can eval a URL!

General XSS techniques IE supports both new lines and line/para separators within the url Chrome supports line/para separator Firefox url encodes  location.hash=‘\nalert(1)’; eval(document.URL) location.hash=‘\u2028alert(1)’; eval(document.URL)

General XSS techniques External urls support new lines/carriage returns and tab between slashes Fool external url checks with tabs and new lines

General XSS techniques Window onerror handler Can be used for XSS without ( or ) E.g. onerror=alert;throw”XSS” Firefox prefixes with two words  Chrome uses only one onerror=eval;throw’=alert\x281\x29’

THE end questions?