كتابة التقارير الأمنية — الجزء 2: تقرير اختبار الاختراق — الاختراق الأخلاقي
كتابة تقارير اختبار الاختراق
أهمية التقرير
- التواصل مع الإدارة والفنيين
- توثيق رسمي للنتائج
- أساس لخطة الإصلاح
- إثبات قيمة العمل
هيكل التقرير
1. الملخص التنفيذي (Executive Summary)
للإدارة غير التقنية:
- نظرة عامة
- أهم المخاطر
- التوصيات الرئيسية
2. نطاق الاختبار (Scope)
- الأنظمة المستهدفة
- الفترة الزمنية
- القيود والاستثناءات
- المنهجية المتبعة
3. الملخص الفني (Technical Summary)
- إحصائيات الثغرات
- التصنيف حسب الخطورة
- رسوم بيانية
4. النتائج التفصيلية (Detailed Findings)
لكل ثغرة:
- العنوان والخطورة
- الوصف
- الأثر
- خطوات إعادة الإنتاج
- الأدلة (Screenshots)
- التوصية
5. الملاحق
- أدوات مستخدمة
- المراجع
- البيانات الإضافية
تصنيف الخطورة
| المستوى | CVSS | المعنى |
|---------|------|--------|
| Critical | 9.0-10.0 | خطر فوري، إصلاح عاجل |
| High | 7.0-8.9 | خطر كبير، إصلاح سريع |
| Medium | 4.0-6.9 | خطر معتدل، تخطيط للإصلاح |
| Low | 0.1-3.9 | خطر منخفض، إصلاح عند الإمكان |
| Info | 0 | معلوماتي فقط |
نصائح الكتابة
- واضح ومباشر
- لا تبالغ ولا تقلل
- أثبت بالدليل
- قدم حلولاً عملية
- راجع قبل التسليم
# مُولّد تقارير اختبار الاختراق
from datetime import datetime
import json
class PentestReportGenerator:
"""
مُولّد تقارير اختبار الاختراق
"""
def __init__(self, client_name, tester_name):
self.client = client_name
self.tester = tester_name
self.date = datetime.now().strftime("%Y-%m-%d")
self.findings = []
self.scope = {}
def set_scope(self, targets, start_date, end_date, methodology):
"""تحديد النطاق"""
self.scope = {
"targets": targets,
"start_date": start_date,
"end_date": end_date,
"methodology": methodology
}
def add_finding(self, title, severity, cvss, description,
impact, steps, evidence, recommendation):
"""إضافة ثغرة"""
finding = {
"id": f"VULN-{len(self.findings)+1:03d}",
"title": title,
"severity": severity,
"cvss": cvss,
"description": description,
"impact": impact,
"steps_to_reproduce": steps,
"evidence": evidence,
"recommendation": recommendation
}
self.findings.append(finding)
return finding["id"]
def generate_executive_summary(self):
"""توليد الملخص التنفيذي"""
severity_count = {
"Critical": 0, "High": 0, "Medium": 0, "Low": 0, "Info": 0
}
for f in self.findings:
severity_count[f["severity"]] += 1
summary = f"""
╔══════════════════════════════════════════════════════════════╗
║ EXECUTIVE SUMMARY ║
╚══════════════════════════════════════════════════════════════╝
Client: {self.client}
Assessment Date: {self.scope.get('start_date', 'N/A')} to {self.scope.get('end_date', 'N/A')}
Report Date: {self.date}
Assessor: {self.tester}
OVERVIEW
--------
A penetration test was conducted against {self.client}'s systems
to identify security vulnerabilities and assess the overall
security posture.
VULNERABILITY SUMMARY
---------------------
🔴 Critical: {severity_count['Critical']}
🟠 High: {severity_count['High']}
🟡 Medium: {severity_count['Medium']}
🟢 Low: {severity_count['Low']}
⚪ Info: {severity_count['Info']}
─────────────────
Total: {len(self.findings)}
KEY FINDINGS
------------"""
# أهم الثغرات
critical_high = [f for f in self.findings
if f["severity"] in ["Critical", "High"]]
for i, f in enumerate(critical_high[:3], 1):
summary += f"""
{i}. [{f['severity']}] {f['title']}
Impact: {f['impact'][:50]}..."""
summary += """
RECOMMENDATIONS
---------------
1. Address Critical and High severity findings immediately
2. Implement security patches and updates
3. Conduct security awareness training
4. Schedule follow-up assessment
"""
return summary
def generate_finding_detail(self, finding):
"""توليد تفاصيل ثغرة"""
severity_emoji = {
"Critical": "🔴", "High": "🟠",
"Medium": "🟡", "Low": "🟢", "Info": "⚪"
}
detail = f"""
┌──────────────────────────────────────────────────────────────┐
│ {finding['id']}: {finding['title']:<45}
├──────────────────────────────────────────────────────────────┤
│ Severity: {severity_emoji[finding['severity']]} {finding['severity']} (CVSS: {finding['cvss']})
└──────────────────────────────────────────────────────────────┘
DESCRIPTION
-----------
{finding['description']}
IMPACT
------
{finding['impact']}
STEPS TO REPRODUCE
------------------"""
for i, step in enumerate(finding['steps_to_reproduce'], 1):
detail += f"\n {i}. {step}"
detail += f"""
EVIDENCE
--------
{finding['evidence']}
RECOMMENDATION
--------------
{finding['recommendation']}
"""
return detail
def generate_full_report(self):
"""توليد التقرير الكامل"""
report = []
# صفحة العنوان
report.append(f"""
╔══════════════════════════════════════════════════════════════╗
║ ║
║ PENETRATION TEST REPORT ║
║ ║
║ Client: {self.client:<30} ║
║ Date: {self.date:<32} ║
║ ║
║ CONFIDENTIAL ║
║ ║
╚══════════════════════════════════════════════════════════════╝
""")
# الملخص التنفيذي
report.append(self.generate_executive_summary())
# النطاق
report.append(f"""
╔══════════════════════════════════════════════════════════════╗
║ SCOPE ║
╚══════════════════════════════════════════════════════════════╝
TARGETS
-------""")
for target in self.scope.get('targets', []):
report.append(f" • {target}")
report.append(f"""
METHODOLOGY: {self.scope.get('methodology', 'OWASP/PTES')}
TESTING PERIOD: {self.scope.get('start_date')} to {self.scope.get('end_date')}
""")
# النتائج التفصيلية
report.append("""
╔══════════════════════════════════════════════════════════════╗
║ DETAILED FINDINGS ║
╚══════════════════════════════════════════════════════════════╝
""")
# ترتيب حسب الخطورة
severity_order = {"Critical": 0, "High": 1, "Medium": 2, "Low": 3, "Info": 4}
sorted_findings = sorted(self.findings,
key=lambda x: severity_order[x["severity"]])
for finding in sorted_findings:
report.append(self.generate_finding_detail(finding))
return "\n".join(report)
def export_json(self):
"""تصدير JSON"""
return json.dumps({
"client": self.client,
"tester": self.tester,
"date": self.date,
"scope": self.scope,
"findings": self.findings
}, indent=2, ensure_ascii=False)
# ===== مثال على استخدام المُولّد =====
report = PentestReportGenerator(
client_name="شركة التقنية",
tester_name="أحمد المختبر"
)
# تحديد النطاق
report.set_scope(
targets=["https://app.example.com", "192.168.1.0/24"],
start_date="2024-01-15",
end_date="2024-01-20",
methodology="OWASP Testing Guide + PTES"
)
# إضافة الثغرات
report.add_finding(
title="SQL Injection in Login Form",
severity="Critical",
cvss=9.8,
description="The login form is vulnerable to SQL injection, allowing "
"authentication bypass and database access.",
impact="An attacker can bypass authentication, access all user data, "
"and potentially gain full database access.",
steps=[
"Navigate to https://app.example.com/login",
"Enter ' OR '1'='1 in username field",
"Enter any value in password field",
"Click Login - Authentication bypassed"
],
evidence="[Screenshot of successful bypass attached]\n"
"Request: POST /login\nBody: user=' OR '1'='1&pass=x",
recommendation="Use parameterized queries/prepared statements. "
"Implement input validation. Consider using an ORM."
)
report.add_finding(
title="Missing HTTPS on Admin Panel",
severity="High",
cvss=7.4,
description="The admin panel is accessible over HTTP, exposing "
"credentials to network sniffing.",
impact="Admin credentials can be captured by anyone on the network.",
steps=[
"Access http://app.example.com/admin",
"Note that connection is not encrypted",
"Capture traffic with Wireshark",
"Credentials visible in plaintext"
],
evidence="[Wireshark capture showing plaintext credentials]",
recommendation="Enforce HTTPS for all pages. Implement HSTS. "
"Redirect all HTTP to HTTPS."
)
# توليد وعرض التقرير
print(report.generate_full_report())اختبر فهمك