forked from ThunderEX/py-kms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kmsPidGenerator.py
134 lines (120 loc) · 4.04 KB
/
kmsPidGenerator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
try:
import random
except ImportError:
import upy.fakerandom as random
import time
try:
import uuid
except ImportError:
import upy.uuid as uuid
APP_ID_WINDOWS = uuid.UUID("55C92734-D682-4D71-983E-D6EC3F16059F")
APP_ID_OFFICE14 = uuid.UUID("59A52881-A989-479D-AF46-F275C6370663")
APP_ID_OFFICE15 = uuid.UUID("0FF1CE15-A989-479D-AF46-F275C6370663")
# KMS Host OS Type
hostOsList = {}
# Windows Server 2008 R2 SP1
hostOsList["HOST_SERVER2008R2"] = {
"type" : 55041,
"osBuild" : 7601
}
# Windows Server 2012 RTM
hostOsList["HOST_SERVER2012"] = {
"type" : 5426,
"osBuild" : 9200
}
# Windows Server 2012 R2 RTM
hostOsList["HOST_SERVER2012R2"] = {
"type" : 6401,
"osBuild" : 9600
}
# Product Specific KeyConfig
pkeyConfigList = {}
# Windows Server KMS Host PID, actual PIDRangeMax = 191999999
pkeyConfigList["windows"] = {
"GroupID" : 206,
"PIDRangeMin" : 152000000,
"PIDRangeMax" : 152999999
}
# Windows Server 2012 R2 KMS Host PID, actual PIDRangeMax = 310999999
pkeyConfigList["windows2012r2"] = {
"GroupID" : 206,
"PIDRangeMin" : 271000000,
"PIDRangeMax" : 271999999
}
# Office 2010 KMSHost Class PID, actual PIDRangeMax = 217999999
pkeyConfigList["office14"] = {
"GroupID" : 96,
"PIDRangeMin" : 199000000,
"PIDRangeMax" : 201999999
}
# Office 2013 KMSHost Class PID, actual PIDRangeMax = 255999999
pkeyConfigList["office15"] = {
"GroupID" : 206,
"PIDRangeMin" : 234000000,
"PIDRangeMax" : 234999999
}
if hasattr(str, 'rjust'):
rjust = str.rjust
else:
rjust = lambda s, width, fillchar=' ': fillchar * (width - len(s)) + s
def epidGenerator(appId, version, lcid):
# Generate Part 1 & 7: Host Type and KMS Server OS Build
hostOsType = random.choice(list(hostOsList.keys()))
hostOsDict = hostOsList[hostOsType]
# Generate Part 2: Group ID and Product Key ID Range
if appId == APP_ID_OFFICE14:
keyConfig = pkeyConfigList["office14"]
elif appId == APP_ID_OFFICE15:
keyConfig = pkeyConfigList["office15"]
else:
# Default to Windows
if hostOsDict['osBuild'] == 9600:
keyConfig = pkeyConfigList["windows2012r2"]
else:
keyConfig = pkeyConfigList["windows"]
# Generate Part 3 and Part 4: Product Key ID
productKeyID = random.randint(keyConfig["PIDRangeMin"], keyConfig["PIDRangeMax"])
# Generate Part 5: License Channel (00=Retail, 01=Retail, 02=OEM,
# 03=Volume(GVLK,MAK)) - always 03
licenseChannel = 3
# Generate Part 6: Language - use system default language
# 1033 is en-us
languageCode = lcid # C# CultureInfo.InstalledUICulture.LCID
# Generate Part 8: KMS Host Activation Date
# Get Minimum Possible Date: Newer Products first
if hostOsType == "HOST_SERVER2012R2" or version == 6:
# Microsoft Windows Server 2012 R2 RTM (October 17, 2013)
minTime = time.mktime((2013, 10, 17, 0, 0, 0, 0, 0, 0))
elif appId == APP_ID_OFFICE15:
# Microsoft Office 2013 RTM (October 24, 2012)
minTime = time.mktime((2012, 10, 24, 0, 0, 0, 0, 0, 0))
elif hostOsType == "HOST_SERVER2012" or version == 5:
# Microsoft Windows Server 2012 RTM (September 4, 2012)
minTime = time.mktime((2012, 9, 4, 0, 0, 0, 0, 0, 0))
else:
# Windows Server 2008 R2 SP1 (February 16, 2011)
minTime = time.mktime((2011, 2, 16, 0, 0, 0, 0, 0, 0))
# Generate Year and Day Number
randomDate = random.randint(int(minTime), int(time.time()))
randomYear = time.localtime(randomDate)[0]
firstOfYear = time.mktime((randomYear, 1, 1, 0, 0, 0, 0, 0, 0))
randomDayNumber = int((randomDate - firstOfYear) / 86400 + 0.5)
# generate the epid string
result = []
result.append(rjust(str(hostOsDict["type"]), 5, "0"))
result.append("-")
result.append(rjust(str(keyConfig["GroupID"]), 5, "0"))
result.append("-")
result.append(rjust(str(productKeyID // 1000000), 3, "0"))
result.append("-")
result.append(rjust(str(productKeyID % 1000000), 6, "0"))
result.append("-")
result.append(rjust(str(licenseChannel), 2, "0"))
result.append("-")
result.append(str(languageCode))
result.append("-")
result.append(rjust(str(hostOsDict["osBuild"]), 4, "0"))
result.append(".0000-")
result.append(rjust(str(randomDayNumber), 3, "0"))
result.append(rjust(str(randomYear), 4, "0"))
return "".join(result)