home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS 1992 June / SIMTEL_0692.cdr / msdos / trojanpr / filecrc.arc / FILECRC.DOC < prev    next >
Encoding:
Text File  |  1988-07-18  |  10.0 KB  |  232 lines

  1.  
  2.                              FILECRC
  3.  
  4.                            30 May 1988
  5.                            Ted H. Emigh
  6.  
  7.  
  8.      FILECRC is a program to help detect when files have been 
  9. corrupted.  FILECRC creates a list of all the files on the 
  10. default drive along with creation date, file size, and a CRC 
  11. (cyclic redundancy check) for each file.  When FILECRC is run at 
  12. a later time, it creates a new list.  COMPARE compares this new 
  13. list to the old list.  For any file, it is possible that:
  14.  
  15. 1)   The file is completely unchanged from the previous time.  
  16.      The file name (and directory entry) are the same at the two 
  17.      times, and it has not been modified.  Files of this sort are 
  18.      counted.
  19.  
  20. 2)   The file has been modified in the normal manner, so that the 
  21.      directory entry has a new time of creation.  Files of this 
  22.      sort are counted and their names are put in the file 
  23.      FILES$$$.UPD.
  24.  
  25. 3)   The file has been deleted in the time since the first time 
  26.      FILECRC was run.  Files of this sort are counted and their 
  27.      names are put in the file FILES$$$.DEL.
  28.  
  29. 4)   A new file has appeared that was not on the disk at the time 
  30.      of the previous run of FILECRC.  Files of this sort are 
  31.      counted, and a list is placed in the file FILES$$$.NEW.  
  32.      While it is usual to find new files on the disk, this gives 
  33.      an easy way to keep track of what files are new, and where 
  34.      they are located.  This is important when using public 
  35.      domain programs to make sure they are not creating new files 
  36.      without you knowing about it.  If a file is moved from one 
  37.      directory to another, then it will appear on both lists 
  38.      FILES$$$.DEL and FILES$$$.NEW.
  39.  
  40. 5)   The directory entry for a file is the same for both of the 
  41.      times the program was run, but the file was modified in some 
  42.      way.  This should not occur in normal practice, so the 
  43.      program writes a message to the terminal, and a list of 
  44.      these files is placed in the file FILES$$$.MOD.  This can 
  45.      occur when you use NORTON UTILITIES, or other such programs 
  46.      to modify the disk directly, bypassing the normal DOS 
  47.      handling of the files.  It also can happen when programs 
  48.      'run wild' (this is what prompted me to write this program 
  49.      in the first place).
  50.  
  51. 6)   In addition, there are several files that are so important 
  52.      to your computer that you need to know if they are changed 
  53.      in any way.  I call these sensitive files, and if any are 
  54.      changed, you are alerted.  Their names can be found in the 
  55.      file FILECRC.OUT.
  56.  
  57.      Running the program prior to each backup will assure you 
  58. that you are not backing up files that have been corrupted.  
  59. Also, in program development, running the program before and 
  60. after a test run of your program can assure you that your program 
  61. has not messed up the disk.
  62.  
  63.  
  64.                          RUNNING FILECRC
  65.  
  66.      There are four files associated with FILECRC:
  67. FILECRC.COM -- Calculates CRCs for all files on the default disk.
  68. COMPARE.COM -- Compares CRCs from successive runs of FILECRC.
  69. SENSITIV    -- A list of all the sensitive files.
  70. CRC.BAT     -- A batch file for running FILECRC and COMPARE.
  71.  
  72. FILECRC
  73.  
  74.      FILECRC is run without command line parameters.  It will 
  75. create CHECK$$$.NEW (or CHECK$$$.CRC if the file does not exist 
  76. in the default directory), which is a list of all the files on 
  77. the default disk in all directories, along with their attribute, 
  78. date and time of creation, size, and CRC.  FILECRC displays the 
  79. directory names as it goes through them.  If you wish to compare 
  80. the files to a previous run of FILECRC, you need to run COMPARE.
  81.  
  82. COMPARE [NEWLIST.FIL [OLDLIST.FIL]]
  83.  
  84.      Compare will compare the files in CHECK$$$.NEW with those in 
  85. CHECK$$$.CRC, noting any differences.  When COMPARE is finished, 
  86. the old file list now will be called CHECK$$$.OLD, and the newly 
  87. created one will be called CHECK$$$.CRC.  If NEWLIST.FIL is 
  88. given, this will be used instead of CHECK$$$.NEW, and, if given, 
  89. OLDLIST.FIL will be used instead of CHECK$$$.CRC.  For example,
  90. COMPARE CHECK
  91. will check the file CHECK with CHECK$$$.CRC.  If any command line 
  92. files are given, then CHECK$$$.CRC will not be renamed.
  93.  
  94.      SENSITIV is a file which contains the names of all the files 
  95. which you consider to be sensitive (up to 30 files, in the 
  96. distributed version).  Compare will alert you of ANY changes in 
  97. the files listed in SENSITIV.  They must be in the specific 
  98. format:
  99. DRIVE:\PATH\FILENAME
  100. with one file per line, all in capitals.  (The format of SENSITIV 
  101. is NOT the same as for CHECK$$$.CRC).  My SENSITIV file looks 
  102. like:
  103.  
  104. C:\AUTOEXEC.BAT
  105. C:\COMMAND.COM
  106. C:\CONFIG.SYS
  107. C:\IBMBIO.COM
  108. C:\IBMDOS.COM
  109. C:\BIN\BOOT\NANSI.SYS
  110. C:\BIN\BOOT\FASTDISK.SYS
  111. C:\BIN\BOOT\RCD.SYS
  112. C:\USR\LOCAL\BIN\WATCH
  113. C:\USR\BIN\SEARCH
  114. C:\USR\LOCAL\BIN\TIMEPARK
  115. C:\USR\BIN\HGC
  116. C:\BIN\MODE
  117. C:\USR\BIN\SUPERSPL
  118. C:\USR\LOCAL\BIN\FMARK
  119.  
  120. You should include in this list all files which you consider 
  121. particularly important, and which ANY change may compromise your 
  122. computer.  I include all my files that are used at boot time, as 
  123. well as any TSR (Terminate and Stay Resident) programs that I 
  124. use.
  125.  
  126.  
  127.      Several files are created by COMPARE:
  128.  
  129. 1)   FILES$$$.NEW   A list of the names of the newly created 
  130.      files.
  131. 2)   FILES$$$.DEL   A list of the names of the deleted files.
  132. 3)   FILES$$$.UPD   A list of the names of files that were 
  133.      updated in the "normal" DOS manner.
  134. 4)   FILES$$$.MOD   A list of the names of files that have been 
  135.      modified in a "NON DOS" manner.
  136. 5)   FILECRC.OUT    A file containing the output of COMPARE -- 
  137.      This lists all the changes in the SENSITIVE files and all 
  138.      files modified in a "NON DOS" manner, as well as summary 
  139.      statistics.
  140.  
  141.  
  142.              USING FILECRC TO PROTECT AGAINST VIRUSES
  143.  
  144.      If you plan to use FILECRC to help in the detection of 
  145. damage done by viruses, you need to make sure you start with a 
  146. clean disk.  Erase all the files on the disk (de-installing any 
  147. commercial software you may have), FORMAT the disk and put on 
  148. clean system files from your DOS distribution disks.  Copy all 
  149. the DOS files you use from the distribution disk and reboot the 
  150. system.  Reinstall all your commercial or "safe" software from 
  151. the original distribution disks.  Run FILECRC and COMPARE a 
  152. couple of times during the process.
  153.      To "check out" a new piece of software, run FILECRC and 
  154. COMPARE; then run your new software; finally, run FILECRC and 
  155. COMPARE again.  Look at ALL the FILES$$$ lists, to make sure the 
  156. software is not changing files it shouldn't be touching.  Run 
  157. FILECRC and COMPARE periodically and look at the FILES$$$.UPD 
  158. list.
  159.  
  160.      Notice:  Due to a "feature" in Turbo Pascal 3.0, each file 
  161. being checked is opened for reading and writing, even though the 
  162. program only reads the file.  This will set off alarms on some 
  163. virus detection programs.  In addition, the file attributes are 
  164. changed, then restored.  This may also set off some alarms.
  165.  
  166.      Remember that FILECRC and COMPARE are useful only if run 
  167. often.  If you plan to make changes to files listed in SENSITIV, 
  168. then run FILECRC/COMPARE before changing them.  Then change the 
  169. files.  Finally, run FILECRC/COMPARE again to "register" their 
  170. new CRCs.
  171.  
  172.      To help to protect against viruses aimed specifically at 
  173. this program -- you will need to change the value of POLY in 
  174. FILECRC.PAS and COMPARE.PAS.  If you know what CRC is computed to 
  175. check for viruses, you can make your virus modify the file and 
  176. maintain the same CRC.  If everyone uses their own CRC, then a 
  177. virus aimed at this program will not work.
  178.  
  179.  
  180.                         PROGRAMMING NOTES
  181.  
  182.  
  183.      FILECRC is written in Pascal and compiled with Turbo Pascal, 
  184. Version 3.0 for MSDOS.  It has been tested on an IBM PC/AT using 
  185. DOS 3.10.  This program is not meant to represent the epitome of 
  186. programming skill, but it works.  Any improvements and 
  187. suggestions are welcome, particularly if you can improve the 
  188. speed.  On my PC/AT with some 860 files occupying 16.5MB the 
  189. program takes about 5-1/4 minutes to complete.  I am convinced 
  190. that FILECRC.COM cannot be improved significantly on speed (take 
  191. that as a challenge, if you wish), but COMPARE.COM is relatively 
  192. inefficient (but then of the 5-1/4 minutes, about 5 minutes are 
  193. spent in FILECRC.COM).  Programming notes in the programs are 
  194. sparse, but I specifically set separate routines for handling 
  195. each of the file comparison types in COMPARE (use the procedures 
  196. file_new, file_deleted, file_updated, file_OK, and bad_CRC if you 
  197. would like to do something special for each file comparison 
  198. type).  The procedure sensitive checks to see if changed files 
  199. are in the sensitive list.
  200.  
  201.      FILECRC will work with any number of files or directories.  
  202. As written, COMPARE has a maximum of 200 directories and 1750 
  203. files with any number of files within any particular directory.  
  204. The maximum length of the directory name string is 64 characters.  
  205. I have used the program on subdirectories up to 10 levels deep 
  206. without any problems.  These values for the number of directories 
  207. and the number of files uses up just about as much memory as 
  208. TURBO Pascal allows, so an increase in these numbers would 
  209. necessitate a redesign of the program.
  210.  
  211. To increase speed, check for ^C is only done once per directory.
  212. Special thanks go to David Dantowitz of Digital Equipment 
  213. Corporation (Dantowitz%eagle1.dec@decwrl) for providing the CRC 
  214. routines (generate_table_256 and crc_string_256) and the routines 
  215. for getting a directory (get_DTA, set_DTA, find_first, and 
  216. find_next).  Of course, he takes no responsibility for the way I 
  217. used his code.
  218.  
  219.  
  220. Ted H. Emigh
  221. Department of Genetics
  222. North Carolina State University
  223. Box 7614
  224. Raleigh, NC   27695-7614
  225.  
  226. emigh@ncsugn.uucp
  227. emigh@ncsugn.ncsu.edu
  228. NEMIGH@TUCC.BITNET
  229.  
  230. Contact me at one of the above addresses if you would like to get 
  231. a "clean" copy.
  232.