前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >反调试专题丨反调试之BeingDebugged

反调试专题丨反调试之BeingDebugged

原创
作者头像
极安御信安全研究院
发布2023-06-28 13:04:59
4200
发布2023-06-28 13:04:59
举报

一、x86下IsDebuggerPresent反调试以及反反调试

1、反调试

进程结构体PEB偏移0x2处是一个标志位,当当前程序在调试状态下时,这个标志位就会被改变:

nt!_PEB +0x000 InheritedAddressSpace : UChar +0x001 ReadImageFileExecOptions : UChar +0x002 BeingDebugged    : UChar                isDbg值,8字节 +0x003 BitField         : UChar +0x003 ImageUsesLargePages : Pos 0, 1 Bit +0x003 IsProtectedProcess : Pos 1, 1 Bit +0x003 IsLegacyProcess  : Pos 2, 1 Bit +0x003 IsImageDynamicallyRelocated : Pos 3, 1 Bit +0x003 SkipPatchingUser32Forwarders : Pos 4, 1 Bit +0x003 SpareBits        : Pos 5, 3 Bits +0x004 Mutant           : Ptr32 Void +0x008 ImageBaseAddress : Ptr32 Void              镜像基址 +0x00c Ldr              : Ptr32 _PEB_LDR_DATA             _PEB_LDR_DATA结构 +0x010 ProcessParameters : Ptr32 _RTL_USER_PROCESS_PARAMETERS +0x014 SubSystemData    : Ptr32 Void +0x018 ProcessHeap      : Ptr32 Void              +0x01c FastPebLock      : Ptr32 _RTL_CRITICAL_SECTION +0x020 AtlThunkSListPtr : Ptr32 Void +0x024 IFEOKey          : Ptr32 Void +0x028 CrossProcessFlags : Uint4B    .    .    .

而API IsdebuggerPresent函数就是检测这个位置(不进内核),FS寄存器偏移0x30的地方就是PEB的地址,此函数的汇编实现如下:

7622C220 mov         eax,dword ptr fs:[00000030h] 7622C226  movzx       eax,byte ptr [eax+2]

下面是部分利用代码:

DWORD WINAPI MyIsDebug( LPVOID lpThreadParameter ) { while (1) { if (IsDebuggerPresent()) {            MessageBox(NULL, L"警告", L"调试中", MB_OK); } } return 1; } int main() { //IsDebuggerPresent();     CreateThread(NULL, NULL, MyIsDebug, NULL, NULL, NULL);     std::cout << "Hello World!\n";     system("pause"); return 0; }

也可以自己实现此函数,可以避免对于IsDebuggerPresent函数的Hook或者断点检查:

bool IsDebuggerR() { bool bRet = false;     __asm {        mov eax, fs: [0x30]        mov al, byte ptr[eax + 2]        mov bRet, al } return bRet;//返回TRUE是debug } DWORD IsDebuggerR() {     DWORD MyPeb = __readfsdword(0x30);     DWORD MyFlag = *(DWORD*)(MyPeb+0x2) return MyFlag; }

效果如下:

2、对于IsdebuggerPresent的反反调试

1. 很多调试器有对应插件,可以过掉此反调试手段。

2. 在调试器中对此函数下断点,修改其函数返回值,达到反反调试。

3. 通过对进程注入DLL,在DLL中Hook函数IsdebuggerPresent。

二、x64下反调试

1、反调试

64位系统下PEB结构有所变化,对于IsDebuggerPresent检测的标志位位置并没有区别,也就是说代码通用,但是自定义由于x64不支持内联汇编,所以引入asm文件,部分代码如下:

mov rax,qword ptr gs:[60h] movzx eax,byte ptr[rax + 2h]

当然也可以通过函数readgsqword获取PEB地址进而获取标志位结果。

2、反反调试

和x86没有区别 最后,CheckRemoteDebuggerPresent函数也是和IsdebuggerPresent函数类似功能。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 一、x86下IsDebuggerPresent反调试以及反反调试
    • 1、反调试
      • 2、对于IsdebuggerPresent的反反调试
      • 二、x64下反调试
        • 1、反调试
          • 2、反反调试
          领券
          问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档