前言

现如今在直播系统定制开发中直播间协议很多已经很少使用http轮询的方式获取直播间的弹幕、礼物、关注等,在用的目前知道的是某音的直播,其他的一些app已经使用socket或者websoceket获取直播间的弹幕等,本次主要针对websocket提供协议破解思路。 设备:小米note8、windows 案例:具体不提供,仅提供破解思路。

抓包分析

本次抓包使用的Charles进行抓包websocket,Charles配置简单,抓包方便。 直播系统定制开发中安卓直播间websocket协议破解还原_抓包 打开该app的直播间,在Charles中可以很清晰的看到,在直播系统定制开发中websocket发送的数据以及接受的推送信息。

ws://chat.**.com:3185
复制代码

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

脱壳分析定位

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

定位关键位置

在直播系统定制开发中通过抓包的关键词​​ctor.entryHandler.enter​​​在该app定位。 直播系统定制开发中安卓直播间websocket协议破解还原_数据_02 这个sdk就告诉我们所有了,​​​com.netease.pomelo​​,通过相关资料

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

根据网易github,​​github.com/netease/pom…​​​ 相关资料,其使用​​socket.io​​​进行发包,并且在logcat中可以很清晰的看到相关发送数据的日志。 直播系统定制开发中安卓直播间websocket协议破解还原_json_03 但是在该数据包中直接发现有乱码,那就只能找该数据包的原始字节。 进一步的hook分析,定位到如下图位置。 直播系统定制开发中安卓直播间websocket协议破解还原_抓包_04直播系统定制开发中安卓直播间websocket协议破解还原_json_05 通过frida进行hook打印该类,默认调用​​​tostring​​方法

var FramedataImpl1 = Java.use("org.java_websocket.framing.FramedataImpl1")
FramedataImpl1.b.overload('boolean').implementation = function (q1) {
this.b(q1)
console.log(this)
}
复制代码

直播系统定制开发中安卓直播间websocket协议破解还原_json_06 得出如下字节数组

//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, 58​​​是​​2::​​,那些乱码的字符,也就是对应的后半部分的字节,其中包括了发包的顺序,从0-9等。

还原协议

在直播系统定制开发中使用python的​​websocket-client​​​,进行还原直播间的协议通讯。 关于上述的字节,可以在java中使用base64进行编码,然后python中进行解码使用。 直播系统定制开发中安卓直播间websocket协议破解还原_数据_07

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将其发送的数据以字节的形式拿到,在通过对比发送字节的不同,构造其发送的数据,最后完成协议还原。