Privilege Escalation
ec2:ModifyInstanceAttribute (user data)
A principal with ec2:ModifyInstanceAttribute, ec2:StopInstances, and ec2:StartInstances can run a cloud boothook and obtain an instance role's credentials.
Required Permissions
Description
A caller who can stop an EC2 instance and change its user data can add a cloud boothook alongside the original user data. Cloud-init runs boothooks on every boot. The boothook executes as root and can read temporary role credentials from the instance metadata service.
The hackaws agent looks for a running Linux instance with an EBS root volume and an instance profile role it cannot already reach. EBS root is required because EC2 only lets it change user data while stopped. It backs up the original user data, stops the instance, adds a temporary boothook beside an inert copy of the original bytes, and starts the instance. The boothook sends the credentials to a temporary, platform-controlled S3 object. The agent then stops the instance again, restores its original user data, and restarts it.
This causes two service interruptions and may change the instance's public IP address. The original boot configuration is restored, but processes and boot-time state may not return to their exact prior state. If restoration fails, injected user data may remain or the instance may need restarting; the assessment creates a cleanup record. The technique requires cloud-init and network access to the S3 endpoint.
Impact
The instance profile role becomes accessible to the attacker. The instance is stopped and started twice, causing downtime and possible public IP changes.
Detection
Correlate StopInstances, ModifyInstanceAttribute on userData, and StartInstances for the same instance. Inspect unexpected user data changes and the instance's cloud-init logs.
Mitigation
Restrict ec2:StopInstances and ec2:ModifyInstanceAttribute to operators who administer the instance. Limit permissions on instance profile roles, and prevent untrusted principals from changing their host configuration.