How do I bypass IsDebuggerPresent with OllyDbg?

落爺英雄遲暮 提交于 2019-12-02 17:41:56

There are many ways to do it. As you said, it's possible to patch the program's thread block. Here is a tutorial, how to get around IsDebuggerPresent, by simply patching this function so it always returns 0.

1) locate IsDebuggerPresent

In my situation, it is at 7664EFF7, and consist of only three instructions + one RET. It reads the thread block (address is at FS:18), and then locates the byte that says "i am being debugged" and returns it. The returns value is stored in EAX (as for most WINAPI functions). If I modify the function so that at the end it will have EAX = 0, I will have successfully bypassed IsDebuggerPresent.

2) patch it

Now the easiest way to do it is to simply make the function simply do a MOV EAX, 0 instruction and then a RETN:

Note that I also filled the rest of the function with NOPs to avoid changing the size of it. It probably is not necessary, you could also just do MOV EAX, 0 and then just RETN.

Also you should know, that the modification is only valid for one run of the program. When you restart it, it will load a new copy of kernel32.dll (where IsDebuggerPresent is located) with the original function, and you will have to apply the patch again. If you want to make the patch permanent, you need to modify the launching binary and modify/remove the call to this function. But before you do that you also need to make sure that the binary doesn't check itself for modifications.

Inject this code in your process:

mov eax,dword ptr fs:[18]
mov eax,dword ptr ds:[eax+30]
mov byte ptr ds:[eax+2],0

This will patch the PEB.BeingDebugged flag, ensuring IsDebuggerPresent always returns 0

When using x64dbg you can run the dbh command.

if you want your application never check it do this:

  • Press Alt + e or open Executable modules window.
  • Select C:\WINDOWS\system32\kernel32.dll and press ctrl + N
  • select IsDebuggerPresent and press enter.
  • press f2
  • run the program and wait your program break on this op-code.
  • press some f8 until come back to your code.
  • looking up for something like TEST EAX,EAX and after some thing like je jnz and etc, be careful the output of IsDebuggerPresent is saved in EAX.
  • if jump happen on this op-code change it to nop and if doesn't happen change it to jmp.
  • save your program. if you don't know how to save modifed code in ollyDBG just search it.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!