Example #1
0
    def toTGS(self):
        tgs_rep = TGS_REP()
        tgs_rep['pvno'] = 5
        tgs_rep['msg-type'] = int(
            constants.ApplicationTagNumbers.TGS_REP.value)
        tgs_rep['crealm'] = self['server'].realm['data']

        # Fake EncryptedData
        tgs_rep['enc-part'] = None
        tgs_rep['enc-part']['etype'] = 1
        tgs_rep['enc-part']['cipher'] = ''
        seq_set(tgs_rep, 'cname',
                self['client'].toPrincipal().components_to_asn1)
        ticket = types.Ticket()
        ticket.from_asn1(self.ticket['data'])
        seq_set(tgs_rep, 'ticket', ticket.to_asn1)

        cipher = crypto._enctype_table[self['key']['keytype']]()

        tgs = dict()
        tgs['KDC_REP'] = encoder.encode(tgs_rep)
        tgs['cipher'] = cipher
        tgs['sessionKey'] = crypto.Key(cipher.enctype,
                                       str(self['key']['keyvalue']))
        return tgs
Example #2
0
    def toTGS(self, newSPN=None):
        tgs_rep = TGS_REP()
        tgs_rep['pvno'] = 5
        tgs_rep['msg-type'] = int(
            constants.ApplicationTagNumbers.TGS_REP.value)
        tgs_rep['crealm'] = self['server'].realm['data']

        # Fake EncryptedData
        tgs_rep['enc-part'] = None
        tgs_rep['enc-part']['etype'] = 1
        tgs_rep['enc-part']['cipher'] = ''
        seq_set(tgs_rep, 'cname',
                self['client'].toPrincipal().components_to_asn1)
        ticket = types.Ticket()
        ticket.from_asn1(self.ticket['data'])
        if newSPN is not None:
            if newSPN.upper() != str(ticket.service_principal).upper():
                LOG.debug(
                    'Changing sname from %s to %s and hoping for the best' %
                    (ticket.service_principal, newSPN))
                ticket.service_principal = types.Principal(
                    newSPN, type=int(ticket.service_principal.type))
        seq_set(tgs_rep, 'ticket', ticket.to_asn1)

        cipher = crypto._enctype_table[self['key']['keytype']]()

        tgs = dict()
        tgs['KDC_REP'] = encoder.encode(tgs_rep)
        tgs['cipher'] = cipher
        tgs['sessionKey'] = crypto.Key(cipher.enctype,
                                       str(self['key']['keyvalue']))
        return tgs
Example #3
0
    def __detect_by_cksum(cls, packet):
        """
        Function which detects Silver Ticket attack execution by wrong privsvr (KRBTGT) checksum.
        We find which algorithm was used and verifying the privsvr signature.
        That is the same idea as using PAC validation, which most of servers don't do.
        We are raising exception if the attack was detected or if a packet wasn't decrypted.
        :param packet: Packet to check in if Silver Ticket attack was executed.
        :return:
        """

        # Get the packet id.
        packet_id = int(get_dict_key_value(packet, FRAME_NUM_KEY_NAME))
        # Get the AP-REQ part of the packet for faster checks in the future.
        apReqDict = get_dict_key_value(packet, cls.identify_keyword)
        try:
            # Getting the PAC checksums
            server_cksum = hex_to_str(
                get_dict_key_value(
                    apReqDict, SERVER_CKSUM_TREE_KEY_NAME)[CKSUM_SIG_KEY_NAME])
            privsvr_chksum = hex_to_str(
                get_dict_key_value(
                    apReqDict, KRBTGT_CKSUM_TREE_KEY_NAME)[CKSUM_SIG_KEY_NAME])
            cksum_type_number = get_dict_key_value(
                apReqDict, KRBTGT_CKSUM_TREE_KEY_NAME)[CKSUM_TYPE_KEY_NAME]

        # The encrypted part wasn't decrypted because the right key is missing.
        except KeyNotFoundError:
            raise SilverTicketSkipped()

        # Get the checksum algorithm.
        cksum_algo = crypto._get_checksum_profile(int(cksum_type_number))
        # Get the KRBTGT key of the the specific algorithm.
        KRBTGT_key = hex_to_str(cls.KRBTGT_keys_dict[cksum_algo])
        # -138 == HMAC doesnt have key algorithm.
        if (not hasattr(cksum_algo, ENC_ATTR)) and (crypto._HMACMD5
                                                    == cksum_algo):
            # We are adding key algorithm attribute.
            cksum_algo.enc = crypto._RC4
        # Create a key from the Krbtgt key type and string.
        KRBTGT_key = crypto.Key(cksum_algo.enc.enctype, KRBTGT_key)

        # Validating if the signature is valid, if not an attack was executed.
        try:
            # Verifying the packet checksum with the real KRBTGT key.
            # If the verify failed , exception will be raised.
            cksum_algo.verify(KRBTGT_key, KERB_NON_KERB_CKSUM_SALT,
                              server_cksum, privsvr_chksum)

        # Wrong signature found
        except crypto.InvalidChecksum as expt:
            if expt.message in BAD_CHKSUM_EXCEPTION:
                # The signature is wrong, Silver Ticket attack execution was detected!.
                raise SilverTicketDetected()

            # Unknown exception
            raise expt