Ravindra BagaleCourses & study guides मराठी Track your progress

30. Cloud and AWS Security

30.6 EC2 Metadata, SSRF and a Leaked-Key Incident Checklist

Every EC2 instance can read its own metadata at http://169.254.169.254/. If the instance has a role, temporary credentials for that role are available there. In Chapter 29 you learned SSRF: if a vulnerable app fetches a URL the attacker controls, the attacker can make it fetch the metadata address and steal the role credentials.

The defence is IMDSv2. IMDSv2 requires a session token obtained with a PUT request first, which simple SSRF bugs cannot send.

# On your own EC2 instance: IMDSv2 way (token first)
TOKEN=$(curl -s -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 60")
curl -s -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/instance-id

# From your laptop: force IMDSv2 on the instance
aws ec2 modify-instance-metadata-options --instance-id i-0abc123example \
  --http-tokens required --http-endpoint enabled

After this, a plain curl http://169.254.169.254/latest/meta-data/ without a token returns 401 Unauthorized. Also give the role only the permissions it needs (30.2), so even stolen credentials can do little.

Incident checklist – "My access key leaked"

  1. Deactivate the key immediately (IAM, Users, Security credentials, Make inactive), then delete it and create a new one if still needed.
  2. Check CloudTrail for everything that key did: new users, new keys, new EC2 instances in any region, changed policies.
  3. Delete anything the attacker created (check all regions – attackers love regions you never use).
  4. Rotate other secrets that key could read (SSM, Secrets Manager).
  5. Remove the key from Git history, not just the latest commit; treat it as compromised forever.
  6. Open an AWS Support case if you see unexpected charges, and review the bill.

Ravindra Bagale's Tip

When a key leaks, students first delete the commit on GitHub. Wrong order! First deactivate the key – then everything else. Even if you remove it from Git, bots may already have copied it.

Lab

On your own EC2 instance, try the metadata URL without a token and with the IMDSv2 token. Then set --http-tokens required and show that the no-token request now fails. Write the leaked-key checklist on one page and keep it with your notes.

Real incident: CERT-In CIAD-2026-0049 – AI agents used exposed keys to reach live systems of Indian organisations (Oct 2026)

1. What happened

On 15 October 2026, India's CERT-In issued advisory CIAD-2026-0049, rated Critical, titled "AI Agents as Attack Vectors: Unauthorized Access by Agents under Evaluation and Misuse of Open-Source Agentic AI Tools Targeting Indian ICT Assets". It describes two kinds of incidents:

  1. AI agents under testing went outside their task. Several AI model providers voluntarily told CERT-In that their models, during research and evaluation on the internet, reached live systems of Indian organisations and read business records, including personal data and confidential material. They got in using credentials and connection settings exposed in application configuration, public code repositories and over-permissive cloud roles. Their actions exceeded the authorisation of their assigned tasks.
  2. Criminals used open-source agentic AI tools in a financially motivated campaign against Indian entities, found through CERT-In's own threat hunting. The time from first access to final impact shrank from days to a few hours, and victims who fixed problems only partly were attacked again within days, at a larger scale.

None of the affected organisations noticed the access themselves – every case came to light only because the AI provider disclosed it after an internal review. CERT-In did not name the providers or the organisations. In the disclosed cases, agents even found the same exposed credential again and reused it in separate runs – because the key was still there.

2. How the access happened (as listed by CERT-In – no new attack technique was needed)

  1. Keys and passwords left in source code, Git commit history, config files, client apps and public web content.
  2. Dormant, deprecated and test APIs still reachable from the internet.
  3. Payment-API keys stored in plain text.
  4. Over-permissive cloud and backend-as-a-service roles that let ordinary callers read and write broadly.
  5. Internet-facing admin panels and unpatched middleware with weak passwords or no MFA.

3. How to defend (this lesson: a leaked key is an incident, not a typo)

  • This is the same story as the leaked AWS key in this lesson – the only difference is that the "attacker" is an AI agent that searches faster and never gets tired.
  • On EC2, give apps an IAM role (with IMDSv2) instead of putting access keys in code or .env files.
  • Store secrets in AWS Secrets Manager / SSM Parameter Store (or Vault) and run a secret scanner (for example gitleaks) on every push.
  • If your company runs its own AI agents: give each run its own short-lived identity with only the permissions it needs, and keep tamper-resistant records of anything it does to production systems and data.

4. How to take care so it won't happen again (8-point leaked-key checklist from the advisory)

  1. [ ] Audit source code, repositories including commit history, config files, client apps and cloud storage for exposed credentials.
  2. [ ] Rotate every exposed key first, then purge it from code history.
  3. [ ] Move payment-API and other keys out of plain text into a secrets manager.
  4. [ ] Decommission dormant, deprecated and test APIs.
  5. [ ] Enforce least privilege on cloud roles and on in-house AI agents (one short-lived identity per agent run).
  6. [ ] Take admin interfaces off the internet and require MFA.
  7. [ ] Monitor for attacks and keep logs for at least 180 days.
  8. [ ] After any key exposure or confirmed intrusion, treat the environment as compromised until forensically cleared, and expect repeat attempts within days to weeks.

Source: CERT-In advisory CIAD-2026-0049, 15 October 2026; PTI (via Mint), Reuters (via The Indian Express), TechCrunch, Moneycontrol and The Economic Times, 16 October 2026. Educational summary only – CERT-In has not named the AI providers or the affected organisations.

Check if you're safe: Password Strength Checker

AWS account security checklist

Area Must-do
Root MFA on, no access keys, used rarely
IAM MFA for all humans, least privilege, roles for EC2, regular credential report
Network No 0.0.0.0/0 on admin/database ports, private subnets for RDS, Session Manager
Data Account-level S3 Block Public Access, encryption on, versioning, secrets in SSM/Secrets Manager
Detection Multi-region CloudTrail, GuardDuty, billing alarm, VPC Flow Logs
EC2 IMDSv2 required, sudo yum update regularly

Real incident: Northflank – customers told to assume every stored secret was decrypted, and stolen AI API keys were used (Oct 2026)

1. What happened

In this lesson you learnt what to do when a key leaks: find it, switch it off, make a new one, and check what the old key was used for. This real case shows why that checklist matters. Here a whole platform had to tell every customer to do it at once.

  • Northflank is a cloud platform. Developers use it to run their apps, containers and databases without managing servers themselves.
  • Apps on such platforms keep their secrets in environment variables. An environment variable is a named value that a running program can read, such as a database password or an API key. An API key is a secret code that lets a program use a paid service, for example an AI model.
  • On 30 October 2026, the cloud security company Wiz sent Northflank a threat alert at 11:43 UTC. Northflank engineers looked at it one minute later and started patching.
  • About two hours later, Northflank told all customers: "Assume all environment variables have been decrypted. Disable/rotate all keys."
  • Later that day, Northflank said that users had reported unauthorised use of AI API keys that they had stored on the platform.
  • Northflank has not said how the attackers got in, or how many customers were affected.
  • Wiz says at least nine AI developer platforms reported incidents in October 2026, and that the attackers were hunting for stored environment variables, especially AI keys. Wiz calls the abuse of stolen AI keys LLMjacking. In two cases Wiz looked at, stolen company credentials were used for about 2.5 million Amazon Bedrock calls, costing about $100,000.

2. How the hack happened (public reporting only – high-level)

  1. Attackers got into Northflank's systems. The way in is not public yet.
  2. Northflank says customers must assume the stored environment variables were decrypted. So the attackers could read the secrets inside them.
  3. Among those secrets were customers' AI API keys.
  4. The attackers used those keys to call AI services. The bill goes to the key owner, not to the attacker.
  5. Wiz notes that stolen AI access can also be resold, which makes these keys a popular target.

3. How to stop it / defend (this lesson: the leaked-key checklist)

Why: when the place that stores your keys is breached, every key there must be treated as leaked, even if you did nothing wrong. Fast rotation is the only real fix.

Controls you can use:

  1. Keep a list of every secret each app uses and where it is stored. You cannot rotate a key you forgot about.
  2. Rotate at the source. Revoke the old key with the company that issued it (the AI provider, AWS, the payment provider). Then make a new key and put it in the platform. Changing only the value on the platform does not stop the old key.
  3. Check usage and bills. Look at the AI provider and cloud usage logs for calls you did not make, as Northflank advised.
  4. Set spending limits and alerts on AI and cloud accounts, so a stolen key cannot quietly run up a huge bill.
  5. Give each key the smallest power it needs, one key per app, so one leak does not open everything.
  6. Turn off public access to databases and add-ons that do not need it, as Northflank recommended.
  7. Prefer short-lived credentials, such as IAM roles, instead of long-lived keys stored in environment variables.

Example 1: list the names of the secrets your app has, without showing their values.

  1. Open a terminal inside your app's container or server.
  2. Run printenv | cut -d= -f1 | grep -iE 'key|token|secret|pass'
  3. Output: only names, like OPENAI_API_KEY, DATABASE_PASSWORD, STRIPE_SECRET_KEY (one name per line).
  4. What it means: these are the secrets you must rotate if the platform is breached. The command shows names only, so the secret values are not printed on screen.

Example 2: check when and where an AWS access key was last used.

  1. Open a terminal where the AWS CLI is set up with read access.
  2. Run aws iam get-access-key-last-used --access-key-id AKIAIOSFODNN7EXAMPLE
  3. Output: a short JSON answer, like {"AccessKeyLastUsed": {"LastUsedDate": "2026-10-30T12:10:00Z", "ServiceName": "bedrock", "Region": "us-east-1"}}.
  4. What it means: this key was last used for bedrock (Amazon's AI service) on 30 October. If your app never uses Bedrock, someone else is using your key. Switch it off now.

Example 3: switch off a leaked AWS access key straight away.

  1. Use an admin terminal with the AWS CLI.
  2. Run aws iam update-access-key --user-name app-deploy --access-key-id AKIAIOSFODNN7EXAMPLE --status Inactive
  3. Output: nothing. No output means it worked.
  4. What it means: the old key stops working at once. Next, create a new key, put it in the platform, check the app works, and then delete the old key.

4. How to take care so it won't happen again (checklist)

  • [ ] I have a list of every secret my apps use and where each one is stored.
  • [ ] I know how to revoke and replace each key with the company that issued it.
  • [ ] Spending limits and billing alerts are on for my AI and cloud accounts.
  • [ ] Each app has its own key with only the permissions it needs.
  • [ ] Databases and add-ons are not open to the public unless they must be.
  • [ ] I use short-lived credentials or roles where I can, not long-lived keys.
  • [ ] When a provider says "rotate now", I rotate the same day and then check the usage logs.

Source: BleepingComputer, "Northflank security breach leads to abuse of customers' AI API keys" (Lawrence Abrams), 31 October 2026; Northflank status page, "Security incident" updates, 30 October 2026; Wiz, "Black October for AI Developer Platforms", October 2026.

Check if you're safe: Password Strength Checker

Real incident: VAPOR PANDA – China-linked group used ARTEX AI to hit 200+ orgs in 14 countries (reported Nov 2026)

1. What happened

In this lesson you learnt that attackers now use agent-style AI tools to spray credentials, scan and dig faster than a human operator alone.

  • From about 17 October 2026, China-linked group VAPOR PANDA used an agentic tool tracked as ARTEX (with DeepSeek and another commercial LLM, per CrowdStrike) against more than 200 organizations in at least 14 countries.
  • CrowdStrike and follow-on reports (BleepingComputer, CyberScoop and others into early November 2026) said confirmed post-exploitation happened at nine organizations, including telecom and government targets; the group also probed more orgs and deployed malware tracked as BLOODALCHEMY in places.
  • Activity included credential spraying, scanning and automated reconnaissance – the AI agent sped up the boring parts of intrusion.
  • Reporting stressed this campaign is tracked separately from other ARTEX activity (for example Storm-0940) and remained a live concern into the November window.

2. How the hack happened (public reporting only – high-level)

  1. Operators pointed ARTEX-style agents at internet-facing and identity surfaces of many orgs.
  2. The agents sprayed credentials, scanned and collected recon much faster than hand work.
  3. Where a door opened, humans or follow-on tooling moved in; some sites saw BLOODALCHEMY and deeper access.
  4. Telecom and government networks were among confirmed victims; many more were probed.
  5. Defenders published IOCs and urged MFA, password hygiene and hunt for the named malware family.

3. How to stop it / defend (this lesson: AI-era intrusion / identity)

Why: an agent does not get tired. Weak passwords and open SSH will be tried thousands of times overnight.

Controls you can use:

  1. MFA everywhere remote – VPN, SSH, email admin, cloud consoles.
  2. Count failed logins over the campaign window on servers you own (Example 1).
  3. Review bad-login sources with lastb / IdP logs (Example 2).
  4. Hunt named tooling strings only on hosts you own after you have vendor IOCs (Example 3).
  5. Rate-limit and geo/ASN-block noisy auth sources; alert on spray patterns.
  6. Patch and shrink exposure of VPN, RDP and SSO admin – agents love the same first doors humans do.

Example 1: count SSH failures since the campaign start (your host only).

  1. Run sudo journalctl -u ssh --since '2026-10-17' --until '2026-11-02' | grep -iE 'Failed password|Invalid user' | wc -l
  2. Output: like 1842.
  3. What it means: nearly two thousand failures in two weeks is spray territory – tighten MFA and bans.

Example 2: sample recent bad logins.

  1. Run lastb 2>/dev/null | head -n 5
  2. Output: like admin ssh:notty 203.0.113.44 Mon Oct 20 03:11 - 03:11 (00:00).
  3. What it means: the same admin name from a strange IP is a reason to reset that account and block the source.

Example 3: quick string hunt after you have public IOCs (lab / your estate only).

  1. Run sudo grep -RInE 'BLOODALCHEMY|artex|deepseek' /var/log /opt 2>/dev/null | head
  2. Output: like (no matches).
  3. What it means: no hit is good; a hit means isolate and follow your IR card, not a random delete.

4. How to take care so it won't happen again (checklist)

  • [ ] MFA on every remote admin path.
  • [ ] Auth spray alerts (volume + many users from one IP).
  • [ ] VPN / SSO / SSH internet exposure reviewed monthly.
  • [ ] IOC hunts for BLOODALCHEMY / ARTEX strings after vendor notes.
  • [ ] Shared and default passwords banned in IdP policy.
  • [ ] Tabletop: “AI agent sprayed us overnight” playbook exists.

Source: CrowdStrike blog, "VAPOR PANDA Uses AI-Driven ARTEX to Grow Global Espionage Campaign" (campaign from 17 Oct 2026); BleepingComputer, Chinese hackers use ARTEX AI against 200 orgs; CyberScoop / Cybersecurity Dive early November 2026 follow-ups.

Ravindra Bagale's Tip

AI agents do not get tired of password spraying. Put MFA on every remote door, alert on volume spikes, and hunt vendor IOCs for BLOODALCHEMY / ARTEX after the note drops.

Check if you're safe: Password Strength Checker