Impacket samrdump.py
SAMR から対象ホストまたはドメインのユーザーとアカウント情報を取得し、表または CSV に出力します。
| 項目 | 内容 |
|---|---|
| 実装 | examples/samrdump.py |
| カテゴリ | Active Directory / LDAP / アカウント管理 |
| 規模 | 256 行 |
| 配布 | setup.py の scripts=examples/*.py によりスクリプトとしてインストール |
CLI と入力
Section titled “CLI と入力”オプションの最新の定義は python examples/samrdump.py -h で確認できます。
| 引数 | 説明 |
|---|---|
target | [[domain/]username[:password]@] |
-csv | Turn CSV output |
-ts | Adds timestamp to every logging output |
-debug | Turn DEBUG output ON |
-dc-ip | IP Address of the domain controller. If ommited it use the domain part (FQDN) specified in the target parameter |
-target-ip | IP Address of the target machine. If ommited 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) |
-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) |
詳細な処理フロー
Section titled “詳細な処理フロー”SAMR named pipe へ接続し、server/domain handle を開いて user をページング列挙します。各 RID の user information を追加取得し、最終ログオンやパスワード時刻を変換して出力します。
仕組みの詳細
Section titled “仕組みの詳細”SAMR の user enumeration は user 詳細を一度に返しません。dump() は最初に
server/domain handle を開き、EnumerateUsersInDomain で RID と account 名の
一覧を page 単位に受け取ります。その後、各 RID の user handle を開き、
QueryInformationUser で追加属性を取得します。
STATUS_MORE_ENTRIES は失敗ではなく continuation marker です。resume handle を
次の要求へ渡し、最後の page まで集約する必要があります。各 user の照会だけが
access denied になった場合でも、列挙済みの他 user を破棄せず、どの RID の詳細
が欠けたかを扱える構造が望まれます。
account 時刻は Windows time から変換され、CSV と表で同じ意味を持つ必要が あります。CSV は機械処理されるため、表示用の空欄、delimiter、文字 encoding を安易に変えないことが互換性上重要です。domain user と local SAM user は 接続先 domain handle によって決まります。
主要な実装要素
Section titled “主要な実装要素”| シンボル | 位置 | 責務を追う入口 |
|---|---|---|
ListUsersException | 36 | 構造体/定数定義 |
SAMRDump | 39 | __init__()、getUnixTime()、dump() |
Impacket 内部
Section titled “Impacket 内部”| モジュール | 使用する主な名前 |
|---|---|
impacket.examples | logger |
impacket.examples.utils | parse_target |
impacket | version |
impacket.nt_errors | STATUS_MORE_ENTRIES |
impacket.dcerpc.v5 | samr, transport |
impacket.dcerpc.v5.rpcrt | DCERPCException |
出力・副作用・必要権限
Section titled “出力・副作用・必要権限”- 照会や認証の試行が中心です。実行回数が多いと監査ログやアカウントロック、対象の負荷に影響します。
失敗経路と後始末
Section titled “失敗経路と後始末”- 失敗時は、名前解決、接続、認証、サービスの状態、権限のどこで止まったかを、プロトコルのステータスから切り分けます。
実装を変更するとき
Section titled “実装を変更するとき”dcerpc.v5.samr / transport、STATUS_MORE_ENTRIES に依存します。SAMRDump.dump() と getUnixTime() が主要実装です。ページング status をエラー終了とせず、取得済み record を保持してください。
- 構文:
python -m py_compile examples/samrdump.py - CLI:
python examples/samrdump.py -h - 関連テスト:
tests/SMB_RPC/test_rpcrt.py - 関連テスト:
tests/misc/test_dcerpc_v5_ndr.py

