AWS
AWS Pentesting
Recon - AWS Eye
Found an account ID:
S3 Recon
s3enum
lazys3
BucketLoot
Bucket inspector that can help users extract assets, flag secret exposures and even search for custom keywords as well as Regular Expressions from publicly-exposed storage buckets by scanning files that store data in plain-text.
Bruteforce S3 buckets
regions.txt
AWSBucketDump
CloudShovel
Enumeration without authentication
Route 53 Misconfiguration
S3 Enumeration Basics
Check website source code - search for s3 url
By default, the AWS CLI includes prefix= (an empty prefix) and delimiter=/ in requests
Check for https://target.com.s3.amazonaws.com/?prefix=&delimiter=/
List bucket content - Anon

If you found an URL like http://target.s3.eu-west-2.amazonaws.com remove the s3.region.amazonaws.com part
By default AWS cli tool interacts with s3.amazonaws.com . If you have another domain hosting
it, you can use --endpoint-url option to point the tool to another domain.

List buckets - with profile

Download one file
Download all files
download all of the bucket’s contents:
List the bucket ACL
List & get objects


Bucket policy
Bucket Policies are attached directly to the bucket and define what actions are allowed or denied by which principal.
More readable
Enumerate Lambda
One misconfiguration organizations often make with Lambda is including sensitive information in the environmental variables of the function

Execute a lmabda function

EC2 acting as a reverse-proxy
SSRF / RCE
Enumerating EC2s
Snapshots ?
Exploit snapshot
Snapshot found
Launch a ec2 instance (create ssh key pair)
Attach the snapshot created to the ec2 instance

Connect to the instance and mount the snapshot

SecretsManager
Get secret
DynamoDB
List tables

View Content

Amazon RDS - Relational Database Service
Amazon RDS supports several database instances including:
Amazon Aurora (port 3306)
PostgreSQL (5432)
MySQL (port 3306)
MariaDB (port 3306)
Oracle Database (port 1521)
SQL Server (port 1433)
Bruteforce attack:
MySQL (3306)The tmpdir variable provides further confirmation that this is an AWS RDS instance

AWS CLI

Keep track of profiles
Configure a named profile
Or
Or
Information about configured identity
Stored Credentials
Windows

Linux


Enumeration - Users
List the IAM groups that the specified IAM user belongs to :
List all manages policies that are attached to the specified IAM user :
Lists the names of the inline policies embedded in the specified IAM user :
Get policy
Enumeration - Groups
IAM Groups
All users in a group
All managed policies that are attached to the specified IAM Group
Names of the inline policies embedded in the specified IAM Group
Enumeration - Roles
List of IAM Roles
All managed policies that are attached to the specified IAM role
Names of the inline policies embedded in the specified IAM role
Enumeration - Policies
List of all iam policies
Information about the specified managed policy
Information about the versions of the specified manages policy
Information about the specified version of the specified managed policy
One of the permissions is iam:CreatePolicyVersion ? Use this to create a new version of the attached policy with privileged access
Specified inline policy document that is embedded on the specified IAM user / group / role
Enumeration - Cloud Services (EC2, S3 etc.) in an Organization AWS Account

This might not return any results if you aren't in the same region. -> Run pacu ec2__enum module
Enumeration - Get Bucket Policy
DynamoDB
CodeCommit
SSRF
SSRF / RCEEC2 - Get Password
Spray AWS Console IAM Logins
To get the ACCOUNTID , run aws sts get-caller-identity with a known account

Pacu
Setting the initial user access key

Permission of current logged-in user
Bruteforce IAM permissions
Enumerate ec2 instance and get the public ip addresses


Enumerate privilege escalation permission and exploit it

Subdomain Takeover
AWS Elastic Beanstalk
DNS (53)Privilege escalation opportunities in IAM configurations
IAM Privilege escalation
List inline policies, attached policies and group policies
IAM Enumeration Tools
PMapper
CloudPEASS

IAMActionHunter
IAMFinder
EnumerateIAM
aws_iam_enum

