What is cloud pentest
Pentesting services in cloud that target users. Good addition with web app pentest .
Why cloud pentest
Even if web app is secure, the cloud may be misconfigured which can lead to compromise
AWS overview
Leading cloud provider 31% share Has a lot of services
Common services
S3 EC2 RDS etc
Shared responsibility
Platform is responsible for security of the cloud. User is responsible for security in the cloud
Account ID
All resources are associated with the account ID Helps to corelate results
Root credential compromise - Critical Vulnerability
AWS regions
Regions can help us focus on enumeration
Lot of resources are exposable with Account ID you can find resources exposed
Demo 1 - Find Exposed services using AWS
seach for AMI → change option to public images and paste the account number or Owner = account number to list resources associated with the Account ID
AWS IAM
IAM Policies - says what is allowed and not allowed It allows and denies actions and access to resources
AWS does Deny by default
IAM Access key ID can be used to find target account ID even if key is revoked or no access is to secret key
Most compromise is due to credential leaks
Github gitlab s3 buckets js files apks container registeries (very lucrative to find keys) - dockerhub, public ecr ,quay.io
How to validate leaked creds
Password spraying
Finds permisiions of leaked creds
enumerate-iam - very noisy for red team
Demo 2
**
Permissions of leaked credentials - find the following:
-
Account ID the user belongs to
-
Name of the user
-
Permissions of the user
**
1
2
3
IAM Roles
i am roles are temproary creds trust relationship
if you have
iam:PassRole On *
then you can run resources using admin access get priv esc
https://rhinosecuritylabs.com/aws/aws-privilege-escalation-methods-mitigation/
Pro tip: Find roles that are most permissive and see which users can reach it
To lookup - PassRole IAM Roles
Amazon s3
Buckets Unique name globally Region specific Used for - user uploads, static content, serve website, logs etc
bucket url has pattern
s3 bucket should have same name as the dns record
Public s3 can be used to find which region is the target using
Greyhat warfare OSINT Public buckets IaC in public repora Google Dorks Presigned URL - with AKIA (s3 buckets)
Coomon issues Public list Public read Public write
Demo 3
Detecting account id from public bucket
https://tracebit.com/blog/2024/02/finding-aws-account-id-of-any-s3-bucket/
Bucketloot - get sensitive data
EC2
Virtual machines Must be within a VPC Allows SSH and RDP for windows Every VM should have 1 private IP
EC2 - AMI (for operating sys), Elastic Block Storage (Persistant storage), Security groups(Like firewall), EC2 Key Pairs, User Data scripts(initialing scripts)
Given an IP we can get if it is aws ip-ranges.amazonaws.com/ip-ranges.json
IMDS
temp creds from IMDS is as dangerous as IAM roles associated with EC2
Demo 4 - Exploring IMDS v1
Demo 5 - Exploring IMDS v2
Demo 6 - Exposed AMIs
EBS
Storage has snapshots can be found using account id has a lot juicy data like source code, sensitive info
not encrypted - we can use it mostly
Exploring metadata endpoint in ECS
ECS, Fargate
ECR
Compromising container image == compromising the cluster
Public ECR Registries - https://gallery.ecr.aws
AWS Inspector doesn’t scan for secrets and sensitive data inside containers
AWS Lambda
Max lifetime is 15 mins
lambda will be kept alive for 15 mins after first call and kills other calls no metadata endpoint read only file system /tmp is writable
lambda exposed via api gateway - cannot be 100% sure lambda exposed via lambda url - sure!
lambda has a 1000 concurrent executions - by new accounts only has 10 lambda - no protection against dos. requests can get throttled
temp creds are always avaialble in env varriables during execution phase no metadata endpoint
Offensive cloud security
Recon
- Account Id and regiom
- Subdomains and domains
Initial Access
- Public resources
- Leaked creds and secrets
- server side vulnerabilities
Priv esc and lateral movement
- Private resources in VPC
- Priv esc techniques (metadata, secrets,linux priv esc, etc)
Data Exfiltration
- Data from private repos
What to do
Try to read secrets
- secrets manager
- ssm param store
Scan internal VPCs
Get admin account If compromised non prod? try for prod access
Tools
Scoutsuite by ncc group - pentesters’ friend prowler - more defensive friendly pacu - aws expoitation framework - like metasploit for aws
Mitre attack cloud matrix - going deep
setup vulnerablre machines and hack
terraform
ctf
create a volume from snapshot, find using acc id then mount and find flag
https://medium.com/@mudasirhaji/step-by-step-process-of-how-to-add-and-mount-ebs-volume-on-ubuntu-ec2-linux-instance-a4be8870a4dd https://docs.aws.amazon.com/ebs/latest/userguide/ebs-using-volumes.html
Find associated AMI using account id discovered in the previous challenge
Spin the instance with the AMI as base
try browsing browser
try ssrf in this endpoint
user-data endpoint has file which contains flag
Should probably query something using ssm - https://docs.aws.amazon.com/cli/latest/reference/ssm/
Something like
with decryption gives flag