Abrufen/Entschlüsseln von Windows 7 Produktschlüssel von Linux

Habe ich versehentlich getrennt meiner Festplatte während es noch läuft und beschädigt meine Windows 7-installation; jetzt bin ich völlig unfähig, boot into Windows. Ich habe alles versucht, um die Installation zu reparieren: Windows Startup Repair, chkdsk / r, SFC /scannow, bootrec /rebuildbcd usw. und kein Glück. Ich möchte nur eine Neuinstallation durchführen, aber mein Problem ist, dass ich meinen Windows-Produktschlüssel nirgendwo niedergeschrieben habe und keine Skripte oder dienstprogramme zum Abrufen aus der Registrierung, da ich nicht in Windows booten kann.

Windows 7-Produktschlüssel werden verschlüsselt im Wert "DigitalProductId" des Registrierungsschlüssels HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion gespeichert. Ich konnte die beschädigte Windows-Partition schreibgeschützt von einer Ubuntu Live-CD mounten und den Windows\System32\config\SOFTWARE registry Hive, der den fraglichen Schlüssel und Wert enthält, auf ein Flash-Laufwerk kopieren, aber diesen Hive in Regedit laden auf eine funktionierende Windows-Installation und der Versuch, Skripte oder Dienstprogramme zum Entschlüsseln des geladenen Werts "DigitalProductId" zu verwenden, geben nur den Produktschlüssel der Host-Windows-Installation zurück, unabhängig davon, wie viel ich versuche. Ich habe versucht, den Microsoft-Support zu kontaktieren, und sie waren ziemlich wenig hilfreich. Würde mich jemand weiter führen können? Vielleicht, wenn es eine andere Möglichkeit gibt, den Produktschlüssel von Linux abzurufen?

Wenn jemandem mehr vertraut mit scripting/Kryptographie wäre bereit, versuchen Sie und folgen Sie dem Entschlüsselungsskript, um den Produktschlüssel von Hand zu entschlüsseln, ich könnte Ihnen den exportierten "DigitalProductId"-Wert, SOFTWARE Registry Hive und Entschlüsselungsskript per E-Mail senden.

Author: sundiata, 2015-04-04

5 answers

Es gibt ein großartiges Tool für Linux namens chntpw. Sie können es leicht auf Debian / Ubuntu bekommen über:

sudo apt install chntpw

Um in die entsprechende Registrierungsdatei zu schauen, mounten Sie die Windows-Festplatte und öffnen Sie sie wie folgt:

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

Um nun das decodierte DigitalProductId zu erhalten, geben Sie diesen Befehl ein:

dpi \Microsoft\Windows NT\CurrentVersion\DigitalProductId
 34
Author: Thomas,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2017-04-20 18:15:30

Für diejenigen, die nicht schüchtern sind, ein wenig Codierung zu tun.

Ich habe vor ungefähr 10 Jahren einen Algorithmus gefunden und ihn in C# implementiert (siehe unten)


Wenn Sie es nur unter Windows ausführen möchten

Ich habe mir die Freiheit genommen, es in ein Powershell-Skript zu konvertieren:

$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

Führen Sie dies aus und Sie erhalten Ihren Produktschlüssel. (Also keine Codierung für dich)


Original Beitrag

Dies ist also der eigentliche C# - Code, den ich ausgegraben habe und kommentiert.

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;
}

Sie müssen es Software\Microsoft\Windows NT\CurrentVersion als Schlüssel übergeben, wo es das DigitalProductId

Zu dieser Zeit verwendeten MS Office-Produkte denselben Algorithmus, sodass die Funktion durch die Bereitstellung des entsprechenden Registrierungsschlüssels auch diese Produktschlüssel berechnen konnte.

Sie können die Funktion natürlich so umgestalten, dass sie ein Byte-Array als Eingabe verwendet.

Wie für heute. Ich habe es gerade auf meinem Windows 10-Computer getestet und es funktioniert immer noch.

 3
Author: MrPaulch,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2017-09-06 11:59:36

Hier ist ein Python-Port der anderen Antwort (angepasst für Windows 8.1). Der Vorteil von chntpw gegenüber chntpw ist, dass es auch mit Laufwerken im schreibgeschützten Zustand funktioniert.

Anforderungen:

pip install python-registry

Code:

#!/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)]))
 3
Author: Lenar Hoyt,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2018-09-26 16:01:22

Hier ist meine Bash-Implementierung. Ich nenne es get_windows_key.sh funktioniert gut von Clonezilla. Ich habe es ursprünglich hier gepostet 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
# https://askubuntu.com/questions/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
# https://askubuntu.com/questions/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
 0
Author: penguinjeff,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2019-12-02 18:15:50

Vielen Dank an Lenar Hoyt für die obige Python-Lösung.

Ich habe einen PC mit Windows 10 mit einer Lizenz, die von Windows 8 aktualisiert wurde, und (gemäß Penguinjeffs Bash-Version unten) benötigen Sie geringfügige Änderungen, um mit solchen Lizenzen umzugehen.

Hinweis: Wenn Sie unter Windows ausgeführt werden, können Sie den decodierten Schlüssel teilweise überprüfen, indem Sie slmgr -dli

Auf meinen PCs meldet dies "Partial Product Key: 3V66T", während Lenars Code (Stand Sept 2018) einen falschen Schlüssel meldet "TY4CG-JDJH7-VJ2WF-DY4X9-HCFC6"

Hier ist meine modifizierte Version des Obigen, die (glaube ich) korrekt einen Schlüssel der Form "xxxxx-xxxxx-xxxxx-xxxxx-3V66T"

#!/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])
isWin8 = (did[66] // 6) & 1
if isWin8:
  did[66] = (did[66] & 0xF7) | ((isWin8 & 2) * 4)

idpart = did[52:52+15]
charStore = "BCDFGHJKMPQRTVWXY2346789";
productkey = "";
lastC = 0    # isWin8 support
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
  lastC = c
if isWin8:
  insert = "N"
  if lastC == 0:
    productkey = insert + productkey
  else:
    keypart1 = productkey[1:1+lastC]
    productkey = productkey[1:].replace(keypart1, keypart1 + insert)

print('-'.join([productkey[i * 5:i * 5 + 5] for i in range(5)]))
 0
Author: Peter.B,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2020-12-08 18:53:39