コンテンツにスキップ

Impacket tstool.py

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

Terminal Services の RPC を使い、セッションやプロセスの列挙、切断、ログオフ、終了などを行います。

項目内容
実装examples/tstool.py
カテゴリリモート実行 / WMI / サービス
規模746 行
配布setup.py の scripts=examples/*.py によりスクリプトとしてインストール

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

subcommand: qwinsta、tasklist、taskkill、tscon、tsdiscon、logoff、shutdown、msg、shadow

引数説明
target[[domain/]username[:password]@]
-debugTurn DEBUG output ON
-tsAdds timestamp to every logging output
-vTurn VERBOSE output ON
-pidSpecifies process id (PID)
-nameSpecifies process name (ImageName). Internally it willexecute tasklist to retrieve PID by ImageName.
-sourceSource SessionId(必須)
-destDestination SessionId(必須)
-passwordDestination Session’s password
-sessionSessionId to disconnect(必須)
-logoffForces sessions to logoff.
-shutdownShuts down the system.
-rebootReboots after shutdown.
-poweroffPowers off after shutdown.
-titleTitle of the MessageBox [Optional]
-messageContents of the MessageBox(必須)
-controlRequest control of the session (default is view only)
-promptRequest user permission (default is silent)
-fileSave invitation to file(既定値: invite.msrcIncident)
-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 session と Terminal Services endpoint へ接続し、qwinsta、tasklist、taskkill、tscon、tsdiscon、logoff、shutdown、msg、shadow subcommand を TSHandler.run() が dispatch します。必要に応じて LSA で SID を user 名へ解決します。

Terminal Services は session と process を独自の RPC interface で公開します。 このコマンドは SMB/RPC transport を確立し、subcommand に応じて session 列挙、 process 列挙、session control、system action を異なる TSTS request へ dispatch します。TSHandler.run() は CLI action と protocol helper の対応表です。

qwinsta は session ID、state、station/user 情報を集め、tasklist は process record の SID を LSA lookup で名前へ補完します。taskkill、tscon、 tsdiscon、logoff は既存 ID/name を解決して状態を変えます。msg と shadow は可変長 text、permission/control flag、応答 code を追加で扱います。

列挙結果は session が同時に変化するため、取得後の ID が操作時には消えている ことがあります。RPC transport error、対象 session 不在、access denied、 利用者拒否などを区別します。shutdown/poweroff は全 session に影響するため、 引数 validation と確認可能なログは protocol call より前に置きます。

シンボル位置責務を追う入口
TSHandler59__init__()、connect()、run()、get_session_list()、enumerate_sessions_config()、enumerate_sessions_info()、do_qwinsta()、lookupSids()、sidToUser()、do_tasklist()、do_taskkill()、do_tscon() ほか
モジュール使用する主な名前
impacketLOG, version
impacket.exampleslogger
impacket.examples.utilsparse_target
impacket.smbconnectionSMBConnection
impacket.dcerpc.v5lsad, lsat, transport, tsts
impacket.dcerpc.v5.rpcrtDCERPCException, RPC_C_AUTHN_GSS_NEGOTIATE, RPC_C_AUTHN_LEVEL_PKT_PRIVACY
impacket.dcerpc.v5.dtypesMAXIMUM_ALLOWED
impacket.dcerpc.v5.tstsSHADOW_CONTROL_REQUEST, SHADOW_PERMISSION_REQUEST, SHADOW_REQUEST_RESPONSE
  • 対象の状態を変更する操作があります。変更前に対象名や SID、パスを確認してください。
  • 失敗時は、名前解決、接続、認証、サービスの状態、権限のどこで止まったかを、プロトコルのステータスから切り分けます。

dcerpc.v5.tsts、transport、lsad / lsat、SMBConnection に依存します。subcommand 固有引数の検証は RPC 呼び出し前に行い、session handle を action 後に閉じてください。