githubEdit

Lambda

1) Get function with URL

aws lambda get-function --function-name arn:aws:lambda:REGION:AWS_ACCOUNT_ID:function:sample-lambda

2) Download

curl "https://GENERATED_URL_FROM_PREVIOUS_COMMAND" --output lambda.zip

3) Unzip contents

unzip lambda.zip

Enumeration

1) Enumerate Lambda functions

aws lambda list-functions

2) Enumerate policies attached to each function

FUNCTIONS="LAMBDA_FUNCTION_NAME NAME_2"

for f in $FUNCTIONS ; do
    ROLE=`aws lambda get-function --function-name $f --query Configuration.Role --output text | awk -F\/ '{print $NF}'`
    echo "$f has $ROLE with these managed policies:"
    aws iam list-attached-role-policies --role-name $ROLE
    for p in `aws iam list-role-policies  --role-name $ROLE --query PolicyNames --output text` ; do
        echo "$ROLE for $f has inline policy $p:"
        aws iam get-role-policy --role-name $ROLE --policy-name $p
    done
done

3) Download function code for analysis

4) Create a new zip file to ready it for upload after modification

Insert Malicious Code

Prerequisites: AWS Credentials that have the permissions to do so.

1) Check policies in the Lambda function

Interesting findings:

  • lambda:UpdateFunctionCode

  • lambda:*

2) Modify the function with a reverse shell, or print sensitive information.

3) Invoke function

Last updated