TExcelTAD
Home › Cloud & Container Security › Cloud Detections: Root Use, MFA, Keys and Policy Changes

Cloud Detections: Root Use, MFA, Keys and Policy Changes

Audit logs only help if someone reads them, and nobody reads millions of events by hand. Detections are rules that pick out the handful of events that mean "a person should look at this now". In the cloud, a short list of rules covers a surprising share of real attacks, because attackers need the same few steps: use powerful credentials, weaken authentication, create credentials of their own, widen permissions, and blind the logging. This lesson writes those rules over synthetic CloudTrail events, shows one in Sigma's portable format, and discusses how to keep them quiet enough to be useful. Sigma Rules and Detection as Code cover the engineering side in depth.

The core rule set

Rule Event pattern (CloudTrail) Why
Root user activity userIdentity.type = Root, any event except a few AWS-initiated ones the root user should be used almost never; any use needs a reason
Console login without MFA eventName = ConsoleLogin, additionalEventData.MFAUsed = No, responseElements.ConsoleLogin = Success password-only access to the console
MFA removed DeactivateMFADevice, DeleteVirtualMFADevice a classic step before taking over an account
New credentials for someone else CreateAccessKey, CreateLoginProfile, UpdateLoginProfile where requestParameters.userName ≠ caller persistence and takeover (IAM escalation)
Privilege change AttachUserPolicy, AttachRolePolicy, PutUserPolicy, PutRolePolicy, CreatePolicyVersion, UpdateAssumeRolePolicy, AddUserToGroup escalation, especially to AdministratorAccess
Resource opened to the world AuthorizeSecurityGroupIngress with 0.0.0.0/0 or ::/0, PutBucketPolicy/PutBucketAcl making a bucket public, DeleteBucketPublicAccessBlock exposure (network, storage)
Logging tampered StopLogging, DeleteTrail, UpdateTrail, PutEventSelectors defense impairment (audit logs)
Burst of denied calls ≥ N AccessDenied errors from one principal in M minutes across several services someone mapping what a stolen key can do

Azure and GCP have direct equivalents (Microsoft.Authorization/roleAssignments/write, SetIamPolicy, CreateServiceAccountKey, Entra ID "User registered security info" / "Admin deleted security info", diagnostic-setting and sink deletions).

A small rule engine

The rules below are Python predicates over parsed events; the threshold rule keeps per-principal state. The 14 events are a synthetic morning in the lab account, mixing normal operations with one attack.

python · try it yourself
import json
from collections import defaultdict, deque
from datetime import datetime, timedelta

