16 KiB
Pentesting Cloud Methodology
{{#include ../banners/hacktricks-training.md}}
Basic Methodology
Cada cloud tiene sus propias peculiaridades, pero en general hay algunas cosas comunes que un pentester debería comprobar al probar un entorno cloud:
- Benchmark checks
- Esto te ayudará a entender el tamaño del entorno y los servicios usados
- También te permitirá encontrar algunas quick misconfigurations ya que puedes realizar la mayoría de estas pruebas con automated tools
- Services Enumeration
- Probablemente no encuentres muchas más misconfigurations aquí si realizaste correctamente las pruebas de benchmark, pero podrías encontrar algunas que no se estaban buscando en la prueba de benchmark.
- Esto te permitirá saber qué se está usando exactamente en el entorno cloud
- Esto ayudará mucho en los siguientes pasos
- Check exposed assets
- Esto se puede hacer durante la sección anterior, necesitas averiguar todo lo que esté potencialmente expuesto a Internet de alguna manera y cómo se puede acceder.
- Aquí me refiero a infraestructura manualmente expuesta, como instances con páginas web u otros ports expuestos, y también a otros cloud managed services que pueden configurarse para estar expuestos (como DBs o buckets)
- Luego deberías comprobar si ese recurso puede exponerse o no (¿información confidencial? ¿vulnerabilities? ¿misconfigurations en el servicio expuesto?)
- Check permissions
- Aquí deberías averiguar todos los permisos de cada role/user dentro del cloud y cómo se usan
- ¿Demasiadas cuentas highly privileged (controlan todo)? ¿keys generadas que no se usan?... La mayoría de estas comprobaciones ya deberían haberse hecho en las pruebas de benchmark
- Si el cliente está usando OpenID o SAML u otra federation, quizá necesites pedirle más information sobre cómo se asigna cada role (no es lo mismo que el role admin se asigne a 1 user o a 100)
- No basta con encontrar qué users tienen permisos de admin "*:*". Hay muchos other permissions que, dependiendo de los servicios usados, pueden ser muy sensitive.
- Además, hay potential privesc que se pueden seguir abusando de permissions. Todo esto debería tenerse en cuenta y deberían reportarse as much privesc paths as possible.
- Check Integrations
- Es muy probable que se estén usando integrations con other clouds or SaaS dentro del entorno cloud.
- Para las integrations del cloud que estás auditando con otra platform, deberías notificar quién tiene acceso para (ab)usar esa integration y deberías preguntar cuán sensitive es la acción que se está realizando.
Por ejemplo, quién puede escribir en un AWS bucket del que GCP está obteniendo data (pregunta cuán sensitive es la acción en GCP tratando esos data). - Para las integrations dentro del cloud que estás auditando desde external platforms, deberías preguntar quién tiene acceso externo para (ab)usar esa integration y comprobar cómo se está usando esos data.
Por ejemplo, si un service está usando una Docker image alojada en GCR, deberías preguntar quién tiene acceso para modificarla y qué sensitive info y access obtendrá esa image cuando se ejecute dentro de un AWS cloud.
Hunt autonomous data streams writing to globally-unique storage
Durante la post-exploitation, revisa exports de larga duración como log sinks, subscriptions, replication jobs, Firehose streams y diagnostic settings que escriben en buckets o storage accounts con nombre globally-unique. Si el destino puede eliminarse y el mismo nombre puede recrearse bajo control del atacante, el upstream service podría seguir entregando datos sensibles al replacement destination incluso cuando el atacante no pueda actualizar el router resource en sí.
Céntrate en esta comprobación en las páginas de servicios relevantes:
{{#ref}} gcp-security/gcp-post-exploitation/gcp-logging-post-exploitation.md {{#endref}}
{{#ref}} gcp-security/gcp-post-exploitation/gcp-pub-sub-post-exploitation.md {{#endref}}
{{#ref}} gcp-security/gcp-post-exploitation/gcp-storage-post-exploitation.md {{#endref}}
{{#ref}} aws-security/aws-post-exploitation/aws-s3-post-exploitation/README.md {{#endref}}
{{#ref}} azure-security/az-post-exploitation/az-blob-storage-post-exploitation.md {{#endref}}
Multi-Cloud tools
Hay varias tools que se pueden usar para probar diferentes entornos cloud. Los pasos de instalación y los links se indicarán en esta sección.
PurplePanda
Una tool para identificar bad configurations y privesc path en clouds y across clouds/SaaS.
{{#tabs }} {{#tab name="Install" }}
# 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" }}
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
Soporta AWS, GCP y Azure. Revisa cómo configurar cada proveedor en https://docs.prowler.cloud/en/latest/#aws
# Install
pip install prowler
prowler -v
# Run
prowler <provider>
# Example
prowler aws --profile custom-profile [-M csv json json-asff html]
# Get info about checks & services
prowler <provider> --list-checks
prowler <provider> --list-services
CloudSploit
AWS, Azure, Github, Google, Oracle, Alibaba
{{#tabs }} {{#tab name="Install" }}
# Install
git clone https://github.com/aquasecurity/cloudsploit.git
cd cloudsploit
npm install
./index.js -h
## Docker instructions in github
{{#endtab }}
{{#tab name="GCP" }}
## You need to have creds for a service account and set them in config.js file
./index.js --cloud google --config </abs/path/to/config.js>
{{#endtab }} {{#endtabs }}
ScoutSuite
AWS, Azure, GCP, Alibaba Cloud, Oracle Cloud Infrastructure
{{#tabs }} {{#tab name="Instalar" }}
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" }}
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
{{#tabs }} {{#tab name="Install" }} Descarga e instala Steampipe (https://steampipe.io/downloads). O usa Brew:
brew tap turbot/tap
brew install steampipe
{{#endtab }}
{{#tab name="GCP" }}
# 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
Revisar todos los Projects
Para revisar todos los projects necesitas generar el archivo gcp.spc indicando todos los projects a probar. Puedes seguir las indicaciones del siguiente script
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"
Para comprobar otros insights de GCP (útil para enumerar servicios) usa: https://github.com/turbot/steampipe-mod-gcp-insights
Para comprobar código Terraform de GCP: https://github.com/turbot/steampipe-mod-terraform-gcp-compliance
Más plugins de GCP de Steampipe: https://github.com/turbot?q=gcp {{#endtab }}
{{#tab name="AWS" }}
# 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
To check Terraform AWS code: https://github.com/turbot/steampipe-mod-terraform-aws-compliance
More AWS plugins of Steampipe: https://github.com/orgs/turbot/repositories?q=aws {{#endtab }} {{#endtabs }}
cs-suite
AWS, GCP, Azure, DigitalOcean.
Requiere python2.7 y parece no mantenido.
Nessus
Nessus tiene un escaneo Audit Cloud Infrastructure compatible con: AWS, Azure, Office 365, Rackspace, Salesforce. Se necesitan algunas configuraciones extra en Azure para obtener un Client Id.
cloudlist
Cloudlist es una herramienta multi-cloud para obtener Assets (Hostnames, IP Addresses) de Cloud Providers.
{{#tabs }} {{#tab name="Cloudlist" }}
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" }}
## For GCP it requires service account JSON credentials
cloudlist -config </path/to/config>
{{#endtab }} {{#endtabs }}
cartography
Cartography es una herramienta de Python que consolida los activos de infraestructura y las relaciones entre ellos en una vista de grafo intuitiva impulsada por una base de datos Neo4j.
{{#tabs }} {{#tab name="Install" }}
# 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" }}
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
Starbase recopila activos y relaciones de servicios y sistemas, incluyendo infraestructura cloud, aplicaciones SaaS, controles de seguridad y más, en una vista de grafo intuitiva respaldada por la base de datos Neo4j.
{{#tabs }} {{#tab name="Install" }}
# 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" }}
## 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
Descubre los usuarios con más privilegios en el entorno AWS o Azure analizado, incluidos los AWS Shadow Admins. Usa powershell.
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
Una herramienta para encontrar la infraestructura, archivos y apps de una empresa (objetivo) en los principales proveedores cloud (Amazon, Google, Microsoft, DigitalOcean, Alibaba, Vultr, Linode).
CloudFox
- CloudFox es una herramienta para encontrar rutas de ataque explotables en infraestructura cloud (actualmente solo se soporta AWS y Azure, con GCP próximamente).
- Es una herramienta de enumeración destinada a complementar el pentesting manual.
- No crea ni modifica ningún dato dentro del entorno cloud.
Más listas de herramientas de seguridad cloud
GCP
{{#ref}} gcp-security/ {{#endref}}
Workspace
{{#ref}} workspace-security/ {{#endref}}
AWS
{{#ref}} aws-security/ {{#endref}}
Azure
{{#ref}} azure-security/ {{#endref}}
Funciones comunes de seguridad cloud
Confidential Computing
{{#ref}} confidential-computing/luks2-header-malleability-null-cipher-abuse.md {{#endref}}
Referencias
- The Global Namespace Risk: Universal Bucket Hijacking Technique for Cloud Data Exfiltration
- Cloud Logging routing and sinks
- Amazon S3 replication
- Azure Monitor diagnostic settings
{{#include ../banners/hacktricks-training.md}}