コード例 #1
0
    def from_url(url_str):
        res = KerberosClientURL()
        url = urlparse(url_str)

        res.dc_ip = url.hostname
        schemes = url.scheme.upper().split('+')
        if schemes[0] not in ['KERBEROS', 'KERBEROS-TCP, KERBEROS-UDP']:
            raise Exception('Unknown protocol! %s' % schemes[0])

        if schemes[0].endswith('UDP') is True:
            res.protocol = KerberosSocketType.UDP

        try:
            res.secret_type = KerberosSecretType(schemes[1])
        except:
            raise Exception('Unknown secret type! %s' % schemes[0])

        if url.username is not None:
            if url.username.find('\\') != -1:
                res.domain, res.username = url.username.split('\\')
            else:
                raise Exception('Domain missing from username!')
        else:
            raise Exception('Missing username!')

        res.secret = url.password
        if url.port is not None:
            res.port = int(url.port)

        query = parse_qs(url.query)
        proxy_present = False
        for k in query:
            if k.startswith('proxy') is True:
                proxy_present = True

            if k in kerberosclienturl_param2var:
                data = query[k][0]
                for c in kerberosclienturl_param2var[k][1]:
                    data = c(data)

                    setattr(res, kerberosclienturl_param2var[k][0], data)

        if proxy_present is True:
            cu = SocksClientURL.from_params(url_str)
            cu.endpoint_ip = res.dc_ip
            cu.endpoint_port = res.port

            res.proxy = KerberosProxy(cu.get_target(), cu.get_creds())

        if res.username is None:
            raise Exception('Missing username!')
        if res.secret is None:
            raise Exception('Missing secret/password!')
        if res.secret_type is None:
            raise Exception('Missing secret_type!')
        if res.dc_ip is None:
            raise Exception('Missing target hostname!')

        return res
コード例 #2
0
ファイル: multiplexor.py プロジェクト: zhuby1973/msldap
	async def connect(self, is_kerberos = False):
		"""
		
		"""		
		#hiding the import, so you'll only need to install multiplexor only when actually using it
		from multiplexor.operator import MultiplexorOperator
		
		con_str = self.target.proxy.target.get_server_url()
		#creating operator and connecting to multiplexor server
		self.operator = MultiplexorOperator(con_str, logging_sink = logger)
		await self.operator.connect()
		#creating socks5 proxy
		server_info = await self.operator.start_socks5(self.target.proxy.target.agent_id)
		await self.operator.terminate()
		#print(server_info)
		if is_kerberos is False:
			
			#copying the original target, then feeding it to socks5proxy object. it will hold the actual socks5 proxy server address we created before
			tp = MSLDAPProxy()
			tp.target = SocksTarget()
			tp.target.version = SocksServerVersion.SOCKS5
			tp.target.server_ip = server_info['listen_ip']
			tp.target.server_port = server_info['listen_port']
			tp.target.is_bind = False
			tp.target.proto = SocksProtocol.TCP
			tp.target.timeout = self.target.timeout
			tp.target.buffer_size = 4096
			
			tp.target.endpoint_ip = self.target.host
			tp.target.endpoint_port = self.target.port
			tp.target.endpoint_timeout = None # TODO: maybe implement endpoint timeout in the msldap target?
			tp.type = MSLDAPProxyType.SOCKS5

			newtarget = copy.deepcopy(self.target)
			newtarget.proxy = tp

			

			return SocksProxyConnection(target = newtarget)
		
		else:
			kt = copy.deepcopy(self.target)
			kt.proxy = KerberosProxy()
			kt.proxy.target = SocksTarget()
			kt.proxy.target.version = SocksServerVersion.SOCKS5
			kt.proxy.target.server_ip = server_info['listen_ip']
			kt.proxy.target.server_port = server_info['listen_port']
			kt.proxy.target.is_bind = False
			kt.proxy.target.proto = SocksProtocol.TCP
			kt.proxy.target.timeout = 10
			kt.proxy.target.buffer_size = 4096
			
			kt.proxy.target.endpoint_ip = self.target.ip
			kt.proxy.target.endpoint_port = self.target.port
			#kt.proxy.creds = copy.deepcopy(self.target.proxy.auth)
			
			return kt