E = lambda **kw: kw
events = [
 E(t="07:58:10", name="ConsoleLogin", src="signin", who="IAMUser:alice", ip="192.0.2.15", mfa="Yes", ok=True),
 E(t="08:02:44", name="RunInstances", src="ec2", who="AssumedRole:ci-deploy", ip="10.10.0.70"),
 E(t="08:15:03", name="ConsoleLogin", src="signin", who="Root:root", ip="203.0.113.66", mfa="No", ok=True),
 E(t="08:15:40", name="ListUsers", src="iam", who="Root:root", ip="203.0.113.66"),
 E(t="08:16:12", name="DeactivateMFADevice", src="iam", who="Root:root", ip="203.0.113.66", req={"userName": "bob"}),
 E(t="08:17:01", name="CreateAccessKey", src="iam", who="Root:root", ip="203.0.113.66", req={"userName": "bob"}),
 E(t="08:20:00", name="DescribeInstances", src="ec2", who="IAMUser:bob", ip="198.51.100.9"),
 E(t="08:20:05", name="ListSecrets", src="secretsmanager", who="IAMUser:bob", ip="198.51.100.9", err="AccessDenied"),
 E(t="08:20:07", name="ListFunctions", src="lambda", who="IAMUser:bob", ip="198.51.100.9", err="AccessDenied"),
 E(t="08:20:09", name="ListRoles", src="iam", who="IAMUser:bob", ip="198.51.100.9", err="AccessDenied"),
 E(t="08:20:12", name="GetBucketPolicy", src="s3", who="IAMUser:bob", ip="198.51.100.9", err="AccessDenied"),
 E(t="08:21:30", name="AttachUserPolicy", src="iam", who="Root:root", ip="203.0.113.66",
   req={"userName": "bob", "policyArn": "arn:aws:iam::aws:policy/AdministratorAccess"}),
 E(t="08:22:10", name="StopLogging", src="cloudtrail", who="IAMUser:bob", ip="198.51.100.9",
   req={"name": "arn:aws:cloudtrail:eu-west-1:123456789012:trail/org-trail"}),
 E(t="08:30:00", name="AuthorizeSecurityGroupIngress", src="ec2", who="AssumedRole:ci-deploy", ip="10.10.0.70",
   req={"groupId": "sg-bastion", "cidrIp": "10.10.5.0/26", "toPort": 22}),
]
PRIV = {"AttachUserPolicy", "AttachRolePolicy", "PutUserPolicy", "PutRolePolicy", "CreatePolicyVersion", "UpdateAssumeRolePolicy"}
rules = {
    "root-activity": (lambda e: e["who"].startswith("Root:"), "HIGH"),
    "console-no-mfa": (lambda e: e["name"] == "ConsoleLogin" and e.get("ok") and e.get("mfa") == "No", "HIGH"),
    "mfa-removed": (lambda e: e["name"] in ("DeactivateMFADevice", "DeleteVirtualMFADevice"), "HIGH"),
    "key-for-other-user": (lambda e: e["name"] in ("CreateAccessKey", "CreateLoginProfile", "UpdateLoginProfile")
                           and e.get("req", {}).get("userName") != e["who"].split(":")[1], "HIGH"),
    "privilege-change": (lambda e: e["name"] in PRIV, "MEDIUM"),
    "admin-policy-attached": (lambda e: e["name"] in PRIV and "AdministratorAccess" in json.dumps(e.get("req", {})), "CRITICAL"),
    "logging-tampered": (lambda e: e["src"] == "cloudtrail" and e["name"] in ("StopLogging", "DeleteTrail", "UpdateTrail", "PutEventSelectors"), "CRITICAL"),
    "world-open-ingress": (lambda e: e["name"] == "AuthorizeSecurityGroupIngress" and e.get("req", {}).get("cidrIp") in ("0.0.0.0/0", "::/0"), "HIGH"),
}
DENY_N, DENY_WINDOW = 4, timedelta(minutes=5)
denied = defaultdict(deque)

alerts = []
for e in events:
    ts = datetime.strptime(e["t"], "%H:%M:%S")
    for name, (pred, sev) in rules.items():
        if pred(e):
            alerts.append((e["t"], sev, name, e["who"], e["name"]))
    if e.get("err") == "AccessDenied":
        q = denied[e["who"]]
        q.append((ts, e["src"]))
        while ts - q[0][0] > DENY_WINDOW:
            q.popleft()
        if len(q) == DENY_N and len({s for _, s in q}) >= 3:
            alerts.append((e["t"], "MEDIUM", "access-denied-burst", e["who"], f"{DENY_N} denials, {len({s for _, s in q})} services"))

for t, sev, rule, who, what in alerts:
    print(f"{t} {sev:8} {rule:22} {who:22} {what}")
print(f"\n{len(events)} events, {len(alerts)} alerts, {len({a[2] for a in alerts})} distinct rules fired")
08:15:03 HIGH     root-activity          Root:root              ConsoleLogin
08:15:03 HIGH     console-no-mfa         Root:root              ConsoleLogin
08:15:40 HIGH     root-activity          Root:root              ListUsers
08:16:12 HIGH     root-activity          Root:root              DeactivateMFADevice
08:16:12 HIGH     mfa-removed            Root:root              DeactivateMFADevice
08:17:01 HIGH     root-activity          Root:root              CreateAccessKey
08:17:01 HIGH     key-for-other-user     Root:root              CreateAccessKey
08:20:12 MEDIUM   access-denied-burst    IAMUser:bob            4 denials, 4 services
08:21:30 HIGH     root-activity          Root:root              AttachUserPolicy
08:21:30 MEDIUM   privilege-change       Root:root              AttachUserPolicy
08:21:30 CRITICAL admin-policy-attached  Root:root              AttachUserPolicy
08:22:10 CRITICAL logging-tampered       IAMUser:bob            StopLogging

14 events, 12 alerts, 8 distinct rules fired

