コンテンツにスキップ

Impacket smbclient.py

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

SMB 共有、ディレクトリ、ファイル、ACL を操作する対話シェルです。入力ファイルによる一括実行にも対応します。

項目内容
実装examples/smbclient.py
カテゴリSMB / MSRPC / NTLM
規模130 行
配布setup.py の scripts=examples/*.py によりスクリプトとしてインストール

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

引数説明
target[[domain/]username[:password]@]
-inputfileinput file with commands to execute in the mini shell
-outputfileOutput file to log smbclient actions in
-debugTurn DEBUG output ON
-tsAdds timestamp to every logging output
-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)
-dfs-followAutomatically 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-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 omitted 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)

関連技術: SMB / NetBIOS、NTLM / SPNEGO。

target parser と認証 option から SMBConnection を作り、dialect negotiation/login 後に MiniImpacketShell へ渡します。shell が share 列挙、cd/ls/get/put、mount、info 等を dispatch し、終了時に logoff します。

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 全体を不要に破棄しないことが使い勝手に関わります。

シンボル位置責務を追う入口
main()31モジュール関数
モジュール使用する主な名前
impacket.exampleslogger
impacket.examples.utilsparse_target
impacket.examples.smbclientMiniImpacketShell
impacketversion
impacket.smbconnectionSMBConnection
  • 対象の状態を変更する操作があります。変更前に対象名や SID、パスを確認してください。
  • オプションによりローカルファイルを作成または更新します。既存ファイルの扱いと秘密情報を含む出力の権限を確認してください。
  • 失敗時は、名前解決、接続、認証、サービスの状態、権限のどこで止まったかを、プロトコルのステータスから切り分けます。

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
  • このコマンド専用のテストは見つかりません。共有モジュールのテストと、必要に応じて隔離環境での動作確認を選びます。