home *** CD-ROM | disk | FTP | other *** search
/ Hacker 2 / HACKER2.mdf / virus / ps_vir1.txt < prev    next >
Text File  |  1995-01-03  |  20KB  |  448 lines

  1.     //==//  //  //  /||      //      //====  //==//  //|   //
  2.    //  //  //  //  //||     //      //      //  //  //||  //
  3.   //==//  //==//  //=||    //      //      //  //  // || //
  4.  //      //  //  //  ||   //      //      //  //  //  ||//
  5. //      //  //  //   ||  //====  //====  //==//  //   ||/
  6.  
  7. -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  8. DISCLAIMER: The author hereby disclaims himself
  9. -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  10. DEDICATION: This was written to make the lives
  11.   of scum such as Patty Hoffman, John McAffee,
  12.   and Ross Greenberg a living hell.
  13. -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  14. OTHER STUFF:  Thanks go to The Shade of Sorrow,
  15.   Demogorgon, and Orion Rouge on their comments
  16.   (which I occasionally listened to!).   Thanks
  17.   also to Hellraiser, who gave me an example of
  18.   some virus source code (his own, of course).
  19. -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  20.  
  21. Dark Angel's Phunky Virus Writing Guide
  22. ---- ------- ------ ----- ------- -----
  23. Virii are  wondrous creations written for the sole purpose of spreading and
  24. destroying the  systems of unsuspecting fools.  This eliminates the systems
  25. of simpletons  who can't  tell that there is a problem when a 100 byte file
  26. suddenly blossoms  into a  1,000 byte  file.   Duh.  These low-lifes do not
  27. deserve to  exist, so  it is  our sacred duty to wipe their hard drives off
  28. the face of the Earth.  It is a simple matter of speeding along survival of
  29. the fittest.
  30.  
  31. Why did  I create  this guide?  After writing several virii, I have noticed
  32. that virus  writers generally  learn how to write virii either on their own
  33. or by  examining the  disassembled code  of  other  virii.    There  is  an
  34. incredible lack  of information  on the  subject.   Even books published by
  35. morons such as Burger are, at best, sketchy on how to create a virus.  This
  36. guide will show you what it takes to write a virus and also will give you a
  37. plethora of source code to include in your own virii.
  38.  
  39. Virus writing  is not  as hard  as you  might first  imagine.   To write an
  40. effective virus,  however, you  *must*  know  assembly  language.    Short,
  41. compact code  are hallmarks  of assembly  language and  these are desirable
  42. characteristics of  virii.  However, it is *not* necessary to write in pure
  43. assembly.   C may  also be  used, as  it allows almost total control of the
  44. system while  generating relatively compact code (if you stay away from the
  45. library functions).   However,  you still  must access  the interrupts,  so
  46. assembly knowledge  is still  required.  However, it is still best to stick
  47. with pure  assembly,  since  most  operations  are  more  easily  coded  in
  48. assembly.  If you do not know assembly, I would recommend picking up a copy
  49. of The Microsoft Macro Assembler Bible (Nabajyoti Barkakati, ISBN #: 0-672-
  50. 22659-6).   It is an easy-to-follow book covering assembly in great detail.
  51. Also get yourself a copy of Undocumented DOS (Schulman, et al, ISBN #0-201-
  52. 57064-5), as it is very helpful.
  53.  
  54. The question  of which  compiler to  use arises  often.   I  suggest  using
  55. Borland Turbo  Assembler and/or  Borland C++.   I  do not  have a  copy  of
  56. Zortech C  (it was  too large  to download), but I would suspect that it is
  57. also a good choice.  Stay away from Microsoft compilers, as they are not as
  58. flexible nor as efficient as those of other vendors.
  59.  
  60. A few more items round out the list of tools helpful in constructing virii.
  61. The latest version of Norton Utilities is one of the most powerful programs
  62. available, and  is immeasurably  helpful.   MAKE SURE YOU HAVE A COPY!  You
  63. can find  it on  any decent board.  It can be used during every step of the
  64. process, from  the writing  to the testing.  A good debugger helps.  Memory
  65. management  utilities   such  as   MAPMEM,  PMAP,   and  MARK/RELEASE,  are
  66. invaluable, especially  when coding  TSR virii.   Sourcer,  the  commenting
  67. disassembler, is  useful when  you wish  to examine the code of other virii
  68. (this is a good place to get ideas/techniques for your virus).
  69.  
  70. Now that  you have  your tools,  you are  ready to  create a  work  of  art
  71. designed to smash the systems of cretins.  There are three types of virii:
  72.  
  73.      1) Tiny virii (under 500 bytes) which are designed to be  undetectable
  74.         due to their small size.   TINY  is  one  such  virus.    They  are
  75.         generally very simple because their code length is so limited.
  76.      2) Large  virii  (over 1,500 bytes)   which   are   designed   to   be
  77.         undetectable because they cover their tracks very  well  (all  that
  78.         code DOES have a use!).  The best example  of  this  is  the  Whale
  79.         virus, which is perhaps the best 'Stealth' virus in existence.
  80.      3) Other virii which are not designed to be hidden at all (the writers
  81.         don't give  a  shit).    The  common  virus  is  like  this.    All
  82.         overwriting virii are in this category.
  83.  
  84. You must  decide which  kind of  virus you wish to write.  I will mostly be
  85. discussing  the  second  type  (Stealth  virii).    However,  many  of  the
  86. techniques discribed  may be easily applied to the first type (tiny virii).
  87. However, tiny  virii generally do not have many of the "features" of larger
  88. virii, such  as  directory  traversal.    The  third  type  is  more  of  a
  89. replicating trojan-type,  and will  warrant a  brief  (very,  very  brief!)
  90. discussion later.
  91.  
  92. A virus may be divided into three parts: the replicator, the concealer, and
  93. the bomb.   The  replicator part  controls the spread of the virus to other
  94. files, the concealer keeps the virus from being detected, and the bomb only
  95. executes when  the activation  conditions of the virus (more on that later)
  96. are satisfied.
  97.  
  98. -=-=-=-=-=-=-=-
  99. THE REPLICATOR
  100. -=-=-=-=-=-=-=-
  101. The job  of the  replicator is to spread the virus throughout the system of
  102. the clod  who has caught the virus.  How does it do this without destroying
  103. the file it infects?  The easiest type of replicator infects COM files.  It
  104. first saves  the first  few bytes  of the  infected file.  It then copies a
  105. small portion of its code to the beginning of the file, and the rest to the
  106. end.
  107.  
  108.   +----------------+      +------------+
  109.   | P1 | P2        |      | V1 | V2    |
  110.   +----------------+      +------------+
  111.  The uninfected file     The virus code
  112.  
  113. In the  diagram, P1 is part 1 of the file, P2 is part 2 of the file, and V1
  114. and V2  are parts 1 and 2 of the virus.  Note that the size of P1 should be
  115. the same  as the size of V1, but the size of P2 doesn't necessarily have to
  116. be the  same size  as V2.   The  virus first  saves P1 and copies it to the
  117. either 1)  the end  of the  file or 2) inside the code of the virus.  Let's
  118. assume it copies the code to the end of the file.  The file now looks like:
  119.  
  120.   +---------------------+
  121.   | P1 | P2        | P1 |
  122.   +---------------------+
  123.  
  124. Then, the  virus copies  the first  part of  itself to the beginning of the
  125. file.
  126.  
  127.   +---------------------+
  128.   | V1 | P2        | P1 |
  129.   +---------------------+
  130.  
  131. Finally, the virus copies the second part of itself to the end of the file.
  132. The final, infected file looks like this:
  133.  
  134.   +-----------------------------+
  135.   | V1 | P2        | P1 | V2    |
  136.   +-----------------------------+
  137.  
  138. The question  is: What  the fuck  do V1 and V2 do?  V1 transfers control of
  139. the program to V2.  The code to do this is simple.
  140.  
  141.      JMP FAR PTR Duh       ; Takes four bytes
  142. Duh  DW  V2_Start          ; Takes two bytes
  143.  
  144. Duh is  a far pointer (Segment:Offset) pointing to the first instruction of
  145. V2.   Note that  the value  of Duh must be changed to reflect the length of
  146. the file  that is  infected.   For example,  if the  original size  of  the
  147. program is  79 bytes,  Duh must  be changed  so  that  the  instruction  at
  148. CS:[155h] is  executed.   The value of Duh is obtained by adding the length
  149. of V1,  the original size of the infected file, and 256 (to account for the
  150. PSP).  In this case, V1 = 6 and P1 + P2 = 79, so 6 + 79 + 256 = 341 decimal
  151. (155 hex).
  152.  
  153. An alternate, albeit more difficult to understand, method follows:
  154.  
  155.      DB 1101001b              ; Code for JMP (2 byte-displacement)
  156. Duh  DW V2_Start - OFFSET Duh ; 2 byte displacement
  157.  
  158. This inserts  the jump  offset directly  into the  code following  the jump
  159. instruction.  You could also replace the second line with
  160.  
  161.      DW V2_Start - $
  162.  
  163. which accomplishes the same task.
  164.  
  165. V2 contains the rest of the code, i.e. the stuff that does everything else.
  166. The last  part of  V2 copies  P1 over  V1 (in memory, not on disk) and then
  167. transfers control  to the  beginning of the file (in memory).  The original
  168. program will  then run happily as if nothing happened.  The code to do this
  169. is also very simple.
  170.  
  171.      MOV SI, V2_START      ; V2_START is a LABEL marking where V2 starts
  172.      SUB SI, V1_LENGTH     ; Go back to where P1 is stored
  173.      MOV DI, 0100h         ; All COM files are loaded @ CS:[100h] in memory
  174.      MOV CX, V1_LENGTH     ; Move CX bytes
  175.      REP MOVSB             ; DS:[SI] -> ES:[DI]
  176.  
  177.      MOV DI, 0100h
  178.      JMP DI
  179.  
  180. This code assumes that P1 is located just before V2, as in:
  181.  
  182. P1_Stored_Here:
  183.      .
  184.      .
  185.      .
  186. V2_Start:
  187.  
  188. It also  assumes ES  equals CS.  If these assumptions are false, change the
  189. code accordingly.  Here is an example:
  190.  
  191.      PUSH CS               ; Store CS
  192.      POP  ES               ;  and move it to ES
  193.                            ; Note MOV ES, CS is not a valid instruction
  194.      MOV SI, P1_START      ; Move from whereever P1 is stored
  195.      MOV DI, 0100h         ;  to CS:[100h]
  196.      MOV CX, V1_LENGTH
  197.      REP MOVSB
  198.  
  199.      MOV DI, 0100h
  200.      JMP DI
  201.  
  202. This code  first moves CS into ES and then sets the source pointer of MOVSB
  203. to where  P1 is located.  Remember that this is all taking place in memory,
  204. so you  need the  OFFSET of P1, not just the physical location in the file.
  205. The offset  of P1  is 100h  higher than  the physical file location, as COM
  206. files are loaded starting from CS:[100h].
  207.  
  208. So here's a summary of the parts of the virus and location labels:
  209.  
  210. V1_Start:
  211.      JMP FAR PTR Duh
  212. Duh  DW  V2_Start
  213. V1_End:
  214.  
  215. P2_Start:
  216. P2_End:
  217.  
  218. P1_Start:
  219.   ; First part of the program stored here for future use
  220. P1_End:
  221.  
  222. V2_Start:
  223.   ; Real Stuff
  224. V2_End:
  225.  
  226. V1_Length EQU V1_End - V1_Start
  227.  
  228. Alternatively, you could store P1 in V2 as follows:
  229.  
  230. V2_Start:
  231.  
  232. P1_Start:
  233. P1_End:
  234.  
  235. V2_End:
  236.  
  237. That's all there is to infecting a COM file without destroying it!  Simple,
  238. no?   EXE files,  however, are a little tougher to infect without rendering
  239. them inexecutable - I will cover this topic in a later file.
  240.  
  241. Now let  us turn our attention back to the replicator portion of the virus.
  242. The steps are outlined below:
  243.  
  244.      1) Find a file to infect
  245.      2) Check if it is already infected
  246.      3) If so, go back to 1
  247.      4) Infect it
  248.      5) If infected enough, quit
  249.      6) Otherwise, go back to 1
  250.  
  251. Finding a  file to  infect is  a  simple  matter  of  writing  a  directory
  252. traversal procedure  and issuing  FINDFIRST  and  FINDNEXT  calls  to  find
  253. possible files  to infect.   Once  you find  the file, open it and read the
  254. first few  bytes.   If they are the same as the first few bytes of V1, then
  255. the file  is already  infected.  If the first bytes of V1 are not unique to
  256. your virus,  change it  so that they are.  It is *extremely* important that
  257. your virus  doesn't reinfect  the same  files, since that was how Jerusalem
  258. was first  detected.   If the file wasn't already infected, then infect it!
  259. Infection should take the following steps:
  260.  
  261.      1) Change the file attributes to nothing.
  262.      2) Save the file date/time stamps.
  263.      3) Close the file.
  264.      4) Open it again in read/write mode.
  265.      5) Save P1 and append it to the end of the file.
  266.      6) Copy V1 to the beginning, but change the offset which it JMPs to so
  267.         it transfers control correctly. See the previous part on infection.
  268.      7) Append V2 to the end of the file.
  269.      8) Restore file attributes/date/time.
  270.  
  271. You should  keep a counter of the number of files infected during this run.
  272. If the number exceeds, say three, then stop.  It is better to infect slowly
  273. then to give yourself away by infecting the entire drive at once.
  274.  
  275. You must  be sure  to cover  your tracks  when you infect a file.  Save the
  276. file's  original   date/time/attributes  and  restore  them  when  you  are
  277. finished.   THIS IS VERY IMPORTANT!  It takes about 50 to 75 bytes of code,
  278. probably less,  to do  these few simple things which can do wonders for the
  279. concealment of your program.
  280.  
  281. I will  include code for the directory traversal function, as well as other
  282. parts of the replicator in the next installment of my phunky guide.
  283.  
  284. -=-=-=-=-
  285. CONCEALER
  286. -=-=-=-=-
  287. This is  the part  which conceals  the program  from notice by the everyday
  288. user and virus scanner.  The simplest form of concealment is the encryptor.
  289. The code for a simple XOR encryption system follows:
  290.  
  291. encrypt_val   db   ?
  292.  
  293. decrypt:
  294. encrypt:
  295.      mov ah, encrypt_val
  296.  
  297.      mov cx, part_to_encrypt_end - part_to_encrypt_start
  298.      mov si, part_to_encrypt_start
  299.      mov di, si
  300.  
  301. xor_loop:
  302.      lodsb                 ; DS:[SI] -> AL
  303.      xor al, ah
  304.      stosb                 ; AL -> ES:[DI]
  305.      loop xor_loop
  306.      ret
  307.  
  308. Note the encryption and decryption procedures are the same.  This is due to
  309. the weird  nature of  XOR.   You can CALL these procedures from anywhere in
  310. the program,  but make sure you do not call it from a place within the area
  311. to be  encrypted, as  the program  will crash.  When writing the virus, set
  312. the encryption  value to  0.  part_to_encrypt_start and part_to_encrypt_end
  313. sandwich the area you wish to encrypt.  Use a CALL decrypt in the beginning
  314. of V2  to unencrypt  the file  so your  program can  run.  When infecting a
  315. file, first change the encrypt_val, then CALL encrypt, then write V2 to the
  316. end of the file, and CALL decrypt.  MAKE SURE THIS PART DOES NOT LIE IN THE
  317. AREA TO BE ENCRYPTED!!!
  318.  
  319. This is how V2 would look with the concealer:
  320.  
  321. V2_Start:
  322.  
  323. Concealer_Start:
  324.   .
  325.   .
  326.   .
  327. Concealer_End:
  328.  
  329. Replicator_Start:
  330.   .
  331.   .
  332.   .
  333. Replicator_End:
  334.  
  335. Part_To_Encrypt_Start:
  336.   .
  337.   .
  338.   .
  339. Part_To_Encrypt_End:
  340. V2_End:
  341.  
  342. Alternatively, you  could move  parts  of  the  unencrypted  stuff  between
  343. Part_To_Encrypt_End and V2_End.
  344.  
  345. The value  of encryption  is readily  apparent.  Encryption makes it harder
  346. for virus  scanners to  locate your virus.  It also hides some text strings
  347. located in  your program.   It is the easiest and shortest way to hide your
  348. virus.
  349.  
  350. Encryption is only one form of concealment.  At least one other virus hooks
  351. into the  DOS interrupts  and alters  the output  of DIR  so the file sizes
  352. appear normal.   Another  concealment scheme  (for TSR virii) alters DOS so
  353. memory utilities  do not  detect the  virus.   Loading the virus in certain
  354. parts of  memory allow  it to survive warm reboots.  There are many stealth
  355. techniques, limited only by the virus writer's imagination.
  356.  
  357. -=-=-=-=-
  358. THE BOMB
  359. -=-=-=-=-
  360. So now all the boring stuff is over.  The nastiness is contained here.  The
  361. bomb part  of the virus does all the deletion/slowdown/etc which make virii
  362. so annoying.   Set  some activation  conditions of  the virus.  This can be
  363. anything, ranging  from when  it's your  birthday to  when  the  virus  has
  364. infected 100  files.   When these  conditions are met, then your virus does
  365. the good stuff.  Some suggestions of possible bombs:
  366.  
  367.      1) System slowdown - easily  handled  by  trapping  an  interrupt  and
  368.         causing a delay when it activates.
  369.      2) File deletion - Delete all ZIP files on the drive.
  370.      3) Message display - Display a nice message saying  something  to  the
  371.         effect of "You are fucked."
  372.      4) Killing/Replacing the Partition Table/Boot Sector/FAT of  the  hard
  373.         drive - This is very nasty, as most dimwits cannot fix this.
  374.  
  375. This is, of course, the fun part of writing a virus, so be original!
  376.  
  377. -=-=-=-=-=-=-=-
  378. OFFSET PROBLEMS
  379. -=-=-=-=-=-=-=-
  380. There is  one caveat  regarding calculation of offsets.  After you infect a
  381. file, the  locations of  variables change.  You MUST account for this.  All
  382. relative offsets  can stay  the same, but you must add the file size to the
  383. absolute offsets  or your  program will  not work.  This is the most tricky
  384. part of  writing virii  and taking  these into  account can  often  greatly
  385. increase the  size of  a virus.   THIS  IS VERY IMPORTANT AND YOU SHOULD BE
  386. SURE TO  UNDERSTAND THIS BEFORE ATTEMPTING TO WRITE A NONOVERWRITING VIRUS!
  387. If you  don't, you'll  get fucked  over and  your virus WILL NOT WORK!  One
  388. entire part of the guide will be devoted to this subject.
  389.  
  390. -=-=-=-
  391. TESTING
  392. -=-=-=-
  393. Testing virii  is a  dangerous yet  essential part  of the  virus  creation
  394. process.   This is  to make  certain that people *will* be hit by the virus
  395. and, hopefully,  wiped out.   Test  thoroughly and  make sure  it activates
  396. under the  conditions.  It would be great if everyone had a second computer
  397. to test  their virii  out, but,  of course, this is not the case.  So it is
  398. ESSENTIAL that  you keep BACKUPS of your files, partition, boot record, and
  399. FAT.   Norton is  handy in  this doing  this.  Do NOT disregard this advice
  400. (even though  I know  that you will anyway) because you WILL be hit by your
  401. own virii.   When  I wrote my first virus, my system was taken down for two
  402. days because I didn't have good backups.  Luckily, the virus was not overly
  403. destructive.   BACKUPS MAKE  SENSE!  LEECH A BACKUP PROGRAM FROM YOUR LOCAL
  404. PIRATE BOARD!   I find a RamDrive is often helpful in testing virii, as the
  405. damage is  not permanent.   RamDrives  are also useful for testing trojans,
  406. but that is the topic of another file...
  407.  
  408. -=-=-=-=-=-=-
  409. DISTRIBUTION
  410. -=-=-=-=-=-=-
  411. This is  another fun  part of  virus writing.   It  involves  sending  your
  412. brilliantly-written  program   through  the  phone  lines  to  your  local,
  413. unsuspecting bulletin  boards.   What you  should do  is infect a file that
  414. actually does something (leech a useful utility from another board), infect
  415. it, and upload it to a place where it will be downloaded by users all over.
  416. The best  thing is  that it  won't be detected by puny scanner-wanna-bes by
  417. McAffee, since it is new!  Oh yeah, make sure you are using a false account
  418. (duh).   Better yet,  make a  false account  with the  name/phone number of
  419. someone you  don't like  and upload  the infected  file under the his name.
  420. You can  call back  from time to time and use a door such as ZDoor to check
  421. the spread  of the virus.  The more who download, the more who share in the
  422. experience of your virus!
  423.  
  424. I promised a brief section on overwriting virii, so here it is...
  425. -=-=-=-=-=-=-=-=-
  426. OVERWRITING VIRII
  427. -=-=-=-=-=-=-=-=-
  428. All these  virii do  is spread  throughout the  system.   They  render  the
  429. infected files  inexecutable, so they are easily detected.  It is simple to
  430. write one:
  431.  
  432.    +-------------+   +-----+   +-------------+
  433.    | Program     | + |Virus| = |Virus|am     |
  434.    +-------------+   +-----+   +-------------+
  435.  
  436. These virii are simple little hacks, but pretty worthless because of their
  437. easy detectability.  Enuff said!
  438.  
  439. -=-=-=-=-=-=-=-=-=-=-=-=-
  440. WELL, THAT JUST ABOUT...
  441. -=-=-=-=-=-=-=-=-=-=-=-=-
  442. wraps it  up for  this installment  of Dark  Angel's Phunky  virus  writing
  443. guide.   There will (hopefully) be future issues where I discuss more about
  444. virii and  include much  more source  code (mo' source!).  Till then, happy
  445. coding!
  446.  
  447. Downloaded From P-80 International Information Systems 304-744-2253
  448.