py-kms/py3-kms/kmsPidGenerator.py

85 lines
3.8 KiB
Python
Raw Normal View History

2018-02-28 23:27:12 +01:00
#!/usr/bin/env python3
import datetime
import random
import time
import uuid
from ast import literal_eval
2018-02-28 23:27:12 +01:00
from kmsDB2Dict import kmsDB2Dict
2018-02-28 23:27:12 +01:00
def epidGenerator(kmsId, version, lcid):
kmsdb = kmsDB2Dict()
winbuilds, csvlkitems, appitems = kmsdb[0], kmsdb[1], kmsdb[2]
hosts, pkeys = [ [] for _ in range(2) ]
2018-02-28 23:27:12 +01:00
# Product Specific Detection (Get all CSVLK GroupID and PIDRange good for EPID generation), then
# Generate Part 2: Group ID and Product Key ID Range
for csvlkitem in csvlkitems:
try:
if kmsId in [ uuid.UUID(kmsitem) for kmsitem in csvlkitem['Activate'] ]:
pkeys.append( (csvlkitem['GroupId'], csvlkitem['MinKeyId'], csvlkitem['MaxKeyId'], csvlkitem['InvalidWinBuild']) )
2018-11-25 22:03:14 +01:00
else:
# fallback to Windows Server 2019 parameters.
pkeys.append( ('206', '551000000', '570999999', '[0,1,2]') )
except IndexError:
# fallback to Windows Server 2019 parameters.
2018-11-25 22:03:14 +01:00
pkeys.append( ('206', '551000000', '570999999', '[0,1,2]') )
pkey = random.choice(pkeys)
GroupId, MinKeyId, MaxKeyId, Invalid = int(pkey[0]), int(pkey[1]), int(pkey[2]), literal_eval(pkey[3])
2018-02-28 23:27:12 +01:00
# Get all KMS Server Host Builds good for EPID generation, then
2018-02-28 23:27:12 +01:00
# Generate Part 1 & 7: Host Type and KMS Server OS Build
for winbuild in winbuilds:
try:
# Check versus "InvalidWinBuild".
if int(winbuild['WinBuildIndex']) not in Invalid:
2018-11-25 22:03:14 +01:00
hosts.append(winbuild)
except KeyError:
# fallback to Windows Server 2019 parameters.
2018-11-25 22:03:14 +01:00
hosts.append( {'BuildNumber':'17763', 'PlatformId':'3612', 'MinDate':'02/10/2018'} )
host = random.choice(hosts)
BuildNumber, PlatformId, MinDate = host['BuildNumber'], host['PlatformId'], host['MinDate']
2018-02-28 23:27:12 +01:00
# Generate Part 3 and Part 4: Product Key ID
productKeyID = random.randint(MinKeyId, MaxKeyId)
2018-02-28 23:27:12 +01:00
# Generate Part 5: License Channel (00=Retail, 01=Retail, 02=OEM, 03=Volume(GVLK,MAK)) - always 03
2018-02-28 23:27:12 +01:00
licenseChannel = 3
# Generate Part 6: Language - use system default language, 1033 is en-us
languageCode = lcid # (C# CultureInfo.InstalledUICulture.LCID)
2018-02-28 23:27:12 +01:00
# Generate Part 8: KMS Host Activation Date
d = datetime.datetime.strptime(MinDate, "%d/%m/%Y")
minTime = datetime.date(d.year, d.month, d.day)
2018-02-28 23:27:12 +01:00
# Generate Year and Day Number
randomDate = datetime.date.fromtimestamp(random.randint(time.mktime(minTime.timetuple()), time.mktime(datetime.datetime.now().timetuple())))
firstOfYear = datetime.date(randomDate.year, 1, 1)
randomDayNumber = int((time.mktime(randomDate.timetuple()) - time.mktime(firstOfYear.timetuple())) / 86400 + 0.5)
# Generate the EPID string
2018-02-28 23:27:12 +01:00
result = []
result.append(str(PlatformId).rjust(5, "0"))
2018-02-28 23:27:12 +01:00
result.append("-")
result.append(str(GroupId).rjust(5, "0"))
2018-02-28 23:27:12 +01:00
result.append("-")
result.append(str(productKeyID // 1000000).rjust(3, "0"))
2018-02-28 23:27:12 +01:00
result.append("-")
result.append(str(productKeyID % 1000000).rjust(6, "0"))
2018-02-28 23:27:12 +01:00
result.append("-")
result.append(str(licenseChannel).rjust(2, "0"))
result.append("-")
result.append(str(languageCode))
result.append("-")
result.append(str(BuildNumber).rjust(4, "0"))
2018-02-28 23:27:12 +01:00
result.append(".0000-")
result.append(str(randomDayNumber).rjust(3, "0"))
result.append(str(randomDate.year).rjust(4, "0"))
2018-02-28 23:27:12 +01:00
return "".join(result)