# AWS - S3 認証なし列挙 {{#include ../../../banners/hacktricks-training.md}} ## S3 パブリックバケット バケットは、**任意のユーザーがバケットの内容をリストできる**場合に**「パブリック」**と見なされ、**特定のユーザーのみがリストまたは書き込みできる**場合に**「プライベート」**と見なされます。 企業は、**バケットの権限が誤って設定されている**可能性があり、すべてのユーザーまたはAWSの任意のアカウントに認証されたすべてのユーザーにアクセスを許可することがあります(つまり、誰でも)。このような誤設定があっても、バケットには独自のアクセス制御リスト(ACL)があるため、いくつかのアクションは実行できない場合があります。 **AWS-S3の誤設定についてはこちらで学ぶ:** [**http://flaws.cloud**](http://flaws.cloud/) **および** [**http://flaws2.cloud/**](http://flaws2.cloud) ### AWS バケットの発見 ウェブページがAWSを使用してリソースを保存しているかどうかを見つけるためのさまざまな方法: #### 列挙 & OSINT: - **wappalyzer** ブラウザプラグインを使用 - burpを使用して(ウェブを**スパイダー**する)または手動でページをナビゲートすることで、すべての**リソース**が履歴に保存されます。 - ドメインでの**リソースを確認**: ``` http://s3.amazonaws.com/[bucket_name]/ http://[bucket_name].s3.amazonaws.com/ ``` - **CNAMES**を確認します。`resources.domain.com`は`bucket.s3.amazonaws.com`のCNAMEを持っている可能性があります。 - **[s3dns](https://github.com/olizimmermann/s3dns)** – DNSトラフィックを分析することでクラウドストレージバケット(S3、GCP、Azure)を受動的に特定する軽量DNSサーバー。CNAMEを検出し、解決チェーンを追跡し、バケットパターンを一致させ、ブルートフォースやAPIベースの発見に対する静かな代替手段を提供します。偵察やOSINTワークフローに最適です。 - [https://buckets.grayhatwarfare.com](https://buckets.grayhatwarfare.com/)、すでに**発見されたオープンバケット**のウェブサイト。 - **バケット名**と**バケットドメイン名**は**同じである必要があります。** - **flaws.cloud**は**IP** 52.92.181.107にあり、そこに行くと[https://aws.amazon.com/s3/](https://aws.amazon.com/s3/)にリダイレクトされます。また、`dig -x 52.92.181.107`は`s3-website-us-west-2.amazonaws.com`を返します。 - バケットであることを確認するには、[https://flaws.cloud.s3.amazonaws.com/](https://flaws.cloud.s3.amazonaws.com/)を**訪問**することもできます。 #### ブルートフォース ペンテストしている会社に関連する**名前をブルートフォース**することでバケットを見つけることができます: - [https://github.com/sa7mon/S3Scanner](https://github.com/sa7mon/S3Scanner) - [https://github.com/clario-tech/s3-inspector](https://github.com/clario-tech/s3-inspector) - [https://github.com/jordanpotti/AWSBucketDump](https://github.com/jordanpotti/AWSBucketDump)(潜在的なバケット名のリストを含む) - [https://github.com/fellchase/flumberboozle/tree/master/flumberbuckets](https://github.com/fellchase/flumberboozle/tree/master/flumberbuckets) - [https://github.com/smaranchand/bucky](https://github.com/smaranchand/bucky) - [https://github.com/tomdev/teh_s3_bucketeers](https://github.com/tomdev/teh_s3_bucketeers) - [https://github.com/RhinoSecurityLabs/Security-Research/tree/master/tools/aws-pentest-tools/s3](https://github.com/RhinoSecurityLabs/Security-Research/tree/master/tools/aws-pentest-tools/s3) - [https://github.com/Eilonh/s3crets_scanner](https://github.com/Eilonh/s3crets_scanner) - [https://github.com/belane/CloudHunter](https://github.com/belane/CloudHunter)
# パーミュテーションを作成するためのワードリストを生成
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
# テストするためのドメインとサブドメインに基づいてワードリストを生成
## これらのドメインとサブドメインを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
# 攻撃するためのドメインとサブドメインのリストに基づいてパーミュテーションを作成
goaltdns -l /tmp/words-hosts-s3.txt -w /tmp/words-s3.txt -o /tmp/final-words-s3.txt.temp
## 前のツールはサブドメインのパーミュテーションを作成することに特化しているので、そのリストをフィルタリングします
### "."で終わる行を削除
cat /tmp/final-words-s3.txt.temp | grep -Ev "\.$" > /tmp/final-words-s3.txt.temp2
### TLDなしのリストを作成
cat /tmp/final-words-s3.txt.temp2 | sed -E 's/\.[a-zA-Z0-9]+$//' > /tmp/final-words-s3.txt.temp3
### ドットなしのリストを作成
cat /tmp/final-words-s3.txt.temp3 | tr -d "." > /tmp/final-words-s3.txt.temp4http://phantom.s3.amazonaws.com/
### ハイフンなしのリストを作成
cat /tmp/final-words-s3.txt.temp3 | tr "." "-" > /tmp/final-words-s3.txt.temp5
## 最終的なワードリストを生成
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
## s3scannerを呼び出す
s3scanner --threads 100 scan --buckets-file /tmp/final-words-s3.txt | grep bucket_exists
#### S3 バケットの略奪
S3のオープンバケットがある場合、[**BucketLoot**](https://github.com/redhuntlabs/BucketLoot)は自動的に**興味深い情報を検索**できます。
### リージョンを見つける
AWSがサポートするすべてのリージョンは、[**https://docs.aws.amazon.com/general/latest/gr/s3.html**](https://docs.aws.amazon.com/general/latest/gr/s3.html)で確認できます。
#### DNSによる
**`dig`**および**`nslookup`**を使用して、発見されたIPの**DNSリクエスト**を行うことでバケットのリージョンを取得できます:
```bash
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」という単語が含まれていることを確認してください。\
静的ウェブサイトには次のURLでアクセスできます: `flaws.cloud.s3-website-us-west-2.amazonaws.com`\
または、バケットには次のURLでアクセスできます: `flaws.cloud.s3-us-west-2.amazonaws.com`
#### 試してみる
バケットにアクセスしようとした場合、**指定したドメイン名に別のリージョンが含まれている**(たとえば、バケットが `bucket.s3.amazonaws.com` にあるが、`bucket.s3-website-us-west-2.amazonaws.com` にアクセスしようとした場合)、**正しい場所に誘導されます**:
.png>)
### バケットの列挙
バケットのオープン性をテストするために、ユーザーは単にURLをウェブブラウザに入力することができます。プライベートバケットは「アクセス拒否」と応答します。パブリックバケットは、保存された最初の1,000オブジェクトをリストします。
誰でもアクセス可能:
.png>)
プライベート:
.png>)
これをCLIでも確認できます:
```bash
#Use --no-sign-request for check Everyones permissions
#Use --profile