The OWASP Foundation OWASP EU09 Poland Exploiting Web 2.0

28
Copyright © The OWASP Foundation Permission is granted to copy, distribute and/or modify this document under the terms of the OWASP License. The OWASP Foundation OWASP EU09 Poland http://www.owasp.org Exploiting Web 2.0 – Next Generation Vulnerabilities Shreeraj Shah Chapter Lead Founder & Director Blueinfy Solutions [email protected] 2 OWASP AppSecEU09 Poland Who Am I? Founder & Director Blueinfy Solutions Pvt. Ltd. SecurityExposure.com Past experience Net Square, Chase, IBM & Foundstone Interest Web security research Published research Articles / Papers – Securityfocus, O’erilly, DevX, InformIT etc. Tools – wsScanner, scanweb2.0, AppMap, AppCodeScan, AppPrint etc. Advisories - .Net, Java servers etc. Books (Author) Web 2.0 Security – Defending Ajax, RIA and SOA Hacking Web Services Web Hacking http://shreeraj.blogspot.com [email protected] http://www.blueinfy.com

Transcript of The OWASP Foundation OWASP EU09 Poland Exploiting Web 2.0

Page 1: The OWASP Foundation OWASP EU09 Poland Exploiting Web 2.0

Copyright © The OWASP FoundationPermission is granted to copy, distribute and/or modify this document under the terms of the OWASP License.

The OWASP Foundation

OWASPEU09 Poland

http://www.owasp.org

Exploiting Web 2.0 – Next Generation Vulnerabilities

Shreeraj ShahChapter LeadFounder & Director Blueinfy [email protected]

2OWASP AppSecEU09 Poland

Who Am I?

Founder & DirectorBlueinfy Solutions Pvt. Ltd.SecurityExposure.com

Past experienceNet Square, Chase, IBM & Foundstone

InterestWeb security research

Published researchArticles / Papers – Securityfocus, O’erilly, DevX, InformIT etc.Tools – wsScanner, scanweb2.0, AppMap, AppCodeScan, AppPrint etc.Advisories - .Net, Java servers etc.

Books (Author) Web 2.0 Security – Defending Ajax, RIA and SOAHacking Web Services Web Hacking

http://[email protected]://www.blueinfy.com

http://[email protected]://www.blueinfy.com

Page 2: The OWASP Foundation OWASP EU09 Poland Exploiting Web 2.0

3OWASP AppSecEU09 Poland

Real Case Study

Web 2.0 Portal – Buy / Sell Technologies & Components – Dojo, Ajax, XML Services, Blog, WidgetsScan with tools/products failedfailedSecurity issues and hacks

SQL injection over XMLAjax driven XSSSeveral XSS with Blog componentSeveral information leaks through JSON fuzzingCSRF on both XML and JS-Array

» HACKED» DEFENSE

4OWASP AppSecEU09 Poland

Web 2.0 Architecture and Security

Page 3: The OWASP Foundation OWASP EU09 Poland Exploiting Web 2.0

5OWASP AppSecEU09 Poland

Web 2.0 Architecture

HTML / JS / DOM

RIA (Flash)

Ajax

Browser

Internet

Blog

Web 2.0 Start

Database Authentication

Application Infrastructure

Web ServicesEnd point

InternetMails

News

Documents

Weather

Bank/Trade

RSS feeds

6OWASP AppSecEU09 Poland

Ajax Flash / RIA

HTML/CSS JavaScript

Widget DOM

SOAP XML-RPC

HTTP/HTTPS

JSON XML

RSS/ATOM Text

JS-Objects Custom

SOA/WOA SaaS

Web Services Ajax

Traditional APIs

REST

Client Layer

Protocol Layer

Structure Layer

Server Layer

Web 2.0 Components

Page 4: The OWASP Foundation OWASP EU09 Poland Exploiting Web 2.0

7OWASP AppSecEU09 Poland

Case study - Pageflakes

8OWASP AppSecEU09 Poland

Case study - Pageflakes

Widgets

Web Services

Page 5: The OWASP Foundation OWASP EU09 Poland Exploiting Web 2.0

9OWASP AppSecEU09 Poland

Impact of Web 2.0

Application Infrastructure

Multiple sources (Urge for integrated information platform)

Single place information (No urge for integration)

(AI4) Information sharing

Asynchronous & Cross-domains (proxy)

SynchronousPostbackRefresh and Redirect

(AI3) Communication methods

