en
Feedback
ReverseEngineering

ReverseEngineering

Open in Telegram
1 265
Subscribers
No data24 hours
-37 days
+730 days
Posts Archive

Windows Process.pdf4.22 MB

EDR Evasion Techniques using Syscalls

🟢 6️⃣ Paging حافظه به Page تقسیم میشه مثلا 4KB Page Table مشخص میکنه: این page به کجای RAM وصله دسترسیش چیه R/W/X کاربرد RE: وقتی صفحه execute نیست اجرای کد خطا میده 🟢 6️⃣ Paging Memory is divided into Pages, for example 4KB Page Table Specifies: Where is this page attached to in RAM What is its access R/W/X RE usage: When the page is not executed, executing the code gives an error @reverseengine

🟢 5️⃣ Virtual Memory سیستم‌ عامل به هر Process یک Virtual Address Space میده یعنی: برنامه فکر میکنه حافظه پیوسته داره ولی OS اونو به صفحات واقعی RAM map میکنه مزایا: جداسازی Process ها امنیت کنترل دسترسی کاربرد RE: آدرس‌ هایی که میبینید virtual هستند 🟢 5️⃣ Virtual Memory The operating system gives each process a Virtual Address Space That is: The program thinks it has contiguous memory But the OS maps it to real RAM pages Advantages: Process isolation Security Access control Use RE: The addresses you see are virtual @reverseengine

40

🟢 4️⃣ Memory Layout چیدمان حافظه Process هر Process معمولا این بخش‌ ها رو داره:
Copy code
Code (text) → دستورالعمل‌ها Data → متغیرهای ثابت Heap → حافظه داینامیک Stack → متغیرهای تابع Mapped DLLs → کتابخانه‌ها RE: وقتی در debugger حافظه رو میبینید این بخش‌ ها رو تشخیص میدید 🟢 4️⃣ Memory Layout Process Memory Layout Each Process usually has these sections: Copy code Code (text) → Instructions Data → Constant variables Heap → Dynamic memory Stack → Function variables Mapped DLLs → Libraries RE: When you look at memory in the debugger, you will recognize these sections @reverseengine

🟢 3️⃣ Context Switch وقتی CPU بین Process/Thread ها جا به جا میشه: رجیسترها ذخیره میشن رجیسترهای اجرای جدید بارگذاری میشن چرا؟ چون اجرای برنامه ممکنه ناپیوسته دیده بشه 🟢 3️⃣ Context Switch When the CPU switches between Process/Thread: Registers are saved New execution registers are loaded Why? Because program execution may appear discontinuous @reverseengine

NX چیسه و چرا Shellcode مستقیم معمولا اجرا نمیشه درباره shellcode کد رو داخل استک ریخت RIP رو فرستاد روی استک کد اجرا می‌شد ولی االان معمولا این کار جواب نمی‌ده دلیلش یک مکانیزم امنیتی مهمه: NX = Non-Executable NX دقیقاً چه کار می‌کند؟ NX میگه: بعضی بخش هاس حافظه فقط برای داده هستن نه برای اجرای کد یعنی: استک → فقط داده هیپ → فقط داده اجرای دستور → ممنوع اگر CPU تلاش کنه از این بخش ها دستور اجرا کنه → برنامه فورا کرش میکنه چه اتفاقی میوفته؟ فرض کنید: Shellcode رو داخل بافر ریختید RIP رو کردی آدرس همون بافر روی سیستم دارای NX: executable : نیست CPU این بخش segmentation fault یعنی: کنترل RIP رو دارید ولی اجرای کد هنوز ندارید و این دقیقاً همون جاییه که خیلی از exploit های مبتدی شکست میخورن پس چرا NX اضافه شد؟ چون Shellcode injection خیلی رایج شده بود NX اومد که این سناریو رو ببنده:
Copy code input → overflow → shellcode → jump → execute
با NX این زنجیره قطع میشه اکسپلویترها چه کار کردن؟ وقتی اجرای کد جدید ممنوع شد ایده‌ ی جدید شکل گرفت: کد جدید اجرا نکنید از کدهای موجود استفاده کنید و این شد: Return Oriented Programming (ROP) یعنی: اجرای gadget های داخل باینری و libc بدون اجرای کد تزریق‌شده کاملا سازگار با NX یک اشتباه رایج NX ≠ ضد اکسپلویت NX فقط: اجرای کد تزریقی رو میبنده ولی: جلوی ROP رو نمیگیره جلوی ret2libc رو نمیگیره جلوی chain کردن gadget ها رو نمیگیره برای همین هنوز exploit ممکنه فقط روشش عوض شده NX باعث میشه بخش‌هایی از حافظه مثل استک و هیپ قابل اجرای کد نباشن یعنی دیگه نمیتونید به سادگی Shellcode تزریق کنید و اجراش کنید همین باعث شد تکنیک‌های مدرن‌تر مثل ROP به وجود بیان پس NX اکسپلویت اخر نبود فقط روشش رو عوض کرد NX What is and why direct shellcode is usually not executed About shellcode Put the code on the stack Push RIP onto the stack The code was executed But now this usually does not work The reason is an important security mechanism: NX = Non-Executable What exactly does NX do? NX says: Some memory sections are for data only, not for code execution That is: Stack → Data only Heap → Data only Instruction execution → Forbidden If the CPU tries to execute an instruction from these sections → the program crashes immediately What happens? Suppose: You put the shellcode into the buffer You did the RIP to the address of the same buffer On a system with NX: The executable is not the CPU of this section Segmentation fault That is: You have control of the RIP but you don't have the code execution yet And this is exactly where many beginner exploits fail So why was NX added? Because shellcode injection had become so common NX was introduced to close this scenario:
Copy code input → overflow → shellcode → jump → execute
With NX, this chain is broken What did the exploiters do? When new code execution was banned, a new idea was born: Don't run new code, use existing code And this is what happened: Return Oriented Programming (ROP) That is: Executing gadgets inside binaries and libc Without executing injected code Completely compatible with NX A common mistake NX ≠ anti-exploit NX only: Stops execution of injected code But: It doesn't prevent ROP It doesn't prevent ret2libc It doesn't prevent chaining of gadgets That's why exploits are still possible, just the method has changed NX Makes parts of memory like the stack and heap inaccessible to code That means you can't simply inject shellcode and execute it That's what gave rise to more modern techniques like ROP So NX wasn't the last exploit, it just changed the method @reverseengine

Hexrays Toolbox - Find code patterns within the Hexrays AST https://github.com/patois/HexraysToolbox @reverseengine

Thread-Name Calling - A new process injection technique using Thread Name. The code to be injected is passed as a thread description to the target https://research.checkpoint.com/2024/thread-name-calling-using-thread-name-for-offense/ @reverseengine

Tools used during the reversing of the Nikon firmware https://github.com/simeonpilgrim/nikon-firmware-tools @reverseengine

A Ghidra processor module for the EFI Byte Code (EBC) https://github.com/meromwolff/Ghidra-EFI-Byte-Code-Processor @reverseengine