MCPcopy Create free account
hub / github.com/XiaoliChan/LDAPShell / ldap_Shell

Class ldap_Shell

ldapsearch-test.py:12–56  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10from impacket import version
11
12class ldap_Shell:
13 def __init__(self, domain, baseDN, username, password, address, options):
14 self.domain = domain
15 self.baseDN = baseDN
16 self.username = username
17 self.password = password
18 self.lmhash = ''
19 self.nthash = ''
20 self.address = address
21 self.ldaps_flag = ''
22 self.gc_flag = ''
23
24 if options.ldaps == True:
25 self.ldaps_flag = True
26
27 if options.gc == True:
28 self.gc_flag = True
29
30 if options.hashes is not None:
31 self.lmhash, self.nthash = options.hashes.split(':')
32
33 def ldap_connect(self):
34 if self.ldaps_flag is True:
35 print("[+] Connecting ldap server over ssl (ldaps)")
36 ldapConnection = ldap.LDAPConnection('ldaps://%s' % self.domain , self.baseDN, self.address)
37 elif self.gc_flag is True:
38 print("[+] Connecting ldap server over global catalog (GC)")
39 ldapConnection = ldap.LDAPConnection('gc://%s' % self.domain, self.baseDN, self.address)
40 else:
41 print("[+] Connecting ldap server without any special")
42 ldapConnection = ldap.LDAPConnection('ldap://%s' % self.domain, self.baseDN, self.address)
43
44 ldapConnection.login(self.username, self.password, self.domain, self.lmhash, self.nthash)
45
46 return ldapConnection
47
48 def dummySearch(self, ldapConnection):
49 # Let's do a search just to be sure it's working
50 searchFilter = "(&(objectclass=person)(sAMAccountName=xiaoli))"
51
52 resp = ldapConnection.search(
53 searchFilter=searchFilter
54 )
55 for item in resp:
56 print(item.prettyPrint())
57
58if __name__ == '__main__':
59 logger.init()

Callers 1

ldapsearch-test.pyFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected