# Pentesting Cloud 방법론 {{#include ../banners/hacktricks-training.md}}
## 기본 방법론 각 클라우드마다 고유한 특성이 있지만, 일반적으로 클라우드 환경을 테스트할 때 **pentester가 확인해야 할 몇 가지 공통 항목**이 있습니다: - **벤치마크 점검** - 이는 환경의 **규모를 이해**하고 **사용되는 서비스**를 파악하는 데 도움이 됩니다 - 대부분의 테스트를 **자동화 도구**로 수행할 수 있기 때문에 일부 **빠른 misconfigurations**를 찾는 데에도 유용합니다 - **서비스 열거** - 벤치마크 테스트를 제대로 수행했다면 여기서 더 많은 misconfigurations를 찾기 어렵지만, 벤치마크에서 찾아보지 않았던 항목을 발견할 수 있습니다. - 이를 통해 클라우드 환경에서 **정확히 무엇이 사용되는지** 알 수 있습니다 - 다음 단계에서 큰 도움이 됩니다 - **노출된 자산 확인** - 이는 이전 섹션에서 수행할 수 있으며, 인터넷에 어떤 방식으로든 **잠재적으로 노출되어 있는 모든 것**과 그것에 어떻게 접근할 수 있는지를 찾아야 합니다. - 여기서는 웹 페이지가 올라가 있는 인스턴스나 다른 포트가 노출된 수동으로 노출된 인프라와, DB나 버킷과 같이 **노출되도록 설정될 수 있는 다른 클라우드 관리형 서비스**에 대해 다루고 있습니다. - 그런 다음 해당 리소스가 **노출될 수 있는지 아닌지**(기밀 정보? 취약점? 노출된 서비스의 misconfigurations?)를 확인해야 합니다. - **권한 확인** - 여기서는 클라우드 내 각 role/user의 **모든 권한을 파악**하고 그것들이 어떻게 사용되는지 확인해야 합니다 - 너무 **많은 고권한(모든 것을 제어하는)** 계정이 있는가? 생성된 키가 사용되지 않고 있는가?... 대부분의 이러한 검사는 이미 벤치마크 테스트에서 수행되었어야 합니다 - 클라이언트가 OpenID나 SAML 또는 다른 **federation**을 사용하고 있다면 각 role이 **어떻게 할당되는지**에 대해 추가 **정보**를 요청해야 할 수도 있습니다(예: admin 역할이 1명에게 할당되는 것과 100명에게 할당되는 것은 같지 않습니다) - 단순히 어떤 사용자가 **admin** 권한 "\*:\*"을 가지고 있는지 찾는 것만으로는 **충분하지 않습니다**. 사용되는 서비스에 따라 매우 **민감한** 많은 **다른 권한들**이 있습니다. - 또한 권한을 남용하여 따를 수 있는 **잠재적 privesc** 경로들이 있습니다. 이 모든 것을 고려하여 가능한 한 **많은 privesc 경로**를 보고해야 합니다. - **통합(Integrations) 확인** - 클라우드 환경 내에서 다른 클라우드나 SaaS와의 **통합이 사용되고 있을 가능성**이 높습니다. - **감사 대상인 클라우드가 다른 플랫폼과 통합된 경우**, 그 통합을 누가 (오용)할 수 있는지 알리고 해당 동작이 얼마나 **민감한지** 물어봐야 합니다.\ 예를 들어, GCP가 데이터를 가져오는 AWS 버킷에 누가 쓸 수 있는지(그 데이터를 처리하는 GCP에서 해당 동작이 얼마나 민감한지 물어보세요). - **감사 대상인 클라우드로부터 외부 플랫폼이 통합하는 경우**, 외부에서 그 통합을 누가 (오용)할 수 있는지 물어보고 그 데이터가 어떻게 사용되는지 확인해야 합니다.\ 예를 들어, 어떤 서비스가 GCR에 호스팅된 Docker 이미지를 사용한다면, 누가 그 이미지를 수정할 수 있는지, 그리고 그 이미지가 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" ```
서비스 열거에 유용한 **다른 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에는 _**Audit Cloud Infrastructure**_ 스캔이 있어 다음을 지원합니다: AWS, Azure, Office 365, Rackspace, Salesforce. **Azure**에서 **Client Id**를 얻으려면 몇 가지 추가 구성이 필요합니다. ### [**cloudlist**](https://github.com/projectdiscovery/cloudlist) Cloudlist는 클라우드 제공업체로부터 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 database 기반의 직관적인 그래프 뷰에서 인프라 자산과 이들 간의 관계를 통합하는 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) 회사 (target)의 인프라, 파일 및 앱을 상위 클라우드 제공업체(Amazon, Google, Microsoft, DigitalOcean, Alibaba, Vultr, Linode)에서 찾아주는 도구입니다. ### [CloudFox](https://github.com/BishopFox/cloudfox) - CloudFox는 클라우드 인프라에서 exploitable attack paths를 찾아주는 도구입니다 (현재는 AWS & Azure만 지원하며 GCP는 곧 지원될 예정입니다). - 수동 pentesting을 보완하기 위한 enumeration 도구입니다. - 클라우드 환경 내의 데이터를 생성하거나 수정하지 않습니다. ### More lists of cloud security tools - [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}}