Iniciar sesión

Practice: reading and matching log lines

12 min · 2 ejercicio(s)

Cheat sheet

You want Pattern
A word / anything up to a space %{WORD:x} / %{NOTSPACE:x}
A number %{INT:x}, %{NUMBER:x}
An IP or host %{IP:x}, %{IPORHOST:x}
Text in brackets \[%{DATA:x}\]
Text in quotes "%{DATA:x}" or %{QS:x}
The rest of the line %{GREEDYDATA:x} (only at the end)
A literal [, (, . \[, \(, \.

Typical mistakes

  • Missing the exact spacing. INFO [auth] has two spaces, a pattern with one doesn't match. Use \s+.
  • Forgetting escapes. sshd[%{INT:pid}] is an invalid regex, sshd\[%{INT:pid}\] works.
  • Normal quotes around a pattern with backslashes. In ES|QL use """…""".
  • Trusting a count without checking nulls. Run once with KEEP message, field and look at rows where the field is null.

Ejercicios prácticos de esta lección

Resuelve estos ejercicios con una consulta en el laboratorio Elasticsearch real. Inicia sesión gratis para acceder al laboratorio, las pistas y la corrección automática.

  1. 1. Allowed or blocked?

    Extract the firewall verdict (ALLOW or BLOCK) into event.action:

    Mar  9 00:06:56 fw-edge-01 kernel: [FW-BLOCK] IN=wan0 OUT= SRC=162.234.241.182 DST=192.0.2.10 LEN=44 PROTO=TCP SPT=39887 DPT=3389
  2. 2. Scanning for accounts

    sshd logs a line when someone tries an account that doesn't exist:

    Mar  9 00:21:07 srv-web-01 sshd[27460]: Invalid user ubuntu from 112.22.254.249 port 58777

    Extract user.name and source.ip from these lines.