SlideShare a Scribd company logo
At Your Service
Abusing the Service Workers Web API
~$ whoami
● Daniel Abeles
○ Sr. Web Security Researcher @Akamai
○ Pythonista
○ ❤️ Breakings things
○ @Daniel_Abeles
● Shay Shavit
○ Sr. Web Security Researcher @Akamai
○ Bounty Hunter (MVP @bugcrowd)
○ @Chapakpuk
How did we get here?
Agenda
Current State of the Browser
Web Workers API
● “Web Workers are a simple means for web content to run scripts in
background threads.” (from MDN)
● Most of the standard features are available
○ No direct DOM manipulation
○ Must be same origin
Service Workers 101
What Are Service Workers?
Primary Uses of
Service Workers
• Handle Network
Requests
• Caching Agent
• Store content for Offline
Experience
Browsers Support
Lifecycle
Registration
The Scope
● Crucial concept of Service Workers.
● Determines from which path the Service Worker (SW) will be activated
● Defines the activation condition for the service worker.
The Scope
● By default - it is the path where the service worker JavaScript file
resides.
● Can be easily reduced (/profile/ instead of /)
● Can be increased (requires the response header - Service-Worker-
Allowed)
Failed Success
Scope Gotcha’s #1
● If there are 2 registered service workers under the same scope, the most
recently registered one will be activated.
● If there are 2 registered service workers on overlapping scope, the
innermost will be activated.
○ / vs /uploads when visiting /uploads/files
Scope Gotcha’s #2
● A service worker can load other scripts using the importScripts function
○ This is how we can load our malicious SW while maintaining the original SW
functional
● Has to be installed on same origin
Installation
● Once the browsers registers a SW, the install event occurs.
● Also occurs when SW is new / changed.
Activation
● Once the installation was successful, the “activate” event occurs.
● Opened pages are not controlled by the SW (must be reloaded).
○ Can be overridden by using the self.clients.claim function
Fetch
● Fires every time a resource is requested
● Control over what is being sent / received.
○ Headers
○ Status
○ Body
Where to find them?
● Developer tools
● chrome://serviceworker-internals
Abuse Scenarios
Response Modification
General Scenario Requirements
All of the following scenarios depend on the following:
● The website has a file upload functionality.
○ We can upload arbitrary JavaScript files there (and retrieve them).
● There’s an XSS vulnerability in the app
○ We can inject JavaScript code in the context of the victims browser.
All of the scenarios abuse the fact that we can attach to the fetch event (of
the service worker) to manipulate requested resources.
• Upload the malicious
service worker to the
website
Upload
• Using our XSS we
register the malicious
service worker
Trigger • Attach to the fetch
event.
• We can modify the
response of
requested resources.
PWN
Response Modification
Response
Modifications
Persistent
XSS
Phishing /
Defacement DoS
Response Modification
• Upload the
malicious service
worker to the
website
Upload
• Using our XSS we
register the
malicious service
worker
Trigger
• Reinject our
code
• Expand our
scope
PWN
XSS Persistency
Response Modification
• Upload the
malicious service
worker to the
website
Upload
• Using our XSS we
register the
malicious service
worker
Trigger
• Deny every
requested
resource
PWN
Denial of Service
Response Modification
• Upload the
malicious service
worker to the
website
Upload
• Using our XSS we
register the
malicious service
worker
Trigger
• Serve
alternate
content.
PWN
Phishing / Defacement
Response Modification
Data Leakage from
Sandboxed Domains
What Are Sandbox Domains?
● Generally host various types of files
● Ment to isolate user uploaded content from the main application
● Are different than the main application domain
● Files on the sandboxed domain are usually publicly available
What Are Sandbox Domains?
● The file names are heavily obfuscated / random (does not resemble the
file content or owner)
○ /super-random-and-unique-path-1337
● Many vendors tend to ignore XSS findings in those domains since no
cookies are shared among the sandboxed domain and the main
application domain, like
● google.com vs googleusercontent.com
● facebook.com vs fbcdn.com
● etc.
Data Leakage from Sandboxed Domains
Consider the following scenario:
● There's a website called “bsides-photos.com” which handles sensitive
information
● The uploaded sensitive data is stored in a sandboxed domain called
“bsides-photos-sbx.com”
● There is an XSS in the sandboxed domain (boring, right?)
Data Leakage from Sandboxed Domains
bsides-photos-sbx.combsides-photos.com
Data Leakage from Sandboxed Domains
bsides-photos-sbx.com
Data Leakage from Sandboxed Domains
bsides-photos-sbx.com
XSS
Victim
Data Leakage from Sandboxed Domains
bsides-photos.com bsides-photos-sbx.com C2 Server
DEMO
Upload Trigger Activate Leak
Data Leakage from Sandboxed Domains
Enhancing Self-XSS
Enhancing Self XSS
In this scenario we have:
● File upload functionality.
● A self XSS finding (low impact) on the /profile page.
○ A XSS that is triggered only on pages that are visible to us.
● Login / logout CSRF
○ Login and logout functions are not protected by CSRF tokens.
○ An attacker can force login/logout the victim.
Enhancing Self XSS
example.com
Enhancing Self XSS
evil-domain.com
example.com/logoutexample.com/login
(as attacker)
example.com/profile
XSS
Enhancing Self XSS
Victim
DEMO
Enhancing Self XSS
Enhancing Self XSS
Setup Visit Logout/Login Register PWN
Caveats
Although this scenario looks promising, we are bounded under the following
restrictions:
● Service Worker scope - if the uploaded service worker resides deeper in
the page tree than the page we want to inspect, we won’t have effect on
it.
○ Since the service worker won’t be activated there.
● Mime Type - the uploaded file must be served with the correct mime
type for JavaScript files “application/javascript”
Mitigations
Scope Enforcement
● Set the uploaded files depth deeper in the tree.
● In sandboxed domain - pick unique path hierarchy for every file
○ Timestamp / random-string dependent
● Refrain from using “/” as the scope (Service-Worker-Allowed response
header)
○ Which allows global activation of the service worker
● Monitor requests with “Service-Worker” header (appended on register).
Mitigations
RUM (Real User Monitoring)
● RUM (real user monitoring) is a passive monitoring technique that
records all the user interaction with the web application.
● It can be used to measure your clients web experience.
● When we observe a very poor performance on a specific client, one of
the reasons could be DOS via Service Worker.
Mitigations
Browser Events Monitoring
● Monitor the navigator.serviceWorker.register function for new
unauthorized register events.
Mitigations
Past Work on SW
Prior Research
● Shadow Workers - https://github.com/shadow-workers/shadow-workers
● Marionet Attackd - https://love2dev.com/pwa/marionet-attack/
Guides
● Service Worker 101 -
https://developers.google.com/web/fundamentals/primers/service-workers/
● FAQ - https://dev.chromium.org/Home/chromium-security/security-faq/service-
worker-security-faq
Vulnerabilities
● %2f Vuln - https://alf.nu/ServiceWorker
● CSRF - https://ahussam.me/Amazon-leaking-csrf-token-using-service-worker/
Key
Takeaways
Service workers can be
useful for web application
They can also cause
mayhem
Sandboxed domains could
be not that sandboxed
Thanks!
Questions?

