# クラウドペンテスティングの方法論 {{#include ../banners/hacktricks-training.md}}
## 基本的な方法論 各クラウドには独自の特性がありますが、一般的にクラウド環境をテストする際に**ペンテスターが確認すべき共通の事項**がいくつかあります: - **ベンチマークチェック** - これにより、**環境の規模**や**使用されているサービス**を理解するのに役立ちます。 - ほとんどのテストを**自動化ツール**で実行できるため、いくつかの**迅速な誤設定**を見つけることも可能です。 - **サービスの列挙** - ベンチマークテストを正しく実施していれば、ここでの誤設定はあまり見つからないでしょうが、ベンチマークテストで見落とされていたものが見つかるかもしれません。 - これにより、クラウド環境で**何が正確に使用されているか**を知ることができます。 - 次のステップに大いに役立ちます。 - **公開されている資産の確認** - これは前のセクションで行うことができ、**インターネットに潜在的に公開されているすべてのもの**を見つけ出し、どのようにアクセスできるかを確認する必要があります。 - ここでは、**手動で公開されたインフラストラクチャ**(ウェブページを持つインスタンスや他のポートが公開されているもの)や、**公開されるように設定できる他のクラウド管理サービス**(DBやバケットなど)について取り上げています。 - 次に、そのリソースが**公開可能かどうか**を確認する必要があります(機密情報?脆弱性?公開されたサービスの誤設定?)。 - **権限の確認** - ここでは、クラウド内の各ロール/ユーザーの**すべての権限を把握**し、それがどのように使用されているかを確認する必要があります。 - **特権の高い**(すべてを制御する)アカウントが多すぎる?生成されたキーが使用されていない?... これらのチェックのほとんどは、すでにベンチマークテストで行われているはずです。 - クライアントがOpenIDやSAML、その他の**フェデレーション**を使用している場合、**各ロールがどのように割り当てられているか**についてさらに**情報**を求める必要があります(管理者ロールが1人のユーザーに割り当てられているのと100人に割り当てられているのは同じではありません)。 - **管理者**権限 "\*:\*" を持つユーザーを見つけるだけでは**不十分**です。使用されるサービスによっては、非常に**敏感**な**他の権限**がたくさんあります。 - さらに、権限を悪用する**潜在的な特権昇格**の方法があります。これらすべてのことを考慮し、**できるだけ多くの特権昇格パス**を報告する必要があります。 - **統合の確認** - **他のクラウドやSaaSとの統合**がクラウド環境内で使用されている可能性が非常に高いです。 - **監査しているクラウドの統合**については、**その統合を(悪用)するアクセス権を持つのは誰か**を通知し、実行されているアクションが**どれほど敏感**であるかを尋ねる必要があります。\ 例えば、GCPがデータを取得しているAWSバケットに書き込むことができるのは誰か(GCPでそのデータを扱う際のアクションの敏感さを尋ねる)。 - **監査しているクラウド内の統合**については、外部プラットフォームからの**その統合を(悪用)するための外部アクセス権を持つのは誰か**を尋ね、データがどのように使用されているかを確認する必要があります。\ 例えば、サービスがGCRにホストされているDockerイメージを使用している場合、そのイメージを修正するアクセス権を持つのは誰か、AWSクラウド内で実行されたときにそのイメージがどのような機密情報やアクセスを取得するかを尋ねる必要があります。 ## マルチクラウドツール 異なるクラウド環境をテストするために使用できるツールがいくつかあります。このセクションでは、インストール手順とリンクが示されます。 ### [PurplePanda](https://github.com/carlospolop/purplepanda) クラウドおよびクラウド/SaaS間の**悪い設定や特権昇格パスを特定する**ためのツールです。 {{#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" ```
他の**GCPインサイト**(サービスを列挙するのに便利)を確認するには、次を使用します: [https://github.com/turbot/steampipe-mod-gcp-insights](https://github.com/turbot/steampipe-mod-gcp-insights) Terraform GCPコードを確認するには: [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には、AWS、Azure、Office 365、Rackspace、Salesforceをサポートする_**Audit Cloud Infrastructure**_スキャンがあります。**Azure**で**Client Id**を取得するために、いくつかの追加設定が必要です。 ### [**cloudlist**](https://github.com/projectdiscovery/cloudlist) Cloudlistは、クラウドプロバイダーから資産(ホスト名、IPアドレス)を取得するための**マルチクラウドツール**です。 {{#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は、インフラストラクチャ資産とそれらの関係を直感的なグラフビューで統合するPythonツールで、Neo4jデータベースによって支えられています。 {{#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シャドウ管理者が含まれます。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}} ### Attack Graph [**Stormspotter** ](https://github.com/Azure/Stormspotter)は、Azureサブスクリプション内のリソースの「攻撃グラフ」を作成します。これにより、レッドチームやpentesterはテナント内の攻撃面とピボットの機会を視覚化でき、ディフェンダーはインシデント対応作業を迅速に方向付け、優先順位を付けることができます。 ### Office365 **Global Admin**または少なくとも**Global Admin Reader**が必要です(ただし、Global Admin Readerには少し制限があります)。ただし、これらの制限は一部のPSモジュールに現れ、**ウェブアプリケーション経由で**機能にアクセスすることで回避できます。 {{#include ../banners/hacktricks-training.md}}