dryzh 发表于 2022-11-30 10:06:44

这是一个 Frida V(伪)EH 示例(更新 x64 执行异常代码)

本帖最后由 dryzh 于 2023-1-14 21:07 编辑

好久没有发技术贴了,看到好多,表哥大大们都喜欢 VEH,小弟不才,一直学了好久的 frida,没学废。最近闲着蛋疼没事就研究了一下 frida 怎么 VEH。现在分享出来,抛转引玉器!
好了废话不多说,因为太简单了,没什么话可以说,直接上代码。
Talk is cheap. Show you My code.


顺便说一句,丢掉调试器,丢掉各种Loader各种Patcher吧,一个 frida 的 js 脚本就能干翻一切。
大佬们可以自己实现下 x64 下的代码(尝试下试硬件断点的方式,尝试下 VMP,TEP,WL,SE各种壳的替换机器码)

2023.1.14更正个概念问题,免得误导大家(学院派),我原来看到Process.setExceptionHandler这个接口函数名,认为是基于进程的VEH,有大佬说 frida 的底层实现应该还是属于 SEH 的。VEH 的 V 代表向量意思(向量化异常vectored exception handle),通常VEH是以双向链表的形式保存在堆里面。修改下 frida 源码让他变真的 V 也不是不可能。另外,本来想研究下硬件执行断点的,发现接口也没有提供 DRx 寄存器,所以就只能更新个 x64 的执行异常了(内存的,非硬件执行断点异常),仅供交流娱乐,高手勿喷(标题也文字游戏处理了一下,姑且叫做伪VEH 吧,效果至少像 VEH)。


python3 安装 frida


pip3 install frida frida-tools -i https://pypi.tuna.tsinghua.edu.cn/simple

然后把这个 js 放 exe 同级目录,在目录下 cmd 或者 PS运行下面命令就行

frida -f 010Editor.exe -l ./frida-veh-010-bs.js



//"use strict"
console.log("\n");
console.warn("Frida.version = " + Frida.version);
console.log("Frida.heapSize = " + Frida.heapSize);
console.warn("Process.arch = " + Process.arch);
console.warn("Process.platform = " + Process.platform);
console.log("Process.pointerSize = " + Process.pointerSize);
console.log("\n");
console.error(" 这是一个 Frida VEH 010 Editor 的牛逼示例")
console.error(" pip3 install frida frida-tools -i https://pypi.tuna.tsinghua.edu.cn/simple ");
console.error(" frida -f 010Editor.exe -l ./frida-veh-010-bs.js --no-pause ");
//
if (Process.platform == "windows" && Process.arch == "x64") {
    console.warn("\n", "Coming soon :) ", "\n");
} else if (Process.platform == "windows" && Process.arch == "ia32") {
    //
    var editor = Process.findModuleByName("010Editor.exe");
    console.log("010 editor base: ", editor.base, typeof (editor.base));
    var sub_patchaddr = editor.base.add(0x31f7fa);
    console.log("010 editor VA: ", sub_patchaddr, typeof (sub_patchaddr));
    var buf = Memory.readByteArray(sub_patchaddr, 16);
    const cc_origin = Memory.readU8(sub_patchaddr);
    console.log("cc_origin: ", cc_origin, typeof (cc_origin));
    console.log(hexdump(sub_patchaddr, { offset: 0, length: 32, header: true, ansi: true }));
    // VEH
    Process.setExceptionHandler(function (details) {
      console.log("\n", "setExceptionHandler ==> address: ", details.address);
      console.error(JSON.stringify(details));
      console.warn("RVA: ", details.address.sub(editor.base));
      //
      console.log("eip: " + ptr(Memory.readU8(details.context.eip)));
      // restore
      //Memory.writeU8(sub_patchaddr, 0x55);
      Memory.writeU8(sub_patchaddr, cc_origin);
      console.warn("eip: " + ptr(Memory.readU8(details.context.eip)));

      console.log("eip: ", details.context.eip);
      console.log("pc: ", details.context.pc);
      console.log("eax: ", details.context.eax);
      //
      details.context.eax = 0xDB;
      details.context.eip = ptr(details.context.eip).add(0x7);
      console.warn("eax: ", details.context.eax);
      console.warn("eip: ", details.context.eip);
      console.warn("pc: ", details.context.pc);
      // int30xCC
      Memory.protect(sub_patchaddr, 1, 'rwx');
      Memory.writeU8(sub_patchaddr, 0xcc);
      return true;
    });
    // int30xCC
    Memory.protect(sub_patchaddr, 1, 'rwx');
    Memory.writeU8(sub_patchaddr, 0xcc);
} else {
    console.warn("\n", "This platform and architecture are not supported :( ", "\n");
}

x64 执行断点实现代码(非硬件断点)
**** Hidden Message *****




5784992 发表于 2022-11-30 10:08:38

66666666666 牛xxx

wgz001 发表于 2022-11-30 10:12:47

666,表哥带带我

email123 发表于 2022-11-30 10:17:48

牛xxx,Nothing to say,just thank you !!!

朦胧的睡了 发表于 2022-11-30 10:43:48

表哥的技术是越来越强悍了

iamok 发表于 2022-11-30 10:57:23

学习一下frida用法

点点星 发表于 2022-11-30 10:59:01

让 江小白 来看看帖子里藏了啥好东西~~~

iamok 发表于 2022-11-30 11:03:50

学习使用frida使用,真是个好工具。

gongyuchang 发表于 2022-11-30 11:21:20

非常感谢楼主分享

creantan 发表于 2022-11-30 11:42:48

跟着学习frida
页: [1] 2 3 4 5 6
查看完整版本: 这是一个 Frida V(伪)EH 示例(更新 x64 执行异常代码)