the xss files find, exploit, and eliminate. josh little security engineer at global vertical market...

23
The XSS Files Find, Exploit, and Eliminate

Upload: sonny-alsip

Post on 15-Jan-2016

227 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: The XSS Files Find, Exploit, and Eliminate. Josh Little Security Engineer at global vertical market business intelligence company. 9 years in application

The XSS FilesFind, Exploit, and Eliminate

Page 2: The XSS Files Find, Exploit, and Eliminate. Josh Little Security Engineer at global vertical market business intelligence company. 9 years in application

2

Josh Little

• Security Engineer at global vertical market business intelligence company.

• 9 years in application support, developer relations, and application review.

• OWASP Detroit Chapter Leader & a #misec founding member

• GSEC, CISSP in limbo

Page 3: The XSS Files Find, Exploit, and Eliminate. Josh Little Security Engineer at global vertical market business intelligence company. 9 years in application

3

What is a XSS flaw?

• XSS = ‘Cross Site Scripting’

• Injection of arbitrary code into a user’s browser session

• #2 on the 2010 OWASP Top 10 and has been on the list since the beginning

Page 4: The XSS Files Find, Exploit, and Eliminate. Josh Little Security Engineer at global vertical market business intelligence company. 9 years in application

4

Causes of XSS Flaws

• Failure of the application to properly sanitize output to the user’s browser.

• Improper trust of of user supplied data.

$a = $_GET['search'];print 'Your search results '.$a;

Page 5: The XSS Files Find, Exploit, and Eliminate. Josh Little Security Engineer at global vertical market business intelligence company. 9 years in application

5

Effects of XSS

• Theft of session cookies

• Arbitrary HTML or Javascript injection

• Exploit injection

• Keystroke Logging

• BeEF & Metasploit can be used to show effects of XSS

Page 6: The XSS Files Find, Exploit, and Eliminate. Josh Little Security Engineer at global vertical market business intelligence company. 9 years in application

6

Reflective vs. Persistent

• Reflective – Payload tied to specific URL. Visit the link, hit the payload.

• Persistent – Embeds the payload into the page (think comments, forum posts, etc.)

Page 7: The XSS Files Find, Exploit, and Eliminate. Josh Little Security Engineer at global vertical market business intelligence company. 9 years in application

7

DOM Based XSS

XSS based on the DOM's (Document Object Model) response to the incoming code and other page/request elements.

Does not require dynamic server-side code.

<script>document.write("Site is at: " + document.location.href + ".");</script>

Page 8: The XSS Files Find, Exploit, and Eliminate. Josh Little Security Engineer at global vertical market business intelligence company. 9 years in application

8

Finding XSS Flaws

Basic test:

Determine how application handles 'special' characters such as " ' < >

If the application returns these characters unencoded, it's possibly (and probably) vulnerable.

Page 9: The XSS Files Find, Exploit, and Eliminate. Josh Little Security Engineer at global vertical market business intelligence company. 9 years in application

9

Automated scanning – Can test a large number of test cases quickly. Not complete, but a good method to find low-hanging fruit quickly.

Source Code Review – Unsanitized use of input is fairly self evident in code review. Time consuming, however, and complex code can make it difficult to follow input paths.

As with other flaws, a multi-pronged approach is best.

Page 10: The XSS Files Find, Exploit, and Eliminate. Josh Little Security Engineer at global vertical market business intelligence company. 9 years in application

10

Preventing XSS

• Input whitelisting

• Context sensitive output encoding

• Javascript, Actionscript, HTML, CSS, etc. must all be treated differently.

• Just encoding for HTML will not prevent all issues.

Page 11: The XSS Files Find, Exploit, and Eliminate. Josh Little Security Engineer at global vertical market business intelligence company. 9 years in application

11

Context is Key

HTML Body

HTML Attribute

s

<STYLE> Context

<SCRIPT>

Context

URL Context

*courtesy of Jim Manico (@manicode)

Page 12: The XSS Files Find, Exploit, and Eliminate. Josh Little Security Engineer at global vertical market business intelligence company. 9 years in application

12

Data Type Context Defense

Numeric, Type safe language Doesn’t Matter Cast to Numeric

