Hacking With WebSockets
Hacking With WebSockets
Hacking With WebSockets
Mike Shema
Sergey Shekyan
Vaagn Toukharian (got sick last night)
December 2012
Thursday, December 13, 12
Almost WebSockets
Forcing HTML5 on a non-HTML5 browser
web-socket-js -- The power of Flashs raw sockets with the
benefits(?) of Flashs security
sockjs-client -- Pure JavaScript, choose your poison: long-polling,
XHR, etc.
HTML5 Server-Sent Events (http://www.w3.org/TR/eventsource/)
Properly-implemented long-polling
Content only flows from server client
Thursday, December 13, 12
- RFC 6455
5
Speak to Me
Protocol
(RFC 6455)
Low overhead
Simple format
Content agnostic
HTTP compatible*
Thursday, December 13, 12
JavaScript API
.onmessage()
.send()
Data as String,
Blob,
ArrayBuffer
Handshake Challenge
GET /?encoding=text HTTP/1.1
Host: echo.websocket.org
User-Agent: ...
Connection: Upgrade
Sec-WebSocket-Version: 13
Origin: http://www.websocket.org
Sec-WebSocket-Key: CjYoQD+BXC718rj3aiExxw==
Handshake Response
HTTP/1.1 101 Switching Protocols
Upgrade: WebSocket
Proxy might
remove this!
Connection: Upgrade
Sec-WebSocket-Accept: c4RVZSknSoEHizZu6BKl3v
+xUuI=
base64(SHA1(challenge + GUID)
[ then the data frames begin ]
HTTP Handshake
Proves mutual agreement to speak WebSockets
Not intended to prove either trust or identity
User Agent should not establish plaintext WebSocket (ws:) from
secure resource (https:)
Includes the Origin header
Must complete before another connection may be established to
the same origin
Thursday, December 13, 12
10
Variable Lengths
Decimal Length (7 bits)
1000000
n/a
128
0111111
00000001 00000000
65535
0111111
11111111 11111111
65536
1111111
2^64 - 1 1 1 1 1 1 1 1
19
1100100
n/a
19
0111111
11001000 00000000
19
1111111
11
src
dst
options
TCP
sport
dport
seq
ack
dataofs
reserved
flags
window
chksum
urgptr
options
10.171.90.44
174.129.224.73
[]
Masking Data
63784
http
4216425855
3939836193
8L
0L
PA
33304
0xfac2
0
[(NOP, None), ([...]
f9 28 00 50 fb 51 8d 7f ea d5 21 21 80 18
82 18 fa c2 00 00 01 01 08 0a c5 4f 2d e2 61 52
72 98
WebSocket
flags
opcode
mask flag
length
mask
frame data
FIN
text frame
1L
37L
0xbdccefe0
\xe9\xa4\x8a\x99\[...]
81 a5 bd cc ef e0 e9 a4 8a 99 9a be 8a c0
de a3 82 89 d3 ab cf 94 d2 ec 88 85 c9 ec 96 8f
c8 e0 cf a2 dc be 8d 81 cf ad c1 ce 93
bd cc ef e0 bd cc ef e0 bd ...
e9 a4 8a 99 9a be 8a c0 de ...
T h e y r e
c
Thursday, December 13, 12
12
Design Choices
Items transparent to JavaScript API
User Agents mask data to the server
Ping & pong frames for connection keep-alive
User Agent should minimize details for certain kinds of
connection failures to prevent better host/port scanning
13
14
15
16
17
18
t
a
19
20
Fuzzing WS
Fuzzing WS data
Capturing real life data with JS
Fuzzing within a Browser
Fuzzing WS frameworks
Fuzzing WS handshake
Fuzzing WS Headers
Thursday, December 13, 12
21
};
this._send(data);
22
Fuzzing Frameworks
23
Fingerprinting
WebSocket++
Successful handshake:
HTTP/1.1 101 Switching Protocols
Connection: Upgrade
Sec-WebSocket-Accept: Pzio3NY64M/GFfA/kK4WJpj2xY4=
Server: WebSocket++/0.2.0dev
Upgrade: websocket
Failed handshake:
HTTP/1.1 404
Server: WebSocket++/0.2.0dev
24
Fingerprinting
AutobahnPython
Successful handshake:
HTTP/1.1 101 Switching Protocols
Connection: Upgrade
Sec-WebSocket-Accept:fKrZviGIoYH4PrDbQ98Nvsbk2cU=
Server: AutobahnPython/0.5.9
Upgrade: WebSocket
Failed handshake:
HTTP/1.1 400 WebSocket version 12 not supported
(supported versions: 13,8,0)
Sec-WebSocket-Version: 13,8,0
Thursday, December 13, 12
25
Fingerprinting
Node.JS
Successful handshake:
HTTP/1.1 101 Switching Protocols
Connection: Upgrade
Sec-WebSocket-Accept:zSKX8MU5Omx1JXHacSpdN5a4ur4=
Upgrade: websocket
Failed handshake:
HTTP/1.1 426 Upgrade Required
Connection: close
Sec-WebSocket-Version: 13
X-WebSocket-Reject-Reason: Unsupported websocket client
version: 12Only versions 8 and 13 are supported.
Thursday, December 13, 12
26
27
Tools
WireShark
Proxies(ZAProxy, Fiddler)
Chrome Developer Tools
overloaded WebSocket constructor and methods
28
29
30
Not really...
Distribution of Alexa Top 600K websites that use WebSockets
100K
200K
300K
400K
500K
600K
0
38
75
113
150
31
Details?
0.15% of websites use WebSockets on
landing page.
Less than 4% of captured WebSockets
are using plain ws:
95% of total WebSockets connect
to a single vendors customer
support chat system
among remaining 5%, less
than 1% are using
encryption
32
100K
200K
300K
400K
500K
600K
0
33
34
Recommendations
What it's good for
Time critical data delivery
Apps that require true bidirectional flow
Interactivity
Higher throughput
Remember, it doesnt fix existing vulnerabilities
Thursday, December 13, 12
35
Deploying a Server
Capacity planning & measurement to prevent self-inflicted DoS
Verify the Origin header
As always, assume the client is hostile -- dont trust it
Be careful when implementing the HTTP handshake
Create a single-purpose HTTP handler, not a pseudo-web server
36
37
38
Summary
WebSockets solve connection problems, not security
problems.
Basic security principles still apply, especially for data
frames content.
The new port 80 -- security devices have poor
(nonexistent!?) awareness of the protocol.
39
Q&A
40
Thank You!
Mike @CodexWebSecurum
Sergey @sshekyan
Vaagn @tukharian
Thursday, December 13, 12
41
References
http://lists.whatwg.org/pipermail/whatwg-whatwg.org/
2008-June/015108.html
http://www.ietf.org/mail-archive/web/tls/current/
msg05593.html
http://webtide.intalio.com/2011/09/cometd-2-4-0websocket-benchmarks/
Thursday, December 13, 12
42
Interest in WebSockets?
43