Reference

AQL query language

AQL is the query language behind Arcsentry's Hunt view, detection rules and AI investigator. A query is a pipeline you read top to bottom: narrow with filter, shape with group, rank with sort, bound with take.

A first query

filter event_code == "4625"
group {source_ip} (aggregate {attempts = count this, accounts = (dcount user_target_name)})
sort {-attempts}
take 10

Run against Windows Security event logs, this lists the ten addresses with the most failed logons and how many accounts each one tried. Each line is one stage, and each stage works on the rows the previous one produced. Write one stage per line, or several on one line joined with |; a line never starts or ends with |.

You rarely have to start from a blank page: ask a question in plain English in the Hunt view and Arcsentry shows the AQL it will run, ready to edit.

Scope: what a query runs over

Which evidence, which event type and which time window a query reads are chosen outside the query: in the Hunt view's pickers, or with --evidence, --event-type, --time-start and --time-end on the command line. The query itself only describes what to do with those rows.

  • Every row has the columns of its event type plus the core columns: id, host_id, event_type, timestamp, timestamp_ms, source_path, user_context, event_summary, verdict, tags, notes, mitre_techniques and others.
  • The artifact library lists the fields each parser records, with their types.
  • When several types are in scope, start with filter event_type == "…" or event_type in (…).
  • An empty result is a real answer: no matching rows in that scope.

Stages

StageWhat it does
filter <condition>Keep the rows where the condition is true. After an aggregate it filters the groups.
select {a, b = expr}Keep and name columns. select !{a, b} keeps everything except a and b.
derive x = exprAdd computed columns. In derive {x = …, y = x + 1} later items can use earlier ones.
sort {a, -b}Order rows; a leading minus sorts descending.
take N, take A..BKeep the first N rows, or rows A to B. Sort first if the order matters.
group {k} (aggregate {n = count this})One row per key with the measures you name.
group {k} (sort … | take 1)The first row per key (or the top N with take N).
aggregate {…}One row of measures over the whole scope.
top N col, rare N colThe most or least frequent values of a column, with a count.
window rows:-N..0 (derive {…})Moving and running calculations after a sort: averages, sums, rank, lag and lead.
join s=(from scope | select {…}) (cond)Correlate rows with other rows of the scope. side:left makes it an outer join.
append (…)Stack the rows of a second pipeline with the same columns.
search_all "word"Full-text search over every field.
sessionize key maxpause:SECONDSNumber sessions per key, starting a new one after a gap. Always last.
# commentIgnored.

Operators and values

WriteMeaning
== != < > <= >=Comparisons. == is an exact match; == null tests for a missing value.
&& || !And, or, not. Use parentheses to group.
col ~= "(?i)pattern"Regular-expression match anywhere in a text value. Start with (?i) to ignore case. A literal dot is [.].
col in ("a", "b")One of several values.
(col | in 1..10)A range of numbers.
a ?? bThe first value that is not null.
f"{user} from {ip}"Build text from columns.
$keyRead a key from the event's data (Windows event log fields, for example). Typed columns are faster, so prefer them when they exist.
"c:\\windows", r"c:\windows"Text. The r form takes backslashes literally.
case [cond => value, true => other]Choose a value by condition.

Time

  • Set the main time window as scope (Hunt view, or --time-start and --time-end). Inside a query, compare timestamp with literals.
  • Dates and times: @2026-06-01, @2026-06-01T15:00:00Z.
  • Durations: 30seconds, 90minutes, 2hours, 7days, 1weeks, 3months, for example timestamp >= @2026-05-26T15:00:00Z && timestamp < @2026-05-26T15:00:00Z + 1hours.
  • Relative: timestamp > ago "7 days".
  • Buckets: startofhour, startofday, startofweek, startofmonth, hour_of, day_of_week, bin s"hour" timestamp.
  • Records without a time keep a null timestamp. They are never given an invented one.

Functions

KindFunctions
Aggregatescount this, dcount, sum, min, max, average, median, percentile, stdev, variance, values, earliest, latest, any, all
Textlower, upper, trim, strlen, substr, split, replace, regex_extract, regex_replace, starts_with, ends_with, lpad, rpad
Conversionto_int, to_float, to_string, to_timestamp, as int, as timestamp
Timetime_diff, duration_seconds, date_part, the bucket functions above
Listsmvcount, mvjoin, mvindex, mvfirst, mvlast, mvdedup, mvsort, makemv
Conditionaliff, ifnull, nullif, coalesce2, coalesce3, case
Sequencesprev, next, row_num, running_count, zscore, rate_of_change, and lag, lead, rank inside window
Encodingmd5, sha1, sha256, base64_encode, base64_decode, to_hex, from_hex, url_encode, url_decode
URLsparse_url_host, parse_url_path, parse_url_query, parse_url_scheme, parse_url_port
JSON$key, json_extract, json_extract_int
Mathmath.round, math.floor, math.ceil, math.abs, math.sqrt, math.log, math.pow