XML, JSON, JS Objects etc.HTML transfer (AI2) Information structures

SOAP, XML-RPC, REST etc. over HTTP & HTTPS

HTTP & HTTPS(AI1) Protocols

Web 2.0Web 1.0Changing dimension

10OWASP AppSecEU09 Poland

Impact of Web 2.0

Security Threats

Both server and client side exploitation

Server side exploitation (T4) Exploitation

• Web services [Payloads]• Client side [XSS & XSRF]

Server side [Typical injections](T3) Vulnerabilities

• Multiple technologies• Information sources• Protocols

Limited(T2) Dependencies

Scattered and multipleStructured(T1) Entry points

Web 2.0Web 1.0Changing dimension

Page 6: The OWASP Foundation OWASP EU09 Poland Exploiting Web 2.0

11OWASP AppSecEU09 Poland

Changes in approach

Methodology

Client-side analysis neededFocus on server-side onlyCode reviews

Client-side with Ajax & FlashOn the server-side [Difficult]Reverse engineering

Difficult with Ajax and web servicesEasy after discoveryAutomated attacks

Difficult with extensive AjaxStructured and simpleScanning

Several streamsStructuredEnumeration

Difficult with hidden callsSimple Discovery

Empowered with searchTypical with "Host" and DNSFootprinting

Web 2.0Web 1.0Changing dimension

12OWASP AppSecEU09 Poland

Web 2.0 Security

Complex architecture and confusion with technologiesWeb 2.0 worms and viruses – Sammy, Yammaner & SpaceflashAjax and JavaScripts – Client side attacks are on the riseWeb Services attacks and exploitationFlash clients are running with risks

Page 7: The OWASP Foundation OWASP EU09 Poland Exploiting Web 2.0

13OWASP AppSecEU09 Poland

Web 2.0 Security

Mashup and un-trusted sourcesRSS feeds manipulation and its integrationSingle Sign On and information convergence at one pointWidgets and third-party components are bringing security concernsOld attacks with new carriers

14OWASP AppSecEU09 Poland

Vulnerabilities & Exploits

Clients side security XML protocols and issues Information sources and processing Information structures’ processing SOA and Web services issues Web 2.0 server side concerns

Page 8: The OWASP Foundation OWASP EU09 Poland Exploiting Web 2.0

15OWASP AppSecEU09 Poland

Web 2.0 – Methodologies & Challenges

16OWASP AppSecEU09 Poland

Methodology, Scan and Attacks

Footprinting & Discovery

Enumeration & Crawling

Attacks and Scanning

Config Scanning

Web 2.0 Firewall

Secure Coding

Web 2.0 Battle Field (Resource)

Secure Web 2.0

Black White

Defense

Code Scanning

Page 9: The OWASP Foundation OWASP EU09 Poland Exploiting Web 2.0

17OWASP AppSecEU09 Poland

Challenges

How to identify possible hosts running the application? – Cross Domain.Identifying Ajax and RIA calls Dynamic DOM manipulations pointsIdentifying XSS and XSRF vulnerabilities for Web 2.0Discovering back end Web Services - SOAP, XML-RPC or REST.How to fuzz XML and JSON structures? Web Services assessment and audit Client side code review Mashup and networked application points

18OWASP AppSecEU09 Poland

Web 2.0 Fingerprinting, Discovery & Crawling

Page 10: The OWASP Foundation OWASP EU09 Poland Exploiting Web 2.0

19OWASP AppSecEU09 Poland

Application Server Fingerprinting

Identifying Web and Application servers.Forcing handlers to derive internal plugin or application servers like Tomcat or WebLogic.Looking for Axis or any other Web Services container.Gives overall idea about infrastructure.

20OWASP AppSecEU09 Poland

Fingerprinting

Ajax based frameworks and identifying technologies.Running with what?

AtlasGWTEtc.

Helps in identifying weakness of the application layer.Good idea on overall application usage.Fingerprinting RIA components running with Flash.Atlas/Ajax.NET script discovery and hidden entry points identification.Scanning for other frameworks.

Page 11: The OWASP Foundation OWASP EU09 Poland Exploiting Web 2.0

21OWASP AppSecEU09 Poland

Discovery

Ajax running with various different structures.Developers are adding various different calls and methods for it.JavaScript can talk with back end sources.Mashups application talking with various sources.It has significant security impact.JSON, Array, JS-Object etc.Identifying and Discovery of structures.

