# Pentesting Cloud Methodology {{#include ../banners/hacktricks-training.md}}
## 基本方法论 每个云都有其独特性,但一般来说,在测试云环境时,有一些**渗透测试人员应该检查的共同事项**: - **基准检查** - 这将帮助你**了解环境的规模**和**使用的服务** - 这也将使你能够找到一些**快速的配置错误**,因为你可以使用**自动化工具**执行大部分测试 - **服务枚举** - 如果你正确执行了基准测试,你可能不会在这里发现更多的配置错误,但你可能会发现一些在基准测试中未被关注的错误。 - 这将使你知道**在云环境中到底使用了什么** - 这在接下来的步骤中会有很大帮助 - **检查暴露的资产** - 这可以在前面的部分中完成,你需要**找出所有可能暴露**于互联网的内容以及如何访问它。 - 这里我指的是**手动暴露的基础设施**,如具有网页的实例或其他暴露的端口,以及其他**可以配置为暴露的云管理服务**(如数据库或存储桶) - 然后你应该检查**该资源是否可以被暴露**(机密信息?漏洞?暴露服务中的配置错误?) - **检查权限** - 在这里你应该**找出每个角色/用户的所有权限**以及它们是如何使用的 - 过多的**高权限**(控制一切)账户?未使用的生成密钥?... 大部分这些检查应该已经在基准测试中完成 - 如果客户使用OpenID或SAML或其他**联合身份验证**,你可能需要向他们询问更多关于**每个角色是如何分配的**信息(管理员角色分配给1个用户或100个用户是不同的) - **仅仅找到**哪些用户具有**管理员**权限“*:*”是不够的。还有很多**其他权限**,根据使用的服务可能非常**敏感**。 - 此外,还有**潜在的权限提升**方式可以通过滥用权限来实现。所有这些都应该考虑在内,并且**尽可能多的权限提升路径**应该被报告。 - **检查集成** - 很可能在云环境中使用了**与其他云或SaaS的集成**。 - 对于**你正在审计的云的集成**与其他平台,你应该通知**谁有权访问(滥用)该集成**,并询问**执行该操作的敏感性**。\ 例如,谁可以在AWS存储桶中写入数据,而GCP正在从中获取数据(询问在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, 阿里云, 甲骨文云基础设施 {{#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。在 **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 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) 一个工具,用于在主要云服务提供商(亚马逊、谷歌、微软、DigitalOcean、阿里巴巴、Vultr、Linode)上查找公司的(目标)基础设施、文件和应用程序。 ### [CloudFox](https://github.com/BishopFox/cloudfox) - CloudFox 是一个用于查找云基础设施中可利用攻击路径的工具(目前仅支持 AWS 和 Azure,GCP 即将推出)。 - 这是一个枚举工具,旨在补充手动渗透测试。 - 它不会在云环境中创建或修改任何数据。 ### 更多云安全工具列表 - [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}} ### 攻击图 [**Stormspotter** ](https://github.com/Azure/Stormspotter) 创建 Azure 订阅中资源的“攻击图”。它使红队和渗透测试人员能够可视化攻击面和租户内的转移机会,并增强防御者快速定位和优先处理事件响应工作的能力。 ### Office365 您需要 **Global Admin** 或至少 **Global Admin Reader**(但请注意,Global Admin Reader 有一些限制)。然而,这些限制出现在某些 PS 模块中,可以通过 **通过网络应用程序** 访问功能来绕过。 {{#include ../banners/hacktricks-training.md}}