More Related Content

What's hot

Php & web server performace
Php & web server performacePhp & web server performace
Php & web server performaceTuyển Đoàn
 
Performance Metrics in a Day with Selenium
Performance Metrics in a Day with SeleniumPerformance Metrics in a Day with Selenium
Performance Metrics in a Day with Selenium
Mark Watson
 
Automated Web App Performance Testing Using WebDriver
Automated Web App Performance Testing Using WebDriverAutomated Web App Performance Testing Using WebDriver
Automated Web App Performance Testing Using WebDriverseleniumconf
 
Beginning MEAN Stack
Beginning MEAN StackBeginning MEAN Stack
Beginning MEAN StackRob Davarnia
 
Writing HTTP Middleware In Go
Writing HTTP Middleware In GoWriting HTTP Middleware In Go
Writing HTTP Middleware In Go
Shiju Varghese
 
Performance Testing w/ WebPage Test Private Instance (DrupalCamp Ohio)
Performance Testing w/ WebPage Test Private Instance (DrupalCamp Ohio)Performance Testing w/ WebPage Test Private Instance (DrupalCamp Ohio)
Performance Testing w/ WebPage Test Private Instance (DrupalCamp Ohio)
Bill Condo
 
Advanced cache invalidation
Advanced cache invalidationAdvanced cache invalidation
Advanced cache invalidation
Per Buer
 
ClubAJAX Basics - Server Communication
ClubAJAX Basics - Server CommunicationClubAJAX Basics - Server Communication
ClubAJAX Basics - Server Communication
Mike Wilcox
 
