The Dark Side of Ajax Jacob West Fortify Software Mashup Pink - - PowerPoint PPT Presentation

the dark side of ajax
SMART_READER_LITE
LIVE PREVIEW

The Dark Side of Ajax Jacob West Fortify Software Mashup Pink - - PowerPoint PPT Presentation

The Dark Side of Ajax Jacob West Fortify Software Mashup Pink Floyd AJAX all purpose cleaner Dark Side of the Moon Ajax Fancier and easier-to-use web applications using: A synchronous Web 1.0 J avaScript Server Web page A nd


slide-1
SLIDE 1

The Dark Side of Ajax

Jacob West Fortify Software

slide-2
SLIDE 2

Mashup

Pink Floyd Dark Side of the Moon AJAX all purpose cleaner

slide-3
SLIDE 3

Ajax

Fancier and easier-to-use web applications using:

Asynchronous JavaScript And XML

Matter of degree, not kind

Server (smart) Web page (dumb) Server (smart) Web page (smart) Web 1.0 Ajax

slide-4
SLIDE 4

Success is foreseeing failure

– Henry Petroski

slide-5
SLIDE 5

Cross-Site Scripting

<c:if test="${param.sayHello}"> Hello ${param.name}! </c:if> “We never intended the code that's in there to actually be production-ready code.”

  • Ryan Asleson
slide-6
SLIDE 6

Reliving Past Mistakes

Cross-site scripting looks more and more like

buffer overflow

Cross-site Scripting

Allows arbitrary code execution Easy mistake to make Exploit is easy to write Well known problem for a decade

Buffer Overflow

Allows arbitrary code execution Easy mistake to make in C/C++ Exploit is hard to write Well known problem for decades

slide-7
SLIDE 7

What’s Wrong with Ajax?

Today’s rage or tomorrow’s security disaster? Could more JavaScript possibly be better? Sample of the almost 400 JavaScript CVE entries:

CVE-2007-1794: The Javascript engine in Mozilla 1.7 and earlier… can allow remote attackers to execute arbitrary code. CVE-1999-0793 Internet Explorer allows remote attackers to read files by redirecting data to a Javascript applet. CVE-1999-0790 A remote attacker can read from a Netscape user's cache via JS CVE-1999-0347 Internet Explorer 4.01 allows remote attackers to read local files and spoof web pages via a "%01" character in an "about:" Javascript URL, which causes Internet Explorer to use the domain specified

slide-8
SLIDE 8

Overview

Introduction Ajax for… Developers Hackers Risks Old New State of the frameworks Automated protections The future of Ajax

slide-9
SLIDE 9

AJAX FOR DEVELOPERS

slide-10
SLIDE 10

Ajax From the Programmer’s Perspective

Increased complexity makes frameworks attractive Popular toolkits for Ajax development include: Google Web Toolkit (GWT) Direct Web Remoting (DWR) Microsoft ASP.NET AJAX (Codename Atlas) Client-side libraries (e.g. Prototype and Dojo) Also popular: ad-hoc Ajax (roll-your-own)

slide-11
SLIDE 11

Ad-hoc Atlas GWT DWR

high

high low

Back-of-the-Napkin Analysis

slide-12
SLIDE 12

Ajax - The Case of the Vanishing “X”

XML being replaced by more JavaScript/JSON

{ "book": { "title":"JavaScript, the Definitive Guide", "publisher":"O'Reilly", "author":"David Flanagan", "cover":"/images/cover_defguide.jpg", "blurb":”elit." } } <book> <title>JavaScript, the Definitive Guide</title> <publisher>O'Reilly</publisher> <author>David Flanagan</author> <cover src="/images/cover_defguide.jpg" /> <blurb>elit.</blurb> </book> XML JSON

slide-13
SLIDE 13

AJAX FOR HACKERS

slide-14
SLIDE 14

Ajax For Malware

Exploit writers buy JavaScript books too Web 2.0 exploits for Web 1.0 vulnerabilities MySpace worm Port scanning behind your firewall Jikto

slide-15
SLIDE 15

MySpace Worm - 1/3

MySpace does bad input validation Users to post a subset of HTML on their pages No <script> tags, no use of the word “javascript”, etc

slide-16
SLIDE 16

MySpace Worm - 2/3

User “Samy” discovers some holes Some browsers allow JavaScript in style attributes Some browsers interpret “java\nscript” as “javascript” Circumvents MySpace's efforts to prevent JavaScript

slide-17
SLIDE 17

MySpace Worm - 3/3

Samy adds JavaScript (Ajax) to his page Visitors to his page automatically add Samy as a

friend and inserts “Samy is my hero” into their profile

Visitors to a page where Samy is a friend take the

same actions

MySpace goes down

slide-18
SLIDE 18

Port Scanning Behind Firewalls - 1/2

Server Malicious Web page Firewall

1) “show me dancing pigs!” 2) “check this out”

