1 731
💣 مثال عملی از Obfuscated Binary
🎯 هدف:
تحلیل یه باینری ساده ولی Obfuscated شده با تکنیکهای:
Junk Code
Control Flow Flattening
Code Transposition
Opaque Predicates
🧪 مرحله ۱ – کد ساده اصلی (قبل از Obfuscation)
فرض کن این کد رو داریم:
int secret() { return 1337; } int main() { int x = secret(); if (x == 1337) printf("Access Granted\n"); else printf("Access Denied\n"); }خیلی ساده و مستقیمه. تو disassembly سریعاً متوجه میشی secret() چیه و شرط رو راحت میفهمی. 💉 مرحله ۲ – اعمال Obfuscation حالا این کد Obfuscated میشه خروجی چیزی شبیه به اینه: 🔻 سطح اسمبلی:
mov eax, 0x539 ; Load garbage value nop jmp label1 label1: xor ecx, ecx mov ecx, 0x539 ; Real value here cmp ecx, 0x539 jne denied mov edx, ecx call check_flag jmp end check_flag: push edx mov eax, edx cmp eax, 0x539 jne denied pop edx jmp success success: push message1 call printf jmp end denied: push message2 call printf end: ret🧠 نکات تحلیل: توابع جابجا شدن → Call Graph به هم ریخته cmp ecx, 0x539 تکراریه ولی ضروریه برای اجرای مسیر درست شرطهای اضافی و jumpهای غیرضروری → Control Flow Flattening check_flag و main درهم ریختهان اسامی توابع حذف شدن یا رمزگذاری شدن 👀 در Ghidra/IDA چی میبینیم؟ ✅ CFG (Control Flow Graph) بهم ریختهست ✅ Cross Reference برای printf هست ولی نمیدونی کِی صدا زده میشه ✅ Flow از بالا به پایین نیست → باید با چشم و منطق بازسازی کنی ✅ جابهجایی labelها مسیر رو نامشخص میکنه 💣 Practical Example of an Obfuscated Binary 🎯 Target: Analyze a simple binary that has been obfuscated using techniques like: Junk Code Control Flow Flattening Code Transposition Opaque Predicates 🧪 Stage 1 – The Original Simple Code (Before Obfuscation) Let’s start with a clean, readable piece of C code:
int secret() { return 1337; } int main() { int x = secret(); if (x == 1337) printf("Access Granted\n"); else printf("Access Denied\n"); }Very straightforward. In the disassembly, you can quickly spot what secret() returns and understand the conditional logic. 💉 Stage 2 – After Obfuscation Now, this code has been obfuscated. The disassembled output might look like this: 🔻 Assembly Level:
mov eax, 0x539 ; Load garbage value nop jmp label1 label1: xor ecx, ecx mov ecx, 0x539 ; Real value here cmp ecx, 0x539 jne denied mov edx, ecx call check_flag jmp end check_flag: push edx mov eax, edx cmp eax, 0x539 jne denied pop edx jmp success success: push message1 call printf jmp end denied: push message2 call printf end: ret🧠 Analysis Notes: Function flow has been rearranged → Call graph is misleading cmp ecx, 0x539 looks redundant but is necessary for valid path execution Extra conditional jumps and labels → Result of Control Flow Flattening check_flag and main are interleaved → harder static analysis Function names are stripped or renamed → Symbol resolution is tricky 👀 What Do You See in Ghidra/IDA? ✅ A messy Control Flow Graph (CFG) ✅ Cross-references to printf() exist, but not clear when it’s triggered ✅ No top-down logic flow — you must reconstruct it manually ✅ Jump labels and code blocks are shuffled → control flow is disguised
10 июня 2025, 01:52

