githubEdit

Web Sockets

WebSockets provide bi-directional, full-duplex communication over a single TCP connection, commonly used for real-time features like chat, notifications, and live updates.

Protocol Basics

Handshake Request

GET /chat HTTP/1.1
Host: normal-website.com
Sec-WebSocket-Version: 13
Sec-WebSocket-Key: wDqumtseNBJdhkihL6PW7w==
Connection: keep-alive, Upgrade
Cookie: session=KOsEJNuflw4Rd9BDNrVmvwBF9rEijeE2
Upgrade: websocket
Origin: https://normal-website.com

Handshake Response

HTTP/1.1 101 Switching Protocols
Connection: Upgrade
Upgrade: websocket
Sec-WebSocket-Accept: 0FFP+2nmNIf/h+4BP36k9uzrYGk=

Security Testing

Cross-Site WebSocket Hijacking (CSWSH)

If the server doesn't validate the Origin header, attackers can hijack WebSocket connections.

Test for CSWSH:

Message Manipulation

Common Vulnerabilities

Vulnerability
Test

Missing Origin validation

Send request with different Origin

No authentication

Connect without session cookie

Injection in messages

Send <script>, SQL, etc. in messages

IDOR via WebSocket

Change user IDs in messages

Rate limiting bypass

WebSocket often lacks rate limits

Insecure ws://

Check if wss:// is enforced

Testing Tools

STEWS - Security Testing for WebSockets

Burp Suite

wscat (CLI WebSocket Client)

websocat

Exploitation Scenarios

XSS via WebSocket

SQL Injection via WebSocket

Authorization Bypass

Browser Console Testing

  • CSRF - CSWSH is similar to CSRF

  • XSS - Can chain with WebSocket attacks

  • IDOR - Common in WebSocket APIs

Last updated

Was this helpful?