Stacking and counting
Stack values with AQL: group and aggregate, top and rare, to find the noisy client, the rare request and the odd one out in thousands of records.
top N colandrare N col: the most and least frequent values, with a count.group {col} (aggregate {n = count this, first = (earliest timestamp), last = (latest timestamp)}): a count and a time span per value.- Sort the groups with
sort {-n}and keep the head withtake.
filter event_type == "logs_nginx" | top 3 remote_addrThousands of records look alike. Stacking turns them into a short list where the unusual values stand out.
Who was busiest
filter event_type == "logs_nginx" | top 3 remote_addr
| remote_addr | n |
|---|---|
| 203.0.113.45 | 647 |
| 135.64.176.122 | 24 |
| 139.132.162.34 | 23 |
One address sent 27 times more requests than the next. That is worth a closer look.
When, as well as how many
filter event_type == "logs_nginx" | group {remote_addr} (aggregate {n = count this, first = (earliest timestamp), last = (latest timestamp)}) | sort {-n} | take 10

The busy client was active for only 36 minutes, while the others spread a few requests over weeks. A burst like this is typical of an automated scanner.
What happened once
filter event_type == "logs_nginx" && http_method == "POST" | rare 5 url
The rarest values are where single actions hide: an upload, a login from a new address, a command run once. Rare is not the same as bad, so read what each one is.
Patterns to remember
| Question | AQL |
|---|---|
| Most frequent values | top 10 col |
| Least frequent values | rare 10 col |
| Count and time span per value | group {col} (aggregate {n = count this, first = (earliest timestamp), last = (latest timestamp)}) |
| Count per pair of values | group {col_a, col_b} (aggregate {n = count this}) |
| Only the groups above a threshold | add filter n > 100 after the group |
| The first record per value | group {col} (sort {timestamp} | take 1) |
Check yourself
Try it
On web01, find the POST request that was made only once to the web server. Which URL was it, from which address, and when?
Show the answer
filter event_type == "logs_nginx" && http_method == "POST" | rare 5 url returns two URLs: /quote/ with 115 posts and /wp-content/plugins/wp-file-manager/lib/php/connector.minimal.php with 1. Filter on that URL to see the request: 203.0.113.45 at 02:47:19 UTC, status 200. That is the file upload through WP File Manager that planted the web shell.