warning ahead: security storms are brewing in your javascript yuval idan, technical director, apac...

47
Warning Ahead: Security Storms are Brewing in Your JavaScript Yuval Idan, Technical Director, APAC Checkmarx [email protected]

Upload: gerald-henderson

Post on 18-Dec-2015

215 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Warning Ahead: Security Storms are Brewing in Your JavaScript Yuval Idan, Technical Director, APAC Checkmarx yuval.idan@checkmarx.com

Warning Ahead: Security Storms are Brewing in Your JavaScript

Yuval Idan, Technical Director, APACCheckmarx

[email protected]

Page 2: Warning Ahead: Security Storms are Brewing in Your JavaScript Yuval Idan, Technical Director, APAC Checkmarx yuval.idan@checkmarx.com

About us

o Founded in 2006

o Enterprise Grade Application Security Solutions:

SAST | RASP | Application Security Education

o Hundreds of Fortune 500 and SMB Customers

o Fanatical support

“Leader” in the 2014 AST Wave

“Challenger “- 2014 AST Magic Quadrant & Only Vendor to score a perfect 5 in 2014 AST Critical Capabilities Report

Fastest Growing Security Company in Israel, 2014 Tech Fast 500

Red Herring EMEA Top 100 Winners

Awards

Page 3: Warning Ahead: Security Storms are Brewing in Your JavaScript Yuval Idan, Technical Director, APAC Checkmarx yuval.idan@checkmarx.com

Warning Ahead: Security Storms are Brewing

in Your JavaScript

Page 4: Warning Ahead: Security Storms are Brewing in Your JavaScript Yuval Idan, Technical Director, APAC Checkmarx yuval.idan@checkmarx.com

About Me

Yuval IdanTechnical Director, APAC

Checkmarx

Page 5: Warning Ahead: Security Storms are Brewing in Your JavaScript Yuval Idan, Technical Director, APAC Checkmarx yuval.idan@checkmarx.com

Agenda

o Broken sandbox

o Same old XSS becomes a monster

o Watch out for your client side

o “I know where you were last summer”

Page 6: Warning Ahead: Security Storms are Brewing in Your JavaScript Yuval Idan, Technical Director, APAC Checkmarx yuval.idan@checkmarx.com

HTML5 is booming

Report released in August 2013 has shown that 153 of the Fortune 500 U.S. companies already

implemented HTML5 on their corporate websites.

Page 7: Warning Ahead: Security Storms are Brewing in Your JavaScript Yuval Idan, Technical Director, APAC Checkmarx yuval.idan@checkmarx.com

Some of the additions in HTML5

o WEB storageo WEB SQL databaseo Indexed DBo Application cacheo Web workerso Web socketo CORSo Web messagingo Sandbox attributeo New HTTP headerso Server sent events

o New and better semantic tags

o New form typeso Audio and video tagso Canvaso Inline SVGo New onevent attributeso Geolocationo New CSS selectors o New javascipt selectorso Custom data - attributes

Page 8: Warning Ahead: Security Storms are Brewing in Your JavaScript Yuval Idan, Technical Director, APAC Checkmarx yuval.idan@checkmarx.com

The Sandbox Attribute

Page 9: Warning Ahead: Security Storms are Brewing in Your JavaScript Yuval Idan, Technical Director, APAC Checkmarx yuval.idan@checkmarx.com

SOP Same Origin Policy

permits scripts running on pages originating from the same site based on combination of scheme, hostname, and port number

Page 10: Warning Ahead: Security Storms are Brewing in Your JavaScript Yuval Idan, Technical Director, APAC Checkmarx yuval.idan@checkmarx.com

Same Origin Policy

http://www.cnn.com/main

main page

“Change background to green”

http://www.cnn.com/story1Iframe

same origin

Page 11: Warning Ahead: Security Storms are Brewing in Your JavaScript Yuval Idan, Technical Director, APAC Checkmarx yuval.idan@checkmarx.com

Same Origin Policy

http://www.cnn.com/main

main page

“Change background to green”

Error!

http://www.fox.comIframe

different origin

Page 12: Warning Ahead: Security Storms are Brewing in Your JavaScript Yuval Idan, Technical Director, APAC Checkmarx yuval.idan@checkmarx.com

Markets

o Recent trend - markets of extensions Salesforce.com, Microsoft 365, etc…

o Extension is Javascript code written by a 3rd party but hosted and delivered from the very same server

o So SOP doesn’t play well

Page 13: Warning Ahead: Security Storms are Brewing in Your JavaScript Yuval Idan, Technical Director, APAC Checkmarx yuval.idan@checkmarx.com

Sandbox concept

Sandbox concept? Sandbox is a hardening of the basic SOP – so that any content running in the sandboxed iframe is treated as if it comes from a different origin, and it gives fine-grained control over what restrictions apply.

Page 14: Warning Ahead: Security Storms are Brewing in Your JavaScript Yuval Idan, Technical Director, APAC Checkmarx yuval.idan@checkmarx.com

