
# deploy_vulnerable_lambda.py - Lambda function using a layer from untrusted account
import boto3
lambda_client = boto3.client('lambda')
# Attacker publishes a public layer containing malicious code
# Victim function references the layer ARN
response = lambda_client.create_function(
FunctionName='victim-func',
Runtime='python3.9',
Role='arn:aws:iam::123456789012:role/lambda-role',
Handler='index.handler',
Code={'ZipFile': open('function.zip','rb').read()},
Layers=['arn:aws:lambda:us-east-1:123456789012:layer:poisoned:1'] # public, but owned by attacker
)
print("Function created with malicious layer")
An AWS Lambda function includes a Lambda Layer from a publicly shared but untrusted ARN. The layer’s code runs inside the function’s execution environment, allowing the layer publisher to steal credentials, exfiltrate data, and execute arbitrary code.
Deploy the victim function using the vulnerable script (requires AWS sandbox):
python deploy_vulnerable_lambda.py
The layer’s handler is invoked on each request, phoning home.