直播间websocket协议破解还原

前言

现如今直播间协议很多已经很少使用http轮询的方式获取直播间的弹幕、礼物、关注等,在用的目前知道的是某音的直播,其他的一些app已经使用socket或者websoceket获取直播间的弹幕等,本次主要针对websocket提供协议破解思路。
 

抓包分析

本次抓包使用的Charles+postern进行抓包websocket,Charles配置简单,抓包方便。
 

file


打开该app的直播间,在Charles中可以很清晰的看到,websocket发送的数据以及接受的推送信息。

1

ws://chat.**.com:3185

ws://也就是该websocket的明显特征,除过ws://还有wss://,而wss是对应ws的加密版本,类似httphttps的关系。

脱壳分析定位

该app是经过加壳的,这里使用youpk进行脱壳,具体流程可看github,https://github.com/Youlor/Youpk

定位关键位置

通过抓包的关键词ctor.entryHandler.enter在该app定位。
 

file


这个sdk就告诉我们所有了,com.netease.pomelo,通过相关资料

1

pomelo是网易12年底出品的一个基于node.js的游戏服务器框架,其设计初衷是游戏服务器, 不过在设计、开发完成后发现pomelo是个通用的分布式实时应用开发框架。

根据网易github,https://github.com/netease/pomelo-androidclient 相关资料,其使用socket.io进行发包,并且在logcat中可以很清晰的看到相关发送数据的日志。
 

file


但是在该数据包中直接发现有乱码,那就只能找该数据包的原始字节。
进一步的hook分析,定位到如下图位置。
 

file


 

file


通过frida进行hook打印该类,默认调用tostring方法

1

2

3

4

5

var FramedataImpl1 = Java.use("org.java_websocket.framing.FramedataImpl1")

   FramedataImpl1.b.overload('boolean').implementation = function (q1) {

       this.b(q1)

       console.log(this)

   }

file


得出如下字节数组

1

2

3

4

5

6

//51, 58, 58, 58, 0, 0, 0, 1, 31,

//51, 58, 58, 58, 0, 0, 0, 2, 28,

//51, 58, 58, 58, 0, 0, 0, 3, 35,

//51, 58, 58, 58, 0, 0, 0, 4, 32,

//51, 58, 58, 58, 0, 0, 0, 5, 32,

//50, 58, 58

剩下就是发现规律,包的顺序以及发那些包,其中
51, 58, 58, 58,就是3:::,50, 58, 582::,那些乱码的字符,也就是对应的后半部分的字节,其中包括了发包的顺序,从0-9等。

还原协议

使用python的websocket-client,进行还原直播间的协议通讯。
关于上述的字节,可以在java中使用base64进行编码,然后python中进行解码使用。

file

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

def send_msg(ws):

    a = base64.b64decode('Mzo6OgAAAAEf')

    enter = {"sid": "", "rid": str(room_id), "userid": "0",

             "brand": "Redmi Note 8", "cores": 8, "memory": 5638, "screen": 1080, "trid": 666, "re_enter": 1,

             "true_ip": "210*12*195*3", "sktime": 1622114102, "sign": sign,

             "version_code": 507,

             "is_intl_pack": "0", "channel": "9700288", "client_code_version": "23", "client_side": 2, "sys_sdk": 29,

             "country_code": "CN", "pkg_channel": "9700288", "is_market": "1", "timestamp": 1622114101589}

    ws.send(a + bytes('sioconnector.entryHandler.enter' + json.dumps(enter), encoding='utf8'))

    b = base64.b64decode('Mzo6OgAAAAIc')

    ws.send(b + bytes('chat.chatHandler.getTopThree' + json.dumps({"timestamp": 1622113988470}), encoding='utf8'))

    c = base64.b64decode('Mzo6OgAAAAMj')

    ws.send(c + bytes('chat.chatHandler.checkUserStatusMix' + json.dumps({"uid": "0", "timestamp": 1622113988484}),

                      encoding='utf8'))

    d = base64.b64decode('Mzo6OgAAAAQg')

    ws.send(d + bytes('chat.chatHandler.getAnchorCdnMix' + json.dumps({"timestamp": 1622113988496}),

                      encoding='utf8'))

    e = base64.b64decode('Mzo6OgAAAAcg')

    ws.send(e + bytes('chat.chatHandler.getGuardinfo' + json.dumps({"timestamp": 1622113988496}),

                      encoding='utf8'))

    f = base64.b64decode('Mzo6OgAAAAYd')

    ws.send(f + bytes('chat.chatHandler.onlineGoldPhone' + json.dumps({"timestamp": 1622113988496}),

                      encoding='utf8'))

    while 1:

        ws.send(b'2::')

        sleep(1)

def on_open(ws):

    print('on_open', ws)

    threading.Thread(target=send_msg, args=(ws,)).start()

def on_message(ws, message):

    print(message)

    message = message[len('3:::'):]

    print('on_message', message)

def on_close(ws, close_status_code, close_reason):

    print('on_close', ws, close_status_code, close_reason)

def start_websocket(chat_url, token):

    # websocket.enableTrace(True)

    ws = websocket.WebSocketApp(

        f"ws://{chat_url}/socket.io/1/websocket/{token}",

        on_message=on_message,

        on_open=on_open,

        on_close=on_close

    )

    ws.run_forever()

小结

该直播app的直播间协议,在获取弹幕过程中,有部分数据是乱码形式,这部分就可以使用hook将其发送的数据以字节的形式拿到,在通过对比发送字节的不同,构造其发送的数据,最后完成协议还原。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值