Impacket GetADUsers.py
LDAP からユーザーのメールアドレス、パスワード更新日時、最終ログオンなどを取得します。既定では有効なユーザーが対象です。
| 項目 | 内容 |
|---|---|
| 実装 | examples/GetADUsers.py |
| カテゴリ | Active Directory / LDAP / アカウント管理 |
| 規模 | 195 行 |
| 配布 | setup.py の scripts=examples/*.py によりスクリプトとしてインストール |
CLI と入力
Section titled “CLI と入力”オプションの最新の定義は python examples/GetADUsers.py -h で確認できます。
| 引数 | 説明 |
|---|---|
target | domain[/username[:password]] |
-user | Requests data for specific user |
-all | Return all users, including those with no email addresses and disabled accounts. When used with -user it will return user’s info even if the account is disabled |
-ts | Adds timestamp to every logging output |
-debug | Turn DEBUG output ON |
-hashes | NTLM hashes, format is LMHASH:NTHASH |
-no-pass | don’t ask for password (useful for -k) |
-k | Use Kerberos authentication. Grabs credentials from ccache file (KRB5CCNAME) based on target parameters. If valid credentials cannot be found, it will use the ones specified in the command line |
-aesKey | AES key to use for Kerberos Authentication (128 or 256 bits) |
-dc-ip | IP Address of the domain controller. If ommited it use the domain part (FQDN) specified in the target parameter |
-dc-host | Hostname of the domain controller to use. If ommited, the domain part (FQDN) specified in the account parameter will be used |
-ldaps / -use-ldaps | Use LDAPS instead of LDAP |
詳細な処理フロー
Section titled “詳細な処理フロー”identity と認証方式を解決し、LDAP bind、ユーザー検索、レコード変換、表形式出力の順に進みます。processRecord() が FILETIME 系の値と account-control flag を処理します。
仕組みの詳細
Section titled “仕組みの詳細”このコマンドは user object の一覧を取得する LDAP reader であり、SAM database
を直接読むものではありません。run() は domain の naming context に対して
user filter を発行し、-user があれば単一の sAMAccountName、-all が
なければ通常利用される有効 account を中心に結果を制限します。LDAP server の
size limit を越える環境では、library の search/paging 動作も結果件数に影響します。
processRecord() は LDAP の生の属性列を表の一行へ変換します。たとえば
pwdLastSet と lastLogon は FILETIME、userAccountControl は bit field、
mail や description は複数値になり得ます。値が存在しないことと空文字列は
同一ではないため、schema 上 optional な属性を追加するときは、未返却・NULL・
複数値の三ケースを考慮します。
表示された lastLogon は問い合わせた DC が持つ値で、複製される
lastLogonTimestamp と意味が異なる場合があります。このコマンドの出力を
「domain 全体での厳密な最終ログオン」と解釈しないことが重要です。開発時は
検索 filter の意味と、表示ラベルが示す AD 属性の意味を一致させてください。
主要な実装要素
Section titled “主要な実装要素”| シンボル | 位置 | 責務を追う入口 |
|---|---|---|
GetADUsers | 38 | __init__()、getUnixTime()、processRecord()、run() |
Impacket 内部
Section titled “Impacket 内部”| モジュール | 使用する主な名前 |
|---|---|
impacket | version |
impacket.dcerpc.v5.samr | UF_ACCOUNTDISABLE |
impacket.examples | logger |
impacket.examples.utils | ldap_login, parse_identity |
impacket.ldap | ldap, ldapasn1 |
出力・副作用・必要権限
Section titled “出力・副作用・必要権限”- 照会や認証の試行が中心です。実行回数が多いと監査ログやアカウントロック、対象の負荷に影響します。
失敗経路と後始末
Section titled “失敗経路と後始末”- 失敗時は、名前解決、接続、認証、サービスの状態、権限のどこで止まったかを、プロトコルのステータスから切り分けます。
実装を変更するとき
Section titled “実装を変更するとき”impacket.ldap.ldap / ldapasn1、examples.utils.parse_identity / ldap_login、SAMR 定数を使用します。取得属性を追加する場合は匿名・権限制限環境で値が存在しないケースもテスト対象にします。
- 構文:
python -m py_compile examples/GetADUsers.py - CLI:
python examples/GetADUsers.py -h - 関連テスト:
tests/SMB_RPC/test_ldap.py - 関連テスト:
tests/dcerpc/test_samr.py

