Exposed AWS keys used to be found by people who searched GitHub by hand. Now software does the search around the clock. On 2 December Perplexity described how an autonomous AI agent spent about two weeks trying to steal its cloud keys. Perplexity blocked every attempt, but the same agent got into two other companies. This post explains what the agent looked for and gives five checks for exposed AWS keys on your own server and in your own code.

The checks use test keys that we planted in a lab folder. The AWS key shown is the example key from Amazon’s own documentation, so it is safe to print.

The short answer

  • The attacker wanted cloud keys that can call AI models through Amazon Bedrock, so it could use those models on the victim’s account.
  • It searched public code, deleted git history, storage buckets and config files such as .env.production.
  • One company fell because a live credential was still sitting in deleted git history. The other left a management API open on a demo system.
  • So the fix is to find your own keys before someone else does, remove them, and replace any key that was ever exposed.

What happened at Perplexity

Perplexity says the probing ran from late October to 8 November 2026. Its own agent platform flagged the activity on 2 November, when a wave of new accounts swept its APIs. The largest burst sent about 48,000 requests in 13 minutes.

The attacker used Cairn, an open-source framework that lets AI coding agents run security tools on their own. According to Perplexity’s report, the agent tried these things:

  • It asked link-fetching features to open the cloud metadata address (169.254.169.254), which hands out temporary keys on cloud servers.
  • It guessed file names in storage buckets, including .env.production, .aws/credentials and state.tfstate.
  • It probed admin pages and tried to open other customers’ files.

Outbound URL checks and permission checks stopped all of it. However, the attacker’s server was left open to the internet, and its files showed two other companies under attack. At the first, the agent found a customer’s live credential in deleted git history. At the second, it logged in to a management API on a demo environment. Perplexity warned both on 4 November.

To find keys, the agent pulled host names from certificate logs, read public code and commit history, and unpacked published packages and app builds. Then it tested each complete key.

Check 1: search your files for keys

We ran every command below in our lab on 4 December 2026. Run them only on servers and code you own.

This searches a folder for AWS access keys, common AI service keys and private keys:

grep -rIlE "AKIA[0-9A-Z]{16}|sk-(proj|ant)-[A-Za-z0-9_-]{20,}|-----BEGIN (RSA |EC |OPENSSH )?PRIVATE KEY-----" . --exclude-dir=.git

In our test project, where we planted an example key:

config/.env

The command prints only file names, so the keys themselves do not land in your terminal history. Run it in your web root, your home folders and your deployment folders.

Check 2: search git history, including deleted files

Deleting a file from a repository does not remove it from the history. This is exactly what the agent used against the first company. In our lab we committed a .env.production file with the AWS example key and then deleted it in a second commit. The working folder looked clean, but:

git log --all --oneline -S"AKIAIOSFODNN7EXAMPLE"
1dd5aaf remove env file
0ecb011 initial

Both commits still contain the key. To search for any AWS key without knowing it:

git log -p --all | grep -nE "AKIA[0-9A-Z]{16}" | head
14:-AWS_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMPLE
30:+AWS_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMPLE

If this finds a real key, do not try to clean the history first. Instead, replace the key at the provider straight away, because anyone who copied the repository already has it. Tools such as gitleaks, which the attacker’s agent also used, run this kind of search with many more patterns.

Check 3: fix file permissions on secrets

A secret in a file that every user on the server can read is one step from stolen. Find such files:

find . -name ".env*" -not -path "./.git/*" -perm /044 -exec ls -l {} \;

Shortened output from our lab:

-rw-r--r-- ./config/.env

Then restrict each file to its owner:

chmod 600 config/.env

After that, ls -l showed -rw-------. Also make sure your web server never serves these files. A request for /.env on your site should return 403 or 404.

Check 4: look in shell history

Keys typed into a command stay in the history file. Search for them:

grep -nE "(SECRET|TOKEN|PASSWORD|API_KEY)[A-Z_]*=" ~/.bash_history

On a test history file we made:

2:export AWS_SECRET_ACCESS_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY

Replace any real key you find, then remove the line. Check the history of root and of every deployment user too.

Check 5: the cloud metadata address

On a cloud server, any program can ask the metadata address for the server’s temporary keys. So if your app fetches URLs that users supply, an attacker can try to point it there. First see whether the address answers from your server:

curl -s -m 3 -o /dev/null -w "%{http_code}\n" http://169.254.169.254/latest/meta-data/

Our lab is not on AWS and printed 403. According to the AWS documentation, on an AWS server 200 means the older mode without a session token still works, and 401 means the server already demands a token (IMDSv2). AWS documents this command to require the token. We did not run it, because we have no AWS instance in the lab:

aws ec2 modify-instance-metadata-options --instance-id i-0123456789abcdef0 --http-tokens required --http-endpoint enabled

In addition, validate every URL your app fetches for users, and block private and link-local addresses. Perplexity credits exactly that check for stopping the agent.

If you find an exposed key

  1. Create a new key at the provider and switch the app to it.
  2. Disable the old key, then delete it.
  3. Read the audit log (CloudTrail on AWS) for what the old key did, especially new users, new keys and calls to AI services.
  4. Give the new key only the rights the app needs. The agent was told to prefer keys with broad rights.
  5. Set a billing alert, so unusual AI or compute use shows up within hours.

Also move secrets out of files where you can. A secrets manager, or the environment settings of your hosting platform, keeps them out of git by design.

Free check: our website safety check grades your site’s HTTPS and security headers from the outside in 30 seconds.

Related guides

Sources

Worried a specific system is affected by a new flaw? Our Emergency Exposure Check (₹2,999) looks at up to five hosts, sites or product versions and gives a written verdict for each within 48 hours, with what to patch first and how to verify the fix. Full refund if we cannot check your setup.

Post author avatar

Bhaskar Soni

Bhaskar Soni is a Security Engineer and the founder of Youngster Company, based in Ahmedabad, Gujarat. He works hands-on with Linux server hardening, vulnerability assessment and penetration testing (VAPT), ISO 27001 compliance and OSINT investigations. He writes practical, tested guides for IT professionals and Indian businesses, and every article on this site is written or reviewed by him.

Leave a Reply