Skip to content
Pwnversity
CLOUD-SERVERLESSadvanced · 5 min · upd. 2026-10

Serverless Security

Serverless (AWS Lambda, Azure Functions, GCP Cloud Functions/Run) runs code without managing servers. For the attacker, each function is a small surface with its own weaknesses: secrets in environment variables, a role/identity with abusable permissions, vulnerable dependencies, and injection if it processes untrusted input. And since functions usually have cloud permissions, compromising one is often the jump into the rest of the account.

A function isn’t “just code”: it runs with an identity (execution role) that has permissions over other cloud resources. The attacker has two paths: read the function’s configuration (secrets in environment variables, code) with enumeration permissions, or execute code inside the function (injection, vulnerable dependency) to steal the role’s credentials from the execution environment. Either one inherits the function’s permissions → escalation and lateral movement (see IAM Abuse and Privilege Escalation).

flowchart TD
    A[Serverless function] --> B{Attack path}
    B -->|enumeration| C[Read env vars / code]
    B -->|injection / vuln dep| D[RCE in the function]
    C --> E[Secrets: API keys, DB creds]
    D --> F[Execution-role credentials]
    F --> G[Role permissions -> cloud-iam]
    E --> G
    B -->|PassRole + CreateFunction| H[Function as admin role]
    H --> G
Ventana de terminal
# functions store config/secrets in env vars (common, insecure practice)
aws lambda get-function-configuration --function-name X # shows Environment.Variables
# inside the function (if there's RCE): printenv / os.environ -> API keys, DB creds, tokens

The function runs with a role/identity whose credentials are in the environment. In AWS Lambda, the runtime exposes AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, and AWS_SESSION_TOKEN as environment variables. If you get RCE in the function (injection), you steal those credentials and use them outside:

Ventana de terminal
# after stealing the role's temporary credentials
export AWS_ACCESS_KEY_ID=ASIA... AWS_SECRET_ACCESS_KEY=... AWS_SESSION_TOKEN=...
aws sts get-caller-identity # confirm which role it is -> escalate (cloud-iam)

The function processes events (HTTP, queues, S3…). If it doesn’t validate input: command injection, SSRF (→ metadata and other services, see Metadata Service (IMDS)), path traversal, deserialization. A function behind API Gateway is a webapp: the Web section attacks apply.

Ventana de terminal
# vulnerable npm/pip packages in the function bundle
# deployment permissions (create/update functions) -> backdoor or PassRole

PassRole / creating functions (escalation)

Section titled “PassRole / creating functions (escalation)”

With lambda:CreateFunction + iam:PassRole over an admin role, you create a function that runs as admin and executes your code (see IAM Abuse and Privilege Escalation).

Ventana de terminal
# AWS
aws lambda list-functions
aws lambda get-function --function-name X # code + configuration
# Azure
az functionapp list
az functionapp config appsettings list --name X --resource-group RG # secrets
# GCP
gcloud functions list
gcloud functions describe X ; gcloud run services list
  • Secrets outside code/env: use Secrets Manager / Key Vault / Secret Manager, not cleartext environment variables.
  • Least privilege in the execution role: the function should only be able to do what it needs (limits the damage of a compromise).
  • Validate all event input (injection, SSRF); scan dependencies (SCA) and the bundle.
  • Don’t grant CreateFunction + PassRole together to non-admin identities; review deployment permissions.
  • Logging (CloudWatch / Application Insights / Cloud Logging) and time/resource limits; WAF in front of HTTP functions.
  • Enumerate functions and their configuration (code + env vars)
  • Secrets in environment variables
  • Execution role/identity and its permissions (IAM Abuse and Privilege Escalation)
  • Injection/SSRF if it processes untrusted input (Metadata Service (IMDS))
  • Role credentials stealable via RCE in the function
  • Vulnerable dependencies in the bundle
  • PassRole + CreateFunction → escalation
  • HTTP functions treated as a webapp (Web section)