def encryptResponse(self, request, decrypted, response): randomSalt = self.getRandomSalt() result = hashlib.sha256(randomSalt).digest() SaltC = bytearray(enco(request['message']['salt'], 'latin-1')) DSaltC = bytearray(enco(decrypted['salt'], 'latin-1')) randomStuff = bytearray(16) for i in range(0, 16): randomStuff[i] = (SaltC[i] ^ DSaltC[i] ^ randomSalt[i]) & 0xff # XorSalts XorSalts = bytearray(16) for i in range(0, 16): XorSalts[i] = (SaltC[i] ^ DSaltC[i]) & 0xff message = self.DecryptedResponse.Message() message['response'] = response message['keys'] = bytes(randomStuff) message['hash'] = result message['xorSalts'] = bytes(XorSalts) message['hwid'] = self.srv_config['hwid'] # SaltS SaltS = self.getRandomSalt() moo = aes.AESModeOfOperation() moo.aes.v6 = True decry = moo.decrypt(SaltS, 16, moo.ModeOfOperation["CBC"], self.key, moo.aes.KeySize["SIZE_128"], SaltS) # DSaltS DSaltS = bytearray(decry) # HMacMsg HMacMsg = bytearray(16) for i in range(0, 16): HMacMsg[i] = (SaltS[i] ^ DSaltS[i]) & 0xff HMacMsg.extend(enco(str(message), 'latin-1')) # HMacKey requestTime = decrypted['request']['requestTime'] HMacKey = self.getMACKey(requestTime) HMac = hmac.new(HMacKey, bytes(HMacMsg), hashlib.sha256) digest = HMac.digest() responsedata = self.DecryptedResponse() responsedata['message'] = message responsedata['hmac'] = digest[16:] padded = aes.append_PKCS7_padding(enco(str(responsedata), 'latin-1')) mode, orig_len, crypted = moo.encrypt(padded, moo.ModeOfOperation["CBC"], self.key, moo.aes.KeySize["SIZE_128"], SaltS) return bytes(SaltS), bytes(bytearray(crypted))
def decryptRequest(self, request): encrypted = bytearray(enco(str(request['message']), 'latin-1')) iv = bytearray(enco(request['message']['salt'], 'latin-1')) moo = aes.AESModeOfOperation() moo.aes.v6 = self.v6 decrypted = moo.decrypt(encrypted, 256, moo.ModeOfOperation["CBC"], self.key, moo.aes.KeySize["SIZE_128"], iv) decrypted = aes.strip_PKCS7_padding(decrypted) decrypted = bytes(bytearray(decrypted)) return self.DecryptedRequest(decrypted)
def decryptResponse(self, response): paddingLength = self.getPadding(response['bodyLength1']) iv = bytearray(enco(response['salt'], 'latin-1')) encrypted = bytearray(enco(response['encrypted'][:-paddingLength], 'latin-1')) moo = aes.AESModeOfOperation() moo.aes.v6 = self.v6 decrypted = moo.decrypt(encrypted, 256, moo.ModeOfOperation["CBC"], self.key, moo.aes.KeySize["SIZE_128"], iv) decrypted = aes.strip_PKCS7_padding(decrypted) decrypted = bytes(bytearray(decrypted)) return self.DecryptedResponse(decrypted)
def readKmsResponseV4(data, request): response = kmsRequestV4.ResponseV4(data) hashed = kmsRequestV4(data, clt_config).generateHash( bytearray(enco(str(response['response']), 'latin-1'))) if deco(hashed, 'latin-1') == response['hash']: loggerclt.info("Response Hash has expected value !") return response
def generateResponse(self, request): responseData = pykms_Base.generateKmsResponseData( request['pduData'], self.srv_config) envelopeLength = len(responseData) response = MSRPCRespHeader() response['ver_major'] = request['ver_major'] response['ver_minor'] = request['ver_minor'] response['type'] = self.packetType['response'] response['flags'] = self.packetFlags['firstFrag'] | self.packetFlags[ 'lastFrag'] response['representation'] = request['representation'] response['call_id'] = request['call_id'] response['alloc_hint'] = envelopeLength response['ctx_id'] = request['ctx_id'] response['cancel_count'] = 0 response['pduData'] = responseData pretty_printer(num_text=17, where="srv") response = byterize(response) loggersrv.debug("RPC Message Response: \n%s\n" % justify(response.dump(print_to_stdout=False))) loggersrv.debug("RPC Message Response Bytes: \n%s\n" % justify( deco(binascii.b2a_hex(enco(str(response), 'latin-1')), 'utf-8'))) return response
def generateRequest(self, requestBase): esalt = self.getRandomSalt() moo = aes.AESModeOfOperation() moo.aes.v6 = self.v6 dsalt = moo.decrypt(esalt, 16, moo.ModeOfOperation["CBC"], self.key, moo.aes.KeySize["SIZE_128"], esalt) dsalt = bytearray(dsalt) decrypted = self.DecryptedRequest() decrypted['salt'] = bytes(dsalt) decrypted['request'] = requestBase padded = aes.append_PKCS7_padding(enco(str(decrypted), 'latin-1')) mode, orig_len, crypted = moo.encrypt(padded, moo.ModeOfOperation["CBC"], self.key, moo.aes.KeySize["SIZE_128"], esalt) message = self.RequestV5.Message(bytes(bytearray(crypted))) request = self.RequestV5() bodyLength = 2 + 2 + len(message) request['bodyLength1'] = bodyLength request['bodyLength2'] = bodyLength request['versionMinor'] = requestBase['versionMinor'] request['versionMajor'] = requestBase['versionMajor'] request['message'] = message pretty_printer(num_text = 10, where = "clt") request = byterize(request) loggersrv.info("Request V%d Data: \n%s\n" % (self.ver, justify(request.dump(print_to_stdout = False)))) loggersrv.info("Request V%d: \n%s\n" % (self.ver, justify(deco(binascii.b2a_hex(enco(str(request), 'latin-1')), 'utf-8')))) return request
def generateRequest(self, requestBase): thehash = self.generateHash(bytearray(enco(str(requestBase), 'latin-1'))) request = kmsRequestV4.RequestV4() bodyLength = len(requestBase) + len(thehash) request['bodyLength1'] = bodyLength request['bodyLength2'] = bodyLength request['request'] = requestBase request['hash'] = thehash request['padding'] = bytes(bytearray(self.getPadding(bodyLength))) ## Debug stuff. ShellMessage.Process(10).run() request = byterize(request) loggersrv.debug("Request V4 Data: \n%s\n" % justify(request.dump(print_to_stdout = False))) loggersrv.debug("Request V4: \n%s\n" % justify(deco(binascii.b2a_hex(enco(str(request), 'latin-1')), 'utf-8'))) return request
def handle(self): self.request.settimeout(srv_config['timeoutsndrcv']) while True: # self.request is the TCP socket connected to the client try: self.data = self.request.recv(1024) if self.data == '' or not self.data: pretty_printer( log_obj=loggersrv.warning, put_text="{reverse}{yellow}{bold}No data received.{end}" ) break except socket.error as e: pretty_printer( log_obj=loggersrv.error, put_text="{reverse}{red}{bold}While receiving: %s{end}" % str(e)) break packetType = MSRPCHeader(self.data)['type'] if packetType == rpcBase.packetType['bindReq']: loggersrv.info("RPC bind request received.") pretty_printer(num_text=[-2, 2], where="srv") handler = pykms_RpcBind.handler(self.data, srv_config) elif packetType == rpcBase.packetType['request']: loggersrv.info("Received activation request.") pretty_printer(num_text=[-2, 13], where="srv") handler = pykms_RpcRequest.handler(self.data, srv_config) else: pretty_printer( log_obj=loggersrv.error, put_text= "{reverse}{red}{bold}Invalid RPC request type %s.{end}" % packetType) break res = enco(str(handler.populate()), 'latin-1') if packetType == rpcBase.packetType['bindReq']: loggersrv.info("RPC bind acknowledged.") pretty_printer(num_text=[-3, 5, 6], where="srv") elif packetType == rpcBase.packetType['request']: loggersrv.info("Responded to activation request.") pretty_printer(num_text=[-3, 18, 19], where="srv") try: self.request.send(res) if packetType == rpcBase.packetType['request']: break except socket.error as e: pretty_printer( log_obj=loggersrv.error, put_text="{reverse}{red}{bold}While sending: %s{end}" % str(e)) break
def executeRequestLogic(self): requestData = self.RequestV4(self.data) response = self.serverLogic(requestData['request']) thehash = self.generateHash(bytearray(enco(str(response), 'latin-1'))) responseData = self.generateResponse(response, thehash) time.sleep(1) # request sent back too quick for Windows 2008 R2, slow it down. return responseData
def encryptResponse(self, request, decrypted, response): randomSalt = self.getRandomSalt() result = hashlib.sha256(randomSalt).digest() iv = bytearray(enco(request['message']['salt'], 'latin-1')) randomStuff = bytearray(16) for i in range(0,16): randomStuff[i] = (bytearray(enco(decrypted['salt'], 'latin-1'))[i] ^ iv[i] ^ randomSalt[i]) & 0xff responsedata = self.DecryptedResponse() responsedata['response'] = response responsedata['keys'] = bytes(randomStuff) responsedata['hash'] = result padded = aes.append_PKCS7_padding(enco(str(responsedata), 'latin-1')) moo = aes.AESModeOfOperation() moo.aes.v6 = self.v6 mode, orig_len, crypted = moo.encrypt(padded, moo.ModeOfOperation["CBC"], self.key, moo.aes.KeySize["SIZE_128"], iv) return bytes(iv), bytes(bytearray(crypted))
def generateRequest(self): firstCtxItem = CtxItem() firstCtxItem['ContextID'] = 0 firstCtxItem['TransItems'] = 1 firstCtxItem['Pad'] = 0 firstCtxItem['AbstractSyntaxUUID'] = uuid.UUID( '51c82175-844e-4750-b0d8-ec255555bc06').bytes_le firstCtxItem['AbstractSyntaxVer'] = 1 firstCtxItem['TransferSyntaxUUID'] = uuidNDR32.bytes_le firstCtxItem['TransferSyntaxVer'] = 2 secondCtxItem = CtxItem() secondCtxItem['ContextID'] = 1 secondCtxItem['TransItems'] = 1 secondCtxItem['Pad'] = 0 secondCtxItem['AbstractSyntaxUUID'] = uuid.UUID( '51c82175-844e-4750-b0d8-ec255555bc06').bytes_le secondCtxItem['AbstractSyntaxVer'] = 1 secondCtxItem['TransferSyntaxUUID'] = uuidTime.bytes_le secondCtxItem['TransferSyntaxVer'] = 1 bind = MSRPCBind() bind['max_tfrag'] = 5840 bind['max_rfrag'] = 5840 bind['assoc_group'] = 0 bind['ctx_num'] = 2 bind['ctx_items'] = str( bind.CtxItemArray(str(firstCtxItem) + str(secondCtxItem))) request = MSRPCHeader() request['ver_major'] = 5 request['ver_minor'] = 0 request['type'] = self.packetType['bindReq'] request['flags'] = self.packetFlags['firstFrag'] | self.packetFlags[ 'lastFrag'] | self.packetFlags['multiplex'] request['call_id'] = self.srv_config['call_id'] request['pduData'] = str(bind) ShellMessage.Process(0).run() bind = byterize(bind) request = byterize(request) loggersrv.debug( "RPC Bind Request: \n%s\n%s\n" % (justify(request.dump(print_to_stdout=False)), justify( MSRPCBind(request['pduData']).dump(print_to_stdout=False)))) loggersrv.debug("RPC Bind Request Bytes: \n%s\n" % justify( deco(binascii.b2a_hex(enco(str(request), 'latin-1')), 'utf-8'))) return request
def generateResponse(self, request): response = MSRPCBindAck() bind = MSRPCBind(request['pduData']) response['ver_major'] = request['ver_major'] response['ver_minor'] = request['ver_minor'] response['type'] = self.packetType['bindAck'] response['flags'] = self.packetFlags['firstFrag'] | self.packetFlags[ 'lastFrag'] | self.packetFlags['multiplex'] response['representation'] = request['representation'] response['frag_len'] = 36 + bind['ctx_num'] * 24 response['auth_len'] = request['auth_len'] response['call_id'] = request['call_id'] response['max_tfrag'] = bind['max_tfrag'] response['max_rfrag'] = bind['max_rfrag'] response['assoc_group'] = 0x1063bf3f port = str(self.srv_config['port']) response['SecondaryAddrLen'] = len(port) + 1 response['SecondaryAddr'] = port pad = (4 - ((response["SecondaryAddrLen"] + MSRPCBindAck._SIZE) % 4)) % 4 response['Pad'] = '\0' * pad response['ctx_num'] = bind['ctx_num'] preparedResponses = {} preparedResponses[uuidNDR32] = CtxItemResult(0, 0, uuidNDR32, 2) preparedResponses[uuidNDR64] = CtxItemResult(2, 2, uuidEmpty, 0) preparedResponses[uuidTime] = CtxItemResult(3, 3, uuidEmpty, 0) response['ctx_items'] = '' for i in range(0, bind['ctx_num']): ts_uuid = bind['ctx_items'][i].ts() resp = preparedResponses[ts_uuid] response['ctx_items'] += str(resp) ShellMessage.Process(4).run() response = byterize(response) loggersrv.debug("RPC Bind Response: \n%s\n" % justify(response.dump(print_to_stdout=False))) loggersrv.debug("RPC Bind Response Bytes: \n%s\n" % justify( deco(binascii.b2a_hex(enco(str(response), 'latin-1')), 'utf-8'))) return response
def generateRequest(self): request = MSRPCRequestHeader() request['ver_major'] = 5 request['ver_minor'] = 0 request['type'] = self.packetType['request'] request['flags'] = self.packetFlags['firstFrag'] | self.packetFlags[ 'lastFrag'] request['representation'] = 0x10 request['call_id'] = self.srv_config['call_id'] request['alloc_hint'] = len(self.data) request['pduData'] = str(self.data) pretty_printer(num_text=11, where="clt") request = byterize(request) loggersrv.debug("RPC Message Request: \n%s\n" % justify(request.dump(print_to_stdout=False))) loggersrv.debug("RPC Message Request Bytes: \n%s\n" % justify( deco(binascii.b2a_hex(enco(str(request), 'latin-1')), 'utf-8'))) return request
def handle(self): while True: # self.request is the TCP socket connected to the client try: self.data = self.request.recv(1024) except socket.error as e: if e.errno == errno.ECONNRESET: loggersrv.error("Connection reset by peer.") break else: raise if self.data == '' or not self.data: loggersrv.warning("No data received !") break packetType = MSRPCHeader(self.data)['type'] if packetType == rpcBase.packetType['bindReq']: loggersrv.info("RPC bind request received.") ShellMessage.Process([-2, 2]).run() handler = pykms_RpcBind.handler(self.data, srv_config) elif packetType == rpcBase.packetType['request']: loggersrv.info("Received activation request.") ShellMessage.Process([-2, 13]).run() handler = pykms_RpcRequest.handler(self.data, srv_config) else: loggersrv.error("Invalid RPC request type ", packetType) break res = enco(str(handler.populate()), 'latin-1') self.request.send(res) if packetType == rpcBase.packetType['bindReq']: loggersrv.info("RPC bind acknowledged.") ShellMessage.Process([-3, 5, 6]).run() elif packetType == rpcBase.packetType['request']: loggersrv.info("Responded to activation request.") ShellMessage.Process([-3, 18, 19]).run() break
def generateResponse(self, iv, encryptedResponse, requestData): response = self.ResponseV5() bodyLength = 2 + 2 + len(iv) + len(encryptedResponse) response['bodyLength1'] = bodyLength response['bodyLength2'] = bodyLength response['versionMinor'] = requestData['versionMinor'] response['versionMajor'] = requestData['versionMajor'] response['salt'] = iv response['encrypted'] = bytes(bytearray(encryptedResponse)) response['padding'] = bytes(bytearray(self.getPadding(bodyLength))) ShellMessage.Process(16).run() response = byterize(response) loggersrv.info( "KMS V%d Response: \n%s\n" % (self.ver, justify(response.dump(print_to_stdout=False)))) loggersrv.info( "KMS V%d Structure Bytes: \n%s\n" % (self.ver, justify( deco(binascii.b2a_hex(enco(str(response), 'latin-1')), 'utf-8')))) return str(response)
def client_create(): loggerclt.info("Connecting to %s on port %d..." % (clt_config['ip'], clt_config['port'])) s = socket.create_connection((clt_config['ip'], clt_config['port'])) loggerclt.info("Connection successful !") binder = pykms_RpcBind.handler(None, clt_config) RPC_Bind = enco(str(binder.generateRequest()), 'latin-1') loggerclt.info("Sending RPC bind request...") ShellMessage.Process([-1, 1]).run() s.send(RPC_Bind) try: ShellMessage.Process([-4, 7]).run() bindResponse = s.recv(1024) except socket.error as e: if e.errno == errno.ECONNRESET: loggerclt.error("Connection reset by peer. Exiting...") sys.exit() else: raise if bindResponse == '' or not bindResponse: loggerclt.error("No data received ! Exiting...") sys.exit() packetType = MSRPCHeader(bindResponse)['type'] if packetType == rpcBase.packetType['bindAck']: loggerclt.info("RPC bind acknowledged.") ShellMessage.Process(8).run() kmsRequest = createKmsRequest() requester = pykms_RpcRequest.handler(kmsRequest, clt_config) s.send(enco(str(requester.generateRequest()), 'latin-1')) ShellMessage.Process([-1, 12]).run() response = s.recv(1024) loggerclt.debug("Response: \n%s\n" % justify(deco(binascii.b2a_hex(response), 'latin-1'))) ShellMessage.Process([-4, 20]).run() parsed = MSRPCRespHeader(response) kmsData = readKmsResponse(parsed['pduData'], kmsRequest, clt_config) kmsResp = kmsData['response'] try: hwid = kmsData['hwid'] loggerclt.info( "KMS Host HWID: %s" % deco(binascii.b2a_hex(enco(hwid, 'latin-1')).upper(), 'utf-8')) except KeyError: pass loggerclt.info("KMS Host ePID: %s" % kmsResp['kmsEpid'].encode('utf-8').decode('utf-16le')) loggerclt.info("KMS Host Current Client Count: %s" % kmsResp['currentClientCount']) loggerclt.info("KMS VL Activation Interval: %s" % kmsResp['vLActivationInterval']) loggerclt.info("KMS VL Renewal Interval: %s" % kmsResp['vLRenewalInterval']) if clt_config['loglevel'] == 'MINI': loggerclt.mini("", extra={ 'host': socket.gethostname() + " [" + clt_config["ip"] + "]", 'status': "Activated", 'product': clt_config["mode"] }) ShellMessage.Process(21).run() elif packetType == rpcBase.packetType['bindNak']: loggerclt.info( justify(MSRPCBindNak(bindResponse).dump(print_to_stdout=False))) sys.exit() else: loggerclt.critical("Something went wrong.") sys.exit()
def client_create(clt_sock): binder = pykms_RpcBind.handler(None, clt_config) RPC_Bind = enco(str(binder.generateRequest()), 'latin-1') try: loggerclt.info("Sending RPC bind request...") pretty_printer(num_text = [-1, 1], where = "clt") clt_sock.send(RPC_Bind) except socket.error as e: pretty_printer(log_obj = loggerclt.error, to_exit = True, where = "clt", put_text = "{reverse}{red}{bold}While sending: %s. Exiting...{end}" %str(e)) try: bindResponse = clt_sock.recv(1024) if bindResponse == '' or not bindResponse: pretty_printer(log_obj = loggerclt.warning, to_exit = True, where = "clt", put_text = "{reverse}{yellow}{bold}No data received. Exiting...{end}") pretty_printer(num_text = [-4, 7], where = "clt") except socket.error as e: pretty_printer(log_obj = loggerclt.error, to_exit = True, where = "clt", put_text = "{reverse}{red}{bold}While receiving: %s. Exiting...{end}" %str(e)) packetType = MSRPCHeader(bindResponse)['type'] if packetType == rpcBase.packetType['bindAck']: loggerclt.info("RPC bind acknowledged.") pretty_printer(num_text = 8, where = "clt") kmsRequest = createKmsRequest() requester = pykms_RpcRequest.handler(kmsRequest, clt_config) try: loggerclt.info("Sending RPC activation request...") RPC_Actv = enco(str(requester.generateRequest()), 'latin-1') pretty_printer(num_text = [-1, 12], where = "clt") clt_sock.send(RPC_Actv) except socket.error as e: pretty_printer(log_obj = loggerclt.error, to_exit = True, where = "clt", put_text = "{reverse}{red}{bold}While sending: %s. Exiting...{end}" %str(e)) try: response = clt_sock.recv(1024) pretty_printer(num_text = [-4, 20], where = "clt") except socket.error as e: pretty_printer(log_obj = loggerclt.error, to_exit = True, where = "clt", put_text = "{reverse}{red}{bold}While receiving: %s. Exiting...{end}" %str(e)) loggerclt.debug("Response: \n%s\n" % justify(deco(binascii.b2a_hex(response), 'latin-1'))) parsed = MSRPCRespHeader(response) kmsData = readKmsResponse(parsed['pduData'], kmsRequest, clt_config) kmsResp = kmsData['response'] try: hwid = kmsData['hwid'] loggerclt.info("KMS Host HWID: %s" % deco(binascii.b2a_hex(enco(hwid, 'latin-1')).upper(), 'utf-8')) except KeyError: pass loggerclt.info("KMS Host ePID: %s" % kmsResp['kmsEpid'].encode('utf-8').decode('utf-16le')) loggerclt.info("KMS Host Current Client Count: %s" % kmsResp['currentClientCount']) loggerclt.info("KMS VL Activation Interval: %s" % kmsResp['vLActivationInterval']) loggerclt.info("KMS VL Renewal Interval: %s" % kmsResp['vLRenewalInterval']) if clt_config['loglevel'] == 'MININFO': loggerclt.mininfo("", extra = {'host': str(clt_sock.getpeername()), 'status' : kmsBase.licenseStates[requester.srv_config['KMSClientLicenseStatus']], 'product' : clt_config["mode"]}) pretty_printer(num_text = 21, where = "clt") elif packetType == rpcBase.packetType['bindNak']: loggerclt.info(justify(MSRPCBindNak(bindResponse).dump(print_to_stdout = False))) sys.exit(0) else: pretty_printer(log_obj = loggerclt.warning, to_exit = True, where = "clt", put_text = "{reverse}{magenta}{bold}Something went wrong. Exiting...{end}")
def generateResponse(self, responseBuffer, thehash): response = self.ResponseV4() bodyLength = len(responseBuffer) + len(thehash) response['bodyLength1'] = bodyLength response['bodyLength2'] = bodyLength response['response'] = responseBuffer response['hash'] = thehash response['padding'] = bytes(bytearray(self.getPadding(bodyLength))) ## Debug stuff. ShellMessage.Process(16).run() response = byterize(response) loggersrv.debug("KMS V4 Response: \n%s\n" % justify(response.dump(print_to_stdout = False))) loggersrv.debug("KMS V4 Response Bytes: \n%s\n" % justify(deco(binascii.b2a_hex(enco(str(response), 'latin-1')), 'utf-8'))) return str(response)
def ts(self): return uuid.UUID(bytes_le=enco(self['TransferSyntaxUUID'], 'latin-1'))
def serverLogic(self, kmsRequest): if self.srv_config['sqlite']: sql_initialize(self.srv_config['sqlite']) pretty_printer(num_text=15, where="srv") kmsRequest = byterize(kmsRequest) loggersrv.debug("KMS Request Bytes: \n%s\n" % justify( deco(binascii.b2a_hex(enco(str(kmsRequest), 'latin-1')), 'latin-1'))) loggersrv.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 = 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: pretty_printer( log_obj=loggersrv.warning, put_text= "{reverse}{yellow}{bold}Unknown time zone ! Request time not localized.{end}" ) local_dt = requestDatetime except ImportError: pretty_printer( log_obj=loggersrv.warning, put_text= "{reverse}{yellow}{bold}Module 'tzlocal' not available ! Request time not localized.{end}" ) local_dt = requestDatetime # Activation threshold. # https://docs.microsoft.com/en-us/windows/deployment/volume-activation/activate-windows-10-clients-vamt MinClients = kmsRequest['requiredClientCount'] RequiredClients = MinClients * 2 if self.srv_config["clientcount"] != None: if 0 < self.srv_config["clientcount"] < MinClients: # fixed to 6 (product server) or 26 (product desktop) currentClientCount = MinClients + 1 pretty_printer( log_obj=loggersrv.warning, put_text= "{reverse}{yellow}{bold}Not enough clients ! Fixed with %s, but activated client \ could be detected as not genuine !{end}" % currentClientCount) elif MinClients <= self.srv_config["clientcount"] < RequiredClients: currentClientCount = self.srv_config["clientcount"] pretty_printer( log_obj=loggersrv.warning, put_text= "{reverse}{yellow}{bold}With count = %s, activated client could be detected as not genuine !{end}" % currentClientCount) elif self.srv_config["clientcount"] >= RequiredClients: # fixed to 10 (product server) or 50 (product desktop) currentClientCount = RequiredClients if self.srv_config["clientcount"] > RequiredClients: pretty_printer( log_obj=loggersrv.warning, put_text= "{reverse}{yellow}{bold}Too many clients ! Fixed with %s{end}" % currentClientCount) else: # fixed to 10 (product server) or 50 (product desktop) currentClientCount = RequiredClients # Get a name for SkuId, AppId. kmsdb = kmsDB2Dict() appitems = kmsdb[2] for appitem in appitems: kmsitems = appitem['KmsItems'] for kmsitem in kmsitems: skuitems = kmsitem['SkuItems'] for skuitem in skuitems: try: if uuid.UUID(skuitem['Id']) == skuId: skuName = skuitem['DisplayName'] break except: skuName = skuId pretty_printer( log_obj=loggersrv.warning, put_text= "{reverse}{yellow}{bold}Can't find a name for this product !{end}" ) try: if uuid.UUID(appitem['Id']) == applicationId: appName = appitem['DisplayName'] except: appName = applicationId pretty_printer( log_obj=loggersrv.warning, put_text= "{reverse}{yellow}{bold}Can't find a name for this application group !{end}" ) infoDict = { "machineName": kmsRequest.getMachineName(), "clientMachineId": str(clientMachineId), "appId": appName, "skuId": skuName, "licenseStatus": kmsRequest.getLicenseStatus(), "requestTime": int(time.time()), "kmsEpid": None } loggersrv.info("Machine Name: %s" % infoDict["machineName"]) loggersrv.info("Client Machine ID: %s" % infoDict["clientMachineId"]) loggersrv.info("Application ID: %s" % infoDict["appId"]) loggersrv.info("SKU ID: %s" % infoDict["skuId"]) loggersrv.info("License Status: %s" % infoDict["licenseStatus"]) loggersrv.info("Request Time: %s" % local_dt.strftime('%Y-%m-%d %H:%M:%S %Z (UTC%z)')) if self.srv_config['loglevel'] == 'MINI': loggersrv.mini("", extra={ 'host': socket.gethostname() + " [" + self.srv_config["ip"] + "]", 'status': infoDict["licenseStatus"], 'product': infoDict["skuId"] }) if self.srv_config['sqlite']: sql_update(self.srv_config['sqlite'], infoDict) return self.createKmsResponse(kmsRequest, currentClientCount)
def get(self): return uuid.UUID(bytes_le=enco(str(self), 'latin-1'))