MEAN Stack - Introduction & Advantages - Why should you switch to MEAN stack ...
MEAN Stack - Introduction & Advantages - Why should you switch to MEAN stack ...MEAN Stack - Introduction & Advantages - Why should you switch to MEAN stack ...
MEAN Stack - Introduction & Advantages - Why should you switch to MEAN stack ...
Hariharan Ganesan
 
Angularjs & REST
Angularjs & RESTAngularjs & REST
Angularjs & REST
Corley S.r.l.
 
Automated Testing with Google Chrome - WebDriver- ChromeDriver
Automated Testing with Google Chrome - WebDriver- ChromeDriverAutomated Testing with Google Chrome - WebDriver- ChromeDriver
Automated Testing with Google Chrome - WebDriver- ChromeDriver
Manoj Kumar Kumar
 
MongoDB and the MEAN Stack
MongoDB and the MEAN StackMongoDB and the MEAN Stack
MongoDB and the MEAN StackMongoDB
 
Preparing your web services for Android and your Android app for web services...
Preparing your web services for Android and your Android app for web services...Preparing your web services for Android and your Android app for web services...
Preparing your web services for Android and your Android app for web services...
Droidcon Eastern Europe
 
Node js crash course session 2
Node js crash course   session 2Node js crash course   session 2
Node js crash course session 2
Abdul Rahman Masri Attal
 
Evolution of java script libraries
Evolution of java script librariesEvolution of java script libraries
Evolution of java script libraries
Columbia Developers Guild
 
Designing REST services with Spring MVC
Designing REST services with Spring MVCDesigning REST services with Spring MVC
Designing REST services with Spring MVC
Serhii Kartashov
 
AJAX for Scalability
AJAX for ScalabilityAJAX for Scalability
AJAX for ScalabilityTuenti
 

What's hot (19)

Php & web server performace
Php & web server performacePhp & web server performace
Php & web server performace
 
Performance Metrics in a Day with Selenium
Performance Metrics in a Day with SeleniumPerformance Metrics in a Day with Selenium
Performance Metrics in a Day with Selenium
 
Automated Web App Performance Testing Using WebDriver
Automated Web App Performance Testing Using WebDriverAutomated Web App Performance Testing Using WebDriver
Automated Web App Performance Testing Using WebDriver
 
Ajax
AjaxAjax
Ajax
 
Beginning MEAN Stack
Beginning MEAN StackBeginning MEAN Stack
Beginning MEAN Stack
 
Writing HTTP Middleware In Go
Writing HTTP Middleware In GoWriting HTTP Middleware In Go
Writing HTTP Middleware In Go
 
Performance Testing w/ WebPage Test Private Instance (DrupalCamp Ohio)
Performance Testing w/ WebPage Test Private Instance (DrupalCamp Ohio)Performance Testing w/ WebPage Test Private Instance (DrupalCamp Ohio)
Performance Testing w/ WebPage Test Private Instance (DrupalCamp Ohio)
 
Advanced cache invalidation
Advanced cache invalidationAdvanced cache invalidation
Advanced cache invalidation
 
T5 Oli Aro
T5 Oli AroT5 Oli Aro
T5 Oli Aro
 
ClubAJAX Basics - Server Communication
ClubAJAX Basics - Server CommunicationClubAJAX Basics - Server Communication
ClubAJAX Basics - Server Communication
 
MEAN Stack - Introduction & Advantages - Why should you switch to MEAN stack ...
MEAN Stack - Introduction & Advantages - Why should you switch to MEAN stack ...MEAN Stack - Introduction & Advantages - Why should you switch to MEAN stack ...
MEAN Stack - Introduction & Advantages - Why should you switch to MEAN stack ...
 
Angularjs & REST
Angularjs & RESTAngularjs & REST
Angularjs & REST
 
Automated Testing with Google Chrome - WebDriver- ChromeDriver
Automated Testing with Google Chrome - WebDriver- ChromeDriverAutomated Testing with Google Chrome - WebDriver- ChromeDriver
Automated Testing with Google Chrome - WebDriver- ChromeDriver
 
MongoDB and the MEAN Stack
MongoDB and the MEAN StackMongoDB and the MEAN Stack
MongoDB and the MEAN Stack
 
Preparing your web services for Android and your Android app for web services...
Preparing your web services for Android and your Android app for web services...Preparing your web services for Android and your Android app for web services...
Preparing your web services for Android and your Android app for web services...
 
Node js crash course session 2
Node js crash course   session 2Node js crash course   session 2
Node js crash course session 2
 
Evolution of java script libraries
Evolution of java script librariesEvolution of java script libraries
Evolution of java script libraries
 
