SlideShare a Scribd company logo
25 Million Flows Later – Large-scale
Detection of DOM-based XSS
CCS 2013, Berlin
Sebastian Lekies, Ben Stock, Martin Johns
Agenda
●  XSS & Attacker Scenario
●  WebSec guys: wake up once you see a cat
●  Motivation
●  Our contributions
●  Summary
2
Cross-Site Scripting
●  Execution of attacker-controlled code on the client in the
context of the vulnerable app
●  Three kinds:
●  Persistent XSS: guestbook, ...
●  Reflected XSS: search forms, ...
●  DOM-based XSS: also called local XSS
●  content dynamically added by JS (e.g. like button), ..
3
Server side
Client side
Cross-Site Scripting: attacker model
●  Attacker wants to inject own code into vuln. app
●  steal cookie
●  take abritrary action in the name of the user
●  pretend to be the server towards the user
●  ...
4
Source: http://blogs.sfweekly.com/thesnitch/
cookie_monster.jpg
Cross-Site Scripting: problem statement
●  Main problem: attacker‘s content ends in document and
is not properly filtered/encoded
●  common for server- and client-side flaws
●  Flow of data: from attacker-controllable source to security-
sensitive sink
●  Our Focus: client side JavaScript code
●  Sources: e.g. the URL
●  Sinks: e.g. document.write
5
Example of a DOMXSS vulnerability
●  Source: location.hash, Sink: document.write
●  Intended usage:
●  http://example.org/#mypage
●  <img src='//adve.rt/ise?hash=mypage'/>!
●  Exploiting the vuln:
●  http://example.org/#'/><script>alert(1)</script>
●  <img src='//adve.rt/ise?hash='/>

<script>alert(1)</script>

'/>
6
document.write("<img src='//adve.rt/ise?hash=" + location.hash.slice(1)+ "'/>");!
How does the attacker exploit this?
a.  Send a crafted link to the victim
b.  Embed vulnerable page with payload into his own page
7
h"p://ki"enpics.org	
  
Source: http://www.hd-gbpics.de/gbbilder/katzen/katzen2.jpg
Our motivation and contribution
●  Perform Large-scale analysis of DOMXSS vulnerabilities
●  Automated, dynamic detection of suspicious flows
●  Automated validation of vulnerabilities
●  Our key components
●  Taint-aware browsing engine
●  Crawling infrastructure
●  Context-specific exploit generator
●  Exploit verification using the crawler
8
Building a taint-aware browsing engine to find
suspicious flows
Our approach: use dynamic taint tracking
●  Taint tracking: Track the flow of marked data from source
to sink
●  Implementation: into Chromium (Blink+V8)
●  Requirements for taint tracking
●  Taint all relevent values / propagate taints
●  Report all sinks accesses
●  be as precise as possible
●  taint details on EVERY character
10
Representing sources
●  In terms of DOMXSS, we have 14 sources
●  additionally, three relevant, built-in encoding functions
●  escape, encodeURI and encodeURIComponent
●  .. may prevent XSS vulnerabilites if used properly
●  Goal: store source + bitmask of encoding functions for
each character
11
Representing sources (cntd)
●  14 sources è 4 bits sufficient
●  3 relevant built-in functions è 3 bits sufficient
7 bits < 1 byte
●  è 1 Byte sufficient to store source + encoding functions
●  encoding functions and counterparts set/unset bits
●  hard-coded characters have source 0
12
enconding functions Source
Representing sources (cntd)
●  Each source API (e.g. URL or cookie) attaches taint bytes
●  identifing the source of a char
●  var x = location.hash.slice(1);!
●  x = escape(x);!
13
t	
   e	
   s	
   '	
   1	
   1	
   1	
   1	
  
t	
   e	
   s	
   %	
   65	
   65	
   65	
   65	
  2	
   7	
   65	
   65	
  
0	
   1	
   0	
   0	
   0	
   0	
   0	
   1	
  
