1---2name: performing-cloud-forensics-with-aws-cloudtrail3description: Perform forensic investigation of AWS environments using CloudTrail logs to reconstruct attacker activity, identify compromised credentials, and analyze API call patterns.4domain: cybersecurity5subdomain: cloud-security6tags: [cloud-security, aws, cloudtrail, forensics, incident-response, dfir, boto3, s3]7version: "1.0"8author: mahipal9license: Apache-2.010metadata:11 source: https://skillmd.com/skills/micsapp/performing-cloud-forensics-with-aws-cloudtrail12---1314# Performing Cloud Forensics with AWS CloudTrail1516## When to Use1718- When investigating suspected AWS account compromise19- After detecting unauthorized API calls or credential exposure20- During incident response involving cloud infrastructure21- When analyzing S3 data exfiltration or IAM privilege escalation22- For post-incident forensic timeline reconstruction2324## Prerequisites2526- AWS account with CloudTrail enabled (management and data events)27- IAM permissions for cloudtrail:LookupEvents, s3:GetObject, athena:StartQueryExecution28- boto3 Python SDK installed29- CloudTrail logs delivered to S3 with optional Athena table configured30- AWS CLI configured with appropriate credentials3132## Workflow33341. **Scope Investigation**: Identify timeframe, affected accounts, and compromised credentials.352. **Query CloudTrail**: Use boto3 lookup_events or Athena to retrieve relevant API events.363. **Filter by Indicators**: Search for suspicious user agents, source IPs, and event names.374. **Reconstruct Timeline**: Build chronological sequence of attacker actions from API calls.385. **Analyze Access Patterns**: Identify data access, IAM changes, and resource modifications.396. **Identify Persistence**: Check for new IAM users, access keys, roles, or Lambda functions.407. **Generate Report**: Produce forensic timeline with findings and remediation steps.4142## Key Concepts4344| Concept | Description |45|---------|-------------|46| LookupEvents | CloudTrail API to query management events (last 90 days) |47| Athena Queries | SQL queries against CloudTrail logs in S3 for historical analysis |48| User Agent Analysis | Identify tool signatures (AWS CLI, SDK, console, custom) |49| AccessKeyId | Track activity by specific IAM access key |50| EventName | AWS API action name (e.g., GetObject, CreateUser, AssumeRole) |51| sourceIPAddress | Origin IP of API call for geolocation analysis |5253## Tools & Systems5455| Tool | Purpose |56|------|---------|57| boto3 CloudTrail client | Programmatic CloudTrail event lookup |58| AWS Athena | SQL-based analysis of CloudTrail S3 logs |59| AWS CLI | Command-line CloudTrail queries |60| jq | JSON processing for CloudTrail event parsing |61| CloudTrail Lake | Advanced event data store with SQL query support |6263## Output Format6465```66Forensic Report: AWS-IR-[DATE]-[SEQ]67Account: [AWS Account ID]68Timeframe: [Start] to [End]69Compromised Credentials: [Access Key IDs]70Suspicious Events: [Count]71Source IPs: [List of attacker IPs]72Actions Taken: [API calls by attacker]73Data Accessed: [S3 objects, secrets, etc.]74Persistence Mechanisms: [New users, keys, roles]75```