Designing REST services with Spring MVC
Designing REST services with Spring MVCDesigning REST services with Spring MVC
Designing REST services with Spring MVC
 
AJAX for Scalability
AJAX for ScalabilityAJAX for Scalability
AJAX for Scalability
 

Similar to At Your Service - Abusing the Service Workers Web API

JSFest 2019: Technology agnostic microservices at SPA frontend
JSFest 2019: Technology agnostic microservices at SPA frontendJSFest 2019: Technology agnostic microservices at SPA frontend
JSFest 2019: Technology agnostic microservices at SPA frontend
Vlad Fedosov
 
Web performance optimization - MercadoLibre
Web performance optimization - MercadoLibreWeb performance optimization - MercadoLibre
Web performance optimization - MercadoLibre
Pablo Moretti
 
Introduction to Web Application Security - Blackhoodie US 2018
Introduction to Web Application Security - Blackhoodie US 2018Introduction to Web Application Security - Blackhoodie US 2018
Introduction to Web Application Security - Blackhoodie US 2018
Niranjanaa Ragupathy
 
JS Fest 2019/Autumn. Влад Федосов. Technology agnostic microservices at SPA f...
JS Fest 2019/Autumn. Влад Федосов. Technology agnostic microservices at SPA f...JS Fest 2019/Autumn. Влад Федосов. Technology agnostic microservices at SPA f...
JS Fest 2019/Autumn. Влад Федосов. Technology agnostic microservices at SPA f...
JSFestUA
 
GDG Ibadan #pwa
GDG Ibadan #pwaGDG Ibadan #pwa
GDG Ibadan #pwa
Gbolahan Alli
 
Crikeycon 2019 Velociraptor Workshop
Crikeycon 2019 Velociraptor WorkshopCrikeycon 2019 Velociraptor Workshop
Crikeycon 2019 Velociraptor Workshop
Velocidex Enterprises
 
Security Best Practices for Bot Builders
Security Best Practices for Bot BuildersSecurity Best Practices for Bot Builders
Security Best Practices for Bot Builders
Max Feldman
 
Web performance mercadolibre - ECI 2013
Web performance   mercadolibre - ECI 2013Web performance   mercadolibre - ECI 2013
Web performance mercadolibre - ECI 2013
Santiago Aimetta
 
Progressive Web Apps
Progressive Web AppsProgressive Web Apps
Progressive Web Apps
Gbolahan Alli
 
Progressive Web Apps
Progressive Web AppsProgressive Web Apps
Progressive Web Apps
Unfold UI
 
Secure Developer Access at Decisiv
Secure Developer Access at DecisivSecure Developer Access at Decisiv
Secure Developer Access at Decisiv
Teleport
 
Content Security Policy - Lessons learned at Yahoo
Content Security Policy - Lessons learned at YahooContent Security Policy - Lessons learned at Yahoo
Content Security Policy - Lessons learned at Yahoo
Binu Ramakrishnan
 
Hacking Vulnerable Websites to Bypass Firewalls
Hacking Vulnerable Websites to Bypass FirewallsHacking Vulnerable Websites to Bypass Firewalls
Hacking Vulnerable Websites to Bypass Firewalls
Netsparker
 
PyGrunn2013 High Performance Web Applications with TurboGears
PyGrunn2013  High Performance Web Applications with TurboGearsPyGrunn2013  High Performance Web Applications with TurboGears
PyGrunn2013 High Performance Web Applications with TurboGears
Alessandro Molina
 
ServiceWorker: New game changer is coming!
ServiceWorker: New game changer is coming!ServiceWorker: New game changer is coming!
ServiceWorker: New game changer is coming!
Chang W. Doh
 
Ever Present Persistence - Established Footholds Seen in the Wild
Ever Present Persistence - Established Footholds Seen in the WildEver Present Persistence - Established Footholds Seen in the Wild
Ever Present Persistence - Established Footholds Seen in the Wild
CTruncer
 
Salesforce Performance hacks - Client Side
Salesforce Performance hacks - Client SideSalesforce Performance hacks - Client Side
Salesforce Performance hacks - Client Side
Paris Salesforce Developer Group
 
Security .NET.pdf
Security .NET.pdfSecurity .NET.pdf
Security .NET.pdf
Abhi Jain
 
Word press optimizations
Word press optimizations Word press optimizations
Word press optimizations
Shawn DeWolfe
 
Understanding Page Load / Ziling Zhao (Google)
Understanding Page Load / Ziling Zhao (Google)Understanding Page Load / Ziling Zhao (Google)
Understanding Page Load / Ziling Zhao (Google)
Ontico
 

