OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

95

description

Abdullah Ulber works at Banan IT as a senior software architect, web developer and education manager. He looks back to more than ten years of professional software development, specialising in web applications based on ASP.NET MVC, HTML5 and Silverlight. He is a keen follower of all trends in the web world and enjoys passing on his knowledge in captivating presentations and courses. Outside his work, he is an organising member of the OWASP local chapter in Khartoum. Before his move to Sudan, Abdullah was the co-organiser of the Swiss Olympiad in Informatics and the team leader of the Swiss delegation to the International Olympiads in Informatics from 1998 to 2005. He holds a master’s degree in computer science from ETH Zurich. This session was held on Saturday 12/01/2013. Check our best shots from the event on our Facebook group: http://fb.com/groups/OWASP.Khartoum

Transcript of OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

Page 1: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013
Page 2: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

About the Speaker

Swiss Olympiad in Informatics

MSc in Computer Science

Abdullah Ulber

Senior Software Architect

Web Developer

Volunteer at OWASP Khartoum

Page 3: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

OWASP Mission

"to make application security visibleso that people and organisations can make informed decisions about application security risks"

Lots of demos Lots of diagrams

Lots of stuff covered“Everything you ever wanted

to know about CSRF ”

Page 4: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

What OWASP is NOT

Hogwarts School of Witchcraft And Wizardry

Page 5: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

Product Neutrality

“OWASP does not endorse or recommend commercial products or services, allowing our community to remain vendor neutral with the collective wisdom of the best minds in software security worldwide.”

Page 6: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

Introduction Motivation CharacterStudy

How CSRF Works Protections

Page 7: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

INTRODUCTION

Page 8: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

CSRF, pronounced "sea surf"

First mention in 2001 by Peter Watkins.

“I'm afraid CSRF is going to be a mess to deal with in many cases. Like trying to tame the seas.”

The attack withthe coolest name.

Page 9: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

A Magic Trick

Page 10: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

MOTIVATION

Page 11: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

Predictions

OWASP 2007: “CSRF is more prevalent than its current ranking would indicate, and it can be highly dangerous.”

MITRE CVE Trends, May 2007:“… there will likely be a significant increase in CSRF reports.”

WhiteHat Security, July 2007:“The Sleeping Giant”

2007

Page 12: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

Interest over Time

2005 2006 2007 2008 2009 2010 2011 2012

Page 13: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

Unlike XSS and SQL Injection

2005 2006 2007 2008 2009 2010 2011 2012

SQL Injection

XSS

Page 14: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

Let’s Be Fair

2005 2006 2007 2008 2009 2010 2011 2012

SQL Injection

XSS

CSRF

Page 15: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

Total 2011 Q1 2012 Q2 2012 Q3 2012

14 1021 12

24 38

43

24

30

4027

35

3212 9

29 CSRF

Directory Traversal

XSS

SQL Injection

CSRF and XSS: The Evil Twins

Statistics by Firehost

Page 16: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

In the News

Page 17: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

Strike #1 Feb 2008

Page 18: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

Strike #2 Sept 2008

Page 19: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

Strike #3 May 2010

Page 20: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

A Career Alternative? Aug 2012

Page 21: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

More Victims

cPanelosCommerceAmazonEbayGmail… and countless more

Page 22: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

A CHARACTER STUDY

Page 23: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

Remote Control

Page 24: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

No Damage Ceiling

Purchase of unwanted/unexpected items

Change the “Ship To:” address

Password Reset / User Account modification

Add contact or “friend”

Page 25: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

Silent but Deadly

No browser warnings

No popups

No unusual behaviour whatsoever

Page 26: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

Easily Mountable

No DNS manipulations

No wire-tapping

“Even a monkey can do it.”

Page 27: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

Sneaky

Page 28: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

Sneaky

Page 29: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

Intranet Penetration

Page 30: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

Administration Areas

Page 31: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

Underestimated

Hard to detect

CSRF attacks fly under radar

Under-reported

Page 32: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

Unprotected by Default

Unlike XSS and SQL Injection

1. Awareness of the threat

2. Knowledge of the protection

3. Use of protection

Page 33: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

A Toxic Mix

Remote control without damage ceiling

Silent But deadly

Sneaky

Underestimated

Unprotected by default

Page 34: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

HOW CSRF WORKS

Page 35: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

Internet 101

Page 36: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

GET

Page 37: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

POST

Page 38: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

Regular Browsing

link

form

link

form

Browser Web ServerGET

GET

POST

Page 39: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

User Identity

Page 40: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

On the Server: Session State

3059750700012299210

Page 41: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

On the Client: Cookies

cnn.com

owasp.sd

3059750700

012299210

Page 42: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

Regular Browsing With Identity

Browser Web Server

link

form

GET

POST

Page 43: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

Prepare For Attack

Page 44: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

POST-Based CSRFBrowser Web Server

form

Evil Web Server

JavaScript

POST

POST

Page 45: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

From the Server’s Perspective

Web Server

Confused deputy problem

Page 46: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

