Beispiel #1
0
    def serialize(self):
        can = 'CAN'  # XmppSocketV2.java line 180,

        device = self.device_id_override if self.device_id_override else device_id
        timestamp = str(CryptographicUtils.make_kik_timestamp())
        sid = CryptographicUtils.make_kik_uuid()

        signature = rsa.sign(
            "{}:{}:{}:{}".format(can + device, kik_version, timestamp,
                                 sid).encode(), private_key, 'SHA-256')
        signature = base64.b64encode(signature,
                                     '-_'.encode()).decode().rstrip('=')

        hmac_data = timestamp + ":" + can + device
        hmac_secret_key = CryptographicUtils.build_hmac_key()
        cv = binascii.hexlify(
            hmac.new(hmac_secret_key, hmac_data.encode(),
                     hashlib.sha1).digest()).decode()

        the_map = {
            'signed': signature,
            'lang': 'en_US',
            'sid': sid,
            'anon': '1',
            'ts': timestamp,
            'v': kik_version,
            'cv': cv,
            'conn': 'WIFI',
            'dev': can + device,
        }

        # Test data to confirm the sort_kik_map function returns the correct result.
        # the_map = {
        #     'signed': 'signature',
        #     'lang': 'en_US',
        #     'sid': 'sid',
        #     'anon': '1',
        #     'ts': 'timestamp',
        #     'v': 'kik_version',
        #     'cv': 'cv',
        #     'conn': 'WIFI',
        #     'dev': 'can+device',
        # }

        if self.n > 0:
            the_map['n'] = self.n

        packet = CryptographicUtils.make_connection_payload(
            *CryptographicUtils.sort_kik_map(the_map))
        return packet.encode()
    def establish_session(self, username, node, password):
        self._log("[+] Establishing session...")
        # reset the socket
        self.wrappedSocket.send_chat_message("</k>".encode('UTF-8'))
        self.wrappedSocket.close()
        self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.sock.settimeout(10)
        self.wrappedSocket = ssl.wrap_socket(self.sock)
        self.wrappedSocket.connect((HOST, PORT))

        jid = node + "@talk.kik.com"
        jid_with_resource = jid + "/CAN" + self.device_id
        timestamp = "1496333389122"
        sid = CryptographicUtils.make_kik_uuid()
        version = "11.1.1.12218"

        # some super secret cryptographic stuff
        private_key_pem = "-----BEGIN RSA PRIVATE KEY-----\nMIIBPAIBAAJBANEWUEINqV1KNG7Yie9GSM8t75ZvdTeqT7kOF40kvDHIp" \
                          "/C3tX2bcNgLTnGFs8yA2m2p7hKoFLoxh64vZx5fZykCAwEAAQJAT" \
                          "/hC1iC3iHDbQRIdH6E4M9WT72vN326Kc3MKWveT603sUAWFlaEa5T80GBiP/qXt9PaDoJWcdKHr7RqDq" \
                          "+8noQIhAPh5haTSGu0MFs0YiLRLqirJWXa4QPm4W5nz5VGKXaKtAiEA12tpUlkyxJBuuKCykIQbiUXHEwzFYbMHK5E" \
                          "/uGkFoe0CIQC6uYgHPqVhcm5IHqHM6/erQ7jpkLmzcCnWXgT87ABF2QIhAIzrfyKXp1ZfBY9R0H4pbboHI4uatySKc" \
                          "Q5XHlAMo9qhAiEA43zuIMknJSGwa2zLt/3FmVnuCInD6Oun5dbcYnqraJo=\n-----END RSA PRIVATE KEY----- "
        private_key = rsa.PrivateKey.load_pkcs1(private_key_pem, format='PEM')
        signature = rsa.sign("{}:{}:{}:{}".format(jid, version, timestamp, sid).encode('UTF-8'), private_key, 'SHA-256')
        signature = base64.b64encode(signature, '-_'.encode('UTF-8')).decode('UTF-8')[:-2]
        hmac_data = timestamp + ":" + jid
        hmac_secret_key = CryptographicUtils.build_hmac_key()
        cv = binascii.hexlify(hmac.new(hmac_secret_key, hmac_data.encode('UTF-8'), hashlib.sha1).digest()).decode(
            'UTF-8')

        password_key = CryptographicUtils.key_from_password(username, password)

        the_map = {'from': jid_with_resource, 'to': 'talk.kik.com', 'p': password_key, 'cv': cv, 'v': version,
                   'sid': sid, 'n': '1', 'conn': 'WIFI', 'ts': timestamp, 'lang': 'en_US', 'signed': signature}
        packet = CryptographicUtils.make_connection_payload(CryptographicUtils.sort_kik_map(the_map)).encode(
            'UTF-8')

        # send session request
        self.wrappedSocket.send_chat_message(packet)
        response = self.wrappedSocket.recv(16384).decode('UTF-8')
        if "ok" not in response:
            raise KikErrorException(response, "Could not init session: " + response)
        self._log("[+] Session established.")
Beispiel #3
0
    def serialize(self):
        jid = self.node + "@talk.kik.com"
        jid_with_resource = jid + "/CAN" + (
            self.device_id_override if self.device_id_override else device_id)
        timestamp = str(CryptographicUtils.make_kik_timestamp())
        sid = CryptographicUtils.make_kik_uuid()

        # some super secret cryptographic stuff

        signature = rsa.sign(
            "{}:{}:{}:{}".format(jid, kik_version, timestamp, sid).encode(),
            private_key, 'SHA-256')
        signature = base64.b64encode(signature,
                                     '-_'.encode()).decode().rstrip('=')
        hmac_data = timestamp + ":" + jid
        hmac_secret_key = CryptographicUtils.build_hmac_key()
        cv = binascii.hexlify(
            hmac.new(hmac_secret_key, hmac_data.encode(),
                     hashlib.sha1).digest()).decode()

        password_key = CryptographicUtils.key_from_password(
            self.username, self.password)

        the_map = {
            'from': jid_with_resource,
            'to': 'talk.kik.com',
            'p': password_key,
            'cv': cv,
            'v': kik_version,
            'sid': sid,
            'n': '1',
            'conn': 'WIFI',
            'ts': timestamp,
            'lang': 'en_US',
            'signed': signature
        }
        packet = CryptographicUtils.make_connection_payload(
            *CryptographicUtils.sort_kik_map(the_map))
        return packet.encode()