Top Banner
JavaScript Static Analysis with IronWASP Nullcon Goa 2012 Lavakumar Kuppan Twitter: @lavakumark e-Mail: [email protected] http://ironwasp.org
51

JavaScript Static Analysis with IronWASP

Feb 12, 2022

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: JavaScript Static Analysis with IronWASP

JavaScript Static Analysis with IronWASPNullcon

Goa 2012

Lavakumar KuppanTwitter: @lavakumarke-Mail: [email protected]://ironwasp.org

Page 2: JavaScript Static Analysis with IronWASP

AboutPenetration Tester

5+ years of experience

Security ResearcherFlash 0-dayWAF bypass 0-day using HPPMultiple HTML5 based attack techniques5th best Web Application Hacking Technique of 2010Attack and Defense Labs – http://andlabs.orgHTML5 Security Resources Repository – http://html5security.org

Page 3: JavaScript Static Analysis with IronWASP

AboutDeveloper

IronWASP (C# + Python + Ruby)

Ravan (PHP + JavaScript)

JS-Recon (JavaScript)

Shell of the Future (C# + JavaScript)

Imposter (C# + JavaScript)

SpeakerBlackHatOWASP AppSec AsiaNullConSecurityByteClubHack

Page 4: JavaScript Static Analysis with IronWASP

Cross-site Scripting??

Page 5: JavaScript Static Analysis with IronWASP

Server-side Vulnerability

Browser Server

http://a.com/search.php?q=<script>alert(1)</script>

<html><head><title>

Search Results for <script>alert(1)</script></title><body>……

Page 6: JavaScript Static Analysis with IronWASP

Not Exactly there is also“DOM based XSS”

[DEMO]

Page 7: JavaScript Static Analysis with IronWASP

DOM XSS Source & Sink

Source:DOM Properties that can be influenced by an attacker

Sink:DOM Properties, JavaScript functions and other client-side entities that can lead to or influence client-side code execution

Page 8: JavaScript Static Analysis with IronWASP

Source Types

Location basedClient-side Storage basedNavigation basedCross-domain

Page 9: JavaScript Static Analysis with IronWASP

Location based Source

locationlocation.hashlocation.hreflocation.pathnamelocation.searchdocument.URLdocument.baseURIdocument.documentURIdocument. URLUnencoded

Page 10: JavaScript Static Analysis with IronWASP

Client-side Storage Based

document.cookiesessionStorage*localStorage*Web SQL Database*Indexed DB*

* HTML5

Page 11: JavaScript Static Analysis with IronWASP

Navigation Based

window.namedocument.referrerhistory (HTML5)

Page 12: JavaScript Static Analysis with IronWASP

Cross-domain

postMessage*XHR call responses from 3rd party JavaScript APIJSON calls backs from 3rd party JavaScript API

*HTML5

Page 13: JavaScript Static Analysis with IronWASP

Sink Types

Execution basedUrl BasedHTML BasedOthers

Page 14: JavaScript Static Analysis with IronWASP

Execution Based

eval()Function()setTimeout()setInterval() execScript() (IE Only)crypto.generateCRMFRequest() (FF Only)

Page 15: JavaScript Static Analysis with IronWASP

Url Based

locationlocation.assign()location.replace()location.hreflocation.protocol*location.search*location.hostname*location.pathname*

*Indirect impact

Page 16: JavaScript Static Analysis with IronWASP

HTML Based

document.write()document.writeln()HTML ElementsHTML Element Attributes

‘src’onclick, onload, onerror etcForm actionhref

Page 17: JavaScript Static Analysis with IronWASP

Others

XHR Callsopen()send()setRequestHeader()

postMessageClient-side StorageJavaScript variables

Page 18: JavaScript Static Analysis with IronWASP

JavaScript Static Analysis using IronWASP

[ONLY DEMOS FROM THIS POINT]

Page 19: JavaScript Static Analysis with IronWASP

DOM XSS Vulnerable Code Example - 1

Page 20: JavaScript Static Analysis with IronWASP

Source Code

<script>var l = location.hash.slice(1);eval(l);

</script>

Page 21: JavaScript Static Analysis with IronWASP

IronWASP Trace

Page 22: JavaScript Static Analysis with IronWASP

DOM XSS Vulnerable Code Example - 2

Page 23: JavaScript Static Analysis with IronWASP

Source Code

<script>var a = "a.b.c.d";arr = a.split(".");var l = location.hash.slice(1);c = "xxx" + arr[1];d = l.indexOf("/");f = l.substring(d);s = eval;Add(c, arr);s(l);

</script>

Page 24: JavaScript Static Analysis with IronWASP

IronWASP Trace

Page 25: JavaScript Static Analysis with IronWASP

DOM XSS Vulnerable Code Example - 3

Page 26: JavaScript Static Analysis with IronWASP

Source Code

<script>function getHash(){

var l = location.hash.slice(1);return l;

}var h = getHash();eval(h);

</script>

Page 27: JavaScript Static Analysis with IronWASP

IronWASP Trace

Page 28: JavaScript Static Analysis with IronWASP

Update Taint Config

• The function ‘getHash’ returns a DOM XSS Source.• Let’s update the ‘Taint Config’ with that:

• Let’s redo the trace now.

Page 29: JavaScript Static Analysis with IronWASP

IronWASP Trace

Page 30: JavaScript Static Analysis with IronWASP

DOM XSS Vulnerable Code Example - 4

Page 31: JavaScript Static Analysis with IronWASP

Source Code

<script>function getLocation(){

var l = location;return l;

}var loc = getLocation();loc = name;

</script>

Page 32: JavaScript Static Analysis with IronWASP

IronWASP Trace

Page 33: JavaScript Static Analysis with IronWASP

Update Taint Config

• The function ‘getLocation’ returns a DOM XSS Sink.• Let’s update the ‘Taint Config’ with that:

• Let’s redo the trace now.

Page 34: JavaScript Static Analysis with IronWASP

IronWASP Trace

Page 35: JavaScript Static Analysis with IronWASP

DOM XSS Vulnerable Code Example - 5

Page 36: JavaScript Static Analysis with IronWASP

Source Code

<script>function doEval(text){

eval(text);}var h = location.hash.slice(1);doEval(h);

</script>

Page 37: JavaScript Static Analysis with IronWASP

IronWASP Trace

Page 38: JavaScript Static Analysis with IronWASP

Update Taint Config

• The function ‘doEval’ assigns its argument to a DOM XSS Sink.

• Let’s update the ‘Taint Config’ with that:

• Let’s redo the trace now.

Page 39: JavaScript Static Analysis with IronWASP

IronWASP Trace

Page 40: JavaScript Static Analysis with IronWASP

DOM XSS Vulnerable Code Example - 6

Page 41: JavaScript Static Analysis with IronWASP

Source Code

<script>function assignName(property){

var n = window.name;property = n;

}var l = location;assignName(l);

</script>

Page 42: JavaScript Static Analysis with IronWASP

IronWASP Trace

Page 43: JavaScript Static Analysis with IronWASP

Update Taint Config

• The function ‘assignName’ assigns a DOM XSS Source to its argument.

• Let’s update the ‘Taint Config’ with that:

• Let’s redo the trace now.

Page 44: JavaScript Static Analysis with IronWASP

IronWASP Trace

Page 45: JavaScript Static Analysis with IronWASP

DOM XSS Vulnerable Code Example - 7

Page 46: JavaScript Static Analysis with IronWASP

Source Code

<script src="sourceret.js"></script>function getHash() {

var l = location.hash.slice(1);

return l;

}

<script src="sinkass.js"></script>function doEval(text) {

eval(text);

}

<script>var h = getHash();doEval(h);

</script>

Page 47: JavaScript Static Analysis with IronWASP

IronWASP Trace

• We did not the analyze the JavaScript that was loaded from the ‘sourceret.js’ and ‘sinkass.js’ files.

• We can get the list of all external scripts referenced for all pages in a site by analyzing the requests and responses captured in the logs.

• This can be done with a simple script

Page 48: JavaScript Static Analysis with IronWASP

The simple Python script:

sessions = Session.FromProxyLog()

for sess in sessions:

if sess.Response != None:

if sess.Response.IsHtml:

script_files = sess.Response.Html.GetValues("script", "src")

print sess.Request.Url

for sf in script_files:

print "\t - " + sf

Page 49: JavaScript Static Analysis with IronWASP

Update Taint Config

• The function ‘getHash’ from ‘sourceret.js’ returns a DOM XSS Source.

• The function ‘doEval’ from ‘sinkass.js’ assigns its argument to a DOM XSS Sink.

• Let’s update the ‘Taint Config’ with that:

• Let’s redo the trace now.

Page 50: JavaScript Static Analysis with IronWASP

IronWASP Trace

Page 51: JavaScript Static Analysis with IronWASP

References

IronWASP http://ironwasp.org

DOM XSS Wiki http://code.google.com/p/domxsswiki