Impacket ntfs-read.py
NTFS ボリュームまたはイメージを読み取り専用で開き、ディレクトリの探索やファイルの抽出を行います。
| 項目 | 内容 |
|---|---|
| 実装 | examples/ntfs-read.py |
| カテゴリ | 秘密情報 / DPAPI / レジストリ / ファイル解析 |
| 規模 | 1455 行 |
| 配布 | setup.py の scripts=examples/*.py によりスクリプトとしてインストール |
CLI と入力
Section titled “CLI と入力”オプションの最新の定義は python examples/ntfs-read.py -h で確認できます。
| 引数 | 説明 |
|---|---|
volume | NTFS volume to open (e.g. \.\C: or /dev/disk1s1) |
-extract | extracts pathname (e.g. \windows\system32\config\sam) |
-debug | Turn DEBUG output ON |
-ts | Adds timestamp to every logging output |
詳細な処理フロー
Section titled “詳細な処理フロー”boot sector から cluster/MFT geometry を読み、MFT record の fixup と resident/non-resident attribute、data run、index root/allocation を解析します。-extract は指定 inode/stream を保存し、それ以外は MiniShell が ls、cd、cat、hexdump、get を dispatch します。
仕組みの詳細
Section titled “仕組みの詳細”NTFS 解析は boot sector から始まります。sector/cluster size、MFT の開始 cluster、
MFT record size を読み、指定 volume/image の byte offset へ変換します。
NTFS.mountVolume() がこの geometry を確定し、MFT 自身の record から後続 inode
を読むための data run を得ます。
各 MFT record は update sequence fixup を適用して sector 末尾の整合性を確認し、 resident/non-resident attribute を列挙します。resident data は record 内、 non-resident data は VCN→LCN の data run を辿って cluster から読みます。 directory は INDEX_ROOT と INDEX_ALLOCATION の B-tree entry を解析し、file 名と MFT reference を子 inode へ結びます。
attribute list がある file は複数 MFT record に extent が分散するため、
NonResidentDataAttribute が run を論理順に統合します。sparse、compressed、
encrypted flag は「読める data stream」と同義ではありません。MiniShell は
この read-only model 上で path 解決、ls/cat/hexdump/get を行い、host filesystem
への書き込みは抽出先だけに限定します。
disk image は未信頼入力です。fixup、attribute length、run length、index entry size、recursive directory reference を検証し、整数 overflow や無限 loop を 避けることが parser 変更時の最優先事項です。
主要な実装要素
Section titled “主要な実装要素”| シンボル | 位置 | 責務を追う入口 |
|---|---|---|
NTFS_BPB | 131 | 構造体/定数定義 |
NTFS_EXTENDED_BPB | 146 | 構造体/定数定義 |
NTFS_BOOT_SECTOR | 160 | 構造体/定数定義 |
NTFS_MFT_RECORD | 170 | 構造体/定数定義 |
NTFS_ATTRIBUTE_RECORD | 188 | 構造体/定数定義 |
NTFS_ATTRIBUTE_RECORD_NON_RESIDENT | 200 | 構造体/定数定義 |
NTFS_ATTRIBUTE_RECORD_RESIDENT | 213 | 構造体/定数定義 |
NTFS_FILE_NAME_ATTR | 221 | 構造体/定数定義 |
NTFS_STANDARD_INFORMATION | 238 | 構造体/定数定義 |
NTFS_INDEX_HEADER | 247 | 構造体/定数定義 |
NTFS_INDEX_ROOT | 256 | 構造体/定数定義 |
NTFS_INDEX_ALLOCATION | 267 | 構造体/定数定義 |
NTFS_INDEX_ENTRY_HEADER | 277 | 構造体/定数定義 |
NTFS_INDEX_ENTRY | 286 | 構造体/定数定義 |
NTFS_DATA_RUN | 296 | 構造体/定数定義 |
NTFS_ATTRIBUTE_LIST_ENTRY | 304 | 構造体/定数定義 |
Attribute | 321 | __init__()、getFlags()、getName()、isNonResident()、dump()、getTotalSize()、getType() |
AttributeResident | 347 | __init__()、dump()、getFlags()、getValue()、read()、getDataSize() |
AttributeNonResident | 370 | __init__()、dump()、getDataSize()、getValue()、parseDataRuns()、readClusters()、readVCN()、read() |
NonResidentDataAttribute | 544 | __init__() |
AttributeStandardInfo | 648 | __init__()、getFileAttributes()、getFileTime()、dump() |
AttributeFileName | 666 | __init__()、getFileNameType()、getFileAttributes()、getFileName()、getFileSize()、getFlags()、dump() |
AttributeIndexAllocation | 690 | __init__()、dump()、read() |
AttributeIndexRoot | 704 | __init__()、parseIndexEntries()、dump()、getType() |
IndexEntry | 729 | __init__()、isSubNode()、isLastNode()、getVCN()、getSize()、getKey()、getINodeNumber()、dump() |
AttributeListEntry | 754 | __init__() |
AttributeList | 771 | __init__()、getEntries() |
INODE | 804 | __init__()、isDirectory()、isCompressed()、isEncrypted()、isSparse()、displayName()、getPrintableAttributes()、parseAttributes()、searchAttribute()、PerformFixUp()、parseIndexBlocks()、walkSubNodes() ほか |
NTFS | 1138 | __init__()、mountVolume()、readBootSector()、getINode() |
MiniShell | 1226 | __init__()、emptyline()、onecmd()、do_exit()、do_shell()、do_help()、do_lcd()、do_cd()、findPathName()、do_pwd()、do_ls()、complete_cd() ほか |
getUnixTime() | 315 | モジュール関数 |
main() | 1432 | モジュール関数 |
Impacket 内部
Section titled “Impacket 内部”| モジュール | 使用する主な名前 |
|---|---|
impacket.examples | logger |
impacket | version |
impacket.structure | Structure, hexdump |
外部パッケージ(直接使用)
Section titled “外部パッケージ(直接使用)”| import 名 | 配布パッケージ | 経路・宣言状態 |
|---|---|---|
six | six | 直接 import、宣言済み |
出力・副作用・必要権限
Section titled “出力・副作用・必要権限”- 主処理はローカルファイルの解析です。入力を信頼せず、offset、length、形式識別子を検証してからデータを参照してください。
- オプションによりローカルファイルを作成または更新します。既存ファイルの扱いと秘密情報を含む出力の権限を確認してください。
失敗経路と後始末
Section titled “失敗経路と後始末”- 入力ファイルがない場合、壊れている場合、読み取りが途中で終わる場合、未対応の形式だった場合を区別します。
実装を変更するとき
Section titled “実装を変更するとき”impacket.structure と標準 file I/O に依存します。NTFS、INODE、各 Attribute* が parser、MiniShell が UI です。untrusted image の offset/length、sparse/compressed/encrypted 属性、attribute list extent の境界検証を保ってください。
- 構文:
python -m py_compile examples/ntfs-read.py - CLI:
python examples/ntfs-read.py -h - 関連テスト:
tests/misc/test_ntfs_read.py - 関連テスト:
tests/misc/test_structure.py

