Impacket filetime.py
SMB 上のファイルやディレクトリについて、作成・アクセス・更新・変更の時刻を照会・変更します。
| 項目 | 内容 |
|---|---|
| 実装 | examples/filetime.py |
| カテゴリ | SMB / MSRPC / NTLM |
| 規模 | 309 行 |
| 配布 | setup.py の scripts=examples/*.py によりスクリプトとしてインストール |
CLI と入力
Section titled “CLI と入力”オプションの最新の定義は python examples/filetime.py -h で確認できます。
subcommand: FILETIME_READ_ACTION、FILETIME_WRITE_ACTION
| 引数 | 説明 |
|---|---|
target | [[domain/]username[:password]@] |
share | The share in which the desired file / directory to query or modify resides. |
path | The path of the desired file / directory whose timestamps we wish to query or modify. |
-debug | Turn DEBUG output ON |
-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) |
-p / --port | Destination port to connect to the SMB Server.(既定値: 445) |
-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 |
-t / --timeout | Set connection timeout (seconds).(既定値: 60) |
-c / --create | Change the “CreationTime” of the file / directory. |
-a / --access | Change the “LastAccessTime” of the file / directory. |
-w / --write | Change the “LastWriteTime” of the file / directory. |
-m / --modify | Change the “ChangeTime” of the file / directory. |
-r / --reference | Specify a file / directory to reference and copy the timestamps of (format is |
-t / --timestamp | Specify a timestamp to set for the selected filetimes (format: YYYY-MM-DD_HH:MM:SS.mmmmmm). |
-v / --validate | Query the file after touching to verify the changes. |
詳細な処理フロー
Section titled “詳細な処理フロー”query は SMB basic information を取得し、FILETIME を日時へ変換します。touch は明示 timestamp、reference file、現在時刻から更新値を作り、未指定 field は保持して set-info を送ります。--validate では書き込み後に再取得して確認します。
仕組みの詳細
Section titled “仕組みの詳細”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 の双方で正しい必要があります。
主要な実装要素
Section titled “主要な実装要素”| シンボル | 位置 | 責務を追う入口 |
|---|---|---|
FileTimes | 66 | pretty_repr() |
filetime_query() | 85 | モジュール関数 |
filetime_set() | 101 | モジュール関数 |
main() | 120 | モジュール関数 |
Impacket 内部
Section titled “Impacket 内部”| モジュール | 使用する主な名前 |
|---|---|
impacket.examples | logger |
impacket.examples.utils | parse_target |
impacket | smbconnection, version |
impacket.nmb | SMB_SESSION_PORT |
impacket.smb | FILE_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.smb3structs | FILE_BASIC_INFORMATION, SMB2_DIALECT_311, SMB2_FILE_BASIC_INFO |
impacket.smb3 | FILE_BASIC_INFORMATION |
出力・副作用・必要権限
Section titled “出力・副作用・必要権限”- 対象の状態を変更する操作があります。変更前に対象名や SID、パスを確認してください。
失敗経路と後始末
Section titled “失敗経路と後始末”- 失敗時は、名前解決、接続、認証、サービスの状態、権限のどこで止まったかを、プロトコルのステータスから切り分けます。
実装を変更するとき
Section titled “実装を変更するとき”smbconnection、SMB1/SMB2 basic info structures、POSIXtoFT / FTtoPOSIX に依存します。filetime_query() / filetime_set() が dialect 差を扱います。timezone と FILETIME 精度を不用意に丸めないでください。
- 構文:
python -m py_compile examples/filetime.py - CLI:
python examples/filetime.py -h - 関連テスト:
tests/SMB_RPC/test_nmb.py - 関連テスト:
tests/SMB_RPC/test_smb.py - 関連テスト:
tests/SMB_RPC/test_smbserver.py

