ITCS 310 · Network Security · Week 13 L2
Firewalls & Intrusion Detection Systems
الجدران النارية وأنظمة كشف التسلل (IDS)
Prevention Layer Detection Layer Stateful vs Stateless ملزمة ثنائية اللغة
ACADEZI.COM
College of Information Technology
Detailed Teaching Guide · دليل تدريس مفصّل
ما هو الجدار الناري؟ (Motivation & Definition) What is a Firewall? – Motivation & Definition §1
يُمثل الجدار الناري خط الدفاع الأول في معمارية الأمان الهرمية (Prevention Layer). هو أي جهاز يُستخدم لمنع الغرباء من الوصول للشبكة. يقوم بمراقبة والتحكم في حركة المرور الواردة والصادرة بناءً على سياسات محددة، مما يمنع الحركة الخبيثة ويسمح بالشرعية. وظيفته الأساسية هي التحكم في الحركة بين "مناطق الثقة" (Zones of Trust)، مثل الإنترنت والشبكة المحلية.
A Firewall represents the first line of defense in a layered security architecture (Prevention Layer). It is any device used to prevent outsiders from gaining access to the network. It monitors and controls incoming and outgoing traffic based on policies, blocking malicious traffic while allowing legitimate ones. Its basic task is to control traffic between "zones of trust" (e.g., Internet vs. Intranet).
What Firewalls Examine
🔍 ماذا يفحص الجدار الناري؟
يقوم عادةً بفحص: مصدر الحركة (Source IP, Port)، وجهة الحركة (Destination IP, Port)، نوع البروتوكول، وأحياناً محتوى الحركة.
Usually examines: Source of traffic (IP, Port), Destination of traffic, Type of traffic (Protocol), and Content of traffic.
Design Goals
🎯 أهداف التصميم
يجب أن تمر كل الحركة عبره، ويسمح للمصرح به فقط. يجب أن يكون منيعاً ضد الاختراق. ويمثل توازناً (Tradeoff) بين الأمان والإنتاجية للموظفين.
All traffic must pass through it, only authorized traffic is allowed. Must be immune to penetration. Represents a tradeoff between security and productivity.
سياسات الوصول للجدار الناري — الإجراءات (Actions) Firewall Access Policies & Actions §2
تُحدد سياسات الجدار أنواع الحركة المصرح لها بالمرور (نطاقات العناوين، البروتوكولات، التطبيقات). بناءً عليها، يتخذ الجدار أحد الإجراءات الثلاثة التالية:
Firewall access policies determine the types of traffic authorized to pass (address ranges, protocols, apps). Based on these, the firewall takes one of three actions:
الإجراءActionالوصف في الجدار الناريDescription
Accepted (مقبول)يُسمح للحزمة بالمرور عبر الجدار الناري وإكمال طريقها.Permitted to pass through the firewall successfully.
Dropped (مُسقَط)لا يُسمح لها بالمرور، ولا يتم إرسال أي إشعار للمرسل برفضها (تجاهل صامت).Not allowed through, with NO indication of failure to the sender.
Rejected (مرفوض)لا يُسمح لها بالمرور، ويتم إبلاغ المصدر برسالة تفيد برفض الحزمة.Not allowed through, accompanied by an attempt to inform the source.
منهجيات بناء السياسات: القائمة السوداء مقابل البيضاء Policies: Blacklists and Whitelists §3
Blacklist Approach (Default-Allow)
المنهجية 1: القائمة السوداء (السماح الافتراضي)
يُسمح بمرور جميع الحزم باستثناء تلك التي تتطابق تحديداً مع القواعد في القائمة السوداء.
المزايا: مرن ولا يعطل سير العمل الطبيعي للشبكة.
العيوب: حركة خبيثة جديدة أو غير متوقعة قد تمر لأنها ليست في القائمة.
All packets are allowed except those matching specific rules in the blacklist.
Pros: Flexible, doesn't disrupt normal network service.
Cons: Unexpected forms of malicious traffic could slip through.
Whitelist Approach (Default-Deny)
المنهجية 2: القائمة البيضاء (الرفض الافتراضي)
يتم إسقاط جميع الحزم ما لم يُسمح لها تحديداً بواسطة قواعد الجدار الناري.
المزايا: نهج أكثر أماناً لتحديد القواعد (A safer approach).
العيوب: يتطلب جهداً كبيراً لتحديد كل حركة مرور مشروعة ومطلوبة والسماح بها مسبقاً.
Packets are dropped unless specifically allowed by the firewall ruleset.
Pros: A much safer approach to defining security.
Cons: Must explicitly consider and list all legitimate traffic.
الفئات الخمس الكبرى للجدران النارية (نظرة عامة) The Five Broad Categories of Firewalls §4
تختلف هذه الأنواع بشكل أساسي في عمق الفحص (Depth of inspection) ومدى الوعي بالحالة (State awareness).
These types differ primarily in the depth of inspection and state awareness.
Type 1
بوابة الدوائر
Circuit Gateways (Transport Layer)
Type 2
تصفية الحزم
Stateless Packet-Filtering (Network)
Type 3
فحص الحالة
Stateful Inspection (Network/Transport)
Type 4
بوابة التطبيقات
Application-Level Gateway (Proxy)
Type 5
متعدد الطبقات
Stateful Multi-layer Firewalls
Type 1: بوابة الدوائر (Circuit Level Gateways) Type 1: Circuit Level Gateways (Transport Level) §5
يعمل في طبقة النقل (Transport Layer). وظيفته التحقق من عملية TCP Handshake بين الاتصالات لتحديد ما إذا كانت الجلسة مشروعة أم لا. العيب الخطير: لا يفحص البيانات في طبقة IP، فإذا كان هناك برمجيات خبيثة (Malware) داخل الحمولة مع TCP Handshake سليم، ستمر بسهولة!
Works at the Transport layer. Verifies and monitors the TCP handshake process to determine if a session is legitimate. Critical Flaw: Doesn't check data at the IP level. If malware is embedded in the payload with a proper handshake, it easily bypasses the firewall!
يتم ذلك عبر إنشاء أنفاق (Tunnels) لعمليات معينة والسماح فقط للحركة المصرح لها داخل النفق. حركته غير كافية لتأمين الشبكة بالكامل بمفردها.
Accomplished by creating tunnels connecting specific processes, allowing only authorized traffic. Insufficient to use by itself to secure the entire network.
Type 2: تصفية الحزم غير المرتبطة بالحالة (Stateless Packet-Filtering) Type 2: Stateless Packet-Filtering (Network Level) §6
يعمل في طبقة الشبكة (Network Layer). هو النوع الأبسط والأكثر شيوعاً. يتجاهل حالة الاتصال؛ يعامل كل حزمة بشكل منفصل دون اعتبار للحزم السابقة. يتم الفحص فقط على "رأس الحزمة" (IP Header) ولا يفحص الحمولة (Payload). خفيف جداً على موارد النظام ولكنه سهل التجاوز.
Works at the Network Layer. Simplest and most common. Ignores the "state" of connection; treats each packet in isolation without considering previous packets. Only inspects the IP Header, not the payload. Very lightweight (not resource-intensive) but easy to bypass.
Access Control List (ACL)
قائمة التحكم في الوصول
يُطبق قائمة من القواعد (ACL) لمعرفة ما يمكنه الدخول أو الخروج. يعتمد على سياسات افتراضية إما: Discard (أكثر أماناً) أو Forward (أسهل إدارةً).
Applies rules defined in an ACL. Two default policies: Discard (prohibit unless permitted) or Forward (permit unless prohibited).
مثال على Access Control List (Type 2)ACL Example - What can enter and leave
الإذن Permission IP المصدر IP Source IP الوجهة IP Destination البروتوكول Protocol المنفذ Port
ALLOW162.213.214.1410.10.10.25TCP110
ALLOW192.168.x.x10.10.10.29TCP125
DENY65.252.1.2ANYHTTP80
DENYANY10.10.10.6UDP23
ALLOW10.10.x.xANYTCP80
Type 3: جدران فحص الحالة (Stateful Inspection) Type 3: Stateful Firewalls §7
تعمل على طبقتين: طبقة الشبكة (Network) وطبقة النقل (Transport). تفحص الحزم وتتأكد من صحة TCP Handshake. تحتفظ بـ "جدول الحالة" (State Table) لتسجيل الاتصالات النشطة ومتابعة تطورها. تستهلك موارد أكثر (Resource-intensive) لأنها تقارن كل حزمة بالقواعد وبجدول الحالة معاً.
Works on Network & Transport layers. Inspects packets and verifies TCP handshakes. Maintains a "State Table" containing info on all active connections to determine if a packet is new, part of an existing session, or invalid. Resource-intensive since packets are compared against rules AND the state table.
ملاحظة هامة: جدار الحماية ذو الحالة يعتمد على "دلالات الاتصال" (Connection Semantics) مثل حالات TCP. لكن وجود جلسة TCP صالحة لا يعني بالضرورة أن الجلسة آمنة (لا يفحص النوايا الخبيثة).
Important Note: Stateful firewalls rely on connection semantics (e.g., TCP states), not on identifying malicious intent. A valid TCP session does not imply a secure or benign session.
جدول الحالة (Connection State Table) وتحليل الحالات Connection State Table & State Analysis §8
جوهر عمل الجدار: يُتيح مرور حركة الردود الواردة (Inbound) فقط إذا كانت استجابة لاتصال تم بدءه من داخل الشبكة الداخلية (Outbound initiated).
Core Logic: Stateful firewalls allow outbound initiated connections, and allow return inbound traffic ONLY if it matches an existing entry in the state table.
IP المصدرIP Source منفذ المصدرSrc Port IP الوجهةIP Dest منفذ الوجهةDest Port البروتوكولProtocol حالة الاتصالConnection State المهلةTimeout
162.213.214.14231510.10.10.2580TCPEstablished3600s
192.168.x.x561310.10.10.29443TCPSYN Sent60s
65.252.1.256510.10.10.5922TCPEstablished7200s
10.10.x.x8010.10.10.231256TCPSYN Received60s
1
SYN Sent (اتصال صادر قيد الانتظار)
SYN Sent (Pending Outbound)
يُشير لعميل داخلي (Private IP) يحاول الاتصال بخادم خارجي. المهلة قصيرة (60s) لانتظار الرد. قد يكون تصفحاً عادياً أو فحصاً للمنافذ (Port Scanning) إذا كان متكرراً.
Internal host initiated a connection but hasn't completed it yet. Timeout is short (60s). Could be normal browsing or scanning behavior.
2
SYN Received (طلب وارد)
SYN Received (Incoming Request)
الجدار الناري رصد طلب SYN قادم من الخارج. قد يكون طلباً شرعياً لخدمة أو محاولة مشبوهة (Attack surface exposure).
Firewall saw an incoming SYN to an internal host. Could be legitimate (server exposed) or suspicious/reconnaissance.
3
Established (اتصال مُكتمل)
Established (Active Session)
تم إكمال Handshake. يُسمح للحركة في الاتجاهين. المهلة طويلة (3600-7200s) لأنها جلسات نشطة لا يجب مقاطعتها.
Full TCP handshake completed. Traffic allowed bidirectionally. Long timeouts applied so active sessions are not interrupted.
مقارنة شاملة: Stateful مقابل Stateless Stateful vs Stateless Firewalls §9
الميزةFeatureStateless (غير معتمد على الحالة)Stateful (معتمد على الحالة)
السياق / Contextلا يحتفظ بأي سجل. يحلل كل حزمة منفردة.No context. Evaluates each packet individually.يحتفظ بسجل الاتصالات (Tracks sessions).Maintains records of active connections.
أساس القرار / DecisionPacket only (Headers & Rules)Packet + Connection State
مستوى الأمان / Securityأمان أساسي / Basicأمان محسّن / Enhanced
استهلاك الموارد / Resourcesخفيف، لا يسبب تأخير (Lightweight)Minimal impact on performance.كثيف، قد يسبب بطئاً (Resource intensive)May introduce latency.
الثغرات / VulnerabilitySpoofingState exhaustion attacks
Type 4: بوابات مستوى التطبيق (البروكسي) Type 4: Application-Level Gateway (Proxy Firewalls) §10
يعمل كوسيط (Relay) لحركة مستوى التطبيق. يفهم التطبيقات والبروتوكولات، ويقوم بـ فحص عميق للحزم (Deep Packet Inspection) لمحتوياتها وحظر المحتوى غير اللائق أو الفيروسات. يتميز بأنه أكثر أماناً من فلاتر الحزم، لكنه يستهلك موارد أعلى ويُبطئ الاتصال (More overhead).
Acts as a relay for application-level traffic. "Understands" applications and performs Deep Packet Inspection on payload contents to block inappropriate content/viruses. More secure than packet filters, but introduces more overhead and slows down communication.
How Proxy Works (Inbound & Outbound)
User
Two Separate Connections
Remote Server
Contact Proxy
User Authenticates to Gateway →
Gateway / Proxy
Gateway checks rules
Gateway Relays TCP segments →
Server
Type 5: الجدران متعددة الطبقات المعتمدة على الحالة Type 5: Stateful Multilayer Firewalls §11
يجمع هذا النوع ميزات جميع الجدران السابقة ليُفلتر الحركة على ثلاث طبقات: الشبكة (Packet Filtering)، النقل (مشروعية الجلسة)، والتطبيق (تقييم المحتوى).
Combines aspects of other types to filter traffic at three levels: Network Layer (Packet Filtering), Transport Layer (Session legitimacy), and Application Layer (evaluate payload contents).
نشر الجدران النارية وأوجه القصور (Limitations) Firewall Deployment & Limitations §12
Software Firewalls
جدران برمجية
على أجهزة اللابتوب والخوادم. توفر "دفاعاً في العمق" بعزل الأجهزة.
On laptops, desktops, servers. Provides defense in depth by isolating devices.
Cloud Firewalls
جدران سحابية
تُقدم كخدمة (FaaS) لحماية تطبيقات السحابة.
Provided as Firewall as a Service (FaaS) to protect cloud apps.
⚠ أوجه قصور الجدران النارية: الجدران النارية ليست حلاً كاملاً لكل المشاكل. لا يمكنها الحماية ضد:
• الهجمات التي تتجاوزها عبر خدمات موثوقة (مثل TLS/SSH).
• التهديدات الداخلية (الموظفين المتآمرين).
• الفيروسات المنقولة عبر فلاشات USB أو أجهزة مصابة خارجياً.
• هجمات طبقة التطبيقات المشفرة (لا يحلل HTTPS بدون فك التشفير).
النتيجة: هذه القصور تفرض ضرورة استخدام أنظمة كشف التسلل (IDS) كآلية أمان مُكملة!
⚠ Firewall Limitations: Firewalls cannot protect against: Bypassed attacks via trusted services, internal threats, transfer of virus-infected files imported locally, or app-layer attacks encrypted in HTTPS (without decryption). This necessitates the use of IDS!
ما هو IDS؟ ولماذا نحتاجه مع الجدار الناري؟ What is IDS? Definitions & Motivation §13
التسلل (Intrusion): أفعال تهدف لخرق النزاهة والسرية والتوفر. نظام كشف التسلل (IDS): عملية تحديد والاستجابة لهذه الأنشطة. يراقب الأنظمة ويحلل حركة الشبكة لاكتشاف الهجمات الجارية. يعطي رؤية للهجمات التي تستخدم منافذ مسموحة (مثل HTTPS) وتتجاوز الجدار الناري التقليدي.
Intrusion: Actions compromising integrity, confidentiality, or availability. IDS: Identifying and responding to intrusion activities. Monitors/analyzes traffic to detect attacks in progress. Provides visibility into attacks that use allowed ports (e.g., HTTPS) and bypass firewall controls.
Host-Based (HIDS)
مبني على المضيف
يُركّب على عقدة / جهاز واحد لمراقبته بشكل فردي.
Installed on and protects a single node/device.
منهجيات التحليل والاكتشاف في IDS IDS Analysis Approaches (Methods of Detection) §14
Signature / Heuristic Detection
المعتمد على التوقيع (Signature)
يعرف السلوك الخبيث مباشرة. يبحث في الحزم عن "بصمات" أو أنماط الهجمات المعروفة مسبقاً (Signatures).
• سريع وفعال جداً في الهجمات المعروفة.
العيب: لا يمكنه اكتشاف الهجمات الجديدة (Zero-day attacks).
Directly defines malicious behavior using known attack patterns (signatures). Checks packets for specific footprints.
• Quick/efficient for known attacks.
Con: Cannot detect unknown or Zero-day attacks.
Anomaly Detection
المعتمد على الشذوذ (Anomaly)
يبني "خط أساس" (Baseline) للسلوك الطبيعي للمستخدمين والشبكة. إذا انحرف السلوك فجأة (مثل الدخول 3 فجراً بدلاً من 9 صباحاً)، يُصدر تنبيهاً.
الميزة: يكتشف هجمات Zero-day غير المعروفة.
العيب: كثرة الإنذارات الكاذبة (False positives) للسلوك الشرعي.
Aims to define normal expected behavior baseline. Any deviation triggers an alert (e.g. logging in at 3am instead of 9am).
Pro: Can detect unknown/Zero-day attacks.
Con: High false alarm rate (False positives).
نظام IDS الهجين (Hybrid): يدمج بين التوقيع والشذوذ لتحسين دقة الاكتشاف. كما يُقيّم IDS رياضياً بناءً على:
معدل الاكتشاف (Detection Rate): (Attacks Detected / Total Attacks) ويجب أن يكون مرتفعاً للتأكد من فاعلية النظام.
معدل الإنذار الكاذب (False Alarm Rate): (Incorrect Classifications / Total Normal Usage) ويجب تقليله إلى أدنى حد ممكن لتجنب الإزعاج.
Hybrid IDS: Combines both approaches to improve accuracy. IDS is evaluated by:
Detection Rate: (Attacks Detected / Total Attacks) which should be high.
False Alarm Rate: (Incorrect Classifications / Total Normal Usage) which should be minimized.
الجدار الناري مقابل IDS (الخلاصة) Firewall vs IDS Comparison §15
الميزةFeatureالجدار الناري Firewallنظام كشف التسلل IDS
الهدف Primary Goalمنع الوصول غير المصرح بهPrevent unauthorized accessاكتشاف الأنشطة المشبوهةDetect suspicious activity
الإجراء Actionالسماح / الحظر (Block)Allow / Block trafficإصدار تنبيه وتوثيق (Alert / Log)Alert / Log (does not block traffic by default)
التركيز FocusPolicy enforcementAttack detection
المنطق LogicPredefined RulesBehavior / Signatures
مثال ExampleBlock port 23 (Telnet)Alert on port scanning behavior