aws_escalate.py
Multiple privesc vectors
Multiple privesc vectors in a single policy
lambda:UpdateFunctionConfiguration
iam:PassRole + ec2:RunInstances: Creating an EC2 instance with an existing instance profile
iam:CreateAccessKey: Creating a new user access key
iam:CreateLoginProfile: Creating a new login profile
iam:UpdateLoginProfile: Updating an existing login profile
iam:AttachUserPolicy: Attaching a policy to a user
iam:AttachGroupPolicy: Attaching a policy to a group
iam:AttachRolePolicy: Attaching a policy to a role
iam:PutUserPolicy: Creating/updating an inline policy for a user
iam:PutGroupPolicy: Creating/updating an inline policy for a group
iam:PutRolePolicy: Creating/updating an inline policy for a role
iam:AddUserToGroup: Adding a user to a group
iam:PassRole + lambda:CreateFunction + lambda:InvokeFunction: Passing a role to a new Lambda function, then invoking it
iam:PassRole + lambda:CreateFunction + lambda:AddPermission
iam:UpdateAssumeRolePolicy + sts:AssumeRole: Updating the AssumeRolePolicyDocument of a role
lambda:UpdateFunctionCode: Updating the code of an existing Lambda function
iam:CreateAccessKey
An attacker with the iam:CreateAccessKey permission on other users can create an access key ID and secret access key belonging to another user in the AWS environment


iam:CreateLoginProfile
An attacker with the iam:CreateLoginProfile permission on other users can create a password to use to login to the AWS console on any user that does not already have a login profile setup.


arn:aws:iam::[Account_ID]:user/[Username]
You can now login as the victim into the AWS console
iam:UpdateLoginProfile
You can now login as the victim into the AWS console - See iam:CreateAccessKey
iam:CreatePolicyVersion
Create a new version of an IAM policy that they have access to.
administrator/policy.json
iam:SetDefaultPolicyVersion
Where “v2” is the policy version with the most privileges available.
Example: CloudGOAT - iam_privesc_by_rollback




With Pacu:


iam:AddUserToGroup
iam:AttachUserPolicy
If attaching AdministratorAccess fails, try to attach another dangerous permission such as SecretsManagerReadWrite
iam:AttachGroupPolicy
Also try with AdministratorAccess - See iam:AttachUserPolicy
iam:PutUserPolicy
Create a policy document policy.json
Check if the policy is in place:
iam:PutGroupPolicy
Create policy.json
Upload the policy to your group
iam:AttachRolePolicy
Find a role you can assume: "Action": "sts:AssumeRole"
Attach Role Policy
iam:PutRolePolicy
Find a role you can assume - See iam:AttachRolePolicy
Create policy.json
Put the role
sts:AssumeRole
List of IAM roles
Retrieve trust relationship between role and user
List managed policies attached to the specified role
Retrieve information about the specified version of the managed policy
Assume role - retrieve temporary security credentials of assumed role
Use the credentials
lambda:UpdateFunctionConfiguration
Allow to attach a layer to a function
iam:PassRole + lambda:CreateFunction + lambda:InvokeFunction
IAM Security Assessment
Metadata
Unauthorized Access to Metadata and User Data
AWS Enumerator
S3 Misconfiguration - Permissions
S3Scanner
Checkov
Nuclei Templates
AWS Extender - Burp Extension
List Permissions

Read Permissions
Download Permissions
Write Permissions

