本文整理汇总了Python中impacket.ldap.ldap.LDAPSearchError方法的典型用法代码示例。如果您正苦于以下问题:Python ldap.LDAPSearchError方法的具体用法?Python ldap.LDAPSearchError怎么用?Python ldap.LDAPSearchError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类impacket.ldap.ldap
的用法示例。
在下文中一共展示了ldap.LDAPSearchError方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _ldap_search
# 需要导入模块: from impacket.ldap import ldap [as 别名]
# 或者: from impacket.ldap.ldap import LDAPSearchError [as 别名]
def _ldap_search(self, search_filter, class_result, attributes=list()):
results = list()
paged_search_control = ldapasn1.SimplePagedResultsControl(criticality=True,
size=1000)
try:
search_results = self._ldap_connection.search(searchFilter=search_filter,
searchControls=[paged_search_control],
attributes=attributes)
except ldap.LDAPSearchError as e:
# If we got a "size exceeded" error, we get the partial results
if e.error == 4:
search_results = e.answers
else:
raise e
# TODO: Filter parenthesis in LDAP filter
except ldap.LDAPFilterSyntaxError as e:
return list()
for result in search_results:
if not isinstance(result, ldapasn1.SearchResultEntry):
continue
results.append(class_result(result['attributes']))
return results
示例2: execute_query
# 需要导入模块: from impacket.ldap import ldap [as 别名]
# 或者: from impacket.ldap.ldap import LDAPSearchError [as 别名]
def execute_query(self, searchFilter, attrs, parser):
sc = ldap.SimplePagedResultsControl(size=9999)
try:
self.con.search(searchBase=self.baseDN, searchFilter=searchFilter, attributes=attrs, searchControls=[sc], sizeLimit=0, timeLimit=50, perRecordCallback=parser)
except ldap.LDAPSearchError as e:
raise Exception("ldap_query error: {}".format(str(e)))
示例3: run
# 需要导入模块: from impacket.ldap import ldap [as 别名]
# 或者: from impacket.ldap.ldap import LDAPSearchError [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.