Reading width
Wide uses the full column for everything, text, diagrams, code, and exercises. Narrow keeps the standard reading width.
Text size
Scales the body text. Headings and code blocks keep their size.
In this section
0.4 Accessors for Disks, Hives and Images
Introduction
Every plugin that reads a file, from glob() to read_file() to parse_lines(), reads it through an accessor.
The accessor decides what a path means and how its bytes are fetched: through the operating system's API, by parsing a file system from raw clusters, from inside a disk image, or from a registry hive treated as a set of keys. The plugin asks for a path; the accessor decides what is there.
That choice changes the evidence. The operating system hides some files, locks others and does not show streams or metadata at all, while a parser sees the volume as it is on disk.
This lesson reads one evidence folder through several accessors on the lab machine: two NTFS images and a SAM hive from Velociraptor's own test data, and an image built for this lesson holding a downloaded file and its Zone.Identifier stream.
Module 4 builds custom artifacts on these accessors; here the aim is to know which one a question needs, and to recognize the wrong one before it reports an empty result.
One Path, Several Readers
What an accessor isAn accessor is a named way of opening a path. The default on most plugins is auto, which uses the file accessor, and file uses the operating system's API: the same calls any program makes to list a folder or open a file. Through it, the lab's evidence folder looks like four ordinary files:
SELECT OSPath.Basename AS Name, Size
FROM glob(globs='/home/analyst/evidence/*')
ORDER BY NameThe evidence folder through the default accessor: four files, two of them whole file systems.
Two of those files are whole file systems and one is a registry hive, and the operating system has no opinion about that. A file is bytes to it. Reading the first few bytes of two of them shows what they really are: a hive starts with the signature regf, and an NTFS boot sector carries the string NTFS at offset 3.
SELECT read_file(filename='/home/analyst/evidence/SAM', length=4) AS Magic,
read_file(filename='/home/analyst/evidence/test.ntfs.dd', offset=3, length=4) AS OEM
FROM scope()The first bytes of two of them: a registry hive begins regf, and an NTFS boot sector carries NTFS at offset 3.
The other accessors read the same bytes and interpret them. ntfs parses the NTFS structures of a live volume from raw clusters, raw_ntfs does the same for an NTFS file system inside an image, ewf opens an Expert Witness container, raw_reg parses a hive into keys and values, and zip, data and offset cover archives, strings held in memory and reads from a starting position.
Each is a different answer to the question of what a path refers to.
The zip accessor deserves an early mention because the course leans on it later. Velociraptor's own collections are zip files: an offline collector writes one, and an export from the server is one. With zip, a collection becomes a folder that plugins can list and read without being unpacked first, which is how collected results are examined on an analyst's machine without importing them anywhere.
A query names its accessor with the accessor argument, and a plugin given none uses the default. Most of the time the default is right. The cases where it is not are exactly the ones investigations care about: locked files, hidden metadata, streams, images and the hives of users who are not logged on.
When the Operating System Says No
The auto fallback, and its limitOn a live Windows host the operating system stands between a query and some of the most useful evidence. Registry hives in use, the page file, files held open by security software and files a filter driver refuses to show cannot be opened through the API.
The Velociraptor documentation describes how auto handles that: it tries the file accessor first and, if the file is locked or access is denied, falls back to ntfs, reading the raw disk clusters instead. That fallback gets around file system permissions and security software filter drivers, which is why most Windows artifacts can collect files that a copy command cannot.
The fallback has a scope, and it is easy to assume more of it than it does. It covers a path that the API refused, on a live NTFS volume.
It does not turn a path that the API understood into a parsed one: a file the API opens successfully is read through the API, with whatever view of it the API gives. And it does nothing for evidence that is not on a live volume at all. Asked to look inside one of the lab's images, the default accessor returned this:
SELECT OSPath.Path AS Path FROM glob(globs='/home/analyst/evidence/test.ntfs.dd/*')Asking the default accessor to look inside an image.
No rows, and no error. The operating system opened the image file without complaint, found nothing inside a file because files do not have insides, and the query finished normally.
That is the third silent empty result in this module, after the skipped collection in lesson 0.1 and the misspelled column in lesson 0.3, and it has the same remedy: before trusting an empty result, confirm the query could have returned something.
Linux and macOS clients have no NTFS fallback to make, because their file systems are not NTFS. There the file accessor is the normal view, and the limits are the operating system's own: the client needs to run with enough privilege to read other users' files, and files the kernel exposes as virtual, such as those under /proc, behave differently from files on disk.
An NTFS volume attached to a Linux machine, or an image of one, is read with raw_ntfs like any other.
On a live Windows host the practical rule is short. Let auto handle locked files, name ntfs explicitly when the question is about NTFS itself, such as metadata files and streams, and treat any evidence held as an image or a container as a job for a different accessor altogether.
Reading NTFS Directly
The file system as it is on diskA parser reads the volume the way the file system itself does, from the structures on disk, and so it sees what the API filters out. Read through raw_ntfs, the root of the first test image holds 20 entries. Seven of them are enough to show the difference:
SELECT OSPath.Path AS Path, Size, IsDir
FROM glob(globs='/*',
root=pathspec(DelegateAccessor='file', DelegatePath='/home/analyst/evidence/test.ntfs.dd'),
accessor='raw_ntfs')Seven of the 20 entries at the root of the NTFS image, read by parsing the file system.
The names beginning with a dollar sign are NTFS metadata files. $MFT is the master file table, with a record for every file on the volume, including deleted ones whose records have not been reused. $LogFile is the transaction journal that NTFS uses to keep its structures consistent. $Secure:$SDS is not a file at all but a named stream of the $Secure file, holding the security descriptors the volume's files point to.
None of them appears in a directory listing made through the operating system, and each is evidence in its own right.
That is the reason parsing exists, not a curiosity of the image. Timestamps that a file's own metadata no longer shows can survive in the master file table, and the journal records changes the file system made.
A tool that only lists files through the API answers a narrower question than a tool that parses the volume, and the difference is the part an attacker is least likely to have cleaned up.
The master file table is also where deleted files live on. A deleted file's record stays in $MFT until NTFS reuses it, with the name, the timestamps and often the location of the data.
Velociraptor's parse_mft() plugin reads the table record by record, deleted records included, and Module 4 uses it in depth. Pointed at the test image's $MFT and asked for every record whose path mentions txt, it found files in subfolders the root listing never reached, and something more:
SELECT EntryNumber, InUse, OSPath, FileSize
FROM parse_mft(
filename=pathspec(DelegateAccessor='file', DelegatePath='/home/analyst/evidence/test.ntfs.dd',
Path='/$MFT'),
accessor='raw_ntfs')
WHERE OSPath =~ 'txt'The master file table read record by record: every text file on the volume, wherever it sits, and one stream hiding behind a file's name.
Record 46 has two entries: a text document, and a named stream attached to it called goodbye.txt, 64 bytes long. Nothing in the folder listing shows it, the document opens normally, and the stream travels with the file for as long as it stays on NTFS. The point is that this evidence exists only for a tool that reads the file system rather than asking it.
The parsed view also changes what a path means. On a live Windows host, ntfs paths name the volume by its device, and on an image the path is relative to the image's root, as in the listing above. The next section shows how a query says which image, and through what.
Images and Delegation
An accessor that reads through anotherAn image is a file system inside a file, and sometimes inside a container as well. Velociraptor handles that with delegation: a pathspec() value names an outer accessor and path that open the container, and the accessor named on the plugin reads what is inside.
The documentation describes the root argument as an OSPath that points the accessor at the file on disk. For the first test image, the outer layer is the file accessor opening test.ntfs.dd, and raw_ntfs reads the file system inside it; that was the query behind the listing in the previous section.
Delegation as layers. Each accessor opens the thing the next one reads, which is how one query reaches a stream inside a file inside a file system inside an image.
Delegation stacks. The same file system is also stored as an E01 file, the Expert Witness format many imaging tools produce, which compresses the image and adds its own structure around it. Changing the outer accessor to ewf unwraps the container, and raw_ntfs reads the same files from inside it:
SELECT OSPath.Path AS Path, Size
FROM glob(globs='/*.txt',
root=pathspec(DelegateAccessor='ewf', DelegatePath='/home/analyst/evidence/test.ntfs.dd.E01'),
accessor='raw_ntfs')The same file system inside an E01 container: ewf unwraps the container, raw_ntfs reads what is inside it.
The same two text files come back from both. The query changed only its outermost layer; everything inside it was read the same way. This is what makes dead-disk analysis with Velociraptor practical: an image handed over by a colleague, a cloud provider or an imaging tool is opened with the same plugins and artifacts used on live hosts, by describing the layers it is wrapped in.
Module 4 covers remapping, which goes further and lets a whole image stand in for a live client so that ordinary artifacts run against it unchanged.
Real disk images add a layer the lab's do not. A whole-disk image starts with a partition table, and the NTFS file system begins at an offset into it, typically a megabyte or more from the start.
The offset accessor reads another file from a given position, so a delegation chain can open the image, skip to the partition and hand that to raw_ntfs. Getting the offset wrong produces the same quiet failure as any other wrong layer.
The cost of delegation is one more thing to get right. Each layer has to be named correctly, and the next section shows what a single wrong layer returns.
Streams the API Hides
One file, two sets of contentsNTFS lets a file carry more than one stream of data. The ordinary contents are the unnamed stream; any number of named streams can sit beside it, invisible to a normal directory listing and untouched by a normal copy to another file system.
Windows uses one of them for the Mark of the Web: when a browser or mail client saves a file from the internet, it writes a stream called Zone.Identifier recording where the file came from.
The lab's second image holds one downloaded file, written with ntfscp together with its Zone.Identifier stream. Listed through raw_ntfs, the file appears twice:
SELECT OSPath.Path AS Path, Size
FROM glob(globs='/Invoice*',
root=pathspec(DelegateAccessor='file', DelegatePath='/home/analyst/evidence/download.img'),
accessor='raw_ntfs')One file, two streams: the second exists only in NTFS, and only a parser lists it.
The stream is 119 bytes, and reading it through the same delegated pathspec returns its contents:
SELECT read_file(
filename=pathspec(DelegateAccessor='file', DelegatePath='/home/analyst/evidence/download.img',
Path='/Invoice_4471.exe:Zone.Identifier'),
accessor='raw_ntfs') AS ZoneIdentifier
FROM scope()The stream's contents: the zone the file came from and the addresses it was fetched from.
Three lines carry the evidence. ZoneId=3 is the internet zone, which is what makes Windows warn before running the file and makes Office block its macros. ReferrerUrl is the page the download was started from, here a mail service, and HostUrl is where the file itself was fetched. For an investigation into how a file reached a host, those three lines often answer the first question outright.
The accessor follows from what the evidence is, not from what the path looks like. The red branch is the one that silently misses users.
The stream belongs to the file only while the file stays on NTFS. Copy it to a FAT32 or exFAT drive, attach it to an email or put it in most zip tools, and the stream is left behind, so the copy carries no record of where it came from.
When a file on one host has a Zone.Identifier and the same file on another host does not, the difference itself says something about how it traveled.
Streams cut both ways. They hold provenance like this, and they are also a place to hide data, because few tools list them. Either way, only an accessor that parses NTFS sees them, on a live volume with ntfs and in an image with raw_ntfs.
Hives Without the Registry API
Why raw parsing covers every userThe Windows registry is stored in hive files, and Velociraptor can read it two ways. The registry accessor uses the live registry API, which is convenient and has a limit the documentation spells out: the API shows the hives that are loaded, and a user's own hive is loaded only while that user is logged on.
A question about every user on a host, through the API, silently becomes a question about the users who happen to be logged on when it runs.
The raw_reg accessor reads a hive file directly, parsing its keys and values from the bytes, so every hive on disk can be read whether or not it is loaded. The documentation recommends it for exactly that reason. Delegated through the file accessor to the SAM hive in the lab's evidence folder, it lists the local accounts by name:
SELECT OSPath.Basename AS UserName
FROM glob(globs='/SAM/Domains/Account/Users/Names/*',
root=pathspec(DelegateAccessor='file', DelegatePath='/home/analyst/evidence/SAM'),
accessor='raw_reg')The account names in a SAM hive, read from the hive file with raw_reg.
The same approach works for every user's NTUSER.DAT and UsrClass.dat, the hives that hold most per-user activity evidence. On a live Windows host those files are usually locked while their users are logged on, which is where the auto fallback from section 2 comes back: the outer layer of the pathspec reads the locked hive file through NTFS, and raw_reg parses it.
Reading a hive file has one caveat of its own. Windows keeps recent registry changes in memory and in transaction logs beside the hive, named with LOG1 and LOG2 extensions, before writing them into the hive file itself. A hive copied from a running system can therefore lag the live registry by its most recent changes, and collections that matter take the logs along with the hive.
The rule of thumb is that a registry question about a person uses the hive file, not the API, unless you know that person is logged on and that is all you need.
The Wrong Accessor Fails Quietly
Reading an empty result, againEverything in this lesson so far worked because each layer was named correctly. Name one wrongly and the query does not fail; it returns nothing. Asked to read the same stream with the ntfs accessor and a path running through the image file, the query returned an empty string and exit code 0:
SELECT read_file(filename='/home/analyst/evidence/download.img/Invoice_4471.exe:Zone.Identifier',
accessor='ntfs') AS ZoneIdentifier
FROM scope()The same stream asked for with the ntfs accessor and a path through the image file.
The ntfs accessor reads a live volume by its device path, and a path through a file on the lab disk meant nothing to it. It opened nothing, read nothing and said so only by returning an empty value. A report built on that result would say the download carried no zone information, which is false.
The same thing happens with each layer of a delegation chain. A wrong DelegatePath, an ewf accessor pointed at a raw image, a raw_ntfs accessor pointed at a FAT volume or a missing partition offset: each gives the plugin nothing to read, and each looks, at the end of the query, exactly like evidence that is not there.
The defense is the one this module keeps returning to. Before reading an empty result as a finding, list what the accessor can see at that path, as the glob in section 5 did, or read a file you know is there.
When the evidence is an image, start by listing its root through the delegated pathspec: a listing with $MFT in it confirms that the layers are right before any question depends on them.
Asking an Assistant
Describing the evidence, not just the artifactAsked how to read a Zone.Identifier stream, an assistant answered correctly for the case it assumed: a live Windows host, the ntfs accessor and a drive-letter path. The evidence in this lesson is an image on a Linux machine, and the same answer, adapted to it, returned an empty string.
- You
How do I read a file's Zone.Identifier stream with Velociraptor?
- Assistant
Use the ntfs accessor, which can see alternate data streams: SELECT read_file(filename='C:/Users/alice/Downloads/file.exe:Zone.Identifier', accessor='ntfs') FROM scope().
- Velociraptor
SELECT read_file(filename='/home/analyst/evidence/download.img/Invoice_4471.exe:Zone.Identifier', accessor='ntfs') AS ZoneIdentifier FROM scope()ZoneIdentifierAn empty string and exit code 0: the accessor did not understand the path and returned nothing.The same stream asked for with the ntfs accessor and a path through the image file.
- You
With velociraptor query 0.77.4 on Linux, I have an NTFS disk image at /home/analyst/evidence/download.img. Inside it is Invoice_4471.exe. Give me VQL that reads that file's Zone.Identifier alternate data stream from the image, name the accessors involved and why each is needed, and tell me how to confirm the query really opened the stream.
- Assistant
The ntfs accessor reads a live volume by drive path, so it cannot see inside an image file. Use a pathspec: the file accessor opens download.img, and raw_ntfs parses the NTFS file system inside it. Path is the path inside the image, with the stream after a colon. To confirm the stream was opened, list the file's streams first with glob() on the same pathspec and check its size, then compare the length of what read_file returns.
- Velociraptor
SELECT read_file( filename=pathspec(DelegateAccessor='file', DelegatePath='/home/analyst/evidence/download.img', Path='/Invoice_4471.exe:Zone.Identifier'), accessor='raw_ntfs') AS ZoneIdentifier FROM scope()ZoneIdentifier[ZoneTransfer] ZoneId=3 ReferrerUrl=https://mail.example.net/ HostUrl=https://files.example.net/d/Invoice_4471.exeThe stream's contents: the zone the file came from and the addresses it was fetched from.
The second prompt described the evidence: where the query would run, that the file is inside an image, which stream was wanted, which accessors were involved and how to confirm the read. The reply built the pathspec layer by layer and suggested the check that catches the silent failure.
- velociraptor query 0.77.4 on Linuxsays where the query runs, which decides which accessors make sense
- an NTFS disk image at /home/analyst/evidence/download.imgsays the evidence is an image, not a live volume
- Zone.Identifier alternate data streamnames the stream, so the answer uses NTFS stream syntax
- name the accessors involved and why each is neededgets the delegation chain explained, not only written
- how to confirm the query really opened the streamasks for the check that catches the silent failure
The assistant saved time on the pathspec syntax and on knowing which accessor reads an image. The point where it needed steering was the evidence itself, and no amount of syntax knowledge substitutes for telling it what the evidence is.
- FailsThe first query opened the streamit returned an empty string with exit code 0
- HoldsThe stream exists in the imageglob through raw_ntfs lists Invoice_4471.exe:Zone.Identifier, 119 bytes
- HoldsThe second query read all of it119 bytes returned, ZoneId=3 and both URLs present
That conclusion rests on a stream that was listed, sized and read in full, which is the standard for any reading made through an accessor, whoever wrote the query.
Practice
Which accessor was reading? your own VelociraptorThe scenario holds the queries a colleague ran on an evidence folder and the conclusion they reached. Decide what each result shows and which accessor the evidence needed.
Then read some evidence yourself. Velociraptor's test images are in its public repository under artifacts/testdata/files; download test.ntfs.dd and SAM, list the image's root through raw_ntfs with a delegated pathspec, and list the SAM's account names through raw_reg. Then run the same glob with the default accessor and see the empty result for yourself.
On a Windows machine, find a file you downloaded and read its Zone.Identifier stream with the ntfs accessor.
An accessor decides what a path means: the operating system's view, a parsed file system, the inside of an image or a hive read as keys.
Parsing sees metadata files, streams and every user's hive, which the API hides; delegation reaches through images and containers; and a wrong accessor returns nothing without an error. Lesson 0.5 turns from how evidence is read to which evidence to read first, on a host that may not stay up.
Resources
Velociraptor changes quickly; where its documentation and this lesson disagree, the documentation is newer.