SlideShare a Scribd company logo
What’s wrong with w/ WebSocket API?
Unveiling vulnerabilities in
WebSocket APIs
Mikhail Egorov / @0ang3el
#HACKTIVITY2019
# whoami
2
▪ Security researcher / full-time bug hunter
▪ https://bugcrowd.com/0ang3el
▪ https://hackerone.com/0ang3el
▪ Conference speaker
▪ https://www.slideshare.net/0ang3el
▪ https://speakerdeck.com/0ang3el
Previous work
3
▪ https://media.blackhat.com/bh-us-
12/Briefings/Shekyan/BH_US_12_Shekyan_Toukharian_Hacking_Websocket_Slides
.pdf
▪ https://www.nccgroup.trust/us/about-us/newsroom-and-
events/blog/2017/may/wssip-a-websocket-manipulation-proxy/
▪ https://chybeta.github.io/2018/04/07/spring-messaging-Remote-Code-Execution-
%E5%88%86%E6%9E%90-%E3%80%90CVE-2018-1270%E3%80%91/
▪ https://www.twistlock.com/labs-blog/demystifying-kubernetes-cve-2018-1002105-
dead-simple-exploit/
▪ https://github.com/andresriancho/websocket-fuzzer
▪ https://www.irongeek.com/i.php?page=videos/derbycon9/stable-35-old-tools-new-
tricks-hacking-websockets-michael-fowl-nick-defoe
4
WebSocket protocol essentials
WebSocket protocol – RFC 6455
5
▪ Efficient two-way communication protocol
▪ WebSocket is stateful (HTTP is stateless)
▪ Two main parts: handshake and data transfer
WebSocket protocol – RFC 6455
6
▪ Extensibility: subprotocols and extensions
▪ Subprotocols
▪ https://www.iana.org/assignments/websocket/websocket.xml#subpro
tocol-name
▪ Wamp
▪ Stomp
▪ Soap
▪ …
WebSocket protocol – RFC 6455
7
▪ Extensibility: subprotocols and extensions
▪ Extensions
▪ https://www.iana.org/assignments/websocket/websocket.xml#extens
ion-name
▪ permessage-deflate
▪ bbf-usp-protocol
WebSocket protocol – RFC 6455
8
▪ Origin-based security model (Browser clients)
▪ No authentication
▪ Client must do client-to-server masking
WebSocket protocol support
9
▪ Major web browsers
▪ Web servers / Proxies
▪ Apache httpd, Nginx, IIS, …
▪ HAProxy, Traefik, Varnish, Envoy, …
▪ Cloud providers
▪WebSocket API (api gateways)
▪WebSocket proxying (load balancers)
WebSocket handshake
10
Upgrade request
Base64(Random nonce)
Protocol version
Required HTTP version
WebSocket handshake
11
Required status code
BASE64(SHA1(Sec-WebSocket-Key || CONST ))
WebSocket data transfer
12
x00 – continuation frame
x01 – text frame
x02 – binary frame
x08 – close frame
x09 – ping
x0A – pong
other values are reserved
WebSocket data transfer - masking
13
▪ Masking key is 32-bit long passed inside frame
▪ Client must send masked data
▪ MASKED = MASK ^ DATA (^ - XOR)
▪ Mechanism protects against cache poisoning and
smuggling attacks
14
Cross-Site WebSocket Hijacking
WebSocket security for Web Browser
15
▪ SOP doesn’t work for WebSocket in web browser
▪ Read from WebSocket cross-origin
▪ Write to WebSocket cross-origin
▪ Header Origin should be checked on handshake
step (origin-based security model)
CSWSH
16
▪ Cookies are used to authenticate upgrade request
▪ Header Origin isn’t checked or checked poorly
CSWSH
17
▪ CORS tricks from @albinowax are applicable to
WebSocket
▪ https://portswigger.net/research/exploiting-cors-misconfigurations-
for-bitcoins-and-bounties
▪ Null origin
▪ Pre-domain wildcard
▪ Post-domain wildcard
▪ …
CSWSH – Null origin
18
▪ nullorigin.html
<iframe src="data:text/html,
<script>const socket = new
WebSocket('wss://example.com');
</script>"></iframe>
CSWSH
19
▪ Playground
▪ https://portswigger.net/web-security/websockets/cross-site-
websocket-hijacking
CSWSH – template for attack
5
Demo
5
22
Authentication / IDOR issues
Authentication
23
▪ WebSocket protocol doesn’t offer authentication
▪ Developers have to roll out their own AuthN
▪ It’s secure to check AuthN only during handshake
▪ Common secure implementations
▪ Session cookies
▪ Tokens
Broken authentication – Case 1
24
▪ Some ID / GUID is required in Upgrade request
▪ Guess ID
▪ Leak GUID (minor IDOR, …)
Broken authentication – Case 2
25
▪ No authentication during handshake step
▪ Some ID / GUID required in API messages
▪ Guess ID
▪ Leak GUID (minor IDOR, …)
Broken authentication – Case 2
26
▪ Exposing GraphQL subscriptions w/o AuthN
▪ https://github.com/righettod/poc-graphql#subscriptions-
websocket-endpoint-default-enabling
▪ Path /subscriptions
Insecure Direct Object Reference issues
27
▪ Strong authentication during handshake step
▪ Some ID / GUID required in API messages
▪ Guess ID
▪ Leak GUID (minor IDOR, …)
28
Smuggling through WebSocket
Reverse proxying WebSocket connection
29
Client
Frontend
Reverse proxy
Backend
/socket.io/
Public WebSocket API
Reverse proxying WebSocket connection
30
Client
Frontend
Reverse proxy
Upgrade request Upgrade request
Backend
/socket.io/
Reverse proxying WebSocket connection
31
Client
Frontend
Reverse proxy
Upgrade request Upgrade request
HTTP/1.1 101HTTP/1.1 101
Backend
/socket.io/
Reverse proxying WebSocket connection
32
Client
Frontend
Reverse proxy
Upgrade request Upgrade request
HTTP/1.1 101HTTP/1.1 101
WebSocket connection
direct WebSocket connection
Client - Backend
Backend
/socket.io/
Smuggling through WebSocket connection
33
Client
Frontend
Reverse proxy
(vulnerable)
Private REST API
Public WebSocket API
Backend
/internal
/socket.io/
34
BackendClient
Frontend
Reverse proxy
(vulnerable)
/internal
Upgrade request
/socket.io/
Sec-WebSocket-Version: 1337
Upgrade request
Sec-WebSocket-Version: 1337
Version correctness isn’t checked!
Smuggling through WebSocket connection
35
BackendClient
Frontend
Reverse proxy
(vulnerable)
/internal
Upgrade request
/socket.io/
Sec-WebSocket-Version: 1337
Upgrade request
Sec-WebSocket-Version: 1337
HTTP/1.1 426HTTP/1.1 426
Response correctness isn’t checked!
Smuggling through WebSocket connection
36
BackendClient
Frontend
Reverse proxy
(vulnerable)
/internal
Upgrade request
/socket.io/
Sec-WebSocket-Version: 1337
Upgrade request
Sec-WebSocket-Version: 1337
HTTP/1.1 426HTTP/1.1 426
TLS connection
direct TLS connection
Client – Backend
not WebSocket!!!
Client can access
/internal
Smuggling through WebSocket connection
Challenge – challenge.0ang3el.tk
37
▪ URL
▪ https://challenge.0ang3el.tk/websocket.html
▪ You need to access flag on localhost:5000
▪ Seems no one solved
Challenge – challenge.0ang3el.tk
38
▪ Frontend
▪ Not disclosed WebSocket reverse proxy
▪ socket.io.js
▪ Proxies only WebSocket API - /socket.io/ path
▪ Backend
▪ Flask, Flask-SoketIO, Flask-Restful
▪ Listens on localhost:5000 only
challenge1.py
challenge1.py - DEMO
Vulnerable reverse proxies
41
▪ Vulnerable
▪ Varnish, Envoy proxy <= 1.8.0, other non-disclosed
▪ Not vulnerable
▪ Nginx, HAProxy, Traefik, others
Varnish response
42
▪ WebSocket proxying configuration
▪ https://varnish-cache.org/docs/6.3/users-guide/vcl-example-
websockets.html
Smuggling through WebSocket connection
43
Client
Frontend
Reverse proxy
(Nginx or another)
Private REST API
Public WebSocket API & REST API
Backend
/internal
/api/socket.io/
/api/health
Smuggling through WebSocket connection
44
Client
Frontend
Reverse proxy
(Nginx or another)
Backend
/internal
/api/socket.io/
/api/health
example.com
GET
HTTP/1.1 200
Smuggling through WebSocket connection
45
Client
Frontend
Reverse proxy
(Nginx or another)
Backend
/internal
/api/socket.io/
/api/health
Only Upgrade: websocket header is checked!
POST /api/health?u= POST /api/health?u=
Smuggling through WebSocket connection
46
Client
Frontend
Reverse proxy
(Nginx or another)
Backend
/internal
/api/socket.io/
/api/health
attacker.com
GET
HTTP/1.1 101
HTTP/1.1 101HTTP/1.1 101
Only status code is checked for response!
POST /api/health?u= POST /api/health?u=
Smuggling through WebSocket connection
47
Client
Frontend
Reverse proxy
(Nginx or another)
Backend
/internal
/api/socket.io/
/api/health
HTTP/1.1 101HTTP/1.1 101
TLS connection
direct TLS connection
Client – Backend
not WebSocket!!!
Client can access
/internal
POST /api/health?u= POST /api/health?u=
Client-to-Server
masking isn’t checked
by proxy!!!
Challenge2 – challenge2.0ang3el.tk
48
▪ URL
▪ https://challenge2.0ang3el.tk/websocket.html
▪ You need to access flag on localhost:5000
▪ Seems no one solved
Challenge2 – challenge2.0ang3el.tk
49
▪ Frontend
▪ Nginx as WebSocket reverse proxy
▪ socket.io.js
▪ Proxies only /api/public path (socket.io and healthcheck)
▪ Backend
▪ Flask, Flask-SoketIO, Flask-Restful
▪ Listens on localhost:5000 only
Challenge2 – challenge2.0ang3el.tk
50
▪ Nginx config
Challenge2 – challenge2.0ang3el.tk
51
▪ REST API - healthcheck
Challenge2.py
5
Challenge2.py - Demo
5
Vulnerable reverse proxies
54
▪ Almost all proxies are affected
▪ But exploitation is limited
▪ External SSRF is required that returns status code
▪ …
55
Discovering WebSocket APIs
Discovering WebSocket API
56
▪ Monitor Upgrade requests
▪ Analyze JavaScript files
▪ Try to establish WebSocket connection to each
URL
▪ …
57
Conclusion
Ideas for further research
58
▪ Security of WebSocket subprotocols
▪ More smuggling techniques
▪ HTTP/2 and WebSocket
▪ …
Thank you!
@0ang3el

