从Linux检索/解密Windows 7产品密钥


19

我不小心断开了仍在运行的硬盘驱动器,并损坏了Windows 7安装;我现在完全无法启动Windows。我已经尝试了所有方法来尝试修复安装:Windows启动修复,chkdsk / r,SFC / scannow,bootrec / rebuildbcd等,但是没有运气。我只想执行全新安装,但是我的问题是我的Windows产品密钥没有记录在任何地方,并且由于无法启动Windows,所以无法使用任何脚本或实用程序从注册表中检索它。

Windows 7产品密钥以加密形式存储在注册表项HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Windows NT \ CurrentVersion的“ DigitalProductId”值中。我能够从Ubuntu实时CD挂载损坏的Windows分区,并将其包含问题的键和值的Windows \ System32 \ config \ SOFTWARE注册表配置单元复制到闪存驱动器,但是将此配置单元加载到regedit中在运行正常的Windows安装上,然后尝试使用脚本或实用程序来解密已加载的“ DigitalProductId”值,无论我尝试了多少摆弄,都只会返回主机Windows安装的产品密钥。我曾尝试与Microsoft支持人员联系,但他们一直无济于事。有人能进一步指导我吗?也许还有其他从Linux检索产品密钥的方法吗?

如果更熟悉脚本/密码学的人愿意尝试并遵循解密脚本来手动解密产品密钥,我可以通过电子邮件将导出的“ DigitalProductId”值,SOFTWARE注册表配置单元和解密脚本发送给您。


这听起来不对。如果您购买了许可证,则应该拥有密钥。现在,另一方面,如果您将手放在其他人的Windows图像上并想要提取其密钥,那么这并不是本网站的重点。
JasonXA 2015年

我确实购买了许可证。我有安装DVD,但是找不到附带的产品密钥。但我想我可能已经在这里找到了解决方案:dagondesign.com/articles/windows-xp-product-key-recovery / ...
sundiata 2015年

是的,这确实可行。使用该方法,我设法重现了我的密钥。
JasonXA 2015年

如果您的固件是基于UEFI的,则许可证密钥实际上存储在ACPI MSDM表中,因此它在重新引导后仍然存在。如果是这样,请参阅blog.fpmurphy.com以获取有关如何恢复它的详细信息。
fpmurphy

Answers:


30

Linux有一个很棒的工具叫做chntpw。您可以通过以下方式在Debian / Ubuntu上轻松获得它:

sudo apt install chntpw

要查看相关的注册表文件,请挂载Windows磁盘并按如下所示打开它:

chntpw -e /path/to/windisk/Windows/System32/config/software

现在,要获取解码,请DigitalProductId输入以下命令:

dpi \Microsoft\Windows NT\CurrentVersion\DigitalProductId

5
相关注册表文件的路径位于/ path / to / windisk / Windows / System32 / config / RegBack / SOFTWARE
Mohamed EL HABIB

2
这是一个很好的答案,我在Ask Ubuntu上引用了它:askubuntu.com/a/953130/75060
Mark Kirby

这次真是万分感谢。请做笔记以检查文件夹和文件名的大小写。就我而言,我必须使用大写字母SOFTWARE作为文件名。
帕迪·兰道

如果您在读取system32文件夹时遇到问题,请尝试制作副本并将该副本的路径提供给chntpw。
Markus von Broady

2

对于那些不害羞的人,可以做一些编码。

我在10年前发现了一种算法,并在C#中实现了该算法(请参见下文)


如果您只想在Windows上运行

我自由地将其转换为powershell脚本:

$dpid = Get-ItemProperty -Path "Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion" -Name "DigitalProductId"

# Get the range we are interested in
$id = $dpid.DigitalProductId[52..(52+14)]

# Character table
$chars = "BCDFGHJKMPQRTVWXY2346789"

# Variable for the final product key
$pkey = ""

# Calculate the product key
for ($i=0; $i -le 24; $i++) {
    $c = 0

    for($j=14; $j -ge 0; $j--) {
        $c = ($c -shl 8) -bxor $id[$j]

        $id[$j] = [Math]::Floor($c / 24) -band 255

        $c = $c % 24
    }
    $pkey = $chars[$c] + $pkey
}
# Insert some dashes
for($i = 4; $i -gt 0; $i--) {
    $pkey = $pkey.Insert($i * 5, "-")
}
$pkey

