示例#1
0
 def get_key_phrase(self) -> bytes:
     """
     Calculates salted username passkey
     """
     username = self.client.username
     password = self.client.password
     return CryptographicUtils.key_from_password(username,
                                                 password).encode()
示例#2
0
 def serialize(self):
     passkey_e = CryptographicUtils.key_from_password(self.old_email, self.password)
     data = ('<iq type="set" id="{}">'
             '<query xmlns="kik:iq:user-profile">'
             '<email>{}</email>'
             '<passkey-e>{}</passkey-e>'
             '</query>'
             '</iq>').format(self.message_id, self.new_email, passkey_e)
     return data.encode()
示例#3
0
    def serialize(self):
        passkey_e = CryptographicUtils.key_from_password(
            self.email, self.password)
        passkey_u = CryptographicUtils.key_from_password(
            self.username, self.password)
        captcha = captcha_element.format(
            self.captcha_result) if self.captcha_result else ''
        data = ('<iq type="set" id="{}">'
                '<query xmlns="jabber:iq:register">'
                '<email>{}</email>'
                '<passkey-e>{}</passkey-e>'
                '<passkey-u>{}</passkey-u>'
                '<device-id>{}</device-id>'
                '<username>{}</username>'
                '<first>{}</first>'
                '<last>{}</last>'
                '<birthday>{}</birthday>'
                '{}'
                '<version>{}</version>'
                '<device-type>android</device-type>'
                '<model>Nexus 7</model>'
                '<android-sdk>25</android-sdk>'
                '<registrations-since-install>1</registrations-since-install>'
                '<install-date>unknown</install-date>'
                '<logins-since-install>0</logins-since-install>'
                '<prefix>CAN</prefix>'
                '<lang>en_US</lang>'
                '<brand>google</brand>'
                '<android-id>{}</android-id>'
                '</query>'
                '</iq>').format(
                    self.message_id, self.email, passkey_e, passkey_u,
                    self.device_id_override
                    if self.device_id_override else device_id, self.username,
                    self.first_name, self.last_name, self.birthday, captcha,
                    kik_version_info["kik_version"], self.android_id_override
                    if self.android_id_override else android_id)

        return data.encode()
示例#4
0
def send(url, filename, jid, username, password):
    password_key = CryptographicUtils.key_from_password(username, password)
    if not os.path.isfile(filename):
        raise KikApiException("File doesn't exist")
    headers = {
        'x-kik-jid':
        jid,
        'x-kik-password':
        password_key,
        'User-Agent':
        f'Kik/{kik_version_info["kik_version"]} (Android 7.1.2) Dalvik/2.1.0 (Linux; U; Android 7.1.2; Nexus 7 Build/NJH47F)',
    }
    Thread(target=picture_upload_thread,
           args=(url, filename, headers),
           name='KikProfilepics').start()
示例#5
0
    def serialize(self) -> bytes:
        password_key = CryptographicUtils.key_from_password(
            self.username, self.password)
        captcha = captcha_element.format(
            self.captcha_result) if self.captcha_result else ''
        if '@' in self.username:
            tag = ('<email>{}</email>' '<passkey-e>{}</passkey-e>')
        else:
            tag = ('<username>{}</username>' '<passkey-u>{}</passkey-u>')

        data = (
            '<iq type="set" id="{}">'
            '<query xmlns="jabber:iq:register">'
            '{}'
            '<device-id>{}</device-id>'
            '<install-referrer>utm_source=google-play&amp;utm_medium=organic</install-referrer>'
            '<operator>{}</operator>'
            '<install-date>{}</install-date>'
            '<device-type>android</device-type>'
            '<brand>{}</brand>'
            '<logins-since-install>{}</logins-since-install>'
            '<version>{}</version>'
            '<lang>en_US</lang>'
            '<android-sdk>{}</android-sdk>'
            '<registrations-since-install>{}</registrations-since-install>'
            '<prefix>CAN</prefix>'
            '<android-id>{}</android-id>'
            '<model>{}</model>'
            '{}'
            '</query>'
            '</iq>').format(
                self.message_id, tag.format(self.username, password_key),
                self.device_id_override
                if self.device_id_override else device_id,
                self.operator_override if self.operator_override else operator,
                self.install_date_override
                if self.install_date_override else install_date,
                self.brand_override if self.brand_override else brand,
                self.logins_since_install_override if
                self.logins_since_install_override else logins_since_install,
                kik_version, self.android_sdk_override
                if self.android_sdk_override else android_sdk,
                self.registrations_since_install_override
                if self.registrations_since_install_override else
                registrations_since_install, self.android_id_override
                if self.android_id_override else android_id,
                self.model_override if self.model_override else model, captcha)
        return data.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.")
