现在的位置: 首页 > 综合 > 正文

提高Windows 产品密钥安全性

2013年01月25日 ⁄ 综合 ⁄ 共 1962字 ⁄ 字号 评论关闭

     今天无意中在CodePlex 发现一个叫Windows Product Key Finder 的项目,从名字就可以看出它的用途。通过这款软件可以轻松的获取本地Windows 的产品密钥。当然对于找不到密钥光盘的人来说这当然是款实用的工具,但如果到了某些图谋不轨的人手里那您的产品密钥必定要受到威胁。

     阅读了项目源代码后,其实程序的核心也是最有价值的部分就是去解码\\HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion 中的DigitalProductId 值。如下代码所示:

public static string DecodeProductKey(byte[] digitalProductId)
{
    // Offset of first byte of encoded product key in 
    // 'DigitalProductIdxxx" REG_BINARY value. Offset = 34H.
    const int keyStartIndex = 52;
    // Offset of last byte of encoded product key in 
    // 'DigitalProductIdxxx" REG_BINARY value. Offset = 43H.
    const int keyEndIndex = keyStartIndex + 15;
    // Possible alpha-numeric characters in product key.
    char[] digits = new char[]
    {
        'B', 'C', 'D', 'F', 'G', 'H', 'J', 'K', 'M', 'P', 'Q', 'R', 
        'T', 'V', 'W', 'X', 'Y', '2', '3', '4', '6', '7', '8', '9',
    };
    // Length of decoded product key
    const int decodeLength = 29;
    // Length of decoded product key in byte-form.
    // Each byte represents 2 chars.
    const int decodeStringLength = 15;
    // Array of containing the decoded product key.
    char[] decodedChars = new char[decodeLength];
    // Extract byte 52 to 67 inclusive.
    ArrayList hexPid = new ArrayList();
    for (int i = keyStartIndex; i <= keyEndIndex; i++)
    {
        hexPid.Add(digitalProductId[i]);
    }
    for (int i = decodeLength - 1; i >= 0; i--)
    {
        // Every sixth char is a separator.
        if ((i + 1) % 6 == 0)
        {
            decodedChars[i] = '-';
        }
        else
        {
            // Do the actual decoding.
            int digitMapIndex = 0;
            for (int j = decodeStringLength - 1; j >= 0; j--)
            {
                int byteValue = (digitMapIndex << 8) | (byte)hexPid[j];
                hexPid[j] = (byte)(byteValue / 24);
                digitMapIndex = byteValue % 24;
                decodedChars[i] = digits[digitMapIndex];
            }
        }
    }
    return new string(decodedChars);
}

     最后将读取出的DigitalProductId 值(Byte)赋给DecodeProductKey 方法即可算出Windows 产品密钥。项目描述中提到该程序在XP、Vista、Windows 7 系统上均可运行。

RegistryKey hklm = Registry.LocalMachine;
hklm = hklm.OpenSubKey("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion");
byte[] digitalProductId = hklm.GetValue("DigitalProductId") as byte[];
textBox1.Text = DecodeProductKey(digitalProductId);

     由此可见简单几行代码就可以使产品密钥落入他人之手,并且这类程序在网上还有很多。对于Vista、Windows 7 用户来说建议使用slmgr /cpky 命令对产品密钥进行一下处理,详细内容请参考《Windows 7 产品密钥是否安全》。从注册表清除产品密钥信息后,再运行该程序便会出现下图效果,产品密钥将全部显示为字母“B”,这样您就不必担心产品密钥的安全性了。

PK

抱歉!评论已关闭.