In this section

0.3 Querying an Endpoint as Data

Module 0

Introduction

Every question Velociraptor asks of an endpoint is written in VQL, the Velociraptor Query Language. Artifacts are VQL, hunts are VQL, notebooks are VQL, and the GUI's buttons compile to VQL before anything is sent. A practitioner who cannot read it is collecting artifacts on trust, and one who can write it can ask the questions no built-in artifact anticipated.

VQL looks like SQL and behaves differently, because its tables are not stored anywhere. A plugin generates rows when it runs: one per file, one per process, one per line of a log.

This lesson writes one investigative question, whether anything on a Linux host is set to run from a temporary folder on a schedule, and builds it from a single plugin to a chained query and an artifact call, running each step on the lab machine.

Along the way it shows the two ways a query fails, why one of them is silent, and why a correct query can still answer a narrower question than the one you meant.

1

Plugins Are Tables

Rows generated on demand

The simplest VQL statement selects from a plugin. A plugin goes between FROM and WHERE and produces rows, each row a set of named columns; a function, by contrast, takes values and returns one value. The documentation draws the distinction in exactly those terms, and it is the first thing to hold onto, because VQL's power comes from plugins and its convenience from functions.

info() is a plugin with one row: the host the query is running on. Run with velociraptor query on the lab machine, which evaluates VQL locally with no server involved, it answers like this:

VQL1 row
SELECT Hostname, OS, Platform, PlatformVersion FROM info()
HostnameOSPlatformPlatformVersion
ir-lablinuxubuntu24.04

info() is a plugin with one row: the host the query is running on.

glob() is a plugin with one row per file that matches a pattern. It is the starting point for most questions about files, because it turns the file system into rows that the rest of the query can filter:

VQL5 rows
SELECT OSPath.String AS Path, Size, Mtime
FROM glob(globs='/etc/cron.d/*')
ORDER BY Path
PathSizeMtime
/etc/cron.d/.placeholder1022024-03-31T00:06:27Z
/etc/cron.d/backup-sync1672026-12-02T18:49:33.66707534Z
/etc/cron.d/e2scrub_all2012026-11-19T18:58:01Z
/etc/cron.d/php7122024-01-19T01:25:55Z
/etc/cron.d/sys-update642026-12-02T18:49:33.667650364Z

glob() is a plugin with one row per matching file. The four files in the lab machine's cron folder.

Two details carry through the rest of the course. Columns can hold structured values: the path that glob() returns is an object with components, which is why the query asks for OSPath.String and names it Path. And AS renames a column, which matters more than it looks, because a column name is what the next stage of a query refers to.

Functions do the per-row work. hash(path=OSPath) returns the MD5, SHA1 and SHA256 of one file, timestamp() turns a number or a string into a time, and format() builds a string from values.

A function sits in the SELECT or the WHERE and operates on one row at a time, which is why the same function call can run thousands of times in a query that returns three rows: once for every row the plugin produced before the filter.

Nothing in those rows existed before the query ran. There is no table of cron files on the host; the plugin read the directory at that moment. That is the property that makes VQL suited to live response, and it is also why a query's cost is paid on the endpoint, every time it runs. The next sections build on these two plugins until they answer the question.

2

Writing the Question Down

From a sentence to a WHERE clause

An investigative question has a shape before it has a syntax. Whether anything is scheduled to run from a temporary folder has three parts: where scheduled work is defined, what counts as running from a temporary folder, and what you need to see about each match. In VQL those parts become the FROM, the WHERE and the SELECT.

SyntaxA question, written as VQL
FROMWhere the rows come from: a plugin, an artifact or a stored query
WHEREThe question: which rows answer it
SELECTWhat you need to see about each answer
LETA named query to reuse; <= runs it once and keeps the rows
foreachFor each row of one query, run another
LIMITStop as soon as enough rows have arrived

Start with one file. A cron file is text, one entry per line, so parse_lines() turns it into rows, and the entry in sys-update is visible at once:

VQL1 row
SELECT Line FROM parse_lines(filename='/etc/cron.d/sys-update')
Line
*/15 * * * * root /bin/sh /tmp/.cache/update.sh >/dev/null 2>&1

parse_lines() returns one row per line of a file: the single entry in sys-update.

The WHERE clause is where the question lives. VQL's regex operator, =~, returns true or false and is case-insensitive by default; the documentation notes that (?-i) makes it case-sensitive and that lookarounds and backreferences are not supported. WHERE Line =~ '/tmp/' therefore reads: keep the lines that mention /tmp/ anywhere.