Sandbox syntax

o Syntax<iframe sandbox="value">

o Attribute ValuesValue Description

"" Applies all restrictions below

allow-same-origin Allows the iframe content to be treated as being from the same origin as the containing document

allow-top-navigation Allows the iframe content to navigate (load) content from the containing document

allow-forms Allows form submission

allow-scripts Allows script execution

Page 15: Warning Ahead: Security Storms are Brewing in Your JavaScript Yuval Idan, Technical Director, APAC Checkmarx yuval.idan@checkmarx.com

http://www.server.com

http://www.server.com/iframe

main page

<script> alert(1) </script>

1

Iframe / same origin

Page 16: Warning Ahead: Security Storms are Brewing in Your JavaScript Yuval Idan, Technical Director, APAC Checkmarx yuval.idan@checkmarx.com

http://www.server.com

http://www.server.com/iframe

main page

<script> alert(1) </script>

Sandboxed IframeDefault permissionsSame Origin

Page 17: Warning Ahead: Security Storms are Brewing in Your JavaScript Yuval Idan, Technical Director, APAC Checkmarx yuval.idan@checkmarx.com

http://www.server.com

http://www.server.com/iframe

main page

<script> alert(1) </script>

1

Sandboxed IframeAllowing Scripts and SOP(Same Origin)

Page 18: Warning Ahead: Security Storms are Brewing in Your JavaScript Yuval Idan, Technical Director, APAC Checkmarx yuval.idan@checkmarx.com

http://www.server.com

http://www.server.com/iframe

main page

<script> top.navigate(…) </script>

Sandboxed IframeAllowing Scripts and SOP(Same Origin)

Page 19: Warning Ahead: Security Storms are Brewing in Your JavaScript Yuval Idan, Technical Director, APAC Checkmarx yuval.idan@checkmarx.com

http://www.server.com

http://www.server.com/iframe

main page

<script> top.find(myself)addPermission(myself, top_nav)Refresh()navigate(…) </script>

Sandboxed IframeAllowing Scripts and SOP(Same Origin)

AndTop Navigation

Page 20: Warning Ahead: Security Storms are Brewing in Your JavaScript Yuval Idan, Technical Director, APAC Checkmarx yuval.idan@checkmarx.com

http://www.server.com

http://www.server.com/iframe

main page

