Nsdd

A personal wiki, chronicling hacking, data, and AI learning.

Pentesting Cloud Methodology

2023-06-15


Support HackTricks and get benefits!

Basic Methodology

Each cloud has its own peculiarities but in general there are a few common things a pentester should check when testing a cloud environment:

Multi-Cloud tools

There are several tools that can be used to test different cloud environments. The installation steps and links are going to be indicated in this section.

PurplePanda

A tool to identify bad configurations and privesc path in clouds and across clouds/SaaS.

{% tabs %} {% tab title=“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 title=“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 %}

CloudSploit

AWS, Azure, Github, Google, Oracle, Alibaba

{% tabs %} {% tab title=“Install” %}

# Install
git clone https://github.com/aquasecurity/cloudsploit.git
cd cloudsploit
npm install
./index.js -h
## Docker instructions in github

{% endtab %}

{% tab title=“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 title=“Install” %}

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 title=“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 title=“Install” %} Download and install Steampipe (https://steampipe.io/downloads). Or use Brew:

brew tap turbot/tap
brew install steampipe

{% endtab %}

{% tab title=“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
Check all Projects

In order to check all the projects you need to generate the gcp.spc file indicating all the projects to test. You can just follow the indications from the following 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"

To check other GCP insights (useful for enumerating services) use: https://github.com/turbot/steampipe-mod-gcp-insights

To check Terraform GCP code: https://github.com/turbot/steampipe-mod-terraform-gcp-compliance

More GCP plugins of Steampipe: https://github.com/turbot?q=gcp {% endtab %}

{% tab title=“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 %}

Nessus

Nessus has an Audit Cloud Infrastructure scan supporting: AWS, Azure, Office 365, Rackspace, Salesforce. Some extra configurations in Azure are needed to obtain a Client Id.

Cloud Brute

A tool to find a company (target) infrastructure, files, and apps on the top cloud providers (Amazon, Google, Microsoft, DigitalOcean, Alibaba, Vultr, Linode).

CloudFox

More lists of cloud security tools

Google

GCP

{% content-ref url=“gcp-security/” %} gcp-security {% endcontent-ref %}

Workspace

{% content-ref url=“workspace-security.md” %} workspace-security.md {% endcontent-ref %}

AWS

{% content-ref url=“aws-security/” %} aws-security {% endcontent-ref %}

Azure

Access the portal here: http://portal.azure.com/
To start the tests you should have access with a user with Reader permissions over the subscription and Global Reader role in AzureAD. If even in that case you are not able to access the content of the Storage accounts you can fix it with the role Storage Account Contributor.

It is recommended to install azure-cli in a linux and windows virtual machines (to be able to run powershell and python scripts): https://docs.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest
Then, run az login to login. Note the account information and token will be saved inside <HOME>/.azure (in both Windows and Linux).

Remember that if the Security Centre Standard Pricing Tier is being used and not the free tier, you can generate a CIS compliance scan report from the azure portal. Go to Policy & Compliance-> Regulatory Compliance (or try to access https://portal.azure.com/#blade/Microsoft_Azure_Security/SecurityMenuBlade/22).
__If the company is not paying for a Standard account you may need to review the CIS Microsoft Azure Foundations Benchmark by “hand” (you can get some help using the following tools). Download it from here.

Run scanners

Run the scanners to look for vulnerabilities and compare the security measures implemented with CIS.

pip install scout
scout azure --cli --report-dir <output_dir>

#Fix azureaudit.py before launching cs.py
#Adding "j_res = {}" on line 1074
python cs.py -env azure

#Azucar is an Azure security scanner for PowerShell (https://github.com/nccgroup/azucar)
#Run it from its folder
.\Azucar.ps1 -AuthMode Interactive -ForceAuth -ExportTo EXCEL

#Azure-CIS-Scanner,CIS scanner for Azure (https://github.com/kbroughton/azure_cis_scanner)
pip3 install azure-cis-scanner #Install
azscan #Run, login before with `az login`

Attack Graph

Stormspotter creates an “attack graph” of the resources in an Azure subscription. It enables red teams and pentesters to visualize the attack surface and pivot opportunities within a tenant, and supercharges your defenders to quickly orient and prioritize incident response work.

More checks

Office365

You need Global Admin or at least Global Admin Reader (but note that Global Admin Reader is a little bit limited). However, those limitations appear in some PS modules and can be bypassed accessing the features via the web application.

Other Cloud Pentesting Guides

Support HackTricks and get benefits!