# Pentesting クラウド方法論 {{#include ../banners/hacktricks-training.md}}
## 基本的なメソドロジー 各クラウドには固有の特性がありますが、一般的にクラウド環境をテストする際にペンテスターが確認すべき**共通の項目**がいくつかあります: - **ベンチマークチェック** - これは環境の**規模を理解**し、**利用されているサービス**を把握するのに役立ちます - ほとんどのテストを**自動化ツール**で実行できるため、**迅速な設定ミス**を見つけるのにも有効です - **サービスの列挙** - ベンチマークテストを正しく実施していればここで新たな設定ミスは多く見つからない可能性がありますが、ベンチマークで見られていなかったものが見つかることがあります - これによりクラウド環境で**具体的に何が使われているか**を把握できます - 次のステップで非常に役立ちます - **公開されているアセットの確認** - これは前節の間に実施できます。インターネットに**何が潜在的に公開されているか**、またそれにどうアクセスできるかを**全て見つけ出す**必要があります。 - ここでは手動で公開されたインフラ(ウェブページや他のポートが公開されているインスタンスなど)や、公開可能に設定されうる**クラウド管理サービス**(例えば DBs やバケット)について扱います - 次にそのリソースが**公開可能かどうかを確認**するべきです(機密情報か?脆弱性か?公開サービスの設定ミスか?) - **権限の確認** - ここではクラウド内の各ロール/ユーザーの**全ての権限を調べ**、それらがどのように使われているかを把握するべきです - あまりにも**多くの高権限アカウント**(すべてを制御する)がありますか? 生成されたキーが未使用ですか?… これらの多くはベンチマークテストで既に確認されているはずです - クライアントが OpenID や SAML やその他の federation を使用している場合、各ロールが**どのように割り当てられているか**についてさらに**情報**を求める必要があるかもしれません(admin ロールが 1 人に割り当てられているのと 100 人に割り当てられているのとでは同じではありません) - 単にどのユーザーが "**admin**" 権限("*:*")を持っているかを見つけるだけでは**不十分**です。利用されているサービスによっては他にも非常に**センシティブな**権限が多数あります。 - さらに、権限を悪用して進められる**privesc** の経路が存在する可能性があります。これらすべてを考慮し、**可能な限り多くの privesc パス**を報告すべきです。 - **統合の確認** - クラウド環境内で他のクラウドや SaaS との**統合**が利用されている可能性が高いです。 - 監査対象のクラウドが他のプラットフォームと統合されている場合、**その統合を(濫用)できるのは誰か**を通知し、その操作がどれほど**センシティブ**かを確認すべきです。\ 例えば、GCP がデータを取得している AWS のバケットに誰が書き込みできるか(GCP 側でそのデータを扱う操作がどれほどセンシティブかを確認する)など。 - 監査対象のクラウド内に外部プラットフォームからの統合がある場合、**外部からその統合を(濫用)できるのは誰か**を確認し、そのデータがどのように使われているかをチェックすべきです。\ 例えば、あるサービスが GCR にホストされた Docker image を使用している場合、その image を修正できるのは誰か、そしてその image が AWS クラウド内で実行されたときにどのような機密情報やアクセスを得るかを確認すべきです。 ## マルチクラウド用ツール さまざまなクラウド環境をテストするために使えるツールがいくつかあります。インストール手順とリンクはこのセクションで示します。 ### [PurplePanda](https://github.com/carlospolop/purplepanda) クラウド内およびクラウド/SaaS 間での**不適切な設定や privesc パスを特定する**ツールです。 {{#tabs }} {{#tab name="Install" }} ```bash # You need to install and run neo4j also git clone https://github.com/carlospolop/PurplePanda cd PurplePanda python3 -m venv . source bin/activate python3 -m pip install -r requirements.txt export PURPLEPANDA_NEO4J_URL="bolt://neo4j@localhost:7687" export PURPLEPANDA_PWD="neo4j_pwd_4_purplepanda" python3 main.py -h # Get help ``` {{#endtab }} {{#tab name="GCP" }} ```bash export GOOGLE_DISCOVERY=$(echo 'google: - file_path: "" - file_path: "" service_account_id: "some-sa-email@sidentifier.iam.gserviceaccount.com"' | base64) python3 main.py -a -p google #Get basic info of the account to check it's correctly configured python3 main.py -e -p google #Enumerate the env ``` {{#endtab }} {{#endtabs }} ### [Prowler](https://github.com/prowler-cloud/prowler) これは **AWS, GCP & Azure** をサポートしています。各プロバイダの設定方法は [https://docs.prowler.cloud/en/latest/#aws](https://docs.prowler.cloud/en/latest/#aws) を参照してください。 ```bash # Install pip install prowler prowler -v # Run prowler # Example prowler aws --profile custom-profile [-M csv json json-asff html] # Get info about checks & services prowler --list-checks prowler --list-services ``` ### [CloudSploit](https://github.com/aquasecurity/cloudsploit) AWS, Azure, Github, Google, Oracle, Alibaba {{#tabs }} {{#tab name="Install" }} ```bash # Install git clone https://github.com/aquasecurity/cloudsploit.git cd cloudsploit npm install ./index.js -h ## Docker instructions in github ``` {{#endtab }} {{#tab name="GCP" }} ```bash ## You need to have creds for a service account and set them in config.js file ./index.js --cloud google --config ``` {{#endtab }} {{#endtabs }} ### [ScoutSuite](https://github.com/nccgroup/ScoutSuite) AWS, Azure, GCP, Alibaba Cloud, Oracle Cloud Infrastructure {{#tabs }} {{#tab name="Install" }} ```bash mkdir scout; cd scout virtualenv -p python3 venv source venv/bin/activate pip install scoutsuite scout --help ## Using Docker: https://github.com/nccgroup/ScoutSuite/wiki/Docker-Image ``` {{#endtab }} {{#tab name="GCP" }} ```bash scout gcp --report-dir /tmp/gcp --user-account --all-projects ## use "--service-account KEY_FILE" instead of "--user-account" to use a service account SCOUT_FOLDER_REPORT="/tmp" for pid in $(gcloud projects list --format="value(projectId)"); do echo "================================================" echo "Checking $pid" mkdir "$SCOUT_FOLDER_REPORT/$pid" scout gcp --report-dir "$SCOUT_FOLDER_REPORT/$pid" --no-browser --user-account --project-id "$pid" done ``` {{#endtab }} {{#endtabs }} ### [Steampipe](https://github.com/turbot) {{#tabs }} {{#tab name="Install" }} Steampipe をダウンロードしてインストールします([https://steampipe.io/downloads](https://steampipe.io/downloads))。または Brew を使用: ``` brew tap turbot/tap brew install steampipe ``` {{#endtab }} {{#tab name="GCP" }} ```bash # Install gcp plugin steampipe plugin install gcp # Use https://github.com/turbot/steampipe-mod-gcp-compliance.git git clone https://github.com/turbot/steampipe-mod-gcp-compliance.git cd steampipe-mod-gcp-compliance # To run all the checks from the dashboard steampipe dashboard # To run all the checks from rhe cli steampipe check all ```
すべてのプロジェクトをチェック すべてのプロジェクトをチェックするには、テストするすべてのプロジェクトを示す `gcp.spc` ファイルを生成する必要があります。以下のスクリプトに従ってください。
```bash FILEPATH="/tmp/gcp.spc" rm -rf "$FILEPATH" 2>/dev/null # Generate a json like object for each project for pid in $(gcloud projects list --format="value(projectId)"); do echo "connection \"gcp_$(echo -n $pid | tr "-" "_" )\" { plugin = \"gcp\" project = \"$pid\" }" >> "$FILEPATH" done # Generate the aggragator to call echo 'connection "gcp_all" { plugin = "gcp" type = "aggregator" connections = ["gcp_*"] }' >> "$FILEPATH" echo "Copy $FILEPATH in ~/.steampipe/config/gcp.spc if it was correctly generated" ``` To check **他の GCP インサイト**(サービスの列挙に役立ちます)を確認するには: [https://github.com/turbot/steampipe-mod-gcp-insights](https://github.com/turbot/steampipe-mod-gcp-insights) To check Terraform GCP code: [https://github.com/turbot/steampipe-mod-terraform-gcp-compliance](https://github.com/turbot/steampipe-mod-terraform-gcp-compliance) Steampipe のその他の GCP プラグイン: [https://github.com/turbot?q=gcp](https://github.com/turbot?q=gcp) {{#endtab }} {{#tab name="AWS" }} ```bash # Install aws plugin steampipe plugin install aws # Modify the spec indicating in "profile" the profile name to use nano ~/.steampipe/config/aws.spc # Get some info on how the AWS account is being used git clone https://github.com/turbot/steampipe-mod-aws-insights.git cd steampipe-mod-aws-insights steampipe dashboard # Get the services exposed to the internet git clone https://github.com/turbot/steampipe-mod-aws-perimeter.git cd steampipe-mod-aws-perimeter steampipe dashboard # Run the benchmarks git clone https://github.com/turbot/steampipe-mod-aws-compliance cd steampipe-mod-aws-compliance steampipe dashboard # To see results in browser steampipe check all --export=/tmp/output4.json ``` Terraform の AWS コードを確認するには: [https://github.com/turbot/steampipe-mod-terraform-aws-compliance](https://github.com/turbot/steampipe-mod-terraform-aws-compliance) Steampipe の他の AWS プラグイン: [https://github.com/orgs/turbot/repositories?q=aws](https://github.com/orgs/turbot/repositories?q=aws) {{#endtab }} {{#endtabs }} ### [~~cs-suite~~](https://github.com/SecurityFTW/cs-suite) AWS, GCP, Azure, DigitalOcean.\ python2.7 が必要で、メンテナンスされていないようです。 ### Nessus Nessus には _**Audit Cloud Infrastructure**_ スキャンがあり、以下をサポートします: AWS, Azure, Office 365, Rackspace, Salesforce。**Azure** では **Client Id** を取得するためにいくつか追加の設定が必要です。 ### [**cloudlist**](https://github.com/projectdiscovery/cloudlist) Cloudlist は Cloud Providers から Assets(Hostnames, IP Addresses)を取得するための **multi-cloud tool** です。 {{#tabs }} {{#tab name="Cloudlist" }} ```bash cd /tmp wget https://github.com/projectdiscovery/cloudlist/releases/latest/download/cloudlist_1.0.1_macOS_arm64.zip unzip cloudlist_1.0.1_macOS_arm64.zip chmod +x cloudlist sudo mv cloudlist /usr/local/bin ``` {{#endtab }} {{#tab name="Second Tab" }} ```bash ## For GCP it requires service account JSON credentials cloudlist -config ``` {{#endtab }} {{#endtabs }} ### [**cartography**](https://github.com/lyft/cartography) Cartographyは、Neo4jデータベースによって駆動される直感的なグラフビューで、インフラ資産とそれらの関係を統合するPythonツールです。 {{#tabs }} {{#tab name="Install" }} ```bash # Installation docker image pull ghcr.io/lyft/cartography docker run --platform linux/amd64 ghcr.io/lyft/cartography cartography --help ## Install a Neo4j DB version 3.5.* ``` {{#endtab }} {{#tab name="GCP" }} ```bash docker run --platform linux/amd64 \ --volume "$HOME/.config/gcloud/application_default_credentials.json:/application_default_credentials.json" \ -e GOOGLE_APPLICATION_CREDENTIALS="/application_default_credentials.json" \ -e NEO4j_PASSWORD="s3cr3t" \ ghcr.io/lyft/cartography \ --neo4j-uri bolt://host.docker.internal:7687 \ --neo4j-password-env-var NEO4j_PASSWORD \ --neo4j-user neo4j # It only checks for a few services inside GCP (https://lyft.github.io/cartography/modules/gcp/index.html) ## Cloud Resource Manager ## Compute ## DNS ## Storage ## Google Kubernetes Engine ### If you can run starbase or purplepanda you will get more info ``` {{#endtab }} {{#endtabs }} ### [**starbase**](https://github.com/JupiterOne/starbase) Starbaseは、クラウドインフラ、SaaSアプリケーション、セキュリティコントロールなどを含むサービスやシステムから資産と関係性を収集し、Neo4jデータベースで支えられた直感的なグラフビューに統合します。 {{#tabs }} {{#tab name="Install" }} ```bash # You are going to need Node version 14, so install nvm following https://tecadmin.net/install-nvm-macos-with-homebrew/ npm install --global yarn nvm install 14 git clone https://github.com/JupiterOne/starbase.git cd starbase nvm use 14 yarn install yarn starbase --help # Configure manually config.yaml depending on the env to analyze yarn starbase setup yarn starbase run # Docker git clone https://github.com/JupiterOne/starbase.git cd starbase cp config.yaml.example config.yaml # Configure manually config.yaml depending on the env to analyze docker build --no-cache -t starbase:latest . docker-compose run starbase setup docker-compose run starbase run ``` {{#endtab }} {{#tab name="GCP" }} ```yaml ## Config for GCP ### Check out: https://github.com/JupiterOne/graph-google-cloud/blob/main/docs/development.md ### It requires service account credentials integrations: - name: graph-google-cloud instanceId: testInstanceId directory: ./.integrations/graph-google-cloud gitRemoteUrl: https://github.com/JupiterOne/graph-google-cloud.git config: SERVICE_ACCOUNT_KEY_FILE: "{Check https://github.com/JupiterOne/graph-google-cloud/blob/main/docs/development.md#service_account_key_file-string}" PROJECT_ID: "" FOLDER_ID: "" ORGANIZATION_ID: "" CONFIGURE_ORGANIZATION_PROJECTS: false storage: engine: neo4j config: username: neo4j password: s3cr3t uri: bolt://localhost:7687 #Consider using host.docker.internal if from docker ``` {{#endtab }} {{#endtabs }} ### [**SkyArk**](https://github.com/cyberark/SkyArk) スキャン対象の AWS または Azure 環境内で、AWS Shadow Admins を含む最も権限の高いユーザーを特定します。powershell を使用します。 ```bash Import-Module .\SkyArk.ps1 -force Start-AzureStealth # in the Cloud Console IEX (New-Object Net.WebClient).DownloadString('https://raw.githubusercontent.com/cyberark/SkyArk/master/AzureStealth/AzureStealth.ps1') Scan-AzureAdmins ``` ### [Cloud Brute](https://github.com/0xsha/CloudBrute) 企業(ターゲット)のインフラ、ファイル、アプリを主要クラウドプロバイダ(Amazon, Google, Microsoft, DigitalOcean, Alibaba, Vultr, Linode)上で発見するためのツール。 ### [CloudFox](https://github.com/BishopFox/cloudfox) - CloudFoxは、クラウドインフラ内の悪用可能な攻撃経路を発見するためのツールです(現時点ではAWSとAzureのみ対応、GCPは今後対応予定)。 - 手動pentestingを補完する列挙ツールです。 - クラウド環境内のデータを作成・変更しません。 ### クラウドセキュリティツールの追加リスト - [https://github.com/RyanJarv/awesome-cloud-sec](https://github.com/RyanJarv/awesome-cloud-sec) ## Google ### GCP {{#ref}} gcp-security/ {{#endref}} ### Workspace {{#ref}} workspace-security/ {{#endref}} ## AWS {{#ref}} aws-security/ {{#endref}} ## Azure {{#ref}} azure-security/ {{#endref}} ## 共通のクラウドセキュリティ機能 ### 機密コンピューティング {{#ref}} confidential-computing/luks2-header-malleability-null-cipher-abuse.md {{#endref}} {{#include ../banners/hacktricks-training.md}}