GET-Based CSRF (Poor Man’s Version)

Browser Web Server

form

Evil Web Server

image

GET

POST

Page 47: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

PROTECTIONS

Page 48: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

Ineffective Protections

Page 49: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

Referer Header

Page 50: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

The Server’s Perspective with Referer

Web Serverreferer

Page 51: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

Corporate Information Leaks

link

referer

Page 52: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

Behaviour Tracking

Tracking site

Tracking cookie

Page 53: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

Real-Life Behaviour Tracking

Page 54: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

A Helpful Venn Diagram

Page 55: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

HTTPS

Page 56: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

HTTPSBrowser Web Server

Evil Web Server

JavaScript

POST

formPOST

protected

Page 57: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

Protected Cookies

httpOnly “secure”

invisible to JavaScript sent only via HTTPS

Page 58: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

Protected Cookies: httpOnlyBrowser Web Server

Evil Web Server

JavaScript

POSTcan’t read

formPOST

can’t read

Page 59: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

Protected Cookies: secureBrowser Web Server

Evil Web Server

JavaScript

POST

formPOST

protected

Page 60: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

Ineffective Protections: Summary

Referer Header

HTTPS Secure Cookies

Would be the perfect solution but suffers from privacy issues.

Good in their own respects, but unfortunately do not help with CSRF.

Page 61: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

Effective Protections

Page 62: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

Protections by Location

BrowserUser App

Server

Server-sideClient-side

Page 63: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

Client-Side Protections

Page 64: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

Separation of Concerns

Page 65: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

Use of Separate Browsers

facebook email everything else

Page 66: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

Use of Separate BrowsersBrowser A Web Server

form

Evil Web Server

JavaScript

POST

POST

Browser B

Page 67: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

Sign Out

Page 68: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

Sign OutBrowser Web Server

form

Evil Web Server

JavaScript

POST

POST

Page 69: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

Cookie Expiry

Page 70: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

Cookie ExpiryBrowser Web Server

form

Evil Web Server

JavaScript

POST

POST

Page 71: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

Anti-CSRF Browser Add-Ons

CsFire

NoScript: Application Boundaries Enforcer (ABE)

Request Policy

Page 72: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

Anti-CSRF Browser Add-Ons (CsFire)

Browser Web Server

form

Evil Web Server

JavaScript

POST

POST

Page 73: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

Anti-CSRF Browser Add-Ons (Request Policy)

Browser Web Server

form

Evil Web Server

JavaScript

POST

Page 74: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

Server-Side Protections

The server has to defend itself.

Don’t rely on the client.

Let the client prove its legitimate origin.

Page 75: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

The Burden of Proof

Web Server

+ proof

Page 76: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

Re-Authentication

Page 77: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

Re-AuthenticationBrowser Web Server

form

Evil Web Server

JavaScript

password

POST

?

Page 78: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

CAPTCHA

Very unfriendly.

Only proves that you are human.

Page 79: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

CAPTCHABrowser Web Server

form

Evil Web Server

JavaScript

solution

POST

?

Page 80: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

Dual-Factor Authentication

Page 81: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

Dual-Factor AuthenticationBrowser Web Server

form

Evil Web Server

JavaScript

POST

POST

Page 82: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

Request Validation Token

Page 83: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

Request Validation TokenBrowser Web Server

form

Evil Web Server

JavaScript

? POST

POST

can’t read

Page 84: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

Double Submit Token

via cookievia form

aka “Synchroniser Token Pattern” (OWASP terminology)

Page 85: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

Double Submit TokenBrowser Web Server

form

Evil Web Server

JavaScript

POST

?

POST

Page 86: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

Good and Evil on the Web

Client Server

Page 87: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

The Padlock Thief

Page 88: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

Protect the Protection

Page 89: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

HMAC (Hash-based message authentication code)

Protected token

Session identity

Token

?

Page 90: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

Protected Double Submit TokenBrowser Web Server

form

Evil Web Server

JavaScript

POST

?

POST

Page 91: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

Pluggable Protection

Web Server

CSRFGuard Library

Apache IIS

Web ApplicationModSecurity CRS Project

Java .NETPHP

Page 92: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

Take Your Pick

User Friendliness

Effec

tiven

ess

low

high

highlow

separate browsers sign out

re-authenticate

dual factor auth.

double submit token

cookie expiry

CAPTCHA

browser add-ons

Page 93: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

Multiple Protections

double submit token

re-authentication

dual-factor authentication

CAPTCHA

cookie expiry

All !

Page 94: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

Take-Aways

CSRF is a clear and present danger.

The bad news

CSRF is on the rise.

There are many protections available.

The good news

Tools are your friends.

Questions?

Page 95: OWASP Khartoum - CSRF Session - Abdullah Ulber - January 2013

Planned Upcoming Presentations

Hijacking Bonanza (SSL/TSL, NTLM, JSON)

Web Server Hardening (Apache/IIS)

Secure Development Practices (PHP/ASP.NET)

Application Defense in Depth

HTML5 Content Security Policy - The End of XSS ?