Showing posts with label DbgBreakpoint. Show all posts
Showing posts with label DbgBreakpoint. Show all posts

Sunday, December 11, 2011

Debuggers Anti-Attaching Techniques - Part 2

In the previous post, i talked about the trick of patching the "DbgUiRemoteBreakin" and "DbgBreakPoint" functions and how to circumvent it.

In this post, i am going to analyze another trick. This time, the trick is patching the "NtContinue" function.

We already know the remote thread starts with executing the "DbgUiRemoteBreakin" function.

Trying to find how execution is transferred to the "DbgUiRemoteBreakin" function in the new thread, i found that it is the "NtContinue" function.

Hooking the "NtContinue" function, we can prevent ollydbg from attaching to processes.

Here you can find an demo (Tested with Windows XP SP2 and Windows 7).
 
This trick is bypassed in the same way as that one in Part 1 and can similarly be implemented in an ollydbg plugin.

Update:
I updated the demo in response to a comment. 

You can follow me on Twitter @waleedassar 

Tuesday, September 21, 2010

BreakOnDllLoad

In this post i will discuss the "BreakOnDllLoad" registry value found under the "Image File Execution Options" registry key a.k.a  IFEO.

Consider the following 2 figures:_


 
As we can see from the reversed code, the "IsDebuggerPresent" field ("BeingDebugged") in PEB is queried. If set, the "LdrQueryImageFileExecutionOptions" function is called to query for the "BreakOnDllLoad" registry value for the DLL that is being loaded. Also, the "ImageFileExecutionOptionsSpec" field ("ReadImageFileExecOptions") in PEB is queried. If set, the "LdrQueryImageFileExecutionOptions" function is called.

If the "LdrQueryImageFileExecutionOptions" function call succeeds, the "DbgBreakPoint" function is called. The "DbgBreakPoint" function is simply an int3 instruction. So, setting this registry value for a specific DLL gives you the chance to check the code of the "DllMain" function whenever you debug an application that loads this DLL, no matter what debugger you use.

Conclusion:
The "BreakOnDllLoad" registry value can be used to insert a breakpoint whenever a specific DLL loads into the address space of any process under any debugger.

You can follow me on Twitter @waleedassar