الدرس 19 من 24

أمان API والهاتف

الأتمتة وقوالب Nuclei

3 دقيقة للقراءة

الأتمتة توسع صيدك للثغرات. Nuclei هو ماسح الثغرات لصيادي الثغرات في 2026—سريع، قابل للتوسعة، ومدعوم من المجتمع.

لماذا الأتمتة؟

الاختبار اليدوي الاختبار الآلي
ساعات لكل هدف دقائق لكل هدف
عميق، مركز تغطية واسعة
اكتشافات عالية الجودة اكتشافات بالحجم
خطر الإرهاق مستدام

أفضل نهج: أتمت الاستطلاع والثغرات المعروفة، اختبر منطق الأعمال يدوياً.

أساسيات Nuclei

الاستخدام الأساسي

# هدف واحد
nuclei -u https://example.com

# أهداف متعددة
nuclei -l targets.txt

# علامات محددة
nuclei -u https://example.com -tags cve,xss,sqli

# خطورة محددة
nuclei -u https://example.com -severity critical,high

# تحديث القوالب
nuclei -update-templates

فئات القوالب

الفئة الوصف العدد (2026)
cves CVEs معروفة 5,000+
exposures ملفات/تكوينات مكشوفة 1,000+
vulnerabilities ثغرات عامة 500+
misconfiguration أخطاء تكوين الخادم 300+
technologies كشف التقنية 400+

خيارات المخرجات

# مخرج JSON
nuclei -l targets.txt -json -o results.json

# تقرير Markdown
nuclei -l targets.txt -me reports/

# الوضع الصامت (مخرج أدنى)
nuclei -l targets.txt -silent -o findings.txt

# تحديد المعدل (كن لطيفاً مع الأهداف)
nuclei -l targets.txt -rate-limit 10

كتابة قوالب مخصصة

هيكل القالب الأساسي

id: my-custom-check

info:
  name: Custom Vulnerability Check
  author: your-name
  severity: medium
  description: Check for specific vulnerability
  tags: custom,webapp

requests:
  - method: GET
    path:
      - "{{BaseURL}}/admin"
    matchers:
      - type: status
        status:
          - 200
      - type: word
        words:
          - "Admin Dashboard"
        condition: and

المطابقات المتقدمة

requests:
  - method: GET
    path:
      - "{{BaseURL}}/.env"
    matchers:
      - type: word
        words:
          - "DB_PASSWORD"
          - "APP_KEY"
        condition: or
      - type: status
        status:
          - 200
    matchers-condition: and

استخدام المتغيرات والحمولات

id: sqli-error-based

requests:
  - method: GET
    path:
      - "{{BaseURL}}/search?q={{payload}}"
    payloads:
      payload:
        - "' OR '1'='1"
        - "1' AND '1'='1"
        - "admin'--"
    matchers:
      - type: word
        words:
          - "SQL syntax"
          - "mysql_fetch"
          - "ORA-"
        condition: or

قالب طلب POST

id: login-default-creds

requests:
  - method: POST
    path:
      - "{{BaseURL}}/login"
    body: "username={{user}}&password={{pass}}"
    payloads:
      user:
        - admin
        - root
      pass:
        - admin
        - password
        - 123456
    attack: clusterbomb
    matchers:
      - type: word
        words:
          - "Welcome"
          - "Dashboard"

سير عمل القالب

id: full-check-workflow

info:
  name: Multi-step Check
  severity: high

requests:
  - method: GET
    path:
      - "{{BaseURL}}/api/version"
    extractors:
      - type: regex
        name: version
        regex:
          - '"version":"([0-9.]+)"'

  - method: GET
    path:
      - "{{BaseURL}}/api/vuln?v={{version}}"
    matchers:
      - type: word
        words:
          - "vulnerable"

خط أنابيب الأتمتة

سكربت استطلاع + مسح كامل

#!/bin/bash
TARGET=$1
OUTPUT="./results/$TARGET"
mkdir -p $OUTPUT

echo "[*] تعداد النطاقات الفرعية..."
subfinder -d $TARGET -silent > $OUTPUT/subs.txt

echo "[*] فحص HTTP..."
cat $OUTPUT/subs.txt | httpx -silent > $OUTPUT/live.txt

echo "[*] تشغيل nuclei..."
nuclei -l $OUTPUT/live.txt \
    -severity critical,high,medium \
    -o $OUTPUT/nuclei.txt

echo "[*] التحقق من التكوينات المكشوفة..."
nuclei -l $OUTPUT/live.txt \
    -tags config,exposure \
    -o $OUTPUT/exposures.txt

echo "[+] انتهى! تحقق من $OUTPUT للنتائج"

المراقبة المستمرة

# مسح يومي مع إشعارات
#!/bin/bash
TARGETS="targets.txt"
PREV="previous-results.json"
CURR="current-results.json"

nuclei -l $TARGETS -json -o $CURR

# قارن للاكتشافات الجديدة
diff $PREV $CURR > new-findings.txt

if [ -s new-findings.txt ]; then
    # أرسل إشعار (Slack، Discord، البريد)
    curl -X POST -d @new-findings.txt $WEBHOOK_URL
fi

mv $CURR $PREV

أفضل الممارسات

  1. حدد المعدل: لا تُثقل الأهداف
  2. حدّث بانتظام: nuclei -update-templates
  3. قوالب مخصصة: ابنِ لأهدافك المحددة
  4. ادمج مع اليدوي: أتمت ما يمكن أتمتته
  5. راقب التغييرات: ميزات جديدة = ثغرات جديدة

نصيحة احترافية: أفضل الصيادين يكتبون قوالب مخصصة للثغرات التي يجدونها يدوياً—يحولون اكتشافاً واحداً لعدة اكتشافات.

في الدرس التالي، سنغطي تسلسل الثغرات لأقصى تأثير. :::

اختبار

الوحدة 5: أمان API والهاتف

خذ الاختبار