当前位置:网站首页>【frida实战】“一行”代码教你获取WeGame平台中所有的lua脚本
【frida实战】“一行”代码教你获取WeGame平台中所有的lua脚本
2022-07-07 06:58:00 【夜猫逐梦】
文章目录
导读
开发环境
| 版本号 | 描述 | |
|---|---|---|
| 操作系统 | Win11-21H2 | 内部版本号22000.588 |
| Python | Python3.7.1 | |
| frida.exe | 15.0.18 | |
预备知识
luaL_loadbuffer
函数原型(https://www.lua.org/manual/5.1/manual.html#luaL_loadbuffer):
int luaL_loadbuffer (lua_State *L, // Lua句柄
const char *buff, // lua脚本
size_t sz, // lua脚本字节数
const char *name); // 标记(通过分析可以发现这里是文件名)
将缓冲区加载为 Lua 块。此函数用于加载lua_load指向的缓冲区中的块。 name是块名称,用于调试信息和错误消息。
WeGame中使用的是Lua51.dll,它导出了两个函数luaL_loadbuffer和luaL_loadbufferx,通过IDA分析可以猜测,luaL_loadbufferx只是比luaL_loadbuffer多了个参数a5,其他参数都是一样的。
frida拦截器Interceptor
frida的Interceptor模块中,attach函数原型为Interceptor.attach(target, callbacks[, data]),实现了对参数target进行hook的操作,下面是简单的参数分析:
target:这是一个 NativePointer,指定您想要拦截调用的函数的地址。我们可以通过Module.getExportByName()来获取可执行文件的导出函数作为该参数,frida会自动处理。callbacks:顾名思义,这是hook的回调函数集合,里面包含了hook前和hook后两个回调函数。onEnter(args):该回调函数的参数args为hook函数的参数数组,每个参数都是一个NativePointer对象,我们可以在这里获取参数信息,或者篡改参数内容。onLeave(retval):该调用是执行完目标函数后的处理,参数retval是一个NativePointer对象,是目标函数的返回值,我们可以修改该指针内容达到hook的目的。
data:可选参数,暂时忽略掉。
示例:
Interceptor.attach(Module.getExportByName('libc.so', 'read'), {
onEnter(args) {
this.fileDescriptor = args[0].toInt32();
// this上下文信息:包含寄存器信息context、返回值地址returnAddress、线程ID threadId等
console.log('Context information:');
console.log('Context : ' + JSON.stringify(this.context));
console.log('Return : ' + this.returnAddress);
console.log('ThreadId : ' + this.threadId);
console.log('Depth : ' + this.depth);
console.log('Errornr : ' + this.err);
},
onLeave(retval) {
if (retval.toInt32() > 0) {
/* do something with this.fileDescriptor */
}
}
});
ps: callbacks是一个对象,frida实现中,会在初始化的时候,给该对象填充
上下文信息信息,这也就是为什么示例中的this可以访问context、returnAddress、threadId这些内容。
ps2: 之前一直纠结
onEnter中生成的变量,怎么在onLeave中使用,其实直接通过this就可以了this.tempVal=333;。这都是对js的基础理解和应用。
NativeFunction创建目录
frida调用dll函数,通过NativeFunction创建一个函数对象,设置响应的参数和返回值。
本文使用的是WinExec函数调用了cmd命令中的mkdir指令来实现创建目录,具体实现看下面的代码。
ps: 也可以使用c函数中的
system,其原型如下:
分析思路
挂起启动WeGame
为了保证hook所有的lua,需要挂起启动WeGame,使用命令frida -f 应用程序全路径即可挂起启动目标进程,命令行示例:
D:\Python\Python371\Scripts\frida.exe -f "G:\Program Files (x86)\WeGame\wegame.exe"
WeGame需要管理员权限启动,否则会报0x000002e4的启动失败错误。
hook函数luaL_loadbufferx保存所有js
var fnWinExec = new NativeFunction(
Module.findExportByName('Kernel32.dll', 'WinExec'),
'int',
['pointer', 'int'],
'stdcall'
);
function ez_fnWinExec(jsStr) {
console.log( 'ez_fnWinExec: ', jsStr );
var cStrPointer = Memory.allocUtf8String(jsStr);
fnWinExec(cStrPointer, 0);
}
Interceptor.attach(Module.getExportByName('Lua51.dll', 'luaL_loadbufferx'), {
onEnter(args) {
// 不可以使用数组解构赋值!!!
// var [_,a,b]=[0,1,3]
// var [L, buff, sz, name] = args;
var buff = args[1];
var sz = args[2];
var name = args[3];
console.log( name.readCString(), sz.toInt32(), buff );
// 过滤非lua文件
if (!name.readCString().endsWith('.lua')){
return;
}
var pth = 'D:\\_TMP\\wegame\\' + name.readCString();
// 创建文件夹
var dir_ = pth.substr(0, pth.lastIndexOf('\\')+1);
ez_fnWinExec('cmd.exe /c mkdir '+ dir_);
// 保存文件
var f = new File(pth, 'wb');
var data = buff.readByteArray(sz.toInt32());
f.write(data);
f.close();
},
onLeave(retval) {
}
});
一开始想的是不需要调用函数
WinExec,优化一下可以写成“一行”代码的,后来发现多级目录,得自己创建目录,又加上了一堆的代码。。。
所以,就不再是“一行”代码实现了。
参考资料
- [frida] 00_简单介绍和使用 https://blog.csdn.net/kinghzking/article/details/123225580
- Lua游戏逆向及破解方法介绍 https://blog.csdn.net/liujiayu2/article/details/81942010
- qq群:夜猫逐梦技术交流裙/953949723

**ps:**文章中内容仅用于技术交流,请勿用于违规违法行为。
边栏推荐
- Some pit avoidance guidelines for using Huawei ECS
- The configuration and options of save actions are explained in detail, and you won't be confused after reading it
- flex弹性布局
- # Arthas 简单使用说明
- SAP MM STO单据的外向交货单创建后新加ITEM?
- IIS redirection redirection appears eurl axd
- In fact, it's very simple. It teaches you to easily realize the cool data visualization big screen
- Redis common commands
- Jenkins+ant+jmeter use
- Huawei HCIP - datacom - Core 03 jours
猜你喜欢

正则匹配以XXX开头的,XXX结束的

Mysql database lock learning notes

JS逆向教程第一发

# Arthas 简单使用说明

網易雲微信小程序
![Pytest+request+allure+excel interface automatic construction from 0 to 1 [familiar with framework structure]](/img/33/9fde4bce4866b988dd2393a665a48c.jpg)
Pytest+request+allure+excel interface automatic construction from 0 to 1 [familiar with framework structure]

四、机器学习基础

Variable parameter of variable length function

【BW16 应用篇】安信可BW16模组/开发板AT指令实现MQTT通讯

STM32 and motor development (from stand-alone version to Networking)
随机推荐
Serializer & modelserializer of DRF serialization and deserialization
Jenkins task grouping
How to use clipboard JS library implements copy and cut function
超十万字_超详细SSM整合实践_手动实现权限管理
细说Mysql MVCC多版本控制
Install pyqt5 and Matplotlib module
华为HCIP-DATACOM-Core_03day
Unity shader (basic concept)
Using JWT to realize login function
Difference between interface iterator and iteratable
Information Security Experiment 4: implementation of IP packet monitoring program
Create an int type array with a length of 6. The values of the array elements are required to be between 1-30 and are assigned randomly. At the same time, the values of the required elements are diffe
Pytest installation (command line installation)
Mysql database index study notes
JS inheritance prototype
(3/8) method parameters of improper use of enumeration (2)
Binary tree high frequency question type
Loxodonframework quick start
H5网页播放器EasyPlayer.js如何实现直播视频实时录像?
嵌套(多级)childrn路由,query参数,命名路由,replace属性,路由的props配置,路由的params参数