Impacket lookupsid.py
LSA に RID ごとの SID を問い合わせ、ドメイン SID とアカウント名の対応を列挙します。
| 項目 | 内容 |
|---|---|
| 実装 | examples/lookupsid.py |
| カテゴリ | Active Directory / LDAP / アカウント管理 |
| 規模 | 204 行 |
| 配布 | setup.py の scripts=examples/*.py によりスクリプトとしてインストール |
CLI と入力
Section titled “CLI と入力”オプションの最新の定義は python examples/lookupsid.py -h で確認できます。
| 引数 | 説明 |
|---|---|
target | [[domain/]username[:password]@] |
maxRid | max Rid to check (default 4000) |
-debug | Turn DEBUG output ON |
-ts | Adds timestamp to every logging output |
-target-ip | IP Address of the target machine. If omitted it will use whatever was specified as target. This is useful when target is the NetBIOS name and you cannot resolve it |
-port | Destination port to connect to SMB Server(選択肢: 139, 445、既定値: 445) |
-domain-sids | Enumerate Domain SIDs (will likely forward requests to the DC) |
-hashes | NTLM hashes, format is LMHASH:NTHASH |
-no-pass | don’t ask for password (useful when proxying through smbrelayx) |
-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 |
詳細な処理フロー
Section titled “詳細な処理フロー”SMB named pipe の LSARPC へ bind し、policy 情報から domain SID を取得します。その SID に RID を付加して lookup を繰り返し、解決できた SID、種類、名前を表示します。-domain-sids は発見した domain SID の出力に重点を置きます。
仕組みの詳細
Section titled “仕組みの詳細”LSA lookup は名前一覧を返す API ではないため、このコマンドは domain SID に
RID を順番に付けた候補 SID を作り、server に名前解決させます。最初に policy
handle から account domain SID を取得し、S-1-5-...-RID を一定数ずつ
LsarLookupSids に渡すことで user/group/alias を発見します。
多くの RID は存在しないので、STATUS_NONE_MAPPED や
STATUS_SOME_NOT_MAPPED は探索中の通常応答です。batch 内の一部だけ解決された
場合も、translated name 配列と domain list の index を正しく対応付ける必要が
あります。例外を一括して終了すると RID 空間の最初の穴で列挙が止まります。
結果は directory の完全な object 一覧ではありません。削除済み RID、lookup
権限、RID 上限、別 domain SID によって見え方が変わります。-domain-sids は
発見した domain 情報の収集に用途を寄せますが、推測した SID と server が
返した domain 名を区別して出力することが重要です。
主要な実装要素
Section titled “主要な実装要素”| シンボル | 位置 | 責務を追う入口 |
|---|---|---|
LSALookupSid | 36 | __init__()、dump() |
Impacket 内部
Section titled “Impacket 内部”| モジュール | 使用する主な名前 |
|---|---|
impacket.examples | logger |
impacket.examples.utils | parse_target |
impacket | version |
impacket.dcerpc.v5 | lsad, lsat, transport |
impacket.dcerpc.v5.samr | SID_NAME_USE |
impacket.dcerpc.v5.dtypes | MAXIMUM_ALLOWED |
impacket.dcerpc.v5.rpcrt | DCERPCException |
出力・副作用・必要権限
Section titled “出力・副作用・必要権限”- 照会や認証の試行が中心です。実行回数が多いと監査ログやアカウントロック、対象の負荷に影響します。
失敗経路と後始末
Section titled “失敗経路と後始末”- 失敗時は、名前解決、接続、認証、サービスの状態、権限のどこで止まったかを、プロトコルのステータスから切り分けます。
実装を変更するとき
Section titled “実装を変更するとき”dcerpc.v5.transport / lsad / lsat と共通 target parser を使用します。LSALookupSid.dump() が接続から列挙までを所有し、STATUS_SOME_NOT_MAPPED を通常の探索結果として扱う必要があります。
- 構文:
python -m py_compile examples/lookupsid.py - CLI:
python examples/lookupsid.py -h - 関連テスト:
tests/SMB_RPC/test_rpcrt.py - 関連テスト:
tests/dcerpc/test_samr.py - 関連テスト:
tests/misc/test_dcerpc_v5_ndr.py

