This guide provides a structured approach to performing hands-on labs focused on Amazon Web Services (AWS) S3 bucket security and Identity and Access Management (IAM) privilege escalation. These labs are designed for CEH v13 students to understand common cloud misconfigurations and attack vectors.
- All activities described herein must be performed EXCLUSIVELY on AWS accounts and resources for which you have explicit, written authorization to conduct security testing.
- Unauthorized scanning or testing of any AWS resources is illegal and unethical.
- It is strongly recommended to use a dedicated AWS Free Tier account or a sandboxed lab environment (like EC-Council iLabs, if applicable) specifically for these exercises to avoid impacting production systems and incurring unexpected costs.
- Always adhere to the AWS Acceptable Use Policy and Customer Agreement.
This lab focuses on identifying publicly accessible or misconfigured S3 buckets.
- An AWS account (for creating test buckets, if not using pre-configured labs).
- A Linux-based machine (e.g., Kali Linux) with internet access.
- AWS CLI installed and configured (optional, but useful for creating test scenarios).
- Python3 and pip installed.
- Git installed.
Lab 1.1: Enumerate S3 Buckets using lazys3
(Note: The original table mentioned lazys3. If you prefer a Python tool, we can adapt to S3Scanner for this part too, as lazys3 is Ruby. For consistency with S3Scanner in 1.2, let's assume a similar Python-based tool or focus on S3Scanner's enumeration capabilities if Lazys3 is harder for students to set up.) For this example, let's adjust and say we'll use a conceptual Python script or S3Scanner's broad enumeration techniques if `lazys3` setup is a hurdle. Since 1.2 *specifically* mentions S3Scanner, let's focus on tools readily available.
Alternative/Focus for 1.1 & 1.2: Using S3Scanner for Broad & Specific Enumeration
S3Scanner can be used for both broad searches and checking specific bucket names. We'll combine the spirit of these two sub-labs using S3Scanner.
- Install S3Scanner:
git clone https://github.com/sa7mon/S3Scanner.git cd S3Scanner sudo pip3 install -r requirements.txt - Create Target Buckets (If doing self-study setup):
In your AWS account, create a couple of S3 buckets for testing:
- One publicly readable: e.g.,
ceh13-lab-public-readable-[yourname](Set permissions to allow public list/read). - One private: e.g.,
ceh13-lab-private-[yourname](Default private permissions). - One with a common permutation: e.g.,
test-ceh13-lab-[yourname]
secret.txt) to the public bucket. - One publicly readable: e.g.,
- Enumerate Specific Buckets (Simulating knowledge of potential names):
python3 s3scanner.py ceh13-lab-public-readable-[yourname] python3 s3scanner.py ceh13-lab-private-[yourname] python3 s3scanner.py non-existent-bucket-[yourname]123Observe the output. It will tell you if the bucket exists and its access level (Public, AuthenticatedUsers, Private, NotFound).
- Enumerate a List of Potential Bucket Names:
Create a file named
buckets.txtwith potential bucket names, one per line (include the names of buckets you created, and some common variations or dictionary words if you want to simulate broader enumeration):Then run:ceh13-lab-public-readable-[yourname] prod-backups-ceh13 dev-assets-ceh13 test-ceh13-lab-[yourname]python3 s3scanner.py -f buckets.txt -o s3_scan_results.txt - Dump a Publicly Readable Bucket (Simulating Lazys3's goal of finding open buckets):
If S3Scanner identifies a bucket as "Public" and readable in step 3 or 4, you can try to dump its contents.
python3 s3scanner.py -d ceh13-lab-public-readable-[yourname]This will attempt to list and download all objects from the bucket if permissions allow.
- Confirm S3Scanner correctly identifies the existence and access levels of your test buckets.
- Verify that S3Scanner successfully lists and downloads files from your publicly readable bucket.
- Check the
s3_scan_results.txtfile for the output from the list scan.
This lab focuses on interacting with and exploiting misconfigured S3 bucket permissions, specifically open write permissions.
Lab 2.1: Exploit Open S3 Buckets using AWS CLI
- AWS CLI installed and configured (can be configured with dummy credentials for unauthenticated access, or with credentials for an account that has access to list/write to the target bucket if simulating authenticated exploitation).
For unauthenticated access, you can just run
aws configureand press Enter for keys and region, or use--no-sign-request. - An S3 bucket misconfigured to allow public write access (or authenticated write access for a specific user you control).
Self-Study Setup: Create a bucket
ceh13-lab-public-writable-[yourname]. In its permissions, under "Bucket policy", add a policy like this (USE WITH EXTREME CAUTION AND ONLY ON TEST BUCKETS YOU OWN - THIS MAKES IT WORLD-WRITABLE!):Replace{ "Version": "2012-10-17", "Statement": [ { "Sid": "AllowPublicWrite", "Effect": "Allow", "Principal": "*", "Action": [ "s3:PutObject", "s3:PutObjectAcl" ], "Resource": "arn:aws:s3:::ceh13-lab-public-writable-[yourname]/*" }, { "Sid": "AllowPublicListAndRead", "Effect": "Allow", "Principal": "*", "Action": [ "s3:GetObject", "s3:ListBucket" ], "Resource": [ "arn:aws:s3:::ceh13-lab-public-writable-[yourname]", "arn:aws:s3:::ceh13-lab-public-writable-[yourname]/*" ] } ] }ceh13-lab-public-writable-[yourname]with your actual bucket name. Remember to delete this policy or bucket after the lab.
- Create a test file to upload:
echo "This is a test file uploaded by a CEH student." > poc.txt - Attempt to list the contents of the target bucket (using
--no-sign-requestfor public buckets):aws s3 ls s3://ceh13-lab-public-writable-[yourname] --no-sign-requestIf this works, it confirms public listability.
- Attempt to upload your test file to the bucket:
aws s3 cp poc.txt s3://ceh13-lab-public-writable-[yourname]/poc.txt --no-sign-request - Verify the upload by listing the bucket contents again:
aws s3 ls s3://ceh13-lab-public-writable-[yourname]/ --no-sign-requestYou should see
poc.txtlisted. - Attempt to access the uploaded file via its public URL (if object ACLs also allow public read):
The URL format is
https://or.s3. .amazonaws.com/ https://s3.. Example:.amazonaws.com/ / https://ceh13-lab-public-writable-[yourname].s3.us-east-1.amazonaws.com/poc.txt. Open this in a browser. - (Optional) Defacement/Modification:
If the bucket hosts a static website, you could try replacing an existing file like
index.html(ONLY ON YOUR OWN TEST BUCKET!).echo "Bucket Defaced for CEH Lab!
" > new_index.html aws s3 cp new_index.html s3://ceh13-lab-public-writable-[yourname]/index.html --no-sign-request --acl public-readThe
--acl public-readis important if you want the new file to be publicly accessible via URL immediately. - Cleanup: Remove your test file.
aws s3 rm s3://ceh13-lab-public-writable-[yourname]/poc.txt --no-sign-request # If you uploaded index.html, remove or revert it.
- Successful upload of
poc.txtto the target bucket. - Ability to list
poc.txtin the bucket after upload. - (If applicable) Ability to access
poc.txtvia its public S3 URL. - (If defacement was attempted) Observation of the changed content on the target website/file.
This lab explores escalating privileges within AWS IAM by exploiting misconfigured user policies.
Lab 3.1: Escalate IAM User Privileges by Exploiting Misconfigured User Policy
- AWS CLI installed and configured with credentials for a low-privileged IAM user.
- An AWS environment where you can create and misconfigure IAM user policies.
- Understanding of AWS IAM policies, users, roles, and permissions.
LowPrivUser. Your goal is to analyze this user's permissions and identify any misconfigurations that would allow you to escalate privileges, ultimately aiming for administrative access or access to sensitive resources.
A common misconfiguration involves a user having permission to create new versions of existing policies (iam:CreatePolicyVersion) that are attached to higher-privileged users/roles, or permission to attach policies (iam:AttachUserPolicy, iam:AttachRolePolicy) to themselves or other entities.
- Create an IAM user named
VictimAdminUser. Attach the AWS managedAdministratorAccesspolicy to this user. (This is our target privesc goal). - Create an IAM user named
LowPrivUser. Generate access keys for this user. - Create a custom IAM policy named
MisconfiguredEscalationPolicywith the following permissions (THIS IS THE MISCONFIGURATION):{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "iam:ListAttachedUserPolicies", "iam:ListPolicies", "iam:GetPolicy", "iam:GetPolicyVersion", "iam:CreatePolicyVersion", // Allows modifying existing policies "iam:SetDefaultPolicyVersion", // Allows setting the active version "iam:AttachUserPolicy" // Allows attaching policies to users ], "Resource": "*" // Overly broad, but common in misconfigs } ] } - Attach
MisconfiguredEscalationPolicytoLowPrivUser. - Configure your AWS CLI to use the access keys of
LowPrivUser.
- Enumerate
LowPrivUser's Permissions:While you "know" the permissions from the setup, in a real scenario, you'd enumerate. One way is to try various
aws iam list-*orget-*commands or use tools like Pacu'siam__enum_permissionsmodule. For this lab, we assume you've identified the key misconfigured permissions.# Verify who you are aws sts get-caller-identity # List policies attached to LowPrivUser (if you didn't know) # aws iam list-attached-user-policies --user-name LowPrivUser - Identify a Target Policy to Modify (or a new one to create and attach):
The goal is to gain admin rights. The misconfiguration allows
iam:CreatePolicyVersion. If we can find an existing policy attached to a user/role we want to escalate to (or that is unattached but powerful), we can modify it. Or, since we also haveiam:AttachUserPolicy, we could try to attach an existing administrative policy (likeAdministratorAccess) to ourLowPrivUser.Path 1: Attaching an Existing Admin Policy (Easier with
iam:AttachUserPolicyto self) - Attempt to Attach AdministratorAccess to
LowPrivUser:Get the ARN of the AdministratorAccess policy.
aws iam list-policies --scope AWS --query 'Policies[?PolicyName==`AdministratorAccess`].Arn' --output textLet's say the output is
arn:aws:iam::aws:policy/AdministratorAccess.aws iam attach-user-policy --user-name LowPrivUser --policy-arn arn:aws:iam::aws:policy/AdministratorAccess - Verify Escalated Privileges:
Try an administrative action that
LowPrivUsercouldn't do before, e.g., list all IAM users or create a new S3 bucket.aws iam list-users aws s3 mb s3://ceh13-privesc-test-bucket-[yourname]If these commands succeed, you've escalated privileges!
-
Path 2: Modifying an Existing Policy (using
iam:CreatePolicyVersionandiam:SetDefaultPolicyVersion)This path is more complex and usually targeted if
iam:AttachUserPolicyto self is not an option, but you can modify a policy attached to another user/role you want to impersonate or gain similar rights to. For this lab, Path 1 is simpler given the permissions.If you were to attempt Path 2, you would:
- Find a target policy ARN.
- Get its current default version document:
aws iam get-policy-version --policy-arn--version-id - Modify the policy document JSON to include permissive statements (e.g.,
"Action": "*", "Resource": "*"). - Create a new policy version:
aws iam create-policy-version --policy-arn--policy-document file://modified_policy.json --set-as-default
- Cleanup:
If you successfully attached the policy:
aws iam detach-user-policy --user-name LowPrivUser --policy-arn arn:aws:iam::aws:policy/AdministratorAccess # aws s3 rb s3://ceh13-privesc-test-bucket-[yourname] # If createdDelete the IAM users and custom policy created for the lab in your AWS account.
- Successful attachment of the
AdministratorAccesspolicy toLowPrivUser. LowPrivUser(with its original keys but now with the new policy) can perform administrative actions previously denied.
- S3 bucket names are globally unique and can sometimes be guessed or enumerated.
- Publicly accessible S3 buckets (read or write) pose significant security risks, leading to data exposure or defacement.
- AWS CLI is a powerful tool for interacting with S3 buckets, both for legitimate management and for exploitation if permissions are lax.
- IAM is the cornerstone of AWS security. Misconfigured IAM policies are a primary vector for privilege escalation.
- Permissions like
iam:CreatePolicyVersion,iam:SetDefaultPolicyVersion,iam:AttachUserPolicy,iam:PutUserPolicy,iam:PassRole(to certain services) are high-risk and can lead to full privilege escalation if not scoped correctly. - Always operate under the principle of least privilege.
- S3 Buckets:
- Keep S3 buckets private by default.
- Use S3 Block Public Access settings at the account and bucket level.
- Implement strict bucket policies and ACLs, granting only necessary permissions to specific principals.
- Enable server access logging and CloudTrail for S3 to monitor access patterns.
- Use S3 Versioning and MFA Delete for critical data.
- Regularly scan for publicly accessible buckets using tools like AWS Config, AWS Security Hub, or third-party tools.
- IAM:
- Adhere to the principle of least privilege: Grant users and roles only the permissions they absolutely need.
- Avoid using wildcard
"*"in IAM policies for Actions or Resources where possible. Be specific. - Regularly review IAM policies for overly permissive settings, especially those related to IAM self-modification (e.g.,
iam:*Policy*,iam:CreateAccessKey). - Use IAM Roles for applications and services running on EC2 or other AWS services instead of long-lived access keys.
- Implement MFA for all IAM users, especially administrative ones.
- Monitor CloudTrail logs for suspicious IAM activity (e.g., unexpected policy changes, access key creation).
- Utilize IAM Access Analyzer to identify resources shared with external entities.
- Explore other S3 enumeration tools (e.g., BucketStream, CloudBrute).
- Investigate S3 website hosting misconfigurations.
- Research more complex IAM privilege escalation paths (e.g., via
iam:PassRoleto services like EC2, Lambda, or CodeBuild; exploiting trust relationships). - Use automated tools like Pacu or Cloudsplaining to identify AWS misconfigurations.