0%

Js逆向之wasm

hello 大家好我是Monday,今天给大家带来篇Js逆向之wasm的文章。。

引言

wasm是什么 先看下 官网 给的定义。

WebAssembly (abbreviated Wasm) is a binary instruction format for a stack-based virtual machine. Wasm is designed as a portable compilation target for programming languages, enabling deployment on the web for client and server applications.

WebAssembly 是基于栈式虚拟机的二进制指令集,可以作为编程语言的编译目标,能够部署在 web 客户端和服务端的应用中。

网站:

1
aHR0cHM6Ly9tYXRjaC55dWFucmVueHVlLmNvbS9tYXRjaC8xNQ==

抓包分析与加密定位

分析的目的:

所以先开抓包分析此网站 请求只有一个参数m

分析js 的堆栈

找到如下函数

这里就引出了window.q这个函数

打上断点再点击翻页可以断在window.q

我们跟进去看看这里window.q的逻辑

分析可知,这段js 代码,大概来自wasm文件,抓包分析时。我们可以下载这个文件代码如下

1
2
3
4
url = "https://match.yuanrenxue.com/static/match/match15/main.wasm"
response = requests.get(url).content
with open("./Wasm.wasm", 'wb') as fp:
fp.write(response)

我们可以使用现成的 python 第三方包pywasm

安装

1
pip install pywasm

官网使用案例:

1
2
3
4
5
6
import pywasm
# pywasm.on_debug()

runtime = pywasm.load('./examples/fib.wasm')
r = runtime.exec('fib', [10])
print(r) # 55

根据分析js文件 window.q(t1, t2).toString() ,相当于我们加载这个wasm文件后,传入t1 和t2 时间参数就可得到

具体代码如下

1
2
3
4
5
6
7
def get_m():
t = int(time.time())
t1 = int(t / 2) # t1 = parseInt(Date.parse(newDate()) / 1000 / 2);
t2 = int(t / 2 - math.floor(random.random() * 50 + 1)) # t2 = parseInt(Date.parse(newDate()) / 1000 / 2 - Math.floor(Math.random() * (50) + 1));
wasm_vm = pywasm.load("./Wasm.wasm")
m = wasm_vm.exec("encode", [t1, t2]) # window.q(t1, t2)
return str(m) + '|' + str(t1) + '|' + str(t2) # window.q(t1, t2).toString() + '|' + t1 + '|' + t2;

完整代码如下:

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
import requests

import math
import random
import time
import pywasm


def get_wasm():
url = "https://match.yuanrenxue.com/static/match/match15/main.wasm"
response = requests.get(url).content
with open("./Wasm.wasm", 'wb') as fp:
fp.write(response)


def get_m():
t = int(time.time())
t1 = int(t / 2) # t1 = parseInt(Date.parse(newDate()) / 1000 / 2);
t2 = int(t / 2 - math.floor(random.random() * 50 + 1)) # t2 = parseInt(Date.parse(newDate()) / 1000 / 2 - Math.floor(Math.random() * (50) + 1));
wasm_vm = pywasm.load("./Wasm.wasm")
m = wasm_vm.exec("encode", [t1, t2]) # window.q(t1, t2)
return str(m) + '|' + str(t1) + '|' + str(t2) # window.q(t1, t2).toString() + '|' + t1 + '|' + t2;


headers = {
#xxx
}
cookies = {
#xxx
}
url = "https://match.yuanrenxue.com/api/match/15"
get_wasm()
params = {
"m": get_m(),
"page": "1"
}
response = requests.get(url, headers=headers, cookies=cookies, params=params)

print(response.text)
print(response)

得到结果如下:

1
{"status": "1", "state": "success", "data": [{"value": 2086}, {"value": 9613}, {"value": 8563}, {"value": 9659}, {"value": 7656}, {"value": 4363}, {"value": 8892}, {"value": 3371}, {"value": 1335}, {"value": 3312}]}

结束语

​ 今天的分享就到这里了,欢迎大家关注微信公众号”菜鸟童靴