Upload a shell
Read Permissions on ACL
Write Permissions on ACL
S3 Versioning
List object versions.
S3 - Shadow Resources
Security Groups - Segmentation
AWS Attack Path Management Tool
Persistence - IAM Role Anywhere
An attacker with sufficient permissions could exploit IAM Roles Anywhere to gain persistent access to an AWS account
VPC - Virtual Private Cloud
Enumeration
Describe aboute VPCs
Describe about subnets
Describe about route table
Describe about Network ACL (NACL)
Lateral Movement / Pivoting
Describes all VPC Peering Connections
Describe about Subnet of the specified VPC :
Describe about Route Table of the specified Subnet
Describe about Network ACL of the specified VPC
Describe about EC2 Instances In the specified VPC
Describe about EC2 Instances In the specified Subnet
EC2 - Elastic Compute Cloud
Enumeration
Describes the information about all instances
Describes the information about specified instance
Describes the information about UserData Attribute of the specified Instance
Describes the infroamtion about IAM instance profile associations
Exploitation
SSRF/RCE
SSRF / RCEAWS Metadata
IMDV1
IMDV2
AWS Userdata
IMDV1
IMDV2
EC2StepShell
Persistence
Generate SSH key pair
On EC2 instance, add private key to user ssh directory
Access EC2 using ssh backdoor key
Privilege Escalation
Lambda Function
Enumeration
List of all lambda functions
Retrieve the information about the specified lambda function
Retrieve the policy information about the specified lambda function
Retrieve the event source mapping information about the specified lambda function
List of all the layers (dependencies) in aws account
Retrieve the full information about the specified layer name
List of all the REST APIs
Get the information about specified API
List information about a collection of resources
Get information about the specified resource
Get the method information for the specified resource
List of all stages for a REST API
Get the information about specified API's stage
Get the information about a specified API key
Credential Access
RCE
Lambda function vulnerable to command injection
Command InjectionSSRF
Using CLI
Environment variable:
Persistence
PrivEsc
iam:PassRole + lambda:CreateFunction + lambda:InvokeFunction
Containers
3 categories:
Registry: store and manage container images: ECR (Elastic Container Registry)
Orchestration: when and where containers run: ECS (Elastic Container Service) and EKS (Elastic Kubernetes Service)
Compute: run containers: Fargate (servless compute engine) and EC2
Enumeration
ECR
Repositories in the container registry
Information about the repo policy
List all images in the specified repository
Information about a container image
ECS
List all ECS clusters
Information about specified cluster
List all services in the specified cluster
Information about a specified service
List all tasks in the specified cluster
List all containers in the specified cluster
EKS
List all EKS clusters
Information about a specified cluster
List of all node groups in a specified cluster
Information about a specified node group in a cluster
List of all fargate in a specified cluster
Information about a specific fargate profile in a cluster
Initial Access
RCE - Command injection
List of all secret in EKS vulnerable container
Get the secret information from running EKS vulnerable container
Persistence
Authenticate docker daemon to ECR
Build backdoored docker image
Tag the docker image
Push the docker image to AWS Container Registry
S3 - Simple Storage Service
Enumeration
List of all the bucket in the AWS account
Information about specified bucket ACLs
Information about specified bucket policy
Retrieve eh Public Access Block configuration for an Amazon S3 bucket
List of all the objects in specified bucket
ACLs information about the specified object
RDS - Relational Database Service
Enumeration
Information about the clusters in RDS
Information about the database instances in RDS
Information about the subnet group in RDS
Information about the database security groups in RDS
Information about the database proxies in RDS
Data Exfiltration
Password Based
MySQL (3306)IAM Based Authentication (token)
Get the database instance connection temporary token from the RDS endpoint
Connect to mysql using temporary token
Snapshots
Public snapshots from single RDS database instances that belong to AWS account ID
Public snapshots from RDS database cluster instances
The snapshot can be restored. From the Actions menuin GUI, select Restore snapshot
EBS - Elastic Block Store
A block storage system used to store persistent data. used for EC2 instances.
Enumeration
Information about EBS volumes
All available EBS snapshots

Create volume permissions

The value of Group is set to all. This reveals that it is a publicly accessible snapshot and any AWS user will be able to create a volume from this public snapshot into their AWS Account.
Enumerate public snapshots

Data Exfiltation
Create a snapshot of the specified volume
Describe all the available EBS snapshots
Create a volume from snapshots
Describe ec2 instances
Attach specified volume to the ec2-instance
Mount volume on EC2 file system
See Exploit snapshot
Secret Manager
Enumeration
List all secrets that are stored by Secrets Manager
Describe about a specified secret
Resource-based policy attached to the specified secret
Key Management Server, KMS
All keys available in KMS
Describe about a specified key
List of policies attached to specified key
Information about a policy
Credential access
Secret Manager
KMS
Decrypt the encrypted secret by KMS key
Cloudtrail
Read access aver Cloudtrail logs
Interesting Book
Interesting BooksAdvanced Penetration Testing: Hacking AWS 2 This book delves deeper into analyzing the security of various AWS services and shows techniques and tactics used by an attacker to breach an AWS environment
Hands-On AWS Penetration Testing with Kali Linux Set up a virtual lab and pentest major AWS services, including EC2, S3, Lambda, and Cloud
Resources
Last updated
