尝试使用以下 ldap 查询。
ldap_query = "(&(objectCategory=Person)(objectClass=user)(member:1.2.840.113556.1.4.1941:=CN=xx,CN=Users,DC=aa,DC=ss,DC=com))"
ldap_query = "(member:1.2.840.113556.1.4.1941:=CN=xx,CN=Users,DC=aa,DC=ss,DC=com)"
代码如下。
for hostname in <<domain.domain_controllers>>:
tls = ldap3.Tls(validate=ssl.CERT_NONE, version=ssl.PROTOCOL_TLS)
server = ldap3.Server(hostname, get_info=ldap3.ALL, mode=ldap3.IP_V4_PREFERRED, tls=tls, use_ssl=True)
with ldap3.Connection(server=server, authentication=ldap3.NTLM, auto_bind=True, password=xx, read_only=True, receive_timeout=30,user=yy) as ldap_connection:
search_parameters = {'search_base': 'DC=aa,DC=ss,DC=com', 'search_filter': ldap_query, 'attributes': ['*']}
ldap_connection.search(**search_parameters)
print(ldap_connection.entries)
它只是为所有 DC 打印 [],但用户有组和子组,如手动检查。