def epidGenerator(kmsId, version, lcid): # Generate Part 2: Group ID and Product Key ID Range xml = parse(tokenize(open('KmsDataBase.xml')), lesslist=False) for item in xml['KmsData'][0]['CsvlkItems'][0]['CsvlkItem']: if '@VlmcsdIndex' in item and kmsId in [ uuid.UUID(kms_item['@KmsItem']) for kms_item in item['Activate'] ]: group_id, key_id_min, key_id_max = int(item['@GroupId']), int( item['@MinKeyId']), int(item['@MaxKeyId']) break else: for item in xml['KmsData'][0]['CsvlkItems'][0]['CsvlkItem']: if kmsId in [ uuid.UUID(kms_item['@KmsItem']) for kms_item in item['Activate'] ]: group_id, key_id_min, key_id_max = int(item['@GroupId']), int( item['@MinKeyId']), int(item['@MaxKeyId']) break else: group_id, key_id_min, key_id_max = fallback_group_id, fallback_key_id_min, fallback_key_id_max # Generate Part 3 and Part 4: Product Key ID productKeyID = random.randint(key_id_min, key_id_max) # 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 # 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 return '%05d-%05d-%03d-%06d-%02d-%04d-%s-%03d%04d' % ( platform_id, group_id, productKeyID // 1000000, productKeyID % 1000000, licenseChannel, languageCode, os_build, randomDayNumber, randomYear)
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: print("Error %s:" % e.args[0]) sys.exit(1) finally: if con: con.commit() con.close() if self.config['debug']: print("KMS Request Bytes:", binascii.b2a_hex(kmsRequest.__bytes__())) print("KMS Request:", kmsRequest.dump()) clientMachineId = str(kmsRequest['clientMachineId'].get()) applicationId = str(kmsRequest['applicationId'].get()) skuId = str(kmsRequest['skuId'].get()) requestDatetime = filetimes.filetime2timestamp(kmsRequest['requestTime']) if not hasattr(time, 'libc'): local_dt = time.strftime('%Y-%m-%d %H:%M:%S (UTC%z)', time.localtime(requestDatetime)) else: # micropython-time doesn't support time zone local_dt = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(requestDatetime)) # activation threshold: # https://docs.microsoft.com/en-us/windows/deployment/volume-activation/activate-windows-10-clients-vamt kmsdata = parse(tokenize(open(kmsdb)), lesslist=False)['KmsData'][0] appName, skuName, currentClientCount = applicationId, skuId, 25 for app in kmsdata['AppItems'][0]['AppItem']: max_activ_thld = 0 for kms in app['KmsItem']: max_activ_thld = max(max_activ_thld, int(kms.get('@NCountPolicy', 25))) for sku in kms.get('SkuItem', []): if sku['@Id'] == skuId: skuName = sku['@DisplayName'] if app['@Id'] == applicationId: appName = app['@DisplayName'] currentClientCount = max_activ_thld * 2 infoDict = { "machineName" : kmsRequest.getMachineName(), "clientMachineId" : clientMachineId, "appId" : appName, "skuId" : skuName, "licenseStatus" : kmsRequest.getLicenseStatus(), "requestTime" : int(time.time()), "kmsEpid" : None } #print infoDict if self.config['verbose']: print(" Machine Name: %s" % infoDict["machineName"]) print("Client Machine ID: %s" % infoDict["clientMachineId"]) print(" Application ID: %s" % infoDict["appId"]) print(" SKU ID: %s" % infoDict["skuId"]) print(" Licence Status: %s" % infoDict["licenseStatus"]) print(" Request Time: %s" % local_dt) 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: print("Error %s:" % e.args[0]) except sqlite3.Error as e: print("Error %s:" % e.args[0]) sys.exit(1) finally: if con: con.commit() con.close() return self.createKmsResponse(kmsRequest, currentClientCount)
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: print("Error %s:" % e.args[0]) sys.exit(1) finally: if con: con.commit() con.close() if self.config['debug']: print("KMS Request Bytes:", binascii.b2a_hex(kmsRequest.__bytes__())) print("KMS Request:", kmsRequest.dump()) clientMachineId = str(kmsRequest['clientMachineId'].get()) applicationId = str(kmsRequest['applicationId'].get()) skuId = str(kmsRequest['skuId'].get()) requestDatetime = filetimes.filetime2timestamp(kmsRequest['requestTime']) if not hasattr(time, 'libc'): local_dt = time.strftime('%Y-%m-%d %H:%M:%S (UTC%z)', time.localtime(requestDatetime)) else: # micropython-time doesn't support time zone local_dt = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(requestDatetime)) # activation threshold: # https://docs.microsoft.com/en-us/windows/deployment/volume-activation/activate-windows-10-clients-vamt kmsdata = parse(tokenize(open(kmsdb)), lesslist=False)['KmsData'][0] appName, skuName, currentClientCount = applicationId, skuId, 25 for app in kmsdata['AppItem']: max_activ_thld = 0 for kms in app['KmsItem']: max_activ_thld = max(max_activ_thld, int(kms.get('@NCountPolicy', 25))) for sku in kms.get('SkuItem', []): if sku['@Id'] == skuId: skuName = sku['@DisplayName'] if app['@Id'] == applicationId: appName = app['@DisplayName'] currentClientCount = max_activ_thld * 2 infoDict = { "machineName" : kmsRequest.getMachineName(), "clientMachineId" : clientMachineId, "appId" : appName, "skuId" : skuName, "licenseStatus" : kmsRequest.getLicenseStatus(), "requestTime" : int(time.time()), "kmsEpid" : None } #print infoDict if self.config['verbose']: print(" Machine Name: %s" % infoDict["machineName"]) print("Client Machine ID: %s" % infoDict["clientMachineId"]) print(" Application ID: %s" % infoDict["appId"]) print(" SKU ID: %s" % infoDict["skuId"]) print(" Licence Status: %s" % infoDict["licenseStatus"]) print(" Request Time: %s" % local_dt) 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: print("Error %s:" % e.args[0]) except sqlite3.Error as e: print("Error %s:" % e.args[0]) sys.exit(1) finally: if con: con.commit() con.close() return self.createKmsResponse(kmsRequest, currentClientCount)