Se connecter

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.name is the join key: all events of one sequence must have the same host.name. You can join on several fields (by host.name, user.name).
  • with maxspan=1m limits 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.

Exercices pratiques de cette leçon

Résolvez ces exercices avec une requête sur le lab Elasticsearch réel. Connectez-vous gratuitement pour accéder au lab, aux indices et à la correction automatique.

  1. 1. Office spawns a shell

    Write a sequence that finds WINWORD.EXE followed by powershell.exe on the same host within 1 minute. Graded by the matched events.

  2. 2. Download and execute on Linux

    On a Linux server somebody downloaded a script with curl and ran it with sh shortly afterwards (within 1 minute, same host). Which user.name did this?