Impacket net.py
SAMR を使い、Windows の net user や net group に近いユーザー・グループの照会と変更を行います。
| 項目 | 内容 |
|---|---|
| 実装 | examples/net.py |
| カテゴリ | Active Directory / LDAP / アカウント管理 |
| 規模 | 589 行 |
| 配布 | setup.py の scripts=examples/*.py によりスクリプトとしてインストール |
CLI と入力
Section titled “CLI と入力”オプションの最新の定義は python examples/net.py -h で確認できます。
subcommand: user、computer、localgroup、group
| 引数 | 説明 |
|---|---|
target | [[domain/]username[:password]@] |
-debug | Turn DEBUG output ON |
-ts | Adds timestamp to every logging output |
-name | Display single user information. |
-create | Add new user account to domain/computer. |
-remove | Remove existing user account from domain/computer. |
-newPasswd | New password to set for creating account. |
-enable | Enables account. |
-disable | Disables account. |
-join | Add user account to specific group. |
-unjoin | Remove user account from specific group. |
-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 omitted it will use the domain part (FQDN) specified in the target parameter |
-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) |
詳細な処理フロー
Section titled “詳細な処理フロー”SMB transport で SAMR/LSA に接続し、subcommand から User、Computer、Group、Localgroup を選択します。object の RID/SID と handle を解決後、列挙、作成、削除、有効化、group join/unjoin 等を実行し、最後に handle と接続を閉じます。
仕組みの詳細
Section titled “仕組みの詳細”このコマンドは Windows の net に似た UI を提供しますが、内部では SAMR object
model を直接操作します。最初に server handle、domain SID、domain handle を
解決し、user/computer/group/localgroup subcommand に応じて RID と object
handle を開きます。名前から RID を得る処理と、RID から詳細情報を読む処理は
別の RPC call です。
User と Computer は account object の作成、削除、照会、password、UAC
変更を扱います。Group は domain group、Localgroup は alias を扱うため、
member 操作で使う SAMR API と SID の範囲が異なります。LsaTranslator は
表示と member 指定のために name/SID を相互変換し、SAMR の責務と分離されています。
RPC handle は親子関係を持ち、途中で失敗しても開いた user/group/domain handle を閉じる必要があります。列挙は一回で完了するとは限らず continuation status を通常系として処理します。新 subcommand を足す場合は、名前解決、handle 取得、操作、handle close の境界を既存 object class に合わせます。
主要な実装要素
Section titled “主要な実装要素”| シンボル | 位置 | 責務を追う入口 |
|---|---|---|
LsaTranslator | 49 | __init__()、Connect()、LookupName()、LookupSids() |
SamrObject | 76 | __init__() |
User | 141 | __init__()、Enumerate()、Query()、Create()、Remove()、SetUserAccountControl() |
Computer | 247 | __init__() |
Group | 254 | Enumerate()、Query()、Join()、UnJoin() |
Localgroup | 296 | Enumerate()、Query()、Join()、UnJoin() |
Net | 338 | __init__()、connect()、disconnect()、run() |
Impacket 内部
Section titled “Impacket 内部”| モジュール | 使用する主な名前 |
|---|---|
impacket | version |
impacket.examples | logger |
impacket.examples.utils | parse_target |
impacket.dcerpc.v5 | lsad, lsat, samr, transport |
impacket.smbconnection | SMBConnection |
出力・副作用・必要権限
Section titled “出力・副作用・必要権限”- 対象の状態を変更する操作があります。変更前に対象名や SID、パスを確認してください。
失敗経路と後始末
Section titled “失敗経路と後始末”- 失敗時は、名前解決、接続、認証、サービスの状態、権限のどこで止まったかを、プロトコルのステータスから切り分けます。
- 後始末に関係する実装として
_close_domain(),disconnect()があります。新しい早期 return や例外経路でも到達するか確認します。
実装を変更するとき
Section titled “実装を変更するとき”dcerpc.v5.samr / lsad / lsat / transport と SMBConnection を使用します。SamrObject が共通 handle 操作、LsaTranslator が SID/name 変換を担当します。
- 構文:
python -m py_compile examples/net.py - CLI:
python examples/net.py -h - 関連テスト:
tests/ImpactPacket/test_ethernet.py - 関連テスト:
tests/misc/test_dcerpc_v5_ndr.py