コード例 #3
0
ファイル: authbuilder.py プロジェクト: zhuby1973/msldap
    def build(self):
        if self.creds.auth_method == LDAPAuthProtocol.SICILY:
            ntlmcred = MSLDAPNTLMCredential()
            ntlmcred.username = self.creds.username
            ntlmcred.domain = self.creds.domain if self.creds.domain is not None else ''
            ntlmcred.workstation = None
            ntlmcred.is_guest = False
            ntlmcred.encrypt = self.creds.encrypt

            if self.creds.password is None:
                raise Exception(
                    'NTLM authentication requres password/NT hash!')

            if len(self.creds.password) == 32:
                try:
                    bytes.fromhex(self.creds.password)
                except:
                    ntlmcred.password = self.creds.password
                else:
                    ntlmcred.nt_hash = self.creds.password

            else:
                ntlmcred.password = self.creds.password

            settings = NTLMHandlerSettings(ntlmcred)
            return NTLMAUTHHandler(settings)

        elif self.creds.auth_method == LDAPAuthProtocol.SIMPLE:
            cred = MSLDAPPLAINCredential()
            cred.username = self.creds.username
            cred.domain = self.creds.domain
            cred.password = self.creds.password
            return cred

        elif self.creds.auth_method == LDAPAuthProtocol.PLAIN:
            cred = MSLDAPSIMPLECredential()
            cred.username = self.creds.username
            cred.domain = self.creds.domain
            cred.password = self.creds.password
            return cred

        elif self.creds.auth_method in [
                LDAPAuthProtocol.NTLM_PASSWORD, LDAPAuthProtocol.NTLM_NT
        ]:
            ntlmcred = MSLDAPNTLMCredential()
            ntlmcred.username = self.creds.username
            ntlmcred.domain = self.creds.domain if self.creds.domain is not None else ''
            ntlmcred.workstation = None
            ntlmcred.is_guest = False
            ntlmcred.encrypt = self.creds.encrypt

            if self.creds.password is None:
                raise Exception('NTLM authentication requres password!')

            if self.creds.auth_method == LDAPAuthProtocol.NTLM_PASSWORD:
                ntlmcred.password = self.creds.password
            elif self.creds.auth_method == LDAPAuthProtocol.NTLM_NT:
                ntlmcred.nt_hash = self.creds.password
            else:
                raise Exception('Unknown NTLM auth method!')

            settings = NTLMHandlerSettings(ntlmcred)
            handler = NTLMAUTHHandler(settings)

            ##setting up SPNEGO
            spneg = SPNEGO()
            spneg.add_auth_context(
                'NTLMSSP - Microsoft NTLM Security Support Provider', handler)

            return spneg

        elif self.creds.auth_method in [
                LDAPAuthProtocol.KERBEROS_RC4, LDAPAuthProtocol.KERBEROS_NT,
                LDAPAuthProtocol.KERBEROS_AES,
                LDAPAuthProtocol.KERBEROS_PASSWORD,
                LDAPAuthProtocol.KERBEROS_CCACHE,
                LDAPAuthProtocol.KERBEROS_KEYTAB
        ]:

            if self.target is None:
                raise Exception('Target must be specified with Kerberos!')

            if self.target.host is None:
                raise Exception(
                    'target must have a domain name or hostname for kerberos!')

            if self.target.dc_ip is None:
                raise Exception('target must have a dc_ip for kerberos!')

            kcred = MSLDAPKerberosCredential()
            kc = KerberosCredential()
            kc.username = self.creds.username
            kc.domain = self.creds.domain
            kcred.enctypes = []
            if self.creds.auth_method == LDAPAuthProtocol.KERBEROS_PASSWORD:
                kc.password = self.creds.password
                kcred.enctypes = [23, 17, 18]
            elif self.creds.auth_method == LDAPAuthProtocol.KERBEROS_NT:
                kc.nt_hash = self.creds.password
                kcred.enctypes = [23]

            elif self.creds.auth_method == LDAPAuthProtocol.KERBEROS_AES:
                if len(self.creds.password) == 32:
                    kc.kerberos_key_aes_128 = self.creds.password
                    kcred.enctypes = [17]
                elif len(self.creds.password) == 64:
                    kc.kerberos_key_aes_256 = self.creds.password
                    kcred.enctypes = [18]

            elif self.creds.auth_method == LDAPAuthProtocol.KERBEROS_RC4:
                kc.kerberos_key_rc4 = self.creds.password
                kcred.enctypes = [23]

            elif self.creds.auth_method == LDAPAuthProtocol.KERBEROS_CCACHE:
                kc.ccache = self.creds.password
                kcred.enctypes = [23, 17, 18]
            elif self.creds.auth_method == LDAPAuthProtocol.KERBEROS_KEYTAB:
                kc.keytab = self.creds.password
                kcred.enctypes = [23, 17, 18]
            else:
                raise Exception(
                    'No suitable secret type found to set up kerberos!')

            if self.creds.etypes is not None:
                kcred.enctypes = list(
                    set(self.creds.etypes).intersection(set(kcred.enctypes)))

            kcred.ccred = kc
            kcred.spn = KerberosSPN.from_target_string(
                self.target.to_target_string())
            kcred.target = KerberosTarget(self.target.dc_ip)
            kcred.encrypt = self.creds.encrypt

            if self.target.proxy is not None:
                kcred.target.proxy = KerberosProxy()
                kcred.target.proxy.type = self.target.proxy.type
                kcred.target.proxy.target = copy.deepcopy(
                    self.target.proxy.target)
                kcred.target.proxy.target.endpoint_ip = self.target.dc_ip
                kcred.target.proxy.target.endpoint_port = 88
                kcred.target.proxy.creds = copy.deepcopy(
                    self.target.proxy.auth)

            handler = MSLDAPKerberos(kcred)

            #setting up SPNEGO
            spneg = SPNEGO()
            spneg.add_auth_context('MS KRB5 - Microsoft Kerberos 5', handler)
            return spneg

        elif self.creds.auth_method == LDAPAuthProtocol.SSPI_KERBEROS:
            if self.target is None:
                raise Exception('Target must be specified with Kerberos SSPI!')

            kerbcred = MSLDAPKerberosSSPICredential()
            kerbcred.username = self.creds.domain if self.creds.domain is not None else '<CURRENT>'
            kerbcred.username = self.creds.username if self.creds.username is not None else '<CURRENT>'
            kerbcred.password = self.creds.password if self.creds.password is not None else '<CURRENT>'
            kerbcred.spn = self.target.to_target_string()
            kerbcred.encrypt = self.creds.encrypt

            handler = MSLDAPKerberosSSPI(kerbcred)
            #setting up SPNEGO
            spneg = SPNEGO()
            spneg.add_auth_context('MS KRB5 - Microsoft Kerberos 5', handler)
            return spneg

        elif self.creds.auth_method == LDAPAuthProtocol.SSPI_NTLM:
            ntlmcred = MSLDAPNTLMSSPICredential()
            ntlmcred.username = self.creds.domain if self.creds.domain is not None else '<CURRENT>'
            ntlmcred.username = self.creds.username if self.creds.username is not None else '<CURRENT>'
            ntlmcred.password = self.creds.password if self.creds.password is not None else '<CURRENT>'
            ntlmcred.encrypt = self.creds.encrypt

            handler = MSLDAPNTLMSSPI(ntlmcred)
            #setting up SPNEGO
            spneg = SPNEGO()
            spneg.add_auth_context(
                'NTLMSSP - Microsoft NTLM Security Support Provider', handler)
            return spneg

        elif self.creds.auth_method.value.startswith('MULTIPLEXOR'):
            if self.creds.auth_method in [
                    LDAPAuthProtocol.MULTIPLEXOR_SSL_NTLM,
                    LDAPAuthProtocol.MULTIPLEXOR_NTLM
            ]:
                from msldap.authentication.ntlm.multiplexor import MSLDAPNTLMMultiplexor
                ntlmcred = MSLDAPMultiplexorCredential()
                ntlmcred.type = 'NTLM'
                if self.creds.username is not None:
                    ntlmcred.username = '******'
                if self.creds.domain is not None:
                    ntlmcred.domain = '<CURRENT>'
                if self.creds.password is not None:
                    ntlmcred.password = '******'
                ntlmcred.is_guest = False
                ntlmcred.is_ssl = True if self.creds.auth_method == LDAPAuthProtocol.MULTIPLEXOR_SSL_NTLM else False
                ntlmcred.parse_settings(self.creds.settings)
                ntlmcred.encrypt = self.creds.encrypt

                handler = MSLDAPNTLMMultiplexor(ntlmcred)
                #setting up SPNEGO
                spneg = SPNEGO()
                spneg.add_auth_context(
                    'NTLMSSP - Microsoft NTLM Security Support Provider',
                    handler)
                return spneg

            elif self.creds.auth_method in [
                    LDAPAuthProtocol.MULTIPLEXOR_SSL_KERBEROS,
                    LDAPAuthProtocol.MULTIPLEXOR_KERBEROS
            ]:
                from msldap.authentication.kerberos.multiplexor import MSLDAPKerberosMultiplexor

                ntlmcred = MSLDAPMultiplexorCredential()
                ntlmcred.type = 'KERBEROS'
                ntlmcred.target = self.target
                if self.creds.username is not None:
                    ntlmcred.username = '******'
                if self.creds.domain is not None:
                    ntlmcred.domain = '<CURRENT>'
                if self.creds.password is not None:
                    ntlmcred.password = '******'
                ntlmcred.is_guest = False
                ntlmcred.is_ssl = True if self.creds.auth_method == LDAPAuthProtocol.MULTIPLEXOR_SSL_NTLM else False
                ntlmcred.parse_settings(self.creds.settings)
                ntlmcred.encrypt = self.creds.encrypt

                handler = MSLDAPKerberosMultiplexor(ntlmcred)
                #setting up SPNEGO
                spneg = SPNEGO()
                spneg.add_auth_context('MS KRB5 - Microsoft Kerberos 5',
                                       handler)
                return spneg
