Skip to content
Tutorials Center
My learning

Topics

Lesson 25 of 38 ยท Monitoring and Detection

Detecting Suspicious Activity in the Cloud

Learn practical cloud threat detection: rules vs baselines, brute force and impossible travel detection, privilege escalation sequences, false positives and tuning.

Collecting logs is only the first step. The next question is what to look for. A busy cloud account can produce millions of events a day, and nearly all of them are normal. Detection is the craft of describing the small part that is not normal, precisely enough that a person or a machine can find it quickly without drowning in false alarms.

This lesson introduces the main detection styles and builds four small detectors in Python on invented log data: a brute-force detector, an impossible-travel check, a detector for sensitive configuration changes and a baseline-based anomaly check. They show the logic behind commercial tools, so you can read, write and tune detection rules.

The sample data uses documentation IP ranges (203.0.113.0/24, 198.51.100.0/24, 192.0.2.0/24) and made-up users. Run detections only on logs from systems you own or are authorised to monitor.

Detection styles

Style Idea Strength Weakness
Signature / rule Match a known bad pattern, such as "root login without MFA" Precise, explainable Misses unknown tricks
Threshold Count events in a window, such as 20 failed logins in 5 minutes Simple and effective Needs tuning per environment
Sequence / correlation Several events in order, such as "new access key, then unusual API calls" Finds multi-step attacks More complex to write
Baseline / anomaly Learn normal behaviour per user and flag deviations Can find new attacks Noisy, harder to explain
Threat intelligence Match known bad IPs, domains and hashes Cheap to apply Indicators age quickly

Mature teams use all of them and map each rule to a stage of an attack, often using the MITRE ATT&CK for Cloud matrix: initial access, persistence, privilege escalation, defence evasion, credential access, discovery, exfiltration and impact.

flowchart LR
    A["Initial access<br/>stolen key, phished login"] --> B["Discovery<br/>list users, buckets, roles"]
    B --> C["Privilege escalation<br/>attach admin policy"]
    C --> D["Persistence<br/>new access key, backdoor role"]
    D --> E["Defence evasion<br/>stop logging"]
    E --> F["Exfiltration or impact"]

A simplified attack path. Each step leaves different log traces, and each can have its own detection.

Detector 1: brute force and password spraying

A burst of failed sign-ins from one source suggests guessing. A spray is the reverse: one source tries a few common passwords against many accounts. Counting failures per source and per target in a time window finds both.

Python Find brute force and password 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.

The same IP failing five times against alice is brute force; 192.0.2.44 touching four different accounts is spraying. The success from a different address two minutes later is a further clue: possibly the attacker guessed correctly from another source. Good rules also check what happened after a suspicious burst.

Preventive controls help here too: multi-factor authentication, account lockout or throttling, and conditional access policies.

Detector 2: impossible travel

If an account signs in from Paris and, twenty minutes later, from Sydney, it is physically impossible for one person to do both. The test is simple: distance divided by time must not exceed a plausible speed.

Python Detect impossible travel between sign-ins

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 products have to cope with VPNs, mobile networks and cloud proxies that make locations unreliable, so a hit raises the risk score of a session instead of automatically blocking it.

Detector 3: sensitive changes and sequences

Some single events are alarming enough to alert by themselves: root account usage, a policy that grants *:*, a storage bucket made public, logging disabled, a new identity provider added. Sequences are even better evidence. This detector looks for "new access key followed by a burst of discovery calls from a new IP" within ten minutes.

Python Detect a persistence-then-discovery sequence

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.

Detector 4: baseline anomalies

Instead of fixed numbers, compare today's behaviour with the user's own history. A simple and robust measure is the z-score: how many standard deviations a value lies from the mean.

Python Flag an unusual download volume

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 single large download is only a hint. It may be a legitimate migration. Combine it with other signals (new device, unusual hour, new region) before paging anyone.

Reduce false positives

  • Tune with context: exclude known scanners, maintenance windows and service accounts with predictable behaviour, but write down each exception and review it.
  • Score instead of block: add up weak signals into a risk score.
  • Measure rules: track how many alerts each rule produces and how many were real, and retire or fix noisy ones.
  • Test your detections: replay old incidents or run safe, authorised simulations in a test account to prove the rule fires.
  • Document the response: every alert needs an owner and a runbook; see alerting and SIEM and incident response.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. One IP fails to sign in once each against 40 different accounts. Which pattern is this?

    Spraying tries few passwords across many accounts, which avoids per-account lockouts. Counting distinct targets per source finds it.
  2. 2. Why is impossible-travel detection better used as a risk signal than as an automatic block?

    Legitimate users on VPNs or mobile networks can look like they teleport, so combine the signal with others.
  3. 3. What does a z-score of 40 for today's download volume tell you?

    A z-score counts standard deviations from the mean. Values beyond about 3 are unusual.
  4. 4. What is the main advantage of sequence (correlation) rules?

    Individual events may look harmless; a meaningful order of events, such as a new key followed by discovery from a new address, is strong evidence.

Summary

  • Combine rules, thresholds, sequences, baselines and threat intelligence, and map them to attack stages.
  • Count failures per source and per target to find brute force and spraying; check what happens after.
  • Impossible travel and baseline z-scores are risk signals, best combined with other evidence.
  • Alert directly on high-impact changes, especially disabling logging, public exposure and new privileged access.
  • Tune, measure and test your detections, and attach a runbook to every alert.

Next: Alerting and SIEM