Lesson 5.3

AQL, step by step

Learn AQL, the Arcsentry query language, one stage at a time: filter, select, sort and take, text and pattern matches, missing values and time literals, with examples checked on the practice case.

20 minEveryone
At a glance for experienced analysts
  • Stages joined by |: filter, select, derive, sort, take, group, aggregate, top, rare.
  • == exact, ~= "(?i)…" regex, in (…), == null for missing; &&, ||, !.
  • Time: @2026-11-24T02:47:19Z, durations like 10minutes. One line: join stages with |. Several lines: one stage per line, no |.
Command line
filter event_type == "logs_nginx" && remote_addr == "203.0.113.77" | select {timestamp, url, http_status_code} | sort {timestamp}

AQL is short to type and easy to read aloud. This lesson builds one query a stage at a time on the practice case. Run each step on web01 as you go.

1. filter: keep the rows you want

filter event_type == "logs_nginx"

37,000-odd rows become the 11,000 web server requests. Add a second condition with &&:

filter event_type == "logs_nginx" && remote_addr == "203.0.113.77"

Eight rows: everything this address asked the web server.

2. select: choose the columns

filter event_type == "logs_nginx" && remote_addr == "203.0.113.77" | select {timestamp, url, http_status_code}

Only three columns come back. Use select !{…} to keep everything except some columns.

3. sort and take, on several lines

A long query reads better with one stage per line. On separate lines, leave the | out: a new line starts a new stage.

filter event_type == "logs_nginx" && remote_addr == "203.0.113.77"
select {timestamp, url, http_status_code}
sort {timestamp}
take 3

sort {timestamp} is oldest first; sort {-timestamp} is newest first. take 3 keeps the first three rows after sorting.

4. Matching text

Write Matches
url == "/quote/" Exactly that value
url ~= "(?i)thumb_cache[.]php" The pattern anywhere in the value, any case
http_method in ("POST", "PUT") One of several values
user_name == null Records with no value recorded
http_status_code != "200" Everything except (status codes are stored as text)

In a pattern, . means any character, so write [.] for a real dot.

5. Time

Times are written with @ and are UTC. Two filter stages in a row work like one joined with &&, which keeps long conditions readable:

filter event_type == "linux_auditd" && user_id == "33"
filter timestamp >= @2026-11-24T02:47:19Z && timestamp < @2026-11-24T02:47:19Z + 10minutes
select {timestamp, process_args}
sort {timestamp}

That is every command run by the web server account (uid 33, www-data) in the ten minutes after the upload: id, uname -a, cat /etc/passwd, cat wp-config.php, a download with curl, running it, a reverse shell and a Python pty.

6. Counting

filter event_type == "logs_nginx" && url ~= "(?i)thumb_cache[.]php" | aggregate {n = count this}

One row: n = 8. Counting per value is the subject of the next lesson.

Check yourself

1. Which stage keeps only the rows that match a condition?
2. How do you match thumb_cache.php anywhere in a URL, ignoring case?
3. How do you find records where user_name was not recorded?

Try it

On web01, count the nginx requests whose URL contains thumb_cache.php, then list them with their time and URL in time order.

Show the answer

filter event_type == "logs_nginx" && url ~= "(?i)thumb_cache[.]php" | aggregate {n = count this} returns 8. Replace the aggregate with select {timestamp, url} | sort {timestamp} to list them: eight GETs from 02:47:49 to 02:50:58, carrying id, uname -a, cat /etc/passwd, a directory listing, cat wp-config.php, which python3 curl wget nc, a curl download and bash /tmp/.l.sh.

Progress is saved in this browser only.