コード例 #4
0
    def build(self):
        if self.creds.auth_method == LDAPAuthProtocol.SICILY:
            ntlmcred = MSLDAPNTLMCredential()
            ntlmcred.username = self.creds.username
            ntlmcred.domain = self.creds.domain if self.creds.domain is not None else ''
            ntlmcred.workstation = None
            ntlmcred.is_guest = False
            ntlmcred.encrypt = self.creds.encrypt

            if self.creds.password is None:
                raise Exception(
                    'NTLM authentication requres password/NT hash!')

            if len(self.creds.password) == 32:
                try:
                    bytes.fromhex(self.creds.password)
                except:
                    ntlmcred.password = self.creds.password
                else:
                    ntlmcred.nt_hash = self.creds.password

            else:
                ntlmcred.password = self.creds.password

            settings = NTLMHandlerSettings(ntlmcred)
            return NTLMAUTHHandler(settings)

        elif self.creds.auth_method == LDAPAuthProtocol.SIMPLE:
            cred = MSLDAPPLAINCredential()
            cred.username = self.creds.username
            cred.domain = self.creds.domain
            cred.password = self.creds.password
            return cred

        elif self.creds.auth_method == LDAPAuthProtocol.PLAIN:
            cred = MSLDAPSIMPLECredential()
            cred.username = self.creds.username
            cred.domain = self.creds.domain
            cred.password = self.creds.password
            return cred

        elif self.creds.auth_method in [
                LDAPAuthProtocol.NTLM_PASSWORD, LDAPAuthProtocol.NTLM_NT
        ]:
            ntlmcred = MSLDAPNTLMCredential()
            ntlmcred.username = self.creds.username
            ntlmcred.domain = self.creds.domain if self.creds.domain is not None else ''
            ntlmcred.workstation = None
            ntlmcred.is_guest = False
            ntlmcred.encrypt = self.creds.encrypt

            if self.creds.password is None:
                raise Exception('NTLM authentication requres password!')

            if self.creds.auth_method == LDAPAuthProtocol.NTLM_PASSWORD:
                ntlmcred.password = self.creds.password
            elif self.creds.auth_method == LDAPAuthProtocol.NTLM_NT:
                ntlmcred.nt_hash = self.creds.password
            else:
                raise Exception('Unknown NTLM auth method!')

            settings = NTLMHandlerSettings(ntlmcred)
            handler = NTLMAUTHHandler(settings)

            ##setting up SPNEGO
            spneg = SPNEGO()
            spneg.add_auth_context(
                'NTLMSSP - Microsoft NTLM Security Support Provider', handler)

            return spneg

        elif self.creds.auth_method in [
                LDAPAuthProtocol.KERBEROS_RC4, LDAPAuthProtocol.KERBEROS_NT,
                LDAPAuthProtocol.KERBEROS_AES,
                LDAPAuthProtocol.KERBEROS_PASSWORD,
                LDAPAuthProtocol.KERBEROS_CCACHE,
                LDAPAuthProtocol.KERBEROS_KEYTAB,
                LDAPAuthProtocol.KERBEROS_KIRBI, LDAPAuthProtocol.KERBEROS_PFX,
                LDAPAuthProtocol.KERBEROS_PEM,
                LDAPAuthProtocol.KERBEROS_CERTSTORE
        ]:

            if self.target is None:
                raise Exception('Target must be specified with Kerberos!')

            if self.target.host is None:
                raise Exception(
                    'target must have a domain name or hostname for kerberos!')

            if self.target.dc_ip is None:
                raise Exception('target must have a dc_ip for kerberos!')

            kcred = MSLDAPKerberosCredential()
            if self.creds.auth_method == LDAPAuthProtocol.KERBEROS_KIRBI:
                kc = KerberosCredential.from_kirbi(self.creds.password,
                                                   self.creds.username,
                                                   self.creds.domain)
            elif self.creds.auth_method == LDAPAuthProtocol.KERBEROS_CCACHE:
                kc = KerberosCredential.from_ccache_file(
                    self.creds.password, self.creds.username,
                    self.creds.domain)
            elif self.creds.auth_method == LDAPAuthProtocol.KERBEROS_KEYTAB:
                kc = KerberosCredential.from_kirbi(self.creds.password,
                                                   self.creds.username,
                                                   self.creds.domain)
            elif self.creds.auth_method == LDAPAuthProtocol.KERBEROS_PFX:
                kc = KerberosCredential.from_pfx_file(
                    self.creds.username,
                    self.creds.password,
                    username=self.creds.altname,
                    domain=self.creds.altdomain)
                self.creds.username = kc.username
                self.creds.domain = kc.domain
                self.target.domain = kc.domain
            elif self.creds.auth_method == LDAPAuthProtocol.KERBEROS_PEM:
                kc = KerberosCredential.from_pem_file(
                    self.creds.username,
                    self.creds.password,
                    username=self.creds.altname,
                    domain=self.creds.altdomain)
                self.creds.username = kc.username
                self.creds.domain = kc.domain
                self.target.domain = kc.domain
            elif self.creds.auth_method == LDAPAuthProtocol.KERBEROS_CERTSTORE:
                # username is the CN of the certificate
                # secret is the name of the certstore, default: MY
                certstore = self.creds.secret
                if self.creds.secret is None:
                    certstore = 'MY'
                kc = KerberosCredential.from_windows_certstore(
                    self.creds.username,
                    certstore,
                    username=self.creds.altname,
                    domain=self.creds.altdomain)
                self.creds.username = kc.username
                self.creds.domain = kc.domain
                self.target.domain = kc.domain

            else:
                kc = KerberosCredential()
                kc.username = self.creds.username
                kc.domain = self.creds.domain
            kcred.enctypes = []
            if self.creds.auth_method == LDAPAuthProtocol.KERBEROS_PASSWORD:
                kc.password = self.creds.password
                kcred.enctypes = [23, 17, 18]
            elif self.creds.auth_method == LDAPAuthProtocol.KERBEROS_NT:
                kc.nt_hash = self.creds.password
                kcred.enctypes = [23]

            elif self.creds.auth_method == LDAPAuthProtocol.KERBEROS_AES:
                if len(self.creds.password) == 32:
                    kc.kerberos_key_aes_128 = self.creds.password
                    kcred.enctypes = [17]
                elif len(self.creds.password) == 64:
                    kc.kerberos_key_aes_256 = self.creds.password
                    kcred.enctypes = [18]

            elif self.creds.auth_method == LDAPAuthProtocol.KERBEROS_RC4:
                kc.kerberos_key_rc4 = self.creds.password
                kcred.enctypes = [23]

            elif self.creds.auth_method == LDAPAuthProtocol.KERBEROS_CCACHE:
                kcred.enctypes = [23, 17, 18]  # TODO: fix this
            elif self.creds.auth_method == LDAPAuthProtocol.KERBEROS_KEYTAB:
                kc.keytab = self.creds.password
                kcred.enctypes = [23, 17, 18]  # TODO: fix this
            elif self.creds.auth_method == LDAPAuthProtocol.KERBEROS_KIRBI:
                kcred.enctypes = [23, 17, 18]  # TODO: fix this
            elif self.creds.auth_method in [
                    LDAPAuthProtocol.KERBEROS_PFX,
                    LDAPAuthProtocol.KERBEROS_CERTSTORE,
                    LDAPAuthProtocol.KERBEROS_PEM
            ]:
                kcred.enctypes = [17, 18]
            else:
                raise Exception(
                    'No suitable secret type found to set up kerberos!')

            if self.creds.etypes is not None:
                kcred.enctypes = list(
                    set(self.creds.etypes).intersection(set(kcred.enctypes)))

            kcred.ccred = kc
            kcred.spn = KerberosSPN.from_target_string(
                self.target.to_target_string())
            kcred.target = KerberosTarget(self.target.dc_ip)
            kcred.encrypt = self.creds.encrypt

            if self.target.proxy is not None:
                kcred.target.proxy = KerberosProxy()
                kcred.target.proxy.type = self.target.proxy.type
                kcred.target.proxy.target = copy.deepcopy(
                    self.target.proxy.target)
                kcred.target.proxy.target[-1].endpoint_ip = self.target.dc_ip
                kcred.target.proxy.target[-1].endpoint_port = 88

            handler = MSLDAPKerberos(kcred)

            #setting up SPNEGO
            spneg = SPNEGO()
            spneg.add_auth_context('MS KRB5 - Microsoft Kerberos 5', handler)
            return spneg

        elif self.creds.auth_method == LDAPAuthProtocol.SSPI_KERBEROS:
            if self.target is None:
                raise Exception('Target must be specified with Kerberos SSPI!')

            kerbcred = MSLDAPKerberosSSPICredential()
            kerbcred.username = self.creds.domain if self.creds.domain is not None else '<CURRENT>'
            kerbcred.username = self.creds.username if self.creds.username is not None else '<CURRENT>'
            kerbcred.password = self.creds.password if self.creds.password is not None else '<CURRENT>'
            kerbcred.spn = self.target.to_target_string()
            kerbcred.encrypt = self.creds.encrypt

            handler = MSLDAPKerberosSSPI(kerbcred)
            #setting up SPNEGO
            spneg = SPNEGO()
            spneg.add_auth_context('MS KRB5 - Microsoft Kerberos 5', handler)
            return spneg

        elif self.creds.auth_method == LDAPAuthProtocol.SSPI_NTLM:
            ntlmcred = MSLDAPNTLMSSPICredential()
            ntlmcred.username = self.creds.domain if self.creds.domain is not None else '<CURRENT>'
            ntlmcred.username = self.creds.username if self.creds.username is not None else '<CURRENT>'
            ntlmcred.password = self.creds.password if self.creds.password is not None else '<CURRENT>'
            ntlmcred.encrypt = self.creds.encrypt

            handler = MSLDAPNTLMSSPI(ntlmcred)
            #setting up SPNEGO
            spneg = SPNEGO()
            spneg.add_auth_context(
                'NTLMSSP - Microsoft NTLM Security Support Provider', handler)
            return spneg

        elif self.creds.auth_method.value.startswith('MULTIPLEXOR'):
            if self.creds.auth_method in [
                    LDAPAuthProtocol.MULTIPLEXOR_SSL_NTLM,
                    LDAPAuthProtocol.MULTIPLEXOR_NTLM
            ]:
                from msldap.authentication.ntlm.multiplexor import MSLDAPNTLMMultiplexor
                ntlmcred = MSLDAPMultiplexorCredential()
                ntlmcred.type = 'NTLM'
                if self.creds.username is not None:
                    ntlmcred.username = '******'
                if self.creds.domain is not None:
                    ntlmcred.domain = '<CURRENT>'
                if self.creds.password is not None:
                    ntlmcred.password = '******'
                ntlmcred.is_guest = False
                ntlmcred.is_ssl = True if self.creds.auth_method == LDAPAuthProtocol.MULTIPLEXOR_SSL_NTLM else False
                ntlmcred.parse_settings(self.creds.settings)
                ntlmcred.encrypt = self.creds.encrypt

                handler = MSLDAPNTLMMultiplexor(ntlmcred)
                #setting up SPNEGO
                spneg = SPNEGO()
                spneg.add_auth_context(
                    'NTLMSSP - Microsoft NTLM Security Support Provider',
                    handler)
                return spneg

            elif self.creds.auth_method in [
                    LDAPAuthProtocol.MULTIPLEXOR_SSL_KERBEROS,
                    LDAPAuthProtocol.MULTIPLEXOR_KERBEROS
            ]:
                from msldap.authentication.kerberos.multiplexor import MSLDAPKerberosMultiplexor

                ntlmcred = MSLDAPMultiplexorCredential()
                ntlmcred.type = 'KERBEROS'
                ntlmcred.target = self.target
                if self.creds.username is not None:
                    ntlmcred.username = '******'
                if self.creds.domain is not None:
                    ntlmcred.domain = '<CURRENT>'
                if self.creds.password is not None:
                    ntlmcred.password = '******'
                ntlmcred.is_guest = False
                ntlmcred.is_ssl = True if self.creds.auth_method == LDAPAuthProtocol.MULTIPLEXOR_SSL_NTLM else False
                ntlmcred.parse_settings(self.creds.settings)
                ntlmcred.encrypt = self.creds.encrypt

                handler = MSLDAPKerberosMultiplexor(ntlmcred)
                #setting up SPNEGO
                spneg = SPNEGO()
                spneg.add_auth_context('MS KRB5 - Microsoft Kerberos 5',
                                       handler)
                return spneg

        elif self.creds.auth_method.value.startswith('SSPIPROXY'):
            if self.creds.auth_method == LDAPAuthProtocol.SSPIPROXY_NTLM:
                from msldap.authentication.ntlm.sspiproxy import MSLDAPSSPIProxyNTLMAuth
                ntlmcred = MSLDAPSSPIProxyCredential()
                ntlmcred.type = 'NTLM'
                if self.creds.username is not None:
                    ntlmcred.username = '******'
                if self.creds.domain is not None:
                    ntlmcred.domain = '<CURRENT>'
                if self.creds.password is not None:
                    ntlmcred.password = '******'
                ntlmcred.is_guest = False
                ntlmcred.encrypt = self.creds.encrypt
                ntlmcred.host = self.creds.settings['host'][0]
                ntlmcred.port = int(self.creds.settings['port'][0])
                ntlmcred.proto = 'ws'
                if 'proto' in self.creds.settings:
                    ntlmcred.proto = self.creds.settings['proto'][0]
                if 'agentid' in self.creds.settings:
                    ntlmcred.agent_id = bytes.fromhex(
                        self.creds.settings['agentid'][0])

                handler = MSLDAPSSPIProxyNTLMAuth(ntlmcred)
                #setting up SPNEGO
                spneg = SPNEGO()
                spneg.add_auth_context(
                    'NTLMSSP - Microsoft NTLM Security Support Provider',
                    handler)
                return spneg

            elif self.creds.auth_method == LDAPAuthProtocol.SSPIPROXY_KERBEROS:
                from msldap.authentication.kerberos.sspiproxyws import MSLDAPSSPIProxyKerberosAuth

                ntlmcred = MSLDAPSSPIProxyCredential()
                ntlmcred.type = 'KERBEROS'
                ntlmcred.target = self.target
                if self.creds.username is not None:
                    ntlmcred.username = '******'
                if self.creds.domain is not None:
                    ntlmcred.domain = '<CURRENT>'
                if self.creds.password is not None:
                    ntlmcred.password = '******'
                ntlmcred.is_guest = False
                ntlmcred.encrypt = self.creds.encrypt
                ntlmcred.host = self.creds.settings['host'][0]
                ntlmcred.port = self.creds.settings['port'][0]
                ntlmcred.proto = 'ws'
                if 'proto' in self.creds.settings:
                    ntlmcred.proto = self.creds.settings['proto'][0]
                if 'agentid' in self.creds.settings:
                    ntlmcred.agent_id = bytes.fromhex(
                        self.creds.settings['agentid'][0])

                handler = MSLDAPSSPIProxyKerberosAuth(ntlmcred)
                #setting up SPNEGO
                spneg = SPNEGO()
                spneg.add_auth_context('MS KRB5 - Microsoft Kerberos 5',
                                       handler)
                return spneg

        elif self.creds.auth_method.value.startswith('WSNET'):
            if self.creds.auth_method in [LDAPAuthProtocol.WSNET_NTLM]:
                from msldap.authentication.ntlm.wsnet import MSLDAPWSNetNTLMAuth

                ntlmcred = MSLDAPWSNETCredential()
                ntlmcred.type = 'NTLM'
                if self.creds.username is not None:
                    ntlmcred.username = '******'
                if self.creds.domain is not None:
                    ntlmcred.domain = '<CURRENT>'
                if self.creds.password is not None:
                    ntlmcred.password = '******'
                ntlmcred.is_guest = False

                handler = MSLDAPWSNetNTLMAuth(ntlmcred)
                spneg = SPNEGO()
                spneg.add_auth_context(
                    'NTLMSSP - Microsoft NTLM Security Support Provider',
                    handler)
                return spneg

            elif self.creds.auth_method in [LDAPAuthProtocol.WSNET_KERBEROS]:
                from msldap.authentication.kerberos.wsnet import MSLDAPWSNetKerberosAuth

                ntlmcred = MSLDAPWSNETCredential()
                ntlmcred.type = 'KERBEROS'
                ntlmcred.target = self.target
                if self.creds.username is not None:
                    ntlmcred.username = '******'
                if self.creds.domain is not None:
                    ntlmcred.domain = '<CURRENT>'
                if self.creds.password is not None:
                    ntlmcred.password = '******'
                ntlmcred.is_guest = False

                handler = MSLDAPWSNetKerberosAuth(ntlmcred)
                #setting up SPNEGO
                spneg = SPNEGO()
                spneg.add_auth_context('MS KRB5 - Microsoft Kerberos 5',
                                       handler)
                return spneg