<script> top.find(myself)addPermission(myself, top_nav)Refresh()Navigate(http://www.hacker.com) </script>

http://www.hacker.com

Sandboxed IframeAllowing Scripts and SOP(Same Origin)

AndTop Navigation

Page 21: Warning Ahead: Security Storms are Brewing in Your JavaScript Yuval Idan, Technical Director, APAC Checkmarx yuval.idan@checkmarx.com

Don’t just count on Sandbox!

Don’t assume that just because an iFrame is sandboxed, your code is secure.

What can you do?Avoid granting a sandboxed iFrame with scripting

and SOP capabilities.

Page 22: Warning Ahead: Security Storms are Brewing in Your JavaScript Yuval Idan, Technical Director, APAC Checkmarx yuval.idan@checkmarx.com

How a single XSSed page can be used to take screenshots of other non-XSSed page ?

Page 23: Warning Ahead: Security Storms are Brewing in Your JavaScript Yuval Idan, Technical Director, APAC Checkmarx yuval.idan@checkmarx.com

Canvas Demo

Is the HTML5 element , used to draw graphics, on the fly, via scripting (usually JavaScript).

Page 24: Warning Ahead: Security Storms are Brewing in Your JavaScript Yuval Idan, Technical Director, APAC Checkmarx yuval.idan@checkmarx.com

Monster XSS – Attack Steps

o Step A – Use Bookstore project Login page vulnerable to Reflected XSS to embed itself in an iframe

http://server/page.aspx?xss=<iframe src=“http://server/page.aspx”>

Iframe border(left visible for demo purposes)

Page 25: Warning Ahead: Security Storms are Brewing in Your JavaScript Yuval Idan, Technical Director, APAC Checkmarx yuval.idan@checkmarx.com

Monster XSS – Attack steps

o Step B – The user logs in and browses the inside frame. The outer page remains the same while it’s scripts can access the inner’s data

Iframe border(left visible for demo purposes)

The user went to the admin page, but the URL is still the XSS’ed login page

Page 26: Warning Ahead: Security Storms are Brewing in Your JavaScript Yuval Idan, Technical Director, APAC Checkmarx yuval.idan@checkmarx.com

Monster XSS – The result

o The attacker gets set of pictures representing all user activity( yes, including user name and password!)

Page 27: Warning Ahead: Security Storms are Brewing in Your JavaScript Yuval Idan, Technical Director, APAC Checkmarx yuval.idan@checkmarx.com

Monster XSS – The technique

o HTML5 introduced the concept of Canvas, which can be used to take screenshots

What is Canvas? (w3schools)The HTML5 <canvas> element is used to draw graphics, on the fly, via scripting (usually JavaScript).

Page 28: Warning Ahead: Security Storms are Brewing in Your JavaScript Yuval Idan, Technical Director, APAC Checkmarx yuval.idan@checkmarx.com

Monster XSS – The technique

o Html2canvas - open-source script which builds screenshots based on DOM information.

o We modify it a bit – to reveal passwords

Page 29: Warning Ahead: Security Storms are Brewing in Your JavaScript Yuval Idan, Technical Director, APAC Checkmarx yuval.idan@checkmarx.com

Monster XSS – The technique

Modified HTML2Canvas runs at the outer page and every 2 seconds takes screenshots of the iframe

XSS that takes base64 screenshots

Page 30: Warning Ahead: Security Storms are Brewing in Your JavaScript Yuval Idan, Technical Director, APAC Checkmarx yuval.idan@checkmarx.com

Monster XSS – The technique

Page 31: Warning Ahead: Security Storms are Brewing in Your JavaScript Yuval Idan, Technical Director, APAC Checkmarx yuval.idan@checkmarx.com

Monster XSS – bottom line

So, what can you do ?

Get rid of XSS!!!

Page 32: Warning Ahead: Security Storms are Brewing in Your JavaScript Yuval Idan, Technical Director, APAC Checkmarx yuval.idan@checkmarx.com

WebSockets

Page 33: Warning Ahead: Security Storms are Brewing in Your JavaScript Yuval Idan, Technical Director, APAC Checkmarx yuval.idan@checkmarx.com

Web Socket

WebSocket – allows persistent connection between the client and the server , when both parties can

start sending data at any time.

Page 35: Warning Ahead: Security Storms are Brewing in Your JavaScript Yuval Idan, Technical Director, APAC Checkmarx yuval.idan@checkmarx.com

New Tricks, Old Dog

o XSS can be used as an agent to map the structure of a network behind a firewall

o Super-charged XSSAdvanced port scanning (WebSockets)

ohttp://www.andlabs.org/tools/jsrecon.html

Page 36: Warning Ahead: Security Storms are Brewing in Your JavaScript Yuval Idan, Technical Director, APAC Checkmarx yuval.idan@checkmarx.com

o Websocket

Fast and efficient network mapping process

Firewall bypass into organization

Page 37: Warning Ahead: Security Storms are Brewing in Your JavaScript Yuval Idan, Technical Director, APAC Checkmarx yuval.idan@checkmarx.com

Client-Side Business Logic

Page 38: Warning Ahead: Security Storms are Brewing in Your JavaScript Yuval Idan, Technical Director, APAC Checkmarx yuval.idan@checkmarx.com

Pacman - winning the odds

o Client site business logic helps to gain efficiency.

o Efficiency brings along security costs

Page 39: Warning Ahead: Security Storms are Brewing in Your JavaScript Yuval Idan, Technical Director, APAC Checkmarx yuval.idan@checkmarx.com

Pacman Demo

Pacman.mp4

Page 40: Warning Ahead: Security Storms are Brewing in Your JavaScript Yuval Idan, Technical Director, APAC Checkmarx yuval.idan@checkmarx.com

Pacman – recommendations

o Don’t trust the client: validate user input

o Do not ever store business logic on the client

Page 41: Warning Ahead: Security Storms are Brewing in Your JavaScript Yuval Idan, Technical Director, APAC Checkmarx yuval.idan@checkmarx.com

GeoLocation

Page 42: Warning Ahead: Security Storms are Brewing in Your JavaScript Yuval Idan, Technical Director, APAC Checkmarx yuval.idan@checkmarx.com

A Variant of Clickjacking

How to trick victims into turning on their PC cameras without them even realizing?

Page 43: Warning Ahead: Security Storms are Brewing in Your JavaScript Yuval Idan, Technical Director, APAC Checkmarx yuval.idan@checkmarx.com

A Variant of Clickjaking

Demohttp://localhost/bookstore/k2.html

Page 44: Warning Ahead: Security Storms are Brewing in Your JavaScript Yuval Idan, Technical Director, APAC Checkmarx yuval.idan@checkmarx.com

A Variant of Clickjaking

Against attacks focused on social engineeringThere is only one solution

Awareness

Page 45: Warning Ahead: Security Storms are Brewing in Your JavaScript Yuval Idan, Technical Director, APAC Checkmarx yuval.idan@checkmarx.com

Summary

o HTML5 brings enhancements to Web development

o …which comes with some great enhancements to security vulnerabilities

Page 46: Warning Ahead: Security Storms are Brewing in Your JavaScript Yuval Idan, Technical Director, APAC Checkmarx yuval.idan@checkmarx.com

Demo

Page 47: Warning Ahead: Security Storms are Brewing in Your JavaScript Yuval Idan, Technical Director, APAC Checkmarx yuval.idan@checkmarx.com

Thank You!Yuval Idan |

[email protected]