Planting backdoors and stealing secrets if not crypto miners!
Before deep diving in this article, I would like to share two awesome resources on the research done on EC2 snapshots/AMI’s
1) Finding Secrets In Publicly Exposed EBS Volumes - Ben Morris
2) Investigating malicious AMIs - Scott Piper
After going through the above articles, I wanted to know what if the snapshot/AMIs could just steal AWS keys/secrets or create backdoors, as cryptominers were flagged and blocked by AWS.
I wrote a shell script steal_creds.sh to check if the IAM role is attached to the instance - if yes send credentials to my telegram bot. Additionally added a command to get a reverse shell on my C2C server
And then create a unit file under /etc/systemd/system
Finally just create a snapshot from the volume and you could also create an AMI from the snapshot. Make the snapshot and AMI both public and wait for the pingback. I had left the snapshot and AMI public for more than a week and it hadn’t been brought down by AWS.
Learnings
-
Don’t create EC2 instance from unknown AMIs or from unknown public snapshots as base volume (especially don’t attach any IAM role)
-
In case when direly needed, just attach the volume on the EC2 instance and mount the volume on a directory to perform analysis. Make sure the instance is isolated and has no keys/roles attached to it.