Impacket mimikatz.py
mimikatz の RPC サーバーに接続し、対話入力またはファイルからコマンドを送ります。
| 項目 | 内容 |
|---|---|
| 実装 | examples/mimikatz.py |
| カテゴリ | リモート実行 / WMI / サービス |
| 規模 | 238 行 |
| 配布 | setup.py の scripts=examples/*.py によりスクリプトとしてインストール |
CLI と入力
Section titled “CLI と入力”オプションの最新の定義は python examples/mimikatz.py -h で確認できます。
| 引数 | 説明 |
|---|---|
target | [[domain/]username[:password]@] |
-file | input file with commands to execute in the mini shell |
-debug | Turn DEBUG output ON |
-ts | Adds timestamp to every logging output |
-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 omitted it will use the domain part (FQDN) specified in the target parameter |
-target-ip | IP 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 |
詳細な処理フロー
Section titled “詳細な処理フロー”target と資格情報から RPC transport を構成し、mimikatz interface へ bind します。MimikatzShell が入力を一行ずつ protocol request へ変換し、応答文字列を decode・表示します。-file では同じ onecmd() 経路へ batch 入力します。
仕組みの詳細
Section titled “仕組みの詳細”このコマンド自身が remote process へ code injection するのではなく、対象上で 既に利用可能な mimikatz RPC server の interface を client として呼びます。 target から DCE/RPC transport/string binding を作り、定義済み interface UUID へ bind した後、入力 command を NDR request structure に格納します。
MimikatzShell は local の cmd.Cmd loop と remote RPC request を分離します。
空行の再実行を抑止し、shell は local OS command、その他は remote mimikatz
command として onecmd()/default() から送信します。-file も各行を同じ
dispatch 経路に通すため、interactive と batch で protocol behavior がずれません。
応答は server が返す encoded buffer を文字列へ変換して表示します。RPC server 未導入、interface UUID 不一致、server command error、文字 encoding failure は 別の層です。新 command を client 側で解釈しすぎず、server へ渡す byte 列と local shell command の境界を明確に保ちます。
主要な実装要素
Section titled “主要な実装要素”| シンボル | 位置 | 責務を追う入口 |
|---|---|---|
MimikatzShell | 45 | __init__()、emptyline()、precmd()、default()、onecmd()、do_exit()、do_shell()、do_help() |
main() | 114 | モジュール関数 |
Impacket 内部
Section titled “Impacket 内部”| モジュール | 使用する主な名前 |
|---|---|
impacket | version |
impacket.dcerpc.v5 | epm, mimilib |
impacket.dcerpc.v5.rpcrt | RPC_C_AUTHN_GSS_NEGOTIATE, RPC_C_AUTHN_LEVEL_PKT_PRIVACY |
impacket.dcerpc.v5.transport | DCERPCTransportFactory |
impacket.examples | logger |
impacket.examples.utils | parse_target |
外部パッケージ(直接使用)
Section titled “外部パッケージ(直接使用)”| import 名 | 配布パッケージ | 経路・宣言状態 |
|---|---|---|
Cryptodome | pycryptodomex | 直接 import、宣言済み |
出力・副作用・必要権限
Section titled “出力・副作用・必要権限”- 対象の状態を変更する操作があります。変更前に対象名や SID、パスを確認してください。
失敗経路と後始末
Section titled “失敗経路と後始末”- 失敗時は、名前解決、接続、認証、サービスの状態、権限のどこで止まったかを、プロトコルのステータスから切り分けます。
実装を変更するとき
Section titled “実装を変更するとき”dcerpc.v5.transport と mimikatz RPC interface、共通 target parser に依存します。shell の local shell command と remote command を混同しないこと、server 未導入時の RPC error を保つことが重要です。
- 構文:
python -m py_compile examples/mimikatz.py - CLI:
python examples/mimikatz.py -h - 関連テスト:
tests/SMB_RPC/test_rpcrt.py - 関連テスト:
tests/misc/test_dcerpc_v5_ndr.py

