1---2intent: defensive3name: performing-cloud-forensics-with-aws-cloudtrail-24description: Perform forensic investigation of AWS environments using CloudTrail logs to reconstruct attacker activity, identify5 compromised credentials, and analyze API call patterns.6domain: cybersecurity7subdomain: cloud-security8tags:9- cloud-security10- aws11- cloudtrail12- forensics13- incident-response14- dfir15- boto316- s317version: '1.0'18author: Krishna Kumar (xalgord)19license: Apache-2.020nist_csf:21- PR.IR-0122- ID.AM-0823- GV.SC-0624- DE.CM-0125metadata:26 source: https://skillmd.com/skills/xalgord/performing-cloud-forensics-with-aws-cloudtrail-227---2829# Performing Cloud Forensics with AWS CloudTrail3031## When to Use3233- When investigating suspected AWS account compromise34- After detecting unauthorized API calls or credential exposure35- During incident response involving cloud infrastructure36- When analyzing S3 data exfiltration or IAM privilege escalation37- For post-incident forensic timeline reconstruction3839## Detection Gaps & Validation4041- **LookupEvents won't show data-plane activity:** `cloudtrail:LookupEvents` returns only management events for the last 90 days. S3 `GetObject`, `PutObject`, and Lambda `Invoke` are *data events*, absent unless data event logging was enabled before the incident - pivot to S3 server access logs / Athena to prove exfiltration.42- **Single-region or non-org trails leave blind spots:** an attacker operating in an unmonitored region produces no events in a region-scoped trail. Confirm the trail is multi-region and org-wide via `aws cloudtrail describe-trails` (`IsMultiRegionTrail`, `IsOrganizationTrail`).43- **Check for anti-forensics first:** hunt `StopLogging`, `UpdateTrail`, `DeleteTrail`, and `PutEventSelectors` events - an attacker may have blinded logging. Then run `aws cloudtrail validate-logs` against the digest files to detect deletion/tampering.44- **Attribute actions correctly:** track both `userIdentity.accessKeyId` and `sessionContext.sessionIssuer` - an `AssumeRole` issues temporary keys (`ASIA...`), so following only the original key loses the attacker after the pivot.45- **`AccessDenied` is signal, not noise:** denied calls are still logged and reveal recon and failed escalation; don't filter them out of the timeline.46- **How to confirm a finding:** corroborate the CloudTrail timeline against VPC Flow Logs (same source IP) and the resource's own logs, and remember every `eventTime` is UTC when sequencing events.47- **Don't conclude "no compromise" until** data events are accounted for (or shown to have been disabled), the trail covered all regions, and logging-tamper events plus digest validation have been checked.4849## Prerequisites5051- AWS account with CloudTrail enabled (management and data events)52- IAM permissions for cloudtrail:LookupEvents, s3:GetObject, athena:StartQueryExecution53- boto3 Python SDK installed54- CloudTrail logs delivered to S3 with optional Athena table configured55- AWS CLI configured with appropriate credentials5657## Workflow58591. **Scope Investigation**: Identify timeframe, affected accounts, and compromised credentials.602. **Query CloudTrail**: Use boto3 lookup_events or Athena to retrieve relevant API events.613. **Filter by Indicators**: Search for suspicious user agents, source IPs, and event names.624. **Reconstruct Timeline**: Build chronological sequence of attacker actions from API calls.635. **Analyze Access Patterns**: Identify data access, IAM changes, and resource modifications.646. **Identify Persistence**: Check for new IAM users, access keys, roles, or Lambda functions.657. **Generate Report**: Produce forensic timeline with findings and remediation steps.6667## Key Concepts6869| Concept | Description |70|---------|-------------|71| LookupEvents | CloudTrail API to query management events (last 90 days) |72| Athena Queries | SQL queries against CloudTrail logs in S3 for historical analysis |73| User Agent Analysis | Identify tool signatures (AWS CLI, SDK, console, custom) |74| AccessKeyId | Track activity by specific IAM access key |75| EventName | AWS API action name (e.g., GetObject, CreateUser, AssumeRole) |76| sourceIPAddress | Origin IP of API call for geolocation analysis |7778## Tools & Systems7980| Tool | Purpose |81|------|---------|82| boto3 CloudTrail client | Programmatic CloudTrail event lookup |83| AWS Athena | SQL-based analysis of CloudTrail S3 logs |84| AWS CLI | Command-line CloudTrail queries |85| jq | JSON processing for CloudTrail event parsing |86| CloudTrail Lake | Advanced event data store with SQL query support |8788## Output Format8990```91Forensic Report: AWS-IR-[DATE]-[SEQ]92Account: [AWS Account ID]93Timeframe: [Start] to [End]94Compromised Credentials: [Access Key IDs]95Suspicious Events: [Count]96Source IPs: [List of attacker IPs]97Actions Taken: [API calls by attacker]98Data Accessed: [S3 objects, secrets, etc.]99Persistence Mechanisms: [New users, keys, roles]100```