运行此命令,您将获得产品密钥。(因此,最终没有为您编码)


原始帖子

这就是我挖掘并注释的实际C#代码。

public static string ConvertDigitalProductID(string regPath, string searchKey = "DigitalProductID") {
    // Open the sub key i.E.: "Software\Microsoft\Windows NT\CurrentVersion"
    var regkey = Registry.LocalMachine.OpenSubKey(regPath, false);
    // Retreive the value of "DigitalProductId"
    var dpid = (byte[])regkey.GetValue(searchKey);
    // Prepare an array for the relevant parts
    var idpart = new byte[15];

    // Copy the relevant parts of the array
    Array.Copy(dpid, 52, idpart, 0, 15);

    // Prepare the chars that will make up the key
    var charStore = "BCDFGHJKMPQRTVWXY2346789";

    // Prepare a string for the result
    string productkey = "";

    // We need 24 iterations (one for each character)
    for(int i = 0; i < 25; i++) {

        int c = 0;
        // Go through each of the 15 bytes of our dpid
        for(int j = 14; j >= 0; j--) {
            // Shift the current byte to the left and xor in the next byte
            c = (c << 8) ^ idpart[j];

            // Leave the result of the division in the current position
            idpart[j] = (byte)(c / 24);

            // Take the rest of the division forward to the next round
            c %= 24;
        }
        // After each round, add a character from the charStore to our key
        productkey = charStore[c] + productkey;
    }

    // Insert the dashes
    for(int i = 4; i > 0; i--) {
        productkey = productkey.Insert(i * 5, "-");
    }

    return productkey;
}

您必须将其Software\Microsoft\Windows NT\CurrentVersion作为密钥传递,然后才能在其中找到DigitalProductId

当时MS Office产品使用相同的算法,因此通过为函数提供相关的注册表项,它也可以计算这些产品密钥。

当然,您可以重构该函数,使其将字节数组作为输入。

至于今天。我刚刚在Windows 10机器上对其进行了测试,但仍然可以使用。


这是一个很好的答案,但问题很老,可能无法收到很多意见。当你是会员,请考虑将您的答案,我们目前提出的Ubuntu后askubuntu.com/questions/953126/...
马克·柯比

谢谢。但是我相信那将不在那儿。我可能会一起拍一个伪代码实现。并将其作为实际实现参考。
MrPaulch '17

没问题,做您认为最好的事情
Mark Kirby

2

这是其他答案的Python端口(适用于Windows 8.1)。这样做的好处chntpw是,即使驱动器处于只读状态也可以使用。

要求:

pip install python-registry

码:

#!/usr/bin/env python
import sys
from Registry import Registry
reg = Registry.Registry("/path/to/drive/Windows/System32/config/RegBack/SOFTWARE")
# Uncomment for registry location for Windows 7 and below:
#reg = Registry.Registry("/path/to/drive/Windows/system32/config/software")
key = reg.open("Microsoft\Windows NT\CurrentVersion")
did = bytearray([v.value() for v in key.values() if v.name() == "DigitalProductId"][0])
idpart = did[52:52+15]
charStore = "BCDFGHJKMPQRTVWXY2346789";
productkey = "";
for i in range(25):
  c = 0
  for j in range(14, -1, -1):
    c = (c << 8) ^ idpart[j]
    idpart[j] = c // 24
    c %= 24
  productkey = charStore[c] + productkey
print('-'.join([productkey[i * 5:i * 5 + 5] for i in range(5)]))

内循环太​​短了一次迭代。现在应该可以工作了。
Lenar Hoyt

0

这是我的bash实现。我称它为get_windows_key.sh在clonezilla中效果很好。我最初将其发布在这里https://sourceforge.net/p/clonezilla/discussion/Open_discussion/thread/979f335385/

