GCP - IAM, Principals & Org Policies Enum

HackTricksをサポートする

サービスアカウント

サービスアカウントとは何かについてのイントロは次を確認してください:

GCP - Basic Information

列挙

サービスアカウントは常にプロジェクトに属します:

gcloud iam service-accounts list --project <project>

ユーザーとグループ

GCPにおけるユーザーとグループの動作についてのイントロは以下を確認してください:

GCP - Basic Information

列挙

権限 serviceusage.services.enableserviceusage.services.use があれば、プロジェクト内で サービスを有効にする ことができます。

デフォルトでは、Workspaceユーザーには Project Creator の役割が付与され、新しいプロジェクトを 作成する アクセスが与えられます。ユーザーがプロジェクトを作成すると、彼はそのプロジェクトに対して owner の役割が付与されます。したがって、彼は Workspaceを列挙するためにこれらのサービスをプロジェクトで有効にする ことができます。

ただし、これらのAPIを呼び出すためには Workspace内で十分な権限を持っている必要がある ことに注意してください。

もし admin サービスを有効にする ことができ、ユーザーが Workspace内で十分な権限を持っている なら、以下の行を使って すべてのグループとユーザーを列挙する ことができます。 identity groups と表示されていても、グループに属さないユーザー も返されます:

# Enable admin
gcloud services enable admin.googleapis.com
gcloud services enable cloudidentity.googleapis.com

# Using admin.googleapis.com
## List all users
gcloud organizations list #The DIRECTORY_CUSTOMER_ID is the Workspace ID
gcloud beta identity groups preview --customer <workspace-id>

# Using cloudidentity.googleapis.com
## List groups of a user (you can list at least the groups you belong to)
gcloud identity groups memberships search-transitive-groups --member-email <email> --labels=cloudidentity.googleapis.com/groups.discussion_forum

## List Group Members (you can list at least the groups you belong to)
gcloud identity groups memberships list --group-email=<email>
### Make it transitive
gcloud identity groups memberships search-transitive-memberships --group-email=<email>

## Get a graph (if you have enough permissions)
gcloud identity groups memberships get-membership-graph --member-email=<email> --labels=cloudidentity.googleapis.com/groups.discussion_forum

前の例では、パラメータ --labels が必要ですので、一般的な値が使用されています(APIを直接使用した場合は必要ありません、PurplePandaがここで行っているように)。

管理サービスが有効になっていても、侵害されたワークスペースユーザーに十分な権限がないため、列挙中にエラーが発生する可能性があります:

IAM

IAMに関する基本情報はこちらを確認してください

デフォルトの権限

ドキュメントから:組織リソースが作成されると、ドメイン内のすべてのユーザーに請求アカウント作成者およびプロジェクト作成者の役割がデフォルトで付与されます。これらのデフォルトの役割により、ユーザーはすぐにGoogle Cloudを使用開始できますが、組織リソースの通常の運用には使用されることを意図していません。

これらの役割権限を付与します:

  • billing.accounts.create および resourcemanager.organizations.get

  • resourcemanager.organizations.get および resourcemanager.projects.create

さらに、ユーザーがプロジェクトを作成すると、ドキュメントに従って、そのプロジェクトのオーナーが自動的に付与されます。したがって、デフォルトでは、ユーザーはプロジェクトを作成し、その上で任意のサービスを実行できるようになります(マイナー?ワークスペースの列挙?...)

GCP組織における最高の権限は組織管理者の役割です。

set-iam-policy vs add-iam-policy-binding

ほとんどのサービスでは、add-iam-policy-bindingまたはset-iam-policyメソッドを使用してリソースに対する権限を変更できます。主な違いは、add-iam-policy-bindingは既存のIAMポリシーに新しい役割のバインディングを追加するのに対し、set-iam-policyは以前に付与された権限を削除し、コマンドで指定されたものだけを設定します

列挙

# Roles
## List roles
gcloud iam roles list --project $PROJECT_ID # List only custom roles
gcloud iam roles list --filter='etag:AA=='

## Get perms and description of role
gcloud iam roles describe roles/container.admin
gcloud iam roles describe --project <proj-name> <role-name>

# Policies
gcloud organizations get-iam-policy <org_id>
gcloud resource-manager folders get-iam-policy <folder-id>
gcloud projects get-iam-policy <project-id>

