How to use the msldap.core.MSLDAPConnection function in msldap

To help you get started, we’ve selected a few msldap examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github skelsec / pypykatz / pypykatz / ldap / cmdhelper.py View on Github external
from msldap import logger as msldaplogger
		from pypykatz.commons.winapi.machine import LiveMachine
		
		machine = LiveMachine()
	
		if args.credential:
			creds = MSLDAPCredential.from_connection_string(args.credential)
		else:
			creds = MSLDAPCredential.get_dummy_sspi()
		
		if args.dc_ip:
			target = MSLDAPTarget(args.dc_ip)
		else:
			target = MSLDAPTarget(machine.get_domain())
			
		connection = MSLDAPConnection(creds, target)
		connection.connect()
		
		try:
			adinfo = connection.get_ad_info()
			domain = adinfo.distinguishedName.replace('DC=','').replace(',','.')
		except Exception as e:
			logging.warning('[LDAP] Failed to get domain name from LDAP server. This is not normal, but happens. Reason: %s' % e)
			domain = machine.get_domain()
		
		if args.cmd == 'spn':
			logging.debug('Enumerating SPN user accounts...')
			cnt = 0
			if args.out_file:
				with open(os.path.join(basefolder,basefile+'_spn_users.txt'), 'w', newline='') as f:
					for user in connection.get_all_service_user_objects():
						cnt += 1
github skelsec / pypykatz / pypykatz / ldap / cmdhelper.py View on Github external
def run(self, args):
		from msldap.core import MSLDAPCredential, MSLDAPTarget, MSLDAPConnection
		from msldap.ldap_objects import MSADUser
		from msldap import logger as msldaplogger
		
		if not args.credential:
			raise Exception('You must provide credentials when using ldap in platform independent mode.')
			
		creds = MSLDAPCredential.from_connection_string(args.credential)
		target = MSLDAPTarget.from_connection_string(args.credential)
			
		connection = MSLDAPConnection(creds, target)
		connection.connect()
		
		try:
			adinfo = connection.get_ad_info()
			domain = adinfo.distinguishedName.replace('DC=','').replace(',','.')
		except Exception as e:
			logging.warning('[LDAP] Failed to get domain name from LDAP server. This is not normal, but happens. Reason: %s' % e)
			domain = machine.get_domain()
		
		if args.cmd == 'spn':
			logging.debug('Enumerating SPN user accounts...')
			cnt = 0
			if args.out_file:
				with open(os.path.join(basefolder,basefile+'_spn_users.txt'), 'w', newline='') as f:
					for user in connection.get_all_service_user_objects():
						cnt += 1