On a real host that pattern would be widened to /var/tmp/ and /dev/shm/, which are just as writable and just as favored by anything that wants to run without leaving a file in a normal place.

The SELECT is the part most often left as an afterthought, and it decides what the finding can say. A line from a cron file without the file it came from is a claim nobody can check, so the path goes into the output alongside the line.

The general rule follows from the evidential point in lesson 0.2: every row that may end up in a report should carry what it is, where it came from, and when it was read.

SELECT * returns every column the plugin produced, which is the right first step with an unfamiliar plugin and the wrong last one. It shows what is available; a finding needs only the columns that support it, and narrowing the SELECT is also what keeps a hunt's results readable when they arrive from a thousand machines.

Writing the question down this way also makes it reviewable. A colleague can read the WHERE clause and see exactly what counted as a match, which no sentence in a report achieves on its own.

3

One Query Feeding Another

foreach and LET

One file is a test, not an answer. The question needs every file in the cron folder, and VQL has no JOIN; the documentation says foreach() fills that role. It takes a row query and runs a second query once for each row, with that row's columns in scope:

VQL1 row
SELECT Path, Line FROM foreach(
  row={ SELECT OSPath FROM glob(globs='/etc/cron.d/*') },
  query={ SELECT OSPath.String AS Path, Line FROM parse_lines(filename=OSPath) })
WHERE Line =~ '/tmp/'
PathLine
/etc/cron.d/sys-update*/15 * * * * root /bin/sh /tmp/.cache/update.sh >/dev/null 2>&1

One query feeding another: every cron file, every line, kept only where it runs from /tmp.

Read it as a pipeline. glob() produces a row per cron file, foreach() hands each file's path to parse_lines(), which produces a row per line, and the outer WHERE keeps the line that runs from /tmp. Four files went in, and one row came out.

glob()one row per fileforeach()each file in turnparse_lines()one row per lineWHERELine =~ '/tmp/'SELECTPath, Line4 files4 filesevery line1 line1 rowRows flow left to right; each stage sees only what the last one passed on

The foreach query as rows moving through stages. Filtering happens as early as the question allows, which is what keeps a query cheap on an endpoint.

LET names a query so it can be used again, and it comes in two forms that behave differently. LET files = SELECT ... stores the query itself, lazily, and runs it each time it is referenced. LET files <= SELECT ... runs it once and keeps the rows in memory; the documentation calls <= the materialize operator. The choice matters on an endpoint: a stored query referenced three times reads the disk three times, and a materialized one holds every row in the client's memory for as long as the query runs. Lesson 0.1's captures used <= to hold a flow ID while waiting for the collection to finish, which is the typical use: a small result needed more than once.

ChoiceWhich LET to use
LET x = queryRe-run each time x is used; nothing held in memory
LET x <= queryRun once, rows kept for every later reference
Small result, used oftenMaterialize it with <=
Large result, used onceStore it with = and let it stream

foreach() also takes a workers setting, which the documentation describes as enabling parallel evaluation. On a server processing collected results that can shorten a long query considerably; on an endpoint it multiplies the load the query puts on the machine, and the default of one worker is usually the considerate choice.

Most VQL that does real work is a foreach() or a LET away from a single plugin. The craft is in deciding which stage filters, because a row dropped early costs nothing later.

4

Artifacts Are Named Queries

Calling one, and naming its source

The query in the previous section is the kind of thing that, once it works, should be saved and shared. That is what an artifact is: named, documented VQL with parameters, which the server can send to any client. Velociraptor ships hundreds of them, and Linux.Sys.Crontab parses the system and user crontabs into columns. An artifact can be called from VQL with the Artifact. prefix:

VQL1 row
SELECT User, Minute, Hour, Command
FROM Artifact.Linux.Sys.Crontab(source='CronTabs')
WHERE Command =~ '/tmp/'
UserMinuteHourCommand
root*/15*/bin/sh /tmp/.cache/update.sh >/dev/null 2>&1

The same question asked of the built-in crontab artifact, naming the source that holds parsed entries.

The query names a source. Many artifacts have several sources, each a separate query with its own columns. Linux.Sys.Crontab has three: CronTabs, the parsed entries; CronScripts, the scripts the entries call; and Uploaded, the files it can upload.

Called without naming one, the artifact returns rows from all of them, and a WHERE clause written for one source is evaluated against rows from the others. The same question without source= still returned the right row, and it also printed a stream of errors, counted here by which source's rows produced them:

$ velociraptor query --nobanner --format json \
    "SELECT Command FROM Artifact.Linux.Sys.Crontab() WHERE Command =~ '/tmp/'" \
    2>&1 | grep 'Symbol Command not found' | grep -o '\[[A-Za-z, _]*_Source\]' | sort | uniq -c
      7 [Mtime, OSPath, Content, _Source]
     15 [OSPath, Upload, _Source]

Each error names the columns the failing row did have. The rows with Mtime, OSPath and Content came from the scripts source and the rows with OSPath and Upload from the upload source; neither has a Command column, so the comparison could not be evaluated for them.

The answer was right and the output was noisy, and in a notebook with a dozen sources that noise hides the one error that matters.

Artifacts also take parameters, passed as named arguments in the call. Linux.Sys.Crontab declares parameters for the glob it uses to find crontabs, the glob for the scripts they call and a maximum length to read, so a host with crontabs in an unusual place is handled by passing a different glob rather than by writing a new query.

The parameter names are in the artifact's definition, and an unknown parameter is another value the artifact will quietly ignore.

Calling an artifact rather than rewriting its VQL has a further advantage. The artifact carries its preconditions, its parameters and its maintainers' fixes, so a query built on it inherits whatever the next release corrects. Read the artifact's definition once, with velociraptor artifacts show, before relying on its columns.

5

Rows That Are Not There

The loud failure and the silent one

A query can fail in two ways, and they could hardly look more different. Name a plugin that does not exist and VQL refuses to run the query at all. An assistant, or a memory of another tool, can easily suggest a parser for cron files that sounds right:

$ velociraptor query --nobanner "SELECT * FROM parse_crontab(filename='/etc/cron.d/sys-update')" \
    2>&1 | grep '^velociraptor: error' | fold -s -w 90
velociraptor: error: query: Plugin parse_crontab not found. Did you mean parse_auditd 
parse_csv parse_ese parse_ese_catalog parse_evtx parse_journald parse_json_array 
parse_jsonl parse_lines parse_mft parse_ntfs_i30 parse_ntfs_ranges parse_pst 
parse_records_with_regex parse_recyclebin parse_unified_logs parse_usn? 

That failure is a gift. The query stops, the exit code is non-zero, and the message lists the real plugins with similar names. parse_lines is among them, and it is the one this lesson used.

Misspell a column and nothing of the kind happens. The query below asks the right artifact and the right source, and filters on CommandLine instead of Command:

VQL0 rows
SELECT User, Command
FROM Artifact.Linux.Sys.Crontab(source='CronTabs')
WHERE CommandLine =~ '/tmp/'
UserCommand
No rows
CommandLine is not a column of this source. The query ran, matched nothing, and reported no error.

The same query with one column misspelled. No rows, and nothing printed to say why.

The column does not exist, so the comparison is never true, no row passes, and the query finishes normally. On this release it printed nothing at all. The documentation notes that a "Symbol not found" message usually indicates a typo, which is true when the message appears, and the run above shows it does not always appear.

The result is indistinguishable from a host with no matching entries, and it is the same trap as lesson 0.1's skipped collection: an empty result that describes the query, not the endpoint.

FailuresTwo ways a query goes wrong
A plugin or function that does not existThe query fails with an error, and names close matches
A column that does not existThe comparison is never true; no rows, often no message
An artifact without a source namedRows from every source, and errors from the ones without the column
The silent one is the dangerous one

The exit code is part of the record when queries are scripted. The plugin failure returned a non-zero code, which a script can test; the misspelled column returned zero, exactly as a correct query with no matches would. Nothing downstream of a script can tell those two cases apart, so the check has to happen while the query is written.

The habit that catches the silent case is cheap. Before trusting a zero, run the query once without its WHERE clause and look at the columns the rows actually carry, or plant a value you know is there and confirm the query finds it. Both take seconds, and both are faster than explaining a missed finding.

6

Lazy Evaluation and the Cost of a Query

Why LIMIT is fast

VQL does as little work as the query allows. The documentation describes the rule: work is delayed until it is needed, a row that WHERE eliminates skips the evaluation of its other columns, and when a LIMIT is satisfied the query is canceled, along with any stored query feeding it. The difference is easy to measure on the lab machine:

$ time velociraptor query --nobanner "SELECT OSPath FROM glob(globs='/usr/**') LIMIT 3" > /dev/null
real 0.279s
$ time velociraptor query --nobanner --format csv \
    "SELECT count() AS Entries FROM glob(globs='/usr/**') GROUP BY 1"
Entries
247407
real 4.340s

The first query asked for three paths under /usr and stopped in 0.279s, because glob() was canceled as soon as three rows had arrived. The second counted every entry, 247,407 of them, which meant walking the whole tree, and took 4.340s. The plugin is the same; the question changed how much of it ran.