22OWASP AppSecEU09 Poland

Discovery

JSON

XML JS-Script

JS-ArrayJS-Object

Page 12: The OWASP Foundation OWASP EU09 Poland Exploiting Web 2.0

23OWASP AppSecEU09 Poland

Crawling challenges

Dynamic page creation through JavaScript using Ajax.DOM events are managing the application layer.DOM is having clear context.Protocol driven crawling is not possible without loading page in the browser.

24OWASP AppSecEU09 Poland

Ajax driven site

Page 13: The OWASP Foundation OWASP EU09 Poland Exploiting Web 2.0

25OWASP AppSecEU09 Poland

Crawling with Ruby/Watir

26OWASP AppSecEU09 Poland

Web 2.0 Vulnerabilities & Exploits

Page 14: The OWASP Foundation OWASP EU09 Poland Exploiting Web 2.0

27OWASP AppSecEU09 Poland

Ajax code review

Ajax scripts are on client side and important to do source sifting on itLooking for business logic and vulnerabilities on Ajax componentsJavaScript analysis and reviewLooking for malicious calls and pattern of malware if anyVery sensitive in mashup contextIn browser debugging would be very handy

28OWASP AppSecEU09 Poland

Source Code Disclosure

Hidden Ajax calls fetching filesDiscovering those callsExploiting with ../ and getting filesCommon with content managements systemsRIA calls can be discovered as well

Page 15: The OWASP Foundation OWASP EU09 Poland Exploiting Web 2.0

29OWASP AppSecEU09 Poland

SQL 2.0

SQL injection over JSON streamsFlash based pointsXML data access layer exposureErrors are not standard in 500200 and messages are embedded in the streamApplication features are AsynchronousAsync. SQL injection is interesting vulnerability with Web 2.0 applicationsRSS feed generation happens in Async. way and possible to exploit

30OWASP AppSecEU09 Poland

XPATH injection

XPATH parsing standard errorXPATH is method available for XML parsingMS SQL server provides interface and one can get table content in XML format.Once this is fetched one can run XPATH queries and obtain results.What if username/password parsing done on using XPATH – XPATH injection

Page 16: The OWASP Foundation OWASP EU09 Poland Exploiting Web 2.0

31OWASP AppSecEU09 Poland

Cross Site Request Forgery (CSRF)

Generic CSRF is with GET / POSTForcefully sending request to the target application with cookie replayLeveraging tags like

IMGSCRIPTIFRAME

Not abide by SOP or Cross Domain is possible

32OWASP AppSecEU09 Poland

Cross Site Request Forgery (CSRF)

Is it possible to do CSRF to XML streamHow?It will be POST hitting the XML processing resources like Web ServicesJSON CSRF is also possibleInteresting check to make against application and Web 2.0 resources

Page 17: The OWASP Foundation OWASP EU09 Poland Exploiting Web 2.0

33OWASP AppSecEU09 Poland

One Way CSRF Scenario

34OWASP AppSecEU09 Poland

One Way CSRF Scenario

Page 18: The OWASP Foundation OWASP EU09 Poland Exploiting Web 2.0

35OWASP AppSecEU09 Poland

One Way CSRF Scenario

36OWASP AppSecEU09 Poland

One Way CSRF Scenario

Page 19: The OWASP Foundation OWASP EU09 Poland Exploiting Web 2.0

37OWASP AppSecEU09 Poland

One-Way CSRF

38OWASP AppSecEU09 Poland

One-Way CSRF

<html><body><FORM NAME="buy" ENCTYPE="text/plain" action="http://trade.example.com/xmlrpc/trade.rem" METHOD="POST">

<input type="hidden" name='<?xml version'value='"1.0"?><methodCall><methodName>stocks.buy</methodName><params><param><value><string>MSFT</string></value></param><param><value><double>26</double></value></param></params></methodCall>'></FORM><script>document.buy.submit();</script></body></html>

Page 20: The OWASP Foundation OWASP EU09 Poland Exploiting Web 2.0

39OWASP AppSecEU09 Poland

Forcing XML

Splitting XML stream in the form.Possible through XForms as well.Similar techniques is applicable to JSON as well.

40OWASP AppSecEU09 Poland

Cross Site Scripting (XSS)

TraditionalPersistentNon-persistent

DOM driven XSS – Relatively newEval + DOM = Combinational XSS with Web 2.0 applications