コード例 #5
0
ファイル: authbuilder.py プロジェクト: Red-infosec/aiosmb
    def to_spnego_cred(creds, target=None):
        if creds.authentication_type == SMBAuthProtocol.NTLM:
            ntlmcred = SMBNTLMCredential()
            ntlmcred.username = creds.username
            ntlmcred.domain = creds.domain if creds.domain is not None else ''
            ntlmcred.workstation = None
            ntlmcred.is_guest = False

            if creds.secret is None:
                raise Exception('NTLM authentication requres password!')
            if creds.secret_type == SMBCredentialsSecretType.NT:
                ntlmcred.nt_hash = creds.secret
            elif creds.secret_type == SMBCredentialsSecretType.PASSWORD:
                ntlmcred.password = creds.secret

            settings = NTLMHandlerSettings(ntlmcred)
            handler = NTLMAUTHHandler(settings)

            #setting up SPNEGO
            spneg = SPNEGO()
            spneg.add_auth_context(
                'NTLMSSP - Microsoft NTLM Security Support Provider', handler)

            return spneg

        elif creds.authentication_type == SMBAuthProtocol.KERBEROS:
            if target is None:
                raise Exception('Target must be specified with Kerberos!')

            if target.hostname is None:
                raise Exception(
                    'target must have a domain name or hostname for kerberos!')

            if target.dc_ip is None:
                raise Exception('target must have a dc_ip for kerberos!')

            kc = KerberosCredential()
            kc.username = creds.username
            kc.domain = creds.domain
            if creds.secret_type == SMBCredentialsSecretType.PASSWORD:
                kc.password = creds.secret
            elif creds.secret_type == SMBCredentialsSecretType.NT:
                kc.nt_hash = creds.secret

            elif creds.secret_type == SMBCredentialsSecretType.AES:
                if len(creds.secret) == 32:
                    kc.kerberos_key_aes_128 = creds.secret
                elif len(creds.secret) == 64:
                    kc.kerberos_key_aes_256 = creds.secret

            elif creds.secret_type == SMBCredentialsSecretType.RC4:
                kc.kerberos_key_rc4 = creds.secret

            elif creds.secret_type == SMBCredentialsSecretType.RC4:
                kc.ccache = creds.secret
            else:
                raise Exception(
                    'No suitable secret type found to set up kerberos!')

            kcred = SMBKerberosCredential()
            kcred.ccred = kc
            kcred.spn = KerberosSPN.from_target_string(
                target.to_target_string())
            kcred.target = KerberosTarget(target.dc_ip)
            if target.proxy is not None:
                kcred.target.proxy = KerberosProxy()
                kcred.target.proxy.target = copy.deepcopy(target.proxy.target)
                kcred.target.proxy.target.endpoint_ip = target.dc_ip
                kcred.target.proxy.target.endpoint_port = 88
                kcred.target.proxy.creds = copy.deepcopy(target.proxy.auth)

            handler = SMBKerberos(kcred)

            #setting up SPNEGO
            spneg = SPNEGO()
            spneg.add_auth_context('MS KRB5 - Microsoft Kerberos 5', handler)
            return spneg

        elif creds.authentication_type == SMBAuthProtocol.SSPI_KERBEROS:
            if target is None:
                raise Exception('Target must be specified with Kerberos SSPI!')

            kerbcred = SMBKerberosSSPICredential()
            kerbcred.client = None  #creds.username #here we could submit the domain as well for impersonation? TODO!
            kerbcred.password = creds.secret
            kerbcred.target = target.to_target_string()

            handler = SMBKerberosSSPI(kerbcred)
            #setting up SPNEGO
            spneg = SPNEGO()
            spneg.add_auth_context('MS KRB5 - Microsoft Kerberos 5', handler)
            return spneg

        elif creds.authentication_type == SMBAuthProtocol.SSPI_NTLM:
            ntlmcred = SMBNTLMSSPICredential()
            ntlmcred.client = creds.username  #here we could submit the domain as well for impersonation? TODO!
            ntlmcred.password = creds.secret

            handler = SMBNTLMSSPI(ntlmcred)
            #setting up SPNEGO
            spneg = SPNEGO()
            spneg.add_auth_context(
                'NTLMSSP - Microsoft NTLM Security Support Provider', handler)
            return spneg

        elif creds.authentication_type.value.startswith('MULTIPLEXOR'):
            if creds.authentication_type in [
                    SMBAuthProtocol.MULTIPLEXOR_SSL_NTLM,
                    SMBAuthProtocol.MULTIPLEXOR_NTLM
            ]:
                from aiosmb.authentication.ntlm.multiplexor import SMBNTLMMultiplexor

                ntlmcred = SMBMultiplexorCredential()
                ntlmcred.type = 'NTLM'
                if creds.username is not None:
                    ntlmcred.username = '******'
                if creds.domain is not None:
                    ntlmcred.domain = '<CURRENT>'
                if creds.secret is not None:
                    ntlmcred.password = '******'
                ntlmcred.is_guest = False
                ntlmcred.is_ssl = True if creds.authentication_type == SMBAuthProtocol.MULTIPLEXOR_SSL_NTLM else False
                ntlmcred.parse_settings(creds.settings)

                handler = SMBNTLMMultiplexor(ntlmcred)
                #setting up SPNEGO
                spneg = SPNEGO()
                spneg.add_auth_context(
                    'NTLMSSP - Microsoft NTLM Security Support Provider',
                    handler)
                return spneg

            elif creds.authentication_type in [
                    SMBAuthProtocol.MULTIPLEXOR_SSL_KERBEROS,
                    SMBAuthProtocol.MULTIPLEXOR_KERBEROS
            ]:
                from aiosmb.authentication.kerberos.multiplexor import SMBKerberosMultiplexor

                ntlmcred = SMBMultiplexorCredential()
                ntlmcred.type = 'KERBEROS'
                ntlmcred.target = creds.target
                if creds.username is not None:
                    ntlmcred.username = '******'
                if creds.domain is not None:
                    ntlmcred.domain = '<CURRENT>'
                if creds.secret is not None:
                    ntlmcred.password = '******'
                ntlmcred.is_guest = False
                ntlmcred.is_ssl = True if creds.authentication_type == SMBAuthProtocol.MULTIPLEXOR_SSL_NTLM else False
                ntlmcred.parse_settings(creds.settings)

                handler = SMBKerberosMultiplexor(ntlmcred)
                #setting up SPNEGO
                spneg = SPNEGO()
                spneg.add_auth_context('MS KRB5 - Microsoft Kerberos 5',
                                       handler)
                return spneg
