Implementing Cloud Vulnerability Posture Management
Overview
Cloud Security Posture Management (CSPM) continuously monitors cloud infrastructure for misconfigurations, compliance violations, and security risks. Unlike traditional vulnerability scanning, CSPM focuses on cloud-native risks: IAM over-permissions, exposed storage buckets, unencrypted data, missing network controls, and service misconfigurations. This skill covers multi-cloud CSPM using AWS Security Hub, Azure Defender for Cloud, and open-source tools like Prowler and ScoutSuite.
Prerequisites
AWS Security Hub
Enable Security Hub
# Enable AWS Security Hub with default standards
aws securityhub enable-security-hub \
--enable-default-standards \
--region us-east-1
# Enable specific standards
aws securityhub batch-enable-standards \
--standards-subscription-requests \
'{"StandardsArn":"arn:aws:securityhub:us-east-1::standards/aws-foundational-security-best-practices/v/1.0.0"}' \
'{"StandardsArn":"arn:aws:securityhub:us-east-1::standards/cis-aws-foundations-benchmark/v/1.4.0"}'
# Get findings summary
aws securityhub get-findings \
--filters '{"SeverityLabel":[{"Value":"CRITICAL","Comparison":"EQUALS"}],"RecordState":[{"Value":"ACTIVE","Comparison":"EQUALS"}]}' \
--max-items 10
Security Hub Standards
| Standard |
Description |
| AWS Foundational Security Best Practices |
AWS-recommended baseline controls |
| CIS AWS Foundations Benchmark 1.4 |
CIS hardening requirements |
| PCI DSS v3.2.1 |
Payment card industry controls |
| NIST SP 800-53 Rev 5 |
Federal security controls |
Azure Defender for Cloud
Enable Defender CSPM
# Enable Defender for Cloud free tier
az security pricing create \
--name CloudPosture \
--tier standard
# Check secure score
az security secure-score list \
--query "[].{Name:displayName,Score:current,Max:max}" \
--output table
# Get security recommendations
az security assessment list \
--query "[?status.code=='Unhealthy'].{Name:displayName,Severity:metadata.severity,Resource:resourceDetails.id}" \
--output table
# Get alerts
az security alert list \
--query "[?status=='Active'].{Name:alertDisplayName,Severity:severity,Time:timeGeneratedUtc}" \
--output table
Open-Source: Prowler
Installation and Execution
# Install Prowler
pip install prowler
# Run full AWS scan
prowler aws --output-formats json-ocsf,csv,html
# Run specific checks
prowler aws --checks s3_bucket_public_access iam_root_mfa_enabled ec2_sg_open_to_internet
# Run against specific AWS profile and region
prowler aws --profile production --region us-east-1 --output-formats json-ocsf
# Run CIS Benchmark compliance check
prowler aws --compliance cis_1.5_aws
# Run PCI DSS compliance
prowler aws --compliance pci_3.2.1_aws
# Scan Azure environment
prowler azure --subscription-ids "sub-id-here"
# Scan GCP environment
prowler gcp --project-ids "project-id-here"
Prowler Check Categories
| Category |
Examples |
| IAM |
Root MFA, password policy, access key rotation |
| S3 |
Public access, encryption, versioning |
| EC2 |
Security groups, EBS encryption, metadata service |
| RDS |
Public access, encryption, backup retention |
| CloudTrail |
Enabled, encrypted, log validation |
| VPC |
Flow logs, default SG restrictions |
| Lambda |
Public access, runtime versions |
| EKS |
Public endpoint, secrets encryption |
Open-Source: ScoutSuite
# Install ScoutSuite
pip install scoutsuite
# Run AWS assessment
scout aws --profile production
# Run Azure assessment
scout azure --cli
# Run GCP assessment
scout gcp --project-id my-project
# Results available as interactive HTML report
# Open scout-report/report.html in browser
Multi-Cloud Aggregation
import json
import subprocess
from datetime import datetime, timezone
def run_prowler_scan(provider, output_dir, compliance=None):
"""Run Prowler scan for a cloud provider."""
cmd = ["prowler", provider, "--output-formats", "json-ocsf",
"--output-directory", output_dir]
if compliance:
cmd.extend(["--compliance", compliance])
result = subprocess.run(cmd, capture_output=True, text=True, timeout=3600)
return result.returncode == 0
def aggregate_findings(prowler_dirs):
"""Aggregate findings from multiple Prowler scans."""
all_findings = []
for scan_dir in prowler_dirs:
json_files = list(Path(scan_dir).glob("*.json"))
for jf in json_files:
with open(jf, "r") as f:
for line in f:
try:
finding = json.loads(line.strip())
all_findings.append(finding)
except json.JSONDecodeError:
continue
# Sort by severity
severity_order = {"critical": 0, "high": 1, "medium": 2, "low": 3, "informational": 4}
all_findings.sort(key=lambda f: severity_order.get(
f.get("severity", "informational").lower(), 5
))
return all_findings
def generate_posture_report(findings, output_path):
"""Generate cloud security posture report."""
report = {
"generated_at": datetime.now(timezone.utc).isoformat(),
"total_findings": len(findings),
"by_severity": {},
"by_provider": {},
"by_service": {},
}
for f in findings:
sev = f.get("severity", "unknown")
provider = f.get("cloud_provider", "unknown")
service = f.get("service_name", "unknown")
report["by_severity"][sev] = report["by_severity"].get(sev, 0) + 1
report["by_provider"][provider] = report["by_provider"].get(provider, 0) + 1
report["by_service"][service] = report["by_service"].get(service, 0) + 1
with open(output_path, "w") as f:
json.dump(report, f, indent=2)
return report
References
1---2name: implementing-cloud-vulnerability-posture-management3description: Implement Cloud Security Posture Management using AWS Security Hub, Azure Defender for Cloud, and open-source tools like Prowler and ScoutSuite for multi-cloud vulnerability detection.4domain: cybersecurity5subdomain: vulnerability-management6tags: [cspm, cloud-security, aws-security-hub, azure-defender, prowler, scoutsuite, misconfiguration, cnapp]7version: "1.0"8author: mahipal9license: Apache-2.010---1112# Implementing Cloud Vulnerability Posture Management1314## Overview1516Cloud Security Posture Management (CSPM) continuously monitors cloud infrastructure for misconfigurations, compliance violations, and security risks. Unlike traditional vulnerability scanning, CSPM focuses on cloud-native risks: IAM over-permissions, exposed storage buckets, unencrypted data, missing network controls, and service misconfigurations. This skill covers multi-cloud CSPM using AWS Security Hub, Azure Defender for Cloud, and open-source tools like Prowler and ScoutSuite.1718## Prerequisites1920- AWS CLI configured with SecurityAudit IAM policy21- Azure CLI with Security Reader role22- Python 3.9+ with `boto3`, `azure-identity`, `azure-mgmt-security`23- Prowler (https://github.com/prowler-cloud/prowler)24- ScoutSuite (https://github.com/nccgroup/ScoutSuite)2526## AWS Security Hub2728### Enable Security Hub29```bash30# Enable AWS Security Hub with default standards31aws securityhub enable-security-hub \32 --enable-default-standards \33 --region us-east-13435# Enable specific standards36aws securityhub batch-enable-standards \37 --standards-subscription-requests \38 '{"StandardsArn":"arn:aws:securityhub:us-east-1::standards/aws-foundational-security-best-practices/v/1.0.0"}' \39 '{"StandardsArn":"arn:aws:securityhub:us-east-1::standards/cis-aws-foundations-benchmark/v/1.4.0"}'4041# Get findings summary42aws securityhub get-findings \43 --filters '{"SeverityLabel":[{"Value":"CRITICAL","Comparison":"EQUALS"}],"RecordState":[{"Value":"ACTIVE","Comparison":"EQUALS"}]}' \44 --max-items 1045```4647### Security Hub Standards48| Standard | Description |49|----------|------------|50| AWS Foundational Security Best Practices | AWS-recommended baseline controls |51| CIS AWS Foundations Benchmark 1.4 | CIS hardening requirements |52| PCI DSS v3.2.1 | Payment card industry controls |53| NIST SP 800-53 Rev 5 | Federal security controls |5455## Azure Defender for Cloud5657### Enable Defender CSPM58```bash59# Enable Defender for Cloud free tier60az security pricing create \61 --name CloudPosture \62 --tier standard6364# Check secure score65az security secure-score list \66 --query "[].{Name:displayName,Score:current,Max:max}" \67 --output table6869# Get security recommendations70az security assessment list \71 --query "[?status.code=='Unhealthy'].{Name:displayName,Severity:metadata.severity,Resource:resourceDetails.id}" \72 --output table7374# Get alerts75az security alert list \76 --query "[?status=='Active'].{Name:alertDisplayName,Severity:severity,Time:timeGeneratedUtc}" \77 --output table78```7980## Open-Source: Prowler8182### Installation and Execution83```bash84# Install Prowler85pip install prowler8687# Run full AWS scan88prowler aws --output-formats json-ocsf,csv,html8990# Run specific checks91prowler aws --checks s3_bucket_public_access iam_root_mfa_enabled ec2_sg_open_to_internet9293# Run against specific AWS profile and region94prowler aws --profile production --region us-east-1 --output-formats json-ocsf9596# Run CIS Benchmark compliance check97prowler aws --compliance cis_1.5_aws9899# Run PCI DSS compliance100prowler aws --compliance pci_3.2.1_aws101102# Scan Azure environment103prowler azure --subscription-ids "sub-id-here"104105# Scan GCP environment106prowler gcp --project-ids "project-id-here"107```108109### Prowler Check Categories110| Category | Examples |111|----------|---------|112| IAM | Root MFA, password policy, access key rotation |113| S3 | Public access, encryption, versioning |114| EC2 | Security groups, EBS encryption, metadata service |115| RDS | Public access, encryption, backup retention |116| CloudTrail | Enabled, encrypted, log validation |117| VPC | Flow logs, default SG restrictions |118| Lambda | Public access, runtime versions |119| EKS | Public endpoint, secrets encryption |120121## Open-Source: ScoutSuite122123```bash124# Install ScoutSuite125pip install scoutsuite126127# Run AWS assessment128scout aws --profile production129130# Run Azure assessment131scout azure --cli132133# Run GCP assessment134scout gcp --project-id my-project135136# Results available as interactive HTML report137# Open scout-report/report.html in browser138```139140## Multi-Cloud Aggregation141142```python143import json144import subprocess145from datetime import datetime, timezone146147def run_prowler_scan(provider, output_dir, compliance=None):148 """Run Prowler scan for a cloud provider."""149 cmd = ["prowler", provider, "--output-formats", "json-ocsf",150 "--output-directory", output_dir]151 if compliance:152 cmd.extend(["--compliance", compliance])153 result = subprocess.run(cmd, capture_output=True, text=True, timeout=3600)154 return result.returncode == 0155156def aggregate_findings(prowler_dirs):157 """Aggregate findings from multiple Prowler scans."""158 all_findings = []159 for scan_dir in prowler_dirs:160 json_files = list(Path(scan_dir).glob("*.json"))161 for jf in json_files:162 with open(jf, "r") as f:163 for line in f:164 try:165 finding = json.loads(line.strip())166 all_findings.append(finding)167 except json.JSONDecodeError:168 continue169 # Sort by severity170 severity_order = {"critical": 0, "high": 1, "medium": 2, "low": 3, "informational": 4}171 all_findings.sort(key=lambda f: severity_order.get(172 f.get("severity", "informational").lower(), 5173 ))174 return all_findings175176def generate_posture_report(findings, output_path):177 """Generate cloud security posture report."""178 report = {179 "generated_at": datetime.now(timezone.utc).isoformat(),180 "total_findings": len(findings),181 "by_severity": {},182 "by_provider": {},183 "by_service": {},184 }185 for f in findings:186 sev = f.get("severity", "unknown")187 provider = f.get("cloud_provider", "unknown")188 service = f.get("service_name", "unknown")189 report["by_severity"][sev] = report["by_severity"].get(sev, 0) + 1190 report["by_provider"][provider] = report["by_provider"].get(provider, 0) + 1191 report["by_service"][service] = report["by_service"].get(service, 0) + 1192193 with open(output_path, "w") as f:194 json.dump(report, f, indent=2)195 return report196```197198## References199200- [AWS Security Hub](https://aws.amazon.com/security-hub/)201- [Azure Defender for Cloud](https://learn.microsoft.com/en-us/azure/defender-for-cloud/)202- [Prowler](https://github.com/prowler-cloud/prowler)203- [ScoutSuite](https://github.com/nccgroup/ScoutSuite)204- [CIS Benchmarks](https://www.cisecurity.org/cis-benchmarks)