More Related Content

PDF
HTTP Request Smuggling via higher HTTP versions
PDF
Bug Bounty Hunter Methodology - Nullcon 2016
PPTX
Attacking thru HTTP Host header
PDF
Frans Rosén Keynote at BSides Ahmedabad
PPTX
XSS - Do you know EVERYTHING?
PPTX
Reverse proxies & Inconsistency
PDF
F5 ASM v12 DDoS best practices
PDF
Neat tricks to bypass CSRF-protection
HTTP Request Smuggling via higher HTTP versions
Bug Bounty Hunter Methodology - Nullcon 2016
Attacking thru HTTP Host header
Frans Rosén Keynote at BSides Ahmedabad
XSS - Do you know EVERYTHING?
Reverse proxies & Inconsistency
F5 ASM v12 DDoS best practices
Neat tricks to bypass CSRF-protection

What's hot (20)

PPTX
WAF Bypass Techniques - Using HTTP Standard and Web Servers’ Behaviour
PPTX
A Forgotten HTTP Invisibility Cloak
PPTX
Waf bypassing Techniques
PPTX
WAF ASM / Advance WAF - Brute force lior rotkovitch f5 sirt v5 clean
PDF
Offzone | Another waf bypass
PDF
HTTP Security Headers
PDF
A story of the passive aggressive sysadmin of AEM
PDF
F5 BIG-IP Misconfigurations
PDF
X-XSS-Nightmare: 1; mode=attack XSS Attacks Exploiting XSS Filter
PDF
Hacking Adobe Experience Manager sites
PDF
The Secret Life of a Bug Bounty Hunter – Frans Rosén @ Security Fest 2016
PDF
Time based CAPTCHA protected SQL injection through SOAP-webservice
PDF
Building Advanced XSS Vectors
PDF
Lior rotkovitch ASM WAF unified learning – building policy with asm v12
PPTX
Going Beyond Microsoft IIS Short File Name Disclosure - NahamCon 2023 Edition
PDF
XSS Magic tricks
PPTX
Command injection
PPTX
XSS Attacks Exploiting XSS Filter by Masato Kinugawa - CODE BLUE 2015
PDF
HTTP Parameter Pollution Vulnerabilities in Web Applications (Black Hat EU 2011)
PDF
Live Hacking like a MVH – A walkthrough on methodology and strategies to win big
WAF Bypass Techniques - Using HTTP Standard and Web Servers’ Behaviour
A Forgotten HTTP Invisibility Cloak
Waf bypassing Techniques
WAF ASM / Advance WAF - Brute force lior rotkovitch f5 sirt v5 clean
Offzone | Another waf bypass
HTTP Security Headers
A story of the passive aggressive sysadmin of AEM
F5 BIG-IP Misconfigurations
X-XSS-Nightmare: 1; mode=attack XSS Attacks Exploiting XSS Filter
Hacking Adobe Experience Manager sites
The Secret Life of a Bug Bounty Hunter – Frans Rosén @ Security Fest 2016
Time based CAPTCHA protected SQL injection through SOAP-webservice
Building Advanced XSS Vectors
Lior rotkovitch ASM WAF unified learning – building policy with asm v12
Going Beyond Microsoft IIS Short File Name Disclosure - NahamCon 2023 Edition
XSS Magic tricks
Command injection
XSS Attacks Exploiting XSS Filter by Masato Kinugawa - CODE BLUE 2015
HTTP Parameter Pollution Vulnerabilities in Web Applications (Black Hat EU 2011)
Live Hacking like a MVH – A walkthrough on methodology and strategies to win big
Ad

