Files
hacktricks-cloud/src/pentesting-cloud/pentesting-cloud-methodology.md

423 lines
15 KiB
Markdown

# Pentesting Cloud Metodologija
{{#include ../banners/hacktricks-training.md}}
<figure><img src="../images/CLOUD-logo-letters.svg" alt=""><figcaption></figcaption></figure>
## Osnovna metodologija
Svaki cloud ima svoje osobenosti, ali generalno postoji nekoliko **zajedničkih stvari koje pentester treba da proveri** kada testira cloud okruženje:
- **Benchmark provere**
- Ovo će vam pomoći da **razumete veličinu** okruženja i **korišćene servise**
- Takođe će vam omogućiti da pronađete neke **brze greške u konfiguraciji** pošto većinu ovih testova možete izvršiti pomoću **automatizovanih alata**
- **Enumeracija servisa**
- Verovatno nećete naći mnogo više grešaka u konfiguraciji ovde ako ste pravilno izvršili benchmark testove, ali možete naći neke koje se nisu tražile u benchmark testu.
- Ovo će vam omogućiti da znate **šta se tačno koristi** u cloud okruženju
- Ovo će mnogo pomoći u narednim koracima
- **Provera izloženih resursa**
- Ovo može biti urađeno tokom prethodnog dela, potrebno je da **otkrijete sve što je potencijalno izloženo** Internetu na neki način i kako se može pristupiti.
- Ovde mislim na **ručno izloženu infrastrukturu** kao što su instance sa web stranicama ili drugim izloženim portovima, i takođe na druge **cloud managed services koje se mogu konfigurisati** da budu izložene (kao što su DBs ili buckets)
- Zatim treba da proverite **da li taj resurs može biti izložen ili ne** (poverljive informacije? ranjivosti? greške u konfiguraciji izloženog servisa?)
- **Provera dozvola**
- Ovde treba da **utvrdite sve dozvole svake uloge/korisnika** u cloud-u i kako se koriste
- Previše **visoko privilegovanih** (kontrolišu sve) naloga? Generisani ključevi se ne koriste?... Većina ovih provera bi već trebalo da je urađena u benchmark testovima
- Ako klijent koristi OpenID, SAML ili neku drugu **federation**, možda ćete morati da od njih zatražite dodatne **informacije** o **kako se svaka uloga dodeljuje** (nije isto da je admin uloga dodeljena jednom korisniku ili 100)
- Nije dovoljno da se utvrdi koji korisnici imaju **admin** dozvole "*:*". Postoji mnogo **ostalih dozvola** koje, u zavisnosti od korišćenih servisa, mogu biti veoma **osetljive**.
- Štaviše, postoje **potencijalni privesc** načini koji se mogu ispratiti zloupotrebom dozvola. Sve ovo treba uzeti u obzir i prijaviti **što više privesc puteva koliko je moguće**.
- **Provera integracija**
- Veoma je verovatno da su **integracije sa drugim cloud-ovima ili SaaS** korišćene unutar cloud okruženja.
- Za **integracije cloud-a koje auditirate** sa drugim platformama treba da obavestite **ko ima pristup da (zloupotrebi) tu integraciju** i treba da pitate **koliko je osetljiva** akcija koja se izvršava.\
Na primer, ko može da upisuje u AWS bucket iz kojeg GCP dobija podatke (pitajte koliko je osetljiva ta radnja u GCP prilikom obrade tih podataka).
- Za **integracije unutar cloud-a koji auditirate** iz eksternih platform, treba da pitate **ko ima eksterni pristup da (zloupotrebi) tu integraciju** i proverite kako se ti podaci koriste.\
Na primer, ako servis koristi Docker image hostovan u GCR, treba da pitate ko ima pristup da modifikuje taj image i koje osetljive informacije i pristupe će taj image dobiti kada se izvrši unutar AWS cloud-a.
## Multi-Cloud alati
Postoji nekoliko alata koji se mogu koristiti za testiranje različitih cloud okruženja. Koraci instalacije i linkovi biće navedeni u ovom delu.
### [PurplePanda](https://github.com/carlospolop/purplepanda)
Alat za **identifikovanje loših konfiguracija i privesc path u cloud-ovima i između cloud-ova/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)
Podržava **AWS, GCP & Azure**. Pogledajte kako konfigurisati svakog provajdera na [https://docs.prowler.cloud/en/latest/#aws](https://docs.prowler.cloud/en/latest/#aws)
```bash
# 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](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 </abs/path/to/config.js>
```
{{#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" }}
Preuzmite i instalirajte Steampipe ([https://steampipe.io/downloads](https://steampipe.io/downloads)). Ili koristite 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
```
<details>
<summary>Proverite sve projekte</summary>
Da biste proverili sve projekte, potrebno je da generišete fajl `gcp.spc` koji navodi sve projekte koje treba testirati. Možete jednostavno slediti uputstva iz sledećeg skripta
```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"
```
</details>
Za proveru **ostalih GCP uvida** (korisno za nabrajanje servisa) koristite: [https://github.com/turbot/steampipe-mod-gcp-insights](https://github.com/turbot/steampipe-mod-gcp-insights)
Za pregled Terraform GCP koda: [https://github.com/turbot/steampipe-mod-terraform-gcp-compliance](https://github.com/turbot/steampipe-mod-terraform-gcp-compliance)
Više GCP plugina za Steampipe: [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
```
Za proveru Terraform AWS koda: [https://github.com/turbot/steampipe-mod-terraform-aws-compliance](https://github.com/turbot/steampipe-mod-terraform-aws-compliance)
Više AWS pluginova za Steampipe: [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.\
Zahteva python2.7 i izgleda neodržavano.
### Nessus
Nessus ima _**Audit Cloud Infrastructure**_ skeniranje koje podržava: AWS, Azure, Office 365, Rackspace, Salesforce. Potrebne su neke dodatne konfiguracije u **Azure** kako bi se dobio **Client Id**.
### [**cloudlist**](https://github.com/projectdiscovery/cloudlist)
Cloudlist je **multi-cloud tool for getting Assets** (Hostnames, IP Addresses) from Cloud Providers.
{{#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 </path/to/config>
```
{{#endtab }}
{{#endtabs }}
### [**cartography**](https://github.com/lyft/cartography)
Cartography je Python alat koji objedinuje infrastrukturne resurse i veze između njih u intuitivnom grafičkom prikazu zasnovanom na Neo4j bazi podataka.
{{#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 prikuplja resurse i odnose iz servisa i sistema, uključujući cloud infrastrukturu, SaaS aplikacije, sigurnosne kontrole i još mnogo toga, u intuitivan grafički prikaz koji koristi Neo4j bazu podataka.
{{#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)
Otkriva najprivilegovanije korisnike u skeniranom AWS ili Azure okruženju, uključujući AWS Shadow Admins. Koristi 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)
Alat za pronalaženje infrastrukture kompanije (cilja), fajlova i aplikacija na vodećim cloud provajderima (Amazon, Google, Microsoft, DigitalOcean, Alibaba, Vultr, Linode).
### [CloudFox](https://github.com/BishopFox/cloudfox)
- CloudFox je alat za pronalaženje iskoristivih puteva napada u cloud infrastrukturi (trenutno podržani samo AWS & Azure, a GCP dolazi uskoro).
- To je alat za enumeraciju koji je namenjen da dopuni manualni pentesting.
- Ne kreira niti menja bilo koje podatke unutar cloud okruženja.
### Više spiskova alata za cloud sigurnost
- [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) kreira „attack graph“ resursa u Azure pretplati. Omogućava red teams i pentesters da vizualizuju površinu napada i mogućnosti pivotovanja unutar tenant-a, i ubrzava vaše odbrambene timove da se brzo orijentišu i daju prioritet radu na odgovoru na incidente.
### Office365
Potrebno je imati **Global Admin** ili bar **Global Admin Reader** (ali imajte na umu da je Global Admin Reader pomalo ograničen). Međutim, ta ograničenja se pojavljuju u nekim PS modulima i mogu se zaobići pristupanjem funkcijama **preko web aplikacije**.
{{#include ../banners/hacktricks-training.md}}