home *** CD-ROM | disk | FTP | other *** search
/ The Hacker's Encyclopedia 1998 / hackers_encyclopedia.iso / pc / virus / sixbytes.txt < prev    next >
Encoding:
Text File  |  2003-06-11  |  17.0 KB  |  395 lines

  1. FTP'd from cert.org:
  2. File pub/virus-l/docs/six.bytes.padgett
  3.  
  4. Date: Fri, 29 Mar 91 16:35:24 -0500
  5. From: padgett%tccslr.dnet@uvs1.orl.mmc.com (A. Padgett Peterson)
  6. Subject: Six Bytes for Virus Detection paper
  7.  
  8. WARNING: The method depicted in this paper will not detect every conceivable
  9.          virus, to do so would take far more than six bytes. What it will
  10.          do is to detect all currently "common" viruses for a knowlegable user,
  11.          however, CHKDSK can do the same thing if intelligently applied. A
  12.          short .COM file following these principles will make a good "first 
  13.          check" before using a scanner to determine if something unknown 
  14.          might be resident. 
  15.  
  16.          Some viruses revealed immediately include Brain, Yale, Datalock,
  17.          Stoned, 4096, Fish-6, Flip, Whale, Joshi, MusicBug, and Azusa. 
  18.          TSR viruses such as the Jerusalem, Sunday, and 1701/1704 variants
  19.          will also be revealed if the user is knowlegable about the system.
  20.  
  21.                         Padgett Peterson, 3/29/91
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.                   Six Bytes for Virus Detection
  33.  
  34.                              in the
  35.  
  36.                         MS-DOS Environment
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.                                         A. Padgett Peterson, P.E.
  60.                                         Orlando, Florida
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.                           Introduction
  70.  
  71.      Concerning the size of the population (over fifty million MS-DOS 
  72. platforms  at  last estimate), to the macro, the 240+  known  viruses 
  73. represent  a relatively small statistic. In the micro  however,  they 
  74. can be devastating.
  75.  
  76.      With  the growth in size of fixed disks and applications,  often 
  77. backups  are obsolete or incomplete where proper discipline  has  not 
  78. been  established. Unfortunately, this seems to include the  majority 
  79. of the non-power users.
  80.  
  81.      Since  the number of known viruses appears to be  doubling  each 
  82. year, the threat is not diminishing, yet the most accepted utilities, 
  83. John  McAfee's SCAN & CLEAN, rely on detection of  known  infections. 
  84. While  there  are  some  products  that  actually  perform  integrity 
  85. management  of  a system (Certus International  CERTUS,  Enigma-Logic 
  86. VIRUS-SAFE and PC-SAFE, Fischer International PC-WATCHDOG, Dr.  Panda 
  87. BEARTRAP),  most are oriented to file protection rather  than  system 
  88. protection.
  89.  
  90.      To  adequately  protect  a  machine  that  possesses  no  native 
  91. integrity management requires a layered approach of user  management, 
  92. files/applications management, and systems management. We have a good 
  93. handle  on  the  first two but the  question  of  systems  integrity, 
  94. something  so pervasive in mainframes that it is taken  for  granted, 
  95. does not currently exist for the PC.
  96.  
  97.      Until  recently, a large enough population did not exist of  not 
  98. only successful but also unsuccessful viruses to draw any  inferences 
  99. concerning their viability in the general population. At the close of 
  100. 1990, however, certain characteristics of "successful" viruses, those 
  101. listed  as "common" in Patricia Hoffman's Virus Summary, have  become 
  102. clear:
  103.  
  104. 1: Become resident in memory following infection
  105.  
  106. 2: Allocate memory to themselves
  107.  
  108. 3: Redirect part of the operating system (not necessarily interrupts)
  109.  
  110.      Each  of these elements is easily detected, often in  more  than 
  111. one  way, yet few people or programs bother to look. Some years  ago, 
  112. this  author  wrote   three simple assembly language  programs,  each 
  113. about 1k bytes long. The first tests file integrity, the second tests 
  114. disk integrity, and the third tests system integrity. Taken  together 
  115. these still detect every "common" virus, not because they "know"  all 
  116. viruses  but  because  they "know" an  uninfected  system.  There  is 
  117. nothing magical involved, merely a knowledge of how the  architecture 
  118. operates.
  119.  
  120.      This paper does not address those viruses that attach themselves 
  121. to  programs or files specifically, rather consideration is  made  to 
  122. those  that  attack  elements of the  operation  system.  That  these 
  123. infections may later attack programs or files is incidental.  Rather,
  124. a description is provided of the third of these routines.
  125.  
  126.  
  127.  
  128.  
  129.  
  130.                           Architecture
  131.  
  132.      One  of  the greatest strengths of the architecture  of  the  PC 
  133. (both  IBM  and  clones - interestingly this  system  has  become  so 
  134. pervasive that while all other systems: Mac, Amiga, etc. are known by 
  135. their  names  or  initials, the letters PC -  standing  for  Personal 
  136. Computer  - most people immediately relate to a  single  platform) is 
  137. its lack of change. 
  138.  
  139.      In a world marked by instability, all systems since October  27, 
  140. 1982  are  compatible  with  every other  system.  In  fact  programs 
  141. properly written to the PC-DOS 1.0 specification will still run under 
  142. MS-DOS 5.0 and on the latest 486-33 mhz machines. (Out of  curiosity, 
  143. yesterday I booted my 386-25 with MS-DOS 1.25 - seeing A: instead  of 
  144. A> had been forgotten.).
  145.  
  146.      The reason that this is possible is because the structure of the 
  147. DOS (disk operating system), while it has received many  enhancements 
  148. in the last ten years, has had no deletions. The low level interrupts 
  149. (0h-1Fh) still operate to the original specifications and provide all
  150. necessary peripheral operations (disk, keyboard, display, etc.).
  151.  
  152.      To understand this, one must picture the architecture in layers:
  153. at  the  bottom are the individual elements,  the  iapx80X86  central 
  154. processing unit, the 8251 programmable I/O, the RAM memory, the  BIOS 
  155. (basic  input output system) ROM, the keyboard, the display, and  the 
  156. disks  (not even necessary in a real IBM-PC). Until turned on,  these 
  157. are merely a collection of inert devices.
  158.  
  159.      On power on, the CPU performs a simple self test and then  reads 
  160. in the instruction stored at address F000:FFF0h in memory. Since  the 
  161. ROM BIOS is connected to the system so that this address is found  in 
  162. its  non-volatile memory, the program stored there begins  execution. 
  163. The BIOS program performs three functions: 
  164.  
  165.      The first is a test and system check (POST - power on self test) 
  166. in  a particular order - CPU and the first 64k of memory  (a  failure 
  167. here results in a series of beeps from the speaker, all the processor 
  168. may  be able to do at this point). Next the low level interrupts  are 
  169. loaded  into  the first 64k and checks are made to determine  if  the 
  170. rest   of  memory,  display,  keyboard,  and  connected   disks   are 
  171. operational. Failures now will be shown on the display.
  172.  
  173.      Second,  the BIOS will scan memory from segment C000h  to  E000h 
  174. for BIOS extensions in hardware. Special hardware cards that  require 
  175. operations  not  found in MS-DOS often contain  their  own  low-level 
  176. interrupt  handlers  &  DOS  makes provision  for  this.  VGA  cards, 
  177. Bernoulli disks, and PLUS Hardcards are good examples.
  178.  
  179.      Finally,  the BIOS will attempt to read in the first  sector  of 
  180. from  either  the first floppy disk (if present) or the  first  fixed 
  181. disk  (if  the  floppy  does not respond)  and,  if  successful  will 
  182. transfer execution to the first location in that sector.
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.      At  this point, the PC is a fully functioning computer,  but  is 
  192. not yet an MS-DOS machine. Whether the PC runs Unix, MS-DOS, CP/M-86, 
  193. OS/2, or any other system depends on what happens next, however it is 
  194. here  that  viruses known as Boot Sector  Infectors  (Brain,  Stoned, 
  195. Joshi, MusicBug, Azusa) become resident. 
  196.  
  197.      The  key is that the PC makes an unconditional transfer  to  the 
  198. program found in sector 1 of the selected disk. Only a trivial  check 
  199. is  made  as  to whether it is a valid program  or  conforms  to  any 
  200. standard. It is this willingness to run any code presented to it that 
  201. makes the PC attractive to many viruses and leaves users  unsurprised 
  202. at having to reboot several times a day.
  203.  
  204.      In fact, there is are rarely exploited points at which integrity 
  205. checking could be layered, either as a hardware ROM extension or as a 
  206. "special" partition table. But while products are known that  enforce 
  207. access  control  and  encryption at this point,  Virus  or  malicious 
  208. software  control  seems an afterthought. Hardware devices  are  also 
  209. expensive.
  210.  
  211.      Should  the access be as intended, the first sector on  a  fixed 
  212. disk  contains  the Partition Table and the program contained  on  it 
  213. defines  the  structure of the disk and  has  information  concerning 
  214. where the Boot Record for the MS-DOS partition is found. Some systems 
  215. such  as the COHERENT operating system will take this opportunity  to 
  216. ask  the  user  if  COHERENT or MS-DOS  is  desired  and  select  the 
  217. appropriate Boot Record matching their choice.
  218.  
  219.      Next  (or  first  if from a floppy disk),  the  Boot  Record  is 
  220. loaded,  again  unconditionally,  and  the program  found  on  it  is 
  221. executed.  Normally,  the  boot record defines the  disks  and  their 
  222. variables, finds the two DOS operating system files, loads them  into 
  223. memory, and transfers control to them.
  224.  
  225.      DOS now examines the data left for it by the previous operations 
  226. and loads handlers for the DOS interrupts including 20h-2Fh. Next DOS 
  227. looks  for an optional file in the root directory  called  CONFIG.SYS 
  228. that  can  contain  device  drivers,  executable  files,  and  system 
  229. parameters. These are loaded and executed again without any integrity 
  230. management. The best current anti-viral programs load as part of  the 
  231. CONFIG  process, already too late to prevent or detect some types  of 
  232. infections.
  233.  
  234.      Finally,  DOS  loads its Command Line  Interpreter,  COMMAND.COM 
  235. which,  as  its first action looks in the root directory for  a  file 
  236. called  AUTOEXEC.BAT, if found, the commands in it will be  executed, 
  237. if not, the familiar requests for Date and Time are presented and DOS 
  238. is ready for use.
  239.  
  240.      At  this point, the machine should have a  stable  configuration 
  241. with   a   certain  amount  of  low-level  memory  in  use   by   the 
  242. parameter/interrupt tables, DOS, and TSR programs. Free memory should 
  243. be  left  to the (normally) 640k/segment A000h boundary, and  vi  deo 
  244. buffers,  hardware  drivers  and the resident part of  the  BIOS  (in 
  245. segment F000h) should reside in the address space above 640k.
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.                             Intrusion
  254.  
  255.      As previously noted, the basic vulnerability of the PC is  found 
  256. in  its  willingness to execute anything properly  presented  to  it. 
  257. There  is  no separation of kernel and user space as  found  in  many 
  258. mainframes and there is no integrity management at all which leads to 
  259. frequent  system  crashes  if anything  not  properly  programmed  is 
  260. executed.
  261.  
  262.      The  ease of subversion of the Boot Sector/Partition  Table  and 
  263. the  fact that this is the first volatile storage that is loaded  and 
  264. executed  makes  this  a  popular target  for  viruses.  Despite  the 
  265. architecture  prescribing  certain  standards  for  such  tables,  no 
  266. checking is done for compliance. This is both good and bad - good  in 
  267. that  few BSI viruses bother to adhere to the standards  making  them 
  268. easy  to  detect on a disk, bad in that integrity  checking  at  this 
  269. point would have detected such viruses early but is not done.
  270.  
  271.      In  view of this, it is surprising that a  commercial  integrity 
  272. management  program  does not yet exist that goes resident  via  this 
  273. means and blocks/detects any attempt to subvert it.
  274.  
  275.      Currently,  the  other target for viruses are  the  applications 
  276. files  that execute under DOS. These are easy detected in  a  "clean" 
  277. DOS environment since for an infection to take place, the files  must 
  278. have experienced a change and this is detectable by nearly any simple 
  279. checksum  routine. Again, unfortunately even though .EXE  files  have 
  280. provision for such a value in the file header, no use is made of it.
  281.  
  282.      Fortunately, two means exist to detect such attacks though  they 
  283. are  not  in DOS. First any attempt to write to  an  executable  file 
  284. should  be  viewed with question. A few programs  (CERTUS,  BEARTRAP, 
  285. FLU-SHOT) do trap such attempts though often the trapping is done  on 
  286. top of DOS and not at the BIOS level. When a program claims to  "trap 
  287. interrupt  13h" the question must be asked *when* and *where*  it  is 
  288. done since DOS traps it from the BIOS first. Again fortunately,  this 
  289. is not important if the virus is not memory resident.
  290.  
  291.  
  292.  
  293.  
  294.  
  295.  
  296.  
  297.                           The Six Bytes
  298.  
  299.      Now  that  knowledge  of  the  structure  of  the  PC  has  been 
  300. established,  examination can be made of the three common  points  of 
  301. "successful" system-infecting viruses and other malicious software in 
  302. terms of detection and the two most important concern residency: Such 
  303. viruses  all become resident and all allocate memory  to  themselves. 
  304. This allocation is detectable.
  305.  
  306.      There  have  been some viruses that have gone  resident  without 
  307. allocating  memory (Icelandic, Alabama, 512) but none of  these  have 
  308. become widespread.
  309.  
  310.      While  the  potential for "new" techniques  exists  and  several 
  311. forms  of malicious software that are not discernable in this  manner 
  312. have  been  postulated,  the following hold true  for  all  currently 
  313. "sucessful" infections.
  314.  
  315.      Memory allocation is done by today's viruses in three ways:
  316. 1) By moving the TOM (top of memory) downward and using the free 
  317.    space. (Brain, Stoned)
  318. 2) By reducing free space beneath the TOM (Datalock, 4096)
  319. 3) By using conventional TSR techniques (Jerusalem, Sunday)
  320.  
  321.      Consequentially, detection of these memory resident viruses is a 
  322. simple matter of checking three values: the TOM (Int 12h return), the
  323. low memory in use (CS: value for a .COM file), and the amount of free 
  324. memory  (Int  21h  Fn  48h with  BX=FFFFh  return).  Of  course  this 
  325. assumes that the user / calling program knows what the memory returns 
  326. are supposed to be. 
  327.  
  328.      The method used by the author is to make the INT 12h call, shift 
  329. the value left six times to convert the number of kilobytes to number 
  330. of  segments  and  store it. Next the Int 21h is  performed  and  the 
  331. number of free segments is added to the CS: value. This should  match 
  332. the  adjusted Int 12h return and match the number of segments in  the 
  333. machine  (A000h for 640k, 8000h for 512k). Any mismatch is cause  for 
  334. concern.
  335.  
  336.      Of course this presupposes two things. First that the amount  of 
  337. memory in the machine is known and that the amount of memory used  by 
  338. the  O/S  and  TSRs is known. Since this is run on every  boot  of  a 
  339. machine  and the memory is most stable immediately following a  boot, 
  340. the expected values are stable. To the technician, eventually a  feel 
  341. for the numbers becomes commonplace.
  342.  
  343.      Currently, the task is made easier since the most recent viruses 
  344. publicly  reported  (Datalock,  MusicBug)  as  well  as  all  of  the 
  345. "stealth"  viruses  (4096, Flip, Whale, Joshi) affect  the  TOM.  For 
  346. these,  detection is a simple as running CHKDSK and knowing what  the 
  347. "total memory" value should be (640k = 655,360 bytes). 
  348.  
  349.      If a virus is found, the size of the discrepancy and the type is 
  350. a  good indication of what it is.  For example, discovery of  a  1792 
  351. byte  unnamed  TSR  in low memory immediately  suggests  a  Jerusalem 
  352.  
  353.  
  354.  
  355.  
  356.  
  357.  
  358. infection.  A 4096 byte loss above the TOM suggests the MusicBug.  In 
  359. any  case, use of tools such as SCAN are in order and the  technician 
  360. now  knows what part of memory is suspect. Where to look when "my  PC 
  361. keeps crashing" is not.
  362.  
  363.                              Summary
  364.  
  365.      We  have  seen how system viruses and other  malicious  software 
  366. rely on two things, the lack of any integrity checking on either  the 
  367. part  of DOS or the user, and the simplicity of creating a "hole"  in 
  368. memory  to  hide  in.  So  far,  those  viruses  that  attempt  other 
  369. concealment or fail to go resident simply have not spread very far.
  370.  
  371.      Since  a  large portion of viruses are "Boot  Sector  Infectors" 
  372. that  become resident before any normal software can  execute,  these 
  373. could  be  difficult  to detect at the DOS  level.  Luckily,  current 
  374. viruses  have  operating  system impacts that  make  them  relatively 
  375. simple  to detect. Hardware ROM extensions or non-standard  partition 
  376. table software would be necessary for increased protection.
  377.  
  378.      Even  at  the user level, integrity checking of attempts  for  a 
  379. program to go resident is a simple matter as a stand-alone and  would 
  380. be  both trivial and fast. Such a check could be incorporated as  one 
  381. layer  of  an integrity shell or Command  Line  Interpreter.  Several 
  382. program  have  attempted  this  in the  past  only  to  fail  through 
  383. excessive screens irritating the user. An "intelligent" program  that 
  384. knows  what  is permitted to go resident and how would be  simple  to 
  385. program and only flag "unregistered" attempts. The surprising fact is 
  386. that no-one seems to have done so as yet.
  387.  
  388.  
  389.  
  390.      Padgett Peterson
  391.      (407)356-4054, 6384 work
  392.      (407)648-0733 FAX
  393.      (407)352-6007 home 
  394. .
  395.