# MISC
## Testable permissions in resource
gcloud iam list-testable-permissions --filter "NOT apiDisabled: true" <resource>
## Grantable roles to a resource
gcloud iam list-grantable-roles <project URL>

cloudasset IAM Enumeration

このサービスを使用して、異なるリソース(組織、フォルダー、プロジェクトなど)内のユーザーのすべての権限を確認する方法はいくつかあります。

  • 権限 cloudasset.assets.searchAllIamPolicies は、リソース内の すべての IAM ポリシー を要求できます。

gcloud asset search-all-iam-policies #By default uses current configured project
gcloud asset search-all-iam-policies --scope folders/1234567
gcloud asset search-all-iam-policies --scope organizations/123456
gcloud asset search-all-iam-policies --scope projects/project-id-123123
  • 権限 cloudasset.assets.analyzeIamPolicy は、リソース内のプリンシパルの すべての IAM ポリシー を要求できます。

# Needs perm "cloudasset.assets.analyzeIamPolicy" over the asset
gcloud asset analyze-iam-policy --organization=<org-id> \
--identity='user:email@hacktricks.xyz'
gcloud asset analyze-iam-policy --folder=<folder-id> \
--identity='user:email@hacktricks.xyz'
gcloud asset analyze-iam-policy --project=<project-name> \
--identity='user:email@hacktricks.xyz'
  • パーミッション cloudasset.assets.searchAllResources は、組織、フォルダー、またはプロジェクトのすべてのリソースをリストすることを許可します。IAM関連のリソース(ロールなど)が含まれます。

gcloud asset search-all-resources --scope projects/<proj-name>
gcloud asset search-all-resources --scope folders/1234567
gcloud asset search-all-resources --scope organizations/123456
  • 権限 cloudasset.assets.analyzeMove は、プロジェクトのようなリソースに影響を与えるポリシーを取得するのにも役立ちます。

gcloud asset analyze-move --project=<proj-name> \
--destination-organization=609216679593
  • cloudasset.assets.queryIamPolicy パーミッションは、プリンシパルのパーミッションを見つけるためのアクセスを提供する可能性があります。

# But, when running something like this
gcloud asset query --project=<proj> --statement='SELECT * FROM compute_googleapis_com_Instance'
# I get the error
ERROR: (gcloud.asset.query) UNAUTHENTICATED: QueryAssets API is only supported for SCC premium customers. See https://cloud.google.com/security-command-center/pricing

testIamPermissions enumeration

もしIAM情報にアクセスできない場合、そしてあなたがレッドチームにいる場合は、ツール https://github.com/carlospolop/bf_my_gcp_perms を使用して現在の権限をブルートフォースすることができます。

ただし、サービス**cloudresourcemanager.googleapis.com**を有効にする必要があります。

Privesc

次のページでは、IAM権限を悪用して特権を昇格させる方法を確認できます:

GCP - IAM Privesc

Unauthenticated Enum

GCP - IAM, Principals & Org Unauthenticated Enum

Post Exploitation

GCP - IAM Post Exploitation

Persistence

高い特権を持っている場合、次のことができます:

  • 新しいSA(またはWorkspace内のユーザー)を作成する

  • 自分が管理するプリンシパルにより多くの権限を与える

  • 脆弱なSAにより多くの特権を与える(VM内のSSRF、脆弱なCloud Function…)

Org Policies

Org Policiesが何であるかのイントロについては、次を確認してください:

GCP - Basic Information

IAMポリシーは、役割を介してプリンシパルがリソースに対して持つ権限を示し、これにより細かい権限が割り当てられます。組織ポリシーは、これらのサービスがどのように使用できるか、またはどの機能が無効にされるかを制限します。これは、GCP環境内の各リソースの最小特権を向上させるのに役立ちます。

gcloud resource-manager org-policies list --organization=ORGANIZATION_ID
gcloud resource-manager org-policies list --folder=FOLDER_ID
gcloud resource-manager org-policies list --project=PROJECT_ID

Privesc

次のページでは、組織ポリシーの権限を悪用して特権を昇格させる方法を確認できます:

GCP - Orgpolicy Privesc
HackTricksをサポートする

Last updated