Page 21: The OWASP Foundation OWASP EU09 Poland Exploiting Web 2.0

41OWASP AppSecEU09 Poland

Cross Site Scripting (XSS)

What is different?Ajax calls get the stream.Inject into current DOM using eval() or any other means.May rewrite content using document.write or innerHTML calls.Source of stream can be un-trusted.Cross Domain calls are very common.

42OWASP AppSecEU09 Poland

DOM

Dynamic HTMLBrowser loads Document Object ModelDOM can be manipulated by scripts in the browserComponents

HistoryLocationForms etc….

Page 22: The OWASP Foundation OWASP EU09 Poland Exploiting Web 2.0

43OWASP AppSecEU09 Poland

XHR - Ajax

function getajax(){

var http;if(window.XMLHttpRequest){

http = new XMLHttpRequest();}else if (window.ActiveXObject){

http=new ActiveXObject("Msxml2.XMLHTTP");if (! http){

http=new ActiveXObject("Microsoft.XMLHTTP");}

}http.open("GET", "./ajax.txt", true);http.onreadystatechange = function(){

if (http.readyState == 4) {response = http.responseText; document.getElementById('main').innerHTML = response;

}}http.send(null);}

44OWASP AppSecEU09 Poland

DOM based XSS

if (http.readyState == 4) {var response = http.responseText; var p = eval("(" + response + ")");document.open(); document.write(p.firstName+"<br>");document.write(p.lastName+"<br>");document.write(p.phoneNumbers[0]); document.close();

Page 23: The OWASP Foundation OWASP EU09 Poland Exploiting Web 2.0

45OWASP AppSecEU09 Poland

DOM based XSS

document.write(…) document.writeln(…) document.body.innerHtml=…document.forms[0].action=…document.attachEvent(…) document.create…(…) document.execCommand(…) document.body. …window.attachEvent(…) document.location=…document.location.hostname=…document.location.replace(…) document.location.assign(…) document.URL=…window.navigate(…)

46OWASP AppSecEU09 Poland

DOM based XSS

document.open(…) window.open(…) window.location.href=… (and assigning to location’s href, host and hostname) eval(…) window.execScript(…) window.setInterval(…) window.setTimeout(…)

Page 24: The OWASP Foundation OWASP EU09 Poland Exploiting Web 2.0

47OWASP AppSecEU09 Poland

Scenario

Blog

DBattacker

Web app

Web app

proxy

WebClient

8008

JSON

eval()

XSS

Posting to the site[Malicious code]

JSONfeed

WebServer

Vulnerable stream coming through proxy

Hijack

48OWASP AppSecEU09 Poland

XSS with JSON stream

Page 25: The OWASP Foundation OWASP EU09 Poland Exploiting Web 2.0

49OWASP AppSecEU09 Poland

XSS with RIA

Applications running with Flash componentsgetURL – injection is possibleSWFIntruderFlasm/Flare

(http://www.nowrap.de/)

50OWASP AppSecEU09 Poland

RSS feeds - Exploits

RSS feeds coming into application from various un-trusted sources.Feed readers are part of 2.0 Applications.Vulnerable to XSS.Malicious code can be executed on the browser.Several vulnerabilities reported.

Page 26: The OWASP Foundation OWASP EU09 Poland Exploiting Web 2.0

51OWASP AppSecEU09 Poland

RSS feeds

52OWASP AppSecEU09 Poland

Mashups Hacks

API exposure for Mashup supplier application.Cross Domain access by callback may cause a security breach.Confidential information sharing with Mashup application handling needs to be checked – storing password and sending it across (SSL)Mashup application can be man in the middle so can’t trust or must be trusted one.

Page 27: The OWASP Foundation OWASP EU09 Poland Exploiting Web 2.0

53OWASP AppSecEU09 Poland

Widgets/Gadgets - Hacks

DOM sharing model can cause many security issues. One widget can change information on another widget – possible.CSRF injection through widget code.Event hijacking is possible – Common DOMIFrame – for widget is a MUST

54OWASP AppSecEU09 Poland

SOA Hacks

Discovering Web ServicesProfiling and Enumerating through WSDLAttacking Web ServicesSOAP manipulation is the key

Page 28: The OWASP Foundation OWASP EU09 Poland Exploiting Web 2.0

55OWASP AppSecEU09 Poland

Conclusion – Questions…

http://[email protected]://www.blueinfy.com

http://[email protected]://www.blueinfy.com