调试器攻击技术 - Unhandled Exception Filter

来源:互联网 发布:淘宝优5元惠券模板 编辑:程序博客网 时间:2024/06/01 08:36

5、 Unhandled Exception Filter

MSDN文档声明当一个异常到达Unhandled Exception Filter(kernel32!UnhandledExceptionFilter)并且程序没有被调试时,Unhandled Exception Filter将会调用在kernel32!SetUnhandledExceptionFilter()API作为参数指定的高层exception Filter。壳利用了这一点,通过设置exception Filter然后抛出异常,如果程序被调试那么这个异常将会被调试器接收,否则,控制被移交到exception Filter运行得以继续。

示例

下面的示例中通过SetUnhandledExceptionFilter()设置了一个高层的exception Filter,然后抛出一个违规访问异常。如果进程被调试,调试器将收到两次异常通知,否则exception Filter将修改CONTEXT.EIP并继续执行。

;set the exception filter

push                .exception_filter

call                  [SetUnhandledExceptionFilter]

mov                 [.original_filter],eax

;throw an exception

xor                  eax,eax

mov                 dword [eax],0

;restore exception filter

push                dword [.original_filter]

call                  [SetUnhandledExceptionFilter]

:::

.exception_filter:

;EAX = ExceptionInfo.ContextRecord

mov              eax,[esp+4]

mov              eax,[eax+4]

;set return EIP upon return

add                dword [eax+0xb8],6

;return EXCEPTION_CONTINUE_EXECUTION

mov              eax,0xffffffff

retn

有些壳并不调用SetUnhandledExceptionFilter()而是直接通过kernel32!_BasepCurrentTopLevelFilter手工设置exception Filter,以防逆向分析人员在那个API上下断。

对策

有意思的是kernel32!UnhandledExceptionFilter()内部实现代码是使用ntdll!NtQueryInformationProcess(ProcessDebugPort)来确定进程是否被调试,从而决定是否调用已注册的exception Filter。因此,处理方法和DebugPort调试器检测技术相同。 
0 0