Skip to content

Commit a9a58a9

Browse files
committed
f
1 parent 449be62 commit a9a58a9

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

src/pentesting-cloud/gcp-security/gcp-privilege-escalation/gcp-misc-perms-privesc.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
### \*.setIamPolicy
88

99
If you owns a user that has the **`setIamPolicy`** permission in a resource you can **escalate privileges in that resource** because you will be able to change the IAM policy of that resource and give you more privileges over it.\
10-
This permission can also allow to **escalate to other principals** if the resource allow to execute code and the iam.ServiceAccounts.actAs is not necessary.
10+
This permission can also allow to **escalate to other principals** if the resource allow to execute code and the `iam.ServiceAccounts.actAs` is not necessary.
1111

1212
- _cloudfunctions.functions.setIamPolicy_
1313
- Modify the policy of a Cloud Function to allow yourself to invoke it.
@@ -22,6 +22,13 @@ These permissions can be very useful to try to escalate privileges in resources
2222

2323
This permission will usually let you **access or modify a Service Account in some resource** (e.g.: compute.instances.setServiceAccount). This **could lead to a privilege escalation** vector, but it will depend on each case.
2424

25+
### iam.ServiceAccounts.actAs
26+
27+
This permission will let you attach a Service Account to a resource that supports it (e.g.: Compute Engine VM, Cloud Function, Cloud Run, etc).\
28+
If you can attach a Service Account that has more privileges than your user to a resource that can execute code, you will be able to escalate your privileges by executing code with that Service Account.
29+
30+
Search in Cloud Hacktricks for `iam.ServiceAccounts.actAs` to find several examples of how to escalate privileges with this permission.
31+
2532
{{#include ../../../banners/hacktricks-training.md}}
2633

2734

src/pentesting-cloud/gcp-security/gcp-privilege-escalation/gcp-orgpolicy-privesc.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,33 @@ gcloud resource-manager org-policies disable-enforce <org-policy> [--folder <id>
1818

1919
A python script for this method can be found [here](https://github.com/RhinoSecurityLabs/GCP-IAM-Privilege-Escalation/blob/master/ExploitScripts/orgpolicy.policy.set.py).
2020

21+
### `orgpolicy.policy.set`, `iam.serviceAccounts.actAs`
22+
23+
uusally it's not possible to attach a service account from a different project to a resource becasue there is a policy constraint enforced named **`iam.disableCrossProjectServiceAccountUsage`** that prevents this action.
24+
25+
It's possible to verify if this constraint is enforced by running the following command:
26+
27+
```bash
28+
gcloud resource-manager org-policies describe \
29+
constraints/iam.disableCrossProjectServiceAccountUsage \
30+
--project=<project-id> \
31+
--effective
32+
33+
booleanPolicy:
34+
enforced: true
35+
constraint: constraints/iam.disableCrossProjectServiceAccountUsage
36+
```
37+
38+
This prevents an attacker from abusing the permission **`iam.serviceAccounts.actAs`** to impersonate a service account from another project without needed further infra permissions to start a new VM for example, which could lead to privilege escalation.
39+
40+
However, an attacker with the permissions **`orgpolicy.policy.set`** can bypass this restriction by disabling the constraint **`iam.disableServiceAccountProjectWideAccess`**. This allows the attacker to attach a service account from another project to a resource in his own project, effectively escalating his privileges.
41+
42+
```bash
43+
gcloud resource-manager org-policies disable-enforce \
44+
iam.disableCrossProjectServiceAccountUsage \
45+
--project=<project-id>
46+
```
47+
2148
## References
2249

2350
- [https://rhinosecuritylabs.com/cloud-security/privilege-escalation-google-cloud-platform-part-2/](https://rhinosecuritylabs.com/cloud-security/privilege-escalation-google-cloud-platform-part-2/)

0 commit comments

Comments
 (0)