Browser

scan scan scan 3) port scan results

slide-19
SLIDE 19

Port Scanning Behind Firewalls - 2/2

Request images from internal IPs

(<img src=“192.168.0.4:8080”/>

Use timeout/onerror to determine if hosts respond <iframe/> with timer/onload to map web servers Fingerprint webapps using known image names

slide-20
SLIDE 20

Jikto - 1/2

JavaScript vulnerability scanner

(Billy Hoffman with credit to pdp for crawler)

Spreads like worm over XSS vulnerabilities Uses Google as proxy to bypass same origin policy Same Origin Policy: basis for browser security JavaScript can't see content from other domains Protects sites from each other

slide-21
SLIDE 21

Jikto - 2/2

Victim Target Site Malicious Site Google Translate "Infected" page

attack vulnerability scanner

slide-22
SLIDE 22

Moral to the Story

No new vulnerabilities here, just better exploits Good offense makes good defense more important Good offense is making fast progress

slide-23
SLIDE 23

OLD RISKS RECONSIDERED

slide-24
SLIDE 24

Defending Ajax: Old Risks Reconsidered

New name, same game

Old vulnerabilities, new programming language Input validation Exposing the server

slide-25
SLIDE 25

Old Vulnerabilities, New Language

Cross-site scripting in pure JavaScript:

q = location.search.split(“q=“)[1]; q = unescape(q); div.innerHTML = “searching for “ + q;

slide-26
SLIDE 26

Easy to lose track of where validation is performed

Old Risks: Input validation - 1/3

Client Server

slide-27
SLIDE 27

Old Risks: Input validation - 2/3

More entry points on the server More, smaller, requests Decentralized design Easy to over-expose

slide-28
SLIDE 28

Old Risks: Input validation - 3/3

More subtle entry points on the server Looks like Web services Hard to tell if method call initiated locally (safe) or

remotely (dangerous)

Harder to tell what can be trusted

slide-29
SLIDE 29

Example: DWR

Old Risk: Exposing Yourself

<dwr> <allow> ... <create creator=”new” javascript=”ApartmentDAO” class=”dwr.sample.ApartmentDAO”> <exclude method=”countApartments”/> </create> </allow> </dwr>

slide-30
SLIDE 30

NEW PROBLEMS

slide-31
SLIDE 31

New: Harder to Test

Dirty-data shooters rely on Web 1.0 conventions HTTP HTML forms 1 parameter = 1 application variable Ajax = more complex data structures Ajax requires sophisticated browser emulation How do you spider an Ajax application? Looks much more like testing conventional software

slide-32
SLIDE 32

Old: Cross-Site Request Forgery (CSRF)

Cross-Site Request Forgery JavaScript submits HTTP requests on victim's behalf Allows attacker to submit commands, but not inspect the

response (Same Origin Policy)

Application is vulnerable if it: Relies on user’s identity

(e.g. persistent or session cookies)

Does not have secondary authentication mechanism Attack against data integrity

slide-33
SLIDE 33

New: JavaScript Hijacking - 1/2

Builds on CSRF Breaks confidentiality through loophole in SOP Vulnerable if: Site responds to HTTP GET Transmits sensitive data in JavaScript syntax

slide-34
SLIDE 34

New: JavaScript Hijacking - 2/2

Malicious Server

Mal page { witness code } <script src=“...”>

1) “show me dancing pigs!” 2) “check this out”

Browser

GET 3) confidential data JavaScript

Ajax Application

slide-35
SLIDE 35

Defenses Against JavaScript Hijacking

Prevent CSRF Decline malicious requests by requiring unique token

… and remember

Default to POST not enough

(Developers add GET so that result can be cached)

Check for a known HTTP header not enough

(Flash CSRF vulnerability)

Prevent execution of JavaScript while(1);, /* ... */, etc

… and remember

calling parseJSON() rather than eval() does not help

slide-36
SLIDE 36

STATE OF THE FRAMEWORKS

slide-37
SLIDE 37

How 12 Popular Frameworks Stack Up

