回答

收藏

安卓直播间websocket协议破解还原

信息分享 信息分享 1055 人阅读 | 0 人回复 | 2021-05-29

前言
现如今直播间协议很多已经很少使用http轮询的方式获取直播间的弹幕、礼物、关注等,在用的目前知道的是某音的直播,其他的一些app已经使用socket或者websoceket获取直播间的弹幕等,本次主要针对websocket提供协议破解思路。
设备:小米note8、windows
案例:具体不提供,仅提供破解思路。
抓包分析
本次抓包使用的Charles进行抓包websocket,Charles配置简单,抓包方便。打开该app的直播间,在Charles中可以很清晰的看到,websocket发送的数据以及接受的推送信息。
  1. ws://chat.**.com:3185
复制代码
  1. ws://
复制代码
也就是该websocket的明显特征,除过
  1. ws://
复制代码
还有
  1. wss://
复制代码
,而
  1. wss
复制代码
是对应
  1. ws
复制代码
的加密版本,类似
  1. http
复制代码
  1. https
复制代码
的关系。
脱壳分析定位
该app是经过加壳的,这里使用youpk进行脱壳,具体流程可看github,https://github.com/Youlor/Youpk
定位关键位置
通过抓包的关键词
  1. ctor.entryHandler.enter
复制代码
在该app定位。这个sdk就告诉我们所有了,
  1. com.netease.pomelo
复制代码
,通过相关资料
  1. pomelo是网易12年底出品的一个基于node.js的游戏服务器框架,其设计初衷是游戏服务器, 不过在设计、开发完成后发现pomelo是个通用的分布式实时应用开发框架。
复制代码
根据网易github,https://github.com/netease/pomelo-androidclient 相关资料,其使用
  1. socket.io
复制代码
进行发包,并且在logcat中可以很清晰的看到相关发送数据的日志。但是在该数据包中直接发现有乱码,那就只能找该数据包的原始字节。
进一步的hook分析,定位到如下图位置。通过frida进行hook打印该类,默认调用
  1. tostring
复制代码
方法
  1. var FramedataImpl1 = Java.use("org.java_websocket.framing.FramedataImpl1")
  2. FramedataImpl1.b.overload('boolean').implementation = function (q1) {
  3. this.b(q1)
  4. console.log(this)
  5. }
复制代码
得出如下字节数组
  1. //51, 58, 58, 58, 0, 0, 0, 1, 31,
  2. //51, 58, 58, 58, 0, 0, 0, 2, 28,
  3. //51, 58, 58, 58, 0, 0, 0, 3, 35,
  4. //51, 58, 58, 58, 0, 0, 0, 4, 32,
  5. //51, 58, 58, 58, 0, 0, 0, 5, 32,
  6. //50, 58, 58
复制代码
剩下就是发现规律,包的顺序以及发那些包,其中
  1. 51, 58, 58, 58,
复制代码
就是
  1. 3:::
复制代码
,
  1. 50, 58, 58
复制代码
  1. 2::
复制代码
,那些乱码的字符,也就是对应的后半部分的字节,其中包括了发包的顺序,从0-9等。
还原协议
使用python的
  1. websocket-client
复制代码
,进行还原直播间的协议通讯。
关于上述的字节,可以在java中使用base64进行编码,然后python中进行解码使用。
  1. def send_msg(ws):
  2. a = base64.b64decode('Mzo6OgAAAAEf')
  3. enter = {"sid": "", "rid": str(room_id), "userid": "0",
  4. "brand": "Redmi Note 8", "cores": 8, "memory": 5638, "screen": 1080, "trid": 666, "re_enter": 1,
  5. "true_ip": "210*12*195*3", "sktime": 1622114102, "sign": sign,
  6. "version_code": 507,
  7. "is_intl_pack": "0", "channel": "9700288", "client_code_version": "23", "client_side": 2, "sys_sdk": 29,
  8. "country_code": "CN", "pkg_channel": "9700288", "is_market": "1", "timestamp": 1622114101589}
  9. ws.send(a + bytes('sioconnector.entryHandler.enter' + json.dumps(enter), encoding='utf8'))
  10. b = base64.b64decode('Mzo6OgAAAAIc')
  11. ws.send(b + bytes('chat.chatHandler.getTopThree' + json.dumps({"timestamp": 1622113988470}), encoding='utf8'))
  12. c = base64.b64decode('Mzo6OgAAAAMj')
  13. ws.send(c + bytes('chat.chatHandler.checkUserStatusMix' + json.dumps({"uid": "0", "timestamp": 1622113988484}),
  14. encoding='utf8'))
  15. d = base64.b64decode('Mzo6OgAAAAQg')
  16. ws.send(d + bytes('chat.chatHandler.getAnchorCdnMix' + json.dumps({"timestamp": 1622113988496}),
  17. encoding='utf8'))
  18. e = base64.b64decode('Mzo6OgAAAAcg')
  19. ws.send(e + bytes('chat.chatHandler.getGuardinfo' + json.dumps({"timestamp": 1622113988496}),
  20. encoding='utf8'))
  21. f = base64.b64decode('Mzo6OgAAAAYd')
  22. ws.send(f + bytes('chat.chatHandler.onlineGoldPhone' + json.dumps({"timestamp": 1622113988496}),
  23. encoding='utf8'))
  24. while 1:
  25. ws.send(b'2::')
  26. sleep(1)
  27. def on_open(ws):
  28. print('on_open', ws)
  29. threading.Thread(target=send_msg, args=(ws,)).start()
  30. def on_message(ws, message):
  31. print(message)
  32. message = message[len('3:::'):]
  33. print('on_message', message)
  34. def on_close(ws, close_status_code, close_reason):
  35. print('on_close', ws, close_status_code, close_reason)
  36. def start_websocket(chat_url, token):
  37. # websocket.enableTrace(True)
  38. ws = websocket.WebSocketApp(
  39. f"ws://{chat_url}/socket.io/1/websocket/{token}",
  40. on_message=on_message,
  41. on_open=on_open,
  42. on_close=on_close
  43. )
  44. ws.run_forever()
复制代码
小结
该直播app的直播间协议,在获取弹幕过程中,有部分数据是乱码形式,这部分就可以使用hook将其发送的数据以字节的形式拿到,在通过对比发送字节的不同,构造其发送的数据,最后完成协议还原。



分享到:
回复

使用道具 举报