11 KiB
AWS - S3 Unauthenticated Enum
{{#include ../../../../banners/hacktricks-training.md}}
S3 Public Buckets
bucket は、任意のユーザーが bucket の内容を list できる場合に “public” と見なされ、bucket の内容を特定のユーザーだけが list または write できる場合に “private” と見なされます。
企業では bucket permissions が mis-configured になっていて、すべてのアクセス権が付与されていたり、AWS のどの account からでも認証済みの全ユーザーにアクセスを許していたりすることがあります(つまり誰にでも)。ただし、このような misconfigurations があっても、bucket 自体に独自の access control lists (ACLs) があるため、実行できない action もある点に注意してください。
AWS-S3 の misconfiguration についてはこちら: http://flaws.cloud and http://flaws2.cloud/
Finding AWS Buckets
Webpage が AWS を使ってリソースを保存しているかを見つけるためのさまざまな方法:
Enumeration & OSINT:
- wappalyzer browser plugin を使う
- burp を使って(web を spidering する)か、ページを手動で辿ることで、loaded されたすべての resources は History に保存される
- 次のようなドメインで resources を確認する:
http://s3.amazonaws.com/[bucket_name]/
http://[bucket_name].s3.amazonaws.com/
- CNAMES を確認する。
resources.domain.comがbucket.s3.amazonaws.comを CNAME に持つことがある - s3dns – DNS traffic を解析して cloud storage buckets (S3, GCP, Azure) を受動的に特定する軽量 DNS server。CNAME を検出し、resolution chain をたどり、bucket pattern に一致させるため、brute-force や API ベースの discovery の静かな代替手段になる。recon や OSINT の workflow に最適。
- すでに discovered された open buckets が載っている web、https://buckets.grayhatwarfare.com を確認する。
- 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/ に visit してもよい。
Brute-Force
pentesting 対象の企業に関連する name を brute-force して bucket を見つけられる:
- https://github.com/sa7mon/S3Scanner
- https://github.com/clario-tech/s3-inspector
- https://github.com/jordanpotti/AWSBucketDump (潜在的な bucket name の list を含む)
- 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 open buckets がある場合、BucketLoot を使って自動的に 興味深い情報を検索できる。
Find the Region
AWS でサポートされているすべての region は https://docs.aws.amazon.com/general/latest/gr/s3.html で確認できる。
By DNS
dig と nslookup を使って、発見した IP に対して DNS request を行うことで 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.
resolved domain には "website" という単語が含まれていることを確認してください。
static website には flaws.cloud.s3-website-us-west-2.amazonaws.com にアクセスして行けます
または bucket には flaws.cloud.s3-us-west-2.amazonaws.com を訪れてアクセスできます
試してみることで
bucket にアクセスしようとして、domain name で別の region を指定した場合(たとえば bucket が bucket.s3.amazonaws.com にあるのに、bucket.s3-website-us-west-2.amazonaws.com にアクセスしようとすると)、正しい場所が示されます:
bucket の列挙
bucket の公開状態をテストするには、ユーザーは web browser に URL を入力するだけでよいです。private bucket は "Access Denied" を返します。public bucket は保存されている最初の 1,000 個の objects を一覧表示します。
Everyone に公開:
Private:
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]
バケットにドメイン名がない場合、列挙しようとするときは、バケット名のみを入れ、AWSs3ドメイン全体は入れないでください。例: s3://<BUCKETNAME>
Public URL template
https://{user_provided}.s3.amazonaws.com
public Bucket から Account ID を取得する
新しい S3:ResourceAccount Policy Condition Key を利用することで、AWS account を特定できます。この condition は、S3 bucket が属している account に基づいて access を制限します(他の account-based policies は、要求元 principal が属している account に基づいて制限します)。
また、policy には wildcards を含められるため、account number を 1桁ずつ 見つけることが可能です。
この tool はこの process を自動化します:
# 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 と、この exploit を自動化するツール conditional-love を参照してください。
Confirming a bucket belongs to an AWS account
this blog post** で説明されているように、bucket を list する権限がある場合、次のような request を送ることで、その 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>
エラーが “Access Denied” なら、アカウントIDが間違っていたことを意味します。
ルートアカウント列挙に Email を使う
この blog post で説明されているように、ACL を使って S3 bucket に対する権限を Email address に与えようとしてみることで、その Email address が何らかの AWS account に関連付いているかを確認できます。これで error が発生しなければ、その email はどこかの 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/
{{#include ../../../../banners/hacktricks-training.md}}
.png)
.png)
.png)