Beispiel #1
0
        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
Beispiel #2
0
    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))
Beispiel #3
0
        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))