コンテンツにスキップ

カテゴリ目次へ戻る / コマンド全体目次へ戻る

LDAP からユーザーのメールアドレス、パスワード更新日時、最終ログオンなどを取得します。既定では有効なユーザーが対象です。

項目内容
実装examples/GetADUsers.py
カテゴリActive Directory / LDAP / アカウント管理
規模195 行
配布setup.py の scripts=examples/*.py によりスクリプトとしてインストール

オプションの最新の定義は python examples/GetADUsers.py -h で確認できます。

引数説明
targetdomain[/username[:password]]
-userRequests data for specific user
-allReturn 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
-tsAdds timestamp to every logging output
-debugTurn DEBUG output ON
-hashesNTLM hashes, format is LMHASH:NTHASH
-no-passdon’t ask for password (useful for -k)
-kUse 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
-aesKeyAES key to use for Kerberos Authentication (128 or 256 bits)
-dc-ipIP Address of the domain controller. If ommited it use the domain part (FQDN) specified in the target parameter
-dc-hostHostname of the domain controller to use. If ommited, the domain part (FQDN) specified in the account parameter will be used
-ldaps / -use-ldapsUse LDAPS instead of LDAP

identity と認証方式を解決し、LDAP bind、ユーザー検索、レコード変換、表形式出力の順に進みます。processRecord() が FILETIME 系の値と account-control flag を処理します。

このコマンドは 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 属性の意味を一致させてください。

シンボル位置責務を追う入口
GetADUsers38__init__()、getUnixTime()、processRecord()、run()
モジュール使用する主な名前
impacketversion
impacket.dcerpc.v5.samrUF_ACCOUNTDISABLE
impacket.exampleslogger
impacket.examples.utilsldap_login, parse_identity
impacket.ldapldap, ldapasn1
  • 照会や認証の試行が中心です。実行回数が多いと監査ログやアカウントロック、対象の負荷に影響します。
  • 失敗時は、名前解決、接続、認証、サービスの状態、権限のどこで止まったかを、プロトコルのステータスから切り分けます。

impacket.ldap.ldap / ldapasn1、examples.utils.parse_identity / ldap_login、SAMR 定数を使用します。取得属性を追加する場合は匿名・権限制限環境で値が存在しないケースもテスト対象にします。