home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast.iso / virus / virus101.001 < prev    next >
Internet Message Format  |  1994-03-07  |  14KB

  1. From: woodside@ttidca.TTI.COM (George Woodside)
  2. Newsgroups: comp.sys.atari.st,comp.sys.apple,comp.sys.mac,comp.sys.ibm.pc
  3. Subject: Virus 101 - Chapter 1
  4. Date: 1 Mar 89 14:39:58 GMT
  5.  
  6. Preface: The program VKILLER is specific to the ATARI ST. My apologies
  7. for not making this clear in the previous posting, which went to
  8. several newsgroups. I have recieved far too many requests for the
  9. program from users of other systems to reply to each one individually,
  10. and the mailer has bounced some of the replies I tried to send. If you
  11. have an Atari, VKILLER was posted here a few weeks ago, and is
  12. available in the archives, on GEnie, Compuserve, and from most public
  13. domain disk distributors and User Group libraries. The current version
  14. is 2.01. 
  15.  
  16. Initial postings will cover virus fundamentals, as they apply to the
  17. area of the Atari ST and, similarly, to MS-DOS systems. The file
  18. systems of the two machines are nearly identical. These general
  19. information articles will be cross-posted to the newsgroups in which
  20. this topic is now active. Future postings will be made only to the
  21. Atari newsgroup, since they will deal with viruses (the plural,
  22. according to Webster's, is viruses) known to exist in the ST world.
  23. They would automatically be different than an IBM virus, since they
  24. are in the 68000 instruction set, or from a Mac or Amiga virus, since
  25. the file systems differ. Since all the viruses I have located are the
  26. "BOOT SECTOR" type (far and away the most common), that's what I will
  27. dwell upon. If and when the proposed newsgroup comp.virus becomes
  28. active, it will be added to the list for all postings.
  29.  
  30. Your generic disclaimer: I just an old-school computer hacker, with 20
  31. years in the software business. I built my first IMSAI many years ago,
  32. and have had several different computers. That qualifies me to have
  33. spent a lot of time on computers, but nothing further. I may be wrong
  34. about some things, may have a different opinion than you or anybody
  35. else, or most anything else you'd care to have disclaimed. What I
  36. think is my own opinion, and in no way represents the opinion or
  37. position of my employer or anyone else. I've written several articles
  38. for magazines as well as software related to virus detection and
  39. killing, but I have been known to be wrong (so they tell me :^)).
  40.  
  41. While posting any kind of information about viruses may trigger
  42. someone to attempt creating one, I believe that the benefit of the
  43. knowledge to potential victims outweighs that risk. I don't believe
  44. that you can stop someone (who wishes to) from creating a virus by
  45. withholding information - it is already available from many sources.
  46. Since not all viruses act the same, or attempt to attack in the same
  47. manner, it may help potential (or current) victims to learn about the
  48. symptoms of the viruses known to exist, and how to protect themselves.
  49.  
  50. While the concept of viruses can be complex, I'll try to keep things
  51. at a level that should be understandable by most anyone past the
  52. casual user genre. However, since I've been at this sort of thing for
  53. some time, what I consider basic knowledge may not be familiar to
  54. everyone. Advance apologies are offered here for any invalid
  55. assumptions, typos, smart alec remarks, grammatic errors, or whatever
  56. offends you. 
  57.  
  58. Some basic terms, as they have come to be used in this area: 
  59.  
  60. A VIRUS is any program which spreads itself secretly. It may be
  61. destructive, a prank, or even intended to be helpful, but it spreads. 
  62.  
  63. A TROJAN HORSE is a program which executes one function secretly while
  64. appearing to be accomplishing some other task, or appearing to be some
  65. other program entirely. One task a Trojan Horse may accomplish is to
  66. install a virus, which would then spread itself.
  67.  
  68. A WORM is a program or function which imbeds itself inside another
  69. program, be it an application, part of a system, a library or
  70. whatever. It may or may not spread itself by some means, and may or
  71. may not have destructive intents. 
  72.  
  73. Now, to the basics of a disk (specifically floppies, but true of most
  74. hard disks as well): 
  75.  
  76. A DIRECTORY is a list of files and sub-directories. There is one
  77. primary directory (called the root directory) on a disk. It contains
  78. the entries for files, and other directories (called sub-directories,
  79. or folders on the Atari). Sub-directories (folders) may contain
  80. entries of other sub-directories, files, or both. Every file has one
  81. entry in the disk directory (or in some sub-directory). That entry
  82. contains, among other things, the file name, date and time of
  83. creation, length, and the address of the first entry in the File
  84. Allocation Table (FAT) for the file. 
  85.  
  86. A FAT is a File Allocation Table. It is a road map of how the
  87. operating system will locate data on a disk. Essentially, it is a
  88. series of pointers. The directory entry of a file points to the first
  89. FAT entry of that file. That entry points to the next, and so on,
  90. until the last entry, which contains a special value indicating end of
  91. file. There are two copies of the FAT on the disk, since it is
  92. absolutely critical. Lose the FAT, and the data on the disk becomes
  93. un-accessable. 
  94.  
  95. A BOOT SECTOR is the first sector on a floppy disk. With the Atari
  96. (and MS-DOS) system, it contains configuration information about the
  97. disk. That information includes how many tracks are on the disk, how
  98. many sectors per track, how many sides on the disk, how big the FATs
  99. and directories are, where the data begins, etc. On the MS-DOS
  100. systems, the boot sector contains the ID of the operating system under
  101. which it was formatted. On the Atari, that value is not used, but
  102. replaced (in part) by a number. That number should be different on
  103. every disk, and is used as part of the mechanism by which disk changes
  104. are detected. The boot sector may or may not contain executable code.
  105. If it does contain executable code, it is normally executed only at system
  106. powerup or system reset time. 
  107.  
  108. On all such disks, the boot sector is number 0, the first sector on the
  109. first side of the first track. On a standard format Atari disk, the
  110. next five sectors are the first copy of the FAT, the next five sectors
  111. are the second copy of the FAT, the next seven sectors are the root
  112. directory, and the remainder of the disk is available for data.
  113.  
  114. Now, on with the show: 
  115.  
  116. Floppy disks are changed on a regular basis while the computer is
  117. being used. More so on systems with no hard disks, but periodically on
  118. most all systems. This event, referred to as a "Media Change", is
  119. detected by the computer's disk drive. The disk door is opened, the
  120. status of the write protection changes as one disk is removed and
  121. another is inserted, etc. When that happens, the operating system must
  122. recognize that the disk has been changed before attempting to read or
  123. write to the new disk. The operating system reads the disk's boot
  124. sector to learn about the newly inserted disk. That instant, when the
  125. operating system checks the new disk, is when nearly all the boot
  126. sector viruses spread. We'll get to that in the next chapter, but first,
  127. a more primary question: 
  128.  
  129. How did the virus get in there? 
  130.  
  131. When a computer is booted up from a power off state, or reset (in most
  132. cases), it starts executing code from internal ROMs. Those ROMs set up
  133. primary vectors, minimal configuration information, and perform some
  134. fundamental tests. Then they start moving into uncharted waters. They
  135. have to find out what devices are attached, and get them into
  136. operating status. They also have to provide a means of expanding their
  137. own capabilities to support new devices, functions, and whatever else
  138. which may not have existed when the ROMs were created. One of the
  139. means by which this is accomplished is by checking various addresses
  140. for special codes, magic numbers, or any kind of response to a read
  141. or write. Another function which may be enabled is checking the boot
  142. sector on an inserted floppy disk for executable status. If that boot
  143. sector has executable status, the code contained in the boot sector is
  144. executed. That code may cause other portions of the disk to be loaded
  145. and executed, set variables or vectors, or nearly anything imaginable.
  146. That includes infecting the system with a virus, if that's what the
  147. boot sector code contains. Executable status may be via a special flag
  148. value in a reserved address, but it is normally determined by adding
  149. up the value of all the data bytes in the boot sector. If the total
  150. derived (called a checksum) is a specific value (a "magic" number),
  151. then the boot sector is deemed executable. The code is usually executed
  152. at that time. The code is not normally garanteed to be loaded at any
  153. specific address in memory, so it must be "position independant",
  154. or capable of executing no matter where it exists in memory.
  155.  
  156. The boot sector is of limited size, normally 512 bytes. While that is
  157. enough for a small program, it may not be enough for whatever task it
  158. is designed to accomplish. So, part of what the code in the boot sector
  159. accomplishes must be to load the rest of the code it needs to get the job done.
  160. This may be a normal data file, or hard coded to some other part of the
  161. disk.
  162.  
  163. If the code from the boot sector is designed only to accomplish some task,
  164. it will normally take the steps to do so, then return to the operating
  165. system. This may be setting the screen resolution or colors, issuing
  166. an initialization command to some device, or setting up some option
  167. or feature. If the code is designed to remain available after the initial
  168. execution (such as part of a device driver), it must inform the operating
  169. system that it wishes to remain resident. The operating system then
  170. alters the amount of RAM available to protect the space occupied by the
  171. loaded code, so that subsequent programs do not tamper with the loaded
  172. routine. Such a routine is referred to as a "Terminate and Stay Resident"
  173. routine, or a TSR. Viruses must be TSR type programs. They have to remain
  174. in the system, and active, to be able to accomplish their spread, and
  175. eventually, their true goal. If the boot sector program was designed
  176. to attack immediately, it may accomplish its destruction, but it would
  177. never get the opportunity to spread, and the disk which caused the
  178. attack would be easily identifiable.
  179.  
  180. Most viruses accomplish system infection by taking over a "vector". A
  181. vector is a specific address in system memory which contains the
  182. address of a routine or function. When an interrupt (such as pressing
  183. a key, the clock ticking, or so on) occurs, processing is suspended,
  184. and the system loads the address in some vector associated with that
  185. event. It executes the routine at the address which was stored in the
  186. vector, then resumes whatever it was up to when the interrupt
  187. occurred. Other vectors are not associated with interrupts, but with
  188. specific functions, such as display a character on the screen, read a
  189. sector from the disk, write to the printer, and so on. 
  190.  
  191. To take over a vector, the steps are fairly simple. A RAMdisk, for
  192. example, will usually take over a disk read/write vector. When it
  193. installs itself, it removes the current address from the vector
  194. assigned to the disk read/write function. It saves that address in
  195. it's own code, and places the address of it's own code in the vector.
  196. When a disk read/write call is made by the operating system, the
  197. operating system loads the address found in the proper vector, and
  198. starts executing the code found at that address. That address now
  199. points to the executable code of the RAMdisk. The first thing the
  200. RAMdisk does is check the function call's parameters to see if the
  201. read/write is for the RAMdisk. If it is, the RAMdisk accomplishes the
  202. read or write, and returns to the operating system. If the read/write
  203. is for some other disk drive, the RAMdisk code passes the call on to
  204. the address it removed from the vector, allowing the assigned device
  205. to accomplish the task. 
  206.  
  207. There may be more than one alteratiion of the vector. Each new routine
  208. which is installed will save the old vector, and insert itself. That
  209. means that the routine installed last will get the first access to any
  210. call which uses that vector. If it does not want the call, it passes
  211. the call on to the address it found in the vector, and so on. The
  212. significance of this sequencing is that a boot sector virus, if
  213. present, will be one of the first "vector snatchers" to get installed.
  214. Conversely, it will be one of the last routines in the sequence to get
  215. executed when a vector is accessed. 
  216.  
  217. If the vector in question happens to be for floppy disk I/O, the virus
  218. will be one of the last vectors before the real physical read/write
  219. routine. So, if a program designed to detect a virus's floppy disk I/O
  220. calls is executed as part of a startup procedure, it can easily be
  221. fooled. The detect program will see only normal system I/O calls
  222. passing through the vector. The virus resides in the vector list after
  223. the anti-virus program, so the anti-virus will never see any activity
  224. generated by the virus. The anti-virus thinks that things are
  225. progressing well, while, in reality, the virus is either spreading or
  226. doing damage behind the anti-virus's back. 
  227.  
  228. If the anti-virus gets installed first (say, by being in a boot sector
  229. itself), it has a better chance of offering protection, but not an
  230. absolute one. Some viruses check things like ROM version numbers, and
  231. know the absolute addresses in the ROMs of the functions they want. By
  232. using those addresses, they can bypass subsequent links in the vector
  233. list, and still do their dirty work. They can also refuse to install
  234. themselves if the addresses or version numbers do not correspond to
  235. the environment they want. 
  236.  
  237. End of Chapter 1. 
  238. -- 
  239. *George R. Woodside - Citicorp/TTI - Santa Monica, CA 
  240. *Path:       ..!{philabs|csun|psivax}!ttidca!woodside
  241.