Similar to At Your Service - Abusing the Service Workers Web API (20)

JSFest 2019: Technology agnostic microservices at SPA frontend
JSFest 2019: Technology agnostic microservices at SPA frontendJSFest 2019: Technology agnostic microservices at SPA frontend
JSFest 2019: Technology agnostic microservices at SPA frontend
 
Web performance optimization - MercadoLibre
Web performance optimization - MercadoLibreWeb performance optimization - MercadoLibre
Web performance optimization - MercadoLibre
 
Introduction to Web Application Security - Blackhoodie US 2018
Introduction to Web Application Security - Blackhoodie US 2018Introduction to Web Application Security - Blackhoodie US 2018
Introduction to Web Application Security - Blackhoodie US 2018
 
JS Fest 2019/Autumn. Влад Федосов. Technology agnostic microservices at SPA f...
JS Fest 2019/Autumn. Влад Федосов. Technology agnostic microservices at SPA f...JS Fest 2019/Autumn. Влад Федосов. Technology agnostic microservices at SPA f...
JS Fest 2019/Autumn. Влад Федосов. Technology agnostic microservices at SPA f...
 
GDG Ibadan #pwa
GDG Ibadan #pwaGDG Ibadan #pwa
GDG Ibadan #pwa
 
Crikeycon 2019 Velociraptor Workshop
Crikeycon 2019 Velociraptor WorkshopCrikeycon 2019 Velociraptor Workshop
Crikeycon 2019 Velociraptor Workshop
 
Security Best Practices for Bot Builders
Security Best Practices for Bot BuildersSecurity Best Practices for Bot Builders
Security Best Practices for Bot Builders
 
Web performance mercadolibre - ECI 2013
Web performance   mercadolibre - ECI 2013Web performance   mercadolibre - ECI 2013
Web performance mercadolibre - ECI 2013
 
Progressive Web Apps
Progressive Web AppsProgressive Web Apps
Progressive Web Apps
 
Progressive Web Apps
Progressive Web AppsProgressive Web Apps
Progressive Web Apps
 
Secure Developer Access at Decisiv
Secure Developer Access at DecisivSecure Developer Access at Decisiv
Secure Developer Access at Decisiv
 
Content Security Policy - Lessons learned at Yahoo
Content Security Policy - Lessons learned at YahooContent Security Policy - Lessons learned at Yahoo
Content Security Policy - Lessons learned at Yahoo
 
Hacking Vulnerable Websites to Bypass Firewalls
Hacking Vulnerable Websites to Bypass FirewallsHacking Vulnerable Websites to Bypass Firewalls
Hacking Vulnerable Websites to Bypass Firewalls
 
PyGrunn2013 High Performance Web Applications with TurboGears
PyGrunn2013  High Performance Web Applications with TurboGearsPyGrunn2013  High Performance Web Applications with TurboGears
PyGrunn2013 High Performance Web Applications with TurboGears
 
ServiceWorker: New game changer is coming!
ServiceWorker: New game changer is coming!ServiceWorker: New game changer is coming!
ServiceWorker: New game changer is coming!
 
Ever Present Persistence - Established Footholds Seen in the Wild
Ever Present Persistence - Established Footholds Seen in the WildEver Present Persistence - Established Footholds Seen in the Wild
Ever Present Persistence - Established Footholds Seen in the Wild
 
Salesforce Performance hacks - Client Side
Salesforce Performance hacks - Client SideSalesforce Performance hacks - Client Side
Salesforce Performance hacks - Client Side
 
Security .NET.pdf
Security .NET.pdfSecurity .NET.pdf
Security .NET.pdf
 
Word press optimizations
Word press optimizations Word press optimizations
Word press optimizations
 
Understanding Page Load / Ziling Zhao (Google)
Understanding Page Load / Ziling Zhao (Google)Understanding Page Load / Ziling Zhao (Google)
Understanding Page Load / Ziling Zhao (Google)
 

Recently uploaded

The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 

Recently uploaded (20)

The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 

