CY6: Logging, monitoring and detection

Lesson 3 of 5 · reading 15–25 minutes; practice and project time is on the module page

Writing detection rules

🎯You'll be able to

Write rules with thresholds and time windows for guessing, account takeover, injection attempts and admin changes.

🏠The everyday picture

A bank doesn't phone you for every card payment. It calls when five payments happen in ten minutes in two different cities. The rule is a count, a time window and a pattern.

📘What it really is

📝A worked example

Input: the kit's login log, which contains 40 failed logins from 203.0.113.45 within a few minutes on 29 October.

Steps:

  1. For each failed login, add its time to that address's window and drop entries older than 5 minutes.
  2. When the window holds 10 or more and the address hasn't alerted in the last hour, raise BRUTE_FORCE.
  3. Continue: the remaining failures fall inside the quiet hour, so no more alerts for that address.

Expected output: one BRUTE_FORCE alert for 203.0.113.45, not 31.

🌍Where it's used

📝Case scenario

A college's IT team alerted on every failed login and received 4,000 emails a day. When a real guessing attack happened, the alert was lost among them. A threshold, a window and a quiet period cut alerts to a handful a day, and the next attack was noticed in minutes.

🖱️Try it

Write in plain words a rule for "too many password reset requests for one account". Success: it names a threshold, a window and a quiet period.

⚠️Common mistakes

🛠️For your project

Tests 2, 3, 5 and 6 check the guessing, takeover, admin-change and injection rules against the kit's logs.

✅Quick check

What three parts does a threshold rule usually have?

Show the answer

A count, a time window and what is being counted (grouped by, for example, address).

Why raise severity when injection-like searches got server errors?

Show the answer

An error can mean the input actually broke the query.

← PreviousReading logs you can trust
ProLearners Assist