利用VMProtect sdk和ASProtect sdk加密delphi程序

0x01

普通的一些加密殼能夠較爲容易的被脫掉,而一些稍微難一點殼,例如VMProtect等,剛入門的新手就不是那麼好脫了,而這些殼也提供了一些sdk幫助我們加密需要加密的函數,使保護殼能夠識別源碼中需要加密保護的代碼段。下面以我的一個delphi程序爲例,介紹VMProtect sdkAsprotect的一些加密方法,其他vc,或者易語言寫的程序也可以使用其進行加密。

0x02 VMProtect保護

VMProtect sdk保護方式可以有兩種,map法和標記法,在官方文檔中,有下述方法。

it is possible by doing the following: use the main menu of the Delphi IDE to open the project

options (Project - Options) and select the "Detailed" option in the "MAP file" group on the "Linker" tab:

將項目設置中map文件的設置從無改成詳細。

可以看到產生了如圖的map文件,map文件中包含了有關被鏈接的程序的下列信息:模塊名稱,爲文件的基名稱,時間戳,來自程序的文件頭(不是來自文件系統),程序中的組列表,包括每個組的起始地址(節:偏移量的形式)、長度、組名和類;公共符號的列表,包括每個地址(節:偏移量的形式)、符號名稱、平直地址和包含符號定義的obj文件;入口點(節:偏移量的形式),另外可以通過map文件確定程序奔潰的位置。

然後下載VMProtect,官網上是未激活版。本文以註冊版演示。

載入文件後,VMProtect界面如圖所示。

VMProtect根據map文件得到了一些函數信息,然後F9即可進行編譯加殼,然後會生成後綴爲.vmp.exe的保護後的文件,在peid0.95中查殼,結果如圖所示。雖然結果爲什麼都沒找到,但是區段中已經有了vmp1vmp0。可以以vmprotect來進行脫殼等操作。

而語句標記法,主要利用了下列語句進行需要保護的代碼的標記

asm 

db $EB,$10,'VMProtect begin',0 //標記開始處.

end;

//想保護的程序代碼

asm

db $EB,$0E,'VMProtect end',0 //標記結束處.

end;

Vc當中標記模式爲:

 __asm    //標記開始處.
    {  
      _emit 0xEB
      _emit 0x10  //jmp 0x10
      _emit 0x56  //ascii "VMProtect begin",0
      _emit 0x4D  
      _emit 0x50 
      _emit 0x72 
      _emit 0x6F 
      _emit 0x74 
      _emit 0x65 
      _emit 0x63 
      _emit 0x74 
      _emit 0x20 
      _emit 0x62 
      _emit 0x65 
      _emit 0x67 
      _emit 0x69 
      _emit 0x6E 
      _emit 0x00
    }
    //想保護的程序代碼
    __asm  //標記結束處.
    {  
      _emit 0xEB
      _emit 0x0E   //jmp 0x0e
      _emit 0x56   //ascii "VMProtect end",0
      _emit 0x4D   
      _emit 0x50 
      _emit 0x72 
      _emit 0x6F 
      _emit 0x74 
      _emit 0x65 
      _emit 0x63 
      _emit 0x74 
      _emit 0x20 
      _emit 0x65 
      _emit 0x6E 
      _emit 0x64 
      _emit 0x00
    }

而在官方文檔中,有下列例子可供參考,將sdk的動態鏈接庫引入,在lib目錄下有相關的dll文件,在library目錄下也有相關的庫文件。

Markers are inserted in the code to protect separate sections of the code and also

protect string constants. Markers are calls of imported procedures stored in an external

 DLL (VMProtectSDK32.dll is used for 32-bit applications and VMProtectSDK64.dll is used

for 64-bit applications; VMProtectDDK32.sys and VMProtectDDK64.sys respectively are

used to protect drivers), VMProtectSDK are used hereinafter. Procedures and functions

located in VMProtectSDK do not do anything and serve only as markers by which VMProtect

determines the borders of the protected code. Correspondingly, the beginning and end of a

protected block are marked in the following way:

Delphi

uses VMProtectSDK;

 

VMProtectBegin(MARKER_NAME);

...

VMProtectEnd;

C/C++

#include "VMProtectSDK.h"

VMProtectBegin(MARKER_NAME);

...

VMProtectEnd();

MASM

include VMProtectSDK.inc

 

invoke VMProtectBegin,SADD(MARKER_NAME)

...

invoke VMProtectEnd

Visual Basic

Call VarPtr("VMProtect begin")

...

Call VarPtr("VMProtect end")

0x03 VMProtectASProtect的混合加密

Asprotect也有相關的sdk,也提供了註冊機制,主要delphi通過標記語句,{$I filename},實現文件的引入,它主要有多態變形標記,crc檢查標記,外殼完整性檢查。不同的標記需要引入不同的文件,例如在多態變形標記中,示例爲:

Delphiexample: 

 Procedure Test;  

 begin

 {$I Inc\UserPolyBuffer.inc}  

 // some code  

 end;  

還得引入相關的apiuses  aspr_api;

如果有map文件時,在軟件界面中也可以導入,如圖所示。

在保護的時候即可自動識別函數。

試驗的程序當先用VMProtect,後用ASProtect時,會出現一個如圖文件損壞的對話框,可能是因爲區段的問題,無法找到入口。

而先用ASProtect,後用VMProtect時,程序正常運行,當然因爲加殼的原因,在在線殺毒引擎中有23%的殺軟(9/38)報告發現病毒。

0x04 MAP文件的結構

一開始是

 Start         Length     Name                   Class

 0001:00000000 00050F4CH .text                   CODE

 0002:00000000 000011D8H .data                   DATA

 0002:000011D8 00000BE1H .bss                    BSS

Pe文件的區段

Detailed map of segments,一些細節方面的東西

Address Publics by Name,然後一些關於函數的偏移量

Line numbers for SysConst(C:\Program Files (x86)\Borland\Delphi7\lib\sysconst.pas) segment .text SysConst代碼中行數的偏移量

Line numbers for Unit1(Unit1.pas) segment .text    代碼中行數的偏移量

Line numbers for Project2(C:\Program Files (x86)\Borland\Delphi7\Projects\Project2.dpr) segment .text

Bound resource files 與之相關的資源文件

Program entry point at 0001:00050EE0  程序入口點

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章