返回首页

通过 WebRTC TURN 的 SOCKS5:Go 实现

工具将 SOCKS5 流量伪装成 WB Stream WebRTC 视频会议。反向 API、最小 protobuf 解析器、通过 TURN 中继的 KCP 带 yamux。纯 Go 完整自动化。

视频会议中的 SOCKS5 隧道:完整详解
Advertisement 728x90

通过WebRTC TURN Wildberries实现SOCKS5隧道:Go语言实现详解

一款工具已开发完成,可在WB Stream平台上将SOCKS5流量隐藏在WebRTC TURN会话中。流量通过LiveKit SFU伪装成视频会议。完整流程包括:反向HTTP API、protobuf解析、基于TURN中继的KCP协议、yamux多路复用。无需浏览器,单条启动命令即可运行。

逆向分析stream.wb.ru API

通过puppeteer收集流量,揭示了四个HTTP请求和一个WebSocket连接的序列。主页面会阻止无浏览器的请求(返回代码498),但API端点仍可访问。

序列如下:

Google AdInline article slot
  • POST /auth/api/v1/auth/user/guest-register — 获取带有displayName的访客JWT令牌。
  • POST /api-room/api/v2/room — 创建房间,参数为roomType: ROOM_TYPE_ALL_ON_SCREENroomPrivacy: ROOM_PRIVACY_FREE
  • POST /api-room/api/v1/room/{id}/join — 加入房间(GET请求返回501)。
  • GET /api-room-manager/api/v1/room/{id}/token — 获取LiveKit令牌(注意Accept-Encoding中的gzip处理)。

WebSocket地址:wss://wbstream01-el.wb.ru:7880/rtc?access_token=...&sdk=js&version=2.15.3&protocol=16。ICE服务器:turn:wb-stream-turn-1.wb.ru:3478

使用net/http实现,无需cookies或CSRF防护。

rr, _ := wb(cl, "POST", "/auth/api/v1/auth/user/guest-register",
    []byte(`{"displayName":"lh_42"}`), "")

LiveKit SignalResponse的Protobuf解析器

LiveKit在SignalResponse > JoinResponse > ICEServer(字段1>5/9)中传输ICE服务器信息。使用完整的google.golang.org/protobuf库过于臃肿,因此编写了一个仅40行的最小化解析器。

Google AdInline article slot

Varint解码:

func pbVar(d []byte, o int) (uint64, int) {
    var v uint64
    for s := 0; o < len(d) && s < 64; s += 7 {
        b := d[o]; o++
        v |= uint64(b&0x7f) << s
        if b < 0x80 { return v, o }
    }
    return 0, o
}

提取长度分隔字段:

func pbAll(d []byte, f uint64) (r [][]byte) {
    for o := 0; o < len(d); {
        t, n := pbVar(d, o)
        if n == o { break }
        o = n
        switch t & 7 {
        case 2:
            l, n := pbVar(d, o); o = n
            e := o + int(l)
            if e > len(d) || e < o { return }
            if t>>3 == f { r = append(r, d[o:e]) }
            o = e
        // ...
        }
    }
    return
}

解析器在字段5(WB分支)和字段9(标准版本)中搜索ICE服务器,提取url、username和credential。

Google AdInline article slot

隧道架构:KCP + TURN + yamux

TCP从SOCKS5 → yamux流 → KCP(AES-256加密) → TURN中继 → VPS → 互联网。

关键组件:

  • TURN分配:通过pion/turn实现,tc.Allocate()返回net.PacketConn
  • 基于中继的KCPkcp.NewConn(peerVPS, blk, 10, 3, relay)
  • Yamux用于流多路复用。
  • VPS上的SOCKS5服务器
uc, _ := net.ListenUDP("udp", nil)
tc, _ := turn.NewClient(&turn.ClientConfig{...})
relay, _ := tc.Allocate()
kc, _ := kcp.NewConn(peerVPS, blk, 10, 3, relay)

服务器端:KCP监听器 + yamux服务器 + SOCKS5。

自动化与容错机制

  • 智能密钥:base64(IP|SHA256(password))。
  • 重连机制:yamux每15秒ping一次,退避时间2-60秒,TURN凭据缓存5分钟。
  • 自清理功能pgrep + 终止先前实例,覆盖systemd配置。
  • 优雅关闭:Ctrl+C → 2秒清理时间。

启动与限制

go build -o lionheart .
# 服务器端
./lionheart  # 复制密钥
# 客户端
./lionheart  # 粘贴密钥 → 127.0.0.1:1080

限制:依赖WB Stream API,硬编码wbstream01-el.wb.ru。未来计划:使用gomobile适配Android/iOS(VpnService/NEPacketTunnelProvider)。

核心要点

  • 以WebRTC流量伪装,应对DPI/防火墙,支持千兆速度。
  • 无依赖的最小化protobuf解析器。
  • TURN中继作为net.PacketConn用于KCP。
  • 全自动化,无需浏览器或API密钥。
  • 纯Go实现,支持gomobile。

— Editorial Team

Advertisement 728x90

继续阅读