加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

在Windows上的“用户空间”中“捕获”进程自己的sysenter调用

发布时间:2020-12-14 02:50:58 所属栏目:Windows 来源:网络整理
导读:我正在 Windows中运行一个运行时非本机二进制转换器,到目前为止,我已经能够通过使用一个使用丑陋的hack来“捕获”操作系统二进制文件的中断(即INT 0x99) Windows SEH处理无效中断;但只是因为系统调用向量与Windows中的不同,允许我通过执行以下操作来捕获这些
我正在 Windows中运行一个运行时非本机二进制转换器,到目前为止,我已经能够通过使用一个使用丑陋的hack来“捕获”操作系统二进制文件的中断(即INT 0x99) Windows SEH处理无效中断;但只是因为系统调用向量与Windows中的不同,允许我通过执行以下操作来捕获这些“软”异常:

static int __stdcall handler_cb(EXCEPTION_POINTERS* pes,...)
{

    if (pes->ExceptionRecord->ExceptionCode != EXCEPTION_ACCESS_VIOLATION)
        return EXCEPTION_CONTINUE_SEARCH;

    char* instruct = (char*) pes->ContextRecord->Eip;

    if (!instruct)
        handle_invalid_instruction(instruct);   

    switch (instruct[0])
    {
        case 0xcd: // INT
        {
            if (instruct[1] != 0x99) // INT 0x99
                handle_invalid_instruction(instruct);
            handle_syscall_translation();
            ...
        }
        ...
        default:
            halt_and_catch_fire();
    }
    return EXCEPTION_SUCCESS;
}

哪个工作得相当好(但很慢),问题是Windows首先尝试处理指令/中断,对于使用sysenter / sysexit而不是int 0x99的非本机二进制文件,非本机二进制文件中的一些systenter指令实际上是有效的NT内核调用,这意味着我的处理程序永远不会被调用,更糟糕的是; “主机”操作系统的状态也受到了损害.有没有办法在Windows中“捕获”sysenter指令?我该怎么做呢?

解决方法

据我所知,没有办法(从用户模式进程)“禁用”SYSENTER,因此执行它会产生异常. (我假设您的程序不尝试SYSEXIT,因为只有Ring 0才能这样做).

我认为你唯一的选择是像VirtualBox那样做,并扫描无效指令,用非法操作码或类似的东西替换它们,你可以捕获并模拟.见10.4. Details about software virtualization.

To fix these performance and security issues,VirtualBox contains a Code Scanning and Analysis Manager (CSAM),which disassembles guest code,and the Patch Manager (PATM),which can replace it at runtime.

Before executing ring 0 code,CSAM scans it recursively to discover problematic instructions. PATM then performs in-situ patching,i.e. it replaces the instruction with a jump to hypervisor memory where an integrated code generator has placed a more suitable implementation. In reality,this is a very complex task as there are lots of odd situations to be discovered and handled correctly. So,with its current complexity,one could argue that PATM is an advanced in-situ recompiler.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读