Detection in AWS
Every API call is logged. The defender who reads CloudTrail wins.
What you will learn
- -Read a CloudTrail event and pull the fields that name an attacker
- -Know what GuardDuty catches for free and what it misses
- -Write the detections that fire on the exact actions from the attack lessons
Here is the fact that flips the whole module: in AWS, every action is an call, and CloudTrail records nearly all of them. When an attacker runs aws s3 ls or creates an or assumes a role, a event lands in a with their , their source IP, the exact API called, and whether it succeeded. The offense in the earlier lessons is loud by design. The defense is knowing how to read the noise.
CloudTrail is on by default for management events, and it keeps 90 days of history you can query without any setup. For real detection you create a trail that ships events to an and, ideally, to CloudWatch Logs so you can alarm on them. The single field that matters most in every event is eventName, the API call, paired with userIdentity and sourceIPAddress.
$aws cloudtrail lookup-events --lookup-attributes AttributeKey=EventName,AttributeValue=CreateAccessKey --max-results 10$aws cloudtrail lookup-events --lookup-attributes AttributeKey=EventName,AttributeValue=AssumeRole --max-results 20$aws cloudtrail lookup-events --lookup-attributes AttributeKey=Username,AttributeValue=deploy-botAn event you should be able to read on sight looks like this, trimmed to what matters:
Read it out loud. The user deploy-bot created an access key for the user admin, from an IP that is not in your office range. That is the privesc from lesson two, caught in one event. A legitimate admin almost never does this, which is exactly why it makes a clean alarm.
GuardDuty does the pattern matching
You will not write every detection by hand. GuardDuty is Amazon's managed detector: turn it on and it reads CloudTrail, Flow Logs, and logs, then scores anomalies with no rules from you. It flags use from a Tor exit , an EC2 instance talking to a known crypto-mining pool, and API calls from an IP that never appears for this account.
$aws guardduty list-findings --detector-id abcd1234The finding type worth memorizing is InstanceCredentialExfiltration. It fires when credentials tied to an EC2 role, the ones you can pull from IMDS, used from an IP outside AWS. That is the -to-metadata attack from lesson one, detected. GuardDuty catching it is the reason that attack is not free.
Know its limits too. GuardDuty is and threat-intel based, so a slow, quiet attacker using expected and normal-looking calls can slide under it. It does not read the contents of your S3 objects, and it will not tell you a bucket is wrong. It catches behavior, not misconfiguration. Pair it with Config and Access Analyzer for the config side.
Reading CloudTrail and GuardDuty in an account you defend is your job. Doing it in an account you do not own is not. On a red-team engagement, disabling CloudTrail or GuardDuty is itself a high-signal action, logged as StopLogging or DeleteDetector, and it belongs only in an authorized with the briefed. Tampering with logging in a account without written approval crosses a legal line.
The detections that actually earn their keep map straight to the attack lessons. Alarm on CreateAccessKey and AttachUserPolicy because privesc runs through them. Alarm on StopLogging, DeleteTrail, and PutBucketPolicy on your log bucket because that is an attacker blinding you. Alarm on GetSecretValue spikes and on any use of the account, which should be close to never. Build those five and you catch most of what the earlier lessons taught.
Your CloudWatch alarm fires on a CloudTrail StopLogging event from an IAM user. Why is this one of the highest-priority alerts you can build?