Looking at the page source, we instantly noticed the script utilize hard coded AWS Cognito Identity Pool as well as s3 bucket name.
The jaavscript uses the AWS SDK to interact with the S3 Bucket. It uses AWS Cognito to retrieve an assumed unauthenticated role. We are able to either use the Javascript console or the aws cli to retrieve the credentials.
With the credentials, we are able to set up an aws profile (I call it enhanced)with aws cli to enumerate our permission.
Running aws sts get-caller-identityas a sanity check, we noticed that the assumed role is called cognito_unauthenticated. However, attempts in further enumeration of our permission were met with AccessDenied by session policy.
Using AWS Cognito Enhanced flow, there are built-in security controls that restrict certain administrative operations.
When credentials are obtained through a Cognito Identity Pool, AWS applies an implicit session policy.
This session policy overrides or restricts certain permissions, even if they're explicitly allowed in the role policy
Looking at the AWS documentation
We can see that there is an inline session policy for guest users using enhanced-flow.
We the access key, secrey key and session token, we are able to configure another profile for the classic flow credential.
Running get-caller-identityagain as a sanity check, we have assumed the role succesfully, with the sesion name test
Now, we can attempt to enumerate IAM again to see if we managed to bypass the session policy.
aws iam get-role --role-name cognito_unauthenticated --profile classic
aws iam list-role-policies --role-name cognito_unauthenticated --profile classic
aws iam get-role-policy --role-name cognito_unauthenticated --policy-name unauthenticated_policy --profile classic
Performing manual enumeration, we managed to retrieve the IAM policy for the role cognito_unauthenticated
Looking at the IAM Policy, we can see that the user has the iam:Get* and iam:List* permission, thus allowing us to enumerate the IAM.
Interestingly, the user also has ECR permission.
AWS ECR is the Elastic Container Registry, which is somewhat similar to a docker registry, but hosted on AWS. The "Resource": "*" in the ECR section grants access to all resources. This is a security risk as it provides the unauthenticated role access to all ECR repositories within the AWS account
aws ecr describe-repositories --profile classic
Running describe profile to tists all Amazon Elastic Container Registry (ECR) repositories in the AWS account associated with the classic profile.
Next, runing describe image to lists details about the container images stored in the specified ECR repository.