Impacket dcomexec.py
DCOM オブジェクトを使い、対象ホストでコマンドまたは半対話シェルを実行します。
| 項目 | 内容 |
|---|---|
| 実装 | examples/dcomexec.py |
| カテゴリ | リモート実行 / WMI / サービス |
| 規模 | 656 行 |
| 配布 | setup.py の scripts=examples/*.py によりスクリプトとしてインストール |
CLI と入力
Section titled “CLI と入力”オプションの最新の定義は python examples/dcomexec.py -h で確認できます。
| 引数 | 説明 |
|---|---|
target | [[domain/]username[:password]@] |
-share | share where the output will be grabbed from (default ADMIN$) |
-nooutput | whether or not to print the output (no SMB connection created) |
-ts | Adds timestamp to every logging output |
-debug | Turn DEBUG output ON |
-codec | 実行時の値を使って動的に生成される help |
-object | DCOM object to be used to execute the shell command (default=ShellWindows)(選択肢: ShellWindows, ShellBrowserWindow, MMC20) |
-com-version | DCOM version, format is MAJOR_VERSION:MINOR_VERSION e.g. 5.7 |
-shell-type | choose a command processor for the semi-interactive shell(選択肢: cmd, powershell、既定値: cmd) |
command | command to execute at the target. If empty it will launch a semi-interactive shell |
-silentcommand | does not execute cmd.exe to run given command (no output, cannot run dir/cd/etc.) |
-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 ommited it use the domain part (FQDN) specified in the target parameter |
-A | smbclient/mount.cifs-style authentication file. See smbclient man page’s -A option. |
-keytab | Read keys for SPN from keytab file |
詳細な処理フロー
Section titled “詳細な処理フロー”DCOM connection を確立し、選択 object の COM interface を取得します。command を dispatch method へ渡し、出力ありの場合は share 上の一時ファイルへ redirect、別の SMB connection で取得します。対話 shell は cmd.Cmd が local/remote command と upload/download を振り分けます。
仕組みの詳細
Section titled “仕組みの詳細”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 と区別して扱います。
主要な実装要素
Section titled “主要な実装要素”| シンボル | 位置 | 責務を追う入口 |
|---|---|---|
DCOMEXEC | 65 | __init__()、getInterface()、run() |
RemoteShell | 206 | __init__()、do_shell()、do_help()、do_lcd()、do_lget()、do_lput()、do_exit()、do_EOF()、emptyline()、do_cd()、default()、get_output() ほか |
RemoteShellMMC20 | 444 | execute_remote() |
AuthFileSyntaxError | 497 | __init__() |
load_smbclient_auth_file() | 511 | モジュール関数 |
Impacket 内部
Section titled “Impacket 内部”| モジュール | 使用する主な名前 |
|---|---|
impacket | version |
impacket.dcerpc.v5.dcom.oaut | DISPATCH_METHOD, DISPATCH_PROPERTYGET, DISPPARAMS, IDispatch, IID_IDispatch, VARENUM, VARIANT, string_to_bin |
impacket.dcerpc.v5.dcomrt | COMVERSION, 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.dtypes | NULL |
impacket.examples | logger |
impacket.examples.utils | parse_target |
impacket.smbconnection | SMB2_DIALECT_002, SMB2_DIALECT_21, SMBConnection, SMB_DIALECT |
impacket.krb5.keytab | Keytab |
外部パッケージ(直接使用)
Section titled “外部パッケージ(直接使用)”| import 名 | 配布パッケージ | 経路・宣言状態 |
|---|---|---|
six | six | 直接 import、宣言済み |
出力・副作用・必要権限
Section titled “出力・副作用・必要権限”- 対象の状態を変更する操作があります。変更前に対象名や SID、パスを確認してください。
- remote service、task、file、share、WMI/RPC resource などの一時資源を利用する経路があります。異常終了時の回収も動作契約です。
失敗経路と後始末
Section titled “失敗経路と後始末”- 失敗時は、名前解決、接続、認証、サービスの状態、権限のどこで止まったかを、プロトコルのステータスから切り分けます。
- 明示的な cleanup 名がなくても
finally相当の経路と protocol handle の close/delete を確認します。
実装を変更するとき
Section titled “実装を変更するとき”dcerpc.v5.dcomrt、DCOM OAUT structures、SMBConnection、keytab に依存します。DCOMEXEC が object activation、RemoteShell 系が command と出力を担当します。COM interface は必ず release/disconnect してください。
- 構文:
python -m py_compile examples/dcomexec.py - CLI:
python examples/dcomexec.py -h - 関連テスト:
tests/dcerpc/test_dcomrt.py