コード例 #6
0
ファイル: url.py プロジェクト: kenshin33/minikerberos
    def from_url(url_str):
        res = KerberosClientURL()
        url = urlparse(url_str)

        res.dc_ip = url.hostname
        schemes = url.scheme.upper().split('+')

        if schemes[0] not in [
                'KERBEROS', 'KERBEROS-TCP, KERBEROS-UDP', 'KRB5', 'KRB5-UDP',
                'KRB5-TCP'
        ]:
            raise Exception('Unknown protocol! %s' % schemes[0])

        if schemes[0].endswith('UDP') is True:
            res.protocol = KerberosSocketType.UDP

        ttype = schemes[1]
        if ttype.find('-') != -1 and ttype.upper().endswith('-PROMPT'):
            ttype = ttype.split('-')[0]
            res.secret = getpass.getpass()
        try:
            res.secret_type = KerberosSecretType(ttype)
        except:
            raise Exception('Unknown secret type! %s' % ttype)

        if url.username is not None:
            if url.username.find('\\') != -1:
                res.domain, res.username = url.username.split('\\')
            else:
                raise Exception('Domain missing from username!')
        else:
            raise Exception('Missing username!')

        if res.secret is None:
            res.secret = url.password
        if url.port is not None:
            res.port = int(url.port)

        query = parse_qs(url.query)
        proxy_type = None
        for k in query:
            if k == 'proxytype':
                proxy_type = query[k][0]

            if k in kerberosclienturl_param2var:
                data = query[k][0]
                for c in kerberosclienturl_param2var[k][1]:
                    data = c(data)

                    setattr(res, kerberosclienturl_param2var[k][0], data)

        if proxy_type is not None:
            cu = SocksClientURL.from_params(url_str)
            cu[-1].endpoint_ip = res.dc_ip
            cu[-1].endpoint_port = res.port

            res.proxy = KerberosProxy(cu, None, type='SOCKS')

        if res.username is None:
            raise Exception('Missing username!')
        if res.secret is None:
            raise Exception('Missing secret/password!')
        if res.secret_type is None:
            raise Exception('Missing secret_type!')
        if res.dc_ip is None:
            raise Exception('Missing target hostname!')

        return res
