githubEdit

WebSocket Pentesting

WebSocket is a protocol that provides full-duplex communication channels over a single single TCP connection.

Connect with CLI

websocatarrow-up-right is a command-line client for WebSockets, like netcat for

websocat ws://<ip>/

Connect with Python Script

import websocket,json

ws = websocket.WebSocket()
ws.connect("ws://10.0.0.1/")
d = {"message": "hello"}
data = str(json.dumps(d))
ws.send(data)
result = ws.recv()
print(json.loads(result))

As above, we can manipulate the data to send. For example,

{"message": "<script>alert(1)</script>"}

If the website reflects the result of the above interactions, we can affect the website.

Blind SQL Injection

First, create a Python script to establish a middleware server to forward sqlmap payloads to the target WebSocket server. The script name is “server.py” here. Also we need to install websocket-clientarrow-up-right Python package.

Then start middleware server by running the above script.

Finally execute sqlmap.

For details, see this awesome postarrow-up-right.

Cross-Site WebSocket Hijacking

  1. Send messages in the target web page like chat room using WebSocket.

  2. Check the WebSocket handshake connection in the request as below. It contains the “Connection: Upgrade”, “Upgrade: websocket”, “Sec-WebSocket-Key”, etc. in the request header.

  3. If there is no CSRF token in the request, we can CSRF on WebSocket.

  4. In our WebSocket server, create the script.

  5. In our attack website, copy files of the target and paste to our web directory to impersonate the target website.

    Start web server using Python.

References

Last updated