home *** CD-ROM | disk | FTP | other *** search
/ The Hacker's Encyclopedia 1998 / hackers_encyclopedia.iso / pc / virus / yetspoly.doc < prev   
Encoding:
Internet Message Format  |  2003-06-11  |  15.0 KB

  1. Date: Fri, 30 Apr 1993 19:43:34 -0400
  2. From: tyetiser@umbc.edu (Mr. Tarkan Yetiser)
  3. Subject: Polymorphic Viruses
  4.  
  5.       Polymorphic Viruses: Implementation, Detection, and Protection
  6.                          
  7.                               Copyright (c) 1993
  8.                                  
  9.                                       by
  10.                   
  11.                           VDS Advanced Research Group
  12.                                 P.O. Box 9393
  13.                           Baltimore, MD 21228, U.S.A.
  14.  
  15.                                   prepared by
  16.                           
  17.                                 Tarkan Yetiser
  18.                     
  19.                         e-mail: tyetiser@umbc5.umbc.edu
  20.         
  21.                                 Jan 24, 1993
  22.                                   PA, U.S.A.                           
  23.  
  24.  
  25.                                    Summary
  26.                               
  27. This paper discusses the subject of polymorphic engines and viruses. It looks 
  28. at general characteristics of polymorphism as currently implemented. It tries 
  29. to maintain a practical presentation of the subject matter rather than an 
  30. academic and abstract approach that would confuse many people. Basic 
  31. knowledge of the Intel 80x86 instruction set will be highly useful in 
  32. understanding the material presented. A very detailed discussion is avoided 
  33. not to have the side effect of "teaching" how to create polymorphic engines 
  34. or viruses. The purpose is to help computer professionals understand this 
  35. trend of virus development and the threats it poses. It should serve as a 
  36. starting point for individuals who would like to get an idea about the 
  37. polymorphic viruses and how they are implemented. Long gone are the days of 
  38. innocence, when any schoolboy could write a virus scanner using a few 
  39. signatures extracted from captured virus samples.
  40.  
  41. The subject of polymorphism can be extended to other areas such as 
  42. anti-reverse-engineering or anti-direct-attacks, and it can be argued to be 
  43. useful in that context. This paper only looks at the use of polymorphism in 
  44. PC viruses to avoid simple detection techniques.
  45.  
  46.  
  47.  
  48. 1. Introduction
  49.  
  50.    In the Spring of 1992, we analyzed a polymorphic engine called MtE, and 
  51. provided a report to satisfy the curiosity of the public. We also provided a 
  52. freeware program called CatchMtE. At the end of 1992, we received reports  
  53. of a new polymorphic engine, called TridenT Polymorphic Engine, or TPE for 
  54. short. It was released in Europe by someone who calls himself Masud Khafir.
  55.  
  56.    Both MtE and TPE are distributed as object modules that can be linked to 
  57. programs allowing them to create different-looking decryptors. One notorious
  58. use of such a module is for writing so-called "polymorphic" viruses. Prior 
  59. to the appearance of TPE, several viruses using MtE (Mutation Engine) have 
  60. been seen. The claimed author of TPE pays tribute to the author of MtE in the
  61. documentation that comes with TPE.
  62.  
  63.    MtE is about 2.4 kilobytes in size. It can generate decyptors using based 
  64. or indexed addressing modes with word-size displacement. The decryptor steps 
  65. through the code a word at a time. It uses 4 variations of the based or 
  66. indexed addressing modes. The structure of the decryptors is constant.
  67.  
  68.    TPE is about 1.5 kilobytes in size. It can generate decryptors using based
  69. or  indexed addressing modes with or without displacement. Unlike MtE, TPE 
  70. can also create byte-at-a-time decryptors, as well as word-at-a-time. It also
  71. uses more addressing modes available on the 80x86; 6 variations of the based 
  72. or indexed addressing modes are used. Its more general nature makes TPE less 
  73. predictable, and complicates the task of recognizing TPE-based viruses. Many 
  74. encryptive viruses can be considered a subset of TPE-based decryptors, and 
  75. may be flagged as such. To overcome this problem, one has to check for other 
  76. viruses before performing check for the presence of a TPE decryptor.
  77.  
  78. 2. Polymorphism and Its Common Use
  79.  
  80.    We will now present some preliminary information on polymorphism in 
  81. general, and discuss certain features of the Intel 80x86 instruction set. 
  82.    
  83.    Although polymorphism is independent of encryption, it is easier to use 
  84. encryption to hide the main body of the virus and implement a polymorphic 
  85. decryptor. Viruses aim to keep their size as small as possible and it is 
  86. impractical to make the main virus body  polymorphic. One could attempt to 
  87. rearrange the instructions in the main virus body or  even use different 
  88. instructions (to defy recognition techniques based on checksumming). Such an 
  89. effort would not be as helpful or as easy as the common approach of using 
  90. encryption in combination with polymorphism. In summary, current polymorphic 
  91. viruses keep the main virus body encrypted, and implement a polymorphic 
  92. decryption routine in plaintext. Since the decryptor is comparatively small, 
  93. and performs one specific task, the amount of time and effort needed to 
  94. craft a polymorphic virus is significantly reduced. Pictorially, a generic 
  95. polymorphic virus would be structured as follows: 
  96.  
  97.  
  98.    virus entry point:
  99.          Polymorphic Decryptor                     
  100.       *****************************
  101.       ** encrypted ****************
  102.       ** main virus body **********
  103.       *****************************
  104.       *****************************
  105.                      
  106.  
  107. 3. Implementation of Polymorphism on the Intel 80x86
  108.  
  109.    In almost every case we have examined, the polymorphic engine exploits the
  110. fact that certain computations can be performed using different registers and
  111. instructions. To  step through encrypted portion of code, for example, one 
  112. can use DI, SI, or BX registers. To increment or to decrement the index value,
  113. one can ADD to the index register, INC it, or use an implicit instruction that
  114. increments it (CMPSB is used in TPE for example).
  115.    
  116.    Polymorphic engines can also rely on the availability of instructions that
  117. are coded using the same opcodes. On the 80x86, there are 11 opcodes used for
  118. several different instructions: 80, 81, 83, D0, D1, D2, D3, F6, F7, FE, and 
  119. FF. When it is necessary to encode information about one operand, the middle 
  120. three bits of the ModRM byte are used to distinguish operations. The ModRM 
  121. byte follows some opcodes and can either extend the opcode or contain 
  122. information about the operand and addressing modes of an  instruction. It 
  123. contains three fields: Mod (2 bits), Reg (3 bits), and R/M (3 bits). For  
  124. example, for the opcode 80, the middle three bits of the ModRM byte, which 
  125. make up the Reg field, have the following meanings: 
  126.  
  127.      ADD    000
  128.      OR     001
  129.      ADC     010
  130.      SBB     011
  131.      AND     100
  132.      SUB     101
  133.      XOR     110
  134.      CMP     111
  135.     
  136.    The second operand of each instruction with an opcode of 80 is an  
  137. immediate byte, so the ModRM fields in the second byte of machine code encode
  138. the first register or memory operand.
  139.  
  140.    By flipping a few bits, it is possible to generate code achieving many 
  141. different operations easily. Combined with a rich set of addressing modes, 
  142. and a good random number generator, one can create very different-looking 
  143. decryptors.
  144.  
  145. 4. Common Characteristics of Polymorphic Viruses
  146.  
  147.    Polymorphic viruses of varying degrees of complexity have appeared in the 
  148. past. In the anti-virus community, polymorphism is still an active area of  
  149. discussion and much disagreement. Most researchers would agree that certain 
  150. viruses are simply encryptive with a variable key. We do not consider such 
  151. beasts polymorphic since they can be recognized using simple wild card scan 
  152. strings. The number of such viruses significantly increased over the past few 
  153. years as a reaction to the worldwide availability of good signature-based 
  154. virus scanners. Similarly, scanners also evolved to handle such beasts using
  155. more flexible signatures that can include wild card or don't-care values to 
  156. accommodate the variable parts of the decryptors.
  157.  
  158.    There are other viruses that exhibit some polymorphic behavior, though 
  159. they remain unsophisticated. Classification of such beasts is a gray area.  
  160. For example, some viruses can generate a limited number of different-looking 
  161. decryptors. These do not implement a polymorphic code generation engine, but 
  162. rather pick from a pre-computed set of code fragments that they carry along. 
  163. Writing detection routines for such viruses is not too difficult. 
  164.  
  165.    To aid in implementing polymorphism, a random-number generator is often 
  166. used. A random-number generator provides selection of a part of the decryptor.
  167. This selection could be for "noise" instructions that are inserted in the 
  168. decryptor to render signature-based scanning ineffective. It could also be 
  169. used to select a certain addressing mode and  appropriate registers. The 
  170. obvious use of random number generators is to get a seed value for encryption.
  171.  
  172.    Another aspect of a polymorphic engine is the choice of instructions that 
  173. actually perform the decryption. XOR is a favorite choice. The chosen 
  174. operation modifies the code to be decrypted using an addressing mode that 
  175. allows external memory access. By external, we mean outside the processor 
  176. registers. By using several instructions and many different addressing modes, 
  177. a polymorphic engine can achieve a large number of combinations of decryptors.
  178.  
  179.    Usually, a loop construct is set up to step through the encrypted code. On
  180. the 80x86, many instructions can be used to accomplish looping. The loop 
  181. counter can be modified implicitly using LOOP instruction. Or it could be 
  182. more explicit using a DEC CX, JNZ ?? combination. Several such possibilities 
  183. exist. Again, availability of different approaches increases the number of 
  184. appearances a decryptor can have. In the MtE, the loop construct was very 
  185. predictable not only because it used a specific instruction but also because 
  186. it had a characteristic that made it very simple to recognize MtE-based 
  187. decryptors. Although "appearance-based" analysis on the MtE left many 
  188. anti-virus developers in despair, a structural analysis proved to be very 
  189. effective. We doubt even the developer of MtE noticed how predictable his 
  190. polymorphic engine is.
  191.  
  192.    The goal of a polymorphic engine is not to leave any predictable sequence 
  193. of instructions that a virus scanner can use to simplify or optimize an 
  194. appropriate detection algorithm. For example, using the same instruction to 
  195. increment the index register is too predictable. A mixture of instructions 
  196. that achieve the same result explicitly or implicitly (as in TPE) would make 
  197. detection a lot harder.
  198.  
  199. 5. Detection of Polymorphic Viruses
  200.  
  201.    There are several problems that must be addressed to develop a reliable 
  202. detection routine for a given polymorphic engine. The most challenging one 
  203. appears to be avoiding false positives. Many programs include a run-time 
  204. decompressor to reduce space requirements. When loaded in memory, the 
  205. decompressor takes charge and produces an expanded copy of the code that can 
  206. be run on the CPU. Furthermore, some programs are actually encrypted on disk, 
  207. and they are decrypted on the fly when they are loaded. The purpose of using 
  208. such a scheme is to make reverse-engineering efforts difficult. Such programs
  209. are more likely to trigger a false positive.
  210.  
  211.    To reduce false positive rate, one can limit the search to a small area of 
  212. the suspect file. This would be helpful in many cases; however, the compressed
  213. and encrypted files carry their decompressor/decryptor at the entry point of 
  214. the program, just where many viruses plant their code. Another trick a few 
  215. viruses employ is to hide the virus entry point where the decryptor is 
  216. located. Of course, scattering the virus code while keeping the host 
  217. functional complicates the virus.
  218.  
  219.    A structural analysis of TPE reveals some information that can be used to 
  220. recognize a TPE-based decryptor, although it is not as useful as it is in the
  221. case of MtE. Note that structural analysis does not rely on presence of 
  222. specific byte sequences, and therefore offers a powerful tool that can be 
  223. used in developing recognition routine for many polymorphic engines. 
  224.  
  225. 6. Protection Mechanisms and Solutions
  226.  
  227.    Anti-virus field is full of solutions to almost every existing virus 
  228. problem, and sometimes solutions to non-existing problems as well. Among 
  229. other things, one solution prevailed as the most popular: scanning. The 
  230. inherent flaw in this solution is that it cannot cope with viruses that it 
  231. does not have signatures for. Therefore ugrades are issued frequently. 
  232. Deployment of such upgrades in large installations requires tremendous 
  233. effort, and quickly translates into having a very old version of a scanner 
  234. installed; even then not necessarily used. Aside from the false sense of  
  235. security scanning gives, some companies make less-than-honest claims about 
  236. the capabilities of their scanners to promote their products. Testing such 
  237. claims is beyond the resources of most organizations. Those who could conduct
  238. such tests are not always impartial.
  239.  
  240.    Scanning has its place, and it is very useful when used properly. The best
  241. protection against computer viruses is user awareness and education. 
  242. Unfortunately, a well-written virus can be so transparent that even the most 
  243. observant user may not notice a thing. Even worse, many users lack the 
  244. technical knowledge to understand how their computers work. Most people simply 
  245. do not have the time or desire to learn more than how to use a mouse. The 
  246. proof of this is the proliferation of products that make excessive hardware 
  247. demands without offering improved functionality. The bulk of the code takes 
  248. care of the user interface. This trend is unlikely to change.
  249.  
  250.    More powerful techniques such as integrity checking can deal with viruses 
  251. of different kinds, including polymorphic viruses. Even a simple integrity 
  252. checker should be able to find if a polymorphic virus is spreading all over 
  253. your disk. In other words, solution to polymorphic viral spread has been 
  254. available for quite some time. Note that there are some viruses that target 
  255. integrity-based products and they must be dealt with accordingly. A detailed
  256. discussion of such viral methods can be found in a paper written by anti-virus
  257. researcher Mr. Vesselin Bontchev of Virus Test Center at the University of 
  258. Hamburg. His paper is titled Attacks Against Integrity Checkers, and it is 
  259. available via anonymous FTP. Interested individuals are encouraged to read 
  260. his excellent paper.
  261.  
  262.    The point is that an integrity-based anti-viral solution should be made 
  263. part of your arsenal against viruses. Such a solution could easily provide 
  264. you with early detection of viruses before they spread. Once the viral spread
  265. is controlled, viruses become nothing more than another "computer glitch" that
  266. can haunt only those without timely backups.
  267.  
  268.    We believe that neither harsh legislation nor emphasis on responsible 
  269. computing can stop virus development, although they may slow it down. It is 
  270. necessary to take matters into your own hands and protect your computers 
  271. adequately.   
  272.