slighted / docs /ARCHITECTURE.md
runitx's picture
Add WebSocket architecture and protocol documentation
690bed1 unverified
|
Raw History Blame Contribute Delete
3.42 kB

awoo.cf / p.awoo.cf WebSocket & Anti-Bot Architecture

Documented from browser network captures, passive DNS/HTTP inspection, and reverse engineering of client JS bundles (app-AGKBSCUS.js).


1. Network & Server Topology

  • Web Frontend (https://awoo.cf):
    • Proxied behind Cloudflare (AS13335).
    • Serves HTML compressed using per-board Zstd dictionaries (e.g. /assets/dictionaries/g/html-*.dict).
    • Runs a Meguca imageboard fork (nekohash client bundles).
  • Token & WebSocket Backend (p.awoo.cf, p4.awoo.cf):
    • Resolves directly (bypassing Cloudflare proxy) to DataWagon LLC infrastructure.
    • Handles token issuance (POST https://p.awoo.cf/v1/token) and WebSocket upgrades (wss://p.awoo.cf/api/socket, wss://p4.awoo.cf/api/socket).

2. Pre-WebSocket Gate & Handshake Flow

Before opening the WebSocket, the client completes:

  1. Cloudflare Clearance:
    • Obtains cf_clearance and __cf_bm cookies on awoo.cf.
  2. WebSocket Gate Check:
    • GET https://awoo.cf/api/captcha/ws-gates/status → {"ok": true}
  3. WebAssembly Fingerprint Challenge:
    • GET https://awoo.cf/api/fp-challenge → {"c": "<base64-challenge>"}
    • Executes /assets/wasm/fp_seal.*.wasm to compute and seal the browser fingerprint into cookie mgc_fpc (v1.<timestamp>.<challenge>.<hmac>).
  4. Token Binding:
    • POST https://p.awoo.cf/v1/token with JSON body {"binding": "<base64url-id>"} → returns initial token binding (v2.<...> structure).

3. WebSocket Upgrade & Challenge-Response Protocol

  • Upgrade Request:

    • wss://p.awoo.cf/api/socket?binding=<binding>
    • Sec-WebSocket-Version: 13
    • Sec-WebSocket-Extensions: permessage-deflate
    • Origin: https://awoo.cf
    • Required cookies: cf_clearance, __cf_bm, meguca_gocaptcha_html, meguca_gocaptcha_ws, mgc_fpc, meta_pass, captcha_session, _known.
  • 6-Step Challenge Handshake:

    • Upon upgrade, the server initiates a multi-step numeric challenge before allowing any commands.
    • Server sends integer t as string: 100000 <= t <= 1999999.
    • Client must immediately reply with str(t + 1).
    • This cycle repeats for 6 consecutive rounds.
    • On the 6th round, the server responds with the confirmed token string (v2.<base64...>).
    • At this point, the connection transitions to authenticated state.
  • Board / Thread Synchronization (44):

    • Client synchronizes by sending message type 44:
      44{
        "board": "all",
        "thread": null,
        "protocolVersion": 1,
        "loginData": null,
        "seal": "noWASM",
        "fp": "<token>",
        "meta_pass": "<meta_pass>"
      }
      
    • For a specific thread (e.g. /g/1256858), set "board": "g" and "thread": 1256858.
    • The server streams initial sync state:
      • 50: Server time / sync counter
      • 56: Captcha & session data
      • 55: Board configuration
      • 63: Thread presence count
      • 44: Thread and post catalog state
  • Real-Time Event Streaming:

    • 01: New post created (INSERT_POST)
    • 02: Real-time text append (APPEND)
    • 04: Real-time text splice (SPLICE)
    • 05: Post finished / closed (CLOSE_POST)
    • 06: Image attachment (INSERT_IMAGE)
  • Keepalive Ping:

    • Client sends message 48 periodically (every 15–20 seconds) as a NOOP ping to prevent idle connection closure.