-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathldap匿名访问检测脚本.py
29 lines (25 loc) · 934 Bytes
/
ldap匿名访问检测脚本.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/bin/env python
# encoding: utf-8
# [url]http://ldap3.readthedocs.io/tutorial.html#accessing-an-ldap-server[/url]
import ldap3
from fileutils import FileUtils
import os
def verify(host):
try:
print host
server = ldap3.Server(host, get_info=ldap3.ALL, connect_timeout=30)
conn = ldap3.Connection(server, auto_bind=True)
#print server
if len(server.info.naming_contexts) > 0:
for _ in server.info.naming_contexts:
if conn.search(_, '(objectClass=inetOrgPerson)'):
naming_contexts = _.encode('utf8')
f = open('ldap.txt','a')
f.write(host + '\n')
f.close()
except Exception, e:
pass
#print e
if __name__ == '__main__':
for host in FileUtils.getLines('ldap.lst'):
verify(host)