Read as a story, the alerts reconstruct the attack without any other data: someone signs in to the root user without MFA from an unknown address, removes bob's MFA, creates a key for bob; bob's new key immediately probes four services and is denied (the burst rule catches it); root then makes bob an administrator, and bob stops the trail. Alice's MFA login, CI's instance launch and CI's narrow SSH rule from the admin range raise nothing.

Root activity fires five times. In a real deployment those would be grouped into one incident (one actor, one session); alert grouping is as important as the rules (Alert Fatigue).

The same rule in Sigma

Detections are better kept as portable rules than as code in one SIEM. One of the rules above in Sigma format (the field names are CloudTrail's, as Sigma's aws/cloudtrail log source expects):

yaml
title: AWS CloudTrail Logging Stopped or Deleted
id: 5b3c0e0e-0000-4000-8000-00000000c1d7
status: experimental
description: A trail was stopped, deleted or its event selectors changed; attackers do this to hide later activity.
logsource:
  product: aws
  service: cloudtrail
detection:
  selection:
    eventSource: cloudtrail.amazonaws.com
    eventName:
      - StopLogging
      - DeleteTrail
      - UpdateTrail
      - PutEventSelectors
  condition: selection
falsepositives:
  - Planned changes by the logging pipeline role (exclude it by userIdentity.arn)
level: high
tags:
  - attack.defense-impairment
  - attack.t1685.002

T1685.002 is MITRE ATT&CK's "Disable or Modify Tools: Disable or Modify Cloud Log", under the Defense Impairment tactic since ATT&CK v19 (April 2026); older rules and mappings tag the same behaviour as T1562.008 (Impair Defenses: Disable or Modify Cloud Logs) under Defense Evasion, which v19 revoked; tagging rules with techniques shows which parts of the cloud matrix the rule set covers (ATT&CK Coverage).

Making the rules usable

  • Exclude the automation that legitimately does these things (the IaC pipeline role attaching policies, the logging account updating trails), by exact principal ARN, never by name pattern.
  • Raise severity with context: an unknown source IP, a new region, no MFA, a principal that has never called IAM before. The same AttachRolePolicy is routine from the pipeline and critical from a developer's key at 3 a.m.
  • Route by urgency: root use, MFA removal and logging tampering should page someone; privilege changes can go to a daily review queue.
  • Test every rule against recorded attack events, like the list above, in CI (Testing Detections).

Pitfalls

  • Detecting only in the region where the trail lives: use an all-region organisation trail, otherwise attacker activity in other regions never reaches the rules.
  • Matching ConsoleLogin failures as attacks: most are typos; correlate failures with a later success instead (Brute Force Followed by Success).
  • Forgetting that CloudTrail delivers events with a delay (typically within about five minutes): real-time expectations should account for it, and EventBridge rules see management events faster.

Practice

1. Add an event where ci-deploy calls AttachRolePolicy with ReadOnlyAccess. Which rules fire, and how would you exclude it if CI does this routinely?

privilege-change (MEDIUM) fires; admin-policy-attached doesn't. Exclude by exact principal and, ideally, by expected target: and not (e["who"] == "AssumedRole:ci-deploy" and e["req"]["roleName"].startswith("app-")), keeping the CRITICAL rule unexcluded.

2. Change DENY_N to 3. When does the burst alert fire now, and is that better?

At 08:20:09 after the third denial (three services). One event earlier, but more false positives from developers testing new permissions; tune with real data, not by feel.

3. Which alert would you page on first in this incident, and what is the first containment action?

console-no-mfa for root at 08:15:03 (or root activity itself). Containment: reset the root password and enable MFA from the organisation's break-glass process, deactivate bob's new key and remove the admin policy, restart logging, then investigate from 08:15 onwards with root and bob's new key as the scope.

Test yourself

Which event indicates someone is hiding later activity?

  1. DescribeInstances
  2. StopLogging on a trail
  3. ConsoleLogin with MFA
  4. GetObject

What does the access-denied burst rule look for?

  1. One failed login
  2. Several AccessDenied errors from one principal across several services within minutes
  3. Root sign-ins
  4. Public buckets

In the program, how many alerts fired in total?

  1. 5
  2. 8
  3. 12
  4. 14

How should automation that legitimately attaches policies be excluded?

  1. Disable the rule
  2. By exact principal ARN (and expected targets), keeping critical variants active
  3. By IP range only
  4. By time of day