DEV Community

Art Akopian
Art Akopian

Posted on Originally published at arutiuns-newsletter.beehiiv.com

Exposed .env files on at least 110,000 domains

On August 15, 2024, Palo Alto Networks Unit 42 published a report on a cloud extortion campaign that started with a simple request. Attackers scanned the internet for files named .env sitting in the web root of applications. Those files often hold cloud keys, database passwords, and mail-service credentials. Unit 42 wrote that the operation scanned more than 230 million unique targets and collected exposed .env files from at least 110,000 domains. Inside those files, the researchers counted more than 90,000 unique variables, including 7,000 that belonged to cloud services.

When a key worked, the attackers followed the same steps each time. They called GetCallerIdentity to see whose key it was. If the account could create roles, they created an IAM role named lambda-ex, attached Amazon's AdministratorAccess policy, and used new Lambda functions to keep scanning. They copied data out of S3 buckets, deleted the objects, and left a ransom note in the empty bucket. Their scanning code also looked for Mailgun credentials, which Unit 42 said attackers can use to send phishing from legitimate domains. The report does not state a dollar loss.

On October 30, 2024, the Sysdig Threat Research Team described a similar operation against a different path. Sysdig named it EMERALDWHALE, and its logs showed the scanning ran between August and September. The attackers used tools sold in underground markets, including MZR V2 and Seyzo-v2, to request /.git/config on public web servers. Sysdig said that, using one target list, the attackers found more than 67,000 URLs with that path exposed, and that this list was being sold on Telegram for $100. From the repositories they pulled, the operators collected more than 15,000 cloud service credentials and credentials for more than 10,000 private repositories. Of roughly 6,000 GitHub tokens Sysdig looked at, about 2,000 were valid. Sysdig said phishing and spam appeared to be the primary goal. It did not state a dollar loss.

A joint FBI and CISA advisory published on January 16, 2024 (AA24-016A) had already described a botnet, Androxgh0st, that looks for the same files. It requests /.env with a GET, or posts to it with a parameter that often identifies the operator. Its path list also includes /.git/config and /.aws/credentials. When AWS credentials come back, the advisory says, the operators have been observed trying to create new users and user policies, and creating new instances to run more scanning. The advisory does not give a victim count.

The file requests in these cases need no exploit. The scanner asks a web server for a path that should never be public. If the file is there, the key inside can be used to copy data, delete it, and leave a ransom note.

Banrox built and open-sourced exposure-scan so a team can make those same requests against hosts and repositories it actually owns, before a stranger does. It asks for /.env, /.git/config, backups, and source maps. It reads JavaScript bundles and the full git history for keys. It connects to datastore and control-plane ports that keep turning up in other breach write-ups, and it checks that listed webhooks reject an unsigned POST. It only scans targets the owner proves they control, with a DNS text record, a file at /.well-known/exposure-scan.txt, or a signed scope file. It never uses a key it finds. The report shows the key type, the location, the length, and a keyed fingerprint, not the secret itself.

It is not a penetration test, an audit opinion, or a certification of any kind. A clean report means only that these checks found nothing. Stolen passwords, phishing, and vulnerable dependencies are out of scope. Secret detection is based on patterns and entropy, so it will miss formats it does not know and will flag some random-looking strings that are not secrets. The port check reports an open port and a banner. It does not check whether the service requires a login, because that would mean speaking the service's protocol. Tests run fixture servers on the loopback address and use fake keys built at run time. A fixture blocks every non-loopback connection, so the suite cannot touch the internet. This study makes no claim about users, customers, or detection rates on real systems.

To try it, on a repository or domain you own:

pip install git+https://github.com/BanroxArt/exposure-scan
exposure-scan local path/to/repo
exposure-scan token
Enter fullscreen mode Exit fullscreen mode

Publish the token as exposure-scan-verification=. You can put it in a DNS TXT record at _exposure-scan.example.com, or as that line at https://www.example.com/.well-known/exposure-scan.txt. Then write a scope file from the example in the repository and run:

exposure-scan remote --scope scope.toml
Enter fullscreen mode Exit fullscreen mode

Scanners will keep asking for /.env and /.git/config either way. Running the same requests against hosts you have proven you own gives the team a list of files and ports to close, and keys to rotate, before someone else finds them.

Sources

Top comments (0)