| name | detecting-aws-cloudtrail-anomalies |
| description | Detect unusual API call patterns in AWS CloudTrail logs using boto3, statistical baselining, and behavioral analysis to identify credential compromise, privilege escalation, and unauthorized resource access. Use when detecting unusual api call patterns in aws cloudtrail logs using. |
| domain | cybersecurity |
| subdomain | cloud-security |
| tags | ["cloud-security","aws","cloudtrail","anomaly-detection","threat-detection","boto3"] |
| version | 1.0 |
| author | oyi77 |
| license | Apache-2.0 |
| nist_csf | ["PR.IR-01","ID.AM-08","GV.SC-06","DE.CM-01"] |
Detecting AWS CloudTrail Anomalies
Overview
AWS CloudTrail records API calls across AWS services. This skill covers querying CloudTrail events with boto3's lookup_events API, building statistical baselines of normal API activity, detecting anomalies such as unusual event sources, geographic anomalies, high-frequency API calls, and first-time API usage patterns that indicate compromised credentials or insider threats.
When to Use
Trigger phrases:
-
"detecting aws cloudtrail anomalies"
-
"Detect unusual API call patterns in AWS CloudTrail logs using boto3, statistical"
-
When investigating security incidents that require detecting aws cloudtrail anomalies
-
When building detection rules or threat hunting queries for this domain
-
When SOC analysts need structured procedures for this analysis type
-
When validating security monitoring coverage for related attack techniques
Prerequisites
- Python 3.9+ with
boto3 library
- AWS credentials with CloudTrail read permissions (cloudtrail:LookupEvents)
- Understanding of AWS IAM and common API patterns
- CloudTrail enabled in target AWS account (management events at minimum)
Steps
import re
IOC_PATTERNS = {
"ip": r"\b(?:\d{1,3}\.){3}\d{1,3}\b",
"domain": r"\b[a-z0-9-]+\.[a-z]{2,}\b",
"hash_md5": r"\b[a-f0-9]{32}\b",
"hash_sha256": r"\b[a-f0-9]{64}\b",
}
def extract_iocs(text: str) -> dict:
return {k: re.findall(v, text) for k, v in IOC_PATTERNS.items()}
- Inventory cloud assets — enumerate services, roles, and configurations in scope
- Assess configurations — check against security best practices and CIS benchmarks