Detecting sink access
●  Taint propagated through all relevant functions
●  Security-sensitive sinks report flow and details
●  such as text, taint information, source code location
●  Chrome extension to handle reporting
●  keep core changes as small as possible
●  repack information in JavaScript
●  stub function directly inside V8
14
Extension
V8 JS eval report
WebKit document.write
Empirical study on suspicious flows
Crawling the Web (at University scale)
●  Crawler infrastructure constisting of
●  modified, taint-aware
browsing engine
●  browser extension
to direct the engine
●  Dispatching and
reporting backend
●  In total, we ran
6 machines Control'backend'
Background'script'
Tab'1'
content''
script'
Web'
page'''
&''
user'
script'
Tab'n'
content''
script'
Web'
page'''
&''
user'
script'…'
Background'script'
Tab'1'
content''
script'
Web'
page'''
&''
user'
script'
Tab'n'
content''
script'
Web'
page'''
&''
user'
script'…'…'
Browser'1' Browser'm'
16
Empirical study
●  Shallow crawl of Alexa Top 5000 Web Sites
●  Main page + first level of links
●  504,275 URLs scanned in roughly 5 days
●  on average containing ~8,64 frames
●  total of 4,358,031 analyzed documents
●  Step 1: Flow detection
●  24,474,306 data flows from possibly attacker-controllable input to
security-sensitive sinks
17
Context-Sensitive Generation of Cross-Site Scripting
Payloads
Validating vulnerabilities
●  Current Situation:
●  Taint-tracking engine delivers suspicious flows
●  Suspicious flow != Vulnerability
●  Why may suspicious flows not be exploitable?
●  e.g. custom filter, validation or encoding function
●  Validation needed: working exploit
<script>!
if (/^[a-z][0-9]+$/.test(location.hash.slice(1)) {!
document.write(location.hash.slice(1));!
}!
</script>
19
Anatomy of an XSS Exploit
●  Cross-Site Scripting exploits are context-specific:
●  HTML Context
●  Vulnerability:
●  Exploit:
●  JavaScript Context
●  Vulnerability:
●  Exploit:
eval("var x = '" + location.hash + "';");
'; alert(1); //
document.write("<img src='pic.jpg?hash=" !
!+ location.hash.slice(1) + "'>");
'><script>alert(1)</script><textarea>
20
Anatomy of an XSS Exploit
●  Context-Sensitivity
●  Breakout-Sequence: Highly context sensitive (generation is difficult)
●  Payload: Not context sensitive (arbitrary JavaScript code)
●  Comment Sequence: Very easy to generate (choose from a handful of
options)
Payload Break-in / Comment SequenceBreak-out Sequence
'; alert(1); //
'><script> alert(1); </script><textarea>
21
Breaking out of JavaScript contexts
●  JavaScript Context
●  Visiting http://example.org/ in our engine
<script>!
var code = 'function test(){' !
! + 'var x = "' + location.href + '";'!
! //inside function test!
! + 'doSomething(x);'!
! + '}'; !
//top level !
eval(code);!
</script>
eval('

function test() {!
var x = "http://example.org";!
doSomething(x);!
}

');
22
Syntax tree to working exploit
●  Two options here:
●  break out of string
●  break out of function
definition
●  Latter is more reliable
●  function test not
necessarily called
automatically on
„normal“ execution
23
Tainted	
  value	
  aka	
  
injecAon	
  point	
  
function test() {!
var x = "http://example.org";!
doSomething(x);!
}
Generating a valid exploit
●  Traverse the AST upwards and “end” the branches
●  Breakout Sequence: “;}
●  Comment: //
●  Exploit: ";}alert(1);//
●  Visit: http://example.org/#";}alert(1);//
}
;
“
24
function test() {!
var x = "http://example.org";!
}!
alert(1);//“; doSomething(x); }
Validating vulnerabilities
●  Our focus: directly controllable exploits
●  Sinks: direct execution sinks
●  HTML sinks (document.write, innerHTML ,...)
●  JavaScript sinks (eval, ...)
●  Sources: location and referrer
●  Only unencoded strings
●  Not in the focus (yet): second-order vulnerabilities
●  to cookie and from cookie to eval
●  ...
25
Empirical study
●  Step 2: Flow reduction
●  Only JavaScript and HTML sinks: 24,474,306 è 4,948,264
●  Only directly controllable sources: 4,948,264 è 1,825,598
●  Only unencoded flows: 1,825,598 è 313,794
●  Step 3: Precise exploit generation
●  Generated a total of 181,238 unique test cases
●  rest were duplicates (same URL and payload)
●  basically same vuln twice in same page
26
Empirical study
●  Step 4: Exploit validation
●  69,987 out of 181,238 unique test cases triggered a vulnerability
●  Step 5: Further analysis
●  8,163 unique vulnerabilities affecting 701 domains
●  …of all loaded frames (i.e. also from outside Top 5000)
●  6,167 unique vulnerabilities affecting 480 Alexa top 5000 domains
●  At least, 9.6 % of the top 5000 Web pages contain one or more XSS
problems
●  This number only represents the lower bound (!)
27
Limitations
●  No assured code coverage
●  e.g. debug GET-param needed?
●  also, not all pages visited (esp. stateful applications)
●  Fuzzing might get better results
●  does not scale as well
●  Not yet looking at the „harder“ flows
●  found one URL è Cookie è eval „by accident“
28
Summary
●  We built a tool capable of detecting flows
●  taint-aware Chromium
●  Chrome extension for crawling and reporting
●  We built an automated exploit generator
●  taking into account the exact taint information
●  ... and specific contexts
●  We found that at least 480 of the top 5000 domains carry
a DOM-XSS vuln
29
Thank you very much for your
attention!
Ben Stock
@kcotsneb
ben.stock@fau.de
31
URL	
   Cookie	
   Referrer	
   window.name	
   postMessage	
   WebStorage	
   Total	
  
