Exploiting API Injection Vulnerabilities
When to Use
- Testing API endpoints that accept user input for database queries, system commands, or external requests
- Assessing APIs that interact with SQL databases, NoSQL stores (MongoDB, Redis), LDAP directories, or external URLs
- Evaluating input validation and parameterized query usage across all API endpoints
- Testing for SSRF where API parameters accept URLs or hostnames that trigger server-side requests
- Identifying injection points in headers, path parameters, query strings, and JSON/XML request bodies
Do not use without written authorization. Injection testing can modify or destroy data and compromise backend systems.
Prerequisites
- Written authorization specifying target API and backend systems in scope
- Python 3.10+ with
requests library
- SQLMap for automated SQL injection detection and exploitation
- Burp Suite Professional with Active Scan capabilities
- Knowledge of the backend database technology (MySQL, PostgreSQL, MongoDB, Redis)
- Isolated test environment to avoid production data corruption
Legal Notice: This skill is for authorized security testing and educational purposes only. Unauthorized use against systems you do not own or have written permission to test is illegal and may violate computer fraud laws.
Workflow
Step 1: Injection Point Identification
import requests
import json
import urllib.parse
BASE_URL = "https://target-api.example.com/api/v1"
headers = {"Authorization": "Bearer <token>", "Content-Type": "application/json"}
# Map all input points across the API
injection_points = [
# Path parameters
{"type": "path", "method": "GET", "url": "/users/{input}"},
{"type": "path", "method": "GET", "url": "/products/{input}"},
{"type": "path", "method": "GET", "url": "/orders/{input}"},
# Query parameters
{"type": "query", "method": "GET", "url": "/users?search={input}"},
{"type": "query", "method": "GET", "url": "/products?sort={input}&order={input}"},
{"type": "query", "method": "GET", "url": "/products?category={input}"},
{"type": "query", "method": "GET", "url": "/search?q={input}"},
# JSON body parameters
{"type": "body", "method": "POST", "url": "/auth/login", "fields": ["username", "password"]},
{"type": "body", "method": "POST", "url": "/users", "fields": ["name", "email"]},
{"type": "body", "method": "POST", "url": "/search", "fields": ["query", "filters"]},
{"type": "body", "method": "POST", "url": "/webhook", "fields": ["url", "callback_url"]},
# Header parameters
{"type": "header", "method": "GET", "url": "/users/me", "headers": ["X-Forwarded-For", "Referer", "User-Agent"]},
]
Step 2: SQL Injection Testing
> 📎 Detailed content (full examples / references / data tables) has been split into `reference.md` in the same directory; use Read to load the relevant section on demand.
1---2name: exploiting-api-injection-vulnerabilities3description: "Exploit API injection vulnerabilities. Signals: API attack, interface testing, GraphQL."4zh-signals: "Exploiting API Injection Vulnerabilities 信号:api攻击,接口测试,graphql。"5when-to-use: >-6 Tests API parameters, headers, and request bodies for injection flaws — SQL injection,7 NoSQL injection, OS command injection, LDAP injection, and SSRF — by crafting8 payloads tailored to the target backend to extract data, execute commands, or9 reach internal services, mapped to OWASP API8:2023 and API7:2023 SSRF. Use when10 performing SQLi, NoSQL injection, command injection, or SSRF testing against APIs,11 or assessing API input validation.12domain: cybersecurity13subdomain: api-security14tags:15- api-security16- owasp17- injection18- sqli19- nosql20- ssrf21- command-injection22version: 1.0.023author: mahipal24license: Apache-2.025nist_csf:26- PR.PS-0127- ID.RA-0128- PR.DS-1029- DE.CM-0130mitre_attack:31- T119032- T1059.00733- T1552.00134- T105535- T105936metadata:37 source: https://skillmd.com/skills/dangeroussong/exploiting-api-injection-vulnerabilities38---3940# Exploiting API Injection Vulnerabilities4142## When to Use4344- Testing API endpoints that accept user input for database queries, system commands, or external requests45- Assessing APIs that interact with SQL databases, NoSQL stores (MongoDB, Redis), LDAP directories, or external URLs46- Evaluating input validation and parameterized query usage across all API endpoints47- Testing for SSRF where API parameters accept URLs or hostnames that trigger server-side requests48- Identifying injection points in headers, path parameters, query strings, and JSON/XML request bodies4950**Do not use** without written authorization. Injection testing can modify or destroy data and compromise backend systems.5152## Prerequisites5354- Written authorization specifying target API and backend systems in scope55- Python 3.10+ with `requests` library56- SQLMap for automated SQL injection detection and exploitation57- Burp Suite Professional with Active Scan capabilities58- Knowledge of the backend database technology (MySQL, PostgreSQL, MongoDB, Redis)59- Isolated test environment to avoid production data corruption606162> **Legal Notice:** This skill is for authorized security testing and educational purposes only. Unauthorized use against systems you do not own or have written permission to test is illegal and may violate computer fraud laws.6364## Workflow6566### Step 1: Injection Point Identification6768```python69import requests70import json71import urllib.parse7273BASE_URL = "https://target-api.example.com/api/v1"74headers = {"Authorization": "Bearer <token>", "Content-Type": "application/json"}7576# Map all input points across the API77injection_points = [78 # Path parameters79 {"type": "path", "method": "GET", "url": "/users/{input}"},80 {"type": "path", "method": "GET", "url": "/products/{input}"},81 {"type": "path", "method": "GET", "url": "/orders/{input}"},82 # Query parameters83 {"type": "query", "method": "GET", "url": "/users?search={input}"},84 {"type": "query", "method": "GET", "url": "/products?sort={input}&order={input}"},85 {"type": "query", "method": "GET", "url": "/products?category={input}"},86 {"type": "query", "method": "GET", "url": "/search?q={input}"},87 # JSON body parameters88 {"type": "body", "method": "POST", "url": "/auth/login", "fields": ["username", "password"]},89 {"type": "body", "method": "POST", "url": "/users", "fields": ["name", "email"]},90 {"type": "body", "method": "POST", "url": "/search", "fields": ["query", "filters"]},91 {"type": "body", "method": "POST", "url": "/webhook", "fields": ["url", "callback_url"]},92 # Header parameters93 {"type": "header", "method": "GET", "url": "/users/me", "headers": ["X-Forwarded-For", "Referer", "User-Agent"]},94]95```9697### Step 2: SQL Injection Testing9899```python100101> 📎 Detailed content (full examples / references / data tables) has been split into `reference.md` in the same directory; use Read to load the relevant section on demand.