这篇文章是我边做pwnedlabs这个靶场边学习aws云安全的一个记录

Identify the AWS Account ID from a Public S3 Bucket

Scenario

The ability to expose and leverage even the smallest oversights is a coveted skill. A global Logistics Company has reached out to our cybersecurity company for assistance and have provided the IP address of their website. Your objective? Start the engagement and use this IP address to identify their AWS account ID via a public S3 bucket so we can commence the process of enumeration.

靶机开启之后给了一个ip地址和AK/SK

image-20250329164324757

这个AK/SK我没有找到有什么用处

最开始我刚开启靶机,试着ping这个ip地址来测试一下网络的连通性

结果就是死活ping不通

image-20250329164739068

一次无意的curl 发现curl可以访问

这才意识到它可能ban掉了ping协议

nmap探测一手端口

1
2
3
4
5
6
7
8
9
10
11
12
13
┌──(root㉿LAPTOP-40PQI58C)-[~/Desktop/cicd/cicd-goat/reports/caterpillar]
└─# nmap -sV -sC 54.204.171.32
Starting Nmap 7.95 ( https://nmap.org ) at 2025-03-29 16:48 CST
Nmap scan report for ec2-54-204-171-32.compute-1.amazonaws.com (54.204.171.32)
Host is up (0.29s latency).
Not shown: 999 filtered tcp ports (no-response)
PORT STATE SERVICE VERSION
80/tcp open http Apache httpd 2.4.52 ((Ubuntu))
|_http-server-header: Apache/2.4.52 (Ubuntu)
|_http-title: Mega Big Tech

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 36.63 seconds

80端口只是一个静态网站

image-20250329165306568

不过网站的图片是从存储桶上面加载的

image-20250329165413458

aws s3存储桶的命名规则是 <桶的名称>.s3.amazonaws.com

所以这个存储桶的名称就是mega-big-tech

在浏览器上面访问这个存储桶,你会发现除了几张图片并没有什么东西

image-20250329165622395

同时你也可以使用aws cli 来访问这个s3存储桶

使用aws s3 ls s3://mega-big-tech --no-sign-request --recursive来匿名访问存储桶 并且递归显示出桶中的内容

image-20250329170230547

不过这个靶场只是让我们获取与这个s3存储桶关联的AWS账户的id

这里可以用**s3-account-search**这个工具来进行ID枚举

你可以在这里了解到这个工具的原理Finding the Account ID of any public S3 bucket

使用这个工具进行爆破的时候需要一个对目标桶具有s3:GetObject或者s3:ListBucket权限的角色的arn

如果你没有aws账户,你可以使用pwnedlabs提供的一个arn进行枚举arn:aws:iam::427648302155:role/LeakyBucket

如果您有一个aws账户,你也可以自己配置一个角色来进行枚举

首先你需要创建一个用户

image-20250329171553257

然后在策略里面新建两条策略

承担该角色的 IAM 用户将附加以下策略

1
2
3
4
5
6
7
8
{
"Version": "2012-10-17",
"Statement": {
"Effect": "Allow",
"Action": "sts:AssumeRole",
"Resource": "arn:aws:iam::<your aws account id>:role/<your role name>"
}
}

您的用户被允许承担的角色将附加以下策略,该策略允许s3:GetObjects3:ListBucket访问存储桶的权限mega-big-tech

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "Enum",
"Effect": "Allow",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::mega-big-tech/*"
},
{
"Sid": "Enum1",
"Effect": "Allow",
"Action": "s3:ListBucket",
"Resource": "arn:aws:s3:::mega-big-tech"
}
]
}

然后创建一个角色,将这两条测试附加上去,我这里分别是rolepolicyget-meth-big

image-20250329171823957

随后你需要添加信任关系

1
2
3
4
5
6
7
8
9
10
11
12
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::<your aws account id>:user/s3enum"
},
"Action": "sts:AssumeRole"
}
]
}

image-20250329171920059

然后就可以使用这个角色的arn进行ID枚举了

image-20250329172007540

等他完全爆破出来就行了

image-20250329172108485

但是AWS Account ID并不是敏感信息

那么拿到这个信息有什么用呢?

接下来,来看下面这个靶场

Loot Public EBS Snapshots

Scenario

Huge Logistics, a titan in their industry, has invited you to simulate an “assume breach” scenario. They’re handing you the keys to their kingdom - albeit, the basic AWS credentials of a fresh intern. Your mission, should you choose to accept it, is to navigate their intricate cloud maze, starting from this humble entry. Gain situational awareness, identify weak spots, and test the waters to see how far you can elevate your access. Can you navigate this digital labyrinth and prove that even the smallest breach can pose significant threats? The challenge is set. The game is on.

靶机只给了一个AK/SK

image-20250329173122662

配置到aws cli中

1
2
3
4
5
6
┌──(root㉿LAPTOP-40PQI58C)-[~/Desktop/cicd/cicd-goat/reports/caterpillar]
└─# aws configure
AWS Access Key ID [****************LGXJ]: AKIARQVIRZ4UCZVR25FQ
AWS Secret Access Key [****************976k]: 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
Default region name [None]:
Default output format [None]:

执行aws sts get-caller-identity来查看当前用户信息。类似于linux中的whoami

1
2
3
4
5
6
7
┌──(root㉿LAPTOP-40PQI58C)-[~/Desktop/cicd/cicd-goat/reports/caterpillar]
└─# aws sts get-caller-identity
{
"UserId": "AIDARQVIRZ4UJNTLTYGWU",
"Account": "104506445608",
"Arn": "arn:aws:iam::104506445608:user/intern"
}

执行aws iam list-attached-user-policies --user-name intern来列出与intern关联的iam策略

1
2
3
4
5
6
7
8
9
10
┌──(root㉿LAPTOP-40PQI58C)-[~/Desktop/cicd/cicd-goat/reports/caterpillar]
└─# aws iam list-attached-user-policies --user-name intern
{
"AttachedPolicies": [
{
"PolicyName": "PublicSnapper",
"PolicyArn": "arn:aws:iam::104506445608:policy/PublicSnapper"
}
]
}

查看该策略aws iam get-policy --policy-arn arn:aws:iam::104506445608:policy/PublicSnapper

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
┌──(root㉿LAPTOP-40PQI58C)-[~/Desktop/cicd/cicd-goat/reports/caterpillar]
└─# aws iam get-policy --policy-arn arn:aws:iam::104506445608:policy/PublicSnapper
{
"Policy": {
"PolicyName": "PublicSnapper",
"PolicyId": "ANPARQVIRZ4UD6B2PNSLD",
"Arn": "arn:aws:iam::104506445608:policy/PublicSnapper",
"Path": "/",
"DefaultVersionId": "v9",
"AttachmentCount": 1,
"PermissionsBoundaryUsageCount": 0,
"IsAttachable": true,
"CreateDate": "2023-06-10T22:33:41+00:00",
"UpdateDate": "2024-01-15T23:47:11+00:00",
"Tags": []
}
}

当前生效的策略版本是v9

  • PolicyName: PublicSnapper - 策略的名称。

  • PolicyId: ANPARQVIRZ4UD6B2PNSLD - 策略的唯一标识符。

  • Arn: arn:aws:iam::104506445608:policy/PublicSnapper - 策略的 ARN。

  • Path: / - 策略的路径(默认路径)。

  • DefaultVersionId: v9 - 当前生效的策略版本是 v9,说明这个策略可能被更新过多次(从 v1 到 v9)。

  • AttachmentCount: 1 - 该策略当前附加到了 1 个实体(这里是用户 intern)。

  • PermissionsBoundaryUsageCount: 0 - 没有使用权限边界。

  • IsAttachable: true - 表示这是一个托管策略,可以附加到用户、组或角色。

  • CreateDate: 2023-06-10T22:33:41+00:00 - 策略创建时间(2023年6月10日)。

  • UpdateDate: 2024-01-15T23:47:11+00:00 - 最后一次更新时间(2024年1月15日)。

  • Tags: [] - 没有附加标签。

查看策略的具体内容aws iam get-policy-version --policy-arn arn:aws:iam::104506445608:policy/PublicSnapper --version-id v9

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
┌──(root㉿LAPTOP-40PQI58C)-[~/Desktop/cicd/cicd-goat/reports/caterpillar]
└─# aws iam get-policy-version --policy-arn arn:aws:iam::104506445608:policy/PublicSnapper --version-id v9
{
"PolicyVersion": {
"Document": {
"Version": "2012-10-17",
"Statement": [
{
"Sid": "Intern1",
"Effect": "Allow",
"Action": "ec2:DescribeSnapshotAttribute",
"Resource": "arn:aws:ec2:us-east-1::snapshot/snap-0c0679098c7a4e636"
},
{
"Sid": "Intern2",
"Effect": "Allow",
"Action": "ec2:DescribeSnapshots",
"Resource": "*"
},
{
"Sid": "Intern3",
"Effect": "Allow",
"Action": [
"iam:GetPolicyVersion",
"iam:GetPolicy",
"iam:ListAttachedUserPolicies"
],
"Resource": [
"arn:aws:iam::104506445608:user/intern",
"arn:aws:iam::104506445608:policy/PublicSnapper"
]
},
{
"Sid": "Intern4",
"Effect": "Allow",
"Action": [
"ebs:ListSnapshotBlocks",
"ebs:GetSnapshotBlock"
],
"Resource": "*"
}
]
},
"VersionId": "v9",
"IsDefaultVersion": true,
"CreateDate": "2024-01-15T23:47:11+00:00"
}
}

拥有ec2:DescribeSnapshotAttributeec2:DescribeSnapshots这两个权限。这个两个权限都可以查看快照信息,不过第一个是针对于特定快照的,并且可以查看具体信息。第二个是针对所有快照的,只能查看基本信息。

列出当前用户拥有的快照aws ec2 describe-snapshots --owner-ids self --region us-east-1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
┌──(root㉿LAPTOP-40PQI58C)-[~/Desktop/cicd/cicd-goat/reports/caterpillar]
└─# aws ec2 describe-snapshots --owner-ids self --region us-east-1
{
"Snapshots": [
{
"Tags": [
{
"Key": "Name",
"Value": "PublicSnapper"
}
],
"StorageTier": "standard",
"TransferType": "standard",
"CompletionTime": "2023-06-12T15:22:57.924000+00:00",
"SnapshotId": "snap-0c0679098c7a4e636",
"VolumeId": "vol-0ac1d3295a12e424b",
"State": "completed",
"StartTime": "2023-06-12T15:20:20.580000+00:00",
"Progress": "100%",
"OwnerId": "104506445608",
"Description": "Created by CreateImage(i-06d9095368adfe177) for ami-07c95fb3e41cb227c",
"VolumeSize": 8,
"Encrypted": false
},
{
"StorageTier": "standard",
"TransferType": "standard",
"CompletionTime": "2023-08-24T19:34:22.909000+00:00",
"SnapshotId": "snap-035930ba8382ddb15",
"VolumeId": "vol-09149587639d7b804",
"State": "completed",
"StartTime": "2023-08-24T19:30:49.742000+00:00",
"Progress": "100%",
"OwnerId": "104506445608",
"Description": "Created by CreateImage(i-0199bf97fb9d996f1) for ami-0e411723434b23d13",
"VolumeSize": 24,
"Encrypted": false
}
]
}

查看快照的createVolumePermission属性

createVolumePermission这个属性决定了谁可以用这个快照来创建EBS卷

EBS(Elastic Block Store)AWS 提供的持久性块存储服务,用于给 EC2 实例提供存储。简单来说,EBS 卷就像是一块云端的硬盘,可以挂载到 EC2 服务器上,并在服务器关机后仍然保留数据。

1
2
3
4
5
6
7
8
9
10
┌──(root㉿LAPTOP-40PQI58C)-[~/Desktop/cicd/cicd-goat/reports/caterpillar]
└─# aws ec2 describe-snapshot-attribute --snapshot-id snap-0c0679098c7a4e636 --attribute createVolumePermission --region us-east-1
{
"SnapshotId": "snap-0c0679098c7a4e636",
"CreateVolumePermissions": [
{
"Group": "all"
}
]
}

{"Group":"all"}表明所有用户都可以用这个夸张进行创建EBS卷

然后我们就可以在aws控制台 进入ec2板块->快照 搜索快照

image-20250329183403549

从快照复制卷

image-20250329183449849

创建好的卷需要记住这个可用区

image-20250329183542169

然后创建一个实例镜像啥的选免费套餐就行

记得创建一个密钥对

这里的可用区一定要和卷的可用区一样

image-20250329183908187

其他的默认,创建实例

不能直接远程登录root

image-20250329184258695

使用他要求的ec2-user就行了

image-20250329184345285

然后把刚才的卷挂载到服务器上面

image-20250329184526560

image-20250329184613036

列出所有块设备

image-20250329184652533

将xvdb挂载一下 mount /dev/xvdb1 /root/pwnedlabs/

image-20250329184911822

/root/pwnedlabs/home/intern/practice_files目录下找到了一个s3_download_file.php

image-20250329185229745

s3_download_file.php中包含了一个桶名称为ecorp-client-data的AK/SK

在aws cli配置好aksk之后,就可以访问存储桶了

image-20250329185459224

image-20250329185545232

Plunder Public RDS Snapshots

Scenario

Huge Logistics, a global logistics leader, has enlisted your team’s expertise for an external security review of their cloud infrastructure. Starting with the provided AWS Account ID, your task is to uncover security flaws within their AWS environment and demonstrate the potential risks they pose. Every finding will bolster their defense against future threats.

靶机只给了一个AWS account ID

image-20250331151525908

看到这个AWS account ID。经过前面两个靶场的经验。我去找了这个ID的EBS快照。但是没找到东西😂

看了wp才知道,这个靶场是利用了RDS快照

然后我就去找了AWS的快照类型

AWS几个主要的快照

1. Amazon EBS 快照(Elastic Block Store Snapshots)

EBS 快照用于 备份 Amazon EBS 卷,主要有以下类型:

  • 手动快照(Manual Snapshots)
    • 由用户手动创建的 EBS 卷备份。
  • 自动快照(Automated Snapshots)
    • 由 AWS Backup 或生命周期策略(Lifecycle Policies)自动创建。
  • 增量快照(Incremental Snapshots)
    • AWS 只存储自上次快照以来更改的数据,以节省存储成本。
  • 共享快照(Shared Snapshots)
    • 你可以与 其他 AWS 账户 共享快照,但加密的快照必须使用相同的 KMS 密钥。
  • 公共快照(Public Snapshots)
    • 任何 AWS 账户都可以访问的快照。

2. Amazon RDS 快照(Relational Database Service Snapshots)

RDS 快照用于 备份 AWS RDS 数据库,主要包括:

  • 手动 RDS 快照(Manual DB Snapshots)
    • 由用户手动创建的数据库备份,可以保留无限时间。
  • 自动 RDS 快照(Automated DB Snapshots)
    • 由 AWS 维护,并根据保留策略自动删除。
  • 共享 RDS 快照(Shared DB Snapshots)
    • 允许你共享数据库快照给其他 AWS 账户。
  • 公共 RDS 快照(Public DB Snapshots)
    • 任何 AWS 账户都可以访问的数据库快照。
  • 跨区域复制 RDS 快照(Cross-Region DB Snapshots)
    • 允许你将快照复制到其他 AWS 区域,以提高容灾能力。

3. Amazon Aurora 快照(Aurora Snapshots)

Aurora 数据库集群也支持快照,与 RDS 类似,包含:

  • 手动 Aurora 快照(Manual Aurora Snapshots)
  • 自动 Aurora 快照(Automated Aurora Snapshots)
  • 共享 Aurora 快照(Shared Aurora Snapshots)
  • 公共 Aurora 快照(Public Aurora Snapshots)
  • 跨区域复制 Aurora 快照(Cross-Region Aurora Snapshots)

4. Amazon Redshift 快照

Redshift 是 AWS 的 数据仓库,它的快照类型包括:

  • 手动快照(Manual Snapshots)
  • 自动快照(Automated Snapshots)
  • 共享快照(Shared Snapshots)
  • 跨区域复制快照(Cross-Region Snapshots)

5. Amazon FSx 快照

Amazon FSx 主要用于 托管文件系统,支持以下快照:

  • FSx for Windows File Server Snapshots
  • FSx for Lustre Snapshots

6. Amazon Backup 管理的快照

AWS Backup 提供 集中化的备份管理,支持:

  • EBS 卷快照
  • RDS/Aurora 数据库快照
  • DynamoDB 备份
  • EFS 备份
  • FSx 备份
  • Storage Gateway 备份

这个AWS account ID 下面有一个RDS的公共快照

image-20250331182601858

还原快照

image-20250331182625475

随便起一个名称

image-20250331182658524

新建一个VPC,然后设置公开访问

image-20250331182804215

然后换源快照,时间可能稍长一些

image-20250331183049646

设置EC2连接

image-20250331183730703

创建一个EC2

image-20250331183803542

这里的VPC要与数据库在同一个VPC一样

image-20250331184041604

然后就可以将数据库连接到EC2上面了

image-20250331184407036

然后修改数据库密码

image-20250331184512092

image-20250331184533617

使用psql -h <endpoint> -U postgres连接到数据库

<endpoint>替换为

image-20250331184920800

EC2上面没有psql使用apt install -y postgresql-client命令安装一个

image-20250331185304398

因为是第一次见到这个数据库,这里我刚开始没明白为什么要使用postgres这个用户去连接数据库

昨晚这个靶场之后我问了一下GPT GPT是这样回答的

image-20250331200351955

使用\l列出数据库

image-20250331194410638

使用\c 数据库名来使用数据库

image-20250331194523587

使用\dt列出数据表

image-20250331194550701

image-20250331194627566