AWS - S3 Unauthenticated Enum
Tip
学习和实践 AWS 黑客技术:
HackTricks Training AWS Red Team Expert (ARTE)
学习和实践 GCP 黑客技术:HackTricks Training GCP Red Team Expert (GRTE)
学习和实践 Azure 黑客技术:
HackTricks Training Azure Red Team Expert (AzRTE)
支持 HackTricks
- 查看 订阅计划!
- 加入 💬 Discord 群组 或 Telegram 群组 或 在 Twitter 🐦 上关注我们 @hacktricks_live.
- 通过向 HackTricks 和 HackTricks Cloud GitHub 仓库提交 PR 来分享黑客技巧。
S3 公共存储桶
A bucket is considered “public” if any user can list the contents of the bucket, and “private” if the bucket’s contents can only be listed or written by certain users.
公司可能会把 buckets 的权限配置错误,导致对所有资源或对任何在 AWS 中已认证的用户(即任何人)开放访问。注意,即使存在这样的配置错误,某些操作也可能无法执行,因为 buckets 可能有各自的访问控制列表 (ACLs)。
Learn about AWS-S3 misconfiguration here: http://flaws.cloud and http://flaws2.cloud/
Finding AWS Buckets
不同的方法可以用来发现网页何时使用 AWS 存储某些资源:
Enumeration & OSINT:
- 使用 wappalyzer 浏览器插件
- 使用 burp(spidering 网页)或通过手动浏览页面,所有被 加载 的 资源 都会保存在 History 中。
- 检查资源 是否出现在如下域名中:
http://s3.amazonaws.com/[bucket_name]/
http://[bucket_name].s3.amazonaws.com/
- 检查 CNAME,因为
resources.domain.com可能有 CNAME 指向bucket.s3.amazonaws.com - s3dns – 一个轻量级的 DNS 服务器,通过分析 DNS 流量被动识别云存储 buckets (S3, GCP, Azure)。它能检测 CNAME、追踪解析链并匹配 bucket 模式,为暴力破解或基于 API 的发现提供一种安静的替代方案。非常适合用于 recon 和 OSINT 工作流。
- 检查 https://buckets.grayhatwarfare.com,这是一个已经 发现的开放 buckets 的网站。
- bucket name 和 bucket domain name 需要 相同。
- flaws.cloud 的 IP 为 52.92.181.107,访问时会重定向到 https://aws.amazon.com/s3/。另外,
dig -x 52.92.181.107会返回s3-website-us-west-2.amazonaws.com。 - 要确认它是一个 bucket,你也可以 访问 https://flaws.cloud.s3.amazonaws.com/。
Brute-Force
你可以通过对与目标公司相关的名称进行 爆破 来发现 buckets:
- https://github.com/sa7mon/S3Scanner
- https://github.com/clario-tech/s3-inspector
- https://github.com/jordanpotti/AWSBucketDump (包含可能的 bucket 名称列表)
- https://github.com/fellchase/flumberboozle/tree/master/flumberbuckets
- https://github.com/smaranchand/bucky
- https://github.com/tomdev/teh_s3_bucketeers
- https://github.com/RhinoSecurityLabs/Security-Research/tree/master/tools/aws-pentest-tools/s3
- https://github.com/Eilonh/s3crets_scanner
- https://github.com/belane/CloudHunter
# Generate a wordlist to create permutations
curl -s https://raw.githubusercontent.com/cujanovic/goaltdns/master/words.txt > /tmp/words-s3.txt.temp
curl -s https://raw.githubusercontent.com/jordanpotti/AWSBucketDump/master/BucketNames.txt >>/tmp/words-s3.txt.temp
cat /tmp/words-s3.txt.temp | sort -u > /tmp/words-s3.txt
# Generate a wordlist based on the domains and subdomains to test
## Write those domains and subdomains in subdomains.txt
cat subdomains.txt > /tmp/words-hosts-s3.txt
cat subdomains.txt | tr "." "-" >> /tmp/words-hosts-s3.txt
cat subdomains.txt | tr "." "\n" | sort -u >> /tmp/words-hosts-s3.txt
# Create permutations based in a list with the domains and subdomains to attack
goaltdns -l /tmp/words-hosts-s3.txt -w /tmp/words-s3.txt -o /tmp/final-words-s3.txt.temp
## The previous tool is specialized increating permutations for subdomains, lets filter that list
### Remove lines ending with "."
cat /tmp/final-words-s3.txt.temp | grep -Ev "\.$" > /tmp/final-words-s3.txt.temp2
### Create list without TLD
cat /tmp/final-words-s3.txt.temp2 | sed -E 's/\.[a-zA-Z0-9]+$//' > /tmp/final-words-s3.txt.temp3
### Create list without dots
cat /tmp/final-words-s3.txt.temp3 | tr -d "." > /tmp/final-words-s3.txt.temp4http://phantom.s3.amazonaws.com/
### Create list without hyphens
cat /tmp/final-words-s3.txt.temp3 | tr "." "-" > /tmp/final-words-s3.txt.temp5
## Generate the final wordlist
cat /tmp/final-words-s3.txt.temp2 /tmp/final-words-s3.txt.temp3 /tmp/final-words-s3.txt.temp4 /tmp/final-words-s3.txt.temp5 | grep -v -- "-\." | awk '{print tolower($0)}' | sort -u > /tmp/final-words-s3.txt
## Call s3scanner
s3scanner --threads 100 scan --buckets-file /tmp/final-words-s3.txt | grep bucket_exists
Loot S3 Buckets
对于开放的 S3 buckets,BucketLoot 可以自动 搜索有价值的信息。
Find the Region
你可以在 https://docs.aws.amazon.com/general/latest/gr/s3.html 找到 AWS 支持的所有 region。
By DNS
你可以通过对发现的 IP 进行 DNS 请求,使用 dig 和 nslookup 来获取 bucket 的 region:
dig flaws.cloud
;; ANSWER SECTION:
flaws.cloud. 5 IN A 52.218.192.11
nslookup 52.218.192.11
Non-authoritative answer:
11.192.218.52.in-addr.arpa name = s3-website-us-west-2.amazonaws.com.
检查解析后的域名是否包含单词 “website”.
你可以通过访问静态网站:flaws.cloud.s3-website-us-west-2.amazonaws.com
或访问 bucket:flaws.cloud.s3-us-west-2.amazonaws.com
通过尝试
如果你尝试访问一个 bucket,但在 域名中指定了另一个区域(例如 bucket 在 bucket.s3.amazonaws.com 但你尝试访问 bucket.s3-website-us-west-2.amazonaws.com),那么你会被 指示到正确的位置:
.png)
枚举 bucket
要测试 bucket 的开放性,用户只需在浏览器中输入 URL。私有 bucket 会响应 “Access Denied”。公共 bucket 会列出已存储的前 1,000 个对象。
对所有人开放:
.png)
私有:
.png)
你也可以使用 cli 检查:
#Use --no-sign-request for check Everyones permissions
#Use --profile <PROFILE_NAME> to indicate the AWS profile(keys) that youwant to use: Check for "Any Authenticated AWS User" permissions
#--recursive if you want list recursivelyls
#Opcionally you can select the region if you now it
aws s3 ls s3://flaws.cloud/ [--no-sign-request] [--profile <PROFILE_NAME>] [ --recursive] [--region us-west-2]
如果 bucket 没有域名,在尝试枚举它时,只放入 bucket 名称,不要使用整个 AWSs3 域名。示例:s3://<BUCKETNAME>
公共 URL 模板
https://{user_provided}.s3.amazonaws.com
从公共 Bucket 获取账户 ID
可以利用新的 S3:ResourceAccount Policy Condition Key 来确定 AWS 账户。该条件会基于 S3 存储桶 限制访问(其他基于账户的策略则是基于发起请求的主体所属的账户来限制访问)。\
由于策略可以包含 通配符,因此可以一次只找出一个数字来确定账户编号。
这个工具自动化了这个过程:
# Installation
pipx install s3-account-search
pip install s3-account-search
# With a bucket
s3-account-search arn:aws:iam::123456789012:role/s3_read s3://my-bucket
# With an object
s3-account-search arn:aws:iam::123456789012:role/s3_read s3://my-bucket/path/to/object.ext
此技术也适用于 API Gateway URLs、Lambda URLs、Data Exchange data sets,甚至可用于获取 tags 的值(如果你知道 tag key)。你可以在 original research 和工具 conditional-love 中找到更多信息以自动化此类利用。
确认 bucket 属于哪个 AWS account
如 this blog post,如果你有列出 bucket 的权限,可以通过发送如下请求来确认该 bucket 所属的 accountID:
curl -X GET "[bucketname].amazonaws.com/" \
-H "x-amz-expected-bucket-owner: [correct-account-id]"
<?xml version="1.0" encoding="UTF-8"?>
<ListBucketResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/">...</ListBucketResult>
If the error is an “Access Denied” it means that the account ID was wrong.
将电子邮件用作 root account enumeration
如 this blog post,所述,可以通过在 S3 bucket 上通过 ACLs 尝试授予一个电子邮件 权限 来检查某个电子邮件地址是否关联到任何 AWS account。如果这不会触发错误,则意味着该电子邮件是某个 AWS account 的 root user:
s3_client.put_bucket_acl(
Bucket=bucket_name,
AccessControlPolicy={
'Grants': [
{
'Grantee': {
'EmailAddress': 'some@emailtotest.com',
'Type': 'AmazonCustomerByEmail',
},
'Permission': 'READ'
},
],
'Owner': {
'DisplayName': 'Whatever',
'ID': 'c3d78ab5093a9ab8a5184de715d409c2ab5a0e2da66f08c2f6cc5c0bdeadbeef'
}
}
)
参考资料
- https://www.youtube.com/watch?v=8ZXRw4Ry3mQ
- https://cloudar.be/awsblog/finding-the-account-id-of-any-public-s3-bucket/
Tip
学习和实践 AWS 黑客技术:
HackTricks Training AWS Red Team Expert (ARTE)
学习和实践 GCP 黑客技术:HackTricks Training GCP Red Team Expert (GRTE)
学习和实践 Azure 黑客技术:
HackTricks Training Azure Red Team Expert (AzRTE)
支持 HackTricks
- 查看 订阅计划!
- 加入 💬 Discord 群组 或 Telegram 群组 或 在 Twitter 🐦 上关注我们 @hacktricks_live.
- 通过向 HackTricks 和 HackTricks Cloud GitHub 仓库提交 PR 来分享黑客技巧。
HackTricks Cloud