HTML	
   1,356,796	
   1,535,299	
   240,341	
   35,446	
   35,103	
   16,387	
   3,219,392	
  
JavaScript	
   22,962	
   359,962	
   511	
   617,743	
   448,311	
   279,383	
   1,728,872	
  
URL	
   3,798,228	
   2,556,709	
   313,617	
   83,218	
   18,919	
   28,052	
   6,798,743	
  
Cookie	
   220,300	
   10,227,050	
   25,062	
   1,328,634	
   2,554	
   5,618	
   11,809,218	
  
post	
  Message	
   451,170	
   77,202	
   696	
   45,220	
   11,053	
   117,575	
   702,916	
  
Web	
  Storage	
   41,739	
   65,772	
   1,586	
   434	
   194	
   105,440	
   215,165	
  
Total	
   5,891,195	
   14,821,994	
   581,813	
   2,110,715	
   516,134	
   552,455	
   24,474,306	
  
Encoded	
   64,78%	
   52,81%	
   83,99%	
   57,69%	
   1,57%	
   30,31%	
  
Sinks Sources
Outlook on future work
32
URL	
   Cookie	
   Referrer	
   window.name	
   postMessage	
   WebStorage	
   Total	
  
HTML	
   1,356,796	
   1,535,299	
   240,341	
   35,446	
   35,103	
   16,387	
   3,219,392	
  
JavaScript	
   22,962	
   359,962	
   511	
   617,743	
   448,311	
   279,383	
   1,728,872	
  
URL	
   3,798,228	
   2,556,709	
   313,617	
   83,218	
   18,919	
   28,052	
   6,798,743	
  
Cookie	
   220,300	
   10,227,050	
   25,062	
   1,328,634	
   2,554	
   5,618	
   11,809,218	
  
post	
  Message	
   451,170	
   77,202	
   696	
   45,220	
   11,053	
   117,575	
   702,916	
  
Web	
  Storage	
   41,739	
   65,772	
   1,586	
   434	
   194	
   105,440	
   215,165	
  
Total	
   5,891,195	
   14,821,994	
   581,813	
   2,110,715	
   516,134	
   552,455	
   24,474,306	
  
Encoded	
   64,78%	
   52,81%	
   83,99%	
   57,69%	
   1,57%	
   30,31%	
  
Sinks Sources
Outlook on future work
33
URL	
   Cookie	
   Referrer	
   window.name	
   postMessage	
   WebStorage	
   Total	
  
HTML	
   1,356,796	
   1,535,299	
   240,341	
   35,446	
   35,103	
   16,387	
   3,219,392	
  
JavaScript	
   22,962	
   359,962	
   511	
   617,743	
   448,311	
   279,383	
   1,728,872	
  
URL	
   3,798,228	
   2,556,709	
   313,617	
   83,218	
   18,919	
   28,052	
   6,798,743	
  
Cookie	
   220,300	
   10,227,050	
   25,062	
   1,328,634	
   2,554	
   5,618	
   11,809,218	
  
post	
  Message	
   451,170	
   77,202	
   696	
   45,220	
   11,053	
   117,575	
   702,916	
  
Web	
  Storage	
   41,739	
   65,772	
   1,586	
   434	
   194	
   105,440	
   215,165	
  
Total	
   5,891,195	
   14,821,994	
   581,813	
   2,110,715	
   516,134	
   552,455	
   24,474,306	
  
Encoded	
   64,78%	
   52,81%	
   83,99%	
   57,69%	
   1,57%	
   30,31%	
  
Sinks Sources
Outlook on future work
34
URL	
   Cookie	
   Referrer	
   window.name	
   postMessage	
   WebStorage	
   Total	
  