Similar to What’s wrong with WebSocket APIs? Unveiling vulnerabilities in WebSocket APIs. (20)

PPTX
14. html 5 security considerations
PDF
Programming WebSockets - OSCON 2010
PDF
Node.js on microsoft azure april 2014
PDF
Nodejs and WebSockets
PDF
What should a hacker know about WebDav?
PPTX
The Hacking Games - A Road to Post Exploitation Meetup - 20240222.pptx
PDF
Websocket shanon
PDF
Programming WebSockets - April 20 2010
PPTX
CodeIgniter i18n Security Flaw
PDF
Attack Chaining: Advanced Maneuvers for Hack Fu
PDF
Analyzing the Performance of Mobile Web
PPTX
Everybody loves html5,h4ck3rs too
PDF
WebSockets: The Current State of the Most Valuable HTML5 API for Java Developers
PPTX
Jon Stace Web Cryptography API
PPTX
Malware Analysis For The Enterprise
PDF
Single sign-on
PDF
Chrome Devtools Protocol via Selenium/Appium (English)
DOCX
Exploration note - none windows based authentication for WCF
PPTX
Cross Context Scripting attacks & exploitation
PDF
Ruby On Rails Security 9984
14. html 5 security considerations
Programming WebSockets - OSCON 2010
Node.js on microsoft azure april 2014
Nodejs and WebSockets
What should a hacker know about WebDav?
The Hacking Games - A Road to Post Exploitation Meetup - 20240222.pptx
Websocket shanon
Programming WebSockets - April 20 2010
CodeIgniter i18n Security Flaw
Attack Chaining: Advanced Maneuvers for Hack Fu
Analyzing the Performance of Mobile Web
Everybody loves html5,h4ck3rs too
WebSockets: The Current State of the Most Valuable HTML5 API for Java Developers
Jon Stace Web Cryptography API
Malware Analysis For The Enterprise
Single sign-on
Chrome Devtools Protocol via Selenium/Appium (English)
Exploration note - none windows based authentication for WCF
Cross Context Scripting attacks & exploitation
Ruby On Rails Security 9984
Ad

