Skip to content
Skillpedia
Agents35k · #5708

detecting-serverless-function-injection

Has your agent detect attacks that try to inject code into serverless functions. It protects cloud services against malicious injections and improper privilege escalation.

What it does

This tool helps find and prevent attacks that try to run malicious code in cloud functions (like AWS Lambda). It checks if data received by these functions can be used to execute unwanted commands or steal information.

When to use it

  • ✓When checking if cloud functions can be attacked through the data they receive.
  • ✓When investigating if an attacker modified a function's code for persistent access.
  • ✓When looking for ways an attacker could gain more permissions than they should have.

Example of what to ask your AI

“Scan my Lambda functions for code injection via event data.”

Want more? Open the sections below.

How to use

The easiest way: copy the message below and paste it into Claude, ChatGPT, Cursor or any AI. It reads the skill and follows the instructions.

Skill link

https://github.com/mukul975/Anthropic-Cybersecurity-Skills/blob/main/skills/detecting-serverless-function-injection/SKILL.md

Ready-to-paste message

Use this skill to help me: https://github.com/mukul975/Anthropic-Cybersecurity-Skills/blob/main/skills/detecting-serverless-function-injection/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
How it works

The tool analyzes the function's code and cloud activity logs. It looks for dangerous patterns that could allow malicious commands to be executed using the data the function receives.

Installation

Easiest way: copy the skill link and paste it into Claude, ChatGPT or Cursor asking it to follow the instructions.

In the terminal (Claude Code, Codex, Cursor), in your project folder:

npx skills add mukul975/Anthropic-Cybersecurity-Skills --skill detecting-serverless-function-injection

Or download just the file:

curl -L https://raw.githubusercontent.com/mukul975/Anthropic-Cybersecurity-Skills/main/skills/detecting-serverless-function-injection/SKILL.md -o SKILL.md
Technical content (original SKILL.md)

Original text by the author, straight from GitHub.

Detecting Serverless Function Injection

When to Use

  • Auditing Lambda/Cloud Functions for code injection vulnerabilities where unsanitized event data flows into dangerous runtime functions (eval, exec, child_process.exec, os.system)
  • Investigating incidents where an attacker modified function code or layers to establish persistence or exfiltrate data from the serverless environment
  • Detecting privilege escalation paths where an adversary with lambda:UpdateFunctionCode and iam:PassRole can assume higher-privilege execution roles
  • Analyzing event source poisoning attacks where malicious payloads are injected through S3 object uploads, SQS messages, DynamoDB stream records, or API Gateway requests that trigger function execution
  • Building detection rules for SOC teams monitoring serverless workloads for unauthorized function modifications, layer additions, and suspicious invocation patterns

Do not use for load testing or denial-of-service simulation against serverless functions, for testing against production functions processing live customer data without explicit authorization, or for modifying IAM policies in shared accounts without change management approval.

Prerequisites

  • AWS account access with read permissions for Lambda, CloudTrail, IAM, CloudWatch Logs, and EventBridge
  • AWS CLI v2 configured with appropriate credentials and region
  • CloudTrail enabled with Data Events for Lambda (captures Invoke events) and Management Events (captures UpdateFunctionCode, UpdateFunctionConfiguration, CreateFunction)
  • Python 3.9+ with boto3, bandit (Python SAST), and semgrep for static analysis
  • Access to function source code or deployment packages for static analysis
  • CloudWatch Logs Insights access for querying Lambda execution logs

Workflow

Step 1: Enumerate the Serverless Attack Surface

Map all Lambda functions and their event source triggers to understand injection entry points:

  • List all Lambda functions and their configurations:
    aws lambda list-functions --query 'Functions[*].[FunctionName,Runtime,Role,Handler,Layers]' --output table
    
  • Map event source mappings: Each event source mapping is a potential injection entry point where untrusted data enters the function:
    aws lambda list-event-source-mappings --output json | \
      jq '.EventSourceMappings[] | {Function: .FunctionArn, Source: .EventSourceArn, State: .State}'
    
  • Identify API Gateway triggers: API Gateway routes pass HTTP request data (headers, query strings, body, path parameters) directly into the Lambda event object:
    aws apigateway get-rest-apis --query 'items[*].[id,name]' --output table
    
    For each API, enumerate resources and methods to identify which Lambda functions receive user-controlled HTTP input.
  • Identify S3 event triggers: S3 bucket notifications can trigger Lambda with attacker-controlled object keys and metadata:
    aws s3api get-bucket-notification-configuration --bucket <bucket-name>
    
  • Catalog function environment variables: Secrets in environment variables are exposed if an attacker achieves code execution inside the function:
    aws lambda get-function-configuration --function-name <name> \
      --query 'Environment.Variables' --output json
    
  • Identify overprivileged execution roles: Functions with * resource permissions or administrative policies are high-value escalation targets:
    aws iam list-attached-role-policies --role-name <lambda-exec-role>
    aws iam list-role-policies --role-name <lambda-exec-role>
    

Step 2: Static Analysis for Injection Sinks

Scan function code for dangerous patterns that allow injected event data to execute as code or commands:

  • Download function deployment packages:
    aws lambda get-function --function-name <name> --query 'Code.Location' --output text | xargs curl -o function.zip
    unzip function.zip -d function_code/
    
  • Python injection sinks (Lambda Python runtimes): Search for functions that execute strings as code:
    # DANGEROUS: Direct eval/exec of event data
    eval(event['expression'])           # Code injection via eval
    exec(event['code'])                 # Arbitrary code execution
    os.system(event['command'])         # OS command injection
    subprocess.call(event['cmd'], shell=True)  # Shell injection
    os.popen(event['input'])            # Command injection
    

…

FAQ

What are 'serverless functions'?

These are programs that run in the cloud without you needing to manage servers. Common examples include AWS Lambda, Azure Functions, and Google Cloud Functions.

What is 'code injection'?

It's a type of attack where an attacker inserts malicious code into a program. If the program runs this code, the attacker can gain control, steal data, or cause other damage.

What is 'event source poisoning'?

This is an attack where malicious data is sent through services that trigger cloud functions (like files uploaded to storage or messages in a queue). This data can then be used to attack the function.

Details

Original description by the author

Detects and prevents code injection attacks targeting serverless functions (AWS Lambda, Azure Functions, Google Cloud Functions) through event source poisoning, malicious layer injection, runtime command execution, and IAM privilege escalation via function modification. The analyst combines static analysis of function code, CloudTrail event correlation, runtime behavior monitoring, and IAM policy

repo: mukul975/Anthropic-Cybersecurity-Skills

Popularity

GitHub stars
35k
Ranking position
#5708
License
Apache-2.0
Updated
8/31/2026

Is this skill useful?

0

Sign in to vote.

Comments

  • …

More skills from this repository

Similar skills