At Your Service - Abusing the Service Workers Web API

  • 1. At Your Service Abusing the Service Workers Web API
  • 2. ~$ whoami ● Daniel Abeles ○ Sr. Web Security Researcher @Akamai ○ Pythonista ○ ❤️ Breakings things ○ @Daniel_Abeles ● Shay Shavit ○ Sr. Web Security Researcher @Akamai ○ Bounty Hunter (MVP @bugcrowd) ○ @Chapakpuk
  • 3. How did we get here?
  • 5. Current State of the Browser
  • 6. Web Workers API ● “Web Workers are a simple means for web content to run scripts in background threads.” (from MDN) ● Most of the standard features are available ○ No direct DOM manipulation ○ Must be same origin
  • 8. What Are Service Workers?
  • 9. Primary Uses of Service Workers • Handle Network Requests • Caching Agent • Store content for Offline Experience
  • 13. The Scope ● Crucial concept of Service Workers. ● Determines from which path the Service Worker (SW) will be activated ● Defines the activation condition for the service worker.
  • 14. The Scope ● By default - it is the path where the service worker JavaScript file resides. ● Can be easily reduced (/profile/ instead of /) ● Can be increased (requires the response header - Service-Worker- Allowed) Failed Success
  • 15. Scope Gotcha’s #1 ● If there are 2 registered service workers under the same scope, the most recently registered one will be activated. ● If there are 2 registered service workers on overlapping scope, the innermost will be activated. ○ / vs /uploads when visiting /uploads/files
  • 16. Scope Gotcha’s #2 ● A service worker can load other scripts using the importScripts function ○ This is how we can load our malicious SW while maintaining the original SW functional ● Has to be installed on same origin
  • 17. Installation ● Once the browsers registers a SW, the install event occurs. ● Also occurs when SW is new / changed.
  • 18. Activation ● Once the installation was successful, the “activate” event occurs. ● Opened pages are not controlled by the SW (must be reloaded). ○ Can be overridden by using the self.clients.claim function
  • 19. Fetch ● Fires every time a resource is requested ● Control over what is being sent / received. ○ Headers ○ Status ○ Body
  • 20. Where to find them? ● Developer tools ● chrome://serviceworker-internals
  • 23. General Scenario Requirements All of the following scenarios depend on the following: ● The website has a file upload functionality. ○ We can upload arbitrary JavaScript files there (and retrieve them). ● There’s an XSS vulnerability in the app ○ We can inject JavaScript code in the context of the victims browser. All of the scenarios abuse the fact that we can attach to the fetch event (of the service worker) to manipulate requested resources.
  • 24. • Upload the malicious service worker to the website Upload • Using our XSS we register the malicious service worker Trigger • Attach to the fetch event. • We can modify the response of requested resources. PWN Response Modification
  • 26. • Upload the malicious service worker to the website Upload • Using our XSS we register the malicious service worker Trigger • Reinject our code • Expand our scope PWN XSS Persistency Response Modification
  • 27.
  • 28. • Upload the malicious service worker to the website Upload • Using our XSS we register the malicious service worker Trigger • Deny every requested resource PWN Denial of Service Response Modification
  • 29.
  • 30. • Upload the malicious service worker to the website Upload • Using our XSS we register the malicious service worker Trigger • Serve alternate content. PWN Phishing / Defacement Response Modification
  • 31.
  • 33. What Are Sandbox Domains? ● Generally host various types of files ● Ment to isolate user uploaded content from the main application ● Are different than the main application domain ● Files on the sandboxed domain are usually publicly available
  • 34. What Are Sandbox Domains? ● The file names are heavily obfuscated / random (does not resemble the file content or owner) ○ /super-random-and-unique-path-1337 ● Many vendors tend to ignore XSS findings in those domains since no cookies are shared among the sandboxed domain and the main application domain, like ● google.com vs googleusercontent.com ● facebook.com vs fbcdn.com ● etc.
  • 35. Data Leakage from Sandboxed Domains Consider the following scenario: ● There's a website called “bsides-photos.com” which handles sensitive information ● The uploaded sensitive data is stored in a sandboxed domain called “bsides-photos-sbx.com” ● There is an XSS in the sandboxed domain (boring, right?)
  • 36. Data Leakage from Sandboxed Domains bsides-photos-sbx.combsides-photos.com
  • 37. Data Leakage from Sandboxed Domains bsides-photos-sbx.com
  • 38. Data Leakage from Sandboxed Domains bsides-photos-sbx.com XSS Victim
  • 39. Data Leakage from Sandboxed Domains bsides-photos.com bsides-photos-sbx.com C2 Server
  • 40. DEMO
  • 41. Upload Trigger Activate Leak Data Leakage from Sandboxed Domains
  • 43. Enhancing Self XSS In this scenario we have: ● File upload functionality. ● A self XSS finding (low impact) on the /profile page. ○ A XSS that is triggered only on pages that are visible to us. ● Login / logout CSRF ○ Login and logout functions are not protected by CSRF tokens. ○ An attacker can force login/logout the victim. Enhancing Self XSS
  • 46. DEMO
  • 47. Enhancing Self XSS Enhancing Self XSS Setup Visit Logout/Login Register PWN
  • 48. Caveats Although this scenario looks promising, we are bounded under the following restrictions: ● Service Worker scope - if the uploaded service worker resides deeper in the page tree than the page we want to inspect, we won’t have effect on it. ○ Since the service worker won’t be activated there. ● Mime Type - the uploaded file must be served with the correct mime type for JavaScript files “application/javascript”
  • 50. Scope Enforcement ● Set the uploaded files depth deeper in the tree. ● In sandboxed domain - pick unique path hierarchy for every file ○ Timestamp / random-string dependent ● Refrain from using “/” as the scope (Service-Worker-Allowed response header) ○ Which allows global activation of the service worker ● Monitor requests with “Service-Worker” header (appended on register). Mitigations
  • 51. RUM (Real User Monitoring) ● RUM (real user monitoring) is a passive monitoring technique that records all the user interaction with the web application. ● It can be used to measure your clients web experience. ● When we observe a very poor performance on a specific client, one of the reasons could be DOS via Service Worker. Mitigations
  • 52. Browser Events Monitoring ● Monitor the navigator.serviceWorker.register function for new unauthorized register events. Mitigations
  • 53. Past Work on SW Prior Research ● Shadow Workers - https://github.com/shadow-workers/shadow-workers ● Marionet Attackd - https://love2dev.com/pwa/marionet-attack/ Guides ● Service Worker 101 - https://developers.google.com/web/fundamentals/primers/service-workers/ ● FAQ - https://dev.chromium.org/Home/chromium-security/security-faq/service- worker-security-faq Vulnerabilities ● %2f Vuln - https://alf.nu/ServiceWorker ● CSRF - https://ahussam.me/Amazon-leaking-csrf-token-using-service-worker/
  • 54. Key Takeaways Service workers can be useful for web application They can also cause mayhem Sandboxed domains could be not that sandboxed