示例#7
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()
    def login(self, username, password, establish_session_on_success=True):
        self._log("[+] Logging in (username: "******", password: "******")...")

        device_id = self.device_id
        password_key = CryptographicUtils.key_from_password(username, password)
        data = ('<iq type="set" id="{}">'
                '<query xmlns="jabber:iq:register">'
                '<username>{}</username>'
                '<passkey-u>{}</passkey-u>'
                '<device-id>{}</device-id>'
                '<install-referrer>utm_source=google-play&amp;utm_medium=organic</install-referrer>'
                '<operator>310260</operator>'
                '<install-date>1494078709023</install-date>'
                '<device-type>android</device-type>'
                '<brand>generic</brand>'
                '<logins-since-install>1</logins-since-install>'
                '<version>{}</version>'
                '<lang>en_US</lang>'
                '<android-sdk>19</android-sdk>'
                '<registrations-since-install>0</registrations-since-install>'
                '<prefix>CAN</prefix>'
                '<android-id>c10d47ba7ee17193</android-id>'
                '<model>Samsung Galaxy S5 - 4.4.4 - API 19 - 1080x1920</model>'
                '</query>'
                '</iq>').format(CryptographicUtils.make_kik_uuid(), username, password_key, device_id,
                                self.kik_version)
        self._make_request(data)
        response = self._get_response()

        if response.error:
            if response.find('password-mismatch'):
                self._log("[-] Password mismatch, can't login", DebugLevel.ERROR)
                raise KikLoginException(response.error, "Password mismatch")
            elif response.error.find('not-registered'):
                self._log("[-] User not registered, can't login", DebugLevel.ERROR)
                raise KikLoginException(response.error, "Not registered")
            else:
                captcha = response.find('captcha-url')
                if captcha:
                    self._log("[-} Encountered a captcha. URL: " + captcha.string, DebugLevel.ERROR)
                    raise KikCaptchaException(response.error, "Captcha when trying to log in! URL: " + captcha.string,
                                              captcha.string)
                else:
                    self._log("[-] Kik error code: {}".format(response.error['code']), DebugLevel.ERROR)
                    self._log(response.error.prettify(), DebugLevel.ERROR)
                    raise KikLoginException(response.error, "Kik error code: {}".format(response.error['code']))

        if response.find("kik:error"):
            captcha = response.find('captcha-type')
            if captcha:
                self._log("[-} Encountered a captcha. URL: " + captcha.string, DebugLevel.ERROR)
                raise KikLoginException(response, "Captcha! URL:" + captcha.string)

        user_info = dict()
        user_info["node"] = response.find('node').text
        user_info["username"] = response.find('username').text
        user_info["email"] = response.find('email').text
        user_info["first"] = response.find('first').text
        user_info["last"] = response.find('last').text
        pubkey = response.find('record', {'pk': 'messaging_pub_key'})
        if pubkey:
            user_info["public_key"] = pubkey.text
            user_info["private_key"] = response.find('record', {'pk': 'enc_messaging_priv_key'}).text
            if response.find('record', {'pk': 'chat_list_bins'}):
                user_info["chat_list"] = self._parse_chat_list_bin(
                    Utilities.decode_base64(response.find('record', {'pk': 'chat_list_bins'}).text.encode('UTF-8')))

        self._log("[+] Logged in.")
        if self.debug_level == DebugLevel.VERBOSE:
            Utilities.print_dictionary(user_info)

        self.user_info = user_info
        if establish_session_on_success:
            self.establish_session(self.user_info["username"], self.user_info["node"], password)

        return self.user_info