More from Mikhail Egorov (9)

PDF
A Hacker's perspective on AEM applications security
PDF
Securing AEM webapps by hacking them
PDF
Hunting for security bugs in AEM webapps
PDF
AEM hacker - approaching Adobe Experience Manager webapps in bug bounty programs
PPTX
CSRF-уязвимости все еще актуальны: как атакующие обходят CSRF-защиту в вашем ...
PDF
Unsafe JAX-RS: Breaking REST API
PDF
Entity provider selection confusion attacks in JAX-RS applications
PDF
New methods for exploiting ORM injections in Java applications
PDF
ORM2Pwn: Exploiting injections in Hibernate ORM
A Hacker's perspective on AEM applications security
Securing AEM webapps by hacking them
Hunting for security bugs in AEM webapps
AEM hacker - approaching Adobe Experience Manager webapps in bug bounty programs
CSRF-уязвимости все еще актуальны: как атакующие обходят CSRF-защиту в вашем ...
Unsafe JAX-RS: Breaking REST API
Entity provider selection confusion attacks in JAX-RS applications
New methods for exploiting ORM injections in Java applications
ORM2Pwn: Exploiting injections in Hibernate ORM

Recently uploaded (20)

PPTX
international classification of diseases ICD-10 review PPT.pptx
PDF
Cloud-Scale Log Monitoring _ Datadog.pdf
PDF
Triggering QUIC, presented by Geoff Huston at IETF 123
PPTX
Job_Card_System_Styled_lorem_ipsum_.pptx
PDF
SASE Traffic Flow - ZTNA Connector-1.pdf
PPTX
PptxGenJS_Demo_Chart_20250317130215833.pptx
PDF
RPKI Status Update, presented by Makito Lay at IDNOG 10
PPTX
Internet___Basics___Styled_ presentation
PDF
Testing WebRTC applications at scale.pdf
PDF
Paper PDF World Game (s) Great Redesign.pdf
PDF
Sims 4 Historia para lo sims 4 para jugar
PPTX
presentation_pfe-universite-molay-seltan.pptx
PPTX
INTERNET------BASICS-------UPDATED PPT PRESENTATION
PPTX
Slides PPTX World Game (s) Eco Economic Epochs.pptx
PPTX
innovation process that make everything different.pptx
PPTX
Module 1 - Cyber Law and Ethics 101.pptx
PPTX
Funds Management Learning Material for Beg
PDF
Best Practices for Testing and Debugging Shopify Third-Party API Integrations...
PDF
APNIC Update, presented at PHNOG 2025 by Shane Hermoso
PDF
The New Creative Director: How AI Tools for Social Media Content Creation Are...
international classification of diseases ICD-10 review PPT.pptx
Cloud-Scale Log Monitoring _ Datadog.pdf
Triggering QUIC, presented by Geoff Huston at IETF 123
Job_Card_System_Styled_lorem_ipsum_.pptx
SASE Traffic Flow - ZTNA Connector-1.pdf
PptxGenJS_Demo_Chart_20250317130215833.pptx
RPKI Status Update, presented by Makito Lay at IDNOG 10
Internet___Basics___Styled_ presentation
Testing WebRTC applications at scale.pdf
Paper PDF World Game (s) Great Redesign.pdf
Sims 4 Historia para lo sims 4 para jugar
presentation_pfe-universite-molay-seltan.pptx
INTERNET------BASICS-------UPDATED PPT PRESENTATION
Slides PPTX World Game (s) Eco Economic Epochs.pptx
innovation process that make everything different.pptx
Module 1 - Cyber Law and Ethics 101.pptx
Funds Management Learning Material for Beg
Best Practices for Testing and Debugging Shopify Third-Party API Integrations...
APNIC Update, presented at PHNOG 2025 by Shane Hermoso
The New Creative Director: How AI Tools for Social Media Content Creation Are...

What’s wrong with WebSocket APIs? Unveiling vulnerabilities in WebSocket APIs.