Skip to content
Tutorials Center
My learning

Topics

Lesson 15 of 37 ยท Detection Rules and Correlation

Threshold Rules, Brute Force and Password Spraying

Write threshold and sliding-window rules that detect brute force, password spraying and credential stuffing from logs. Runnable Python examples on synthetic data only.

The most common first detection is a threshold rule: alert when something happens N times within a time window. Used well, it catches password guessing and scanning. Used badly, it floods the queue. This lesson builds threshold rules from simple to realistic and shows why one rule is not enough for all guessing styles.

All data is synthetic. Never run guessing tools against accounts or systems you do not own.

Three guessing styles

Style Pattern What you see in logs
Brute force Many passwords against one account Many failures, one user, one or few IPs
Password spraying A few common passwords against many accounts Few failures per user, many users, one IP
Credential stuffing Leaked username and password pairs from other breaches Many users, mostly failures, some success, many IPs, often via web or API

Each needs a different grouping field, which is why you write several rules.

Fixed and sliding windows

A fixed window counts per clock bucket (for example each minute). An attacker who sends 4 failures at 10:00:59 and 4 at 10:01:01 never exceeds a threshold of 5 in either bucket. A sliding window looks at the previous N minutes from every event, so it catches this.

Python Sliding-window brute-force 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.

Clearing the queue after an alert avoids a storm of duplicates. Real SIEMs call this alert throttling or suppression.

Password spraying rule

Group by source IP and count distinct users that failed.

Python Distinct-user count for spraying

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.

Spraying stays below per-account lockout limits, so the per-IP distinct-user view catches it while a per-account threshold misses it. Attackers also spread attempts over many IPs; then group by user-agent, ASN, or the target application instead.

Failure then success

The most important variation is failures followed by a success from the same source, because that suggests the guessing worked.

Python Failures followed by success

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.

Choosing thresholds

  • Look at your data first. Chart typical failures per user per hour; set the limit above normal noise.
  • Start conservative, then tighten.
  • Exclude known sources: your own scanners, test accounts, and monitoring probes (documented!).
  • Use different thresholds per context: VPN and web logins fail more than domain controller logons.
  • Pair with outcome: failures alone are medium; failures then success is high.

Alert on lockouts of many accounts at once (Windows event 4740). It often signals spraying that bumped into the lockout policy.

Equivalent logic in SIEM languages (read-only)

Splunk SPL:

TEXT
index=auth action=failure
| bin _time span=5m
| stats count dc(user) as users by _time, src_ip
| where count >= 20 OR users >= 8

Sentinel KQL:

TEXT
SigninLogs
| where ResultType != 0
| summarize failures = count(), users = dcount(UserPrincipalName) by bin(TimeGenerated, 5m), IPAddress
| where failures >= 20 or users >= 8

Both are fixed 5-minute buckets, simple but with the boundary weakness described above.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which pattern describes password spraying?

    Spraying avoids per-account lockouts by trying few passwords on many accounts.
  2. 2. Why is a sliding window better than a fixed window?

    A fixed bucket can split a burst in two so neither half reaches the threshold.
  3. 3. What field do you count to detect spraying from one IP?

    Many different users failing from one source indicates spraying.
  4. 4. What raises the severity of a brute-force alert?

    Success after many failures suggests the guessing worked.

Summary

  • Brute force, spraying and credential stuffing differ in what they group and count.
  • Sliding windows avoid bucket-edge gaps; throttle repeats after alerting.
  • Count distinct users per source for spraying; correlate failures with a later success.
  • Set thresholds from real data and exclude documented benign sources.

Next: Correlation Rules and Event Sequences