Skip to content

Impacket ntfs-read.py

Back to the category index / Back to the command index

Opens an NTFS volume or image read-only to browse directories and extract files.

ItemDetails
Implementationexamples/ntfs-read.py
CategorySecrets / DPAPI / registry / file analysis
Size1,455 lines
DistributionInstalled as a script through scripts=examples/*.py in setup.py

Run python examples/ntfs-read.py -h for the current option definitions.

ArgumentDescription
volumeNTFS volume to open (e.g. \.\C: or /dev/disk1s1)
-extractExtract a pathname (for example, \windows\system32\config\sam)
-debugEnable debug output
-tsAdd a timestamp to each log message

The tool reads cluster and MFT geometry from the boot sector, then parses MFT record fixups, resident and non-resident attributes, data runs, and index roots and allocations. -extract saves a specified inode or stream; otherwise, MiniShell dispatches ls, cd, cat, hexdump, and get.

NTFS parsing starts at the boot sector. The tool reads sector and cluster sizes, the starting MFT cluster, and MFT record size, then converts them to byte offsets in the specified volume or image. NTFS.mountVolume() establishes this geometry and obtains data runs from the MFT’s own record to read later inodes.

Each MFT record applies update sequence fixups to check sector-end consistency and enumerates resident and non-resident attributes. Resident data sits in the record; non-resident data is read from clusters by following VCN-to-LCN data runs. Directories parse B-tree entries in INDEX_ROOT and INDEX_ALLOCATION, linking file names and MFT references to child inodes.

For files with an attribute list, extents span multiple MFT records, so NonResidentDataAttribute combines runs in logical order. Sparse, compressed, and encrypted flags do not imply a readable data stream. MiniShell resolves paths and runs ls, cat, hexdump, and get on this read-only model; writes to the host filesystem are limited to extracted files.

Disk images are untrusted input. Validate fixups, attribute and run lengths, index entry sizes, and recursive directory references to avoid integer overflows and infinite loops when changing the parser.

SymbolLocationWhere to trace its responsibility
NTFS_BPB131Structure or constant definition
NTFS_EXTENDED_BPB146Structure or constant definition
NTFS_BOOT_SECTOR160Structure or constant definition
NTFS_MFT_RECORD170Structure or constant definition
NTFS_ATTRIBUTE_RECORD188Structure or constant definition
NTFS_ATTRIBUTE_RECORD_NON_RESIDENT200Structure or constant definition
NTFS_ATTRIBUTE_RECORD_RESIDENT213Structure or constant definition
NTFS_FILE_NAME_ATTR221Structure or constant definition
NTFS_STANDARD_INFORMATION238Structure or constant definition
NTFS_INDEX_HEADER247Structure or constant definition
NTFS_INDEX_ROOT256Structure or constant definition
NTFS_INDEX_ALLOCATION267Structure or constant definition
NTFS_INDEX_ENTRY_HEADER277Structure or constant definition
NTFS_INDEX_ENTRY286Structure or constant definition
NTFS_DATA_RUN296Structure or constant definition
NTFS_ATTRIBUTE_LIST_ENTRY304Structure or constant definition
Attribute321__init__(), getFlags(), getName(), isNonResident(), dump(), getTotalSize(), getType()
AttributeResident347__init__(), dump(), getFlags(), getValue(), read(), getDataSize()
AttributeNonResident370__init__(), dump(), getDataSize(), getValue(), parseDataRuns(), readClusters(), readVCN(), read()
NonResidentDataAttribute544__init__()
AttributeStandardInfo648__init__(), getFileAttributes(), getFileTime(), dump()
AttributeFileName666__init__(), getFileNameType(), getFileAttributes(), getFileName(), getFileSize(), getFlags(), dump()
AttributeIndexAllocation690__init__(), dump(), read()
AttributeIndexRoot704__init__(), parseIndexEntries(), dump(), getType()
IndexEntry729__init__(), isSubNode(), isLastNode(), getVCN(), getSize(), getKey(), getINodeNumber(), dump()
AttributeListEntry754__init__()
AttributeList771__init__(), getEntries()
INODE804__init__(), isDirectory(), isCompressed(), isEncrypted(), isSparse(), displayName(), getPrintableAttributes(), parseAttributes(), searchAttribute(), PerformFixUp(), parseIndexBlocks(), walkSubNodes(), and others
NTFS1138__init__(), mountVolume(), readBootSector(), getINode()
MiniShell1226__init__(), emptyline(), onecmd(), do_exit(), do_shell(), do_help(), do_lcd(), do_cd(), findPathName(), do_pwd(), do_ls(), complete_cd(), and others
getUnixTime()315Module function
main()1432Module function
ModuleMain names used
impacket.exampleslogger
impacketversion
impacket.structureStructure, hexdump
Import nameDistribution packageImport path and declaration status
sixsixImported directly; declared

Output, side effects, and required privileges

Section titled “Output, side effects, and required privileges”
  • The main operation parses local files. Treat input as untrusted: validate offsets, lengths, and format identifiers before accessing data.
  • Options may create or update local files. Check how existing files are handled and the permissions on output containing secrets.
  • Distinguish a missing input file, a damaged file, an incomplete read, and an unsupported format.

The code depends on impacket.structure and standard file I/O. NTFS, INODE, and each Attribute* class handle parsing; MiniShell handles the UI. Preserve boundary checks for offsets and lengths in untrusted images, sparse/compressed/encrypted attributes, and attribute-list extents.