一、目标
frida玩了很久,andriod和ios下都玩的不错。不过飞哥其实是混windows出道的,那frida能不能分析winPE呢?
今天介绍下Windows下的玩法,要点如下:
- Hook Windows Api
- 修改参数和返回值
- 主动调用Windows Api
二、步骤
打开心爱的MFC
写个demo小程序,密码是 1234 ,输入正确提示 "密码正确"。
Hook MessageBoxA
var pMessageBoxA = Module.findExportByName("user32.dll", 'MessageBoxA')
Interceptor.attach(pMessageBoxA, {
onEnter: function (args, state) {
console.log("[+] MessageBoxA");
console.log("¦- hWnd: " + args[0]);
console.log("¦- lpText: " + Memory.readAnsiString(args[1]));
console.log("¦- lpCaption: " + Memory.readAnsiString(args[2]));
console.log("¦- uType: " + args[3] + "\n");
},
onLeave: function (retval, state) {
}
});
迫不及待了,好久没有玩windows,跑一下,我们输入 "1234"

修改入参和返回值
console.log("[!] Hooking lpText: 真的对吗");
this.lpText = Memory.allocAnsiString("真的对吗"); // Allocate new heap ANSI string
args[1] = this.lpText; // Replace lpText pointer
在跑一下,真的对吗?

修改返回值就比较简单了,这个例子修改返回值也没啥用。
console.log("retval: " + retval.toInt32());
retval.replace(0);
console.log("retval modify: " + retval.toInt32());
主动调用Windows Api
我们来试试如何主动调用 MessageBox,首先按照函数原型,创建对应的 NativeFunction 函数,然后创建好入参,就可以调用了。
var pMessageBoxW = Module.findExportByName("user32.dll", 'MessageBoxA')
var lpText = Memory.allocAnsiString("I'm New MessageBox");
var funMsgBox = new NativeFunction(pMessageBoxW, 'uint32',['uint32','pointer','pointer','uint32']);
// 调用
funMsgBox(0,ptr(lpText),ptr(lpText),0);
完美搞定~

启动命令
最后说一下启动的命令,因为一开始我也犯难,习惯了启动Android和Ios App了,不知道如何启动 winPE了。
frida C:\Users\35085\Desktop\demo\fridawin.exe -l nt.js --no-pause // spawn 模式
frida *fridawin* -l nt.js // attach模式
其实都差不多,跨平台工具的好处是,经验可以复用。
三、总结
Windows其实更好玩,只是时代变了,不过就像《神鞭》里说的, 辫子剪了,神留着,一变还是绝活
frida里面的数据类型和各个平台下的类型对应关系要熟练掌握。

朕岂可亲系草鞋之绳

关注微信公众号,最新技术干货实时推送
