コンテンツにスキップ

Impacket filetime.py

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

SMB 上のファイルやディレクトリについて、作成・アクセス・更新・変更の時刻を照会・変更します。

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

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

subcommand: FILETIME_READ_ACTION、FILETIME_WRITE_ACTION

引数説明
target[[domain/]username[:password]@]
shareThe share in which the desired file / directory to query or modify resides.
pathThe path of the desired file / directory whose timestamps we wish to query or modify.
-debugTurn DEBUG output ON
-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)
-p / --portDestination port to connect to the SMB Server.(既定値: 445)
-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
-t / --timeoutSet connection timeout (seconds).(既定値: 60)
-c / --createChange the “CreationTime” of the file / directory.
-a / --accessChange the “LastAccessTime” of the file / directory.
-w / --writeChange the “LastWriteTime” of the file / directory.
-m / --modifyChange the “ChangeTime” of the file / directory.
-r / --referenceSpecify a file / directory to reference and copy the timestamps of (format is ).
-t / --timestampSpecify a timestamp to set for the selected filetimes (format: YYYY-MM-DD_HH:MM:SS.mmmmmm).
-v / --validateQuery the file after touching to verify the changes.

query は SMB basic information を取得し、FILETIME を日時へ変換します。touch は明示 timestamp、reference file、現在時刻から更新値を作り、未指定 field は保持して set-info を送ります。--validate では書き込み後に再取得して確認します。

NTFS/SMB の basic information には creation、last access、last write、change の四時刻があります。query はこれらを FILETIME から datetime/表示文字列へ 変換します。change time は metadata 更新時刻であり、content write time と 同義ではありません。利用者が指定する create/access/write/modify と wire field の対応を固定することが重要です。

touch は既存 basic information を先に読み、変更対象だけを新しい FILETIME へ置換します。値は明示 timestamp、reference file の対応 field、現在時刻の いずれかから作られます。未指定 field を 0 で送るか保持するかは SMB API の 意味を変えるため、dialect ごとの set structure と合わせて扱います。

--validate は書き込み後に再取得し、server が格納した値を比較します。 filesystem の時刻精度、timezone 表示、server 側 rounding があるため、 文字列の完全一致だけではなく FILETIME 単位と許容差を意識します。open handle の権限と share mode が reference/target の双方で正しい必要があります。

シンボル位置責務を追う入口
FileTimes66pretty_repr()
filetime_query()85モジュール関数
filetime_set()101モジュール関数
main()120モジュール関数
モジュール使用する主な名前
impacket.exampleslogger
impacket.examples.utilsparse_target
impacketsmbconnection, version
impacket.nmbSMB_SESSION_PORT
impacket.smbFILE_READ_ATTRIBUTES, FILE_READ_DATA, FILE_SHARE_DELETE, FILE_SHARE_READ, FILE_SHARE_WRITE, FILE_WRITE_ATTRIBUTES, FILE_WRITE_DATA, FTtoPOSIX, POSIXtoFT, SMBQueryFileBasicInfo, SMBSetFileBasicInfo, SMB_DIALECT, SMB_QUERY_FILE_BASIC_INFO, SMB_SET_FILE_BASIC_INFO
impacket.smb3structsFILE_BASIC_INFORMATION, SMB2_DIALECT_311, SMB2_FILE_BASIC_INFO
impacket.smb3FILE_BASIC_INFORMATION
  • 対象の状態を変更する操作があります。変更前に対象名や SID、パスを確認してください。
  • 失敗時は、名前解決、接続、認証、サービスの状態、権限のどこで止まったかを、プロトコルのステータスから切り分けます。

smbconnection、SMB1/SMB2 basic info structures、POSIXtoFT / FTtoPOSIX に依存します。filetime_query() / filetime_set() が dialect 差を扱います。timezone と FILETIME 精度を不用意に丸めないでください。