Functions take their parameters first and the column last, and calls with arguments go in parentheses inside a stage: derive d = (startofday timestamp).

Examples

Each example below was run on a host from our Windows demo case and returned the rows described. The line above each query names the event type to put in scope.

Failed logons, newest first

Event type: evtx_security

filter event_code == "4625"
select {timestamp, user_target_name, source_ip, event_log_logon_type}
sort {-timestamp}
take 5

In the demo case this returns the password guessing against m.lund and a.berg.

The most common event codes

Event type: evtx_security

top 5 event_code

Successes and failures per account in one pass

Event type: evtx_security

filter event_code in ("4624", "4625")
group {user_target_name} (aggregate {
    ok = (sum (iff (event_code == "4624") 1 0)),
    failed = (sum (iff (event_code == "4625") 1 0))
  })
sort {-failed}
take 5

In the demo case a.berg tops the list with 15 failures and 5 successes.

Who logged on from where

Event type: evtx_security

filter event_code == "4624"
group {source_ip, user_target_name} (aggregate {n = count this})
sort {-n}
take 5

Logon types, with distinct accounts per type

Event type: evtx_security

filter event_code == "4624"
group {event_log_logon_type} (aggregate {n = count this, accounts = (dcount user_target_name)})
sort {-n}

When interactive logons happen (day of week and hour)

Event type: evtx_security

filter event_code == "4624" && event_log_logon_type != "3 - NETWORK"
derive {hr = (hour_of timestamp), dow = (day_of_week timestamp)}
group {dow, hr} (aggregate {n = count this})
sort {-n}
take 5

Group logons into sessions with a 10-minute gap

Event type: evtx_security

filter event_code == "4624"
sort {timestamp}
take 200
sessionize user_target_name maxpause:600

sessionize adds a _session_id column. It always runs last, so put take above it.

Remote Desktop sessions by user and source

Event type: evtx_microsoft_windows_terminalservices_localsessionmanager_operational

filter event_code in ("21", "25") && source_ip != "LOCAL"
group {user_name, source_ip} (aggregate {n = count this})
sort {-n}
take 5

In the demo case this finds the RDP takeover of a.berg's session from 10.211.55.2.

Services installed outside the Windows folder

Event type: evtx_system

filter event_code == "7045"
derive {svc = $servicename, img = $imagepath, acct = $accountname}
filter !(img ~= "(?i)^c:[\\\\]windows[\\\\]")
select {timestamp, svc, img, acct}
sort {-timestamp}
take 5

$name reads a key from the event's data.

Tools of interest in Prefetch

Event type: prefetch

filter process_executable ~= "(?i)(rclone|7z|psexec|net[.]exe|whoami)"
select {timestamp, process_executable, run_count}
sort {-timestamp}
take 5

First and last seen per publisher in Amcache

Event type: amcache

group {file_publisher} (aggregate {
    first_seen = (earliest timestamp),
    last_seen = (latest timestamp),
    n = count this
  })
sort {-n}
take 3

The rarest service start types

Event type: services

rare 3 service_start_type

Search every field for a word

Event type: shimcache

search_all "powershell"

Full-text search covers every field of the type in scope. This example comes from the product's own test suite.

When to use SQL instead

AQL covers almost every investigative question. For the few analyses it cannot express, the same scope can be queried with read-only SQL: percentile ranks and quartiles, expanding a list into one row per value, set operations such as EXCEPT, and correlated subqueries. SQL reads from a table named scope that already carries the evidence, type and time window, so you never repeat them in the statement.

SELECT user_target_name, count(*) AS failures
FROM scope
WHERE event_code = '4625'
GROUP BY user_target_name
ORDER BY failures DESC
LIMIT 10

Only a single SELECT or WITH statement runs, and statements that change data are refused.

Where AQL is used

  • Hunt view: type AQL, or ask in plain English and edit the AQL Arcsentry shows.
  • Command line: arcsentry query --aql '…', see the query command.
  • Detection rules: each arrow carries an AQL body.
  • The AI investigator writes AQL too, and shows every query it runs.