Codebase list msldap / d194e76
Import upstream version 0.4.6 Kali Janitor 1 year, 6 months ago
8 changed file(s) with 58 addition(s) and 30 deletion(s). Raw diff Collapse all Expand all
00 Metadata-Version: 2.1
11 Name: msldap
2 Version: 0.4.1
2 Version: 0.4.6
33 Summary: Python library to play with MS LDAP
44 Home-page: https://github.com/skelsec/msldap
55 Author: Tamas Jos
00
1 __version__ = "0.4.1"
1 __version__ = "0.4.6"
22 __banner__ = \
33 """
44 # msldap %s
33 # Tamas Jos (@skelsec)
44 #
55
6 from codecs import lookup
76 import copy
87 import asyncio
98
113112 self._serverinfo = res
114113 self._tree = res['defaultNamingContext']
115114 self._ldapinfo, err = await self.get_ad_info()
116 self._domainsid_cache[self._ldapinfo.objectSid] = self._ldapinfo.name
115 if self._con.is_anon is False:
116 if err is not None:
117 raise err
118 self._domainsid_cache[self._ldapinfo.objectSid] = self._ldapinfo.name
119
117120 if self.keepalive is True:
118121 self.__keepalive_task = asyncio.create_task(self.__keepalive())
119 if err is not None:
120 raise err
121122 return True, None
122123 except Exception as e:
123124 return False, e
932933 """
933934 changes = {
934935 'servicePrincipalName': [('add', [spn])]
936 }
937 return await self._con.modify(user_dn, changes)
938
939 async def del_user_spn(self, user_dn, spn):
940 """
941 Adds an SPN record to the user object.
942
943 :param user_dn: The user's DN
944 :type user_dn: str
945 :param spn: The SPN to be added. It must follow the SPN string format specifications.
946 :type spn: str
947 :return: A tuple of (True, None) on success or (False, Exception) on error.
948 :rtype: (:class:`bool`, :class:`Exception`)
949
950 """
951 changes = {
952 'servicePrincipalName': [('delete', [spn])]
935953 }
936954 return await self._con.modify(user_dn, changes)
937955
1717 from asysocks.unicomm.common.target import UniProto
1818 from msldap.commons.exceptions import LDAPBindException, LDAPAddException, LDAPModifyException, LDAPDeleteException
1919 from hashlib import sha256
20 from minikerberos.gssapi.channelbindings import ChannelBindingsStruct
2120 from asysocks.unicomm.client import UniClient
2221 from asyauth.common.constants import asyauthProtocol
2322 from asyauth.common.credentials import UniCredential
23 from asyauth.common.winapi.constants import ISC_REQ
2424
2525 class MSLDAPClientConnection:
2626 def __init__(self, target:MSLDAPTarget, credential:UniCredential, auth=None):
3333
3434 self.connected = False
3535 self.bind_ok = False
36 self.is_anon = False
3637 self.__sign_messages = False
3738 self.__encrypt_messages = False
3839 self.network = None
180181 # now processing channel binding options
181182 if self.target.protocol == UniProto.CLIENT_SSL_TCP:
182183 certdata = self.network.get_peer_certificate()
183 cb_struct = ChannelBindingsStruct()
184 cb_struct.application_data = b'tls-server-end-point:' + sha256(certdata).digest()
185
186 self.cb_data = cb_struct.to_bytes()
184 self.cb_data = b'tls-server-end-point:' + sha256(certdata).digest()
187185
188186 self.handle_incoming_task = asyncio.create_task(self.__handle_incoming())
189187 logger.debug('Connection succsessful!')
233231 logger.debug('BIND in progress...')
234232 try:
235233 if self.credential.protocol == asyauthProtocol.SICILY:
236
237 data, to_continue, err = await self.auth.authenticate(None, spn=self.target.to_target_string())
234 flags = ISC_REQ.CONNECTION|ISC_REQ.CONFIDENTIALITY|ISC_REQ.INTEGRITY
235 if self.target.protocol == UniProto.CLIENT_SSL_TCP:
236 flags = ISC_REQ.CONNECTION
237 data, to_continue, err = await self.auth.authenticate(None, spn=self.target.to_target_string(), flags=flags, cb_data = self.cb_data)
238238 if err is not None:
239239 return None, err
240240
288288 res['protocolOp']['diagnosticMessage']
289289 )
290290
291 data, to_continue, err = await self.auth.authenticate(res['protocolOp']['matchedDN'], spn=self.target.to_target_string())
291 data, to_continue, err = await self.auth.authenticate(res['protocolOp']['matchedDN'], spn=self.target.to_target_string(), cb_data = self.cb_data)
292292 if err is not None:
293293 return None, err
294294
329329 user = b''
330330 if self.auth.username != None:
331331 user = self.auth.username.encode()
332
332 if user == b'':
333 self.is_anon = True
334
333335 auth = {
334336 'simple' : pw
335337 }
363365 challenge = None
364366 while True:
365367 try:
366 data, to_continue, err = await self.auth.authenticate(challenge, cb_data = self.cb_data, spn=self.target.to_target_string())
368 flags = ISC_REQ.CONNECTION|ISC_REQ.CONFIDENTIALITY|ISC_REQ.INTEGRITY
369 if self.target.protocol == UniProto.CLIENT_SSL_TCP:
370 flags = ISC_REQ.CONNECTION
371
372 data, to_continue, err = await self.auth.authenticate(challenge, cb_data = self.cb_data, spn=self.target.to_target_string(), flags=flags)
367373 if err is not None:
368374 raise err
369375 except Exception as e:
394400 res = res.native
395401 if res['protocolOp']['resultCode'] == 'success':
396402 if 'serverSaslCreds' in res['protocolOp']:
397 data, _, err = await self.auth.authenticate(res['protocolOp']['serverSaslCreds'], cb_data = self.cb_data, spn=self.target.to_target_string())
403 data, _, err = await self.auth.authenticate(res['protocolOp']['serverSaslCreds'], cb_data = self.cb_data, spn=self.target.to_target_string(), flags=flags)
398404 if err is not None:
399405 return False, err
400406
401 self.encryption_sequence_counter = self.auth.get_seq_number()
407 if self.auth.encryption_needed() is True or self.auth.signing_needed() is True:
408 self.encryption_sequence_counter = self.auth.get_seq_number()
402409 self.__bind_success()
403410
404411 return True, None
772779 #print('res')
773780 #print(res)
774781 return convert_attributes(res.native['protocolOp']['attributes']), None
775
776
777
778
779
780
781
782
783
577577 traceback.print_exc()
578578 return False
579579
580 async def do_delspn(self, user_dn, spn):
581 """Removes an SPN entry to the users account"""
582 try:
583 _, err = await self.connection.del_user_spn(user_dn, spn)
584 if err is not None:
585 raise err
586 print('SPN removed!')
587 return True
588 except:
589 traceback.print_exc()
590 return False
591
580592 async def do_addhostname(self, user_dn, hostname):
581593 """Adds additional hostname to computer account"""
582594 try:
00 Metadata-Version: 2.1
11 Name: msldap
2 Version: 0.4.1
2 Version: 0.4.6
33 Summary: Python library to play with MS LDAP
44 Home-page: https://github.com/skelsec/msldap
55 Author: Tamas Jos
00 unicrypto>=0.0.9
1 asyauth>=0.0.2
1 asyauth>=0.0.5
22 asysocks>=0.2.1
33 asn1crypto>=1.3.0
44 minikerberos>=0.3.1
4747 ),
4848 install_requires=[
4949 'unicrypto>=0.0.9',
50 'asyauth>=0.0.2',
50 'asyauth>=0.0.5',
5151 'asysocks>=0.2.1',
5252 'asn1crypto>=1.3.0',
5353 'minikerberos>=0.3.1',