Impacket smbclient.py
SMB 共有、ディレクトリ、ファイル、ACL を操作する対話シェルです。入力ファイルによる一括実行にも対応します。
| 項目 | 内容 |
|---|---|
| 実装 | examples/smbclient.py |
| カテゴリ | SMB / MSRPC / NTLM |
| 規模 | 130 行 |
| 配布 | setup.py の scripts=examples/*.py によりスクリプトとしてインストール |
CLI と入力
Section titled “CLI と入力”オプションの最新の定義は python examples/smbclient.py -h で確認できます。
| 引数 | 説明 |
|---|---|
target | [[domain/]username[:password]@] |
-inputfile | input file with commands to execute in the mini shell |
-outputfile | Output file to log smbclient actions in |
-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) |
-dfs-follow | Automatically follow DFS links by creating new SMB connections to target servers. Disabled by default for OPSEC reasons (use dfs_mode command in shell to toggle at runtime) |
-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 |
-port | Destination port to connect to SMB Server(選択肢: 139, 445、既定値: 445) |
関連技術: SMB / NetBIOS、NTLM / SPNEGO。
詳細な処理フロー
Section titled “詳細な処理フロー”target parser と認証 option から SMBConnection を作り、dialect negotiation/login 後に MiniImpacketShell へ渡します。shell が share 列挙、cd/ls/get/put、mount、info 等を dispatch し、終了時に logoff します。
仕組みの詳細
Section titled “仕組みの詳細”CLI file は認証済み SMBConnection を作って MiniImpacketShell へ渡す
bootstrap です。接続時に dialect negotiation、NTLM/Kerberos login、server
capability の確定が行われ、以降の shell command は同じ session を再利用します。
DFS follow の有無は path が referral を返したときの接続先切替を変えます。
shell は share context と current directory を状態として持ちます。shares/
use/ls は tree・directory 操作、get/put は file read/write、ACL/info
系は追加 SMB request へ対応します。local filesystem を触る command と remote
SMB path を触る command を分離し、Windows path separator と wildcard を
server semantics に合わせて処理します。
batch input も interactive と同じ command dispatcher を通るため、prompt の有無 以外の動作を揃えられます。file handle、tree connect、secondary DFS connection は shell 終了時に閉じます。SessionError の status code を command 単位で表示し、 一つの file 不存在で session 全体を不要に破棄しないことが使い勝手に関わります。
主要な実装要素
Section titled “主要な実装要素”| シンボル | 位置 | 責務を追う入口 |
|---|---|---|
main() | 31 | モジュール関数 |
Impacket 内部
Section titled “Impacket 内部”| モジュール | 使用する主な名前 |
|---|---|
impacket.examples | logger |
impacket.examples.utils | parse_target |
impacket.examples.smbclient | MiniImpacketShell |
impacket | version |
impacket.smbconnection | SMBConnection |
出力・副作用・必要権限
Section titled “出力・副作用・必要権限”- 対象の状態を変更する操作があります。変更前に対象名や SID、パスを確認してください。
- オプションによりローカルファイルを作成または更新します。既存ファイルの扱いと秘密情報を含む出力の権限を確認してください。
失敗経路と後始末
Section titled “失敗経路と後始末”- 失敗時は、名前解決、接続、認証、サービスの状態、権限のどこで止まったかを、プロトコルのステータスから切り分けます。
実装を変更するとき
Section titled “実装を変更するとき”impacket.examples.smbclient.MiniImpacketShell と SMBConnection に依存します。CLI file は session bootstrap に限定され、command を追加する場所は共有 shell class 側です。
- 構文:
python -m py_compile examples/smbclient.py - CLI:
python examples/smbclient.py -h - このコマンド専用のテストは見つかりません。共有モジュールのテストと、必要に応じて隔離環境での動作確認を選びます。