コード例 #7
0
    async def run(self):
        try:
            if self.progress_queue is not None:
                msg = GathererProgress()
                msg.type = GathererProgressType.KERBEROAST
                msg.msg_type = MSGTYPE.STARTED
                msg.adid = self.ad_id
                msg.domain_name = self.domain_name
                await self.progress_queue.put(msg)

            if self.domain_name is None:
                info = self.db_session.query(ADInfo).get(self.ad_id)
                self.domain_name = str(info.distinguishedName).replace(
                    ',', '.').replace('DC=', '')

            _, err = await self.get_targets()
            if err is not None:
                raise err

            if len(self.targets_asreq) == 0 and len(self.targets_spn) == 0:
                logger.debug('No targets found!')
                return True, None

            if isinstance(self.kerb_url, KerberosClientURL):
                self.kerb_mgr = self.kerb_url
                if self.proxy is not None:
                    pu = SocksClientURL.from_urls(self.proxy)
                    p = KerberosProxy(pu, None, type='SOCKS')
                    self.kerb_mgr.proxy = p

            elif isinstance(self.kerb_url, str):
                if self.kerb_url == 'auto':
                    if platform.system() == 'Windows':
                        _, err = await self.asreproast()
                        if err is not None:
                            raise err

                        _, err = await self.kerberoast_sspi()
                        if err is not None:
                            raise err
                        return True, None
                    else:
                        raise Exception(
                            'No kerberos URL was provided and not running on Windows!'
                        )

                elif self.kerb_url.startswith('kerberos'):
                    self.kerb_mgr = KerberosClientURL.from_url(self.kerb_url)
                    if self.proxy is not None:
                        pu = SocksClientURL.from_urls(self.proxy)
                        p = KerberosProxy(pu, None, type='SOCKS')
                        self.kerb_mgr.proxy = p

                    _, err = await self.asreproast()
                    if err is not None:
                        raise err

                    _, err = await self.kerberoast()
                    if err is not None:
                        raise err

                elif self.kerb_url.startswith('ws'):
                    if self.kerb_url.find('type=sspiproxy'):
                        await self.kerberoast_sspiproxy()
                    else:
                        await self.kerberoast_multiplexor()

            return True, None
        except Exception as e:
            return None, e
        finally:
            if self.progress_queue is not None:
                msg = GathererProgress()
                msg.type = GathererProgressType.KERBEROAST
                msg.msg_type = MSGTYPE.FINISHED
                msg.adid = self.ad_id
                msg.domain_name = self.domain_name
                await self.progress_queue.put(msg)
コード例 #8
0
	async def connect(self, is_kerberos = False):
		"""
		
		"""
		try:
			#hiding the import, so you'll only need to install multiplexor when actually using it
			from multiplexor.operator import MultiplexorOperator
			

			#creating connection string
			#if self.target.proxy.type == SMBProxyType.MULTIPLEXOR:
			#	con_str = 'ws://%s:%s' % (self.target.proxy.ip, self.target.proxy.port)
			#else:
			#	con_str = 'wss://%s:%s' % (self.target.proxy.ip, self.target.proxy.port)
			con_str = self.target.proxy.target.get_server_url()
			#creating operator and connecting to multiplexor server
			self.operator = MultiplexorOperator(con_str, logging_sink = logger)
			await self.operator.connect()
			#creating socks5 proxy
			server_info = await self.operator.start_socks5(self.target.proxy.target.agent_id)
			await self.operator.terminate()
			#print(server_info)
			if is_kerberos is False:
				
				#copying the original target, then feeding it to socks5proxy object. it will hold the actual socks5 proxy server address we created before
				tp = SMBProxy()
				tp.target = SocksTarget()
				tp.target.version = SocksServerVersion.SOCKS5
				tp.target.server_ip = server_info['listen_ip']
				tp.target.server_port = server_info['listen_port']
				tp.target.is_bind = False
				tp.target.proto = SocksProtocol.TCP
				tp.target.timeout = 10
				tp.target.buffer_size = 4096
				
				tp.target.endpoint_ip = self.target.ip
				tp.target.endpoint_port = self.target.port
				tp.target.endpoint_timeout = self.target.timeout
				tp.type = SMBProxyType.SOCKS5

				newtarget = copy.deepcopy(self.target)
				newtarget.proxy = tp

				

				return SocksProxyConnection(target = newtarget), None
			
			else:
				kt = copy.deepcopy(self.target)
				kt.proxy = KerberosProxy()
				kt.proxy.target = SocksTarget()
				kt.proxy.target.version = SocksServerVersion.SOCKS5
				kt.proxy.target.server_ip = server_info['listen_ip']
				kt.proxy.target.server_port = server_info['listen_port']
				kt.proxy.target.is_bind = False
				kt.proxy.target.proto = SocksProtocol.TCP
				kt.proxy.target.timeout = 10
				kt.proxy.target.buffer_size = 4096

				kt.proxy.target.endpoint_ip = self.target.ip
				kt.proxy.target.endpoint_port = self.target.port
				kt.proxy.creds = copy.deepcopy(self.target.proxy.auth)

				return kt, None

		except Exception as e:
			return None, e
