forked from Simplxss/QQNTPCHOOKTOOL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mlikiowa.py
167 lines (149 loc) · 5.61 KB
/
mlikiowa.py
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
import frida
import sys
import json
import struct
def on_message(message, data):
# print(message)
try:
j = json.loads(message["payload"])
t = j["type"]
if t == "tea_encrypt":
o = {
"mode": "tea",
"enc": True,
"data": j["data"],
"result": j["result"],
"key": j["key"],
}
print(json.dumps(o))
try:
b = bytes.fromhex(j["data"])
headLen = struct.unpack("!i", b[:4])[0]
seq = struct.unpack("!i", b[4:8])[0]
appid = struct.unpack("!i", b[8:12])[0]
localId = struct.unpack("!i", b[12:16])[0]
# struct.unpack("!i!i!i", b[16:28])
l1 = struct.unpack("!i", b[28:32])[0] - 4
tgt = b[32 : 32 + l1]
l2 = struct.unpack("!i", b[32 + l1 : 36 + l1])[0] - 4
cmd = b[36 + l1 : 36 + l1 + l2].decode("utf-8")
l3 = struct.unpack("!i", b[36 + l1 + l2 : 40 + l1 + l2])[0] - 4
msgCookie = b[40 + l1 + l2 : 40 + l1 + l2 + l3]
l4 = struct.unpack("!i", b[40 + l1 + l2 + l3 : 44 + l1 + l2 + l3])[0] - 4
guid = b[44 + l1 + l2 + l3 : 44 + l1 + l2 + l3 + l4].decode("utf-8")
# struct.unpack("!i", b[44 + l1 + l2 + l3 + l4 : 47 + l1 + l2 + l3 + l4]) - 4
l5 = (
struct.unpack("!h", b[48 + l1 + l2 + l3 + l4 : 50 + l1 + l2 + l3 + l4])[
0
]
- 2
)
rVersion = b[50 + l1 + l2 + l3 + l4 : 50 + l1 + l2 + l3 + l4 + l5].decode(
"utf-8"
)
l6 = (
struct.unpack(
"!i", b[50 + l1 + l2 + l3 + l4 + l5 : 54 + l1 + l2 + l3 + l4 + l5]
)[0]
- 4
)
signature = b[
54 + l1 + l2 + l3 + l4 + l5 : 54 + l1 + l2 + l3 + l4 + l5 + l6
]
# bodyLen = (
# struct.unpack(
# "!i", b[54 + l1 + l2 + l3 + l4 + l5 + l6 : 58 + l1 + l2 + l3 + l4 + l5 + l6]
# )[0]
# - 4
# )
# body = b[
# 58 + l1 + l2 + l3 + l4 + l5 + l6 : 58 + l1 + l2 + l3 + l4 + l5 + l6 + bodyLen
# ]
body = b[headLen:]
if cmd =='':
raise Exception('cmd is empty')
o = {
"msgCookie": msgCookie.hex(),
"buffer": body.hex(),
"cmd": cmd,
"seq": seq,
"uin": "10001",
"mode": "send",
"type": "unknown",
"source": 0,
}
print(json.dumps(o))
except:
pass
elif t == "tea_decrypt":
o = {
"mode": "tea",
"enc": False,
"data": j["data"],
"result": j["result"],
"key": j["key"],
}
print(json.dumps(o))
try:
b = bytes.fromhex(j["result"])
headLen = struct.unpack("!i", b[:4])[0]
seq = struct.unpack("!i", b[4:8])[0]
retCode = struct.unpack("!i", b[8:12])[0]
l1 = struct.unpack("!i", b[12:16])[0] - 4
extra = b[16 : 16 + l1].decode("utf-8")
l2 = struct.unpack("!i", b[16 + l1 : 20 + l1])[0] - 4
cmd = b[20 + l1 : 20 + l1 + l2].decode("utf-8")
l3 = struct.unpack("!i", b[20 + l1 + l2 : 24 + l1 + l2])[0] - 4
msgCookie = b[24 + l1 + l2 : 24 + l1 + l2 + l3]
isCompress = struct.unpack("!i", b[24 + l1 + l2 + l3 : 28 + l1 + l2 + l3])[
0
]
body = b[headLen:]
if cmd =='':
raise Exception('cmd is empty')
o = {
"msgCookie": msgCookie.hex(),
"buffer": body.hex(),
"cmd": cmd,
"seq": seq,
"uin": "10001",
"mode": "receive",
"type": "unknown",
"source": 0,
}
print(json.dumps(o))
except:
pass
elif t == "aes_encrypt":
o = {
"mode": "aes",
"enc": True,
"data": j["data"],
"result": j["result"] + " " + j["tag"],
"key": j["key"] + " " + j["iv"],
}
print(json.dumps(o))
elif t == "aes_decrypt":
o = {
"mode": "aes",
"enc": False,
"data": j["data"] + " " + j["tag"],
"result": j["result"],
"key": j["key"] + " " + j["iv"],
}
print(json.dumps(o))
except:
print(message)
def main():
# pid = frida.spawn(program="/usr/bin/qq", argv=["--no-sandbox"])
pid = frida.spawn(program="D:\\AppD\\QQNT\\QQ.exe", argv=["--enable-logging"])
session = frida.attach(pid)
frida.resume(pid)
while True:
with open("hooktea.js", encoding="utf-8") as f:
script = session.create_script(f.read())
script.on("message", on_message)
script.load()
sys.stdin.readline()
if __name__ == "__main__":
main()