On an endpoint that difference is the user's experience. A query that walks a whole disk competes with whatever the machine is doing, and a hunt runs that query on every machine at once. Three habits follow. Put the most selective condition where it filters earliest, so later stages see fewer rows.

Narrow the glob before filtering, since a pattern that names the folder is cheaper than one that walks the drive and discards most of it. And use LIMIT while developing, to see the shape of the rows before paying for all of them.

ChecklistHabits that keep a query cheap
Narrow the source firstglob(globs='/etc/cron.d/*') before glob(globs='/**')
Filter as early as the question allowsIn the inner query of a foreach, not only the outer one
Develop with LIMITSee the columns before paying for every row
Avoid computing what WHERE will discardHashes and parses belong after the filter

The same discipline applies to the question as a whole. A glob of /** across every host in an estate is occasionally the right query, and when it is, it belongs in a hunt scheduled for a quiet hour with a resource limit, which Module 7 covers. Most of the time the question names a place, and the query should too.

Lazy evaluation is also why a query's runtime is not a measure of how thorough it was. A fast answer may mean an efficient query, or one that stopped as soon as it could.

7

What the Query Did Not Ask

The scope of a correct answer

Every query so far was correct, and the answer they gave is still incomplete. The lab machine has a second script in /tmp/.cache, and asking the crontab artifact about it returns nothing:

VQL0 rows
SELECT User, Command
FROM Artifact.Linux.Sys.Crontab(source='CronTabs')
WHERE Command =~ 'clean.sh'
UserCommand
No rows

The crontab artifact asked about the second script on the lab machine. It has no entry for it.

The artifact is not wrong. It parses crontabs, and the second script is not in one. It is run by a systemd timer: a timer unit that names a service, and a service whose ExecStart line runs the script. Asking that mechanism means reading unit files, which glob() and parse_lines() already do:

VQL1 row
SELECT Path, Line FROM foreach(
  row={ SELECT OSPath FROM glob(globs='/etc/systemd/system/*.service') },
  query={ SELECT OSPath.String AS Path, Line FROM parse_lines(filename=OSPath)
          WHERE Line =~ '^ExecStart=' })
WHERE Line =~ '/tmp/'
PathLine
/etc/systemd/system/cache-clean.serviceExecStart=/bin/sh /tmp/.cache/clean.sh

The same question asked of systemd unit files: the service a timer starts every ten minutes.

The service file is the evidence, and the timer is the schedule: cache-clean.timer names cache-clean.service and fires every ten minutes. A complete finding would read both, so it can say when the script runs as well as what runs. The figure sets the question out as branches, with what each one found.

Runs on a schedule from /tmp?cronLinux.Sys.Crontabfound update.shsystemd timerno artifact askedfound clean.sh by globat, rc.local, profilesnot asked hereunknown

The question is the behavior, and each mechanism is a branch of it. A query answers only the branches it was written for, so the unanswered ones belong in the finding.

The lesson in this is about questions, not syntax. "Is anything scheduled to run from a temporary folder" is a question about behavior, and a host can be configured to schedule work in several places: crontabs, systemd timers, at jobs, startup scripts, shell profiles and more.

A query answers the branches it was written for. A finding that says "no scheduled execution from /tmp" after checking only cron is a statement about cron, presented as a statement about the host.

The fix is to write the scope into the result. Name the mechanisms checked and the ones not checked, and treat the unchecked ones as open rather than clean. Module 3 builds the VQL for the remaining branches; the habit of stating what a query covered starts here.

8

Asking an Assistant

Asking about the behavior, not the mechanism

An assistant is good at VQL syntax and at naming artifacts, and both strengths showed in this session. The first answer, to a question that named cron, was correct and ran first time. Its limit was the question it was given: asked about cron jobs, it answered about cron jobs.

Scheduled execution from a temporary folderCaptured: Claude Opus 5.5, 2 December 2026
  1. You

    How do I find cron jobs that run something from /tmp with Velociraptor?

  2. Assistant

    Use the built-in artifact: SELECT User, Command FROM Artifact.Linux.Sys.Crontab(source='CronTabs') WHERE Command =~ '/tmp/'. It parses /etc/crontab, /etc/cron.d and the user crontabs.

  3. Velociraptor
    VQL1 row
    SELECT User, Minute, Hour, Command
    FROM Artifact.Linux.Sys.Crontab(source='CronTabs')
    WHERE Command =~ '/tmp/'
    UserMinuteHourCommand
    root*/15*/bin/sh /tmp/.cache/update.sh >/dev/null 2>&1

    The same question asked of the built-in crontab artifact, naming the source that holds parsed entries.

  4. You

    On a Linux endpoint, with Velociraptor 0.77.4, I need every way the host is set to run something on a schedule or at boot from a temporary folder (/tmp, /var/tmp, /dev/shm). List the mechanisms, say which built-in artifact covers each and which none does, and give me VQL for the gaps that I can run with velociraptor query.

  5. Assistant

    Cron (system and user crontabs): Linux.Sys.Crontab. Systemd timers and services: they are unit files, and the timer only names a service, so check the service's ExecStart. at jobs, rc.local and shell profiles are further places to look. For systemd, glob the unit folders and read ExecStart lines: SELECT Path, Line FROM foreach(row={ SELECT OSPath FROM glob(globs='/etc/systemd/system/*.service') }, query={ SELECT OSPath.String AS Path, Line FROM parse_lines(filename=OSPath) WHERE Line =~ '^ExecStart=' }) WHERE Line =~ '/tmp/'. Widen the glob to /lib/systemd/system and the user unit folders on a real host.

  6. Velociraptor
    VQL1 row
    SELECT Path, Line FROM foreach(
      row={ SELECT OSPath FROM glob(globs='/etc/systemd/system/*.service') },
      query={ SELECT OSPath.String AS Path, Line FROM parse_lines(filename=OSPath)
              WHERE Line =~ '^ExecStart=' })
    WHERE Line =~ '/tmp/'
    PathLine
    /etc/systemd/system/cache-clean.serviceExecStart=/bin/sh /tmp/.cache/clean.sh

    The same question asked of systemd unit files: the service a timer starts every ten minutes.

The second prompt asked about the behavior instead: every way the host could run something on a schedule from a temporary folder, which built-in artifact covers each, and VQL for the gaps. The reply named systemd timers, pointed out that a timer only names a service so the ExecStart line is what matters, listed further places to look, and gave a query that found the second script.

PromptThe prompt that asks for the whole question
On a Linux endpoint, with Velociraptor 0.77.4, I need every way the host is set to run something on a schedule or at boot from a temporary folder (/tmp, /var/tmp, /dev/shm). List the mechanisms, say which built-in artifact covers each and which none does, and give me VQL for the gaps that I can run with velociraptor query.
  1. every way the host is set to run something on a schedule or at bootasks about the behavior, not one mechanism the asker already thought of
  2. /tmp, /var/tmp, /dev/shmnames the folders, so the regex covers all three
  3. which built-in artifact covers each and which none doesmakes the gaps part of the answer
  4. VQL for the gapsgets queries only where no artifact exists
  5. velociraptor queryasks for something runnable now, on a lab machine

The time the assistant saved was in the syntax of the nested foreach() and in knowing where systemd keeps unit files. What made the result usable was the scope it listed, which turned into the finding's statement of what was and was not checked.

What the finding rests on
  1. HoldsThe crontab artifact found the cron entrysys-update runs /tmp/.cache/update.sh every 15 minutes
  2. FailsThe crontab artifact covers timersit returned nothing for clean.sh, which a timer runs
  3. HoldsThe unit-file query found the timer's servicecache-clean.service ExecStart runs /tmp/.cache/clean.sh
DecisionTwo scheduled scripts in /tmp, not one; the scope of the question decided the answer.

That finding is better than the first one by exactly one script and one sentence of scope, and both came from asking a wider question.

Do

Practice

What did these queries actually ask?
your own Velociraptor

The scenario holds four runs a colleague made on a Linux host while answering the same question as this lesson, and the conclusion they wrote. Read each query and its result, then decide what the conclusion can and cannot say.

Then write the queries yourself on your own machine with velociraptor query. If it runs Linux, list your cron folder with glob(), read one file with parse_lines(), and chain them with foreach().

Run the crontab artifact with and without source='CronTabs' and compare the output. Misspell a column on purpose and see what your release prints. On Windows, ask the same question of scheduled tasks with Artifact.Windows.System.TaskScheduler(), and inspect its sources before filtering.

VQL asks a question by generating rows from plugins, filtering them with WHERE and chaining queries with foreach and LET. It fails loudly on a plugin that does not exist and silently on a column that does not, it does only the work the query requires, and it answers only the question it was written to ask.

Lesson 0.4 looks underneath the plugins, at accessors: how the same path can be read through the operating system, from the raw disk or from an image.

Resources

Velociraptor changes quickly; where its documentation and this lesson disagree, the documentation is newer.

Stuck? Spotted an error?