コード例 #9
0
    def to_spnego_cred(creds, target=None):
        if creds.authentication_type == SMBAuthProtocol.NEGOEX:
            with_certstrore = creds.secret_type == SMBCredentialsSecretType.CERTSTORE
            settings = SPNEGOEXAuthHandlerSettings(
                creds.username,
                creds.secret,
                target,
                dh_params=None,
                with_certstrore=with_certstrore)
            handler = SPNEGOEXAuthHandler(settings)

            #setting up SPNEGO
            spneg = SPNEGO()
            spneg.add_auth_context(
                'NEGOEX - SPNEGO Extended Negotiation Security Mechanism',
                handler)

            return spneg

        elif creds.authentication_type == SMBAuthProtocol.NTLM:
            ntlmcred = SMBNTLMCredential()
            ntlmcred.username = creds.username
            ntlmcred.domain = creds.domain if creds.domain is not None else ''
            ntlmcred.workstation = None
            ntlmcred.is_guest = False

            if creds.secret is None:
                if creds.username is None and creds.domain is None:
                    ntlmcred.is_guest = True
                else:
                    raise Exception('NTLM authentication requres password!')

            if creds.secret_type == SMBCredentialsSecretType.NT:
                ntlmcred.nt_hash = creds.secret
            elif creds.secret_type == SMBCredentialsSecretType.PASSWORD:
                ntlmcred.password = creds.secret

            settings = NTLMHandlerSettings(ntlmcred)
            handler = NTLMAUTHHandler(settings)

            #setting up SPNEGO
            spneg = SPNEGO()
            spneg.add_auth_context(
                'NTLMSSP - Microsoft NTLM Security Support Provider', handler)

            return spneg

        elif creds.authentication_type == SMBAuthProtocol.KERBEROS:
            if target is None:
                raise Exception('Target must be specified with Kerberos!')

            if target.hostname is None:
                raise Exception(
                    'target must have a domain name or hostname for kerberos!')

            if target.dc_ip is None:
                raise Exception('target must have a dc_ip for kerberos!')

            if creds.secret_type == SMBCredentialsSecretType.KEYTAB:
                filename = creds.secret
                if creds.secret.upper() == 'ENV':
                    filename = os.environ['KRB5KEYTAB']

                kc = KerberosCredential.from_keytab(filename, creds.username,
                                                    creds.domain)

            elif creds.secret_type == SMBCredentialsSecretType.CCACHE:
                filename = creds.secret
                if creds.secret.upper() == 'ENV':
                    try:
                        filename = os.environ['KRB5CCACHE']
                    except:
                        raise Exception(
                            'Kerberos auth missing environment variable KRB5CCACHE'
                        )
                kc = KerberosCredential.from_ccache_file(filename)
                kc.username = creds.username
                kc.domain = creds.domain

            elif creds.secret_type == SMBCredentialsSecretType.KIRBI:
                filename = creds.secret
                kc = KerberosCredential.from_kirbi(filename)
                kc.username = creds.username
                kc.domain = creds.domain

            elif creds.secret_type == SMBCredentialsSecretType.PFX:
                kc = KerberosCredential.from_pfx_file(creds.username,
                                                      creds.secret,
                                                      username=creds.altname,
                                                      domain=creds.altdomain)
                creds.username = kc.username
                creds.domain = kc.domain
                target.domain = kc.domain

            elif creds.secret_type == SMBCredentialsSecretType.PFXSTR:
                kc = KerberosCredential.from_pfx_string(creds.username,
                                                        creds.secret,
                                                        username=creds.altname,
                                                        domain=creds.altdomain)
                creds.username = kc.username
                creds.domain = kc.domain
                target.domain = kc.domain

            elif creds.secret_type == SMBCredentialsSecretType.PEM:
                kc = KerberosCredential.from_pem_file(creds.username,
                                                      creds.secret,
                                                      username=creds.altname,
                                                      domain=creds.altdomain)
                creds.username = kc.username
                creds.domain = kc.domain
                target.domain = kc.domain

            elif creds.secret_type == SMBCredentialsSecretType.CERTSTORE:
                # username is the CN of the certificate
                # secret is the name of the certstore, default: MY
                certstore = creds.secret
                if creds.secret is None:
                    certstore = 'MY'
                kc = KerberosCredential.from_windows_certstore(
                    creds.username,
                    certstore,
                    username=creds.altname,
                    domain=creds.altdomain)
                creds.username = kc.username
                creds.domain = kc.domain
                target.domain = kc.domain

            else:
                kc = KerberosCredential()
                kc.username = creds.username
                kc.domain = creds.domain
                if creds.secret_type == SMBCredentialsSecretType.PASSWORD:
                    kc.password = creds.secret
                elif creds.secret_type == SMBCredentialsSecretType.NT:
                    kc.nt_hash = creds.secret

                elif creds.secret_type == SMBCredentialsSecretType.AES:
                    if len(creds.secret) == 32:
                        kc.kerberos_key_aes_128 = creds.secret
                    elif len(creds.secret) == 64:
                        kc.kerberos_key_aes_256 = creds.secret

                elif creds.secret_type == SMBCredentialsSecretType.RC4:
                    kc.kerberos_key_rc4 = creds.secret

            if kc is None:
                raise Exception(
                    'No suitable secret type found to set up kerberos!')

            kcred = SMBKerberosCredential()
            kcred.ccred = kc
            kcred.spn = KerberosSPN.from_target_string(
                target.to_target_string())

            if target.proxy is not None:
                if target.proxy.type in [
                        SMBProxyType.WSNET, SMBProxyType.SOCKS5,
                        SMBProxyType.SOCKS5_SSL, SMBProxyType.SOCKS4,
                        SMBProxyType.SOCKS4_SSL
                ]:
                    kcred.target = KerberosTarget(target.dc_ip)
                    kcred.target.proxy = KerberosProxy()
                    kcred.target.proxy.target = copy.deepcopy(
                        target.proxy.target)
                    kcred.target.proxy.target[-1].endpoint_ip = target.dc_ip
                    kcred.target.proxy.target[-1].endpoint_port = 88

                elif target.proxy.type in [
                        SMBProxyType.MULTIPLEXOR, SMBProxyType.MULTIPLEXOR_SSL
                ]:
                    kcred.target = KerberosTarget(target.dc_ip)
                    kcred.target.proxy = copy.deepcopy(target.proxy)

            else:
                kcred.target = KerberosTarget(target.dc_ip)
            handler = SMBKerberos(kcred)
            #setting up SPNEGO
            spneg = SPNEGO()
            spneg.add_auth_context('MS KRB5 - Microsoft Kerberos 5', handler)
            return spneg

        elif creds.authentication_type == SMBAuthProtocol.SSPI_KERBEROS:
            if target is None:
                raise Exception('Target must be specified with Kerberos SSPI!')

            kerbcred = SMBKerberosSSPICredential()
            kerbcred.client = None  #creds.username #here we could submit the domain as well for impersonation? TODO!
            kerbcred.password = creds.secret
            kerbcred.target = target.to_target_string()

            handler = SMBKerberosSSPI(kerbcred)
            #setting up SPNEGO
            spneg = SPNEGO()
            spneg.add_auth_context('MS KRB5 - Microsoft Kerberos 5', handler)
            return spneg

        elif creds.authentication_type == SMBAuthProtocol.SSPI_NTLM:
            ntlmcred = SMBNTLMSSPICredential()
            ntlmcred.client = creds.username  #here we could submit the domain as well for impersonation? TODO!
            ntlmcred.password = creds.secret

            handler = SMBNTLMSSPI(ntlmcred)
            #setting up SPNEGO
            spneg = SPNEGO()
            spneg.add_auth_context(
                'NTLMSSP - Microsoft NTLM Security Support Provider', handler)
            return spneg

        elif creds.authentication_type.value.startswith('MPN'):
            if creds.authentication_type in [
                    SMBAuthProtocol.MPN_SSL_NTLM, SMBAuthProtocol.MPN_NTLM
            ]:
                from aiosmb.authentication.ntlm.mpn import SMBNTLMMPN
                ntlmcred = SMBMPNCredential()
                ntlmcred.type = 'NTLM'
                ntlmcred.is_ssl = True if creds.authentication_type == SMBAuthProtocol.MPN_SSL_NTLM else False
                ntlmcred.parse_settings(creds.settings)

                handler = SMBNTLMMPN(ntlmcred)
                #setting up SPNEGO
                spneg = SPNEGO()
                spneg.add_auth_context(
                    'NTLMSSP - Microsoft NTLM Security Support Provider',
                    handler)
                return spneg

            elif creds.authentication_type in [
                    SMBAuthProtocol.MPN_SSL_KERBEROS,
                    SMBAuthProtocol.MPN_KERBEROS
            ]:
                from aiosmb.authentication.kerberos.mpn import SMBKerberosMPN

                ntlmcred = SMBMPNCredential()
                ntlmcred.type = 'KERBEROS'
                ntlmcred.target = creds.target
                if creds.username is not None:
                    ntlmcred.username = '******'
                if creds.domain is not None:
                    ntlmcred.domain = '<CURRENT>'
                if creds.secret is not None:
                    ntlmcred.password = '******'
                ntlmcred.is_guest = False
                ntlmcred.is_ssl = True if creds.authentication_type == SMBAuthProtocol.MPN_SSL_KERBEROS else False
                ntlmcred.parse_settings(creds.settings)

                handler = SMBKerberosMPN(ntlmcred)
                #setting up SPNEGO
                spneg = SPNEGO()
                spneg.add_auth_context('MS KRB5 - Microsoft Kerberos 5',
                                       handler)
                return spneg

        elif creds.authentication_type.value.startswith('MULTIPLEXOR'):
            if creds.authentication_type in [
                    SMBAuthProtocol.MULTIPLEXOR_SSL_NTLM,
                    SMBAuthProtocol.MULTIPLEXOR_NTLM
            ]:
                from aiosmb.authentication.ntlm.multiplexor import SMBNTLMMultiplexor

                ntlmcred = SMBMultiplexorCredential()
                ntlmcred.type = 'NTLM'
                if creds.username is not None:
                    ntlmcred.username = '******'
                if creds.domain is not None:
                    ntlmcred.domain = '<CURRENT>'
                if creds.secret is not None:
                    ntlmcred.password = '******'
                ntlmcred.is_guest = False
                ntlmcred.is_ssl = True if creds.authentication_type == SMBAuthProtocol.MULTIPLEXOR_SSL_NTLM else False
                ntlmcred.parse_settings(creds.settings)

                handler = SMBNTLMMultiplexor(ntlmcred)
                #setting up SPNEGO
                spneg = SPNEGO()
                spneg.add_auth_context(
                    'NTLMSSP - Microsoft NTLM Security Support Provider',
                    handler)
                return spneg

            elif creds.authentication_type in [
                    SMBAuthProtocol.MULTIPLEXOR_SSL_KERBEROS,
                    SMBAuthProtocol.MULTIPLEXOR_KERBEROS
            ]:
                from aiosmb.authentication.kerberos.multiplexor import SMBKerberosMultiplexor

                ntlmcred = SMBMultiplexorCredential()
                ntlmcred.type = 'KERBEROS'
                ntlmcred.target = creds.target
                if creds.username is not None:
                    ntlmcred.username = '******'
                if creds.domain is not None:
                    ntlmcred.domain = '<CURRENT>'
                if creds.secret is not None:
                    ntlmcred.password = '******'
                ntlmcred.is_guest = False
                ntlmcred.is_ssl = True if creds.authentication_type == SMBAuthProtocol.MULTIPLEXOR_SSL_NTLM else False
                ntlmcred.parse_settings(creds.settings)

                handler = SMBKerberosMultiplexor(ntlmcred)
                #setting up SPNEGO
                spneg = SPNEGO()
                spneg.add_auth_context('MS KRB5 - Microsoft Kerberos 5',
                                       handler)
                return spneg

        elif creds.authentication_type.value.startswith('WSNET'):
            if creds.authentication_type in [SMBAuthProtocol.WSNET_NTLM]:
                from aiosmb.authentication.ntlm.wsnet import SMBWSNetNTLMAuth

                ntlmcred = SMBWSNETCredential()
                ntlmcred.type = 'NTLM'
                if creds.username is not None:
                    ntlmcred.username = '******'
                if creds.domain is not None:
                    ntlmcred.domain = '<CURRENT>'
                if creds.secret is not None:
                    ntlmcred.password = '******'
                ntlmcred.is_guest = False

                handler = SMBWSNetNTLMAuth(ntlmcred)
                spneg = SPNEGO()
                spneg.add_auth_context(
                    'NTLMSSP - Microsoft NTLM Security Support Provider',
                    handler)
                return spneg

            elif creds.authentication_type in [SMBAuthProtocol.WSNET_KERBEROS]:
                from aiosmb.authentication.kerberos.wsnet import SMBWSNetKerberosAuth

                ntlmcred = SMBWSNETCredential()
                ntlmcred.type = 'KERBEROS'
                ntlmcred.target = creds.target
                if creds.username is not None:
                    ntlmcred.username = '******'
                if creds.domain is not None:
                    ntlmcred.domain = '<CURRENT>'
                if creds.secret is not None:
                    ntlmcred.password = '******'
                ntlmcred.is_guest = False

                handler = SMBWSNetKerberosAuth(ntlmcred)
                #setting up SPNEGO
                spneg = SPNEGO()
                spneg.add_auth_context('MS KRB5 - Microsoft Kerberos 5',
                                       handler)
                return spneg

        elif creds.authentication_type.value.startswith('SSPIPROXY'):
            if creds.authentication_type == SMBAuthProtocol.SSPIPROXY_NTLM:
                from aiosmb.authentication.ntlm.sspiproxy import SMBSSPIProxyNTLMAuth

                ntlmcred = SMBSSPIProxyCredential()
                ntlmcred.type = 'NTLM'
                if creds.username is not None:
                    ntlmcred.username = '******'
                if creds.domain is not None:
                    ntlmcred.domain = '<CURRENT>'
                if creds.secret is not None:
                    ntlmcred.password = '******'
                ntlmcred.is_guest = False
                ntlmcred.host = creds.settings['host'][0]
                ntlmcred.port = int(creds.settings['port'][0])
                ntlmcred.proto = 'ws'
                if 'proto' in creds.settings:
                    ntlmcred.proto = creds.settings['proto'][0]
                if 'agentid' in creds.settings:
                    ntlmcred.agent_id = bytes.fromhex(
                        creds.settings['agentid'][0])

                handler = SMBSSPIProxyNTLMAuth(ntlmcred)
                spneg = SPNEGO()
                spneg.add_auth_context(
                    'NTLMSSP - Microsoft NTLM Security Support Provider',
                    handler)
                return spneg

            elif creds.authentication_type == SMBAuthProtocol.SSPIPROXY_KERBEROS:
                from aiosmb.authentication.kerberos.sspiproxy import SMBSSPIProxyKerberosAuth

                ntlmcred = SMBSSPIProxyCredential()
                ntlmcred.type = 'KERBEROS'
                ntlmcred.target = creds.target
                if creds.username is not None:
                    ntlmcred.username = '******'
                if creds.domain is not None:
                    ntlmcred.domain = '<CURRENT>'
                if creds.secret is not None:
                    ntlmcred.password = '******'
                ntlmcred.is_guest = False
                ntlmcred.host = creds.settings['host'][0]
                ntlmcred.port = int(creds.settings['port'][0])
                ntlmcred.proto = 'ws'
                if 'proto' in creds.settings:
                    ntlmcred.proto = creds.settings['proto'][0]
                if 'agentid' in creds.settings:
                    ntlmcred.agent_id = bytes.fromhex(
                        creds.settings['agentid'][0])

                handler = SMBSSPIProxyKerberosAuth(ntlmcred)
                #setting up SPNEGO
                spneg = SPNEGO()
                spneg.add_auth_context('MS KRB5 - Microsoft Kerberos 5',
                                       handler)
                return spneg