Impacket machine_role.py
対象の Windows 端末がスタンドアロン、ドメインメンバー、Domain Controller のどれかを調べ、ドメインやフォレストの情報を表示します。
| 項目 | 内容 |
|---|---|
| 実装 | examples/machine_role.py |
| カテゴリ | Active Directory / LDAP / アカウント管理 |
| 規模 | 176 行 |
| 配布 | setup.py の scripts=examples/*.py によりスクリプトとしてインストール |
CLI と入力
Section titled “CLI と入力”オプションの最新の定義は python examples/machine_role.py -h で確認できます。
| 引数 | 説明 |
|---|---|
target | [[domain/]username[:password]@] |
-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 “詳細な処理フロー”SMB named pipe \pipe\lsarpc 上の MS-DSSP interface へ接続し、DsRolerGetPrimaryDomainInformation の応答を取得して、machine role、NetBIOS/DNS domain 名、forest 名、domain GUID を表示します。
仕組みの詳細
Section titled “仕組みの詳細”MS-DSSP の DsRolerGetPrimaryDomainInformation は、host が認識している
primary domain と machine role を一つの構造体で返します。このコマンドは
SMB 上の \pipe\lsarpc へ DCE/RPC 接続し、DSSP interface に bind して
basic domain information level を要求します。
応答の machine role enum は standalone workstation/server、member workstation/server、backup/primary DC を区別します。さらに flat NetBIOS domain 名、DNS domain 名、forest 名、domain GUID を取り出します。単なる OS product type 判定ではなく、domain membership と DC role の確認に使う 情報である点が重要です。
名前解決用の remoteName と実接続先 remoteHost は分離されています。
Kerberos 利用時は SPN に host 名が必要なため、-target-ip へ IP を指定しても
論理名を失ってはいけません。未知 enum や NULL domain field は将来版・
standalone host で起こり得るので、辞書の直接 index だけに依存しない実装が
望まれます。
主要な実装要素
Section titled “主要な実装要素”| シンボル | 位置 | 責務を追う入口 |
|---|---|---|
MachineRole | 34 | __init__()、print_info() |
Impacket 内部
Section titled “Impacket 内部”| モジュール | 使用する主な名前 |
|---|---|
impacket.examples | logger |
impacket.examples.utils | parse_target |
impacket | version |
impacket.uuid | bin_to_string |
impacket.dcerpc.v5 | dssp, transport |
出力・副作用・必要権限
Section titled “出力・副作用・必要権限”- 照会や認証の試行が中心です。実行回数が多いと監査ログやアカウントロック、対象の負荷に影響します。
失敗経路と後始末
Section titled “失敗経路と後始末”- 失敗時は、名前解決、接続、認証、サービスの状態、権限のどこで止まったかを、プロトコルのステータスから切り分けます。
実装を変更するとき
Section titled “実装を変更するとき”dcerpc.v5.transport と dcerpc.v5.dssp、共通 target/auth parser に依存します。MachineRole が request と表示を担当します。enum や flag を追加する場合は未知値でも表示が破綻しないようにしてください。
- 構文:
python -m py_compile examples/machine_role.py - CLI:
python examples/machine_role.py -h - 関連テスト:
tests/misc/test_dcerpc_v5_ndr.py

