
짜증 없는 LDAP 쿼리
이 도구는 ldapsearch 및 일반적인 AD 상호 작용에서 겪었던 많은 문제를 해결하기 위해 작성되었습니다. 특히, 이 도구는 제가 경험했던 다음과 같은 문제들을 해결합니다:
AD에서 천 개 이상의 결과를 반환할 수 없는 문제. 이 도구는 LDAP 레코드 페이징을 지원하고 다른 AD 버그를 우회하여 임의의 수의 레코드를 검색할 수 있게 해줍니다.
직관적인 방식으로 NTLM 자격 증명을 사용하여 인증할 수 없는 문제. NETBIOS 도메인 이름, 사용자 이름, 비밀번호를 제공하여 Windows DC에 인증할 수 있습니다.
반환되는 레코드 수, 반환 속도, 한 번에 가져오는 레코드 수를 정밀하게 제어할 수 없는 문제. 이 도구는 각 페이징 호출 사이에 지연을 추가하는 기능을 포함하여 이러한 모든 항목을 제어할 수 있게 해줍니다. 또한, 라운드로빈 방식으로 쿼리하기 위해 여러 DC를 지정할 수 있습니다.
결과를 쉽게 파악할 수 있는 형태로 반환할 수 없는 문제. 이 도구는 현재 세 가지 형식을 지원합니다:
원하는 속성만 반환할 수 없는 문제. 이 도구를 사용하면 모든 속성을 반환하거나 원하는 속성만 반환할 수 있습니다.
자주 사용하는 쿼리를 사전 정의된 목록으로 저장할 수 없는 문제.
git clone ...
pip install -r requirements.txt
# python3 ldapper.py
usage: ldapper.py [-h] --domain DOMAIN --user USER --password PASSWORD
--server SERVER [--basedn BASEDN] --search SEARCH
[--maxrecords MAXRECORDS] [--pagesize PAGESIZE]
[--delay DELAY] [--format {plain,json,json_tiny}]
[--encryption {1,2,3}]
[--advanced [ADVANCED [ADVANCED ...]]] [--outfile OUTFILE]
[--engine {ldap3,impacket}]
[attribute [attribute ...]]
AD LDAP Command Line Searching that doesn't suck.
positional arguments:
attribute Attributes to return (Defaults to all for custom query. For canned queries, pass a "*" to get all attributes instead of default ones.)
optional arguments:
-h, --help show this help message and exit
--domain DOMAIN, -D DOMAIN
Domain
--user USER, -U USER Username
--password PASSWORD, -P PASSWORD
Password or LM:NTLM formatted hash
--server SERVER, -S SERVER
DC IP or resolvable name
--basedn BASEDN, -b BASEDN
Base DN should typically be "dc=", followed by the long domain name with periods replaced with ",dc=". Will attempt to derive it if not provided from the LDAP server.
--search SEARCH, -s SEARCH
LDAP search string or number indicating custom search from "Custom Searches" list. Use "-" for read from stdin.
--maxrecords MAXRECORDS, -m MAXRECORDS
Maximum records to return (Default is 100), 0 means all.
--pagesize PAGESIZE, -p PAGESIZE
Number of records to return on each pull (Default is 10). Should be <= max records.
--delay DELAY, -d DELAY
Millisecond delay between paging requests (Defaults to 0).
--format {plain,json,json_tiny}, -f {plain,json,json_tiny}
Format of output (Default is "plain"), can be: plain, json. json_tiny
--encryption {1,2,3}, -n {1,2,3}
3) Connect to 636 TLS (Default); 2) Connect 389 No TLS, but attempt STARTTLS and fallback as needed (not available with impacket); 1) Connect to 389, Force Plaintext
--advanced [ADVANCED [ADVANCED ...]], -a [ADVANCED [ADVANCED ...]]
Advanced way to pass options for canned searches that prompt for additional input (for multiple prompts, pass argument in the order of prompting)
--outfile OUTFILE, -o OUTFILE
Output File (if specified output will be routed here instead of stdout [Can prevent encoding errors in Windows])
--engine {ldap3,impacket}, -e {ldap3,impacket}
Pick the engine to use (Defaults to "ldap3"). SEE OPSEC NOTES!
Custom Searches:
1) Get all users
1.1) Get specific user (You will be prompted for the username)
2) Get all groups (and their members)
2.1) Get specific group (You will be prompted for the group name)
3) Get all printers
4) Get all computers
4.1) Get specific computer (You will be prompted for the computer name)
5) Get Domain/Enterprise Administrators
6) Get Domain Trusts
7) Search for Unconstrained SPN Delegations (Potential Priv-Esc)
8) Search for Accounts where PreAuth is not required. (ASREPROAST)
9) Search for User SPNs (KERBEROAST)
9.1) Search for specific User SPN (You will be prompted for the User Principle Name)
10) Show All LAPS LA Passwords (that you can see)
10.1) Search for specific Workstation LAPS Password (You will be prompted for the Workstation Name)
*11) Search for common plaintext password attributes (UserPassword, UnixUserPassword, unicodePwd, and msSFU30Password)
12) Show All Quest Two-Factor Seeds (if you have access)
13) Oracle "orclCommonAttribute" SSO password hash
*14) Oracle "userPassword" SSO password hash
15) Get SCCM Servers
16) Search for Accounts where password is not required. (PasswordNotRequired)
Starred items have never been tested in an environment where they could be verified, so please let me know if they work.
다음 예제에서는 다음을 가정합니다:
NETBIOS NAME: EMP
FULL DOMAIN NAME: EXAMPLE.LOCAL
DC IPs: 10.0.0.2, 10.0.0.3
USERNAME: bob
PASSWORD: password
모든 레코드를 검색하고 cn 속성만 반환합니다:
python ldapper.py -D 'EMP' -U 'bob' -P 'password' -S '10.0.0.2,10.0.0.3' -m 0 -s '(cn=*)' cn
특정 사용자에 대한 세부 정보를 검색합니다 (사용자 이름을 묻는 메시지가 표시됩니다):
python ldapper.py -D 'EMP' -U 'bob' -P 'password' -S '10.0.0.2,10.0.0.3' -m 0 -s '1.1'
특정 사용자에 대한 세부 정보를 검색합니다 (프롬프트가 표시되지 않도록 사용자 이름을 전달합니다):
python ldapper.py -D 'EMP' -U 'bob' -P 'password' -S '10.0.0.2,10.0.0.3' -m 0 -s '1.1' -a 'alice'
상위 100개 사용자 Kerberos SPN을 한 번에 최대 5개씩, 각 페이지 요청 사이에 2초 간격으로 간결한 JSON 형식으로 검색합니다:
python ldapper.py -D 'EMP' -U 'bob' -P 'password' -S '10.0.0.2,10.0.0.3' -m 100 -p 5 -d 2000 -f json_tiny -s '(&(objectcategory=user)(serviceprincipalname=*))' serviceprincipalname userprincipalname
프린터의 모든 레코드를 수동으로 검색하고 모든 관련 속성을 표시합니다:
python ldapper.py -D 'EMP' -U 'bob' -P 'password' -S '10.0.0.2,10.0.0.3' -m 0 -s '(objectClass=printQueue)'
제한 없는 SPN 위임을 쉽게 검색합니다:
python ldapper.py -D 'EMP' -U 'bob' -P 'password' -S '10.0.0.2,10.0.0.3' -m 0 -s 4
Impacket 엔진을 사용하면서 baseDN을 제공하지 않으면, 도구는 baseDN을 도출하기 위해 도메인 컨트롤러에 SMB 인증 및 연결을 시도하여 도메인의 NETBIOS 이름을 가져옵니다. 이 동작은 매우 민감한 환경에서 탐지로 이어질 수 있습니다. 이러한 환경에서는 Impacket을 사용하지 않거나 항상 baseDN을 지정하십시오.
Impacket은 전체 LDAPS 연결 또는 완전히 암호화되지 않은 연결 중 하나를 수행합니다. 현재 STARTTLS를 사용할 수 없으므로, 일반 텍스트 LDAP 연결이 탐지될 수 있다면 전체 TLS 연결만 시도하거나 Impacket 엔진을 사용하지 마십시오.
Impacket은 레코드를 가져오는 속도를 세밀하게 제어할 수 없습니다. 따라서 "--delay" 옵션은 부분적으로만 구현되어 있습니다. 레코드 가져오기 지연이 중요한 경우 Impacket 엔진을 사용하지 마십시오.
Kerberoast: https://adsecurity.org/?p=2293
ASREPRoast: http://www.harmj0y.net/blog/activedirectory/roasting-as-reps/
제한 없는 위임 남용: http://www.harmj0y.net/blog/activedirectory/the-most-dangerous-user-right-you-probably-have-never-heard-of/
Oracle 관련 참고 자료: https://blogs.oracle.com/mwilcox/entry/clarifying_ovd-ad_eus_password and http://onlineappsdba.com/index.php/2014/03/03/what-hashing-algorithm-oid-uses-to-store-user-password-ssha-or-md5/
Qwest/Defender/Oneidentity 2차 인증 토큰 데이터: http://support-public.cfm.quest.com/43565_Defender_5.9_AdminGuide.pdf
일반적인 일반 텍스트 비밀번호: https://www.blackhillsinfosec.com/domain-goodness-learned-love-ad-explorer/
LDAP3가 항상 작동하는 것은 아니므로(Impacket도 마찬가지) LDAP3의 대안으로 Impacket을 추가했습니다.
이 기능이 실제로 필요하지 않고 Impacket에도 실제로 존재하지 않으므로 다중 LDAP 서버 선택 기능을 제거했습니다.
전체를 리팩토링했습니다.
SCCM 검색 기능을 추가했습니다.
출력 파일 옵션을 추가했습니다.
몇 가지 출력 형식 관련 문제를 수정했습니다.
stdin에서 LDAP 쿼리를 입력받는 기능을 추가했습니다.
사용자가 이미 괄호로 감싸지 않은 경우 쿼리를 자동으로 괄호로 감쌉니다.
Python 2 지원 버그를 수정했습니다.
사용 중인 일반적인 검색 열거 항목이 있다면 알려주세요. 목록에 추가하겠습니다.
...
Shelby Spencer(shellster)가 작성했습니다. 버그나 기능 요청이 있으면 연락 주세요.