Malware Analysis - Lecture 3: Static Malware Analysis
This lecture introduces the fundamental concepts of static malware analysis, which is the first step in understanding malicious software.
هذه المحاضرة تقدم المفاهيم الأساسية لتحليل البرمجيات الخبيثة الثابتة، وهي الخطوة الأولى في فهم البرامج الضارة. Static Malware Analysis هو عملية تحليل البرمجيات الخبيثة دون تشغيلها.
Static Analysis - Definition and Objectives
The Objective:
To extract useful information from the malware: What can we learn about a piece of malware without executing it?
What Static Malware Analysis Helps Us Understand:
- The type of malware we are dealing with - Virus, worm, trojan, ransomware, spyware, downloader, dropper, etc.
- What the malware can do - Its capabilities and potential impact
Static analysis هو تحليل البرمجيات الخبيثة دون تشغيلها. الهدف الرئيسي هو استخراج معلومات مفيدة عن البرنامج الضار. يساعدنا هذا التحليل في فهم:
- نوع البرنامج الضار: فيروس (virus)، دودة (worm)، حصان طروادة (trojan)، برامج الفدية (ransomware)، برامج التجسس (spyware)، برامج التحميل (downloader)، برامج التنزيل والتثبيت (dropper)
- ما يمكن أن يفعله البرنامج الضار - قدراته وتأثيره المحتمل
Static Malware Analysis - Detailed Capabilities
What type of malware is this?
- Virus
- Worm
- Trojan
- Ransomware
- Spyware
- Downloader
- Dropper
What is its intended behavior?
- File modification - Creating, deleting, or modifying files
- Persistence mechanisms - How it stays on the system after reboot
- Credential theft - Stealing usernames and passwords
- Network communication - Connecting to C2 servers
- Payload delivery - Downloading additional malware
What capabilities does the malware have?
- Uses networking APIs? - Check for network-related functions
- Interacts with the registry or file system? - Persistence and configuration
- Performs privilege escalation or process injection? - Advanced hiding techniques
Static analysis يساعدنا في تحديد:
نوع الملف الضار:
- Virus (فيروس): برنامج ينسخ نفسه ويلحق بملفات أخرى
- Worm (دودة): ينتشر عبر الشبكات دون تدخل المستخدم
- Trojan (حصان طروادة): يتنكر كبرنامج شرعي
- Ransomware (فدية): يشفر الملفات ويطلب فدية
- Spyware (تجسس): يراقب نشاط المستخدم
- Downloader: يقوم بتحميل برامج ضارة أخرى
- Dropper: يقوم بتثبيت برامج ضارة أخرى
السلوك المتوقع:
- File modification: تعديل الملفات (إنشاء، حذف، تعديل)
- Persistence: آليات البقاء في النظام بعد إعادة التشغيل
- Credential theft: سرقة أسماء المستخدمين وكلمات المرور
- Network communication: الاتصال بخوادم التحكم (C2 servers)
Internal Structure and Malware Classification
How is it structured internally?
- File format - PE (Windows Executable), ELF (Linux), script, etc.
- Sections, headers, imports, strings - Internal organization
- Packing or obfuscation techniques - Hidden or compressed code
Is it suspicious or malicious, and why?
- Known malicious signatures - Matches known malware patterns
- Suspicious strings or API imports - Indicators of malicious intent
- Indicators of Compromise (IOCs) - Evidence of infection
Is it related to known malware families?
- Code reuse - Similar code patterns
- Similar structure or artifacts - Common characteristics
- Matching hashes or patterns - Digital fingerprints
الهيكل الداخلي للملف:
- File format: تنسيق الملف مثل PE لويندوز أو ELF للينكس
- Sections: أقسام الملف مثل .text للكود و .data للبيانات
- Packing: تقنيات ضغط أو تشفير الكود لإخفائه
مؤشرات الخبث:
- Signatures: تواقيع ضارة معروفة
- IOCs (Indicators of Compromise): مؤشرات الاختراق
- API imports: دوال برمجية مشبوهة
الانتماء لعائلات معروفة:
- Code reuse: إعادة استخدام كود من برمجيات خبيثة سابقة
- Matching hashes: تطابق في البصمة الرقمية
Static Analysis Flow - Step 1: File Type Identification
1. Identify the File Type:
Determine what kind of file you are dealing with.
Questions to answer:
- What is the target operating system? - Windows, Linux, Android, etc.
- What is the architecture? - 32-bit, 64-bit, ARM, etc.
- What is the format? - .exe, .dll, .apk, .elf
الخطوة الأولى: تحديد نوع الملف
يجب أن نعرف نوع الملف الذي نتعامل معه لأن الأدوات والتقنيات تختلف حسب نظام التشغيل والمعمارية.
الأسئلة التي يجب الإجابة عليها:
- ما هو نظام التشغيل المستهدف؟ (Windows, Linux, Android)
- ما هي المعمارية؟ (32-bit, 64-bit, ARM)
- ما هو تنسيق الملف؟ (.exe, .dll, .apk, .elf)
Step 2: Generate a Unique Identifier (Hashing)
Compute hashes such as MD5, SHA-1, or SHA-256.
Purpose:
- A hash acts as a fingerprint for the malware - Unique identifier
- Check if the sample has already been analyzed by others - Using online databases
Tools/Platforms:
- VirusTotal - Multi-antivirus scanner
- Hybrid Analysis - Advanced analysis platform
- MalwareBazaar - Malware repository
الخطوة الثانية: توليد معرف فريد (هاش)
نقوم بحساب الهاشات مثل MD5 أو SHA-1 أو SHA-256.
الغرض:
- الهاش يعمل كبصمة أصبع للبرنامج الضار - معرف فريد
- التحقق مما إذا كانت العينة قد تم تحليلها بالفعل من قبل الآخرين باستخدام قواعد البيانات عبر الإنترنت
الأدوات والمنصات:
- VirusTotal: فحص متعدد لمضادات الفيروسات
- Hybrid Analysis: منصة تحليل متقدمة
- MalwareBazaar: مستودع للبرامج الضارة
Step 3: Analyze Embedded Strings
Extract human-readable text from the binary.
Why? Strings may reveal:
- IP addresses, URLs, domains - Network indicators
- Registry keys, file paths - System interaction points
- API function names or commands - Program functionality
الخطوة الثالثة: تحليل النصوص المضمنة
String هو سلسلة من الأحرف في البرنامج. البرنامج يحتوي على نصوص إذا كان يطبع رسالة، أو يتصل بموقع، أو ينسخ ملف إلى موقع محدد.
لماذا نقوم بتحليل النصوص؟
- عناوين IP، URLs، domains - مؤشرات الشبكة
- مفاتيح الريجستري (registry keys)، مسارات الملفات (file paths)
- أسماء دوال API أو أوامر - وظائف البرنامج
ما نبحث عنه: أسماء الملفات، عناوين URL، عناوين IP، مفاتيح الريجستري، رسائل الخطأ، سلاسل الأوامر
Step 4: Check for Packing & Obfuscation
Indicators of Packing:
- Very few readable strings - Most text is compressed/encrypted
- Suspicious section names in headers - Unusual section names
- Unusually high entropy (randomness) - Indicates compressed/encrypted data
What to do if packed:
Try unpacking or using automated unpackers to reveal original content.
الخطوة الرابعة: التحقق من التعبئة والتشويش
غالباً ما يستخدم مؤلفو البرامج الضارة packers (أدوات التعبئة) أو obfuscators (أدوات التشويش) لإخفاء الكود الحقيقي.
مؤشرات التعبئة:
- القليل جداً من النصوص المقروءة - معظم النصوص مضغوطة/مش
- أسماء أقسام مشبوهة في الترويسات
- Entropy عالية بشكل غير طبيعي (عشوائية) - تشير إلى بيانات مضغوطة/مشفرة
ماذا نفعل إذا كان الملف مضغوطاً؟
نحاول فك الضغط أو استخدام أدوات فك ضغط أوتوماتيكية للكشف عن المحتوى الأصلي.
Entropy العادية: 4-6، المضغوطة/المشفرة: 6-8
Step 5: Inspect PE Headers (Windows Executables)
The PE header contains critical information:
- Import Address Table (IAT): Which Windows APIs are used (networking, file system, registry)
- Export Table: Functions exposed by DLLs
- Section headers: .text, .data, .rdata, suspicious or custom sections
- Entry point: Where execution begins
This can reveal the functionality of the malware before execution.
الخطوة الخامسة: فحص ترويسات PE (ملفات ويندوز التنفيذية)
PE file هو تنسيق الملفات التنفيذية المحمولة المستخدم في ويندوز للملفات التنفيذية (.exe) والمكتبات الديناميكية (.dll) وملفات النظام (.sys).
تحتوي ترويسة PE على معلومات حاسمة:
- Import Address Table (IAT): جدول عناوين الاستيراد - يوضح أي APIs من ويندوز يتم استخدامها
- Export Table: جدول التصدير - الدوال التي تصدرها الـ DLLs
- Section headers: ترويسات الأقسام مثل .text (الكود)، .data (البيانات)
- Entry point: نقطة الدخول - أين يبدأ التنفيذ
هذا يمكن أن يكشف وظائف البرنامج الضار قبل التنفيذ.
Step 1 Details: Identifying the File Type
Why it is important?
We must know what kind of file we are dealing with, because the tools and techniques differ depending on the operating system, architecture, and format.
What to identify:
- Target Operating System - Windows, Linux, Android, macOS, etc.
- Target Architecture - x86, x64, ARM, MIPS, etc.
- File format - EXE, DLL, APK, ELF, Mach-O, script, document, etc.
Methods:
- CLI tools - 'file' command on Linux/Unix
- PEiD / Detect It Easy (DIE) - Specialized tools
- Hex editors - Check magic numbers (e.g., MZ for Windows PE files)
الخطوة الأولى بالتفصيل: تحديد نوع الملف
لماذا هو مهم؟
يجب أن نعرف نوع الملف الذي نتعامل معه، لأن الأدوات والتقنيات تختلف حسب نظام التشغيل والمعمارية والتنسيق.
ماذا نحدد؟
- نظام التشغيل المستهدف: ويندوز، لينكس، أندرويد، ماك
- المعمارية المستهدفة: x86, x64, ARM, MIPS
- تنسيق الملف: EXE, DLL, APK, ELF, Mach-O، سكريبت، مستند
الطرق:
- أدوات سطر الأوامر: أمر file في لينكس
- أدوات متخصصة: PEiD أو Detect It Easy (DIE)
- Hex editors: فحص الأرقام السحرية (magic numbers) مثل MZ لملفات ويندوز
Common Executable Files - Detailed Table
| File Type | Extension(s) | Target OS / Platform | Magic Number (Hex) | Notes / Malware Usage |
|---|---|---|---|---|
| Windows Executable | .exe | Windows | MZ (0x4D 0x5A) | Standard program executable. Most common malware format on Windows. |
| Windows Dynamic Library | .dll | Windows | MZ (same as EXE) | Shared library. Malware may load malicious DLLs into trusted processes ("DLL injection"). |
| Portable Executable (PE) | .exe, .dll, .sys | Windows | MZ → later "PE\0\0" in header | Umbrella format for executables, drivers, and libraries on Windows. |
| Linux Executable (ELF) | no fixed ext. (.elf, binaries) | Linux / Unix | 7F 45 4C 46 (.ELF) | Used in Linux malware, IoT devices, servers. |
| Android Package | .apk | Android | Zip archive magic: 50 4B 03 04 | Contains compiled Java code (.dex), manifest, resources. Common for Android malware. |
| macOS Executable (Mach-O) | .app, .dmg | macOS | FE ED FA CE or CA FE BA BE | Used in Mac malware (adware, trojans). |
الملفات التنفيذية الشائعة - جدول مفصل
الملفات التنفيذية لها تواقيع سحرية (magic numbers) تميزها:
- Windows Executable (.exe): يبدأ بـ MZ (4D 5A)
- Windows DLL (.dll): نفس توقيع EXE (MZ)
- Linux ELF: يبدأ بـ 7F 45 4C 46
- Android APK: يبدأ بتوقيع ZIP (50 4B 03 04)
- macOS Mach-O: يبدأ بـ FE ED FA CE أو CA FE BA BE
File Type Identification - Visual Examples
This page shows hexadecimal representations of different file types.
4D 5A 90 00 03 00 00 00 04 00 00 00 FF FF 00 00
B8 00 00 00 00 00 00 00 40 00 00 00 00 00 00 00
أمثلة مرئية لتحديد نوع الملف
عند فتح ملف في محرر سداسي عشري (hex editor):
- ملف Windows PE: يبدأ بـ 4D 5A (MZ)
- ملف ELF (لينكس): يبدأ بـ 7F 45 4C 46
- ملف PDF: يبدأ بـ 25 50 44 46 (%PDF)
File Type Identification - Continued
Magic Numbers - Quick Reference:
- Windows PE (EXE/DLL): 4D 5A (MZ)
- Linux ELF: 7F 45 4C 46
- Android APK (ZIP): 50 4B 03 04
- macOS Mach-O: FE ED FA CE or CA FE BA BE
- PDF Document: 25 50 44 46
- JPEG Image: FF D8 FF
الأرقام السحرية - مرجع سريع
- ويندوز: 4D 5A (MZ)
- لينكس: 7F 45 4C 46
- أندرويد: 50 4B 03 04
- ماك: FE ED FA CE
- PDF: 25 50 44 46
- JPEG: FF D8 FF
File Type Identification - Important Notes
Example: malware.exe → renamed to document.pdf
Analyst Best Practice:
Always check the file header, not just the name.
Example: Windows EXE in a Hex Editor
Open suspicious file with a hex editor (e.g., HxD on Windows).
The first two bytes should be: 4D 5A
مفهوم حاسم: البرامج الضارة تخفي نفسها بتغيير الامتداد
مثال: malware.exe يتم تغيير اسمه إلى document.pdf
أفضل ممارسة للمحلل: دائماً افحص ترويسة الملف (file header)، وليس الاسم فقط.
مثال: ملف Windows EXE في محرر سداسي عشري
افتح الملف المشبوه بمحرر سداسي عشري (مثل HxD على ويندوز).
أول بايتين يجب أن يكونا: 4D 5A
Visual Hex Dump Example
This page shows a visual representation of hex dump analysis.
00000010: B8 00 00 00 00 00 00 00 40 00 00 00 00 00 00 00 ........@.......
00000020: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000030: 00 00 00 00 00 00 00 00 00 00 00 00 80 00 00 00 ................
The 'MZ' at the beginning clearly identifies this as a Windows executable.
مثال على عرض سداسي عشري
هذه الصفحة تظهر تمثيلاً بصرياً لتحليل التفريغ السداسي العشري.
ظهور MZ في البداية يحدد بوضوح أن هذا ملف ويندوز تنفيذي.
Step 2: Malware Hashing - Detailed Explanation
Why We Use Hashing:
- Use the hash as a label
- Share that hash with other analysts to help them identify malware
- Hashes are used to identify malware on malware analysis sites (VirusTotal)
- Search for that hash online to see if the file has already been identified
Hash Algorithms:
- MD5 - 128-bit hash (32 characters) - Fast but cryptographically broken
- SHA-1 - 160-bit hash (40 characters) - Also considered weak
- SHA-256 - 256-bit hash (64 characters) - Currently recommended
الخطوة الثانية: الهاش - شرح مفصل
لماذا نستخدم الهاش؟
- نستخدم الهاش كتسمية (label) للملف
- نشارك الهاش مع محللين آخرين لمساعدتهم في تحديد البرامج الضارة
- الهاش يستخدم لتحديد البرامج الضارة على مواقع تحليل البرامج الضارة (مثل VirusTotal)
- نبحث عن الهاش عبر الإنترنت لمعرفة ما إذا تم التعرف على الملف بالفعل
خوارزميات الهاش:
- MD5: هاش 128-بت (32 حرف) - سريع ولكن غير آمن
- SHA-1: هاش 160-بت (40 حرف) - أيضاً ضعيف
- SHA-256: هاش 256-بت (64 حرف) - موصى به حالياً
Malware Hashing - Tools and Examples
Tools for hashing:
- HashMyFiles - Lightweight Windows utility (shows MD5, SHA1, SHA256)
- HashCalc - Windows tool, supports multiple hash algorithms
- Command line - certutil -hashfile (Windows), sha256sum (Linux)
Example:
- File: malware.exe
- SHA-256: d2c7f2c5e0f0b8a7d3c3...
أدوات الهاش وأمثلة
أدوات الهاش:
- HashMyFiles: أداة ويندوز خفيفة تظهر MD5، SHA1، SHA256
- HashCalc: أداة ويندوز تدعم خوارزميات هاش متعددة
- سطر الأوامر: certutil -hashfile في ويندوز، sha256sum في لينكس
مثال:
- الملف: malware.exe
- SHA-256: d2c7f2c5e0f0b8a7d3c3...
Malware Hashing - Visual Examples
These pages show visual representations of hash values and how they appear in tools.
SHA-1: da39a3ee5e6b4b0d3255bfef95601890afd80709
SHA-256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
أمثلة بصرية للهاش
هذه الصفحات تظهر تمثيلات بصرية لقيم الهاش وكيف تظهر في الأدوات.
MD5 ينتج 32 حرفاً سداسياً عشرياً
SHA-1 ينتج 40 حرفاً
SHA-256 ينتج 64 حرفاً
Step 3: Extracting Strings - Detailed Explanation
A string in a program is a sequence of characters.
A program contains strings if it prints a message, connects to a URL, or copies a file to a specific location.
Is the process of extracting readable characters and words from the malware.
الخطوة الثالثة: استخراج النصوص - شرح مفصل
ما هي الـ String؟
الـ string هو سلسلة من الأحرف في البرنامج.
البرنامج يحتوي على نصوص إذا كان يطبع رسالة، أو يتصل بموقع، أو ينسخ ملف إلى موقع محدد.
ما هو تحليل النصوص؟
هو عملية استخراج الأحرف والكلمات القابلة للقراءة من البرنامج الضار.
Why We Do String Analysis
Why we do String analysis?
- Searching through the strings can be a simple way to get hints about the functionality of a program
- Example: if the program accesses a URL, then you will see the URL accessed stored as a string in the program
- Malware can have useful strings and random strings known as Garbage strings
- Strings are in ASCII and Unicode format
لماذا نقوم بتحليل النصوص؟
- البحث في النصوص يمكن أن يكون طريقة بسيطة للحصول على تلميحات حول وظائف البرنامج
- مثال: إذا كان البرنامج يصل إلى URL، فسترى الـ URL مخزناً كنص في البرنامج
- البرامج الضارة قد تحتوي على نصوص مفيدة ونصوص عشوائية تسمى Garbage strings
- النصوص تكون بصيغة ASCII أو Unicode
ASCII Format
What is ASCII and Unicode?
Both ASCII and Unicode formats store characters in sequences that end with a NULL terminator to indicate that the string is complete.
ASCII:
- 1 byte per character
- Example: "BAD" = 0x42 0x41 0x44 0x00
تنسيق ASCII
صيغتا ASCII و Unicode تخزنان الأحرف في تسلسلات تنتهي بـ NULL terminator للإشارة إلى اكتمال النص.
ASCII:
- 1 بايت لكل حرف
- مثال: "BAD" = 0x42 0x41 0x44 0x00
Unicode Format
Unicode:
- 2 Bytes per Character
- Example: "BAD" = 0x42 0x00 0x41 0x00 0x44 0x00 0x00 0x00
Note: Windows often uses UTF-16 (2-byte Unicode) internally.
تنسيق Unicode
Unicode:
- 2 بايت لكل حرف
- مثال: "BAD" = 0x42 0x00 0x41 0x00 0x44 0x00 0x00 0x00
ملاحظة: ويندوز غالباً ما يستخدم UTF-16 داخلياً.
Types of Strings We Look For
The types of strings we are looking for are:
- File names - e.g., config files, system files
- URL's (Domains the malware connects to) - C2 servers
- IP Addresses - Direct connections
- Registry Keys - Persistence locations
"http://malicious.com/panel.php"
"SOFTWARE\Microsoft\Windows\CurrentVersion\Run"
"192.168.1.100"
"C:\Windows\System32\config\"
أنواع النصوص التي نبحث عنها
- أسماء الملفات: مثل ملفات الإعدادات، ملفات النظام
- عناوين URL (الدومينات التي يتصل بها البرنامج الضار): خوادم التحكم C2
- عناوين IP: اتصالات مباشرة
- مفاتيح الريجستري: مواقع الاستمرارية
أمثلة على نصوص مشبوهة:
"http://malicious.com/panel.php"
"SOFTWARE\Microsoft\Windows\CurrentVersion\Run"
"192.168.1.100"
Windows Registry - Detailed Explanation
The Windows Registry is a big database that stores settings and configurations.
Think of it as the control center of Windows.
Organized in a tree structure with "keys" and "values".
Example Keys:
- HKCU = HKey Current User (settings only for logged-in user)
- HKLM = HKey Local Machine (settings for the whole computer)
Why Malware Loves the Registry:
Malware adds entries to:
- Run at startup → HKCU\Software\Microsoft\Windows\CurrentVersion\Run
- Hide itself in services → HKLM\System\CurrentControlSet\Services
ما هو Windows Registry؟
Windows Registry هو قاعدة بيانات كبيرة تخزن الإعدادات والتكوينات.
فكر فيه كمركز التحكم في ويندوز.
منظم في هيكل شجري مع "مفاتيح" (keys) و"قيم" (values).
أمثلة على المفاتيح:
- HKCU = HKey Current User (إعدادات المستخدم الحالي فقط)
- HKLM = HKey Local Machine (إعدادات الكمبيوتر بالكامل)
لماذا تحب البرامج الضارة الريجستري؟
البرامج الضارة تضيف إدخالات لـ:
- التشغيل عند بدء التشغيل → HKCU\Software\Microsoft\Windows\CurrentVersion\Run
- إخفاء نفسها في الخدمات → HKLM\System\CurrentControlSet\Services
What Strings Could Reveal - Part 1
1. Strange Text Messages:
- What they are: Hidden "markers" or "flags" inside malware code
- Why malware uses them:
- Debugging messages left by the author
- Internal codes to track progress ("did installation succeed?", "did antivirus get killed?")
Examples:
- "LOADER_OK" means malware loader installed correctly
- "KILL_AV" command to disable antivirus
- "UPLOAD_SUCCESS" stolen data was uploaded to attacker's server
ماذا يمكن أن تكشف النصوص - الجزء الأول
1. رسائل نصية غريبة:
- ما هي: "علامات" أو "أعلام" مخفية داخل كود البرنامج الضار
- لماذا تستخدمها البرامج الضارة:
- رسائل تصحيح أخطاء تركها المؤلف
- أكواد داخلية لتتبع التقدم ("هل نجح التثبيت؟"، "هل تم تعطيل مكافح الفيروسات؟")
أمثلة:
- "LOADER_OK" يعني أن محمل البرنامج الضار تم تثبيته بشكل صحيح
- "KILL_AV" أمر لتعطيل مكافح الفيروسات
- "UPLOAD_SUCCESS" تم تحميل البيانات المسروقة إلى خادم المهاجم
What Strings Could Reveal - Part 2 (Registry)
2. Registries:
- What they are: Settings stored in the Windows Registry (a big configuration database)
- Why malware uses them:
- To achieve persistence (run again after reboot)
- To disable security tools
Example:
HKCU\Software\Microsoft\Windows\CurrentVersion\Run
Any program listed here runs every time Windows starts.
Malware often puts its own file here to make sure it never dies.
ماذا يمكن أن تكشف النصوص - الجزء الثاني (الريجستري)
2. الريجستري:
- ما هي: إعدادات مخزنة في Windows Registry
- لماذا تستخدمها البرامج الضارة:
- لتحقيق الاستمرارية (persistence) - التشغيل مرة أخرى بعد إعادة التشغيل
- لتعطيل أدوات الأمان
مثال:
HKCU\Software\Microsoft\Windows\CurrentVersion\Run
أي برنامج مدرج هنا يتم تشغيله في كل مرة يبدأ فيها ويندوز.
البرامج الضارة غالباً ما تضع ملفها الخاص هنا لتضمن أنها لا تموت أبداً.
What Strings Could Reveal - Part 3 (IP Addresses)
3. IP Addresses
- What they are: Direct network addresses like 123.45.67.89
- Why malware uses them:
- If defenders block a malicious domain, malware can connect directly to an IP
- Often found in botnets and trojans
Example:
185.14.29.66 could be a server in another country that the malware uses.
Hardcoded IPs in a program are suspicious (most normal software uses domain names).
ماذا يمكن أن تكشف النصوص - الجزء الثالث (عناوين IP)
3. عناوين IP
- ما هي: عناوين شبكة مباشرة مثل 123.45.67.89
- لماذا تستخدمها البرامج الضارة:
- إذا قام المدافعون بحظر نطاق ضار، يمكن للبرنامج الضار الاتصال مباشرة بعنوان IP
- غالباً ما توجد في botnets وأحصنة طروادة
مثال:
185.14.29.66 يمكن أن يكون خادماً في بلد آخر يستخدمه البرنامج الضار.
عناوين IP المضمنة (hardcoded) في البرنامج مشبوهة (معظم البرامج العادية تستخدم أسماء النطاقات).
Common Libraries - kernel32.dll
Common Libraries & Functions Used by Malware
kernel32.dll - Core System Control
File handling, process creation, memory management
Common functions:
| Function | Description | Malicious Use |
|---|---|---|
| CreateFile | Creates or opens files | Creating malicious files, opening system files |
| WriteFile | Writes data to disk | Writing payloads, logging stolen data |
| DeleteFile | Removes files | Deleting evidence, removing competing malware |
| CreateProcess | Launches another program | Process injection, launching payloads |
| LoadLibrary | Loads a DLL at runtime | Dynamic loading of malicious DLLs |
| GetProcAddress | Locates a function inside a DLL | Resolving API addresses dynamically |
المكتبات الشائعة - kernel32.dll
kernel32.dll - التحكم الأساسي في النظام: معالجة الملفات، إنشاء العمليات، إدارة الذاكرة
الدوال الشائعة والاستخدام الضار:
- CreateFile: إنشاء أو فتح ملفات - لإنشاء ملفات ضارة
- WriteFile: كتابة بيانات على القرص - لكتابة الحمولات الضارة
- DeleteFile: حذف الملفات - لإزالة الأدلة
- CreateProcess: تشغيل برنامج آخر - لحقن العمليات
- LoadLibrary: تحميل DLL في وقت التشغيل - لتحميل مكتبات ضارة
- GetProcAddress: تحديد موقع دالة داخل DLL - للوصول إلى APIs بشكل ديناميكي
Common Libraries - ws2_32.dll and advapi32.dll
ws2_32.dll — Network Communication
Internet and network access
Common functions:
| Function | Description |
|---|---|
| socket | Creates a network connection |
| connect | Connects to a remote server |
| send / recv | Sends or receives data |
advapi32.dll — Registry & Security
Registry access and privilege control
Common functions:
| Function | Description |
|---|---|
| RegOpenKey | Opens a registry key |
| RegSetValue | Adds or modifies registry data |
| AdjustTokenPrivileges | Changes access privileges |
المكتبات الشائعة - ws2_32.dll و advapi32.dll
ws2_32.dll — اتصالات الشبكة:
- socket: إنشاء اتصال شبكة
- connect: الاتصال بخادم بعيد
- send/recv: إرسال أو استقبال البيانات
advapi32.dll — الريجستري والأمان:
- RegOpenKey: فتح مفتاح في الريجستري
- RegSetValue: إضافة أو تعديل بيانات في الريجستري
- AdjustTokenPrivileges: تغيير صلاحيات الوصول
Common Libraries - user32.dll
user32.dll - User Interaction
Keyboard, mouse, windows
Common functions:
| Function | Description | Malicious Use |
|---|---|---|
| GetAsyncKeyState | Reads keyboard input | Keylogging |
| FindWindow | Checks running applications | Detecting security tools, avoiding sandboxes |
| MessageBox | Displays fake messages | Social engineering, fake alerts |
المكتبات الشائعة - user32.dll
user32.dll - تفاعل المستخدم: لوحة المفاتيح، الفأرة، النوافذ
الدوال الشائعة والاستخدام الضار:
- GetAsyncKeyState: قراءة مدخلات لوحة المفاتيح - تسجيل ضغطات المفاتيح (keylogging)
- FindWindow: فحص التطبيقات الجارية - كشف أدوات الأمان، تجنب بيئات التحليل
- MessageBox: عرض رسائل مزيفة - الهندسة الاجتماعية، تنبيهات وهمية
Registry Keys for Persistence - Part 1
Registry Keys Commonly Used by Malware
Persistence (Run at Startup)
Key: HKCU\Software\Microsoft\Windows\CurrentVersion\Run
Breakdown:
- HKCU - HKEY_CURRENT_USER:
- Applies only to the currently logged-in user
- Settings stored here are loaded when that user logs in
- Software
- Stores configuration for software programs
- Both legitimate apps and malware use this location
- Microsoft\Windows
- Core Windows configuration area
- Windows actively checks these locations during startup
مفاتيح الريجستري للاستمرارية - الجزء الأول
الاستمرارية (التشغيل عند بدء التشغيل):
HKCU\Software\Microsoft\Windows\CurrentVersion\Run
تحليل المسار:
- HKCU (HKEY_CURRENT_USER):
- ينطبق فقط على المستخدم الحالي
- يتم تحميل الإعدادات عندما يسجل هذا المستخدم الدخول
- Software
- يخزن تكوينات البرامج
- كل من التطبيقات الشرعية والضارة تستخدم هذا الموقع
Registry Keys for Persistence - Part 2
CurrentVersion
- Points to the active Windows version
- Ensures compatibility across updates
Run
- Windows automatically executes every entry in this key
- Execution happens every time the user logs in
System-Wide Persistence
Key: HKLM\Software\Microsoft\Windows\CurrentVersion\Run
This affects all users and requires administrator privileges.
مفاتيح الريجستري للاستمرارية - الجزء الثاني
CurrentVersion
- يشير إلى إصدار ويندوز النشط
- يضمن التوافق عبر التحديثات
Run
- ويندوز ينفذ تلقائياً كل إدخال في هذا المفتاح
- يحدث التنفيذ في كل مرة يسجل فيها المستخدم الدخول
الاستمرارية على مستوى النظام:
HKLM\Software\Microsoft\Windows\CurrentVersion\Run
يؤثر على جميع المستخدمين ويتطلب صلاحيات مدير النظام.
Registry Keys for Services (Stealth & Privileges)
Services (Stealth & Privileges)
Key: HKLM\System\CurrentControlSet\Services
Breakdown:
- HKLM — HKEY_LOCAL_MACHINE
- Applies to the entire system
- Affects all users
- Requires administrator privileges
- => Malware gains system-wide persistence
- System
- Stores core operating system configuration
- Loaded during system boot
- => Malware here runs very early
مفاتيح الريجستري للخدمات (الاختفاء والصلاحيات)
HKLM\System\CurrentControlSet\Services
تحليل المسار:
- HKLM (HKEY_LOCAL_MACHINE)
- ينطبق على النظام بأكمله
- يؤثر على جميع المستخدمين
- يتطلب صلاحيات مدير النظام
- => البرنامج الضار يحصل على استمرارية على مستوى النظام
- System
- يخزن تكوين نظام التشغيل الأساسي
- يتم تحميله أثناء إقلاع النظام
- => البرنامج الضار هنا يعمل مبكراً جداً
Registry Keys for Services - CurrentControlSet
CurrentControlSet
- The active system configuration
- Windows uses this set every time it boots
- => Malware here survives Reboots and System configuration changes
Services
- Contains definitions of Windows services
- Each subkey = one service
- => Windows automatically loads these services at boot and starts them based on configuration
مفاتيح الريجستري للخدمات - CurrentControlSet
CurrentControlSet
- تكوين النظام النشط
- ويندوز يستخدم هذه المجموعة في كل مرة يقلع فيها
- => البرنامج الضار هنا يبقى بعد إعادة التشغيل وتغييرات تكوين النظام
Services
- يحتوي على تعريفات خدمات ويندوز
- كل مفتاح فرعي = خدمة واحدة
- => ويندوز يحمل هذه الخدمات تلقائياً عند الإقلاع ويبدأها حسب التكوين
Example: Malware Creating a Fake Service
Example: the malware creates a fake service:
HKLM\...\Services\WinUpdateSvc
With values like:
- ImagePath → path to malware executable
- Start = 2 → start automatically at boot
Result:
- Malware runs every boot
- Runs silently
- Often runs as SYSTEM
مثال: البرنامج الضار ينشئ خدمة مزيفة
HKLM\...\Services\WinUpdateSvc
مع قيم مثل:
- ImagePath → مسار الملف التنفيذي الضار
- Start = 2 → يبدأ تلقائياً عند الإقلاع
النتيجة:
- البرنامج الضار يعمل في كل إقلاع
- يعمل بصمت
- غالباً ما يعمل بصلاحيات SYSTEM (أعلى صلاحية)
Step 4: Packed and Obfuscated Malware - Introduction
- Malware authors hide real code using obfuscation or packing
- Malware obfuscation makes code intentionally difficult to read and understand
- Packed programs are a subset of obfuscated programs in which the malicious program is compressed and cannot be analyzed
- Goal: Evade detection & hinder static analysis
الخطوة 4: البرامج الضارة المضغوطة والمشوشة - مقدمة
- مؤلفو البرامج الضارة يخفون الكود الحقيقي باستخدام obfuscation (التشويش) أو packing (التعبئة)
- Malware obfuscation: يجعل الكود صعب القراءة والفهم عمداً
- Packed programs: نوع فرعي من البرامج المشوشة حيث يتم ضغط البرنامج الضار ولا يمكن تحليله
- الهدف: تجنب الكشف وإعاقة التحليل الثابت
Indicators of Packed Malware
Few or no readable strings
Legitimate programs → many strings
Packed malware → very few strings
Look for suspicious imports:
- LoadLibrary: Loads a Dynamic Link Library (DLL) into the program's memory. Instead of statically importing DLLs (visible in the PE header), malware can load DLLs dynamically at runtime. This hides dependencies from static analysis tools.
- GetProcAddress: Retrieves the address of a function inside a loaded DLL. After loading a DLL with LoadLibrary, the malware needs a way to call specific functions inside that DLL.
مؤشرات البرامج الضارة المضغوطة
قلة أو عدم وجود نصوص مقروءة:
البرامج الشرعية → نصوص كثيرة
البرامج الضارة المضغوطة → نصوص قليلة جداً
ابحث عن واردات مشبوهة:
- LoadLibrary: تحميل مكتبة DLL في ذاكرة البرنامج. بدلاً من استيراد DLLs بشكل ثابت (ظاهر في ترويسة PE)، يمكن للبرنامج الضار تحميل DLLs ديناميكياً في وقت التشغيل. هذا يخفي التبعيات من أدوات التحليل الثابت.
- GetProcAddress: الحصول على عنوان دالة داخل DLL محمل. بعد تحميل DLL باستخدام LoadLibrary، يحتاج البرنامج الضار لطريقة لاستدعاء دوال محددة داخل تلك الـ DLL.
How Packed Malware Works
How Packed Malware Works
- The malware you see is not the real program
- It contains a small wrapper (loader)
- When executed:
- The wrapper runs first
- It decompresses or decrypts the hidden payload
- The real malware runs in memory
- => That's why strings and code are not visible before execution
كيف تعمل البرامج الضارة المضغوطة
- البرنامج الضار الذي تراه ليس البرنامج الحقيقي
- يحتوي على غلاف صغير (wrapper أو loader)
- عند التنفيذ:
- الغلاف يعمل أولاً
- يقوم بفك ضغط أو فك تشفير الحمولة المخفية
- البرنامج الضار الحقيقي يعمل في الذاكرة
- => لهذا السبب النصوص والكود غير مرئية قبل التنفيذ
Packed Program Execution Flow
When the packed program is run, a small wrapper program also runs to decompress the packed file and then run the unpacked file.
1. User executes packed.exe
2. Wrapper code runs
3. Wrapper decompresses/decrypts payload in memory
4. Wrapper transfers execution to the unpacked code
5. Real malware runs
تدفق تنفيذ البرنامج المضغوط
عند تشغيل البرنامج المضغوط، يعمل برنامج غلاف صغير أيضاً لفك ضغط الملف المضغوط ثم تشغيل الملف المفكوك.
تدفق التنفيذ:
- المستخدم يشغل packed.exe
- كود الغلاف يعمل
- الغلاف يفك ضغط/تشفير الحمولة في الذاكرة
- الغلاف ينقل التنفيذ إلى الكود المفكوك
- البرنامج الضار الحقيقي يعمل
Static Analysis Red Flags for Packing
Key Static Analysis Red Flags
- Very few readable strings
- Very few imported functions
- Almost always imports:
- LoadLibrary
- GetProcAddress
Why is this suspicious?
The wrapper needs these APIs to:
- Load system DLLs
- Dynamically resolve functions
- Unpack and execute the hidden payload
علامات التحليل الثابت للبرامج المضغوطة
المؤشرات الرئيسية:
- قليل جداً من النصوص المقروءة
- قليل جداً من الدوال المستوردة
- دائماً تقريباً يستورد:
- LoadLibrary
- GetProcAddress
لماذا هذا مشبوه؟
الغلاف يحتاج هذه الـ APIs من أجل:
- تحميل DLLs النظام
- حل عناوين الدوال ديناميكياً
- فك ضغط وتنفيذ الحمولة المخفية
Detecting Obfuscation & Packing - Entropy
How to Detect Obfuscation & Packing?
- Entropy provides a quick view that our binary is packed or not
- Entropy is a measure of the unpredictability of the file's data
- A high entropy means a deliberate attempt to hide something
- Normal code and data: low-medium entropy (~4-6)
- Packed/encrypted data: high entropy (~6-8)
Tool: Pestudio
Pestudio is a tool that can calculate entropy and identify packed files.
كشف التشويش والتعبئة - الإنتروبيا
- Entropy (الإنتروبيا) يعطي نظرة سريعة ما إذا كان الملف الثنائي مضغوطاً أم لا
- Entropy هو قياس لعدم predictability (عدم قابلية التنبؤ) لبيانات الملف
- الإنتروبيا العالية تعني محاولة متعمدة لإخفاء شيء ما
- الكود والبيانات العادية: إنتروبيا منخفضة-متوسطة (~4-6)
- البيانات المضغوطة/المشفرة: إنتروبيا عالية (~6-8)
أداة: Pestudio
Pestudio هي أداة يمكنها حساب الإنتروبيا وتحديد الملفات المضغوطة.
Entropy Visualization
This page shows visual representation of entropy in different file sections.
- 0.0 - 3.0: Very low entropy (highly structured)
- 3.0 - 6.0: Normal code/data entropy
- 6.0 - 8.0: High entropy (packed/encrypted)
تصور الإنتروبيا
نطاقات الإنتروبيا:
- 0.0 - 3.0: إنتروبيا منخفضة جداً (منظم بشكل كبير)
- 3.0 - 6.0: إنتروبيا عادية للكود/البيانات
- 6.0 - 8.0: إنتروبيا عالية (مضغوط/مشفر)
Most Commonly Used Packers
Most Commonly Used Packers
- UPX – very common, open-source, easy to unpack
- Themida – strong commercial protector
- VMProtect – uses virtualization-based obfuscation
- ASPack – older but still seen
- PECompact
- MPRESS
- Obsidium
- Enigma Protector
أكثر أدوات التعبئة استخداماً
- UPX – شائع جداً، مفتوح المصدر، سهل فك الضغط
- Themida – حماية تجارية قوية
- VMProtect – يستخدم تشويش قائم على المحاكاة الافتراضية
- ASPack – أقدم لكن لا يزال يُرى
- PECompact
- MPRESS
- Obsidium
- Enigma Protector
PEiD - Packer Detection Tool
- PEiD is a free tool that provides details about Windows executable files
- It can identify signatures associated with over 600 different packers and compilers
- This tool also displays the type of packer used in packing a malware
PEiD - أداة كشف أدوات التعبئة
- PEiD هي أداة مجانية توفر تفاصيل حول ملفات ويندوز التنفيذية
- يمكنها التعرف على تواقيع مرتبطة بأكثر من 600 أداة تعبئة ومترجم مختلف
- هذه الأداة تعرض أيضاً نوع أداة التعبئة المستخدمة في تعبئة البرنامج الضار
Detect It Easy (DIE)
- Detect It Easy (DIE) is an application used for determining the types of files
- DIE is also available for Linux and Mac OS
- It has a completely open architecture of signatures and can easily add its own algorithms for detecting or modifying the existing signatures
- It detects a file's compiler, linker, packer, etc. using a signature-based detection method
Detect It Easy (DIE)
- Detect It Easy (DIE) هو تطبيق يستخدم لتحديد أنواع الملفات
- DIE متاح أيضاً لأنظمة لينكس وماك
- لديه بنية تواقيع مفتوحة بالكامل ويمكنه بسهولة إضافة خوارزميات خاصة للكشف أو تعديل التواقيع الموجودة
- يكتشف مترجم الملف، رابط المكتبات، أداة التعبئة، إلخ باستخدام طريقة كشف قائمة على التوقيع
Step 5: Inspect PE Headers - Introduction
Why Inspect PE Headers?
- Windows executables use the Portable Executable (PE) format
- The PE header tells Windows how to load and run the program
- For analysts, PE headers reveal:
- Architecture (32-bit / 64-bit)
- Entry point
- Imported libraries
- Suspicious anomalies (packing, obfuscation, tampering)
What Is a PE File?
- A PE file is a structured binary format used by:
- Executables (.exe)
- Dynamic libraries (.dll)
- It contains metadata + code + data, arranged in a fixed layout
- Windows does not guess how to run a file — it follows the PE headers
الخطوة 5: فحص ترويسات PE - مقدمة
لماذا نفحص ترويسات PE؟
- ملفات ويندوز التنفيذية تستخدم تنسيق Portable Executable (PE)
- ترويسة PE تخبر ويندوز كيف يحمل ويشغل البرنامج
- للمحللين، ترويسات PE تكشف:
- المعمارية (32-bit / 64-bit)
- نقطة الدخول (entry point)
- المكتبات المستوردة
- الشذوذ المشبوه (التعبئة، التشويش، التلاعب)
ما هو ملف PE؟
- ملف PE هو تنسيق ثنائي منظم يستخدم بواسطة:
- الملفات التنفيذية (.exe)
- المكتبات الديناميكية (.dll)
- يحتوي على بيانات وصفية + كود + بيانات، مرتبة في تخطيط ثابت
- ويندوز لا يخمن كيفية تشغيل ملف - يتبع ترويسات PE
PE File Structure
| Component | Description |
|---|---|
| MZ Header/DOS Header | Defines the file as an executable binary |
| DOS Stub | Prints "This program cannot be run in DOS mode" when run in DOS (Exists for compatibility) |
| PE File Header (Signature) | Defines the executable as a PEImage |
| Optional Header | Stores important information about the executable: Like the subsystem and the entry point |
| Sections Table | Instructions on how to load the executable into memory |
| Sections | Executable sections of code and data used by the executable |
هيكل ملف PE
- MZ Header/DOS Header: يحدد الملف كملف ثنائي تنفيذي
- DOS Stub: يطبع رسالة عند التشغيل في DOS (موجود للتوافق)
- PE File Header (Signature): يحدد الملف التنفيذي كـ PEImage
- Optional Header: يخزن معلومات مهمة عن الملف التنفيذي: مثل النظام الفرعي ونقطة الدخول
- Sections Table: تعليمات حول كيفية تحميل الملف التنفيذي في الذاكرة
- Sections: أقسام قابلة للتنفيذ من الكود والبيانات المستخدمة بواسطة الملف التنفيذي
DOS Header and DOS Stub
1. DOS Header (MZ Header)
- First bytes of every PE file
- Starts with signature: MZ
- Identifies the file as an executable
- Missing or corrupted MZ → suspicious file
- Malware sometimes tampers with it to break tools
2. DOS Stub
- Small legacy program
- Displays message: "This program cannot be run in DOS mode"
- Exists only for backward compatibility
DOS Header و DOS Stub
1. DOS Header (MZ Header):
- أول بايتات من كل ملف PE
- يبدأ بتوقيع: MZ
- يحدد الملف كملف تنفيذي
- MZ مفقود أو تالف ← ملف مشبوه
- البرامج الضارة أحياناً تتلاعب به لتعطيل الأدوات
2. DOS Stub:
- برنامج صغير قديم
- يعرض رسالة: "لا يمكن تشغيل هذا البرنامج في وضع DOS"
- موجود فقط للتوافق مع الإصدارات السابقة
PE Signature and COFF Header
PE Signature
- Always: PE\0\0
- Marks the start of the real PE structure
COFF Header Contains
- Machine type (x86, x64, ARM)
- Number of sections
- Compilation timestamp
- Size of optional header
Malware clues
- Fake or zero timestamps
- Unusual number of sections
- Architecture mismatch
توقيع PE و COFF Header
توقيع PE:
- دائماً: PE\0\0
- يشير إلى بداية هيكل PE الحقيقي
COFF Header يحتوي على:
- نوع الآلة (Machine type): x86, x64, ARM
- عدد الأقسام (Number of sections)
- طابع زمني للترجمة (Compilation timestamp)
- حجم الترويسة الاختيارية (Size of optional header)
مؤشرات خبث (Malware clues):
- Fake or zero timestamps: طوابع زمنية مزيفة أو صفرية - تشير إلى محاولة إخفاء وقت الترجمة الحقيقي (مثلاً 0 يعني 1 يناير 1970)
- Unusual number of sections: عدد غير طبيعي من الأقسام (قليل جداً مثل 1-2 أو كثير جداً >10) - البرامج العادية لها عدد ثابت من الأقسام (عادة 3-6)
- Architecture mismatch: عدم تطابق المعمارية - مثلاً ملف مكتوب لـ 64-bit لكن الترويسة تشير إلى 32-bit، أو العكس
Optional Header - Critical Information
Optional Header Contains:
- Entry Point → where execution starts
- Image Base → preferred memory address
- Subsystem → GUI or Console
- Section alignment → how sections are aligned in memory
- Data directories (imports, exports, resources)
Why as analysts we check optional header?
- Entry point often points to:
- Unpacking code
- Loader stubs
- Add entry points = suspicious behavior
Optional Header - معلومات حاسمة
الترويسة الاختيارية تحتوي على:
- Entry Point: نقطة الدخول - أين يبدأ التنفيذ
- Image Base: عنوان الذاكرة المفضل
- Subsystem: النظام الفرعي - واجهة مستخدم رسومية (GUI) أو وحدة تحكم (Console)
- Section alignment: محاذاة الأقسام في الذاكرة
- Data directories: أدلة البيانات (الواردات، الصادرات، الموارد)
لماذا نفحص الـ Optional Header كمحللين؟
- نقطة الدخول غالباً ما تشير إلى:
- كود فك التعبئة (unpacking code)
- مُحمِّلات (loader stubs)
- نقاط دخول متعددة = سلوك مشبوه
Section Table - Roadmap of Sections
Section Table (a roadmap of sections)
- Each entry describes one section of the program
- Contains: name, size, location, memory permissions (read/write/execute)
Common sections:
| Section | Description | Malware Relevance |
|---|---|---|
| .text | Contains executable code | Main code section - usually where malware hides |
| .rdata | Read-only data (imports, constants) | May contain strings, IPs, URLs |
| .data | Stores data (read/write) | Global variables, configuration |
| .idata | Stores the import tables | Shows which APIs are used |
| .edata | Stores the export data | What functions the DLL exports |
| .rsrc | Resources (icons, dialogs, version info) | May hide additional payloads |
Section Table - خريطة الأقسام
الأقسام الشائعة:
- .text: يحتوي على الكود القابل للتنفيذ - القسم الرئيسي حيث يخفي البرنامج الضار كوده
- .rdata: بيانات للقراءة فقط (الواردات، الثوابت) - قد يحتوي على نصوص، عناوين IP، URLs
- .data: يخزن بيانات (قراءة/كتابة) - متغيرات عامة، تكوين
- .idata: يخزن جداول الاستيراد - يظهر أي APIs تستخدم
- .edata: يخزن بيانات التصدير - الدوال التي يصدرها الـ DLL
- .rsrc: الموارد (أيقونات، مربعات حوار، معلومات الإصدار) - قد يخفي حمولات إضافية
Linked Libraries and Imports - Introduction
What Are Imports?
- Functions the program uses but does not implement
- Loaded from external DLLs (e.g., kernel32.dll, user32.dll)
- They reveal capabilities:
- Networking
- File operations
- Registry access
- Process injection
المكتبات المرتبطة والواردات - مقدمة
ما هي الـ Imports؟
- دوال يستخدمها البرنامج لكنه لا ينفذها بنفسه
- يتم تحميلها من DLLs خارجية (مثل kernel32.dll, user32.dll)
- تكشف الإمكانيات:
- الشبكات (networking)
- عمليات الملفات (file operations)
- الوصول للريجستري (registry access)
- حقن العمليات (process injection)
How Programs Link Libraries
How Programs Link Libraries
1. Static Linking
- Code copied directly into executable
- Rare on Windows
- Harder to distinguish functionality
2. Dynamic Linking (Most Common)
- Imports listed in PE header
- Resolved at program load
- Analyst-friendly
3. Runtime Linking (Common in Malware)
- Imports not listed
- Malware calls:
- LoadLibrary
- GetProcAddress
- APIs resolved during execution
كيف تربط البرامج المكتبات
1. الربط الثابت (Static Linking):
- الكود ينسخ مباشرة في الملف التنفيذي
- نادر في ويندوز
- أصعب تمييز الوظائف
2. الربط الديناميكي (Dynamic Linking) - الأكثر شيوعاً:
- الواردات مدرجة في ترويسة PE
- يتم حلها عند تحميل البرنامج
- صديق للمحلل
3. الربط وقت التشغيل (Runtime Linking) - شائع في البرامج الضارة:
- الواردات غير مدرجة
- البرنامج الضار يستدعي:
- LoadLibrary
- GetProcAddress
- الـ APIs تحل أثناء التنفيذ
Common DLLs and Their Purposes
| DLL | Description | Malware Usage |
|---|---|---|
| Kernel32.dll | Core functionality: memory, files, hardware | File operations, process creation, memory manipulation |
| Advapi32.dll | Advanced components: Service Manager, Registry | Registry persistence, service installation, privilege manipulation |
| User32.dll | User-interface components: buttons, scroll bars, user actions | Keylogging, window manipulation, message boxes |
| Gdi32.dll | Displaying and manipulating graphics | Screen capture, GUI manipulation |
| Ntdll.dll | Interface to Windows kernel. Executables generally do not import this directly (imported via Kernel32.dll). If imported directly → suspicious | Native API access, process manipulation, hiding functionality |
| WSock32.dll / Ws2_32.dll | Networking DLLs | Network communication, C2 connections |
| Wininet.dll | Higher-level networking functions (FTP, HTTP, NTP) | HTTP communications, downloading payloads |
DLLs الشائعة وأغراضها
- Kernel32.dll: وظائف أساسية - الذاكرة، الملفات، العتاد - يستخدم لعمليات الملفات، إنشاء العمليات
- Advapi32.dll: مكونات متقدمة - مدير الخدمات، الريجستري - للاستمرارية في الريجستري، تثبيت الخدمات
- User32.dll: مكونات واجهة المستخدم - لتسجيل ضربات المفاتيح (keylogging)، التلاعب بالنوافذ
- Ntdll.dll: واجهة نواة ويندوز - إذا تم استيراده مباشرة فهذا مشبوه - للوصول المباشر للنواة
- Ws2_32.dll: مكتبات الشبكة - للاتصال بخوادم C2
- Wininet.dll: وظائف شبكات عالية المستوى - لاتصالات HTTP، تحميل الحمولات
Exported Functions
What Are Exported Functions?
Like imports, exports are functions defined in a program that can be used by other programs.
DLLs are the main providers of exports:
- They implement functionality (e.g., file operations, networking, registry)
- Executables (EXEs) can then import and use these functions
- DLL hijacking preparation
- Code injection targets
- Malware that acts as both EXE and DLL
الدوال المصدرة (Exported Functions)
ما هي الدوال المصدرة؟
مثل الواردات، الصادرات هي دوال معرفة في برنامج يمكن أن تستخدمها برامج أخرى.
الـ DLLs هي المزود الرئيسي للصادرات:
- تنفذ وظائف (مثل عمليات الملفات، الشبكات، الريجستري)
- الملفات التنفيذية (EXEs) يمكنها استيراد واستخدام هذه الدوال
⚠️ مهم: الملفات التنفيذية نادراً ما تصدر دوال، لأنها ليست مخصصة لتكون مكتبات مشتركة. إذا كان EXE يصدر دوال، فهذا مشبوه جداً وغالباً ما يشير إلى:
- تحضير لاختطاف DLL (DLL hijacking)
- أهداف حقن الكود
- برنامج ضار يعمل كـ EXE و DLL في نفس الوقت
Complete Static Malware Analysis Checklist
✅ Step-by-Step Analysis Flow:
- Identify File Type: Check magic numbers, not extensions
- Generate Hashes: SHA-256 for fingerprinting
- Extract Strings: Look for IPs, URLs, registry keys, commands
- Check for Packing: Analyze entropy, imports, section names
- Inspect PE Headers: Entry point, IAT, sections, timestamps
- Analyze Imports/Exports: Identify capabilities
- Check Registry Indicators: Persistence locations
- Correlate with Online Databases: VirusTotal, etc.
🚩 Red Flags Summary:
- High entropy (>6.5) → packed/encrypted
- Few readable strings → packed
- LoadLibrary + GetProcAddress → dynamic resolution, often packed
- Suspicious section names (e.g., .UPX, .themida)
- Entry point in unusual section
- Direct ntdll.dll imports → native API usage
- EXE with export table → highly suspicious
- Registry Run keys or Service entries in strings
- Hardcoded IP addresses instead of domains
ملخص كامل لتحليل البرامج الضارة الثابت
خطوات التحليل:
- تحديد نوع الملف: فحص magic numbers وليس الامتدادات
- توليد الهاش: SHA-256 للبصمة
- استخراج النصوص: البحث عن عناوين IP، URLs، مفاتيح الريجستري، أوامر
- التحقق من التعبئة: تحليل entropy، الواردات، أسماء الأقسام
- فحص ترويسات PE: نقطة الدخول، IAT، الأقسام، الأطوابع الزمنية
- تحليل الواردات/الصادرات: تحديد الإمكانيات
- فحص مؤشرات الريجستري: مواقع الاستمرارية
- الربط مع قواعد البيانات عبر الإنترنت: VirusTotal، إلخ
ملخص العلامات الحمراء:
- High entropy (>6.5) → ملف مضغوط/مشفر
- قلة النصوص المقروءة → ملف مضغوط
- LoadLibrary + GetProcAddress → تحليل ديناميكي، غالباً ملف مضغوط
- أسماء أقسام مشبوهة (مثل .UPX، .themida)
- نقطة الدخول في قسم غير عادي
- استيراد مباشر من ntdll.dll → استخدام مباشر لواجهة النواة
- ملف EXE يحتوي على export table → مشبوه جداً
- مفاتيح Run في الريجستري أو إدخالات خدمات في النصوص
- عناوين IP مثبتة في الكود بدلاً من أسماء النطاقات
Static Malware Analysis - Key Takeaways
What We've Covered:
- ✅ Static analysis = examining malware without execution
- ✅ File type identification using magic numbers (not extensions)
- ✅ Hashing for unique identification and lookup
- ✅ String analysis reveals IPs, URLs, registry keys, commands
- ✅ Packing detection through entropy, imports, section analysis
- ✅ PE header analysis reveals structure, imports, entry point
- ✅ Registry persistence locations (Run, Services, etc.)
- ✅ Common DLLs and their malicious uses
- ✅ IOCs extraction for threat intelligence
⚠️ Remember:
- File extensions can lie - magic numbers never lie
- Packed malware hides its true nature - always check entropy
- LoadLibrary + GetProcAddress = dynamic resolution (often packed)
- EXEs with exports are highly suspicious
- Always verify findings with multiple tools
- Static analysis is just the first step - dynamic analysis may be needed
تحليل البرامج الضارة الثابت - النقاط الرئيسية
ما قمنا بتغطيته:
- التحليل الثابت = فحص البرامج الضارة دون تنفيذها
- تحديد نوع الملف باستخدام الأرقام السحرية (وليس الامتدادات)
- الهاش للتعريف الفريد والبحث
- تحليل النصوص يكشف IPs، URLs، مفاتيح الريجستري، أوامر
- كشف التعبئة من خلال الإنتروبيا، الواردات، تحليل الأقسام
- تحليل ترويسات PE يكشف الهيكل، الواردات، نقطة الدخول
- مواقع الريجستري للاستمرارية
- مكتبات DLL الشائعة واستخداماتها الضارة
- استخراج IOCs للاستخبارات الأمنية
تذكر دائماً:
- امتدادات الملفات يمكن أن تكذب - الأرقام السحرية لا تكذب أبداً
- البرامج المضغوطة تخفي طبيعتها الحقيقية - دائماً افحص الإنتروبيا
- LoadLibrary + GetProcAddress = تحليل ديناميكي (غالباً مضغوط)
- ملفات EXE مع صادرات مشبوهة جداً
- دائماً تحقق من النتائج بأدوات متعددة
- التحليل الثابت هو مجرد الخطوة الأولى - قد تحتاج لتحليل ديناميكي