الاختبار الديناميكي وأمان وقت التشغيل

اختبار أمان 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/
نقص تحديد المواردفحوصات حد المعدل المخصصة
BFLAhttp/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

الجانبNucleiZAP
السرعةسريع جداًأبطأ
القوالب7000+ YAMLمكتوبة بسكريبت
منحنى التعلممنخفضمتوسط
الزحف العميقمحدودممتاز
الفحوصات المخصصةسهل (YAML)معقد
الأفضل لـفحوصات سريعة، CI/CDاختبار شامل

بعد ذلك، سنستكشف الحماية الذاتية للتطبيقات أثناء التشغيل (RASP). :::

مراجعة سريعة: كيف تجد هذا الدرس؟

اختبار

الوحدة 4: الاختبار الديناميكي وأمان وقت التشغيل

خذ الاختبار
نشرة أسبوعية مجانية

ابقَ على مسار النيرد

بريد واحد أسبوعياً — دورات، مقالات معمّقة، أدوات، وتجارب ذكاء اصطناعي.

بدون إزعاج. إلغاء الاشتراك في أي وقت.