HTML	
   1,356,796	
   1,535,299	
   240,341	
   35,446	
   35,103	
   16,387	
   3,219,392	
  
JavaScript	
   22,962	
   359,962	
   511	
   617,743	
   448,311	
   279,383	
   1,728,872	
  
URL	
   3,798,228	
   2,556,709	
   313,617	
   83,218	
   18,919	
   28,052	
   6,798,743	
  
Cookie	
   220,300	
   10,227,050	
   25,062	
   1,328,634	
   2,554	
   5,618	
   11,809,218	
  
post	
  Message	
   451,170	
   77,202	
   696	
   45,220	
   11,053	
   117,575	
   702,916	
  
Web	
  Storage	
   41,739	
   65,772	
   1,586	
   434	
   194	
   105,440	
   215,165	
  
Total	
   5,891,195	
   14,821,994	
   581,813	
   2,110,715	
   516,134	
   552,455	
   24,474,306	
  
Encoded	
   64,78%	
   52,81%	
   83,99%	
   57,69%	
   1,57%	
   30,31%	
  
Sinks Sources
Outlook on future work

More Related Content

PDF
Building Advanced XSS Vectors
PDF
Introduction to JWT and How to integrate with Spring Security
PDF
Autenticação com Json Web Token (JWT)
PPT
WebSocket JSON Hackday
PDF
Blockchain Meetup- Introduction to dApps and the steps involved to create a d...
PDF
Biting into the forbidden fruit. Lessons from trusting Javascript crypto.
DOC
Id32
ODP
MQTT and Java - Client and Broker Examples
Building Advanced XSS Vectors
Introduction to JWT and How to integrate with Spring Security
Autenticação com Json Web Token (JWT)
WebSocket JSON Hackday
Blockchain Meetup- Introduction to dApps and the steps involved to create a d...
Biting into the forbidden fruit. Lessons from trusting Javascript crypto.
Id32
MQTT and Java - Client and Broker Examples

What's hot (20)

PPTX
JWTs and JOSE in a flash
PDF
Protecting Users Against XSS-based Password Manager Abuse
PPTX
Orion Context Broker NGSI-v2 Overview for Developers That Already Know Ngsi-v...
PPTX
Orion contextbroker ngs-iv2-overview-for-developers-that-already-know-ngsiv1-...
PPTX
NGSIv2 Overview for Developers That Already Know NGSIv1 20180928
PPTX
NGSIv2 Overview for Developers That Already Know NGSIv1 20181218
PDF
Breaking AngularJS Javascript sandbox
PPTX
ngsiv2-overview-for-developers-that-already-know-ngsiv1-20190214
PPTX
Orion Context Broker NGSIv2 Overview for Developers That Already Know NGSIv1 ...
PPTX
Web security: Securing untrusted web content at browsers
PPTX
Find maximum bugs in limited time
PPTX
Orion Context Broker NGSIv2 Overview for Developers That Already Know NGSIv1 ...
PDF
AREA41 - Anatomy of attacks aimed at financial sector by the Lazarus group
PDF
A XSSmas carol
ODP
Real world blockchains
PDF
New Methods in Automated XSS Detection & Dynamic Exploit Creation
PDF
How does cryptography work? by Jeroen Ooms
PDF
The innerHTML Apocalypse
ODP
Hunting Security Bugs in Modern Web Applications
PDF
Ruxmon feb 2013 what happened to rails
JWTs and JOSE in a flash
Protecting Users Against XSS-based Password Manager Abuse
Orion Context Broker NGSI-v2 Overview for Developers That Already Know Ngsi-v...
Orion contextbroker ngs-iv2-overview-for-developers-that-already-know-ngsiv1-...
NGSIv2 Overview for Developers That Already Know NGSIv1 20180928
NGSIv2 Overview for Developers That Already Know NGSIv1 20181218
Breaking AngularJS Javascript sandbox
ngsiv2-overview-for-developers-that-already-know-ngsiv1-20190214
Orion Context Broker NGSIv2 Overview for Developers That Already Know NGSIv1 ...
Web security: Securing untrusted web content at browsers
Find maximum bugs in limited time
Orion Context Broker NGSIv2 Overview for Developers That Already Know NGSIv1 ...
AREA41 - Anatomy of attacks aimed at financial sector by the Lazarus group
A XSSmas carol
Real world blockchains
New Methods in Automated XSS Detection & Dynamic Exploit Creation
How does cryptography work? by Jeroen Ooms
The innerHTML Apocalypse
Hunting Security Bugs in Modern Web Applications
Ruxmon feb 2013 what happened to rails
Ad

