| 32 | self.lmhash = "aad3b435b51404eeaad3b435b51404ee" |
| 33 | |
| 34 | def ldap_connection(self, tls_version): |
| 35 | user_withDomain = '%s\\%s' % (self.domain, self.username) |
| 36 | if tls_version is not None: |
| 37 | use_ssl = True |
| 38 | port = 636 |
| 39 | tls = ldap3.Tls(validate=ssl.CERT_NONE, version=tls_version) |
| 40 | else: |
| 41 | use_ssl = False |
| 42 | port = 389 |
| 43 | tls = None |
| 44 | ldap_server = ldap3.Server(self.address, get_info=ldap3.ALL, port=port, use_ssl=use_ssl, tls=tls) |
| 45 | if self.nthash != "": |
| 46 | ldap_session = ldap3.Connection(ldap_server, user=user_withDomain, password=self.lmhash + ":" + self.nthash, authentication=ldap3.NTLM, auto_bind=True) |
| 47 | else: |
| 48 | ldap_session = ldap3.Connection(ldap_server, user=user_withDomain, password=self.password, authentication=ldap3.NTLM, auto_bind=True) |
| 49 | return ldap_server, ldap_session |
| 50 | |
| 51 | # For ldap3 with tls mode(only for ldap3). |
| 52 | # Picked function from rbcd.py |