sequence by
14 min · 2 exercice(s)
The real power of EQL is the sequence: a list of events that must happen in this order.
sequence by host.name with maxspan=1m
[process where process.name == "WINWORD.EXE"]
[process where process.name == "powershell.exe"]- Each
[ … ]is an event query. by host.nameis the join key: all events of one sequence must have the samehost.name. You can join on several fields (by host.name, user.name).with maxspan=1mlimits the time between the first and the last event (s,m,h,d).
The result contains one entry per matching sequence. In the lab table, the column sequence tells you which events belong together.
Why sequences matter
A single event is often harmless: Word starts every day, PowerShell is used by admins. Word followed by PowerShell on the same host within seconds is a classic sign of a malicious macro (MITRE ATT&CK T1566.001, Spearphishing Attachment). Sequences let you express behaviour instead of single indicators.
🔎 Pour aller plus loin : fonctions, pièges et pratique
Sequence options
| Syntax | Meaning |
|---|---|
sequence by host.name |
shared join key for all steps |
[ … ] by user.name |
additional join key per step (can differ between steps) |
with maxspan=5m |
the whole sequence must fit into 5 minutes |
[ … ] with runs=3 |
the step must occur 3 times in a row |
until [ … ] |
stop: an event that ends the sequence early (e.g. process end) |
![ … ] |
a missing event: this must not happen at this position |
How matching works
EQL processes events in time order and keeps a small state machine per join key. Every event that matches step 1 starts a candidate. Candidates advance when the next step matches and expire when maxspan is exceeded. That's why sequences are efficient even on large data, as long as the first step is selective.
Write selective first steps
[any where true] as a first step creates a candidate for every event. Start with the rarest event of the chain (e.g. Office starting a shell, not "a process started").
Sequences in Elastic Security
Event correlation rules alert on every matching sequence. Many prebuilt Elastic rules are sequences, for example "process started by Office application followed by network connection". Reading prebuilt rules is one of the best ways to learn EQL.