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. 01REST APIエンドポイントの評価
  2. 02IDORと権限昇格の確認
  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 ファジング
  • Mass Assignment の脆弱性
  • API ドキュメントの発見

使用するタイミング

次の依頼を受けたときに、このスキルを有効にします。

  • REST または GraphQL API をテストする
  • API の脆弱性を見つける
  • API 認証/認可をバイパスする
  • API エンドポイントを発見する
  • API のビジネスロジックをテストする
  • API ファジングを実行する
  • API ドキュメントを分析する
  • API ペネトレーションテストを支援する

使用しないタイミング

  • ソースコードが利用できる場合 — auditing-code-for-vulnerabilities を使用します
  • ブラウザーでレンダリングされるアプリケーションのサーフェス — testing-web-applications を使用します
  • トークンと署名の構築をレビューする場合 — reviewing-cryptography を使用します
  • LLM/エージェントのツール API — securing-ai-systems を使用します
  • GraphQL に特化した場合 — attacking-graphql を使用します。認可はリゾルバーに移り、リクエストごとのレート制限はバッチ処理で機能しなくなります
  • gRPC/protobuf — attacking-grpc-protobuf を使用します。それ以外の作業を始める前にスキーマを復元する必要があります
  • サーバーに URL を取得させるパラメーター — exploiting-ssrf を使用します
  • シリアライズされたオブジェクトを含むボディまたは Cookie — exploiting-deserialization を使用します
  • 偽造、解読、または混乱の対象となる JWT ベアラートークン — 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"

Mass Assignment:

# 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 のテスト

GraphQL の発見用エンドポイント、イントロスペクションクエリ、クエリ/ミューテーションの例、GraphQL 固有の攻撃ペイロード(IDOR、Mass Assignment、バッチ処理/ネストによる DoS、エイリアスの悪用)については、references/graphql-and-injection-attacks.md を参照してください。包括的なエンゲージメントには、専用の 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 インジェクション攻撃

クエリパラメーターと JSON/XML リクエストボディの両方に使用する、SQL、コマンド、NoSQL、XXE ペイロードを含む API インジェクションペイロードの完全なカタログについては、references/graphql-and-injection-attacks.md を参照してください。

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 を実行してください。レポートで引用する前に、 現在の ATT&CK リリースに照らして ID を再確認してください。

初期アクセス(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。

コメント