الاختبار الديناميكي وأمان وقت التشغيل
اختبار أمان API مع Nuclei
3 دقيقة للقراءة
Nuclei هو ماسح ثغرات سريع قائم على القوالب مثالي لاختبار أمان API. قوالب YAML الخاصة به تجعل من السهل كتابة فحوصات أمان مخصصة.
لماذا Nuclei لـ APIs
| الميزة | الفائدة |
|---|---|
| قائم على القوالب | سهل التخصيص والمشاركة |
| سريع | فحص متزامن، حمل أدنى |
| قابل للتوسيع | 7000+ قالب من المجتمع |
| صديق لـ CI/CD | إخراج JSON/SARIF، أكواد خروج |
| مركز على API | دعم OpenAPI/Swagger |
التثبيت
# macOS
brew install nuclei
# Linux
go install -v github.com/projectdiscovery/nuclei/v3/cmd/nuclei@latest
# Docker
docker pull projectdiscovery/nuclei:latest
# تحديث القوالب
nuclei -update-templates
الاستخدام الأساسي
# فحص URL واحد
nuclei -u https://api.example.com -t http/
# فحص مع قوالب محددة
nuclei -u https://api.example.com -t cves/ -t exposed-panels/
# فحص من مواصفات OpenAPI
nuclei -u https://api.example.com/openapi.json -t http/exposures/
# الإخراج إلى JSON
nuclei -u https://api.example.com -json -o results.json
قوالب أمان API
ثغرات API الشائعة
# اختبار مشاكل API الشائعة
nuclei -u https://api.example.com \
-t http/exposures/apis/ \
-t http/misconfiguration/ \
-t http/vulnerabilities/
تغطية OWASP API Top 10
| مخاطر OWASP API | قوالب Nuclei |
|---|---|
| تفويض مستوى الكائن المكسور | http/exposures/apis/ |
| المصادقة المكسورة | http/default-logins/ |
| التعرض المفرط للبيانات | http/exposures/ |
| نقص تحديد الموارد | فحوصات حد المعدل المخصصة |
| BFLA | http/misconfiguration/ |
| التعيين الجماعي | قوالب مخصصة |
| سوء تكوين الأمان | http/misconfiguration/ |
| الحقن | http/vulnerabilities/ |
| إدارة الأصول غير السليمة | http/technologies/ |
| التسجيل غير الكافي | قوالب مخصصة |
قالب API مخصص
إنشاء قوالب مخصصة لـ APIs الخاصة بك:
# .nuclei/templates/api-auth-bypass.yaml
id: api-auth-bypass
info:
name: API Authentication Bypass
author: your-team
severity: high
description: اختبارات للمصادقة المفقودة على نقاط نهاية API
tags: api,auth,bypass
http:
- method: GET
path:
- "{{BaseURL}}/api/v1/users"
- "{{BaseURL}}/api/v1/admin/settings"
- "{{BaseURL}}/api/v1/internal/debug"
matchers-condition: and
matchers:
- type: status
status:
- 200
- type: word
words:
- '"users"'
- '"data"'
- '"settings"'
condition: or
تكامل CI/CD
GitHub Actions
# .github/workflows/nuclei-api.yml
name: API Security Scan
on:
push:
branches: [main]
schedule:
- cron: '0 3 * * *'
jobs:
nuclei:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run Nuclei
uses: projectdiscovery/nuclei-action@main
with:
target: https://api.example.com
templates: |
http/exposures/
http/misconfiguration/
http/vulnerabilities/
output: nuclei-results.txt
sarif-export: nuclei-results.sarif
flags: "-severity critical,high,medium"
- name: Upload SARIF
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: nuclei-results.sarif
فحص مواصفات OpenAPI
- name: Generate targets from OpenAPI
run: |
# استخراج نقاط النهاية من مواصفات OpenAPI
curl -s ${{ secrets.API_SPEC_URL }} | \
jq -r '.paths | keys[]' | \
sed "s|^|https://api.example.com|" > targets.txt
- name: Run Nuclei on API endpoints
run: |
nuclei -l targets.txt \
-t http/vulnerabilities/ \
-severity critical,high \
-json -o results.json
ميزات متقدمة
تحديد المعدل
# تحديد الطلبات في الثانية
nuclei -u https://api.example.com -rate-limit 10
# الطلبات المتزامنة
nuclei -u https://api.example.com -concurrency 5
الفحص المصادق عليه
# مع رؤوس مخصصة
nuclei -u https://api.example.com \
-H "Authorization: Bearer $API_TOKEN" \
-H "X-API-Key: $API_KEY"
# مع الكوكيز
nuclei -u https://api.example.com \
-H "Cookie: session=abc123"
قوالب سير العمل
ربط فحوصات متعددة:
# workflow-api-audit.yaml
id: api-security-audit
info:
name: Complete API Security Audit
author: your-team
workflows:
- template: http/technologies/
- template: http/exposures/apis/
- template: http/vulnerabilities/
- template: custom/api-auth-bypass.yaml
Nuclei مقابل ZAP لـ APIs
| الجانب | Nuclei | ZAP |
|---|---|---|
| السرعة | سريع جداً | أبطأ |
| القوالب | 7000+ YAML | مكتوبة بسكريبت |
| منحنى التعلم | منخفض | متوسط |
| الزحف العميق | محدود | ممتاز |
| الفحوصات المخصصة | سهل (YAML) | معقد |
| الأفضل لـ | فحوصات سريعة، CI/CD | اختبار شامل |
بعد ذلك، سنستكشف الحماية الذاتية للتطبيقات أثناء التشغيل (RASP). :::