AWS
Introduction
Nowadays, it is pretty common that applications are being executed inside cloud environments like Amazon Web Service (AWS). In this section, you will learn some techinques that will help you to enumerate your environment.
Profile Configuration
aws configure --profile $profile
aws configure set aws_session_token "" --profile $profileAssume Role
# Assume the role
aws sts assume-role \
--role-session-name "PostExploitSession" \
--profile $profile \
--role-arn "" > /tmp/post_creds.json
# Export to environment variables
## JQ
export AWS_ACCESS_KEY_ID=$(jq -r '.Credentials.AccessKeyId' /tmp/post_creds.json)
export AWS_SECRET_ACCESS_KEY=$(jq -r '.Credentials.SecretAccessKey' /tmp/post_creds.json)
export AWS_SESSION_TOKEN=$(jq -r '.Credentials.SessionToken' /tmp/post_creds.json)
## Python
export AWS_ACCESS_KEY_ID=$(python3 -c 'import json; print(json.load(open("/tmp/post_creds.json"))["AccessKeyId"])')
export AWS_SECRET_ACCESS_KEY=$(python3 -c 'import json; print(json.load(open("/tmp/post_creds.json"))["SecretAccessKey"])')
export AWS_SESSION_TOKEN=$(python3 -c 'import json; print(json.load(open("/tmp/post_creds.json"))["Token"])')
# Update the AWS CLI profile configuration
aws configure set aws_access_key_id "$AWS_ACCESS_KEY_ID" --profile $profile
aws configure set aws_secret_access_key "$AWS_SECRET_ACCESS_KEY" --profile $profile
aws configure set aws_session_token "$AWS_SESSION_TOKEN" --profile $profile
aws configure set region us-east-1 --profile $profile
aws configure set output json --profile $profile
Enumeration Commands
Caller identity
IAM
Policies
Roles
Secrets
KMS
S3
EC2
LightSail - Database
RDS
Lambda
EFS
DynamoDB
ECR
ECS
ElasticBeanStalk
Codebuild
SQS
SNS
Cognito
Schedulers
API Gateway
Step Functions
SSRF inside AWS
If you can perform an SSRF attack inside an AWS EC2 instance, container, lambda function or elastik server, you can retrieve its temporal credentials.
EC2 Creds - IMDSv1 || Elastic Beanstalk
EC2 Creds - IMDSv2
EC2 User-data
Lambda
Containers metadata
Tools
Pentesting/Red Teaming:
confused-binary/aws-enumerator: A Go-based tool designed for service enumeration and data dumping during black-box testing to speed up the review of compromised AWS accounts.
bf-aws-perms-simulate: A Python script that identifies an AWS user's permissions by performing batch simulations of API actions using the
SimulatePrincipalPolicymethod.aws-Perms2ManagedPolicies: A utility that compares a list of discovered permissions against existing AWS managed policies to identify which policies might be granting those permissions.
CloudPEASS: Part of the PEASS-ng suite, this tool is designed for automated cloud privilege escalation scanning across AWS, Azure, and GCP.
Pacu: Metasploit for AWS
Audit related
cloudfox: An offensive security tool for penetration testers to discover exploitable attack paths and gain situational awareness in unfamiliar cloud environments.
ScoutSuite: A multi-cloud security auditing tool that automates the collection of configuration data and generates an HTML report highlighting security risks.
tfstate2IAM: A Python tool that parses Terraform state files in S3 buckets to extract IAM entities (users, roles, policies), providing insight into permissions without requiring direct IAM read access.
Red Team Tips
Cloud Trail Bypasses
Discovering Canary Tokens
The best way to identify canary tokens without triggering an alerts is by adding that token to a profile and perform requests against a resource outside of the attacking organization. Example:
As a result, you can see that that user might be some canary token.
Last updated