Exploiting Secrets in Elastic Beanstalk (CloudGoat – beanstalk_secrets)

In this CloudGoat (beanstalk_secrets) scenario, I explored an AWS misconfiguration where sensitive credentials were exposed through Elastic Beanstalk environment variables. Starting with a low-privileged IAM user, I was able to escalate all the way to admin access and capture the final flag. I used the AWS CLI to manually walk through the steps to better understand how to enumerate resources, then repeated the process using PACU to see how automation can streamline the workflow.


Manual AWS CLI Walkthrough

I started by enumerating the environment with a low-privileged IAM user using the AWS CLI. While I couldn’t access environment resources directly, I was able to pull the Beanstalk configuration and spot secondary AWS credentials exposed in environment variables.

After switching to the secondary credentials, I discovered that the associated IAM user had the ability to create access keys for any IAM resource in the account. With further enumeration, I found an existing admin_user and used that permission to generate a new access key for them effectively escalating my access to full administrator. With those admin credentials, I queried AWS Secrets Manager and successfully retrieved the final flag!


PACU Automation

Using an automated approach, I ran through the scenario again using PACU. Using modules like elasticbeanstalk__enum, iam__bruteforce_permissions, iam__enum_permissions, iam__privesc_scan, and secrets__enum, I was able to:

  • Instantly detect leaked credentials in Beanstalk config
  • Confirm the privilege escalation path
  • Create an admin access key
  • Dump secrets from Secrets Manager

PACU made it easy to spot the vulnerabilities and helped speed up the entire process.


Key Takeaways

  • Never store secrets in Elastic Beanstalk environment variables.
  • Even limited permissions like iam:CreateAccessKey can be dangerous if misconfigured.
  • Tools like PACU are powerful for identifying and automating privilege escalation in AWS environments.

Detailed steps:

Manual Enumeration using AWS CLI


Initial Access

Caller Identity

  1. Listing Beanstalk Applications
  1. Listing Environments
  • We found a load balancer URL
  1. Low Priv user does not have access to list environment resources
  1. Listed config for each resource in the environment and found the secondary creds
    1. Access Key: AKIAS6FO56W*********
    2. Secret Key: brS2oUqbVGqtowAJVV+dHZv*****************

Enumerating Secondary User (manual enumeration)

  1. Listing Caller Identity
  1. Listing IAM users
  1. Listing Managed policies
    1. Access denied to list inline policies.
  1. Now we will enumerate the managed policy to see what permissions it has.
  1. Listing Policy version ID
    1. We found this policy allows us to create an access key for any resource in the environment. Earlier we listed all users and found an “admin_user”. We can use this admin user to create a new access key for them.
  1. Checking “admin_user” permissions to make sure they do have full admin rights. Listed policies attached to the user.
  1. Creating an access key for the admin user.
  1. Listing admin_user identity
  1. Listing AWS Secrets Manager
  1. Retrieving the secret string value.

Enumerating Low Priv User (Using Pacu)

Initial Access

Listing Caller Identity of Low Priv user

  1. We started a new Pacu sessions and imported our keys
  1. We will now start by enumerating Elastic BeanStalk with Pacu. We are going to start with running elasticbeanstalk__enum.
    1. Using one command in Pacu we found the secondary user access key and secret access key.
      1. Access Key: AKIAS6FO56W*********
      2. Secret Key: KeZ/8shwlV8FdOtmXeyxbbfLRN***************
  1. We will now enumerate IAM users and Policies with the Secondary user access. We listed the users identity and then start a new session in Pacu with our new secondary user keys.
  1. We now will enumerate the users to see what users exist and what roles and polices they have attached.
    1. We found an admin_user exists.
  1. We now we will run iam__bruteforce_enum to list what permissions our second user has.
  1. Next lets run iam__enum_permissions.
    1. We see our user has access to create access keys for IAM resources. We will now try creating a new access key for our admin_user we found earlier.
  1. Our second user has access to create access keys. We will now run the iam__privesc_scan to confirm we can create access keys.
  1. With the confirmation that we can create access keys for existing resources we will try to create a new key for the admin_user.
  1. Now we will enumerate AWS Secrets Manager to retrieve any secrets stored. We will use secrets__enum in Pacu.
  1. Secrets exposed!

Leave a Reply

Your email address will not be published. Required fields are marked *