Viewers also liked (20)

PPTX
The health of nigerians doctors
PPT
Matter and change
PDF
ACCT 402 Pinnacle Project
PDF
Jornal Cruzeiro do Sul
PPTX
Taller N10 DIEGO ARLEY GIRALDO
PDF
Electrolux Interim Report Q2 2016 - Report
PPTX
Comprehensive Plan 5-Year Report
PDF
Earnings Results 2Q09
PPTX
263 订味啦商业计划书
PDF
Colombia y ODM
PDF
España revision de la ue
PDF
Deaths in Alzheimers
PDF
中国手机广告市场现状及发展趋势分析专题报告2009
PDF
9vos billetes cr
PDF
Quran in Hindi Part-25
PPTX
Slide vn update q3.2014 website
PDF
clearchannel 34
PDF
安博士Asec 2011年1月安全报告
PDF
4 q13 earnings presentation final
The health of nigerians doctors
Matter and change
ACCT 402 Pinnacle Project
Jornal Cruzeiro do Sul
Taller N10 DIEGO ARLEY GIRALDO
Electrolux Interim Report Q2 2016 - Report
Comprehensive Plan 5-Year Report
Earnings Results 2Q09
263 订味啦商业计划书
Colombia y ODM
España revision de la ue
Deaths in Alzheimers
中国手机广告市场现状及发展趋势分析专题报告2009
9vos billetes cr
Quran in Hindi Part-25
Slide vn update q3.2014 website
clearchannel 34
安博士Asec 2011年1月安全报告
4 q13 earnings presentation final
Ad

Similar to 25 Million Flows Later – Large-scale Detection of DOM-based XSS (20)

PPTX
NullCon 2012 - Ra.2: blackbox DOM-based XSS scanner
PPTX
Understanding dom based xss
PDF
Ch 12 Attacking Users - XSS
PDF
CNIT 129S: Ch 12: Attacking Users: Cross-Site Scripting
PDF
CNIT 129S: Ch 12: Attacking Users: Cross-Site Scripting
PDF
Dom XSS - Encounters of the 3rd Kind (Bishan Singh Kochher)
PPTX
Cross Context Scripting attacks & exploitation
PDF
Introduction to Cross Site Scripting ( XSS )
PPTX
Cross Site Scripting ( XSS)
PDF
xss-100908063522-phpapp02.pdf
PPTX
Dom XSS: Encounters of the3rd kind
PDF
"Подход к написанию безопасного клиентского кода на примере React", Иван Елки...
PPTX
Owasp web application security trends
PPTX
[2.1] Web application Security Trends - Omar Ganiev
PPT
Cross site scripting (xss)
PDF
OWASP SF - Reviewing Modern JavaScript Applications
PDF
Subresource Integrity
PDF
PPTX
Html5 security
PDF
Window Shopping Browser - Bug Hunting in 2012
NullCon 2012 - Ra.2: blackbox DOM-based XSS scanner
Understanding dom based xss
Ch 12 Attacking Users - XSS
CNIT 129S: Ch 12: Attacking Users: Cross-Site Scripting
CNIT 129S: Ch 12: Attacking Users: Cross-Site Scripting
Dom XSS - Encounters of the 3rd Kind (Bishan Singh Kochher)
Cross Context Scripting attacks & exploitation
Introduction to Cross Site Scripting ( XSS )
Cross Site Scripting ( XSS)
xss-100908063522-phpapp02.pdf
Dom XSS: Encounters of the3rd kind
"Подход к написанию безопасного клиентского кода на примере React", Иван Елки...
Owasp web application security trends
[2.1] Web application Security Trends - Omar Ganiev
Cross site scripting (xss)
OWASP SF - Reviewing Modern JavaScript Applications
Subresource Integrity
Html5 security
Window Shopping Browser - Bug Hunting in 2012

Recently uploaded (20)

PPTX
Lecture Notes Electrical Wiring System Components
PPTX
Internet of Things (IOT) - A guide to understanding
PDF
Digital Logic Computer Design lecture notes
PPTX
additive manufacturing of ss316l using mig welding
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PPTX
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PDF
Well-logging-methods_new................
PPTX
OOP with Java - Java Introduction (Basics)
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PPTX
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PDF
PPT on Performance Review to get promotions
PPTX
UNIT 4 Total Quality Management .pptx
Lecture Notes Electrical Wiring System Components
Internet of Things (IOT) - A guide to understanding
Digital Logic Computer Design lecture notes
additive manufacturing of ss316l using mig welding
CYBER-CRIMES AND SECURITY A guide to understanding
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
Operating System & Kernel Study Guide-1 - converted.pdf
Model Code of Practice - Construction Work - 21102022 .pdf
Well-logging-methods_new................
OOP with Java - Java Introduction (Basics)
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
UNIT-1 - COAL BASED THERMAL POWER PLANTS
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PPT on Performance Review to get promotions
UNIT 4 Total Quality Management .pptx

