閒話破解(2)

看雪資料發表於2003-08-26

談談商用保護的破解

   這裡的商用保護,指直接使用第三方的工具,利用其程式設計介面實現軟體的保護部分,而非原作者從頭開始自行開發,比如Flexlm,SoftLocx等。直接在可執行檔案上加殼的情況不在討論之列。商用保護往往是眾矢之的,研究的人比較多,在網際網路上可以找到類似案例,結果是一損俱損,搞定一個,倒下一片。Flexlm就是最好的例子。使用dongle進行保護的,也有類似之處(但不盡相同)。

  破解商用保護,最重要的是儘可能地獲取其資料,如果有正規的使用手冊、演示程式碼等是最好的。這在破解中起著決定性的作用。

  破解第一步,就是仔細閱讀待破解軟體的文件,不要漏過任何蛛絲馬跡,切不可一頭扎進SoftIce或IDA中瞎找。很多時候從SoftIce和IDA Pro中費心勞神得出的東西,文件中講得明明白白。使用商用保護的軟體,其文件常常會有說明。如果沒有,在跟蹤以及閱讀反彙編程式碼的過程中也一定會暴露出來。這時候應當立即停下破解工作,到網上搜尋一切相關資訊,最好能下載到保護軟體的試用版本,以及查詢是否有相關的破解案例。儘可能地瞭解該保護軟體的使用方法,各種程式設計介面,各錯誤碼的含義,研究其弱點。從實戰經驗看,只要掌握了保護軟體的使用方式,一般都能發現其弱點。比如Softlocx,其檢查軟體的返回結果是個字串,為“LICENSED”,“EVALUATION”,“EXPIRED”等等,應用軟體根據這樣的字串來決定執行路徑。這樣的保護會強嗎?
  
  破解商用保護,比較簡單省力的方法是找到保護軟體與被保護軟體的連線點,打斷其連線,強迫被保護的軟體正常執行。這種方式一般需要修改其二進位制程式碼,打個補丁。這是下策,非不得以不為之。
  
  上策嘛,當然是完全保留原有的保護機制,或是寫個序號產生器,或是擷取一個序列號或license,或是湊個keyfile。總之,以儘量不打補丁為原則。當然,這樣做意味著要與專業對手交鋒,難度大得多。很多時候要把加密演算法搞懂,寫出個逆運算,幾乎是不可能的。有些演算法根本不可逆。

  不過,可以換一個方式。Think like a cracker!我的辦法是,把保護軟體的資料好好研究,透過softIce跟蹤,獲取足夠的資料,直接寫個程式,呼叫保護軟體,讓它為我們生成一個合法的結果。這一招屢試不爽。
 

  以下的例子是個軟體工程類的國外商業軟體,名字隱去。本文是根據以前的破解筆記整理的,軟體可能早已升過級了:-)。安裝完執行時,出現一個license配置對話方塊,提示超期日期。另外有以下資料:

   Computer ID: 496861184
   Session ID: 286021360

   下面要求輸入 Product Unlock Code。如果不輸,可以Evaluation方式執行。


1. 在對主執行檔案稍加分析後,即可將疑點集中到一個叫ETLicens.dll的動態連結庫上。這個檔案的檔名及其中的資源(包括Dialog,String等)是如此的露骨,簡直就是crack的不二人選。其輸出的函式也是如此。我以為就要在此解決戰鬥了:-)。實際上,也確實可以在此patch,以暴破搞定。但給人的感覺不完美,需要patch的位置較多,沒有一個合適的著力點。

  在分析過程中可得到以下一些有趣的東西:

  1)一個反覆出現的字串“ERStudioRulez!!”。這是什麼?
 
  2)會多次訪問一個登錄檔項:
     LOCALMACHINE\Software\Classes\sysdskdrv\75f42175d63bd284,?
     
   另有一個對應的字串“:LM:Software\Classes\sysdskdrv\75f42175d63bd284”。

  
  在這個Dll中花了不少工夫,結果完全弄偏了方向。注意到此Dll還使用了另一個Dll:KeyLbE32.dll。反編譯一下這個檔案,再用ResHacker看看,其CompanyName為“Concept Software, Inc.”。是另一家的東西?

