本文整理汇总了Python中impacket.ldap.ldap.LDAPSessionError方法的典型用法代码示例。如果您正苦于以下问题:Python ldap.LDAPSessionError方法的具体用法?Python ldap.LDAPSessionError怎么用?Python ldap.LDAPSessionError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类impacket.ldap.ldap
的用法示例。
在下文中一共展示了ldap.LDAPSessionError方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: kerberos_login
# 需要导入模块: from impacket.ldap import ldap [as 别名]
# 或者: from impacket.ldap.ldap import LDAPSessionError [as 别名]
def kerberos_login(self, aesKey, kdcHost):
# Create the baseDN
domainParts = self.domain.split('.')
self.baseDN = ''
for i in domainParts:
self.baseDN += 'dc=%s,' % i
# Remove last ','
self.baseDN = self.baseDN[:-1]
if self.kdcHost is not None:
target = self.kdcHost
else:
target = self.domain
try:
self.ldapConnection.kerberosLogin(self.username, self.password, self.domain, self.lmhash, self.nthash,
self.aesKey, kdcHost=self.kdcHost)
except ldap_impacket.LDAPSessionError as e:
if str(e).find('strongerAuthRequired') >= 0:
# We need to try SSL
self.ldapConnection = ldap_impacket.LDAPConnection('ldaps://%s' % target, self.baseDN, self.kdcHost)
self.ldapConnection.kerberosLogin(self.username, self.password, self.domain, self.lmhash, self.nthash,
self.aesKey, kdcHost=self.kdcHost)
return True
示例2: _create_ldap_connection
# 需要导入模块: from impacket.ldap import ldap [as 别名]
# 或者: from impacket.ldap.ldap import LDAPSessionError [as 别名]
def _create_ldap_connection(self, queried_domain=str(), ads_path=str(),
ads_prefix=str()):
if not self._domain:
self._domain = self._get_netfqdn()
if not queried_domain:
queried_domain = self._get_netfqdn()
self._queried_domain = queried_domain
base_dn = str()
if ads_prefix:
self._ads_prefix = ads_prefix
base_dn = '{},'.format(self._ads_prefix)
if ads_path:
# TODO: manage ADS path starting with 'GC://'
if ads_path.upper().startswith('LDAP://'):
ads_path = ads_path[7:]
self._ads_path = ads_path
base_dn += self._ads_path
else:
base_dn += ','.join('dc={}'.format(x) for x in self._queried_domain.split('.'))
try:
ldap_connection = ldap.LDAPConnection('ldap://{}'.format(self._domain_controller),
base_dn, self._domain_controller)
ldap_connection.login(self._user, self._password, self._domain,
self._lmhash, self._nthash)
except ldap.LDAPSessionError, e:
if str(e).find('strongerAuthRequired') >= 0:
# We need to try SSL
ldap_connection = ldap.LDAPConnection('ldaps://{}'.format(self._domain_controller),
base_dn, self._domain_controller)
ldap_connection.login(self._user, self._password, self._domain,
self._lmhash, self._nthash)
else:
raise e
示例3: _create_ldap_connection
# 需要导入模块: from impacket.ldap import ldap [as 别名]
# 或者: from impacket.ldap.ldap import LDAPSessionError [as 别名]
def _create_ldap_connection(self, queried_domain=str(), ads_path=str(), ads_prefix=str()):
if not self._domain:
self._domain = self._get_netfqdn()
if not queried_domain:
queried_domain = self._get_netfqdn()
self._queried_domain = queried_domain
base_dn = str()
if ads_prefix:
self._ads_prefix = ads_prefix
base_dn = '{},'.format(self._ads_prefix)
if ads_path:
# TODO: manage ADS path starting with 'GC://'
if ads_path.upper().startswith('LDAP://'):
ads_path = ads_path[7:]
self._ads_path = ads_path
base_dn += self._ads_path
else:
base_dn += ','.join('dc={}'.format(x) for x in self._queried_domain.split('.'))
try:
ldap_connection = ldap.LDAPConnection('ldap://{}'.format(self._domain_controller),
base_dn, self._domain_controller)
ldap_connection.login(self._user, self._password, self._domain,
self._lmhash, self._nthash)
except ldap.LDAPSessionError as e:
if str(e).find('strongerAuthRequired') >= 0:
# We need to try SSL
ldap_connection = ldap.LDAPConnection('ldaps://{}'.format(self._domain_controller),
base_dn, self._domain_controller)
ldap_connection.login(self._user, self._password, self._domain,
self._lmhash, self._nthash)
else:
raise e
except socket.error as e:
return
self._ldap_connection = ldap_connection
示例4: run
# 需要导入模块: from impacket.ldap import ldap [as 别名]
# 或者: from impacket.ldap.ldap import LDAPSessionError [as 别名]
def run(self):
if self.__doKerberos:
self.__target = self.getMachineName()
else:
if self.__kdcHost is not None:
self.__target = self.__kdcHost
else:
self.__target = self.__domain
# Connect to LDAP
try:
ldapConnection = ldap.LDAPConnection('ldap://%s'%self.__target, self.baseDN, self.__kdcHost)
if self.__doKerberos is not True:
ldapConnection.login(self.__username, self.__password, self.__domain, self.__lmhash, self.__nthash)
else:
ldapConnection.kerberosLogin(self.__username, self.__password, self.__domain, self.__lmhash, self.__nthash,
self.__aesKey, kdcHost=self.__kdcHost)
except ldap.LDAPSessionError, e:
if str(e).find('strongerAuthRequired') >= 0:
# We need to try SSL
ldapConnection = ldap.LDAPConnection('ldaps://%s' % self.__target, self.baseDN, self.__kdcHost)
if self.__doKerberos is not True:
ldapConnection.login(self.__username, self.__password, self.__domain, self.__lmhash, self.__nthash)
else:
ldapConnection.kerberosLogin(self.__username, self.__password, self.__domain, self.__lmhash, self.__nthash,
self.__aesKey, kdcHost=self.__kdcHost)
else:
raise
# Building the search filter
示例5: plaintext_login
# 需要导入模块: from impacket.ldap import ldap [as 别名]
# 或者: from impacket.ldap.ldap import LDAPSessionError [as 别名]
def plaintext_login(self, domain, username, password):
self.username = username
self.password = password
self.domain = domain
# Create the baseDN
self.baseDN = ''
domainParts = self.domain.split('.')
for i in domainParts:
self.baseDN += 'dc=%s,' % i
# Remove last ','
self.baseDN = self.baseDN[:-1]
if self.kdcHost is not None:
target = self.kdcHost
else:
target = domain
if self.password == '' and self.args.asreproast:
hash_TGT = KerberosAttacks(self).getTGT_asroast(self.username)
if hash_TGT:
self.logger.highlight(u'{}'.format(hash_TGT))
with open(self.args.asreproast, 'a+') as hash_asreproast:
hash_asreproast.write(hash_TGT + '\n')
return False
# Connect to LDAP
out = u'{}{}:{}'.format('{}\\'.format(domain),
username,
password)
try:
self.ldapConnection = ldap_impacket.LDAPConnection('ldap://%s' % target, self.baseDN, self.kdcHost)
self.ldapConnection.login(self.username, self.password, self.domain, self.lmhash, self.nthash)
self.logger.success(out)
except ldap_impacket.LDAPSessionError as e:
if str(e).find('strongerAuthRequired') >= 0:
# We need to try SSL
try:
self.ldapConnection = ldap_impacket.LDAPConnection('ldaps://%s' % target, self.baseDN, self.kdcHost)
self.ldapConnection.login(self.username, self.password, self.domain, self.lmhash, self.nthash)
self.logger.success(out)
except ldap_impacket.LDAPSessionError as e:
self.logger.error(u'{}\{}:{}'.format(self.domain,
self.username,
self.password))
else:
self.logger.error(u'{}\{}:{}'.format(self.domain,
self.username,
self.password))
return False
return True
示例6: run
# 需要导入模块: from impacket.ldap import ldap [as 别名]
# 或者: from impacket.ldap.ldap import LDAPSessionError [as 别名]
def run(self):
if self.__doKerberos:
self.__target = self.getMachineName()
else:
if self.__kdcHost is not None:
self.__target = self.__kdcHost
else:
self.__target = self.__domain
# Connect to LDAP
try:
ldapConnection = ldap.LDAPConnection('ldap://%s'%self.__target, self.baseDN, self.__kdcHost)
if self.__doKerberos is not True:
ldapConnection.login(self.__username, self.__password, self.__domain, self.__lmhash, self.__nthash)
else:
ldapConnection.kerberosLogin(self.__username, self.__password, self.__domain, self.__lmhash, self.__nthash,
self.__aesKey, kdcHost=self.__kdcHost)
except ldap.LDAPSessionError as e:
if str(e).find('strongerAuthRequired') >= 0:
# We need to try SSL
ldapConnection = ldap.LDAPConnection('ldaps://%s' % self.__target, self.baseDN, self.__kdcHost)
if self.__doKerberos is not True:
ldapConnection.login(self.__username, self.__password, self.__domain, self.__lmhash, self.__nthash)
else:
ldapConnection.kerberosLogin(self.__username, self.__password, self.__domain, self.__lmhash, self.__nthash,
self.__aesKey, kdcHost=self.__kdcHost)
else:
raise
logging.info('Querying %s for information about domain.' % self.__target)
# Print header
print((self.__outputFormat.format(*self.__header)))
print((' '.join(['-' * itemLen for itemLen in self.__colLen])))
# Building the search filter
if self.__all:
searchFilter = "(&(sAMAccountName=*)(objectCategory=user)"
else:
searchFilter = "(&(sAMAccountName=*)(mail=*)(!(UserAccountControl:1.2.840.113556.1.4.803:=%d))" % UF_ACCOUNTDISABLE
if self.__requestUser is not None:
searchFilter += '(sAMAccountName:=%s))' % self.__requestUser
else:
searchFilter += ')'
try:
logging.debug('Search Filter=%s' % searchFilter)
sc = ldap.SimplePagedResultsControl(size=100)
ldapConnection.search(searchFilter=searchFilter,
attributes=['sAMAccountName', 'pwdLastSet', 'mail', 'lastLogon'],
sizeLimit=0, searchControls = [sc], perRecordCallback=self.processRecord)
except ldap.LDAPSearchError:
raise
ldapConnection.close()
# Process command-line arguments.