izee
Electrical Ordered Freedom EOF-DR-RRLF
May 2008
Nowadays there are plenty anti-debugging tricks, some of them are known, some not. However, all publicly known tricks are Win32-specific and Win64 is still untouched currently. In the first part of article i'm going to demonstrate few new tricks, which are coded for Win64, but can be easily ported to Win32. In the second part i'll show how to implement SEH and TLS on Win64 and also some other new Win64-specific anti-debug techniques.
By loading something in IDA for analysis, you can notice that files with the following extensions are being created in the current directory:
program file name.id0 id1 nam til
These are IDA database related files. Using FindFirstFileA(W) function, we can easily check if there are files with such extensions in the current directory or not, and thus detect a presence of IDA.
Let's have a look at the example.
See also: idadb64.rar
Tested on: Windows Vista SP0/SP1 32/64bit
Applies to: Interactive Disassembler
Can be ported to Windows XP 32/64
The idea: to check if a debugger-specific keys (such as: F4, F7, F8, F9, F10, F11) were pressed during the debugging session. For that, we'll use the GetAsyncKeyState function.
In the following example we'll try to determine if a typical debugger key -- F8 -- was pressed.
See also: gaks64.rar
Tested on: Windows Vista SP0/SP1 32/64bit
Applies to: Interactive Disassembler, WinDBG, OllyDBG, future ring3 debuggers
Can be ported to Windows XP 32/64
For a local debugging of 64bit executables an IDA Win64 Remote Debug Server must be turned on. It's a console application, which listens on port #23946. We can try to connect to this port and thus detect a presence of IDA.
And now an example.
See also: idardbg64.rar
Tested on: Windows Vista SP0/SP1 64bit
Applies to: Interactive Disassembler 64
I can't say much about this syscall, since it's not documented well, however i found it as a new anti-debug trick. What the syscall does is sets the debug output filter level for the specified component, under debugger it returns NT_STATUS_SUCCESS (0), otherwise it returns error code 22.
Let's have a quick look at the example now.
See also: ntsdfs64.rar
Tested on: Windows Vista SP0/SP1 64bit
Applies to: Interactive Disassembler, WinDBG, future ring3 debuggers
Can be ported to Windows XP: unknown.
The function enables a debugger to attach to an active process and debug it. Not so long ago i found, that calling this function with current process handle on Windows Vista x64 under the ring-3 debugger will cause a local DoS or even BSOD. I still analyze this strange behavior,however i decided to write about my current researches. The funny thing is, that local DoS or BSOD will occur only on x64 versions of Windows Vista, not on x86.
Here's the example.
Here's the disassembled version.
See also: dap64.rar
Tested on: Windows Vista SP0/SP1 64bit
Applies to: Interactive Disassembler 64, WinDBG 64, probably future ring3 64bit debuggers
SEH can be used as a powerful anti-debug trick, as we know. Here is an example of SEH for Microsoft Linker x64.
eh proc ;exception handler <----, | ; your code goes here | | eh endp | | | eof proc frame: eh | |^ push rbp | | .pushreg rbp | .endprolog | | ud2, int3, icebp ---------------' nop > eof endp
See also: seh64.rar
Now a bit of explanation.
Debuggers especially don't like ud2 instruction. IDA for instance will be not capable to disassembly nor debug that instruction.
Tested on: Windows Vista SP0/SP1 64bit
Applies to: Interactive Disassembler 64, WinDBG 64, future ring3 64bit debuggers
TLS Callback is called before the main entrypoint, this gives an ability to execute the virus or check for a debugger presence, before the debugger reaches the main entrypoint. Unfortunately, ml64 don't support TLS Callbacks, so FASM is the only choice then currently for implementing TLS manually in Win64 executables.
Let's examine the example below.
See also: tls64.rar
Tested on: Windows Vista SP0/SP1 64bit
Applies to: Interactive Disassembler, WinDBG, future ring3 64bit debuggers
I hope you enjoyed reading the article as much as I enjoyed writing it. Don't forget to see attached archives also. If you will have some questions or comments, you can always write me an e-mail to: izee@eof-project.net
Welcome to Win64 world and let's protect our future creations!
WarGame, roy g biv, kaze, RadiatioN, Scorpions.
[Back to index] [Comments (0)]