關於病毒--Code篇

 
  這一頁展示一些由書上和BBS站上所學得的一些與防毒有關的code和概念 希望對大家有幫助: 

 
 
  (1)COM型反病毒疫苗:
 
 
        其實電腦病毒的程式中,本身已經包括了解毒動作。因為病毒為了保持原程式的繼續執行,必須將原程式在記憶體中復原,再跳至原程式執行,但它並不將還原後的程式寫回檔案,故可以寫一程式將記憶體內的原程式寫回磁碟,那不就完成解毒工作了嗎!
 
      Source Code:
   code_seg_a    segment
                  assume  cs:code_seg_a, ds:code_seg_a
                  org     100h
 
  COMPROTECT     PROC FAR
   go:
               CALL START
 
 COMP_SIZE DW 231
 OLD_LENGTH DW ?
 NEW_LENGTH DW ?
 HANDLE DW  ?
 SOURCE_SIZE DW ?
 MEMORY    DW ?
 VN        DW ?
 ftime     dw ?
 fdate     dw ?
 
START:
      POP BX
      SUB BX,3
      MOV CS:VN,BX
      ;
      ;disable ctitinal error
      ;
      mov dx,offset cs:newint24
      mov al,24h
      mov ah,25h
      int 21h
 
      mov ah,62h
      int 21h
      mov ds,bx
      mov ax,word ptr ds:[02ch]
      mov ds,ax
      mov si,0
seek1:
      inc si
      mov al,ds:[si]
      cmp al,0
      jne seek1
      inc si
      mov aL,ds:[si]
      cmp al,0
      jne seek1
      add si,3
      ;
      ;open file
      ;
      mov dx,si
      mov ah,3dh
      mov al,2
      int 21h
      push cs
      pop ds
 
      mov cs:handle,ax
 
      mov ax,4202h
      mov cx,0
      mov dx,0
      mov bx,cs:handle
      int 21h
 
      sub ax,cs:old_length
      cmp ax,0
      jne recover
      jmp close
 
recover:
 
      mov ah,42h
      mov al,00h
      mov cx,0
      mov dx,0
      mov bx,cs:handle
      int 21h
 
      mov bx,cs:handle
      mov cx,cs:old_length
      mov dx,cs:vn
      mov ax,cs
      mov ds,ax
      mov ax,4000h
      int 21h
 
      mov ah,42h
      mov al,0
      mov DX,CS:OLD_LENGTH
      MOV CX,0
      mov bx,cs:handle
      int 21h
 
      mov ah,40h
      mov bx,cs:handle
      mov cx,0
      int 21h
 
close: mov ah,3eh
       mov bx,cs:handle
       int 21h
 
       ;
       ;execute original file
       ;
 
        mov  di,100h
        mov  ax,cs
        mov  es,ax
        mov  dx,ax
        mov  si,CS:COMP_SIZE
        add  si,100h
        mov  cx,source_size
        rep  movsb
        jmp  go
 
        db 'COMprot'
newint24:
         mov al,0
         iret
 
COMPROTECT  ENDP
code_seg_a      ends
end go
 
(2)EXE型反病毒疫苗:
     EXE檔的反病毒疫苗原理更為簡單,我們只需將原程式(加反病毒疫苗後)的檔頭重要資料(約32 Bytes)備份一份至反病毒疫苗內,當發現檔案被病毒感染後在將其原備份的檔頭資料回存,並將檔案多出的部份移除即可完成解毒的工作了。

  Source Code:
.MODEL SMALL
.CODE
 
START:
 
 original_header DB 32 DUP(0)
 fsize1  dw ?
 fsize2  dw ?
 db 0
 O_SS DW ?
 O_SP DW ?
 O_IP DW ?
 O_CS DW ?
 LENCX DW ?
 LENDX DW ?
 handle dw ?
 
ACTION:
      ;
      ;disable critical error
      ;
 
      mov dx,offset cs:newint24
      mov ah,25h
      mov al,24h
      int 21h
 
      mov ah,62h
      int 21h
      mov ds,bx
      mov ax,word ptr ds:[02ch]
      mov ds,ax
      mov si,0
seek1:
      inc si
      mov al,ds:[si]
      cmp al,0
      jne seek1
      inc si
      mov aL,ds:[si]
      cmp al,0
      jne seek1
      add si,3
 
      ;
      ;open file
      ;
 
       mov dx,si
 
 
 
       mov ah,3dh
       mov al,2
       int 21h
 
       mov cs:handle,ax
 
       mov ah,42h
       mov al,0
       mov bx,cs:handle
       mov cx,0
       mov dx,2
       int 21h
 
       mov ah,3fh
       mov bx,cs:handle
       mov cx,4
       lea dx,cs:fsize1
       int 21h
 
       mov si,offset cs:original_header
       mov ax,[si+3]
       cmp ax,cs:fsize1
       jne recover
 
       mov ax,[si+5]
       cmp ax,cs:fsize1
       jne recover
 
       jmp close
 
      ;
      ;write original header to file
      ;
 
recover:
 
       mov ax,cs
       mov ds,ax
 
       mov ah,40h
       mov bx,cs:handle
       mov cx,32
       lea dx,cs:original_header
       int 21h
       ;
       ;write to file bottom
       ;
       mov ah,42h
       mov al,0
       mov cx,cs:lencx
       mov dx,cs:lendx
       mov bx,cs:handle
       int 21h
 
       mov ah,40h
       mov bx,cs:handle
       mov cx,0
       int 21h
 
       ;
       ;close file
       ;
close: mov ah,3eh
       mov bx,cs:handle
       int 21h
 
       ;
       ;execute original file
       ;
       mov ah,62h
       int 21h
       mov ax,cs:o_cs
       add ax,bx
       add ax,010h
       mov cs:o_cs,ax
       jmp dword ptr cs:o_ip
      db 'EXE Protector Written by Plus Lin'
 
newint24:
         mov al,0
         iret
 
END START
END

 

回首頁