#!/bin/bash
# written by Jeff Sadowski
# credit
###################################################
# Pavel Hruška, Scott Skahht, and Philip M for writting
# https://github.com/mrpeardotnet/WinProdKeyFinder/blob/master/WinProdKeyFind/KeyDecoder.cs
# that I got my conversion code from
#
# I used the comments on the sudo code from
# /ubuntu/953126/can-i-recover-my-windows-product-key- from-ubuntu
# by MrPaulch
#
# and the creator of chntpw
#
# Petter Nordahl-Hagen
# without which I would not be able to get the key in linux
#
# also the creators of ntfs-3g, linux and bash

parted -l 2>/dev/null |grep -e ntfs -e fat -e Disk|grep -v Flags
#get the first mac address that isn't a loopback address
# loopback will have all zeros
MAC=$(cat /sys/class/net/*/address|grep -v 00:00:00:00:00:00|head -n 1|sed "s/:/-/g")
if [ "$1" = "" ];then
 echo "mount the Windows share then give this script the path where you mounted it"
 exit
fi
cd $1
#
# This way will work no matter what the capitalization is
next=$(find ./ -maxdepth 1 -iname windows);cd ${next}
next=$(find ./ -maxdepth 1 -iname system32);cd ${next}
next=$(find ./ -maxdepth 1 -iname config);cd ${next}
file=$(find ./ -maxdepth 1 -iname software)
#echo $(pwd)${file:1}
#Get the necissary keys
#get the version key
VERSION=$((16#$(echo -e "cat \\Microsoft\\Windows NT\\CurrentVersion\\CurrentMajorVersionNumber\nq\n" | chntpw -e ${file}|grep "^0x"|cut -dx -f2)))
hexPid_csv_full=$(echo $(echo -e "hex \\Microsoft\\Windows NT\\CurrentVersion\\DigitalProductId\nq\n" | chntpw -e ${file}|grep "^:"|cut -b 9-55)|sed 's/ /,/g' | tr '[:u>
# get the subset 53 to 68 of the registry entry
hexPid_csv=$(echo $(echo -e "hex \\Microsoft\\Windows NT\\CurrentVersion\\DigitalProductId\nq\n" | chntpw -e ${file}|grep "^:"|cut -b 9-55)|sed 's/ /,/g' | tr '[:upper:>
echo "${hexPid_csv_full}" > /custom/DigitalProductId_${MAC}.txt
#formatted output
spread()
{
 key=$1
 echo ${key:0:5}-${key:5:5}-${key:10:5}-${key:15:5}-${key:20:5}
}
# almost a direct conversion of c# code from
# https://github.com/mrpeardotnet/WinProdKeyFinder/blob/master/WinProdKeyFind/KeyDecoder.cs
# however most of this looks similar to sudo code I found
# /ubuntu/953126/can-i-recover-my-windows-product-key-from-ubuntu
DecodeProductKey()
{
digits=(B C D F G H J K M P Q R T V W X Y 2 3 4 6 7 8 9)
for j in {0..15};do
#Populate the Pid array from the values found in the registry
 Pid[$j]=$((16#$(echo ${hexPid_csv}|cut -d, -f $(($j+1)))))
done
if [ "$1" = "8+" ];then
# modifications needed for getting the windows 8+ key
 isWin8=$(($((${Pid[14]}/6))&1))
 Pid[14]=$(( $(( ${Pid[14]}&247 )) | $(( $(( ${isWin8} & 2 )) * 4 )) ))
fi
key=""
last=0
for i in {24..0};do
 current=0
 for j in {14..0};do
  # Shift the current contents of c to the left by 1 byte 
  # and add it with the next byte of our id
  current=$((${current}*256))
  current=$((${Pid[$j]} + current))
  # Put the result of the divison back into the array
  Pid[$j]=$((${current}/24))
  # Calculate remainder of c
  current=$((${current}%24))
  last=${current}
 done
 # Take character at position c and prepend it to the ProductKey
 key="${digits[${current}]}${key}"
done
if [ "$1" = "8+" ];then
# another modification needed for a windows 8+ key
 key="${key:1:${last}}N${key:$((${last}+1)):24}"
 echo -n "Windows 8+ key: "
else
 echo -n "Windows 7- key: "
fi
spread "${key}"
}
if [ "$VERSION" -gt "7" ];then
 DecodeProductKey 8+
else
 DecodeProductKey
fi
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.