Writing the rule: Sigma in depth

Unit 2 of 5 in Detection engineering.

You will be able to write a Sigma rule with modifiers, conditions, a filter and a correlation, and explain what each part does.

Lesson

The parts of a rule

The Sigma specification lists the parts of a rule. Mandatory: a title, a log source and a detection. Optional but valuable: a globally unique id (a random version 4 UUID), a status, a description, references, author, date and modified date, a list of fields worth showing the analyst, a list of known false positives, a level and tags. The specification says to give a rule a new id when its logic changes in a big way, when you derive a new rule from it and keep both active, or when you merge rules; the related field records the relationship as derived, obsolete, merged, renamed or similar.

The status field tells readers how far to trust the rule: stable may be used in production; test is mostly stable but may need adjusting for the environment; experimental could be noisy; deprecated has been replaced; unsupported cannot be used as written. Tags are namespaced with a dot, for example attack.t1234 for ATT&CK technique 1234. Use all of these. A rule with no status and no known false positives asks the next reader to guess.

Selections: maps are AND, lists are OR

Inside the detection, a search identifier is a named group of matches. The specification gives two shapes. A map is a set of field and value pairs, and all pairs must match (logical AND). A list of values for one field matches if any value matches (logical OR), and a list of maps matches if any map matches. Values are treated as case-insensitive strings, with * and ? as wildcards, while regular expressions are case-sensitive by default.

Read this slowly, because it is the source of many wrong rules. A map with an event identifier of two values and a user name means 'either event, and that user'. When a rule fires on far too much, check whether a list should have been a map.

Modifiers and conditions

Modifiers change how a value is matched, and are appended to the field name with a pipe: contains, startswith and endswith for text, re for regular expressions, cidr for network ranges, gt and lt for numbers, base64offset for text that may appear encoded, and others. Lists of values are joined with OR, and the all modifier changes that to AND. It is for cases like a command line with several parameters in any order; a single value is not allowed to use it.

The condition combines search identifiers with and, or, not and brackets, and with 'one of' and 'all of' patterns such as 'selection*'. Precedence from loosest to tightest is or, and, not, then the 'x of' expressions and brackets. The specification discourages 'all of them' because it stops downstream users from generically filtering unwanted matches; use 'all of selection*' and keep filter identifiers named with a common prefix. Conditions also let a rule exclude a known false positive, for instance 'selection and not filter_admin'.

Filters: keep your exceptions out of the shared rule

Every organization has its own harmless exceptions: a management agent, a jump host, a scanner. Sigma filters let you keep them in separate files that look like rules but use a filter section instead of a detection, and that name the rules they apply to by name or id. The documentation says this lets you split exclusions out, apply one filter to several rules, and keep the original rule in its pristine state, which makes updating from rule packs easier. When you convert, a command-line option applies the filter to the generated query.

The habit to learn: put what is true everywhere in the rule and what is true only for you in a filter. Then your tuning survives the next upstream update, and anyone can review your exceptions on their own.

Correlation: a behaviour made of several events

Some behaviour is invisible in one event. Many failed sign-ins followed by a successful one is the textbook example. Sigma correlation rules express this on top of ordinary rules. The specification defines types: event_count (how many matching events), value_count (how many distinct values of a field), temporal (several different rules matching within a timespan) and temporal_ordered (in a given order). A correlation names the rules it refers to, a group-by that sets the scope (for example per user, or per user and host), a timespan, and a condition such as a count threshold. It can also set a level, so single hits stay low or informational and the correlation raises it.

The specification is also honest about limits. A target system that cannot recognise the order of events may produce false positives from differently ordered events. If it only recognises fixed time windows, a one-hour span only matches events inside a single clock hour, so a pattern that straddles two hours could be missed. Whenever you convert a correlation, test it near window edges.

Key points

Sources

Practice in the labs

Write rules against Linux audit events, process events and a sign-in sequence, then check them in the Detection Lab.

Also try, in the simulators

Knowledge check

  1. In Sigma, a selection has two fields, each with one value. What does it mean? Answer: Both fields must match in the same event (logical AND). The specification says all elements of a map are joined with a logical AND; it is a list of values for one field that is joined with OR.
  2. Why keep a site-specific exception in a Sigma filter instead of editing the rule? Answer: The shared rule stays unchanged, so updates are easy and your exceptions can be reviewed separately. The Sigma documentation says filters let you split exclusions out, apply them to several rules and keep the original rule in its original state, which eases updating from rule packs.
  3. A correlation rule uses a one-hour timespan. What limit does the specification warn about? Answer: Some systems only match events inside a single clock hour, so a pattern across two hours could be missed. The correlation specification warns that where a target recognises only static time boundaries, events split across two hours might not match, causing false negatives.
  4. Which condition style does the specification prefer, and why? Answer: 'all of selection*', because 'all of them' stops downstream users filtering unwanted matches. The specification discourages 'all of them' because it prevents generic filtering of unwanted matches downstream, and points to 'all of' with a search-identifier pattern as the preferred method.

Back to the syllabus or see all classes.

Related