コンテンツにスキップ

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

DCOM オブジェクトを使い、対象ホストでコマンドまたは半対話シェルを実行します。

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

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

引数説明
target[[domain/]username[:password]@]
-shareshare where the output will be grabbed from (default ADMIN$)
-nooutputwhether or not to print the output (no SMB connection created)
-tsAdds timestamp to every logging output
-debugTurn DEBUG output ON
-codec実行時の値を使って動的に生成される help
-objectDCOM object to be used to execute the shell command (default=ShellWindows)(選択肢: ShellWindows, ShellBrowserWindow, MMC20)
-com-versionDCOM version, format is MAJOR_VERSION:MINOR_VERSION e.g. 5.7
-shell-typechoose a command processor for the semi-interactive shell(選択肢: cmd, powershell、既定値: cmd)
commandcommand to execute at the target. If empty it will launch a semi-interactive shell
-silentcommanddoes not execute cmd.exe to run given command (no output, cannot run dir/cd/etc.)
-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 ommited it use the domain part (FQDN) specified in the target parameter
-Asmbclient/mount.cifs-style authentication file. See smbclient man page’s -A option.
-keytabRead keys for SPN from keytab file

DCOM connection を確立し、選択 object の COM interface を取得します。command を dispatch method へ渡し、出力ありの場合は share 上の一時ファイルへ redirect、別の SMB connection で取得します。対話 shell は cmd.Cmd が local/remote command と upload/download を振り分けます。

DCOM は remote COM object を activation し、その interface method を RPC として 呼び出す仕組みです。このコマンドは ShellWindows、ShellBrowserWindow、 MMC20.Application のいずれかを作り、IDispatch を介して shell execution に 到達します。object ごとに property/method chain が異なるため、getInterface() と RemoteShellMMC20 が差を吸収します。

command の return value だけでは stdout を得られないため、通常は remote shell に share 上の一時 file へ出力させ、別の SMBConnection で読み戻します。 対話 shell は current directory を command prefix として保持し、lget/lput だけは SMB file transfer、その他の入力は DCOM process execution へ送ります。 -nooutput では SMB 接続が不要になり、実行確認の意味も変わります。

COM object は interface reference と DCOM connection の lifecycle を持ちます。 method call が失敗しても interface release と disconnect を行い、一時 file の polling が無限化しないようにします。COM version、object availability、 desktop/session isolation による違いは credential error と区別して扱います。

シンボル位置責務を追う入口
DCOMEXEC65__init__()、getInterface()、run()
RemoteShell206__init__()、do_shell()、do_help()、do_lcd()、do_lget()、do_lput()、do_exit()、do_EOF()、emptyline()、do_cd()、default()、get_output() ほか
RemoteShellMMC20444execute_remote()
AuthFileSyntaxError497__init__()
load_smbclient_auth_file()511モジュール関数
モジュール使用する主な名前
impacketversion
impacket.dcerpc.v5.dcom.oautDISPATCH_METHOD, DISPATCH_PROPERTYGET, DISPPARAMS, IDispatch, IID_IDispatch, VARENUM, VARIANT, string_to_bin
impacket.dcerpc.v5.dcomrtCOMVERSION, DCOMConnection, FLAGS_OBJREF_CUSTOM, FLAGS_OBJREF_EXTENDED, FLAGS_OBJREF_HANDLER, FLAGS_OBJREF_STANDARD, INTERFACE, IRemUnknown2, OBJREF, OBJREF_CUSTOM, OBJREF_EXTENDED, OBJREF_HANDLER, OBJREF_STANDARD
impacket.dcerpc.v5.dtypesNULL
impacket.exampleslogger
impacket.examples.utilsparse_target
impacket.smbconnectionSMB2_DIALECT_002, SMB2_DIALECT_21, SMBConnection, SMB_DIALECT
impacket.krb5.keytabKeytab
import 名配布パッケージ経路・宣言状態
sixsix直接 import、宣言済み
  • 対象の状態を変更する操作があります。変更前に対象名や SID、パスを確認してください。
  • remote service、task、file、share、WMI/RPC resource などの一時資源を利用する経路があります。異常終了時の回収も動作契約です。
  • 失敗時は、名前解決、接続、認証、サービスの状態、権限のどこで止まったかを、プロトコルのステータスから切り分けます。
  • 明示的な cleanup 名がなくても finally 相当の経路と protocol handle の close/delete を確認します。

dcerpc.v5.dcomrt、DCOM OAUT structures、SMBConnection、keytab に依存します。DCOMEXEC が object activation、RemoteShell 系が command と出力を担当します。COM interface は必ず release/disconnect してください。