学院首页>网络编程>ASP.NET>URTracker 2.11版 license验证原理剖析

URTracker 2.11版 license验证原理剖析

作者: 来源: 添加时间:2006-5-21 19:50:08
注 :原创,转载请注明出处。
作 者:草惜草
首 发: http://kokey.blogchina.com

序言:

看了henryouly的文章以后深受启发,决定对URTracker最新的版本来个剖析。在此,特别感谢henryouly!

×××××××××××××××××××××××××××××××××××××××××××××
URTracker事务跟踪系统是一款功能强大而且易于使用的Web方式的协同工作软件 。它用于帮助公司和团队跟踪工作中的问题,管理和记录这些问题的处理过程。
URTracker向您的团队提供了一个全功能的,高度可定制的软件工具用于报告和跟踪问题、需求、缺陷(BUG)或者任务等事务。它拥有丰富的自定义字段、基于项目和角色的权限控制、简化的工作流、友好的用户界面,以及更多的其他特性。我们非常确信您将会喜欢上URTracker,因为我们相信她正是您所需要的。
 ××××××××××××××××××××××××××××××××××××××××××××
 工具介绍:
 
   要研究.NET当然离不开Reflector for .NET 。(Reflector is a class browser for .NET components. It supports assembly and namespace views, type and member search, XML documentation, call and callee graphs, IL, Visual Basic, Delphi and C# decompiler, dependency trees, base type and derived type hierarchies and resource viewers. )
   如果想把代码保存下来,那就需要Reflector的插件Reflector.FileDisassembler了。(The Reflector.FileDisassembler is a little add-in for the new version of Lutz Roeder's .NET Reflector that you can use to dump the decompiler output to files of any Reflector supported language (C#, VB.NET, Delphi). This is extremely useful if you are searching for a specific line of code as you can use VS.NET's "Find in Files" or want to convert a class from one language to another.

  下载地址:Reflector for .NET   http://www.aisto.com/roeder/dotnet/
Reflector.FileDisassembler http://www.denisbauer.com/NETTools/FileDisassembler.aspx
 
 正文:

严重声明:本文只作科研和学习用途。如果由本文产生的法律纠纷,一概与本人无关。

好了,了解了Reflector咱们就可以动手研究URTracker了。

当然首先用Reflector分析bin文件夹下的文件,一共有12个DLL文件,从他们的名称你也可以猜出个八八九九,反正你不怕麻烦你就挨个用Reflector试好了...^_^
最后找到了WebTracker.dll 可疑,因为在Reflector按F3,你可以搜索到很多关于license的东东。哈哈,探究之路开始了。
首先看看Lealsoft.URTracker.BLL下有个ServerLicenseProvider类。

public class ServerLicenseProvider : LicenseProvider
{
   // Methods
   static ServerLicenseProvider();
   public ServerLicenseProvider();
   protected virtual ServerLicense CreateEmptyLicense(Type type);
   protected virtual ServerLicense CreateLicense(Type type, string key);
   public override License GetLicense(LicenseContext context, Type type, object instance, bool allowExceptions);
   protected virtual string GetLicenseData(Type type);
   protected virtual Stream GetLicenseDataStream(Type type);
   protected virtual bool ValidateLicense(ServerLicense license, out string errorMessage);
   protected virtual bool ValidateLicenseData(Type type, string licenseData);

// Fields
   private static readonly ServerLicenseCollector LicenseCollector;

// Nested Types
   private sealed class ServerLicenseCollector
   {
   // Methods
   public ServerLicenseCollector();
   public void AddLicense(Type objectType, ServerLicense license);
   public ServerLicense GetLicense(Type objectType);
   public void RemoveLicense(Type objectType);

// Fields
   private IDictionary _collectedLicenses;
   }
}
 
看到没,有几个CreateLicense,GetLicense,ValidateLicense ,ValidateLicenseData,GetLicenseDataStream这几个方法。好,打开看看都是什么东东。

protected virtual ServerLicense CreateLicense(Type type, string key)
{
   char[] chArray1 = new char[1] { ':' } ;
   string[] textArray1 = key.Split(chArray1);
   return new URTrackerLicense(type, key, long.Parse(textArray1[1], CultureInfo.InvariantCulture), long.Parse(textArray1[2], CultureInfo.InvariantCulture), textArray1[3], long.Parse(textArray1[4], CultureInfo.InvariantCulture), long.Parse(textArray1[5], CultureInfo.InvariantCulture), textArray1[6]);
}
 
哇!就是新建license,URTrackerLicense后面有几个参数,什么也看不出,感觉是要用":"split开一个字符串。来,打开URTrackerLicense构造函数看看。
public URTrackerLicense(Type type, string key, long startTicks, long ticks, string username, long userIndex, long clientCount, string mac) : base(type, key)
{
   this._foundMac = false;
   this._ticks = ticks;
   this._startTicks = startTicks;
   this._username = username;
   this._userIndex = userIndex;
   this._clientCount = clientCount;
   this._mac = mac;
   this._macArray = URTrackerLicense.GetMacArray();
   this._foundMac = this._macArray.IndexOf(this._mac) > -1;
}
 
哦,看到ticks,startTicks,username,userIndex,clientCount,mac
难道这些就是所需参数"到期时间,使用开始时间,用户名,用户名索引,用户数,本机网卡地址"
有点意思了。呵呵。
找到了 URTrackerLicense 类,你就会知道我们猜测的没有错了。
public class URTrackerLicense : ServerLicense
{
   // Methods
   public URTrackerLicense(Type type, string key, long startTicks, long ticks, string username, long userIndex, long clientCount, string mac);
   public static ArrayList GetMacArray();

// Properties
   public long ClientCount { get; }
   public bool IsExpired { get; }
   public string Mac { get; }
   public long StartTicks { get; }
   public long Ticks { get; }
   public long UserIndex { get; }
   public string Username { get; }

// Fields
   private long _clientCount;
   private bool _foundMac;
   private string _mac;
   private ArrayList _macArray;
   private long _startTicks;
   private long _ticks;
   private long _userIndex;
   private string _username;
}
 
继续,刚才找了CreateLicense,现在开始找ValidateLicenseData。
protected virtual bool ValidateLicenseData(Type type, string licenseData)
{
   bool flag1 = false;
   char[] chArray1 = new char[1] { ':' } ;
   string[] textArray1 = licenseData.Split(chArray1);
   if (textArray1.Length == 7)
   {
   return (string.Compare("URTracker1Licensed", textArray1[0], true, CultureInfo.InvariantCulture) == 0);
   }
   return flag1;
}
 
哈哈,就是说刚才分析那个数组中textArray1[0],必须是URTracker1Licensed!哈哈,这也进一步证实了我们要把注册信息字符串用":"分开的设想。
Come on!离成功越来越近了!接着分析ValidateLicense。
protected virtual bool ValidateLicense(ServerLicense license, out string errorMessage)
{
   errorMessage = null;
   URTrackerLicense license1 = (URTrackerLicense) license;
   if (license1.IsExpired)
   {
   errorMessage = "The License has expired.";
   return false;
   }
   return true;
}
 
哦,知道了!原来是判断URTrackerLicense的属性IsExpired的真假!好,咱们看看属性IsExpired。
public bool IsExpired
{
   get
   {
   if ((DateTime.Today.Ticks <= this._ticks) && (DateTime.Now.Ticks >= this._startTicks))
   {
   return !this._foundMac;
   }
   return true;
   }
}
 
 知道了吧!就是判断当前时间要在ticks和startTicks之间!然后再判断Mac的值。
 现在查找Mac的相关类或者方法。找到了GetMacArray
 public static ArrayList GetMacArray()
{
   ManagementClass class1 = new ManagementClass("Win32_NetworkAdapterConfiguration");
   ManagementObjectCollection collection1 = class1.GetInstances();
   ArrayList list1 = new ArrayList();
   using (ManagementObjectCollection.ManagementObjectEnumerator enumerator1 = collection1.GetEnumerator())
   {
   while (enumerator1.MoveNext())
   {
   ManagementObject obj1 = enumerator1.get_Current();
   if ((bool) obj1.get_Item("IPEnabled"))
   {
   list1.Add(obj1.get_Item("MacAddress").ToString().Replace(":", "").ToUpper());
   }
   obj1.Dispose();
   }
   }
   return list1;
}

第 1 页,共 2 页 [1] [2]
站内搜索