Lesson 3 of 5 · 25 min read

AWS CloudTrail Anatomy — Management Events, Data Events, Multi-Region Trails

You already saw CloudTrail event structure in M02. This lesson goes deeper: how to configure trails for comprehensive coverage, what the common attack patterns look like in CloudTrail, and how to write detections against the API-call model.


CloudTrail Configuration: What You Must Enable

1. Multi-Region Trail

aws cloudtrail create-trail \
  --name org-security-trail \
  --s3-bucket-name my-cloudtrail-logs \
  --is-multi-region-trail \
  --include-global-service-events \
  --enable-log-file-validation

Multi-region (--is-multi-region-trail): Captures activity in all regions. Required because attackers use non-standard regions to evade region-specific trails.

Global service events (--include-global-service-events): Captures IAM, STS, CloudFront API calls. IAM calls are “global” — they’re not region-specific. Without this, you miss iam:CreateUser, iam:AttachRolePolicy, and most privilege escalation API calls.

Log file validation (--enable-log-file-validation): Creates SHA-256 digests for each log file delivery. Allows you to detect if someone tampered with CloudTrail log files in S3.

2. Data Events (S3 + Lambda)

# Enable data events for all S3 buckets
aws cloudtrail put-event-selectors \
  --trail-name org-security-trail \
  --event-selectors '[{
    "ReadWriteType": "All",
    "IncludeManagementEvents": true,
    "DataResources": [{
      "Type": "AWS::S3::Object",
      "Values": ["arn:aws:s3:::"]
    }]
  }]'

Data events capture: s3:GetObject, s3:PutObject, s3:DeleteObject, lambda:InvokeFunction. Required for exfiltration detection.


Attack Patterns in CloudTrail

Pattern 1: Credential Reconnaissance (T1078.004)

/* Multiple AccessDenied errors across services — permissions probing */
{"eventTime": "09:23:14Z", "eventName": "DescribeInstances", "errorCode": "AccessDenied", "eventSource": "ec2.amazonaws.com"}
{"eventTime": "09:23:16Z", "eventName": "ListBuckets", "errorCode": "AccessDenied", "eventSource": "s3.amazonaws.com"}
{"eventTime": "09:23:18Z", "eventName": "ListUsers", "errorCode": "AccessDenied", "eventSource": "iam.amazonaws.com"}
{"eventTime": "09:23:20Z", "eventName": "GetCallerIdentity", "errorCode": null, "eventSource": "sts.amazonaws.com"}

GetCallerIdentity succeeds (no IAM permission required, always works). The three preceding calls failed. This is an attacker mapping what permissions their stolen credential has.

Detection: Count of distinct errorCode: 'AccessDenied' events from the same principal over a short window, especially followed by a successful call.

Pattern 2: Persistence via IAM (T1098.001)

/* Sequence: create user → attach admin policy → create access key */
{"eventName": "CreateUser", "requestParameters": {"userName": "support-bot"}}
{"eventName": "AttachUserPolicy", "requestParameters": {"userName": "support-bot", "policyArn": "arn:aws:iam::aws:policy/AdministratorAccess"}}
{"eventName": "CreateAccessKey", "requestParameters": {"userName": "support-bot"}}

Each call alone could be legitimate. The sequence — create → grant admin → generate API key — is the attack.

Pattern 3: Console Login Without MFA

{
  "eventName": "ConsoleLogin",
  "userIdentity": {"type": "IAMUser", "userName": "admin-jdoe"},
  "additionalEventData": {
    "MFAUsed": "No",
    "LoginTo": "https://console.aws.amazon.com/console/home"
  },
  "responseElements": {"ConsoleLogin": "Success"},
  "sourceIPAddress": "203.0.113.55"
}

Admin account logging in without MFA from an external IP. This should alert immediately.


Reading CloudTrail userIdentity Types

typeWho made the callDetection note
IAMUserDirect IAM user with long-term credentialsMost common legitimate auth
AssumedRoleShort-term credentials via STS AssumeRoleCheck role chain + session duration
RootAWS root accountShould almost never appear — alert immediately
AWSServiceAWS service acting on your behalf (e.g., Lambda calling S3)Normal; filter by service principal in exclude rules
AWSAccountCross-account accessVerify the source account is trusted
AWS CloudTrail User Guide— AWS Docs Stratus Red Team— Datadog Security Labs