badldap 0.6.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- badldap-0.6.0/LICENSE +97 -0
- badldap-0.6.0/MANIFEST.in +2 -0
- badldap-0.6.0/PKG-INFO +37 -0
- badldap-0.6.0/README.md +102 -0
- badldap-0.6.0/badldap/__init__.py +15 -0
- badldap-0.6.0/badldap/__main__.py +75 -0
- badldap-0.6.0/badldap/_version.py +8 -0
- badldap-0.6.0/badldap/bloodhound.py +779 -0
- badldap-0.6.0/badldap/client.py +1932 -0
- badldap-0.6.0/badldap/commons/__init__.py +0 -0
- badldap-0.6.0/badldap/commons/adexplorer.py +833 -0
- badldap-0.6.0/badldap/commons/authbuilder.py +18 -0
- badldap-0.6.0/badldap/commons/common.py +7 -0
- badldap-0.6.0/badldap/commons/exceptions.py +84 -0
- badldap-0.6.0/badldap/commons/factory.py +182 -0
- badldap-0.6.0/badldap/commons/ldif.py +127 -0
- badldap-0.6.0/badldap/commons/plugin.py +18 -0
- badldap-0.6.0/badldap/commons/target.py +134 -0
- badldap-0.6.0/badldap/commons/utils.py +124 -0
- badldap-0.6.0/badldap/connection.py +923 -0
- badldap-0.6.0/badldap/examples/__init__.py +6 -0
- badldap-0.6.0/badldap/examples/jsontest.py +130 -0
- badldap-0.6.0/badldap/examples/msldapbloodhound.py +19 -0
- badldap-0.6.0/badldap/examples/msldapclient.py +1815 -0
- badldap-0.6.0/badldap/examples/msldapcompdnslist.py +99 -0
- badldap-0.6.0/badldap/examples/utils/__init__.py +0 -0
- badldap-0.6.0/badldap/examples/utils/completers.py +60 -0
- badldap-0.6.0/badldap/external/__init__.py +0 -0
- badldap-0.6.0/badldap/external/aiocmd/__init__.py +0 -0
- badldap-0.6.0/badldap/external/aiocmd/aiocmd/__init__.py +0 -0
- badldap-0.6.0/badldap/external/aiocmd/aiocmd/aiocmd.py +159 -0
- badldap-0.6.0/badldap/external/aiocmd/aiocmd/nested_completer.py +97 -0
- badldap-0.6.0/badldap/external/aiocmd/setup.py +22 -0
- badldap-0.6.0/badldap/external/asciitree/__init__.py +0 -0
- badldap-0.6.0/badldap/external/asciitree/asciitree/__init__.py +83 -0
- badldap-0.6.0/badldap/external/asciitree/asciitree/drawing.py +101 -0
- badldap-0.6.0/badldap/external/asciitree/asciitree/traversal.py +43 -0
- badldap-0.6.0/badldap/external/asciitree/asciitree/util.py +4 -0
- badldap-0.6.0/badldap/external/asciitree/setup.py +24 -0
- badldap-0.6.0/badldap/external/bloodhoundpy/__init__.py +0 -0
- badldap-0.6.0/badldap/external/bloodhoundpy/acls.py +608 -0
- badldap-0.6.0/badldap/external/bloodhoundpy/lib/__init__.py +0 -0
- badldap-0.6.0/badldap/external/bloodhoundpy/lib/cstruct.py +1894 -0
- badldap-0.6.0/badldap/external/bloodhoundpy/resolver.py +141 -0
- badldap-0.6.0/badldap/external/bloodhoundpy/utils.py +55 -0
- badldap-0.6.0/badldap/ldap_objects/__init__.py +57 -0
- badldap-0.6.0/badldap/ldap_objects/adca.py +38 -0
- badldap-0.6.0/badldap/ldap_objects/adcertificatetemplate.py +517 -0
- badldap-0.6.0/badldap/ldap_objects/adcomp.py +334 -0
- badldap-0.6.0/badldap/ldap_objects/adcontainer.py +87 -0
- badldap-0.6.0/badldap/ldap_objects/adenrollmentservice.py +48 -0
- badldap-0.6.0/badldap/ldap_objects/adgmsa.py +176 -0
- badldap-0.6.0/badldap/ldap_objects/adgpo.py +108 -0
- badldap-0.6.0/badldap/ldap_objects/adgroup.py +136 -0
- badldap-0.6.0/badldap/ldap_objects/adinfo.py +213 -0
- badldap-0.6.0/badldap/ldap_objects/adou.py +128 -0
- badldap-0.6.0/badldap/ldap_objects/adschemaentry.py +95 -0
- badldap-0.6.0/badldap/ldap_objects/adsec.py +76 -0
- badldap-0.6.0/badldap/ldap_objects/adtrust.py +200 -0
- badldap-0.6.0/badldap/ldap_objects/aduser.py +375 -0
- badldap-0.6.0/badldap/ldap_objects/common.py +45 -0
- badldap-0.6.0/badldap/network/__init__.py +0 -0
- badldap-0.6.0/badldap/network/packetizer.py +41 -0
- badldap-0.6.0/badldap/protocol/__init__.py +0 -0
- badldap-0.6.0/badldap/protocol/constants.py +12 -0
- badldap-0.6.0/badldap/protocol/ldap_filter/__init__.py +2 -0
- badldap-0.6.0/badldap/protocol/ldap_filter/filter.py +492 -0
- badldap-0.6.0/badldap/protocol/ldap_filter/parser.py +1530 -0
- badldap-0.6.0/badldap/protocol/ldap_filter/soundex.py +20 -0
- badldap-0.6.0/badldap/protocol/messages.py +407 -0
- badldap-0.6.0/badldap/protocol/query.py +132 -0
- badldap-0.6.0/badldap/protocol/typeconversion.py +2015 -0
- badldap-0.6.0/badldap/protocol/utils.py +16 -0
- badldap-0.6.0/badldap/relay/__init__.py +0 -0
- badldap-0.6.0/badldap/relay/server.py +89 -0
- badldap-0.6.0/badldap/relay/serverconnection.py +148 -0
- badldap-0.6.0/badldap/wintypes/__init__.py +10 -0
- badldap-0.6.0/badldap/wintypes/asn1/__init__.py +7 -0
- badldap-0.6.0/badldap/wintypes/asn1/sdflagsrequest.py +20 -0
- badldap-0.6.0/badldap/wintypes/dnsp/__init__.py +0 -0
- badldap-0.6.0/badldap/wintypes/dnsp/structures/__init__.py +3 -0
- badldap-0.6.0/badldap/wintypes/dnsp/structures/dnsproperty.py +284 -0
- badldap-0.6.0/badldap/wintypes/dnsp/structures/dnsrecord.py +342 -0
- badldap-0.6.0/badldap/wintypes/dnsp/structures/misc.py +63 -0
- badldap-0.6.0/badldap/wintypes/encryptedlaps.py +85 -0
- badldap-0.6.0/badldap/wintypes/managedpassword.py +60 -0
- badldap-0.6.0/badldap.egg-info/PKG-INFO +37 -0
- badldap-0.6.0/badldap.egg-info/SOURCES.txt +94 -0
- badldap-0.6.0/badldap.egg-info/dependency_links.txt +1 -0
- badldap-0.6.0/badldap.egg-info/entry_points.txt +3 -0
- badldap-0.6.0/badldap.egg-info/not-zip-safe +1 -0
- badldap-0.6.0/badldap.egg-info/requires.txt +9 -0
- badldap-0.6.0/badldap.egg-info/top_level.txt +1 -0
- badldap-0.6.0/pyproject.toml +3 -0
- badldap-0.6.0/setup.cfg +4 -0
- badldap-0.6.0/setup.py +70 -0
badldap-0.6.0/LICENSE
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
This projects contains two other project written by a 3rd party.
|
|
2
|
+
All code is licensed under MIT.
|
|
3
|
+
|
|
4
|
+
License for badldap:
|
|
5
|
+
MIT License
|
|
6
|
+
|
|
7
|
+
Copyright (c) 2018 Tamas Jos (@skelsec)
|
|
8
|
+
|
|
9
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
10
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
11
|
+
in the Software without restriction, including without limitation the rights
|
|
12
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
13
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
14
|
+
furnished to do so, subject to the following conditions:
|
|
15
|
+
|
|
16
|
+
The above copyright notice and this permission notice shall be included in all
|
|
17
|
+
copies or substantial portions of the Software.
|
|
18
|
+
|
|
19
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
20
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
21
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
22
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
23
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
24
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
25
|
+
SOFTWARE.
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
License for "asciitree":
|
|
29
|
+
|
|
30
|
+
Copyright (c) 2015 Marc Brinkmann
|
|
31
|
+
|
|
32
|
+
Permission is hereby granted, free of charge, to any person obtaining a
|
|
33
|
+
copy of this software and associated documentation files (the "Software"),
|
|
34
|
+
to deal in the Software without restriction, including without limitation
|
|
35
|
+
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
36
|
+
and/or sell copies of the Software, and to permit persons to whom the
|
|
37
|
+
Software is furnished to do so, subject to the following conditions:
|
|
38
|
+
|
|
39
|
+
The above copyright notice and this permission notice shall be included in
|
|
40
|
+
all copies or substantial portions of the Software.
|
|
41
|
+
|
|
42
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
43
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
44
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
45
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
46
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
47
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
48
|
+
DEALINGS IN THE SOFTWARE.
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
License for "aiocmd":
|
|
52
|
+
|
|
53
|
+
MIT License
|
|
54
|
+
|
|
55
|
+
Copyright (c) 2019 Dor Green
|
|
56
|
+
|
|
57
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
58
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
59
|
+
in the Software without restriction, including without limitation the rights
|
|
60
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
61
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
62
|
+
furnished to do so, subject to the following conditions:
|
|
63
|
+
|
|
64
|
+
The above copyright notice and this permission notice shall be included in all
|
|
65
|
+
copies or substantial portions of the Software.
|
|
66
|
+
|
|
67
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
68
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
69
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
70
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
71
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
72
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
73
|
+
SOFTWARE.
|
|
74
|
+
|
|
75
|
+
License for "Bloodhound.py":
|
|
76
|
+
|
|
77
|
+
MIT License
|
|
78
|
+
|
|
79
|
+
Copyright (c) 2018 Fox-IT
|
|
80
|
+
|
|
81
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
82
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
83
|
+
in the Software without restriction, including without limitation the rights
|
|
84
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
85
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
86
|
+
furnished to do so, subject to the following conditions:
|
|
87
|
+
|
|
88
|
+
The above copyright notice and this permission notice shall be included in all
|
|
89
|
+
copies or substantial portions of the Software.
|
|
90
|
+
|
|
91
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
92
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
93
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
94
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
95
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
96
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
97
|
+
SOFTWARE.
|
badldap-0.6.0/PKG-INFO
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: badldap
|
|
3
|
+
Version: 0.6.0
|
|
4
|
+
Summary: Python library to play with MS LDAP
|
|
5
|
+
Home-page: https://github.com/CravateRouge/badldap
|
|
6
|
+
Author: Tamas Jos
|
|
7
|
+
Author-email: info@skelsecprojects.com
|
|
8
|
+
Maintainer: Baptiste Crépin
|
|
9
|
+
Maintainer-email: baptiste@cravaterouge.com
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.7
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Requires-Python: >=3.7
|
|
15
|
+
License-File: LICENSE
|
|
16
|
+
Requires-Dist: unicrypto>=0.0.10
|
|
17
|
+
Requires-Dist: badauth>=0.1.0
|
|
18
|
+
Requires-Dist: asysocks>=0.2.11
|
|
19
|
+
Requires-Dist: asn1crypto>=1.3.0
|
|
20
|
+
Requires-Dist: winacl>=0.1.8
|
|
21
|
+
Requires-Dist: prompt-toolkit>=3.0.2
|
|
22
|
+
Requires-Dist: tqdm
|
|
23
|
+
Requires-Dist: wcwidth
|
|
24
|
+
Requires-Dist: tabulate
|
|
25
|
+
Dynamic: author
|
|
26
|
+
Dynamic: author-email
|
|
27
|
+
Dynamic: classifier
|
|
28
|
+
Dynamic: description
|
|
29
|
+
Dynamic: home-page
|
|
30
|
+
Dynamic: license-file
|
|
31
|
+
Dynamic: maintainer
|
|
32
|
+
Dynamic: maintainer-email
|
|
33
|
+
Dynamic: requires-dist
|
|
34
|
+
Dynamic: requires-python
|
|
35
|
+
Dynamic: summary
|
|
36
|
+
|
|
37
|
+
Python library to play with MS LDAP
|
badldap-0.6.0/README.md
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# badldap
|
|
2
|
+
LDAP library for MS AD
|
|
3
|
+
|
|
4
|
+
# Documentation
|
|
5
|
+
[Awesome documentation here!](https://msldap.readthedocs.io/en/latest/)
|
|
6
|
+
|
|
7
|
+
# Features
|
|
8
|
+
- Comes with a built-in console LDAP client
|
|
9
|
+
- All parameters can be conrolled via a conveinent URL (see below)
|
|
10
|
+
- Supports integrated windows authentication (SSPI) both with NTLM and with KERBEROS
|
|
11
|
+
- Supports channel binding (for ntlm and kerberos not SSPI)
|
|
12
|
+
- Supports encryption (for NTLM/KERBEROS/SSPI)
|
|
13
|
+
- Supports LDAPS (TODO: actually verify certificate)
|
|
14
|
+
- Supports SOCKS5 proxy withot the need of extra proxifyer
|
|
15
|
+
- Minimal footprint
|
|
16
|
+
- A lot of pre-built queries for convenient information polling
|
|
17
|
+
- Easy to integrate to your project
|
|
18
|
+
- No testing suite
|
|
19
|
+
|
|
20
|
+
# Installation
|
|
21
|
+
Via GIT
|
|
22
|
+
`python3 setup.py install`
|
|
23
|
+
OR
|
|
24
|
+
`pip install badldap`
|
|
25
|
+
|
|
26
|
+
# Prerequisites
|
|
27
|
+
- `asn1crypto` module. Some LDAP queries incorporate ASN1 structures to be sent on top of the ASN1 transport XD
|
|
28
|
+
- `asysocks` module. To support socks proxying.
|
|
29
|
+
- `aiocmd` For the interactive client
|
|
30
|
+
- `asciitree` For plotting nice trees in the interactive client
|
|
31
|
+
|
|
32
|
+
# Usage
|
|
33
|
+
Please note that this is a library, and was not intended to be used as a command line program.
|
|
34
|
+
Whit this noted, the projects packs a fully functional LDAP interactive client. When installing the `badldap` module with `setup.py install` a new binary will appear called `badldap`.
|
|
35
|
+
|
|
36
|
+
# LDAP connection URL
|
|
37
|
+
The major change was needed in version 0.2.0 to unify different connection options as one single string, without the need for additional command line switches.
|
|
38
|
+
The new connection string is composed in the following manner:
|
|
39
|
+
`<protocol>+<auth_method>://<domain>\<username>:<password>@<ip>:<port>/?<param>=<value>&<param>=<value>&...`
|
|
40
|
+
|
|
41
|
+
WARNING: URL special chars (@, :, /, ?, &, =) must be URL encoded!
|
|
42
|
+
|
|
43
|
+
Detailed explanation with examples:
|
|
44
|
+
```
|
|
45
|
+
<protocol>+<auth>://<username>:<password>@<ip_or_host>:<port>/<tree>/?<param>=<value>
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
<protocol> sets the ldap protocol following values supported:
|
|
49
|
+
- ldap
|
|
50
|
+
- ldaps
|
|
51
|
+
- gc
|
|
52
|
+
- gc_ssl
|
|
53
|
+
|
|
54
|
+
<auth> can be omitted if plaintext authentication is to be performed (in that case it default to ntlm-password), otherwise:
|
|
55
|
+
- ntlm-password
|
|
56
|
+
- ntlm-nt
|
|
57
|
+
- kerberos-password (dc option param must be used)
|
|
58
|
+
- kerberos-rc4 / kerberos-nt (dc option param must be used)
|
|
59
|
+
- kerberos-aes (dc option param must be used)
|
|
60
|
+
- kerberos-keytab (dc option param must be used)
|
|
61
|
+
- kerberos-ccache (dc option param must be used)
|
|
62
|
+
- kerberos-pfx (dc option param must be used)
|
|
63
|
+
- kerberos-pem (dc option param must be used)
|
|
64
|
+
- kerberos-certstore (dc option param must be used, windows only)
|
|
65
|
+
- sspi-ntlm (windows only!)
|
|
66
|
+
- sspi-kerberos (windows only!)
|
|
67
|
+
- anonymous
|
|
68
|
+
- plain
|
|
69
|
+
- simple
|
|
70
|
+
- sicily (same format as ntlm-nt but using the SICILY authentication)
|
|
71
|
+
|
|
72
|
+
<tree>:
|
|
73
|
+
OPTIONAL. Specifies the root tree of all queries
|
|
74
|
+
|
|
75
|
+
<param> can be:
|
|
76
|
+
- timeout : connection timeout in seconds
|
|
77
|
+
- proxytype: currently only socks5 proxy is supported
|
|
78
|
+
- proxyhost: Ip or hostname of the proxy server
|
|
79
|
+
- proxyport: port of the proxy server
|
|
80
|
+
- proxytimeout: timeout ins ecodns for the proxy connection
|
|
81
|
+
- dc: the IP address of the domain controller, MUST be used for kerberos authentication
|
|
82
|
+
|
|
83
|
+
Examples:
|
|
84
|
+
ldap://10.10.10.2 (anonymous bind)
|
|
85
|
+
ldaps://test.corp (anonymous bind)
|
|
86
|
+
ldap+sspi-ntlm://test.corp
|
|
87
|
+
ldap+sspi-kerberos://test.corp
|
|
88
|
+
ldap://TEST\\victim:<password>@10.10.10.2 (defaults to SASL GSSAPI NTLM)
|
|
89
|
+
ldap+simple://TEST\\victim:<password>@10.10.10.2 (SASL SIMPLE auth)
|
|
90
|
+
ldap+plain://TEST\\victim:<password>@10.10.10.2 (SASL SIMPLE auth)
|
|
91
|
+
ldap+ntlm-password://TEST\\victim:<password>@10.10.10.2
|
|
92
|
+
ldap+ntlm-nt://TEST\\victim:<nthash>@10.10.10.2
|
|
93
|
+
ldap+kerberos-password://TEST\\victim:<password>@<hostname>/?dc=10.10.10.2
|
|
94
|
+
ldap+kerberos-rc4://TEST\\victim:<rc4key>@<hostname>/?dc=10.10.10.2
|
|
95
|
+
ldap+kerberos-aes://TEST\\victim:<aes>@<hostname>/?dc=10.10.10.2
|
|
96
|
+
ldap://TEST\\victim:password@10.10.10.2/DC=test,DC=corp/
|
|
97
|
+
ldap://TEST\\victim:password@10.10.10.2/DC=test,DC=corp/?timeout=99&proxytype=socks5&proxyhost=127.0.0.1&proxyport=1080&proxytimeout=44
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
# Kudos
|
|
101
|
+
Certificate services functionality was based on [certi](https://github.com/zer1t0/certi) created by @zer1t0
|
|
102
|
+
AC-RN
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
#
|
|
3
|
+
# Author:
|
|
4
|
+
# Tamas Jos (@skelsec)
|
|
5
|
+
#
|
|
6
|
+
|
|
7
|
+
import logging
|
|
8
|
+
|
|
9
|
+
logger = logging.getLogger(__name__)
|
|
10
|
+
handler = logging.StreamHandler()
|
|
11
|
+
formatter = logging.Formatter(
|
|
12
|
+
'%(asctime)s %(name)-12s %(levelname)-8s %(message)s')
|
|
13
|
+
handler.setFormatter(formatter)
|
|
14
|
+
logger.addHandler(handler)
|
|
15
|
+
logger.setLevel(logging.INFO)
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
#
|
|
3
|
+
# Author:
|
|
4
|
+
# Tamas Jos (@skelsec)
|
|
5
|
+
#
|
|
6
|
+
|
|
7
|
+
import logging
|
|
8
|
+
import csv
|
|
9
|
+
from badldap.connection import MSLDAPClientConnection
|
|
10
|
+
from badldap.commons.factory import LDAPConnectionFactory
|
|
11
|
+
from badldap.ldap_objects import MSADUser, MSADMachine
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def run():
|
|
15
|
+
import argparse
|
|
16
|
+
parser = argparse.ArgumentParser(description='MS LDAP library')
|
|
17
|
+
parser.add_argument('-v', '--verbose', action='count', default=0, help='Verbosity, can be stacked')
|
|
18
|
+
parser.add_argument('connection', help='Connection string in URL format.')
|
|
19
|
+
parser.add_argument('--tree', help='LDAP tree to perform the searches on')
|
|
20
|
+
|
|
21
|
+
subparsers = parser.add_subparsers(help = 'commands')
|
|
22
|
+
subparsers.required = True
|
|
23
|
+
subparsers.dest = 'command'
|
|
24
|
+
|
|
25
|
+
dump_group = subparsers.add_parser('dump', help='Dump all user objects to TSV file')
|
|
26
|
+
dump_group.add_argument('outfile', help='output file')
|
|
27
|
+
|
|
28
|
+
spn_group = subparsers.add_parser('spn', help='Dump all users with servicePrincipalName attribute set to TSV file')
|
|
29
|
+
spn_group.add_argument('outfile', help='output file')
|
|
30
|
+
|
|
31
|
+
dsa_group = subparsers.add_parser('dsa', help='Grab basic info about the AD')
|
|
32
|
+
|
|
33
|
+
args = parser.parse_args()
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
###### VERBOSITY
|
|
37
|
+
if args.verbose == 0:
|
|
38
|
+
logging.basicConfig(level=logging.INFO)
|
|
39
|
+
else:
|
|
40
|
+
logging.basicConfig(level=logging.DEBUG)
|
|
41
|
+
|
|
42
|
+
url_dec = LDAPConnectionFactory.from_url(args.connection)
|
|
43
|
+
creds = url_dec.get_credential()
|
|
44
|
+
target = url_dec.get_target()
|
|
45
|
+
print(str(creds))
|
|
46
|
+
print(str(target))
|
|
47
|
+
connection = MSLDAPClientConnection(creds, target)
|
|
48
|
+
|
|
49
|
+
if args.command == 'dsa':
|
|
50
|
+
print(connection.get_server_info())
|
|
51
|
+
|
|
52
|
+
elif args.command == 'dump':
|
|
53
|
+
connection.connect()
|
|
54
|
+
adinfo = connection.get_ad_info()
|
|
55
|
+
with open(args.outfile, 'w', newline='', encoding = 'utf8') as f:
|
|
56
|
+
writer = csv.writer(f, delimiter = '\t')
|
|
57
|
+
writer.writerow(MSADUser.TSV_ATTRS)
|
|
58
|
+
for user in connection.get_all_user_objects():
|
|
59
|
+
writer.writerow(user.get_row(MSADUser.TSV_ATTRS))
|
|
60
|
+
|
|
61
|
+
with open(args.outfile + '_comp', 'w', newline='', encoding = 'utf8') as f:
|
|
62
|
+
writer = csv.writer(f, delimiter = '\t')
|
|
63
|
+
writer.writerow(MSADMachine.TSV_ATTRS)
|
|
64
|
+
for comp in connection.get_all_machine_objects():
|
|
65
|
+
writer.writerow(comp.get_row(MSADMachine.TSV_ATTRS))
|
|
66
|
+
|
|
67
|
+
elif args.command == 'spn':
|
|
68
|
+
connection.connect()
|
|
69
|
+
adinfo, err = connection.get_ad_info()
|
|
70
|
+
with open(args.outfile, 'w', newline='', encoding = 'utf8') as f:
|
|
71
|
+
for user in connection.get_all_service_user_objects():
|
|
72
|
+
f.write(user.sAMAccountName + '\r\n')
|
|
73
|
+
|
|
74
|
+
if __name__ == '__main__':
|
|
75
|
+
run()
|