def updateConfig(): kmsdb = kmsDB2Dict() appitems = kmsdb[2] for appitem in appitems: kmsitems = appitem['KmsItems'] for kmsitem in kmsitems: # Threshold. try: count = int(kmsitem['NCountPolicy']) except KeyError: count = 25 name = re.sub('\(.*\)', '', kmsitem['DisplayName']).replace('2015', '').replace(' ', '') if name == config['mode']: skuitems = kmsitem['SkuItems'] # Select 'Enterprise' for Windows or 'Professional Plus' for Office. # (improvement: choice could be also random: skuitem = random.choice(skuitems)) for skuitem in skuitems: if skuitem['DisplayName'].replace(' ','') == name + 'Enterprise' or \ skuitem['DisplayName'].replace(' ','') == name[:6] + 'ProfessionalPlus' + name[6:]: config['KMSClientSkuID'] = skuitem['Id'] config['RequiredClientCount'] = count config['KMSProtocolMajorVersion'] = int( float(kmsitem['DefaultKmsProtocol'])) config['KMSProtocolMinorVersion'] = 0 config['KMSClientLicenseStatus'] = 2 config['KMSClientAppID'] = appitem['Id'] config['KMSClientKMSCountedID'] = kmsitem['Id'] break
def serverLogic(self, kmsRequest): if self.config['sqlite'] and self.config['dbSupport']: self.dbName = 'clients.db' if not os.path.isfile(self.dbName): # Initialize the database. con = None try: con = sqlite3.connect(self.dbName) cur = con.cursor() cur.execute( "CREATE TABLE clients(clientMachineId TEXT, machineName TEXT, applicationId TEXT, \ skuId TEXT, licenseStatus TEXT, lastRequestTime INTEGER, kmsEpid TEXT, requestCount INTEGER)" ) except sqlite3.Error as e: logger.error("Error %s:" % e.args[0]) sys.exit(1) finally: if con: con.commit() con.close() shell_message(nshell=15) kmsRequest = byterize(kmsRequest) logger.debug("KMS Request Bytes: \n%s\n" % justify( binascii.b2a_hex( str(kmsRequest).encode('latin-1')).decode('utf-8'))) logger.debug("KMS Request: \n%s\n" % justify(kmsRequest.dump(print_to_stdout=False))) clientMachineId = kmsRequest['clientMachineId'].get() applicationId = kmsRequest['applicationId'].get() skuId = kmsRequest['skuId'].get() requestDatetime = filetimes.filetime_to_dt(kmsRequest['requestTime']) # Localize the request time, if module "tzlocal" is available. try: from tzlocal import get_localzone from pytz.exceptions import UnknownTimeZoneError try: tz = get_localzone() local_dt = tz.localize(requestDatetime) except UnknownTimeZoneError: logger.warning( 'Unknown time zone ! Request time not localized.') local_dt = requestDatetime except ImportError: logger.warning( 'Module "tzlocal" not available ! Request time not localized.') local_dt = requestDatetime # Get SkuId, AppId and client threshold. appName, skuName = applicationId, skuId kmsdb = kmsDB2Dict() appitems = kmsdb[2] for appitem in appitems: kmsitems = appitem['KmsItems'] for kmsitem in kmsitems: # Activation threshold. try: count = int(kmsitem['NCountPolicy']) except KeyError: count = 25 if self.config["CurrentClientCount"] <= count: currentClientCount = count + 1 else: currentClientCount = self.config["CurrentClientCount"] skuitems = kmsitem['SkuItems'] for skuitem in skuitems: try: if uuid.UUID(skuitem['Id']) == skuId: skuName = skuitem['DisplayName'] break except IndexError: pass if uuid.UUID(appitem['Id']) == applicationId: appName = appitem['DisplayName'] infoDict = { "machineName": kmsRequest.getMachineName(), "clientMachineId": str(clientMachineId), "appId": appName, "skuId": skuName, "licenseStatus": kmsRequest.getLicenseStatus(), "requestTime": int(time.time()), "kmsEpid": None } #print infoDict logger.info("Machine Name: %s" % infoDict["machineName"]) logger.info("Client Machine ID: %s" % infoDict["clientMachineId"]) logger.info("Application ID: %s" % infoDict["appId"]) logger.info("SKU ID: %s" % infoDict["skuId"]) logger.info("License Status: %s" % infoDict["licenseStatus"]) logger.info("Request Time: %s" % local_dt.strftime('%Y-%m-%d %H:%M:%S %Z (UTC%z)')) if self.config['sqlite'] and self.config['dbSupport']: con = None try: con = sqlite3.connect(self.dbName) cur = con.cursor() cur.execute( "SELECT * FROM clients WHERE clientMachineId=:clientMachineId;", infoDict) try: data = cur.fetchone() if not data: #print "Inserting row..." cur.execute( "INSERT INTO clients (clientMachineId, machineName, applicationId, \ skuId, licenseStatus, lastRequestTime, requestCount) VALUES (:clientMachineId, :machineName, :appId, :skuId, :licenseStatus, :requestTime, 1);", infoDict) else: #print "Data:", data if data[1] != infoDict["machineName"]: cur.execute( "UPDATE clients SET machineName=:machineName WHERE \ clientMachineId=:clientMachineId;", infoDict) if data[2] != infoDict["appId"]: cur.execute( "UPDATE clients SET applicationId=:appId WHERE \ clientMachineId=:clientMachineId;", infoDict) if data[3] != infoDict["skuId"]: cur.execute( "UPDATE clients SET skuId=:skuId WHERE \ clientMachineId=:clientMachineId;", infoDict) if data[4] != infoDict["licenseStatus"]: cur.execute( "UPDATE clients SET licenseStatus=:licenseStatus WHERE \ clientMachineId=:clientMachineId;", infoDict) if data[5] != infoDict["requestTime"]: cur.execute( "UPDATE clients SET lastRequestTime=:requestTime WHERE \ clientMachineId=:clientMachineId;", infoDict) # Increment requestCount cur.execute( "UPDATE clients SET requestCount=requestCount+1 WHERE \ clientMachineId=:clientMachineId;", infoDict) except sqlite3.Error as e: logger.error("Error %s:" % e.args[0]) except sqlite3.Error as e: logger.error("Error %s:" % e.args[0]) sys.exit(1) finally: if con: con.commit() con.close() return self.createKmsResponse(kmsRequest, currentClientCount)
def epidGenerator(kmsId, version, lcid): kmsdb = kmsDB2Dict() winbuilds, csvlkitems, appitems = kmsdb[0], kmsdb[1], kmsdb[2] hosts, pkeys = [[] for _ in range(2)] # 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'])) except IndexError: # fallback to Windows Server 2019 parameters. GroupId, MinKeyId, MaxKeyId, Invalid = 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]) # Get all KMS Server Host Builds good for EPID generation, then # Generate Part 1 & 7: Host Type and KMS Server OS Build # https://www.itprotoday.com/windows-78/volume-activation-server-2008 # https://docs.microsoft.com/en-us/windows-server/get-started-19/activation-19 # https://docs.microsoft.com/en-us/windows-server/get-started/windows-server-release-info # https://support.microsoft.com/en-us/help/13853/windows-lifecycle-fact-sheet for winbuild in winbuilds: try: # Check versus "InvalidWinBuild". if int(winbuild['WinBuildIndex']) not in Invalid: # Re-check versus "version" protocol. if ((version == 4 and int(winbuild['BuildNumber']) >= 7601) or (version == 5 and int(winbuild['BuildNumber']) >= 9200) or (version == 6 and int(winbuild['BuildNumber']) >= 9600)): hosts.append(winbuild) except KeyError: # fallback to Windows Server 2019 parameters. BuildNumber, PlatformId, MinDate = '17763', '3612', '02/10/2018' host = random.choice(hosts) BuildNumber, PlatformId, MinDate = host['BuildNumber'], host[ 'PlatformId'], host['MinDate'] # Generate Part 3 and Part 4: Product Key ID productKeyID = random.randint(MinKeyId, MaxKeyId) # 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 d = datetime.datetime.strptime(MinDate, "%d/%m/%Y") minTime = datetime.date(d.year, d.month, d.day) # 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 result = [] result.append(str(PlatformId).rjust(5, "0")) result.append("-") result.append(str(GroupId).rjust(5, "0")) result.append("-") result.append(str(productKeyID / 1000000).rjust(3, "0")) result.append("-") result.append(str(productKeyID % 1000000).rjust(6, "0")) result.append("-") result.append(str(licenseChannel).rjust(2, "0")) result.append("-") result.append(str(languageCode)) result.append("-") result.append(str(BuildNumber).rjust(4, "0")) result.append(".0000-") result.append(str(randomDayNumber).rjust(3, "0")) result.append(str(randomDate.year).rjust(4, "0")) return "".join(result)
from tzlocal import get_localzone from pytz.exceptions import UnknownTimeZoneError try: tz = get_localzone() local_dt = tz.localize(requestDatetime) except UnknownTimeZoneError: logging.warning('Unknown time zone ! Request time not localized.') local_dt = requestDatetime except ImportError: logging.warning('Module "tzlocal" not available ! Request time not localized.') local_dt = requestDatetime # Get SkuId, AppId and client threshold. appName, skuName = applicationId, skuId kmsdb = kmsDB2Dict() appitems = kmsdb[2] for appitem in appitems: kmsitems = appitem['KmsItems'] for kmsitem in kmsitems: # Activation threshold. try: count = int(kmsitem['NCountPolicy']) except KeyError: count = 25 if self.config["CurrentClientCount"] <= count: currentClientCount = count + 1 else:
def epidGenerator(kmsId, version, lcid): kmsdb = kmsDB2Dict() winbuilds, csvlkitems, appitems = kmsdb[0], kmsdb[1], kmsdb[2] hosts, pkeys = [[] for _ in range(2)] # 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'])) else: # fallback to Windows Server 2019 parameters. pkeys.append(('206', '551000000', '570999999', '[0,1,2]')) except IndexError: # fallback to Windows Server 2019 parameters. 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]) # Get all KMS Server Host Builds good for EPID generation, then # 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: hosts.append(winbuild) except KeyError: # fallback to Windows Server 2019 parameters. hosts.append({ 'BuildNumber': '17763', 'PlatformId': '3612', 'MinDate': '02/10/2018' }) host = random.choice(hosts) BuildNumber, PlatformId, MinDate = host['BuildNumber'], host[ 'PlatformId'], host['MinDate'] # Generate Part 3 and Part 4: Product Key ID productKeyID = random.randint(MinKeyId, MaxKeyId) # 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 d = datetime.datetime.strptime(MinDate, "%d/%m/%Y") minTime = datetime.date(d.year, d.month, d.day) # 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 result = [] result.append(str(PlatformId).rjust(5, "0")) result.append("-") result.append(str(GroupId).rjust(5, "0")) result.append("-") result.append(str(productKeyID / 1000000).rjust(3, "0")) result.append("-") result.append(str(productKeyID % 1000000).rjust(6, "0")) result.append("-") result.append(str(licenseChannel).rjust(2, "0")) result.append("-") result.append(str(languageCode)) result.append("-") result.append(str(BuildNumber).rjust(4, "0")) result.append(".0000-") result.append(str(randomDayNumber).rjust(3, "0")) result.append(str(randomDate.year).rjust(4, "0")) return "".join(result)