GCP - IAM Privesc
IAM
Find more information about IAM in:
GCP - IAM, Principals & Org Policies Enumiam.roles.update
(iam.roles.get
)
iam.roles.update
(iam.roles.get
)An attacker with the mentioned permissions will be able to update a role assigned to you and give you extra permissions to other resources like:
You can find a script to automate the creation, exploit and cleaning of a vuln environment here and a python script to abuse this privilege here. For more information check the original research.
iam.serviceAccounts.getAccessToken
(iam.serviceAccounts.get
)
iam.serviceAccounts.getAccessToken
(iam.serviceAccounts.get
)An attacker with the mentioned permissions will be able to request an access token that belongs to a Service Account, so it's possible to request an access token of a Service Account with more privileges than ours.
You can find a script to automate the creation, exploit and cleaning of a vuln environment here and a python script to abuse this privilege here. For more information check the original research.
iam.serviceAccountKeys.create
iam.serviceAccountKeys.create
An attacker with the mentioned permissions will be able to create a user-managed key for a Service Account, which will allow us to access GCP as that Service Account.
You can find a script to automate the creation, exploit and cleaning of a vuln environment here and a python script to abuse this privilege here. For more information check the original research.
Note that iam.serviceAccountKeys.update
won't work to modify the key of a SA because to do that the permissions iam.serviceAccountKeys.create
is also needed.
iam.serviceAccounts.implicitDelegation
iam.serviceAccounts.implicitDelegation
If you have the iam.serviceAccounts.implicitDelegation
permission on a Service Account that has the iam.serviceAccounts.getAccessToken
permission on a third Service Account, then you can use implicitDelegation to create a token for that third Service Account. Here is a diagram to help explain.
Note that according to the documentation, the delegation of gcloud
only works to generate a token using the generateAccessToken() method. So here you have how to get a token using the API directly:
You can find a script to automate the creation, exploit and cleaning of a vuln environment here and a python script to abuse this privilege here. For more information check the original research.
iam.serviceAccounts.signBlob
iam.serviceAccounts.signBlob
An attacker with the mentioned permissions will be able to sign of arbitrary payloads in GCP. So it'll be possible to create an unsigned JWT of the SA and then send it as a blob to get the JWT signed by the SA we are targeting. For more information read this.
You can find a script to automate the creation, exploit and cleaning of a vuln environment here and a python script to abuse this privilege here and here. For more information check the original research.
iam.serviceAccounts.signJwt
iam.serviceAccounts.signJwt
An attacker with the mentioned permissions will be able to sign well-formed JSON web tokens (JWTs). The difference with the previous method is that instead of making google sign a blob containing a JWT, we use the signJWT method that already expects a JWT. This makes it easier to use but you can only sign JWT instead of any bytes.
You can find a script to automate the creation, exploit and cleaning of a vuln environment here and a python script to abuse this privilege here. For more information check the original research.
iam.serviceAccounts.setIamPolicy
iam.serviceAccounts.setIamPolicy
An attacker with the mentioned permissions will be able to add IAM policies to service accounts. You can abuse it to grant yourself the permissions you need to impersonate the service account. In the following example we are granting ourselves the roles/iam.serviceAccountTokenCreator
role over the interesting SA:
You can find a script to automate the creation, exploit and cleaning of a vuln environment here.
iam.serviceAccounts.actAs
iam.serviceAccounts.actAs
The iam.serviceAccounts.actAs permission is like the iam:PassRole permission from AWS. It's essential for executing tasks, like initiating a Compute Engine instance, as it grants the ability to "actAs" a Service Account, ensuring secure permission management. Without this, users might gain undue access. Additionally, exploiting the iam.serviceAccounts.actAs involves various methods, each requiring a set of permissions, contrasting with other methods that need just one.
Service account impersonation
Impersonating a service account can be very useful to obtain new and better privileges. There are three ways in which you can impersonate another service account:
Authentication using RSA private keys (covered above)
Authorization using Cloud IAM policies (covered here)
Deploying jobs on GCP services (more applicable to the compromise of a user account)
iam.serviceAccounts.getOpenIdToken
iam.serviceAccounts.getOpenIdToken
An attacker with the mentioned permissions will be able to generate an OpenID JWT. These are used to assert identity and do not necessarily carry any implicit authorization against a resource.
According to this interesting post, it's necessary to indicate the audience (service where you want to use the token to authenticate to) and you will receive a JWT signed by google indicating the service account and the audience of the JWT.
You can generate an OpenIDToken (if you have the access) with:
Then you can just use it to access the service with:
Some services that support authentication via this kind of tokens are:
Google Cloud Endpoints (if using Google OIDC)
You can find an example on how to create and OpenID token behalf a service account here.
References
Last updated