コンテンツにスキップ

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

SCMR で一時サービスを作り、コマンドの実行結果を SMB 共有経由で取得します。対象へ実行用バイナリを常設しません。

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

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

引数説明
target[[domain/]username[:password]@]
-shareshare where the output will be grabbed from (default C$)
-modemode to use (default SHARE, SERVER needs root!)(選択肢: SERVER, SHARE)
-tsadds timestamp to every logging output
-debugTurn DEBUG output ON
-codec実行時の値を使って動的に生成される help
-shell-typechoose a command processor for the semi-interactive shell(選択肢: cmd, powershell、既定値: cmd)
-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 ommited 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)
-service-nameThe name of theservice used to trigger the payload
-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)
-keytabRead keys for SPN from keytab file

SMB transport で Service Control Manager へ接続し、command を service の binPath として登録・開始します。出力は target から指定 share へ書かせ、client 側または local SMB server で回収します。SERVER/SHARE mode により出力経路が変わり、終了時に service と一時出力を削除します。

SMBEXEC は executable service binary を配置せず、SCMR service の binPath 自体に shell command を設定して起動します。service process として長時間動く ことを期待せず、command interpreter に処理させた後で一時 service entry を 削除します。PSEXEC との大きな違いは専用 named-pipe agent を使わない点です。

stdout/stderr は service から直接 RPC へ戻せないため、command line で file または UNC path へ redirect します。SHARE mode は対象上の share から回収し、 SERVER mode は client 側で一時 SMB server を立てて対象から書き込ませます。 この選択は inbound connection の要否、firewall、credential の露出範囲を変えます。

対話 shell は入力ごとに新しい service command を作り、出力 file の生成を polling して表示します。service start が timeout/error を返しても command が 実行済みの場合があるため、SCMR status と出力 file の存在を別に評価します。 一時 service、local server thread、出力 file の cleanup を確実に行います。

シンボル位置責務を追う入口
SMBServer62__init__()、cleanup_server()、run()、stop()
CMDEXEC116__init__()、run()
RemoteShell173__init__()、finish()、do_shell()、do_exit()、do_EOF()、emptyline()、do_cd()、do_CD()、default()、get_output()、execute_remote()、send_data()
モジュール使用する主な名前
impacket.exampleslogger
impacket.examples.utilsparse_target
impacketsmbserver, version
impacket.dcerpc.v5scmr, transport
impacket.krb5.keytabKeytab
  • 対象の状態を変更する操作があります。変更前に対象名や SID、パスを確認してください。
  • remote service、task、file、share、WMI/RPC resource などの一時資源を利用する経路があります。異常終了時の回収も動作契約です。
  • 失敗時は、名前解決、接続、認証、サービスの状態、権限のどこで止まったかを、プロトコルのステータスから切り分けます。
  • 後始末に関係する実装として cleanup_server(), stop(), finish() があります。新しい早期 return や例外経路でも到達するか確認します。

dcerpc.v5.scmr / transport、impacket.smbserver、keytab に依存します。CMDEXEC が接続、RemoteShell が command lifecycle、SMBServer が callback share を担当します。