コンテンツにスキップ

カテゴリ目次へ戻る / コマンド全体目次へ戻る

SAMR を使い、Windows の net user や net group に近いユーザー・グループの照会と変更を行います。

項目内容
実装examples/net.py
カテゴリActive Directory / LDAP / アカウント管理
規模589 行
配布setup.py の scripts=examples/*.py によりスクリプトとしてインストール

オプションの最新の定義は python examples/net.py -h で確認できます。

subcommand: user、computer、localgroup、group

引数説明
target[[domain/]username[:password]@]
-debugTurn DEBUG output ON
-tsAdds timestamp to every logging output
-nameDisplay single user information.
-createAdd new user account to domain/computer.
-removeRemove existing user account from domain/computer.
-newPasswdNew password to set for creating account.
-enableEnables account.
-disableDisables account.
-joinAdd user account to specific group.
-unjoinRemove user account from specific group.
-hashesNTLM hashes, format is LMHASH:NTHASH
-no-passdon’t ask for password (useful for -k)
-kUse 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
-aesKeyAES key to use for Kerberos Authentication (128 or 256 bits)
-dc-ipIP Address of the domain controller. If omitted it will use the domain part (FQDN) specified in the target parameter
-target-ipIP 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
-portDestination port to connect to SMB Server(選択肢: 139, 445、既定値: 445)

SMB transport で SAMR/LSA に接続し、subcommand から User、Computer、Group、Localgroup を選択します。object の RID/SID と handle を解決後、列挙、作成、削除、有効化、group join/unjoin 等を実行し、最後に handle と接続を閉じます。

このコマンドは 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 に合わせます。

シンボル位置責務を追う入口
LsaTranslator49__init__()、Connect()、LookupName()、LookupSids()
SamrObject76__init__()
User141__init__()、Enumerate()、Query()、Create()、Remove()、SetUserAccountControl()
Computer247__init__()
Group254Enumerate()、Query()、Join()、UnJoin()
Localgroup296Enumerate()、Query()、Join()、UnJoin()
Net338__init__()、connect()、disconnect()、run()
モジュール使用する主な名前
impacketversion
impacket.exampleslogger
impacket.examples.utilsparse_target
impacket.dcerpc.v5lsad, lsat, samr, transport
impacket.smbconnectionSMBConnection
  • 対象の状態を変更する操作があります。変更前に対象名や SID、パスを確認してください。
  • 失敗時は、名前解決、接続、認証、サービスの状態、権限のどこで止まったかを、プロトコルのステータスから切り分けます。
  • 後始末に関係する実装として _close_domain(), disconnect() があります。新しい早期 return や例外経路でも到達するか確認します。

dcerpc.v5.samr / lsad / lsat / transport と SMBConnection を使用します。SamrObject が共通 handle 操作、LsaTranslator が SID/name 変換を担当します。