Kodax

مقدمة في الاختراق الأخلاقي — الاختراق الأخلاقي

الاختراق الأخلاقي (Ethical Hacking)

ما هو الاختراق الأخلاقي؟

استخدام نفس أدوات وتقنيات المخترقين بإذن قانوني لاكتشاف الثغرات.

الفرق بين القبعات

🎩 White Hat (القبعة البيضاء)

- مخترق أخلاقي

- يعمل بإذن قانوني

- يبلّغ عن الثغرات

- يحصل على مكافآت (Bug Bounty)

🖤 Black Hat (القبعة السوداء)

- مخترق ضار

- يعمل بشكل غير قانوني

- يستغل الثغرات للضرر

- يواجه السجن

🎩 Gray Hat (القبعة الرمادية)

- بين الاثنين

- قد يخترق بدون إذن

- لكن يبلّغ عن الثغرات

القواعد الأساسية

1. احصل على إذن كتابي دائماً!

📝 Scope of Work / Authorization Letter
- ما المسموح اختباره؟
- ما الممنوع؟
- الفترة الزمنية
- التوقيعات

2. لا تُلحق ضرراً

- لا تحذف بيانات

- لا تُعطّل خدمات

- وثّق كل شيء

3. أبلغ عن كل ما تجده

- حتى الثغرات البسيطة

- لا تستغل أي شيء لنفسك

مجالات العمل

- Penetration Tester

- Security Consultant

- Bug Bounty Hunter

- Red Team Member

- Security Researcher

الشهادات المعتمدة

- CEH (Certified Ethical Hacker)

- OSCP (Offensive Security)

- CompTIA PenTest+

- eJPT (eLearnSecurity)

# مثال: كيف يفكر المخترق الأخلاقي

"""
سيناريو: فحص تطبيق ويب بإذن قانوني

الخطوات المنهجية:
1. الاستطلاع (Reconnaissance)
2. الفحص (Scanning)
3. الوصول (Gaining Access)
4. الحفاظ على الوصول (Maintaining Access)
5. تغطية الآثار (Covering Tracks) - في الاختبار الأخلاقي نوثّق بدلاً من التغطية
6. التقرير (Reporting)
"""

class EthicalHackingWorkflow:
    """
    سير عمل الاختراق الأخلاقي
    """
    
    def __init__(self, target, authorization):
        self.target = target
        self.authorization = authorization
        self.findings = []
        
        # التحقق من الإذن أولاً!
        if not self.verify_authorization():
            raise Exception("⚠️ لا يوجد إذن قانوني! توقف فوراً!")
    
    def verify_authorization(self):
        """التحقق من وجود إذن قانوني"""
        required_fields = [
            'client_name',
            'scope',
            'start_date',
            'end_date',
            'signature'
        ]
        
        for field in required_fields:
            if field not in self.authorization:
                print(f"❌ حقل مفقود: {field}")
                return False
        
        print("✅ الإذن القانوني صالح")
        return True
    
    def reconnaissance(self):
        """المرحلة 1: جمع المعلومات"""
        print("\n🔍 مرحلة الاستطلاع...")
        
        info = {
            "domain": self.target,
            "ip_addresses": [],
            "subdomains": [],
            "technologies": [],
            "employees": []  # من LinkedIn مثلاً
        }
        
        # جمع معلومات عامة (Passive)
        print("  - جمع معلومات DNS")
        print("  - البحث في Google Dorks")
        print("  - فحص WHOIS")
        
        return info
    
    def scanning(self):
        """المرحلة 2: الفحص"""
        print("\n📡 مرحلة الفحص...")
        
        # فحص المنافذ
        print("  - فحص المنافذ (nmap)")
        print("  - فحص الثغرات (Nessus/OpenVAS)")
        print("  - فحص تطبيق الويب (Burp Suite)")
        
        return {
            "open_ports": [80, 443, 22],
            "vulnerabilities": []
        }
    
    def add_finding(self, severity, title, description, recommendation):
        """إضافة ثغرة مكتشفة"""
        finding = {
            "id": len(self.findings) + 1,
            "severity": severity,  # Critical, High, Medium, Low
            "title": title,
            "description": description,
            "recommendation": recommendation
        }
        self.findings.append(finding)
        print(f"  🔴 ثغرة {severity}: {title}")
    
    def generate_report(self):
        """المرحلة الأخيرة: التقرير"""
        print("\n📝 إنشاء التقرير...")
        
        report = f"""
╔══════════════════════════════════════╗
║     تقرير اختبار الاختراق           ║
╚══════════════════════════════════════╝

🎯 الهدف: {self.target}
📅 التاريخ: 2024-01-15
👤 المختبر: Security Team

📊 ملخص الثغرات:
"""
        
        severity_count = {"Critical": 0, "High": 0, "Medium": 0, "Low": 0}
        for f in self.findings:
            severity_count[f["severity"]] += 1
        
        for sev, count in severity_count.items():
            report += f"  - {sev}: {count}\n"
        
        report += "\n📋 التفاصيل:\n"
        for f in self.findings:
            report += f"""
[{f['severity']}] {f['title']}
  الوصف: {f['description']}
  التوصية: {f['recommendation']}
"""
        
        return report


# مثال على الاستخدام
authorization = {
    "client_name": "شركة Example",
    "scope": "example.com و جميع النطاقات الفرعية",
    "start_date": "2024-01-01",
    "end_date": "2024-01-31",
    "signature": "توقيع المدير التنفيذي"
}

try:
    pentest = EthicalHackingWorkflow("example.com", authorization)
    
    # تنفيذ المراحل
    pentest.reconnaissance()
    pentest.scanning()
    
    # إضافة ثغرات مكتشفة (مثال)
    pentest.add_finding(
        "High",
        "SQL Injection في صفحة تسجيل الدخول",
        "حقل username يقبل أوامر SQL",
        "استخدام Prepared Statements"
    )
    
    pentest.add_finding(
        "Medium",
        "Missing Security Headers",
        "لا يوجد Content-Security-Policy",
        "إضافة CSP headers"
    )
    
    # التقرير النهائي
    print(pentest.generate_report())
    
except Exception as e:
    print(f"❌ {e}")
اختبر فهمك