Beginner Friendly
![]()
Leverage Leaked Credentials for Pwnage
This foundations lab shows how leaked secrets committed to a public repository can let an attacker pwn a cloud environment and access personally identifiable information. You discover a committed .env file containing database credentials and an AWS access key, recover the AWS account ID, and reuse the password to log in to the AWS console. From there you pivot through Secrets Manager to an RDS database holding sensitive employee and dependent data.
Overview
This foundations lab shows how leaked secrets committed to a public repository can let an attacker pwn a cloud environment and access personally identifiable information. You discover a committed .env file containing database credentials and an AWS access key, recover the AWS account ID, and reuse the password to log in to the AWS console. From there you pivot through Secrets Manager to an RDS database holding sensitive employee and dependent data.
Scenario
Rumors suggest Huge Logistics has overlooked weaknesses hidden across its GitHub repositories. As a security consultant, you comb through their repos hunting for the smallest exposure others have missed.
Lab prerequisites
- Basic Linux command line knowledge
- Familiarity with the AWS CLI and console
- Basic understanding of Git repositories
Learning outcomes
- Identify secrets such as .env credentials committed to a public Git repository
- Retrieve an AWS account ID from an access key with aws sts get-access-key-info
- Exploit password reuse to log in to the AWS console as an IAM user
- Retrieve database credentials from AWS Secrets Manager
- Enumerate an RDS MySQL database and extract PII from its tables
- Use SAST tools such as TruffleHog and Gitleaks to detect exposed secrets
Real-world context
Exposure of sensitive credentials in .env files is a common real-world issue, and accidentally committing them to shared or public repositories hands attackers everything needed to compromise a company's infrastructure. Automated scanners run by both defenders and malicious actors continuously hunt for these leaks.
KEY TAKEAWAY
Environment files exist to keep secrets out of source code, and they end up committed, deployed to web roots and copied into images anyway. The file was never the control, and the only durable fix is that the secret should not be a long-lived string in a file at all.
What this lab covers
You find configuration that was not meant to be reachable, use static analysis tooling to identify the secrets inside it, and follow those into an AWS account and the database behind the application.
The lab also covers something small and useful: an AWS access key identifier encodes the account it belongs to, so a key alone tells you which account you have reached before you authenticate.
It assumes no prior AWS experience and is a good foundational lab, because leaked configuration is the single most common way people first get into a cloud environment.
How environment file exposure happens
Environment files hold configuration as key and value pairs and are read at application startup. They were adopted precisely to keep credentials out of source code, and they solve that narrow problem while creating several others.
They leak in predictable ways. They get committed despite ignore rules, particularly when someone forces the add or the rule is added after the first commit. They get deployed into web-accessible directories, where a request for the filename retrieves them. They get copied into container images, where they persist in a layer. Each route is common enough that scanning for them is routine.
Static analysis tooling finds them by pattern and entropy. Recognized credential formats such as cloud access keys are matched directly, and high-randomness strings that match no known pattern are flagged as likely secrets, which catches database passwords and generic API tokens.
How to detect this in your own environment
Watch web server logs for requests to environment and configuration filenames. These have no legitimate purpose and are among the cleanest indicators of reconnaissance available.
Scan repositories, images and deployed filesystems rather than only source. The file frequently exists somewhere other than the place people think to look.
Detect on use as well as on exposure. First use of an access key from an unfamiliar network typically surfaces faster than any scanning you run, because automated tooling finds public exposure within minutes.
How to prevent it
Serve configuration from outside the web root and configure the server to refuse dotfiles. Two configuration changes remove the most embarrassing exposure route entirely.
Replace long-lived credentials with short-lived ones from a role or workload identity, so the file contains a reference rather than a secret. This removes the class of problem instead of protecting the artifact.
Rotate anything that has appeared in a file that leaked, rather than removing the file. The credential should be considered compromised the moment it was reachable.
Real-world context
Exposed environment files are a persistent and widely exploited finding, and there have been large-scale campaigns specifically scanning the internet for them and using the cloud credentials they contain.
The pattern endures because the practice is otherwise good advice. Teams are told not to hardcode secrets, they move them to a file, and the file inherits every distribution mechanism the code has, which is exactly what the advice was trying to avoid.
The pattern maps to MITRE ATT&CK T1552.001 Credentials In Files, T1083 File and Directory Discovery and T1078.004 Cloud Accounts.
Applying this at work
- Request the common environment filenames against your own web endpoints. It takes one request per host and occasionally finds something.
- Scan repositories, container images and deployed filesystems for configuration files containing secrets.
- Configure web servers to refuse dotfiles and move configuration outside served directories.
- Replace long-lived access keys in configuration with role-based short-lived credentials.
- Confirm you would be alerted if one of your access keys were used from an unfamiliar network.
Frequently asked questions
Why do .env files leak so often?
Because they inherit every distribution path the code has. They get committed despite ignore rules, deployed into web-accessible directories, and copied into container images, and each of those routes is common enough to be scanned for routinely.
Can an AWS access key reveal which account it belongs to?
Yes. The account identifier is encoded in the key identifier itself, so the owning account can be determined from the key alone, before any authentication attempt is made.
What should replace secrets in configuration files?
References to short-lived credentials obtained from a role or workload identity, or from a secrets manager at runtime. That removes the long-lived string, so there is nothing durable in the file to leak.
Do I need my own AWS account to practice this?
No. The lab runs in a live AWS environment that Pwned Labs provisions for you, so there is nothing to set up and no risk to your own infrastructure.
Which certification covers this in depth?
The Amazon Cloud Red Team Professional (ACRTP) covers AWS attack and detection paths in full, including IAM abuse and privilege escalation, and is assessed hands-on in a live AWS account.
Cloud Security Training To Protect Your Business
Pwned Labs for Business gives your team access to dedicated business content, including labs and cyber ranges.
We also offer in-person or remote workshops, and our cloud penetration services are helping businesses become more secure!