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

  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 2
  4. Date: 6 Mar 89 14:00:21 GMT
  5.  
  6. In response to a lot of the mail I've received:
  7. 1) You haven't missed the "rest of the chapters". I'm posting them as I
  8.    get them written.
  9.  
  10. 2) You may not agree with me. I tried to set down the definitions and
  11.    terms as I would be using them, for the benefit of those who weren't
  12.    familiar with them. This whole area is rather vague, and most of us
  13.    in the trenches and making up the rules, as we learn the game.
  14.  
  15. When we left our virus at the end of Chapter 1, it had managed to get
  16. itself installed in our system by being present on the boot sector of a
  17. disk in the machine at cold start or reset. 
  18.  
  19. Another way a virus may be installed is via a trojan horse program. Trojan
  20. horses come in many flavors. Some disguise themselves as programs which
  21. provide some useful function or service, while secretly doing something
  22. else. The something else may be installing a virus, sabotaging some part of
  23. a disk, setting up hooks to steal passwords on time sharing systems, or
  24. whatever else you can imagine. In the event of the virus installer, the
  25. trojan horse has a bit more flexibility than a typical boot sector virus,
  26. simply because it doesn't have to fit itself into a relatively small space.
  27. Since it is hiding in a larger program, it can be whatever size is
  28. necessary to accomplish the task. 
  29.  
  30. A typical boot sector contains information about the layout of the disk it
  31. resides upon. This block of data requires 26 bytes. The first three bytes
  32. of the boot sector are left available for an assembly language "jump"
  33. command, to allow the execution of the code to skip over the boot sector's
  34. data block. And, the boot sector must add up to the proper magic number to
  35. have executable status. That will require another two bytes, since the
  36. checksum is a 16 bit value. So, 31 bytes are allocated. Since (at least in
  37. the 68000 family) machine instructions are always 16 bits and must begin on
  38. an even address, 32 of the 512 bytes in the boot sector are not available
  39. to any executable program. So, there are 480 bytes available for the
  40. executable code. Machine instructions vary in length, depending upon what
  41. they do, and how much additional information is required. In the 68000,
  42. instruction lengths vary from one to five words, but a reasonable average
  43. instruction length for a program is just over two words. That translates
  44. the 480 bytes to 120 instructions. 
  45.  
  46. The virus must contain the code to install itself, reserve the memory it
  47. occupies to keep subsequent programs from over-writing it, spread itself to
  48. other disks, and whatever it really intends to do once it decides it is
  49. time to act. That's quite a bit of code to fit into 120 instructions,
  50. unless it extends itself by loading some other part of the disk, or a file. 
  51.  
  52. Files are pretty much out of the question. Most computer users would notice
  53. if some file they didn't recognize started popping up on a lot of their
  54. disks. There are attributes settable in a disk directory which can be used
  55. to tell the operating system that certain files are "Hidden" or "System"
  56. files. If the file had the proper status bits set, it could prevent itself
  57. from appearing in normal disk directory displays. There are, however, more
  58. flexible disk directory listing programs which will display the entries for
  59. these files, as well as normal files. There is also the problem of the
  60. space the hidden file occupies, as well as the directory entry. The space
  61. available on the disk will be less than it should be, since the hidden file
  62. is present. These symptoms would not escape detection for long. 
  63.  
  64. A more effective method is the use of specific disk sectors. The standard
  65. disk layout covered in the preceeding chapter mentioned such things as File
  66. Allocation Tables, and disk directory space. In a standard format Atari
  67. disk, for example, each FAT is 5 sectors long, and the directory is 7
  68. sectors long. That is more than enough FAT space to accomodate the entire
  69. disk. A virus in need of more space than 480 bytes might write the
  70. remainder of itself in the last sector of the FAT (I have one that does
  71. this). It might also write itself in the last sector of the directory,
  72. taking advantage of a quirk in the operating system. 
  73.  
  74. When a disk is formatted, all data sectors are normally filled with a
  75. pre-defined value, E5 (hexadecimal). The directory and FAT space is usually
  76. set to 00. When a directory entry is made active, the file name is written
  77. in the directory, along with some other required information. When a file
  78. is deleted, the first byte of the directory entry is set to E5. That makes
  79. the entry available again. This is a carry over from the early days of
  80. floppy disks, when where the directory would exist on a disk was not as
  81. well defined. The directory entries had to appear as empty on a freshly
  82. formatted disk, so E5 was used as a deleted entry mark. That way, no matter
  83. where the directory was, a freshly formatted disk would always appear as
  84. empty. Now, since disk formats are more flexible, the directory is located
  85. by parameters, and normally the entire directory space is zeroed at
  86. formatting time. Since an active entry will have some legitimate ASCII
  87. character in the beginning of the file name, and a deleted entry will have
  88. E5 in the first byte, it is generally assumed that encountering a directory
  89. entry with a value of 00 in the first byte indicates that the entry has
  90. never been used. Since directory entries are used (and deleted ones
  91. re-used) on a first-found basis, finding one with 00 means that not only
  92. has it not been used, but none of the ones following it will have been used
  93. either. Consequently, most software stops looking at the directory entries
  94. when a 00 entry pops up. If there are several more sectors available, there
  95. may be something hiding out there, beyond the last used entry. While this
  96. method of hiding is not foolproof, the typical virus is not concerned about
  97. being bulletproof in all cases. It just has to survive long enough to
  98. reproduce itself, and it has half the battle won. As long as it keeps
  99. spreading, sooner or later it will survive long enough to do the task it is
  100. designed to do, then it wins both halves of the battle. 
  101.  
  102. There are other ways for the virus to get additional disk space. Typically,
  103. floppy disks are not used up a sector at a time, but rather in groups of
  104. sectors. Each group of sectors is referred to as a data "cluster". The
  105. number of sectors in a cluster is variable, and is one of the parameters
  106. stored in the boot sector. If the number of data sectors on the entire
  107. disk, minus the boot sector, FATs, and directory, is not an exact multiple
  108. of the number of sectors in a data cluster, the remaining sectors will
  109. never be used by the opearting system. A clever virus can find them and
  110. hide there. The inconvenience of this is that the unused sectors would
  111. normally be at the end of the last track of the disk, causing long (and
  112. noticeable) disk seeks to load or spread the virus. 
  113.  
  114. There is a parameter in the boot sector designed to permit the disk to have
  115. sectors reserved for any purpose, and not accessed as part of the normal
  116. data area. A virus could also use this method to extend itself, but it,
  117. too, has shortcomings. Using this feature requires the parameter to be set
  118. when the disk has absolutely no data on it. Reserving sectors causes the
  119. start of the data area to be moved further into the disk. While the data
  120. area would be moved, the data already on the disk would not. Consequently,
  121. altering the reserved sectors parameter would make all files on the disk
  122. garbage. (They could be returned to proper status by restoring the original
  123. value to the reserved sectors parameter, providing no disk write had
  124. occurred.) There would also be the problem of the disk's free space being
  125. less that it should. 
  126.  
  127. Consequently, if a virus needs extra space, using prescribed system
  128. features or hidden files is not a good choice, since it is too easily
  129. detected. The approach used so far is to hide in sectors unlikely to be
  130. used, and hope to spread before they get clobbered (and it works). 
  131.  
  132. OK, so now the virus has managed to get onto a disk in your library, and
  133. then get itself booted into your system at startup or reset. It may have
  134. been on a disk you received from someone, and booted with, or it may even
  135. have been installed by a trojan horse, but it is in your system. How does
  136. it spread? 
  137.  
  138. There are ways, and then there ways..... 
  139.  
  140. The most common method is through the vector reserved for floppy disk read
  141. and write functions. As we saw in Chapter 1, floppy disks get changed (some
  142. surprise, eh?). One disk is removed, and another is inserted. When that
  143. happens, the operating system is notified by the physical act of changing
  144. the disk that the event has occurred. How that event is detected will vary
  145. with different disk drives, but there are two common methods. One is the
  146. disk drive latch. Some hardware reports the transition of the latch on the
  147. floppy disk drive's door. When the locking lever is moved, a signal is sent
  148. to the disk controller card, indicating that the disk door has been opened.
  149. (Door is a carry over term from older drive mechanisms which had fully
  150. closing doors over the disk drive slot.) The operating system makes note of
  151. the fact that a disk change may have occurred. 
  152.  
  153. The other method is the write protect notch. On both 5 1/4 and 3 1/2 inch
  154. disks, the write protect notch tab is located in a position which makes it
  155. impossible to fully remove and install a disk without having the write
  156. protect detection mechanism be fully obstructed at some point, and fully
  157. unobstructed at some point. The detection mechanism may be a physical sense
  158. switch, or an optical sensor. Either way, as the body of the disk is
  159. removed from the drive, it will be blocked. Then, when the disk is out, the
  160. sense area is open. So, the drive will report transitions on the status
  161. line. The operating system notes the change, and sets the necessary flags
  162. to indicate that the disk may not be the same one that was there a little
  163. while ago. It may also be, if the same disk was re-inserted, but that's not
  164. important. The fact that it may have changed is very important. Attempting
  165. to read or write to the disk, without first noting the characteristics of
  166. it, could be very destructive. 
  167.  
  168. When the next access of the (possibly) changed disk occurs, the operating
  169. system will read the boot sector. In MS-DOS systems, I believe that the
  170. operating system assumes that if there is a possiblity that the disk has
  171. changed, it assumes that it has, dumps all information relative to the old
  172. disk, and starts fresh. In the Atari, the operating attempts to be a bit
  173. smarter. The boot sector contains a serial number which is supposed to be
  174. unique across all disks. This serial number is 12 bits long, and is
  175. assigned when the disk is formatted. If there is a possibility that the
  176. disk has changed, the operating system reads the serial number. If the
  177. serial number is different than before, the disk has changed, all old data
  178. is wiped out, and the new serial number is noted. If the serial number is
  179. the same, the disk has presumably not changed, and the data in the
  180. operating system's internal buffers is assumed to be valid. This leads to
  181. thoroughly trashed disks if two disks have identical serial numbers, and
  182. are used consecutively. 
  183.  
  184. In any event, when a possible disk change has occurred, the boot sector is
  185. always read to determine the characteristics of the new disk. The operating
  186. system uses the floppy disk read function to access the first sector on the
  187. disk. As previously noted, this disk read function is pointed to by a
  188. vector. If the vector has been altered to point to a virus, the plot
  189. thickens... 
  190.  
  191. We will assume a typical floppy disk boot sector virus for a while, and see
  192. exactly what happens. The virus first checks the number of the drive being
  193. accessed. If it is not a floppy disk, it passes the call on to the address
  194. it found in the vector. No harm done. 
  195.  
  196. If the call is to a floppy disk, most viruses check the side, track, and
  197. sector of the call to see if it is the boot sector. If it isn't, it passes
  198. the call on, and again, no harm done. Why? Performance. Not that the virus
  199. cares about good disk performance, mind you. What it cares about is being
  200. noticed. If it was busy snagging all the disk calls, and checking the boot
  201. sector all the time, there would be an incredible increase in disk head
  202. seeking, and a very noticeable drop in performance of the system. Anyone
  203. with at least half a brain (witch inkluds sum smarter komputer pepel) would
  204. notice that, and would become inquisitive about what was happenning. The
  205. virus would have given itself away. No self-respecting virus would want to
  206. be detected before it got a chance to spread, and possibly wreak a bit of
  207. havoc, so it remains inactive until it can accomplish its task unnoticed. 
  208.  
  209. When the read call is to the boot sector, the virus goes into action. The
  210. data is read into a buffer, as designated by the host operating system's
  211. call, exactly as expected. Normally, the disk read function would return to
  212. the operating system at this point, but the virus doesn't. Depending upon
  213. the sophistication of the virus, several things may happen. Some viruses
  214. will first check the image of the boot sector in the buffer, to see if they
  215. are already on the disk. If they find the disk already has the virus, the
  216. go back to sleep (pleased, we assume!). Some even check revision levels in
  217. the virus image, and replace themselves if the disk had a more recent
  218. version of themselves! 
  219.  
  220. If the image from the boot sector is not the virus, some will check to see
  221. if the image was of an executable boot. If it was, the virus does not alter
  222. it. Doing so would make a self-booting disk fail forever after, and would
  223. probably lead to the detection of the virus. Other viruses, not as
  224. sophisticated, will not execute this test, and may be spotted more readily. 
  225.  
  226. Now, assuming that the boot sector is not executable, or that it is but
  227. this virus is too dumb to leave it alone, it's time for the virus to
  228. spread. There is a copy of the boot sector from the original virus disk in
  229. a reserved memory area, from the original boot up process. The executing
  230. copy of the virus knows where that is, since it reserved the memory for
  231. itself and the image at the same time. The characteristics of the disk the
  232. virus came from may not be the same as the disk in the machine now.
  233. Depending upon the operating system's standards, the virus will either copy
  234. the disk parameter information from the current disk into its own image
  235. buffer, or copy its image into the current disk's buffer, leaving the
  236. disk's parameters unchanged. Either way, the result is a copy of the
  237. current disk's parameters, combined with the executable image of the virus.
  238. Now, the executable status checksum must be computed, and added to the
  239. buffer. This may be accomplished by a routine in the virus, or by an
  240. operating system call. If the virus is on an Atari, it might be careful
  241. enough to insure that the serial number on the new disk remains the same.
  242. Failing to do so would lead to all disks with the virus having the same
  243. serial number. That would lead to disks being accidently altered (due to
  244. the serial number test), and the virus would probably be detected too soon. 
  245.  
  246. When the new checksum is completed, the updated boot sector is re-written
  247. to the disk. All this occurs in much less than the time required for the
  248. floppy disk to make a single revolution, so the boot sector is re-written
  249. on the next spin. Since the rotation speed of the disk is either 300 or 360
  250. rpms, the total time lost is less than 1/5 of one second. Nearly impossible
  251. for anyone to notice, when combined with the time required for the drive to
  252. load the head, seek to track zero, read the sector, etc. 
  253.  
  254. The only potential problem here is one of the virus' intended victim's
  255. primary levels of defense: the write protect feature. Despite rumors to the
  256. contrary, I have not seen a virus capable of writing to a write protected
  257. disk. The hardware in the disk drive will not write if the write protect
  258. status is set. It reports an error to the operating system. The virus can
  259. not override this protection, but it must be wary of it. Older viruses were
  260. sometimes spotted when a system error occurred, reporting that an attempt
  261. was being made to write to a disk which was write protected. If the
  262. function being performed (listing a directory, for example) should not be
  263. writing to the disk, there was reason to become suspect. Most viruses now
  264. are more sophisticated. They take over the error vector before attempting
  265. the write, and restore it afterwards. That way, if the attempt to spread
  266. themselves to the new disk fails, the error never gets reported. While the
  267. user doesn't know that the attempt was ever made, the disk also doesn't get
  268. infected. 
  269.  
  270. Many viruses run counters. Some count the number of already infected disks
  271. they have seen, while others count the number of disks they infect. Either
  272. way, the counting viruses have some threshold they are attempting to reach.
  273. When they reach that number, they (presumably) consider themselves
  274. thoroughly spread, and it is now time to start their third act. 
  275.  
  276. End of Chapter 2. 
  277. -- 
  278. *George R. Woodside - Citicorp/TTI - Santa Monica, CA 
  279. *Path:       ..!{philabs|csun|psivax}!ttidca!woodside
  280.