2.到Google上查一下,可在http://www.softwarekey.com上下到此保護軟體:Protection Plus V4.109,與KeyLbE32.dll中的版本資訊完全一致。研究一下此軟體的使用方式。
  Protection Plus只是SoftwareKey產品系列中的一個,暫且不管別的東西,先只看這一個。產品基本介紹如下:

  Control Applications:

  . Create demos, rentals, pay-per-use applications.
   . Immediate software activation via phone, fax, e-mail, or the Internet.
   . Extend a demo, rental, or lease for an additional period of time.
   . Turn on one or more menu options or applications in a suite.
   . Convert application from single-user mode to multi-user mode.
   . Protect using either fixed or floating network licensing.
   . Modify the number of allowed network workstations.
   . Convert from "lite" version to professional version.
   . Increase or decrease a counter.
   . Trigger any user-defined action.

   Enforce License Compliance:

   . Lock the application to run on the current computer or network server
   only.
   . Limit the number of allowed network users or computers.
   . Terminate rental or lease applications that are not paid.
   . Turn an illegal copy into a demo or disable it.
   . Force returned software or fraudulent purchases to stop working.

   Other Features:

   . Detects click backdating or demo reinstallation to gain additional usage.
   . Encrypt/decrypt user data.
   . Personalize and/or serialize without recompiling.
   . Extremely flexible programming interface means applications limited only
     by your imagination!

  看起來很強大,可供呼叫的函式很多:-)。這裡就不一一列舉。只提一下與crack直接相關的幾個概念。

   . License Files

   License Files contain many data fields that allow you to store information to control the flow of execution in your application.  The fields can be initialized before sending your application using our Windows-based License File Editor application and/or can be manipulated by the application remotely using Trigger Codes. License Files may be stored in a regular file in any directory, the Windows registry, a Marx Software Security Crypto-Box Hardware Key, or on an Internet Web Server.  There are many character,string,numeric/bit, and date fields in the License File. Data ranges from pre-defined fields such as serial number, expiration date, and number of allowed network users, to user-defined fields.
  
  注意license的儲存形式:可以是常規的檔案,登錄檔項(回想一下1中的那個:-),在硬體狗中,或在Web伺服器上。

  . Trigger Codes - Adds Remote Licensing Control

   The PLUS system has a mechanism to send one-time secure remote signals to your application while running on the Client's computer. The user contacts you and gives you 2 six to eight-digit numbers that are displayed on a dialog box on their computer. These numbers can be sent by phone, FAX, e-mail, etc.  In our Windows-based License File Editor application,these two numbers are entered; and, depending on what function you want to perform on their application, you return them one of 50 six to eight-digit numbers.  In addition to the remote signal sent, you can also send an encrypted number.  The encrypted number can contain data such as the number of allowed workstations, number of pay-per-use events, etc.

  想想那個Unlock Code。

  主要涉及的概念就這兩個。函式很多,只要動手寫個小程式,嘗試幾次,即可找到破解之道(破綻百出:-)。license配置對話方塊中的Computer ID是機器標識。Session ID沒有直接的對應物,象是Trigger Event ID與Trigger Event Data加密組合的結果。在第一步中提到的兩個資料含義如下:

 1)字串“ERStudioRulez!!”為保護license檔案的password:-)
 2)LOCALMACHINE\Software\Classes\sysdskdrv\75f42175d63bd284下就是儲存在登錄檔中
   的license

 破解時的有些細節記不清了,筆記隨手亂寫不完整:-(,試了試生成自己的Unlock Code,當時沒成功,好象是建立license時有的field沒填對。乾脆呼叫pp_copyadd直接設為合法的機器。至於為什麼用了內嵌組合語言的方式來呼叫函式,大概是有些引數拿不穩,要對照IDA中的使用方式吧(也記不清了:-)。這份程式碼是隨手寫的,能工作就沒管了(未檢測各函式的返回值),有點虎頭蛇尾呵呵。

 以下為設定合法license的程式碼:

 ///////////////////////////////////////

 #include "stdafx.h"
 #include "ETLicense.h"

 CWinApp theApp;

 using namespace std;

 int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
 {
     int nRetCode = 0;

     HINSTANCE hCommProt=::LoadLibrary("KeyLbE32.dll");

     FARPROC pp_lfopen,pp_lfclose,pp_copyadd;

     pp_lfopen=::GetProcAddress(hCommProt,MAKEINTRESOURCE(0x31));
   pp_lfclose=::GetProcAddress(hCommProt,MAKEINTRESOURCE(0x2C));
     pp_copyadd=::GetProcAddress(hCommProt,MAKEINTRESOURCE(0xC));

   
   CString strSysDiskInfo(":LM:Software\Classes\sysdskdrv\75f42175d63bd284");
   char * lpszKeyName=strSysDiskInfo.GetBuffer(128);

     long hLicFile=0;
     char szPassword[]="ERStudioRulez!!";
     char *lpszPass=szPassword;
     
     _asm
     {
          lea eax,hLicFile
          push eax//存放控制程式碼

          push lpszPass//license檔案密碼
          push 2//型別LF_REGISTRY
          push 0//license檔案屬性LF_CREATE_NORMAL
          push lpszKeyName //license檔名(登錄檔項)

          call pp_lfopen
     
      push 0x1D9D8000 //Computer ID,也可調pp_compno()獲取
          push 2   //COPYADD_ERASEALL,刪除現有值
          push hLicFile
          call pp_copyadd  //把我這臺機器加為合法使用者吧:-)

          push hLicFile
          call pp_lfclose  //關閉license檔案
     }
     
     ::FreeLibrary(hCommProt);
     return nRetCode;
 }

 ////////////////////////////////////////////////

3.總結一下破解用Protection Plus保護的軟體。

  先下載開發包,可以用IDA Pro的Flair做出Sig檔案(我破解成功後就沒幹這個了,手懶:-)。攔截pp_lfopen函式,要訪問license資料,必調此函式。在此可獲取最重要的資料:

  . license檔名(與license位置相關)

  . license位置(可能是真正的檔名、登錄檔項、dongle或是一個網址,
    如果是個網址可能會麻煩些:-)
 
  . 用於保護license檔案的password

  有了這些資料,能幹什麼?借用一下SoftwareKey的廣告語:Limited only by your imagination!好好研究聯機幫助吧:-)。


相關文章