Created
March 19, 2011 01:06
-
-
Save Spaceghost/877110 to your computer and use it in GitHub Desktop.
A script to decrypt windows product keys written in python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import _winreg | |
def DecodeKey(rpk): | |
rpkOffset = 52 | |
i = 28 | |
szPossibleChars = "BCDFGHJKMPQRTVWXY2346789" | |
szProductKey = "" | |
while i >= 0: | |
dwAccumulator = 0 | |
j = 14 | |
while j >= 0: | |
dwAccumulator = dwAccumulator * 256 | |
d = rpk[j+rpkOffset] | |
if isinstance(d, str): | |
d = ord(d) | |
dwAccumulator = d + dwAccumulator | |
rpk[j+rpkOffset] = (dwAccumulator / 24) if (dwAccumulator / 24) <= 255 else 255 | |
dwAccumulator = dwAccumulator % 24 | |
j = j - 1 | |
i = i - 1 | |
szProductKey = szPossibleChars[dwAccumulator] + szProductKey | |
if ((29 - i) % 6) == 0 and i != -1: | |
i = i - 1 | |
szProductKey = "-" + szProductKey | |
return szProductKey | |
def GetKeyFromRegLoc(key, value="DigitalProductID"): | |
key = _winreg.OpenKey( | |
_winreg.HKEY_LOCAL_MACHINE,key) | |
value, type = _winreg.QueryValueEx(key, value) | |
return DecodeKey(list(value)) | |
def GetIEKey(): | |
return GetKeyFromRegLoc("SOFTWARE\Microsoft\Internet Explorer\Registration") | |
def GetXPKey(): | |
return GetKeyFromRegLoc("SOFTWARE\Microsoft\Windows NT\CurrentVersion") | |
def GetWPAKey(): | |
return GetKeyFromRegLoc("SYSTEM\WPA\Key-4F3B2RFXKC9C637882MBM") | |
print "XP: %s" % GetXPKey() | |
print "IE: %s" % GetIEKey() | |
print "WPA: %s" % GetWPAKey() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have created a windows package that does exactly that job, without the need of
os.system
for security reasons (wmi package is required though).You can find the code here https://github.com/netinvent/windows_tools/blob/master/windows_tools/product_key/__init__.py which also contains this as a backup solution for elder windows versions.
You might install the whole package with
pip install windows_tools.product_key
then just use the following:[EDIT]
I also have a self elevating package that installs with this one, and works with vanilla / pyinstaller / nuitka python builds
You'll find it at https://github.com/netinvent/command_runner
[/EDIT]