Skip to content
Tutorials Center
My learning

Topics

Lesson 14 of 37 ยท Detection Rules and Correlation

Detection Rule Basics: Signatures, Behavior and Anomalies

Learn the main kinds of SIEM detection rules, how to write a clear rule with logic, data, severity and response, and build a small rule engine in Python.

A detection rule is a precise statement of "this pattern in the data deserves a human's attention". Good rules find real attacks with few false alarms and explain themselves. Bad rules wake people at night for nothing. This lesson covers the rule types and a template for writing them.

Three families

Family Idea Strength Weakness
Signature / indicator Match a known bad value (IP, hash, domain, string) Simple, accurate Easy to evade, needs fresh intel
Behavior Match a suspicious action or sequence (Office spawns shell) Catches new tools Needs careful tuning
Anomaly / statistical Flag deviation from a baseline (10x normal logins) Finds the unknown Noisy, hard to explain

The most durable detections target behavior, because attackers can change a file name or an IP address in seconds but cannot easily avoid the actions their goal requires, such as creating an account or dumping credentials.

Anatomy of a good rule

Write every rule as a small document:

  1. Name: what it detects, in plain words.
  2. Description and rationale: why this matters.
  3. Data source: which logs it needs (and the fields).
  4. Logic: the condition.
  5. Severity: how urgent if true.
  6. Known false positives: what benign thing looks the same.
  7. Response guidance: what the analyst should check first.
  8. Mapping: the ATT&CK technique (chapter 8).
  9. Owner and review date.

A simple rule engine

Python Evaluate rules written as data

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Real SIEMs express the same idea in their query language or in YAML rules; the structure (name, test, severity) is identical.

Anomaly detection in one example

A simple baseline compares today's count with the user's normal range.

Python Simple statistical baseline

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

A z-score counts how many standard deviations a value is above the average. Above 3 is rare under normal conditions. Anomalies are leads, not verdicts: a sudden spike might be a product launch.

Rules as code

Treat rules like software:

  • Store them in version control with review.
  • Test each rule against sample events that should and should not match.
  • Roll out in report-only mode first, review the hits, then turn on alerting.
  • Retire rules that no longer fire or are always noise.
Python Unit-test a rule

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

"Time of day" rules need the user's or site's local time. Store UTC, convert using the right zone before comparing hours.

Choosing severity

Severity combines confidence (how likely this is malicious) and impact (how bad if it is). A low-confidence alert on a critical asset may outrank a high-confidence alert on a lab machine. Write severity logic down so analysts understand it.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Why are behavior-based rules more durable than IP-based ones?

    Indicators like IPs change quickly; behaviors tied to an attacker's goals are harder to avoid.
  2. 2. What is a z-score above 3 telling you?

    It is a statistical lead of rare deviation, not proof of malice.
  3. 3. What should you do before enabling alerting on a new rule?

    Reviewing hits first reveals false positives before analysts are interrupted.
  4. 4. Which item belongs in a rule's documentation?

    Analysts need to know what benign activity looks similar and what to check first.

Summary

  • Rules fall into signature, behavior and anomaly families; behavior rules last longest.
  • Document each rule: logic, data, severity, false positives, response and owner.
  • Treat rules as code: version, test, roll out in report-only mode, retire.
  • Severity weighs confidence and impact.

Next: Threshold and Brute-Force Rules