Framework Summary Prevents JavaScript Hijacking? Prototype Supports JSON. Defaults to POST when no method is specified, but is easily customizable for using either POST or GET. No Script.aculo.us Supports JSON. Provides additional UI controls and uses the Prototype library for generating requests. No Dojo Supports JSON. Defaults to POST, but does not explicitly prevent JavaScript Hijacking. No DWR 1.1.4 Uses an expanded version of JSON. Does not implement any JavaScript Hijacking prevention mechanisms. No Moo.fx Supports JSON. Defaults to POST, but can easily be configured to use GET. No jQuery Supports JSON. Defaults to GET. No Yahoo! UI Supports JSON. Responds to GET requests. No Rico Does not currently support JSON, but will in the future. Supports XML as a data transfer

  • format. Defaults to GET.

N/A Microsoft Atlas Supports JSON. Uses POST by default, but allows programmers to easily change POST to GET and encourages doing so for performance and caching. No MochiKit Supports JSON. Defaults to GET. No xajax Does not currently support JSON. Supports XML as a data transfer format. N/A GWT Supports JSON. Uses POST by default; however, documentation describes how to make GET requests instead and does not mention any security ramifications. No

slide-38
SLIDE 38

Popular Framework Responses - 1/3

We will fix it “…Thanks for the heads up on this…” “…Thanks for the paper. We are looking at the issue,

and we’re starting to formulate some solutions that mesh well with what you’re suggesting…”

slide-39
SLIDE 39

Popular Framework Responses - 2/3

This is not a client-side framework problem “…Entirely dependent on the server to do the right thing” “Why the hell should there be security documentation in

client frameworks?”

“I added comment stripping support so that people would

shut up, not because it’s useful in theory or practice…”

slide-40
SLIDE 40

Popular Framework Responses - 3/3

You are recommending bad practices “But by recommending bad practices, and by failing

to strongly recommend good practices, you are making things worse…”

slide-41
SLIDE 41

Proof is in the Pudding

3 releases that contain a fix: Dojo 0.4.3

Implemented /* … */, but… Only for JSON, not JavaScript

DWR 2.0

Implemented double-cookie submission Accepted our /* … */ patch

Prototype 1.5.1

Implemented /* … */

3 frameworks planned a fix: GWT MochiKit Script.aculo.us

Head-in-the-sand defense

slide-42
SLIDE 42

Also Good

4 mentioned in documentation: dojotoolkit.org/2007/04/02/note-javascript-hijacking getahead.org/dwr/security/script-tag-protection www.prototypejs.org/learn/json developer.yahoo.com/security/

slide-43
SLIDE 43

AUTOMATED PROTECTIONS

slide-44
SLIDE 44

Static Analysis (Fortify SCA)

Challenge: Lacking standard way to build dynamic JavaScript Identify the use of vulnerable frameworks API calls Configuration files Source files Identify construction of JavaScript responses response.setContentType(“text/javascript”)

slide-45
SLIDE 45

Real-Time Analysis (Fortify RTA)

Guard to prevent CSRF Insert CSRF token on the page using JavaScript Verify the unique token is present in requests

slide-46
SLIDE 46

CONCLUSIONS

slide-47
SLIDE 47

Confusion over JavaScript Hijacking

A system administration problem Not unique – just a way to parse results of CSRF Not interesting – just “View Source” JavaScript Hijacking can be prevented by: Defaulting to HTTP POST Using parseJSON() instead of eval() Using object notation {} rather than array notation [] Checking for “application/json” in content-type

slide-48
SLIDE 48

The Future of Ajax - 1/2

Frameworks offer a chance to build security in Prevent CSRF Provide secure defaults Opportunity for better validation Better separation between display and controller Better definition for browser/server interaction

slide-49
SLIDE 49

The Future of Ajax - 2/2

Better Web standards Cookies: broken, need *working* HTTP only cookies Browsers: broken, need to distinguish between scripts

from different domains

Flash? Documented security best-practices Hard to mistake data and code Well-defined system for cross-domain communication

slide-50
SLIDE 50

Mashups Aren’t Secure

Scripts from multiple domains == security problem Fine for maps, not okay for confidential data

Pink Floyd Dark Side of the Moon AJAX all purpose cleaner

slide-51
SLIDE 51

Summary

Ajax: a matter of degree Attack techniques improving quickly Technology pushed well past original design goals Old best practices still apply Don’t trust the client Protect the server New challenges Harder to test More complexity == more room for error A new ally Build security into Ajax frameworks

slide-52
SLIDE 52

Jacob West jacob@fortify.com