WebSockets
Last updated
Was this helpful?
Last updated
Was this helpful?
Handshake: The connection starts with an HTTP handshake, where the client sends an upgrade request to switch the protocol from HTTP
to WebSocket
.
Data Frames: After the handshake, data is exchanged in frames (text or binary data).
Connection Lifecycle: The connection remains open, allowing either party to send data until one side closes the connection.
The example below is based on PostSwigger's lab.
If we sent a payload directly from the Live chat functionality, it gets encoded (Figure 1).
We can intercept the traffic, decode the payload manually, and let the traffic be forwarded (Figure 2).
To achieve WebSocket Hijacking we need to perform a attack on a WebSocket handshake, which is possible if:
The handshake relies on cookies.
There are no CSRF tokens.
We notice that we are assigned a session
cookie with the SameSite
attribute set to None
, which is a prerequisite for this attack (Figure 3).
After inspecting the WebSocket connection behaviour, we can create a payload and retrieve the chat logs which include carlos
's password (Figure 4).
The example below is based on PostSwigger's lab.
The example below is based on PostSwigger's lab.
In an effort to replicate our attack process, we get our IP address blacklisted (Figure 6).
We can try different to bypass this filter and send a slightly obfuscated payload instead (Figure 7).