String HTML Body HTML Entity Encode

String HTML Attribute, quoted Minimal Attribute Encoding

String HTML Attribute, unquoted Maximum Attribute Encoding

String GET Parameter URL Encoding

String Untrusted URL URL Validation, avoid javascript: URL’s, Attribute encoding, safe URL verification

String CSS Strict structural validation, CSS Hex encoding, good design

HTML HTML Body HTML Validation (JSoup, AntiSamy, HTML Sanitizer)

Any DOM DOM XSS Cheat sheet

Untrusted JavaScript Any Sandboxing

JSON Client parse time JSON.parse() or json2.js

*courtesy of Jim Manico (@manicode)

Page 13: The XSS Files Find, Exploit, and Eliminate. Josh Little Security Engineer at global vertical market business intelligence company. 9 years in application

13

To be truly successful, sanitization should be part of the development framework and not optional.

Most successful when the decision on whether to apply sanitization is not up to the individual developer but enforced by the development environment.

Page 14: The XSS Files Find, Exploit, and Eliminate. Josh Little Security Engineer at global vertical market business intelligence company. 9 years in application

14

Anti-XSS Frameworks

.NET – MS AntiXSS Libraryhttp://msdn.microsoft.com/en-us/security/aa973814

JAVA, .NET – OWASP AntiSAMYhttps://www.owasp.org/index.php/Category:OWASP_AntiSamy_Project

Javascript – Google CAJAhttp://code.google.com/p/google-caja/

Page 15: The XSS Files Find, Exploit, and Eliminate. Josh Little Security Engineer at global vertical market business intelligence company. 9 years in application

15

Browser Based Defenses

• Most modern browsers have some form of XSS protection either built-in or via a 3rd party plugin (i.e. NoScript)

• Bad code is still bad code – don't rely on the browser for defense.

Page 16: The XSS Files Find, Exploit, and Eliminate. Josh Little Security Engineer at global vertical market business intelligence company. 9 years in application

16

DEMOSBasic XSS Examples

Page 17: The XSS Files Find, Exploit, and Eliminate. Josh Little Security Engineer at global vertical market business intelligence company. 9 years in application

17

Demos

All demos are available at http://xploit.zombietango.com/xss

Feel free to play with them and use them in additional demonstrations.

Page 18: The XSS Files Find, Exploit, and Eliminate. Josh Little Security Engineer at global vertical market business intelligence company. 9 years in application

18

#1 Basic XSS & Mitigation Strategies

http://xploit.zombietango.com/xss/1/

Mitigation Strategies:

• Basic – Strips <script></script> tags

• Good – Encodes output within HTML context

• Textarea – Encloses error message in a <textarea> tag

Page 19: The XSS Files Find, Exploit, and Eliminate. Josh Little Security Engineer at global vertical market business intelligence company. 9 years in application

19

#2 Attacking incomplete filtering

http://xploit.zombietango.com/xss/2/

No input written to page body, so we're safe, right?

Search term written to <title> tag without sanitization

Page 20: The XSS Files Find, Exploit, and Eliminate. Josh Little Security Engineer at global vertical market business intelligence company. 9 years in application

20

#3 XSS with Style

http://xploit.zombietango.com/xss/3/

Don't confuse limited means of input with limited input

Some apps respond to multiple HTTP methods

Cookies can provide a method of persistence within a user's browser session.

Page 21: The XSS Files Find, Exploit, and Eliminate. Josh Little Security Engineer at global vertical market business intelligence company. 9 years in application

21

#4 DOM Based XSS

http://xploit.zombietango.com/xss/4/

Site builds comment link with ref to current URL.

# tag in URL before payload prevents attack from showing up in server logs

Page 22: The XSS Files Find, Exploit, and Eliminate. Josh Little Security Engineer at global vertical market business intelligence company. 9 years in application

22

#5 XSS through POST

http://xploit.zombietango.com/xss/5/

Apps using only the POST method are not immune to XSS

Requires the use of secondary page to build & submit the exploitable form

Page 23: The XSS Files Find, Exploit, and Eliminate. Josh Little Security Engineer at global vertical market business intelligence company. 9 years in application

23

QUESTIONS?