Impacket GetADComputers.py
LDAP から computer account の OS や最終ログオン時刻などを取得します。必要に応じて DNS で IP アドレスも補います。
| 項目 | 内容 |
|---|---|
| 実装 | examples/GetADComputers.py |
| カテゴリ | Active Directory / LDAP / アカウント管理 |
| 規模 | 234 行 |
| 配布 | setup.py の scripts=examples/*.py によりスクリプトとしてインストール |
CLI と入力
Section titled “CLI と入力”オプションの最新の定義は python examples/GetADComputers.py -h で確認できます。
| 引数 | 説明 |
|---|---|
target | domain[/username[:password]] |
-user | Requests data for specific user |
-ts | Adds timestamp to every logging output |
-debug | Turn DEBUG output ON |
-resolveIP | Tries to resolve the IP address of computer objects, by performing the nslookup on the DC. |
-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/LDAPS へ bind し、computer object を検索します。processRecord() が LDAP 属性と Windows timestamp を表示用に変換し、-resolveIP 時は DNS を照会します。-user は特定アカウントへの絞り込みです。
仕組みの詳細
Section titled “仕組みの詳細”検索対象は LDAP の computer object です。run() は domain から base DN を
組み立て、指定 user がある場合は sAMAccountName で絞り込み、そうでなければ
computer account をまとめて取得します。返却される属性は常に揃うわけでは
ないため、processRecord() は OS 情報、DNS host 名、UAC、時刻属性を独立に
扱い、欠けた値を空欄として表示します。
Active Directory の時刻属性は Unix timestamp ではなく、1601 年起点の
Windows FILETIME です。変換処理は 0 や「未設定」を通常の日付として表示しない
ようにする役割も持ちます。account disabled の判定は文字列ではなく
userAccountControl の bit flag を使います。このため、属性追加時も LDAP
から届く byte/string 表現を表示層へ直接渡さず、型と特殊値を正規化します。
-resolveIP は LDAP の dNSHostName を DC 指定の resolver で A record へ
解決する補助処理です。LDAP レコード取得の成功と DNS 解決の成功は別なので、
DNS に登録がない computer を検索結果から落としてはいけません。検索 filter、
属性変換、DNS 補完という三つの段階を分けて保守するのがこのコマンドの要点です。
主要な実装要素
Section titled “主要な実装要素”| シンボル | 位置 | 責務を追う入口 |
|---|---|---|
GetADComputers | 42 | __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 “外部パッケージ(直接使用)”| import 名 | 配布パッケージ | 経路・宣言状態 |
|---|---|---|
dns | dnspython | 直接 import、直接依存には未宣言 |
出力・副作用・必要権限
Section titled “出力・副作用・必要権限”- 照会や認証の試行が中心です。実行回数が多いと監査ログやアカウントロック、対象の負荷に影響します。
失敗経路と後始末
Section titled “失敗経路と後始末”- 失敗時は、名前解決、接続、認証、サービスの状態、権限のどこで止まったかを、プロトコルのステータスから切り分けます。
実装を変更するとき
Section titled “実装を変更するとき”impacket.ldap.ldap / ldapasn1、SAMR の UF_ACCOUNTDISABLE、examples.utils.ldap_login、dns.resolver に依存します。検索 filter や属性を変える場合は run() と processRecord() を同時に更新し、欠落属性を許容してください。
- 構文:
python -m py_compile examples/GetADComputers.py - CLI:
python examples/GetADComputers.py -h - 関連テスト:
tests/SMB_RPC/test_ldap.py - 関連テスト:
tests/dcerpc/test_samr.py

