PISA Pakistan — Community CERT

← ⚙️ Red Team Fundamentals (Ethical)

44. Serverless Cloud Penetration Testing: Attacking AWS Lambda and Azure Functions

⏱ 7 min

Overview

Serverless functions (e.g., AWS Lambda, Azure Functions) abstract away the underlying OS, but they still require IAM roles, environment variables, and runtime permissions that can be abused. Red teams must understand how to enumerate functions, identify over‑privileged execution contexts, and achieve persistence without a traditional host. This lesson walks through a Pakistani e‑commerce scenario where a startup uses Lambda to process easypaisa payment callbacks.

Serverless Threat Model

  • Function as a target: injection via unvalidated event data (API Gateway, S3 triggers).
  • IAM misconfigurations: functions often run with admin‑like policies for convenience.
  • Environment secrets: API keys, database credentials, and tokens stored in plain text.
  • Dead‑letter queues (DLQ): unprocessed events may retain sensitive payload if not sanitized.

Enumerating Functions & IAM Roles

  1. Use AWS CLI (aws lambda list-functions) or Azure CLI (az functionapp list) to discover functions in the target account.
  2. Pull the function’s execution role with aws lambda get-function-configuration; check for * actions in the attached policy.
  3. Enumerate S3 bucket policies and DynamoDB tables that the function can access (aws s3api get-bucket-policy, aws dynamodb describe-table).
  4. Run Pacu modules (lambda__enum, lambda__privesc_scan) to automate privilege‑escalation checks.

Escalation & Persistence in Lambda

  • Inject malicious code through an S3 upload trigger: upload a crafted payload that the function deserializes without validation.
  • Privilege escalation: if the function’s role has sts:AssumeRole with a broad trust policy, invoke it to obtain temporary credentials for other services.
  • Backdoor via DLQ: set the function’s error handler to invoke a secondary function you control, ensuring continued execution even after the original code is patched.
  • Exfiltrate data: use the over‑privileged role to call ses:SendEmail with captured payment tokens, simulating a data breach.

Do / Don't

  • Do create a separate test AWS/Azure account for all serverless experiments to avoid accidental production impact.
  • Do log all function invocations in CloudWatch/Log Analytics for later review and reporting.
  • Don't store captured secrets in plain text; encrypt them with a team‑wide GPG key before archiving.
  • Don't modify production function code; demonstrate the risk through read‑only enumeration and safe proof‑of‑concept payloads.

Key Takeaway

Serverless functions introduce a new class of attack surface where IAM misconfigurations and insecure deserialization can lead to full environment compromise. By mastering enumeration tools like Pacu, MicroBurst, and the cloud CLI, red teams can provide Pakistani businesses—particularly fintech firms using easypaisa/JazzCash integrations—with concrete remediation steps. Report any discovered exposure to NCCIA 1799 and reference pisa.maahir.io for detailed lab walkthroughs.

← PrevNext →