agentleFS
kaandgnshkaandgnsh/Claude-Blue/skills/aws-security/cloudtrail-investigation/SKILL.md

cloudtrail-investigation

Skill0 starsChanged 12 days agoMITView on GitHub

Investigate AWS activity with CloudTrail — Event history (lookup-events), CloudTrail Lake SQL, Athena over S3 logs — tracing identities through AssumeRole chains, finding persistence, privilege escalation, defense evasion and data access; includes a tested summarizer script. Use when investigating a suspicious AWS principal, access key, console login or GuardDuty finding.

The file

Files
SKILL.md

CloudTrail Investigation

Get the data

# Last 90 days of management events (Event history), per key or user — slow, 2 req/s per account/region
aws cloudtrail lookup-events --lookup-attributes AttributeKey=AccessKeyId,AttributeValue=AKIA... \
  --start-time 2025-03-01T00:00:00Z --max-results 50 > lookup.json
aws cloudtrail lookup-events --lookup-attributes AttributeKey=Username,AttributeValue=alice --region us-east-1 > alice.json
# Summarize (bundled): identities, IPs, user agents, regions, high-risk API calls
python3 scripts/cloudtrail_summary.py lookup.json
python3 scripts/cloudtrail_summary.py s3-export/*.json.gz

Event history is per region — query every region (attackers love unused regions), and us-east-1 for global services (IAM, STS console sign-in events).

CloudTrail Lake:

SELECT eventTime, eventName, sourceIPAddress, userAgent, errorCode
FROM <event_data_store_id>
WHERE userIdentity.accessKeyId = 'AKIA...' AND eventTime > '2025-03-01 00:00:00'
ORDER BY eventTime

Athena (organization trail table): filter on partition columns (region, date) first; useridentity.arn, eventname, sourceipaddress, errorcode.

Trace identity

  • userIdentity.type: IAMUser, AssumedRole, Root, FederatedUser, AWSService.
  • For AssumedRole, follow the chain: find the AssumeRole/AssumeRoleWithSAML/AssumeRoleWithWebIdentity event whose responseElements.credentials.accessKeyId equals the session's accessKeyId; its userIdentity is the caller. sourceIdentity (if set) survives chaining.
  • Temporary keys start ASIA, long-term AKIA.

What to look for

TacticEvents
DiscoveryGetCallerIdentity, ListBuckets, DescribeInstances, GetAccountAuthorizationDetails, many AccessDenied (permission probing)
PersistenceCreateUser, CreateAccessKey, CreateLoginProfile, UpdateAssumeRolePolicy (trust to external account), new IdP (CreateSAMLProvider/CreateOpenIDConnectProvider), Lambda/EventBridge backdoors
Privilege escalationAttachUserPolicy/PutRolePolicy with admin, CreatePolicyVersion + SetDefaultPolicyVersion, PassRole + RunInstances/CreateFunction
Defense evasionStopLogging, DeleteTrail, PutEventSelectors, DeleteDetector (GuardDuty), DeleteFlowLogs, region usage outside baseline
Credential accessGetSecretValue, GetParameter --with-decryption, GetPasswordData
Exfiltration/impactS3 data events (GetObject volume — requires data events enabled), ModifySnapshotAttribute (share snapshot to external account), PutBucketPolicy public, DeleteObject/KMS key disable (ransom)

Note GetObject and other data-plane events only exist if data events were enabled for the bucket.

Output

Timeline (UTC) of the principal's actions, list of created/modified resources (for eradication), source IPs/ASNs/user agents, data accessed, and logging gaps.

Related skills

aws-credential-compromise, guardduty-triage, aws-iam-review, cloud-incident-response

References

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.