Skip to Content
Asterrr's Handbook
1 · Detection

Exposed keys and forensic evidence

Scoping the damage of a leaked access key and preserving evidence with S3 Object Lock.

The decision: which tool shows what a leaked access key did, and how do you keep the evidence unchangeable while you investigate?

Two incident-flavored detection topics. First, finding out what a leaked access key did. Second, keeping evidence unchangeable while you investigate.

AWS accountwhich keycontaincopy logslockExposed keycheckCloudTrailhistoryDeactivate keyEvidence bucketObject Lock
Detect the leak, scope it in CloudTrail, contain the key, and lock the evidence.

Evaluating an exposed access key

StepTool
DetectTrusted Advisor Exposed Access Keys check scans public repositories and flags odd EC2 use. GuardDuty flags credential misuse, for example UnauthorizedAccess:IAMUser/InstanceCredentialExfiltration or ResourceConsumption findings
ScopeCloudTrail event history shows what a user, role or access key did, with time, source IP and resource. Search by the access key ID
ContainDeactivate the key in IAM first, then delete it after the investigation. An IAM user can hold at most two keys, so rotation is deactivate, create, update the app, delete
Clean upRemove resources the attacker created and review roles and policies they changed
  • AWS may temporarily limit creating some resources when a key is exposed. That only limits charges. It does not secure the account.
  • Best practice is to avoid long-term keys. Use roles and temporary credentials.

Exam signal

"Find out which actions were made with a leaked key": CloudTrail, filtered by access key ID. "Detect that keys were posted publicly": Trusted Advisor Exposed Access Keys.

S3 Object Lock for evidence

Object Lock gives write once read many protection per object version. It needs S3 Versioning on the bucket.

FeatureWhat to remember
Compliance modeNo one can overwrite or delete the version, not even root. Mode and period cannot be shortened. Only closing the account removes it
Governance modeMost users cannot change it. Users with s3:BypassGovernanceRetention who send x-amz-bypass-governance-retention:true can. Good for testing retention settings
Retention periodFixed retain-until-date, or variable retention with an event hold and duration. Can set a bucket default in days or years
Legal holdSame protection, no end date. Removed explicitly with s3:PutObjectLegalHold. Independent from retention
Permissionss3:PutObjectRetention, s3:PutObjectLegalHold, s3:PutBucketObjectLockConfiguration and the matching Get actions

Lock protects the version only. New versions and delete markers can still be added. A simple delete returns 200 and adds a delete marker. A delete by version ID returns 403.

Exam trap

Governance mode does not stop an admin who holds the bypass permission, so it is not evidence-grade. Use compliance mode, or a legal hold, when the exam says "no one including root".

Trusted Advisor and Health, GuardDuty, Systems Manager for compromised SSH keys. Immutable storage covers Object Lock and Vault Lock in depth.

Further reading

On this page