25 Million Flows Later – Large-scale Detection of DOM-based XSS

  • 1. 25 Million Flows Later – Large-scale Detection of DOM-based XSS CCS 2013, Berlin Sebastian Lekies, Ben Stock, Martin Johns
  • 2. Agenda ●  XSS & Attacker Scenario ●  WebSec guys: wake up once you see a cat ●  Motivation ●  Our contributions ●  Summary 2
  • 3. Cross-Site Scripting ●  Execution of attacker-controlled code on the client in the context of the vulnerable app ●  Three kinds: ●  Persistent XSS: guestbook, ... ●  Reflected XSS: search forms, ... ●  DOM-based XSS: also called local XSS ●  content dynamically added by JS (e.g. like button), .. 3 Server side Client side
  • 4. Cross-Site Scripting: attacker model ●  Attacker wants to inject own code into vuln. app ●  steal cookie ●  take abritrary action in the name of the user ●  pretend to be the server towards the user ●  ... 4 Source: http://blogs.sfweekly.com/thesnitch/ cookie_monster.jpg
  • 5. Cross-Site Scripting: problem statement ●  Main problem: attacker‘s content ends in document and is not properly filtered/encoded ●  common for server- and client-side flaws ●  Flow of data: from attacker-controllable source to security- sensitive sink ●  Our Focus: client side JavaScript code ●  Sources: e.g. the URL ●  Sinks: e.g. document.write 5
  • 6. Example of a DOMXSS vulnerability ●  Source: location.hash, Sink: document.write ●  Intended usage: ●  http://example.org/#mypage ●  <img src='//adve.rt/ise?hash=mypage'/>! ●  Exploiting the vuln: ●  http://example.org/#'/><script>alert(1)</script> ●  <img src='//adve.rt/ise?hash='/>
 <script>alert(1)</script>
 '/> 6 document.write("<img src='//adve.rt/ise?hash=" + location.hash.slice(1)+ "'/>");!
  • 7. How does the attacker exploit this? a.  Send a crafted link to the victim b.  Embed vulnerable page with payload into his own page 7 h"p://ki"enpics.org   Source: http://www.hd-gbpics.de/gbbilder/katzen/katzen2.jpg
  • 8. Our motivation and contribution ●  Perform Large-scale analysis of DOMXSS vulnerabilities ●  Automated, dynamic detection of suspicious flows ●  Automated validation of vulnerabilities ●  Our key components ●  Taint-aware browsing engine ●  Crawling infrastructure ●  Context-specific exploit generator ●  Exploit verification using the crawler 8
  • 9. Building a taint-aware browsing engine to find suspicious flows
  • 10. Our approach: use dynamic taint tracking ●  Taint tracking: Track the flow of marked data from source to sink ●  Implementation: into Chromium (Blink+V8) ●  Requirements for taint tracking ●  Taint all relevent values / propagate taints ●  Report all sinks accesses ●  be as precise as possible ●  taint details on EVERY character 10
  • 11. Representing sources ●  In terms of DOMXSS, we have 14 sources ●  additionally, three relevant, built-in encoding functions ●  escape, encodeURI and encodeURIComponent ●  .. may prevent XSS vulnerabilites if used properly ●  Goal: store source + bitmask of encoding functions for each character 11
  • 12. Representing sources (cntd) ●  14 sources è 4 bits sufficient ●  3 relevant built-in functions è 3 bits sufficient 7 bits < 1 byte ●  è 1 Byte sufficient to store source + encoding functions ●  encoding functions and counterparts set/unset bits ●  hard-coded characters have source 0 12 enconding functions Source
  • 13. Representing sources (cntd) ●  Each source API (e.g. URL or cookie) attaches taint bytes ●  identifing the source of a char ●  var x = location.hash.slice(1);! ●  x = escape(x);! 13 t   e   s   '   1   1   1   1   t   e   s   %   65   65   65   65  2   7   65   65   0   1   0   0   0   0   0   1  
  • 14. Detecting sink access ●  Taint propagated through all relevant functions ●  Security-sensitive sinks report flow and details ●  such as text, taint information, source code location ●  Chrome extension to handle reporting ●  keep core changes as small as possible ●  repack information in JavaScript ●  stub function directly inside V8 14 Extension V8 JS eval report WebKit document.write
  • 15. Empirical study on suspicious flows
  • 16. Crawling the Web (at University scale) ●  Crawler infrastructure constisting of ●  modified, taint-aware browsing engine ●  browser extension to direct the engine ●  Dispatching and reporting backend ●  In total, we ran 6 machines Control'backend' Background'script' Tab'1' content'' script' Web' page''' &'' user' script' Tab'n' content'' script' Web' page''' &'' user' script'…' Background'script' Tab'1' content'' script' Web' page''' &'' user' script' Tab'n' content'' script' Web' page''' &'' user' script'…'…' Browser'1' Browser'm' 16
  • 17. Empirical study ●  Shallow crawl of Alexa Top 5000 Web Sites ●  Main page + first level of links ●  504,275 URLs scanned in roughly 5 days ●  on average containing ~8,64 frames ●  total of 4,358,031 analyzed documents ●  Step 1: Flow detection ●  24,474,306 data flows from possibly attacker-controllable input to security-sensitive sinks 17
  • 18. Context-Sensitive Generation of Cross-Site Scripting Payloads
  • 19. Validating vulnerabilities ●  Current Situation: ●  Taint-tracking engine delivers suspicious flows ●  Suspicious flow != Vulnerability ●  Why may suspicious flows not be exploitable? ●  e.g. custom filter, validation or encoding function ●  Validation needed: working exploit <script>! if (/^[a-z][0-9]+$/.test(location.hash.slice(1)) {! document.write(location.hash.slice(1));! }! </script> 19
  • 20. Anatomy of an XSS Exploit ●  Cross-Site Scripting exploits are context-specific: ●  HTML Context ●  Vulnerability: ●  Exploit: ●  JavaScript Context ●  Vulnerability: ●  Exploit: eval("var x = '" + location.hash + "';"); '; alert(1); // document.write("<img src='pic.jpg?hash=" ! !+ location.hash.slice(1) + "'>"); '><script>alert(1)</script><textarea> 20
  • 21. Anatomy of an XSS Exploit ●  Context-Sensitivity ●  Breakout-Sequence: Highly context sensitive (generation is difficult) ●  Payload: Not context sensitive (arbitrary JavaScript code) ●  Comment Sequence: Very easy to generate (choose from a handful of options) Payload Break-in / Comment SequenceBreak-out Sequence '; alert(1); // '><script> alert(1); </script><textarea> 21
  • 22. Breaking out of JavaScript contexts ●  JavaScript Context ●  Visiting http://example.org/ in our engine <script>! var code = 'function test(){' ! ! + 'var x = "' + location.href + '";'! ! //inside function test! ! + 'doSomething(x);'! ! + '}'; ! //top level ! eval(code);! </script> eval('
 function test() {! var x = "http://example.org";! doSomething(x);! }
 '); 22
  • 23. Syntax tree to working exploit ●  Two options here: ●  break out of string ●  break out of function definition ●  Latter is more reliable ●  function test not necessarily called automatically on „normal“ execution 23 Tainted  value  aka   injecAon  point   function test() {! var x = "http://example.org";! doSomething(x);! }
  • 24. Generating a valid exploit ●  Traverse the AST upwards and “end” the branches ●  Breakout Sequence: “;} ●  Comment: // ●  Exploit: ";}alert(1);// ●  Visit: http://example.org/#";}alert(1);// } ; “ 24 function test() {! var x = "http://example.org";! }! alert(1);//“; doSomething(x); }
  • 25. Validating vulnerabilities ●  Our focus: directly controllable exploits ●  Sinks: direct execution sinks ●  HTML sinks (document.write, innerHTML ,...) ●  JavaScript sinks (eval, ...) ●  Sources: location and referrer ●  Only unencoded strings ●  Not in the focus (yet): second-order vulnerabilities ●  to cookie and from cookie to eval ●  ... 25
  • 26. Empirical study ●  Step 2: Flow reduction ●  Only JavaScript and HTML sinks: 24,474,306 è 4,948,264 ●  Only directly controllable sources: 4,948,264 è 1,825,598 ●  Only unencoded flows: 1,825,598 è 313,794 ●  Step 3: Precise exploit generation ●  Generated a total of 181,238 unique test cases ●  rest were duplicates (same URL and payload) ●  basically same vuln twice in same page 26
  • 27. Empirical study ●  Step 4: Exploit validation ●  69,987 out of 181,238 unique test cases triggered a vulnerability ●  Step 5: Further analysis ●  8,163 unique vulnerabilities affecting 701 domains ●  …of all loaded frames (i.e. also from outside Top 5000) ●  6,167 unique vulnerabilities affecting 480 Alexa top 5000 domains ●  At least, 9.6 % of the top 5000 Web pages contain one or more XSS problems ●  This number only represents the lower bound (!) 27
  • 28. Limitations ●  No assured code coverage ●  e.g. debug GET-param needed? ●  also, not all pages visited (esp. stateful applications) ●  Fuzzing might get better results ●  does not scale as well ●  Not yet looking at the „harder“ flows ●  found one URL è Cookie è eval „by accident“ 28
  • 29. Summary ●  We built a tool capable of detecting flows ●  taint-aware Chromium ●  Chrome extension for crawling and reporting ●  We built an automated exploit generator ●  taking into account the exact taint information ●  ... and specific contexts ●  We found that at least 480 of the top 5000 domains carry a DOM-XSS vuln 29
  • 30. Thank you very much for your attention! Ben Stock @kcotsneb ben.stock@fau.de
  • 31. 31 URL   Cookie   Referrer   window.name   postMessage   WebStorage   Total   HTML   1,356,796   1,535,299   240,341   35,446   35,103   16,387   3,219,392   JavaScript   22,962   359,962   511   617,743   448,311   279,383   1,728,872   URL   3,798,228   2,556,709   313,617   83,218   18,919   28,052   6,798,743   Cookie   220,300   10,227,050   25,062   1,328,634   2,554   5,618   11,809,218   post  Message   451,170   77,202   696   45,220   11,053   117,575   702,916   Web  Storage   41,739   65,772   1,586   434   194   105,440   215,165   Total   5,891,195   14,821,994   581,813   2,110,715   516,134   552,455   24,474,306   Encoded   64,78%   52,81%   83,99%   57,69%   1,57%   30,31%   Sinks Sources Outlook on future work
  • 32. 32 URL   Cookie   Referrer   window.name   postMessage   WebStorage   Total   HTML   1,356,796   1,535,299   240,341   35,446   35,103   16,387   3,219,392   JavaScript   22,962   359,962   511   617,743   448,311   279,383   1,728,872   URL   3,798,228   2,556,709   313,617   83,218   18,919   28,052   6,798,743   Cookie   220,300   10,227,050   25,062   1,328,634   2,554   5,618   11,809,218   post  Message   451,170   77,202   696   45,220   11,053   117,575   702,916   Web  Storage   41,739   65,772   1,586   434   194   105,440   215,165   Total   5,891,195   14,821,994   581,813   2,110,715   516,134   552,455   24,474,306   Encoded   64,78%   52,81%   83,99%   57,69%   1,57%   30,31%   Sinks Sources Outlook on future work
  • 33. 33 URL   Cookie   Referrer   window.name   postMessage   WebStorage   Total   HTML   1,356,796   1,535,299   240,341   35,446   35,103   16,387   3,219,392   JavaScript   22,962   359,962   511   617,743   448,311   279,383   1,728,872   URL   3,798,228   2,556,709   313,617   83,218   18,919   28,052   6,798,743   Cookie   220,300   10,227,050   25,062   1,328,634   2,554   5,618   11,809,218   post  Message   451,170   77,202   696   45,220   11,053   117,575   702,916   Web  Storage   41,739   65,772   1,586   434   194   105,440   215,165   Total   5,891,195   14,821,994   581,813   2,110,715   516,134   552,455   24,474,306   Encoded   64,78%   52,81%   83,99%   57,69%   1,57%   30,31%   Sinks Sources Outlook on future work
  • 34. 34 URL   Cookie   Referrer   window.name   postMessage   WebStorage   Total   HTML   1,356,796   1,535,299   240,341   35,446   35,103   16,387   3,219,392   JavaScript   22,962   359,962   511   617,743   448,311   279,383   1,728,872   URL   3,798,228   2,556,709   313,617   83,218   18,919   28,052   6,798,743   Cookie   220,300   10,227,050   25,062   1,328,634   2,554   5,618   11,809,218   post  Message   451,170   77,202   696   45,220   11,053   117,575   702,916   Web  Storage   41,739   65,772   1,586   434   194   105,440   215,165   Total   5,891,195   14,821,994   581,813   2,110,715   516,134   552,455   24,474,306   Encoded   64,78%   52,81%   83,99%   57,69%   1,57%   30,31%   Sinks Sources Outlook on future work