Editor's Notes

  1. * add twitter
  2. 6 months ago Morning discussion Brainstormed on how to take low-med attacks and combine them into Meaningful high impact attack This is where this research was born
  3. Were going to talk about How SW API can enhance those low-med attacks into High impact, featureful attack Abuse scenarios Mitigations
  4. Browser run JS JS is single threaded Every tab has a thread – main thread On extreme load on the main thread we want responsive UI Delegate to other threads Web Workers API
  5. Main: // init new worker let worker = new Worker('worker.js'); // handle the message event worker.addEventListener('message', (e) => { console.log(e); }) // post some data postMessage({ name: 'BsidesLV' }); Worker: // handle the message event addEventListener('message', (e)=>{ // print out the data console.log(e.data); // send it back to the main thread postMessage(e.data); });
  6. Web Workers are bounded the a single page They have to be registered every time Expensive load time
  7. Type of web worker (no DOM) Proxy Scope Lifespan
  8. Supported on most browsers IE is still behind (like always)
  9. Registration Installation Activation Events Terminate != Deregistered
  10. Include a script tag inside the page Tells the browser where the SW is Returns a promise, when resolved Scope is logged The Browser only completes the register is the SW is new/updated Actual File (not in memory) https://carbon.now.sh/?bg=rgba(171%2C%20184%2C%20195%2C%201)&t=monokai&wt=none&l=javascript&ds=true&dsyoff=20px&dsblur=68px&wc=true&wa=true&pv=0px&ph=0px&ln=true&fm=Hack&fs=18px&lh=142%25&si=false&es=4x&wm=false&code=%252F%252F%2520main.js%250A%250Anavigator.serviceWorker.register(%27%252Fsw.js%27)%250A%2520%2520.then((reg)%2520%253D%253E%2520%257B%250A%2509console.log(%2560Registered!%2520Scope%253A%2520%2524%257Breg.scope%257D%2560)%250A%2520%2520%2520%257D)%253B
  11. Default We set the scope to /profile/ The SW will control /profile/* NOT for higher https://carbon.now.sh/?bg=rgba(171%2C%20184%2C%20195%2C%201)&t=monokai&wt=none&l=javascript&ds=true&dsyoff=20px&dsblur=68px&wc=true&wa=true&pv=0px&ph=0px&ln=true&fm=Hack&fs=18px&lh=142%25&si=false&es=4x&wm=false&code=%252F%252F%2520main.js%250A%250Anavigator.serviceWorker.register(%27%252Fsw.js%27%252C%2520%257B%250A%2509scope%253A%2520%27%252Fprofile%252F%27%250A%257D)%253B
  12. Good for caching https://carbon.now.sh/?bg=rgba(171%2C%20184%2C%20195%2C%201)&t=monokai&wt=none&l=javascript&ds=true&dsyoff=20px&dsblur=68px&wc=true&wa=true&pv=0px&ph=0px&ln=true&fm=Hack&fs=18px&lh=142%25&si=false&es=4x&wm=false&code=%252F%252F%2520sw.js%250A%250Aself.addEventListener(%27install%27%252C%2520(event)%2520%253D%253E%2520%257B%250A%2509%252F%252F%2520handle%2520installation%250A%257D)%253B
  13. Cleanup stale data https://carbon.now.sh/?bg=rgba(171%2C%20184%2C%20195%2C%201)&t=monokai&wt=none&l=javascript&ds=true&dsyoff=20px&dsblur=68px&wc=true&wa=true&pv=0px&ph=0px&ln=true&fm=Hack&fs=18px&lh=142%25&si=false&es=4x&wm=false&code=%252F%252F%2520sw.js%250A%250Aself.addEventListener(%27activate%27%252C%2520(event)%2520%253D%253E%2520%257B%250A%2509%252F%252F%2520handle%2520activation%252C%2520like%2520cleanup%2520of%2520old%2520SW%250A%257D)%253B
  14. Can respond also with cache https://carbon.now.sh/?bg=rgba(171%2C%20184%2C%20195%2C%201)&t=monokai&wt=none&l=javascript&ds=true&dsyoff=20px&dsblur=68px&wc=true&wa=true&pv=0px&ph=0px&ln=true&fm=Hack&fs=18px&lh=142%25&si=false&es=4x&wm=false&code=%252F%252F%2520sw.js%250A%250Aself.addEventListener(%27fetch%27%252C%2520(event)%2520%253D%253E%2520%257B%250A%2520%2520%2509console.log(%2560URL%253A%2520%2524%257Bevent.request.url%257D%2560)%253B%250A%2520%2520%250A%2509event.respondWith(%250A%2509%2509fetch(event.request)%253B%250A%2520%2520%2520%2520)%253B%250A%257D)%253B
  15. Visit a page w/o XSS Go to vuln page w/ XSS XSS triggered SW installed Back to page YES XSS!
  16. Go to page w/ some data No SW Trigger XSS Register SW Go to page No data SW responds 404 on that page
  17. Go to login page See that is successful Trigger XSS Install SW Installed verified Reload page Login again Submitted to malicious website
  18. Theres a website X that holds sensitive photoss Those photos are not hosted directly on X rather on Y (which is sandboxed)
  19. First, we upload the SW to the website (trivial since its sandbox)
  20. Then, we trigger the XSS on the victim Installs the SW
  21. Now, when the victim visits X and previews and image, the request is being made under the Y domain The service worker kicks in URL leaked
  22. Go to gallery See Images Trigger XSS Install SW Back to gallery Show
  23. Upload We upload the malicious SW to the sandboxed domain Trigger Using the XSS we register the SW Activate On every page under the scope, the SW is activated Leak Leak the image
  24. First, we upload the SW to the website (trivial since its sandbox)
  25. The victim goes to our page The page has an iframe Logout Login (attacker creds) Redirect to the actual site Trigger XSS Install SW
  26. Login as victim Show Victim Visiting attacker domain logout login redirect Login as Victim (again) PWN
  27. https://carbon.now.sh/?bg=rgba(171%2C%20184%2C%20195%2C%201)&t=monokai&wt=none&l=javascript&ds=true&dsyoff=20px&dsblur=68px&wc=true&wa=true&pv=0px&ph=0px&ln=true&fm=Hack&fs=18px&lh=142%25&si=false&es=4x&wm=false&code=%252F%252F%2520main.js%250A%250Alet%2520oldReg%2520%253D%2520navigator.serviceWorker.register%253B%2520%250A%250AObject.defineProperty(navigator.serviceWorker%252C%2520%27register%27%252C%2520%257B%2520%250A%2520%2520%2520get%253A%2520function()%2520%257B%2520%2520%250A%2520%2520%2520%2520%2520%2520console.log(%27will%2520be%2520invoked%2520before%2520every%2520register!%27)%253B%2520%250A%2520%2520%2520%2520%2520%2520return%2520oldReg%253B%2520%250A%2520%2520%2520%257D%2520%250A%257D)%253B