Toolkit for Windows internals, vulnerability analysis, and reproducible security research workflows.
https://github.com/kernelstub/NTForge
https://github.com/kernelstub/NTForge
Bypassing Denuvo in Hogwarts Legacy
https://momo5502.com/posts/2024-03-31-bypassing-denuvo-in-hogwarts-legacy/
https://momo5502.com/posts/2024-03-31-bypassing-denuvo-in-hogwarts-legacy/
Maurice's Blog
Bypassing Denuvo in Hogwarts Legacy
When I announced my Black Ops 3 integrity bypass, someone commented that my research was not impressive and I should try analyzing Denuvo instead.
That kinda stuck with me, so I did what everyone would do and spent the last 5 months of my free time reverse…
That kinda stuck with me, so I did what everyone would do and spent the last 5 months of my free time reverse…
A dive into the PE file format
https://0xrick.github.io/win-internals/pe1/
https://0xrick.github.io/win-internals/pe2/
https://0xrick.github.io/win-internals/pe3/
https://0xrick.github.io/win-internals/pe4/
https://0xrick.github.io/win-internals/pe5/
https://0xrick.github.io/win-internals/pe6/
[Mastering PE Structure for Malware Analysis: A Layman’s Guide](https://tech-zealots.com/malware-analysis/pe-portable-executable-structure-malware-analysis-part-2/)
[Peering Inside the PE: A Tour of the Win32 Portable Executable File Format](https://coffi.readthedocs.io/en/latest/peering_inside_pe.pdf)
https://0xrick.github.io/win-internals/pe8/
packages:
- c++ : https://lief.re/doc/stable/formats/pe/cpp.html
- rust : https://docs.rs/pe-parser/latest/pe_parser/
- python : https://pypi.org/project/pe-parser/
questions? :
- [What does "e_lfanew" mean in the DOS header for the PE format?](https://stackoverflow.com/questions/47711282/what-does-e-lfanew-mean-in-the-dos-header-for-the-pe-format)
- [Disassemble Windows PE .data section (using python)](https://stackoverflow.com/questions/58775954/disassemble-windows-pe-data-section)
- [Loading a 64-bit Windows PE file from memory](https://stackoverflow.com/questions/68988499/loading-a-64-bit-windows-pe-file-from-memory)
https://0xrick.github.io/win-internals/pe1/
https://0xrick.github.io/win-internals/pe2/
https://0xrick.github.io/win-internals/pe3/
https://0xrick.github.io/win-internals/pe4/
https://0xrick.github.io/win-internals/pe5/
https://0xrick.github.io/win-internals/pe6/
[Mastering PE Structure for Malware Analysis: A Layman’s Guide](https://tech-zealots.com/malware-analysis/pe-portable-executable-structure-malware-analysis-part-2/)
[Peering Inside the PE: A Tour of the Win32 Portable Executable File Format](https://coffi.readthedocs.io/en/latest/peering_inside_pe.pdf)
https://0xrick.github.io/win-internals/pe8/
packages:
- c++ : https://lief.re/doc/stable/formats/pe/cpp.html
- rust : https://docs.rs/pe-parser/latest/pe_parser/
- python : https://pypi.org/project/pe-parser/
questions? :
- [What does "e_lfanew" mean in the DOS header for the PE format?](https://stackoverflow.com/questions/47711282/what-does-e-lfanew-mean-in-the-dos-header-for-the-pe-format)
- [Disassemble Windows PE .data section (using python)](https://stackoverflow.com/questions/58775954/disassemble-windows-pe-data-section)
- [Loading a 64-bit Windows PE file from memory](https://stackoverflow.com/questions/68988499/loading-a-64-bit-windows-pe-file-from-memory)
0xRick's Blog
A dive into the PE file format - Introduction
A dive into the PE file format - Introduction What is this ? This is going to be a series of blog posts covering PE files in depth, it’s going to include a range of different topics, mainly the structure of PE files on disk and the way PE files get mapped…
GitRunner-C2
C2 framework abusing GitLab self-hosted runners as implants — Vue 3 operator UI, NGINX proxy, full file transfer and detection coverage.
Blog: https://vrls.ws/posts/abusing-gitlab-ci-runners-as-c2/
C2 framework abusing GitLab self-hosted runners as implants — Vue 3 operator UI, NGINX proxy, full file transfer and detection coverage.
Blog: https://vrls.ws/posts/abusing-gitlab-ci-runners-as-c2/
Dispatcher قلب ماشین مجازی
اگر فقط یک قسمت از VMProtect یا هر Virtual Machine رو بخواید تحلیل کنید اون قسمت Dispatcher هست
Dispatcher
مسئول اینه که تصمیم بگیره الان کدوم Opcode باید اجرا بشه
بدون Dispatcher هیچ Opcode ی اجرا نمیشه
فرض کنید این بایت کد رو داریم:
اینجا:
01 یعنی LOAD
02 یعنی ADD
03 یعنی PRINT
Dispatcher
اولین بایت (01) رو میخونه تشخیص میده Opcode از نوع LOAD هست و کنترل رو به Handler مربوط به LOAD میده
بعد دوباره برمیگرده
حالا Opcode بعدی (02) رو میخونه و Handler مربوط به ADD اجرا میشه
دوباره برمیگرده
در آخر Opcode 03 اجرا میشه
در تمام این مدت فقط Dispatcher داره تصمیم میگیره مرحله بعدی چیه
به همین خاطر بهش میگن قلب ماشین مجازی
در اکثر ماشینهای مجازی این چرخه دائماً
تکرار میشه:
به این چرخه معمولا Fetch → Decode → Execute گفته میشه
تقریبا تمام CPU های دنیا هم با همین ایده کار میکنن
تنها تفاوت اینه که CPU دستورهای واقعی پردازنده رو اجرا میکنه ولی ماشین مجازی دستورهای اختصاصی خودش رو
وقتی Dispatcher رو داخل دیس اسمبل پیدا کنید معمولا چند نشونه میبینی:
یک حلقه که دائما تکرار میشه
خواندن یک بایت از حافظه یا جدول Opcode ها
یک پرش غیرمستقیم یا انتخاب بین چند Handler
برگشت دوباره به ابتدای حلقه
به همین دلیل تحلیلگرها معمولا از Dispatcher شروع میکنن چون تمام مسیرهای اجرا از اون عبور میکنن
تمرین:
یک برنامه ساده بنویس که فقط سه Opcode داشته باشه:
بعد Dispatcher اونو رسم کنید
لازم نیست کد بنویسید فقط روی کاغذ مشخص کنید هر Opcode بعد از Dispatcher به کجا میره
وقتی این مفهوم رو کاملا درک کنید فهمیدن ماشینهای مجازی پیچیده مثل VMProtect خیلی سادهتر میشه
Dispatcher is the heart of the virtual machine
If you want to analyze only one part of VMProtect or any Virtual Machine, that part is Dispatcher
Dispatcher
is responsible for deciding which Opcode should be executed now
Without Dispatcher, no Opcode can be executed
Suppose we have this byte code:
Here:
Dispatcher
reads the first byte (01) and recognizes that the Opcode is of type LOAD and passes control to the Handler related to LOAD
Then it returns again
Now it reads the next Opcode (02) and the Handler related to ADD is executed
It returns again
Finally, Opcode 03 is executed
All this time, only Dispatcher is deciding what the next step is
That is why it is called the heart of the virtual machine
In most virtual machines, this cycle
is constantly
repeated:
Reading Opcode
Determining type Opcode
Execution of Handler
Return to Dispatcher
Read next Opcode
This cycle is usually called Fetch → Decode → Execute
Almost all CPUs in the world work with the same idea
The only difference is that the CPU executes the actual processor instructions, but the virtual machine executes its own instructions
When you find the Dispatcher in the disassembler, you will usually see a few signs:
A loop that repeats itself over and over
Reading a byte from memory or the Opcode table
An indirect jump or selection between several Handlers
Return to the beginning of the loop
That is why analysts usually start with the Dispatcher because all execution paths pass through it
Exercise:
Write a simple program that has only three Opcodes:
Then draw the Dispatcher
You don't need to write the code, just mark on paper where each Opcode goes after the Dispatcher
Once you fully understand this concept, understanding machines Complex virtualization like VMProtect becomes much simpler
@reverseengine
اگر فقط یک قسمت از VMProtect یا هر Virtual Machine رو بخواید تحلیل کنید اون قسمت Dispatcher هست
Dispatcher
مسئول اینه که تصمیم بگیره الان کدوم Opcode باید اجرا بشه
بدون Dispatcher هیچ Opcode ی اجرا نمیشه
فرض کنید این بایت کد رو داریم:
01 10
02 20
03
اینجا:
01 یعنی LOAD
02 یعنی ADD
03 یعنی PRINT
Dispatcher
اولین بایت (01) رو میخونه تشخیص میده Opcode از نوع LOAD هست و کنترل رو به Handler مربوط به LOAD میده
بعد دوباره برمیگرده
حالا Opcode بعدی (02) رو میخونه و Handler مربوط به ADD اجرا میشه
دوباره برمیگرده
در آخر Opcode 03 اجرا میشه
در تمام این مدت فقط Dispatcher داره تصمیم میگیره مرحله بعدی چیه
به همین خاطر بهش میگن قلب ماشین مجازی
در اکثر ماشینهای مجازی این چرخه دائماً
تکرار میشه:
خواندن Opcode
تشخیص نوع Opcode
اجرای Handler
برگشت به Dispatcher
خواندن Opcode بعدی
به این چرخه معمولا Fetch → Decode → Execute گفته میشه
تقریبا تمام CPU های دنیا هم با همین ایده کار میکنن
تنها تفاوت اینه که CPU دستورهای واقعی پردازنده رو اجرا میکنه ولی ماشین مجازی دستورهای اختصاصی خودش رو
وقتی Dispatcher رو داخل دیس اسمبل پیدا کنید معمولا چند نشونه میبینی:
یک حلقه که دائما تکرار میشه
خواندن یک بایت از حافظه یا جدول Opcode ها
یک پرش غیرمستقیم یا انتخاب بین چند Handler
برگشت دوباره به ابتدای حلقه
به همین دلیل تحلیلگرها معمولا از Dispatcher شروع میکنن چون تمام مسیرهای اجرا از اون عبور میکنن
تمرین:
یک برنامه ساده بنویس که فقط سه Opcode داشته باشه:
LOAD
XOR
بعد Dispatcher اونو رسم کنید
لازم نیست کد بنویسید فقط روی کاغذ مشخص کنید هر Opcode بعد از Dispatcher به کجا میره
وقتی این مفهوم رو کاملا درک کنید فهمیدن ماشینهای مجازی پیچیده مثل VMProtect خیلی سادهتر میشه
Dispatcher is the heart of the virtual machine
If you want to analyze only one part of VMProtect or any Virtual Machine, that part is Dispatcher
Dispatcher
is responsible for deciding which Opcode should be executed now
Without Dispatcher, no Opcode can be executed
Suppose we have this byte code:
01 10
02 20
03
Here:
01 means LOAD
02 means ADD
03 means PRINT
Dispatcher
reads the first byte (01) and recognizes that the Opcode is of type LOAD and passes control to the Handler related to LOAD
Then it returns again
Now it reads the next Opcode (02) and the Handler related to ADD is executed
It returns again
Finally, Opcode 03 is executed
All this time, only Dispatcher is deciding what the next step is
That is why it is called the heart of the virtual machine
In most virtual machines, this cycle
is constantly
repeated:
Reading Opcode
Determining type Opcode
Execution of Handler
Return to Dispatcher
Read next Opcode
This cycle is usually called Fetch → Decode → Execute
Almost all CPUs in the world work with the same idea
The only difference is that the CPU executes the actual processor instructions, but the virtual machine executes its own instructions
When you find the Dispatcher in the disassembler, you will usually see a few signs:
A loop that repeats itself over and over
Reading a byte from memory or the Opcode table
An indirect jump or selection between several Handlers
Return to the beginning of the loop
That is why analysts usually start with the Dispatcher because all execution paths pass through it
Exercise:
Write a simple program that has only three Opcodes:
LOAD
XOR
Then draw the Dispatcher
You don't need to write the code, just mark on paper where each Opcode goes after the Dispatcher
Once you fully understand this concept, understanding machines Complex virtualization like VMProtect becomes much simpler
@reverseengine
🔥1
Persistence ماندگاری داده
فرض کنید فایل زیر رو ذخیره میکنید:
report.docx
بعد سیستم رو خاموش میکنید
روز بعد دوباره روشن میکنید
فایل هنوز وجود داره
چرا؟
چون داده روی حافظه دائمی ذخیره شده
اگر سیستمعامل Persistence نداشت:
با خاموش شدن سیستم همه چیز پاک میشد
هیچ فایلی وجود نداشت
هیچ دیتابیسی وجود نداشت
وظیفه سیستمعامل
سیستمعامل باید:
فایلها رو ذخیره میکنن
پوشهها رو مدیریت میکنن
خرابی اطلاعات رو کاهش میده
عملیات دیسک رو مدیریت میکنن
چرا برای مهندسی معکوس مهمه؟
چون بدافزارها و برنامهها دائما با موارد زیر کار میکنن:
اگر File System رو نفهمید تحلیل بسیاری از رفتارهای برنامه سخت میشه
Persistence of data
Suppose you save the following file:
report.docx
Then you shut down the system
You turn it back on the next day
The file still exists
Why?
Because the data is stored in permanent memory
If the operating system did not have persistence:
Everything would be erased when the system was shut down
There would be no files
There would be no databases
Operating system tasks
The operating system must:
Store files
Manage folders
Reduce data corruption
Manage disk operations
Why is it important for reverse engineering?
Because malware and programs constantly work with:
If you do not understand the File System, it becomes difficult to analyze many of the behavior of the program
@reverseengine
فرض کنید فایل زیر رو ذخیره میکنید:
report.docx
بعد سیستم رو خاموش میکنید
روز بعد دوباره روشن میکنید
فایل هنوز وجود داره
چرا؟
چون داده روی حافظه دائمی ذخیره شده
اگر سیستمعامل Persistence نداشت:
با خاموش شدن سیستم همه چیز پاک میشد
هیچ فایلی وجود نداشت
هیچ دیتابیسی وجود نداشت
وظیفه سیستمعامل
سیستمعامل باید:
فایلها رو ذخیره میکنن
پوشهها رو مدیریت میکنن
خرابی اطلاعات رو کاهش میده
عملیات دیسک رو مدیریت میکنن
چرا برای مهندسی معکوس مهمه؟
چون بدافزارها و برنامهها دائما با موارد زیر کار میکنن:
Files
Registry
Logs
Databases
Disk I/O
اگر File System رو نفهمید تحلیل بسیاری از رفتارهای برنامه سخت میشه
Persistence of data
Suppose you save the following file:
report.docx
Then you shut down the system
You turn it back on the next day
The file still exists
Why?
Because the data is stored in permanent memory
If the operating system did not have persistence:
Everything would be erased when the system was shut down
There would be no files
There would be no databases
Operating system tasks
The operating system must:
Store files
Manage folders
Reduce data corruption
Manage disk operations
Why is it important for reverse engineering?
Because malware and programs constantly work with:
Files
Registry
Logs
Databases
Disk I/O
If you do not understand the File System, it becomes difficult to analyze many of the behavior of the program
@reverseengine
بخش نوزدهم بافر اورفلو
Heap Overflow
از دید یک Reverse Engineer
تا الان بیشتر با استک کار کردیم
ولی خیلی از آسیب پذیری های واقعی روی Heap اتفاق میوفتن
قبل از اینکه بخوایم Heap Overflow رو تحلیل کنیم باید اول خود Heap رو بشناسیم
Heap اصلا چیه
بخشی از حافظه است که برنامه موقع اجرا هر وقت به حافظه بیشتری نیاز داشته باشه ازش استفاده میکنه
برخلاف Stack که خودکار مدیریت میشه
Heap کاملا تحت کنترل برنامه است
یعنی برنامه خودش درخواست حافظه میده
بعد هم خودش باید آزادش کنه
دو تابعی که همیشه میبینید
تقریبا تو هر برنامه C این دو تابع رو میبینید
malloc() free() malloc حافظه رزرو میکنه
free هم همون حافظه رو آزاد میکنه
یک مثال ساده:
#include <stdlib.h> int main() { char *buf = malloc(32); free(buf); return 0; }
پشت صحنه چه اتفاقی میوفته
وقتی malloc(32) صدا زده میشه
برنامه فقط 32 بایت داده نمیگیره
کتابخانه مدیریت حافظه کنار اون داده یکسری اطلاعات مدیریتی هم ذخیره میکنه
به این مجموعه معمولا میگن Chunk
هر Chunk دو بخش داره
اطلاعات مدیریتی
دادهای که برنامه ازش استفاده میکنه
از دید مهندسی معکوس
وقتی داخل Ghidra یا IDA تابعی مثل این رو ببینید
char *buf = malloc(64)strcpy(buf, input)memcpy(buf, input, len)باید بررسی کنید
آیا اندازه ورودی واقعا با اندازه Chunk یکیه یا نه
فرق Heap Overflow با Stack Overflow
در Stack Overflow معمولا هدف Return Address بود
ولی در Heap Overflow معمولا Return Address وجود نداره
در عوض چیزی که اهمیت داره ساختار Heap و دادههای کنار حافظه است
به همین خاطر روش تحلیل این دو کاملا فرق میکنه
موقع آنالیز باینری دنبال چی بگردیم
اگر این الگوها رو دیدید بیشتر دقت کنید
malloc(...) بعد از اون
strcpy(...)
یا
memcpy(...)
یا
read(...) اگر اندازه ورودی کنترل نشده باشه
احتمال وجود Heap Overflow بیشتر میشه
نکته مهم
هر جا malloc دیدید به معنی آسیب پذیری نیست
باید ببینید
چقدر حافظه گرفته شده
چقدر داده داخلش نوشته میشه
آیا قبل از نوشتن بررسی اندازه انجام شده یا نه
Heap با Stack فرق داره
حافظه Heap با malloc گرفته میشه
هر قطعه حافظه یک Chunk داره
و در مهندسی معکوس باید مسیر
ورودی → malloc → نوشتن داده
رو دنبال کنیم
چالش این قسمت:
یک برنامه ساده که از malloc استفاده میکنه داخل Ghidra باز کنید
مسیر حرکت داده از ورودی تا حافظه Heap رو پیدا کنید و مشخص کنید داده دقیقا کجا نوشته میشه
@reverseengine
ReverseEngineering
بخش نوزدهم بافر اورفلو Heap Overflow از دید یک Reverse Engineer تا الان بیشتر با استک کار کردیم ولی خیلی از آسیب پذیری های واقعی روی Heap اتفاق میوفتن قبل از اینکه بخوایم Heap Overflow رو تحلیل کنیم باید اول خود Heap رو بشناسیم Heap اصلا چیه بخشی از…
Part 19 Buffer Overflow
Heap Overflow
From a Reverse Engineer's Perspective
So far, we have worked mostly with the stack
But many real vulnerabilities occur on the heap
Before we try to analyze heap overflow, we must first understand the heap itself
What is the heap?
It is a part of memory that the program uses whenever it needs more memory during execution
Unlike the stack, which is automatically managed
The heap is completely under the control of the program
That is, the program itself requests memory
Then it must free it
Two functions that you always see
You will see these two functions in almost every C program
malloc() free()
malloc reserves memory
free also frees the same memory
A simple example:
#include <stdlib.h> int main() { char *buf = malloc(32); free(buf); return 0; }
What happens behind the scenes
When malloc(32) is called
The program doesn't just get 32 bytes of data
The memory management library also stores some management information along with that data
This collection is usually called a Chunk
Each Chunk has two parts
Management information
Data that the program uses
From a reverse engineering perspective
When you see a function like this in Ghidra or IDA
char *buf = malloc(64)
strcpy(buf, input)
memcpy(buf, input, len)
You need to check
Is the input size really the same as the Chunk size or not
The difference between Heap Overflow and Stack Overflow
In Stack Overflow, the target was usually the Return Address
But in Heap Overflow, there is usually no Return Address
Instead, what matters is the structure of the Heap and the data next to the memory
That's why the analysis method for these two is completely different
What to look for when analyzing binary Let's look
If you see these patterns, pay more attention
malloc(...)
After that
strcpy(...)
or
memcpy(...)
or
read(...)
If the input size is not controlled
The probability of Heap Overflow increases
Important point
Wherever you see malloc, it does not mean a vulnerability
You need to see
How much memory is taken
How much data is written into it
Whether the size check is done before writing
Heap is different from Stack
Heap memory is taken with malloc
Each piece of memory has a Chunk
And in reverse engineering, we need to follow the path
Input → malloc → writing data
Challenge of this part:
Open a simple program that uses malloc in Ghidra
Find the path of data movement from input to Heap memory and determine where exactly the data is written
@reverseengine
Windows Process Injection: Print Spooler
https://modexp.wordpress.com/2019/03/07/process-injection-print-spooler
https://modexp.wordpress.com/2019/03/07/process-injection-print-spooler
modexp
Windows Process Injection: Print Spooler
Introduction Every application running on the windows operating system has a thread pool or a “worker factory” and this internal mechanism allows an application to offload management of…
درود دوستان امیدوارم حالتون خوب باشه اگر این چند روز زیاد فعال نیستم و اینکه پست نمیذارم به دلیل جام جهانیه و اینکه ساعتشون با کشور ما متاسفانه یکی نیست و یه سری مشکلات هست که برام پیش اومده وقتی که اوکی شد دوباره پر قدرت برمیگردیم زیاد طول نمیکشه چند روز دیگه برمیگردم دوستون دارم
Alone. 🩶
Hello friends, I hope you are well. If I haven't been very active these past few days, and I haven't been posting, it's because of the World Cup, and unfortunately their time zone is not the same as ours, and there are a number of problems that have come up for me. When it's OK, we'll be back with full force again. It won't be long. I'll be back in a few days. I love you all,
Alone. 🖤
Alone. 🩶
Hello friends, I hope you are well. If I haven't been very active these past few days, and I haven't been posting, it's because of the World Cup, and unfortunately their time zone is not the same as ours, and there are a number of problems that have come up for me. When it's OK, we'll be back with full force again. It won't be long. I'll be back in a few days. I love you all,
Alone. 🖤
❤10
ReverseEngineering
درود دوستان امیدوارم حالتون خوب باشه اگر این چند روز زیاد فعال نیستم و اینکه پست نمیذارم به دلیل جام جهانیه و اینکه ساعتشون با کشور ما متاسفانه یکی نیست و یه سری مشکلات هست که برام پیش اومده وقتی که اوکی شد دوباره پر قدرت برمیگردیم زیاد طول نمیکشه چند روز…
امشب دوباره شروع میکنیم.
We start again tonight.
We start again tonight.
🔥7
Handler
جایی که کار واقعی انجام میشه
تو پست قبل گفتیم Dispatcher فقط تصمیم میگیره کدوم Opcode اجرا بشه
اما خودش هیچ کار خاصی انجام نمیده
کار اصلی داخل Handler ها انجام میشه
هر Opcode حداقل یک Handler داره
مثلا فرض کنید این بایت کد رو داریم:
اگر معنی Opcode ها این باشه:
اتفاقی که میوفته اینه:
Dispatcher
مقدار 01 رو میبینه و Handler مربوط به LOAD اجرا میشه
داخل Handler مقدار 05 داخل یکی از رجیسترهای مجازی ذخیره میشه
بعد کنترل دوباره برمیگرده به Dispatcher
این بار Dispatcher مقدار 02 رو میخونه
Handler
مربوط به ADD اجرا میشه و عدد 03 به مقدار قبلی اضافه میشه
دوباره کنترل برمیگرده به Dispatcher
در آخر Opcode 03 اجرا میشه
Handler
مربوط به PRINT مقدار نهایی رو چاپ میکنه
پس همیشه این چرخه تکرار میشه:
Dispatcher ↓ Handler ↓ Dispatcher ↓ Handler ↓ Dispatcher
نکته مهم اینجاست که همه Handler ها شبیه هم نیستن
بعضی ها فقط یک مقدار رو جا به جا میکنن
بعضی ها عملیات ریاضی انجام میدن
بعضی ها پرش شرطی انجام میدن
بعضی ها حافظه رو میخونن یا مینویسن
در ماشین های مجازی واقعی مثل VMProtect ممکنه صدها Handler مختلف وجود داشته باشه
به همین خاطر اولین کاری که تحلیلگر انجام میده دستهبندی Handler هاست
مثلا بعد از بررسی چندتا از اونا متوجه میشه:
این Handler همیشه داده رو جا به جا میکنه
اون یکی همیشه عملیات XOR انجام میده
یکی دیگه همیشه مقدارها رو با هم مقایسه میکنه
یکی هم مسئول پرش های شرطیه
کم کم با کنار هم گذاشتن این اطلاعات معنی Opcode ها مشخص میشه
این دقیقا همون چیزیه که بهش Opcode Mapping میگن
یعنی ساختن یک جدول که مشخص کنه هر Opcode چه کاری انجام میده
تمرین
یک جدول برای Opcode های زیر درست کنید:
بعد سعی کنبد برای هر Opcode بنویسید Handler اون باید چکاری انجام بده
این تمرین باعث میشه ذهنتون دقیقا مثل یک تحلیلگر Devirtualization شروع به فکر کردن کنه
Handler
Where the real work is done
In the previous post, we said that Dispatcher only decides which Opcode to execute
But it doesn't do anything special
The main work is done inside Handlers
Each Opcode has at least one Handler
For example, suppose we have this bytecode:
If the meaning of the Opcodes is:
What happens is this:
Dispatcher
Sees the value 01 and the Handler corresponding to LOAD is executed
Inside the Handler, the value 05 is stored in one of the virtual registers
Then control returns to Dispatcher
This time Dispatcher reads the value 02
Handler
Related to ADD is executed and the number 03 is added to the previous value
Control returns to Dispatcher again
Finally, Opcode 03 is executed
Handler
Related to PRINT Prints the final value
So this cycle always repeats:
The important thing here is that not all Handlers are the same
Some just move a value
Some perform mathematical operations
Some perform conditional jumps
Some read or write memory.
In real virtual machines like VMProtect, there may be hundreds of different Handlers
That is why the first thing the analyst does is to categorize the Handlers
For example, after examining a few of them, he will notice:
This Handler always moves data
That one always performs XOR operations
Another always compares values
One is responsible for conditional jumps
Little by little, by putting this information together, the meaning of the Opcodes becomes clear
This is exactly what is called Opcode Mapping
That is, creating a table that specifies what each Opcode does
Exercise:
Create a table for the following Opcodes:
Then try to write for each Opcode what its Handler should do
This exercise will make your mind start thinking exactly like a Devirtualization analyst
@reverseengine
جایی که کار واقعی انجام میشه
تو پست قبل گفتیم Dispatcher فقط تصمیم میگیره کدوم Opcode اجرا بشه
اما خودش هیچ کار خاصی انجام نمیده
کار اصلی داخل Handler ها انجام میشه
هر Opcode حداقل یک Handler داره
مثلا فرض کنید این بایت کد رو داریم:
01 05 02 03 03
اگر معنی Opcode ها این باشه:
01 = LOAD
02 = ADD
03 = PRINT
اتفاقی که میوفته اینه:
Dispatcher
مقدار 01 رو میبینه و Handler مربوط به LOAD اجرا میشه
داخل Handler مقدار 05 داخل یکی از رجیسترهای مجازی ذخیره میشه
بعد کنترل دوباره برمیگرده به Dispatcher
این بار Dispatcher مقدار 02 رو میخونه
Handler
مربوط به ADD اجرا میشه و عدد 03 به مقدار قبلی اضافه میشه
دوباره کنترل برمیگرده به Dispatcher
در آخر Opcode 03 اجرا میشه
Handler
مربوط به PRINT مقدار نهایی رو چاپ میکنه
پس همیشه این چرخه تکرار میشه:
Dispatcher ↓ Handler ↓ Dispatcher ↓ Handler ↓ Dispatcher
نکته مهم اینجاست که همه Handler ها شبیه هم نیستن
بعضی ها فقط یک مقدار رو جا به جا میکنن
بعضی ها عملیات ریاضی انجام میدن
بعضی ها پرش شرطی انجام میدن
بعضی ها حافظه رو میخونن یا مینویسن
در ماشین های مجازی واقعی مثل VMProtect ممکنه صدها Handler مختلف وجود داشته باشه
به همین خاطر اولین کاری که تحلیلگر انجام میده دستهبندی Handler هاست
مثلا بعد از بررسی چندتا از اونا متوجه میشه:
این Handler همیشه داده رو جا به جا میکنه
اون یکی همیشه عملیات XOR انجام میده
یکی دیگه همیشه مقدارها رو با هم مقایسه میکنه
یکی هم مسئول پرش های شرطیه
کم کم با کنار هم گذاشتن این اطلاعات معنی Opcode ها مشخص میشه
این دقیقا همون چیزیه که بهش Opcode Mapping میگن
یعنی ساختن یک جدول که مشخص کنه هر Opcode چه کاری انجام میده
تمرین
یک جدول برای Opcode های زیر درست کنید:
01 → LOAD 02 → ADD 03 → XOR 04 → CMP 05 → JMP 06 → PRINT
بعد سعی کنبد برای هر Opcode بنویسید Handler اون باید چکاری انجام بده
این تمرین باعث میشه ذهنتون دقیقا مثل یک تحلیلگر Devirtualization شروع به فکر کردن کنه
Handler
Where the real work is done
In the previous post, we said that Dispatcher only decides which Opcode to execute
But it doesn't do anything special
The main work is done inside Handlers
Each Opcode has at least one Handler
For example, suppose we have this bytecode:
01 05 02 03 03
If the meaning of the Opcodes is:
01 = LOAD
02 = ADD
03 = PRINT
What happens is this:
Dispatcher
Sees the value 01 and the Handler corresponding to LOAD is executed
Inside the Handler, the value 05 is stored in one of the virtual registers
Then control returns to Dispatcher
This time Dispatcher reads the value 02
Handler
Related to ADD is executed and the number 03 is added to the previous value
Control returns to Dispatcher again
Finally, Opcode 03 is executed
Handler
Related to PRINT Prints the final value
So this cycle always repeats:
Dispatcher ↓ Handler ↓ Dispatcher ↓ Handler ↓ Dispatcher
The important thing here is that not all Handlers are the same
Some just move a value
Some perform mathematical operations
Some perform conditional jumps
Some read or write memory.
In real virtual machines like VMProtect, there may be hundreds of different Handlers
That is why the first thing the analyst does is to categorize the Handlers
For example, after examining a few of them, he will notice:
This Handler always moves data
That one always performs XOR operations
Another always compares values
One is responsible for conditional jumps
Little by little, by putting this information together, the meaning of the Opcodes becomes clear
This is exactly what is called Opcode Mapping
That is, creating a table that specifies what each Opcode does
Exercise:
Create a table for the following Opcodes:
01 → LOAD 02 → ADD 03 → XOR 04 → CMP 05 → JMP 06 → PRINT
Then try to write for each Opcode what its Handler should do
This exercise will make your mind start thinking exactly like a Devirtualization analyst
@reverseengine
وقتی روی یک برنامه دوبار کلیک میکنید پشت صحنه چه اتفاقی میوفته؟
تا اینجا فهمیدیم Process چیه و داخلش چه بخش هایی وجود داره
حالا یک سوال جالب:
وقتی روی notepad.exe یا chrome.exe دوبار کلیک میکنید دقیقا چه اتفاقی میوفته؟
همه این مراحل در چند میلی ثانیه انجام میشن اما پشت صحنه کارهای زیادی انجام میشه
مرحله 1: پیدا کردن فایل اجرایی
اول سیستمعامل فایل برنامه را روی دیسک پیدا میکنه
مثلا:
در این مرحله هنوز هیچ کدی اجرا نشده فقط فایل پیدا شده
مرحله 2: ساختن Process
حالا کرنل یک Process جدید ایجاد میکنه
برای این Process اطلاعاتی مثل:
رو آماده میکنه
از این لحظه سیستم عامل میتونه این برنامه رو مدیریت کنه
مرحله 3: ایجاد فضای حافظه
حالا سیستم عامل یک Virtual Address Space برای Process میسازه
یعنی یک فضای حافظه اختصاصی که فقط متعلق به همین Process هست.
در این فضا بخش هایی مثل:
قرار میگیرن
نکته مهم اینجاست که هر Process فضای حافظه مخصوص خودش رو داره و معمولا نمیتونه مستقیما به حافظه Process دیگه ای دسترسی پیدا کنه
مرحله 4: بارگذاری فایل اجرایی
حالا سیستم عامل فایل اجرایی رو داخل حافظه اپلود میکنه
بخش های مختلف فایل مثل کد و دادهها در جای مناسب خودشون قرار میگیرن
اگر برنامه به کتابخانه هایی مثل DLL نیاز داشته باشه اونا هم در همین مرحله اپلود میشن
مرحله 5: آماده شدن Thread اصلی
هر Process حداقل یک Thread داره
که به اون Main Thread میگن
این Thread از اولین دستور برنامه شروع به اجرا مبکنه بعدا اگر برنامه لازم داشته باشه میتونه Thread های بیشتری بسازه
مرحله 6: شروع اجرای برنامه
حالا CPU اجرای اولین دستور برنامه رو شروع میکنه
از این لحظه به بعد برنامه واقعا در حال اجراست
یک مثال واقعی:
فرض کنید روی Google Chrome کلیک میکنید
در چند لحظه:
✅ فایل Chrome پیدا میشه
✅ یک Process جدید ساخته میشه
✅ حافظه اختصاصی برای اون ایجاد میشه
✅ فایل اجرایی و DLL های مورد نیاز اپلود میشن
✅ Main Thread ساخته میشه
✅ اولین دستور Chrome اجرا میشه
همه این مراحل اونقدر سریع انجام میشن که کاربر فقط باز شدن پنجره مرورگر رو میبینه
چرا این موضوع برای مهندسی معکوس مهمه؟
وقتی در ابزارهایی مثل دیباگر یا تحلیل بدافزار کار میکنید باید بدونید برنامه از لحظه اجرا چه مراحلی رو طی کرده
برای مثال بیشتر بدافزارها:
قبل از اجرای کد اصلی DLL های خاصی رو اپلود میکنن
در همون ابتدای اجرا چند Thread جدید میسازن
حافظه جدید اختصاص میدن و کد خودشون رو در اون قرار میدن
اگر فرآیند ایجاد Process رو بشناسید تحلیل چنین رفتار هایی بسیار ساده تر میشه
What happens behind the scenes when you double-click on a program?
So far we have understood what a Process is and what parts it contains
Now an interesting question:
What exactly happens when you double-click on notepad.exe or chrome.exe?
All these steps are done in a few milliseconds, but a lot of work is done behind the scenes
Step 1: Finding the executable file
First, the operating system finds the program file on the disk
For example:
At this stage, no code is executed yet, only the file is found
Step 2: Creating a Process
Now the kernel creates a new Process
For this Process, it provides information such as:
From this moment, the operating system can manage this program
Step 3: Creating a memory space
Now the operating system creates a Virtual Address Space for the Process
That is, a dedicated memory space that belongs only to this Process.
In this space, sections such as:
The important point here is that each Process has its own memory space and usually cannot directly access the memory of another Process
Step 4: Loading the executable file
Now the operating system uploads the executable file into memory
Different parts of the file such as code and data are placed in their appropriate places
If the program needs libraries such as DLLs, they are also uploaded at this stage
Step 5: Preparing the main thread
Each process has at least one thread
which is called the main thread
تا اینجا فهمیدیم Process چیه و داخلش چه بخش هایی وجود داره
حالا یک سوال جالب:
وقتی روی notepad.exe یا chrome.exe دوبار کلیک میکنید دقیقا چه اتفاقی میوفته؟
همه این مراحل در چند میلی ثانیه انجام میشن اما پشت صحنه کارهای زیادی انجام میشه
مرحله 1: پیدا کردن فایل اجرایی
اول سیستمعامل فایل برنامه را روی دیسک پیدا میکنه
مثلا:
C:\Windows\System32\notepad.exe
در این مرحله هنوز هیچ کدی اجرا نشده فقط فایل پیدا شده
مرحله 2: ساختن Process
حالا کرنل یک Process جدید ایجاد میکنه
برای این Process اطلاعاتی مثل:
شناسه پردازه (PID)
وضعیت پردازه
اطلاعات زمان بندی
مجوزهای دسترسی
رو آماده میکنه
از این لحظه سیستم عامل میتونه این برنامه رو مدیریت کنه
مرحله 3: ایجاد فضای حافظه
حالا سیستم عامل یک Virtual Address Space برای Process میسازه
یعنی یک فضای حافظه اختصاصی که فقط متعلق به همین Process هست.
در این فضا بخش هایی مثل:
Code
Data
Heap
Stack
قرار میگیرن
نکته مهم اینجاست که هر Process فضای حافظه مخصوص خودش رو داره و معمولا نمیتونه مستقیما به حافظه Process دیگه ای دسترسی پیدا کنه
مرحله 4: بارگذاری فایل اجرایی
حالا سیستم عامل فایل اجرایی رو داخل حافظه اپلود میکنه
بخش های مختلف فایل مثل کد و دادهها در جای مناسب خودشون قرار میگیرن
اگر برنامه به کتابخانه هایی مثل DLL نیاز داشته باشه اونا هم در همین مرحله اپلود میشن
مرحله 5: آماده شدن Thread اصلی
هر Process حداقل یک Thread داره
که به اون Main Thread میگن
این Thread از اولین دستور برنامه شروع به اجرا مبکنه بعدا اگر برنامه لازم داشته باشه میتونه Thread های بیشتری بسازه
مرحله 6: شروع اجرای برنامه
حالا CPU اجرای اولین دستور برنامه رو شروع میکنه
از این لحظه به بعد برنامه واقعا در حال اجراست
یک مثال واقعی:
فرض کنید روی Google Chrome کلیک میکنید
در چند لحظه:
✅ فایل Chrome پیدا میشه
✅ یک Process جدید ساخته میشه
✅ حافظه اختصاصی برای اون ایجاد میشه
✅ فایل اجرایی و DLL های مورد نیاز اپلود میشن
✅ Main Thread ساخته میشه
✅ اولین دستور Chrome اجرا میشه
همه این مراحل اونقدر سریع انجام میشن که کاربر فقط باز شدن پنجره مرورگر رو میبینه
چرا این موضوع برای مهندسی معکوس مهمه؟
وقتی در ابزارهایی مثل دیباگر یا تحلیل بدافزار کار میکنید باید بدونید برنامه از لحظه اجرا چه مراحلی رو طی کرده
برای مثال بیشتر بدافزارها:
قبل از اجرای کد اصلی DLL های خاصی رو اپلود میکنن
در همون ابتدای اجرا چند Thread جدید میسازن
حافظه جدید اختصاص میدن و کد خودشون رو در اون قرار میدن
اگر فرآیند ایجاد Process رو بشناسید تحلیل چنین رفتار هایی بسیار ساده تر میشه
What happens behind the scenes when you double-click on a program?
So far we have understood what a Process is and what parts it contains
Now an interesting question:
What exactly happens when you double-click on notepad.exe or chrome.exe?
All these steps are done in a few milliseconds, but a lot of work is done behind the scenes
Step 1: Finding the executable file
First, the operating system finds the program file on the disk
For example:
C:\Windows\System32\notepad.exe
At this stage, no code is executed yet, only the file is found
Step 2: Creating a Process
Now the kernel creates a new Process
For this Process, it provides information such as:
Process ID (PID)
Process status
Scheduling information
Access permissions
From this moment, the operating system can manage this program
Step 3: Creating a memory space
Now the operating system creates a Virtual Address Space for the Process
That is, a dedicated memory space that belongs only to this Process.
In this space, sections such as:
Code
Data
Heap
Stack
The important point here is that each Process has its own memory space and usually cannot directly access the memory of another Process
Step 4: Loading the executable file
Now the operating system uploads the executable file into memory
Different parts of the file such as code and data are placed in their appropriate places
If the program needs libraries such as DLLs, they are also uploaded at this stage
Step 5: Preparing the main thread
Each process has at least one thread
which is called the main thread
This thread starts executing from the first command of the program, and later if the program needs it, it can create more threads
Step 6: Starting the program
Now the CPU starts executing the first command of the program
From this moment on, the program is really running
A real example:
Suppose you click on Google Chrome
In a few moments:
✅ The Chrome file is found
✅ A new process is created
✅ Dedicated memory is created for it
✅ The executable and required DLLs are uploaded
✅ The main thread is created
✅ The first Chrome command is executed
All these steps are done so quickly that the user only sees the browser window opening
Why is this important for reverse engineering?
When working in tools such as debuggers or malware analysis, you need to know what steps the program has taken since execution
For example, most malware:
Uploads specific DLLs before executing the main code
Creates several new threads at the very beginning of execution
Allocates new memory and places its code in it
If you understand the process of process creation, analyzing such behavior becomes much easier
@reverseengine
Step 6: Starting the program
Now the CPU starts executing the first command of the program
From this moment on, the program is really running
A real example:
Suppose you click on Google Chrome
In a few moments:
✅ The Chrome file is found
✅ A new process is created
✅ Dedicated memory is created for it
✅ The executable and required DLLs are uploaded
✅ The main thread is created
✅ The first Chrome command is executed
All these steps are done so quickly that the user only sees the browser window opening
Why is this important for reverse engineering?
When working in tools such as debuggers or malware analysis, you need to know what steps the program has taken since execution
For example, most malware:
Uploads specific DLLs before executing the main code
Creates several new threads at the very beginning of execution
Allocates new memory and places its code in it
If you understand the process of process creation, analyzing such behavior becomes much easier
@reverseengine
EDR
ها چطور حملات رو تشخیص میدن؟
خیلی ها فکر میکنن EDR فقط دنبال امضای فایل یا اسم API ها هستن ولی واقعیت اینه که نسل جدید EDR ها بیشتر روی رفتار تمرکز دارن
اگر یه برنامه این کارها رو انجام بده:
یک پروسه جدید ایجاد میکنه
حافظه قابل اجرا (Executable Memory) رزرو میکنه
داخل اون حافظه داده مینویسه
یک Thread جدید اجرا میکنه
ممکنه هیچ فایل مخربی روی دیسک وجود نداشته باشه اما همین زنجیره رفتارها میتونه امتیاز ریسک بالایی ایجاد کنه
EDR
ها به چه چیزایی دقت میکنن؟
چرا فقط یک رفتار کافی نیست؟
مثلا:
هر کدوم از اینها به تنهایی ممکنه طبیعی باشن اما وقتی پشت سر هم باشن برای EDR یک الگوی مشکوک ایجاد میکنن
تشخیص دادن
نسل جدید EDR ها معمولا از مدل های رفتاری استفاده میکنن نه فقط Signature
به همین دلیل ممکنه دو فایل کاملا متفاوت اگر رفتار مشابهی داشته باشن هر دو شناسایی بشن
How EDRs Detect Attacks?
Many people think that EDRs only look for file signatures or API names, but the truth is that the new generation of EDRs focuses more on behavior
If a program does these things:
There may not be any malicious files on disk, but this chain of behavior can generate a high risk score
What do EDRs look for?
Why is just one behavior not enough?
For example:
Each of these may be normal on their own, but when they are in a row, they create a suspicious pattern for EDR
Detection
Newer generation EDRs usually use behavioral models, not just Signature
That's why two completely different files may both be detected if they have similar behavior
@reverseengine
ها چطور حملات رو تشخیص میدن؟
خیلی ها فکر میکنن EDR فقط دنبال امضای فایل یا اسم API ها هستن ولی واقعیت اینه که نسل جدید EDR ها بیشتر روی رفتار تمرکز دارن
اگر یه برنامه این کارها رو انجام بده:
یک پروسه جدید ایجاد میکنه
حافظه قابل اجرا (Executable Memory) رزرو میکنه
داخل اون حافظه داده مینویسه
یک Thread جدید اجرا میکنه
ممکنه هیچ فایل مخربی روی دیسک وجود نداشته باشه اما همین زنجیره رفتارها میتونه امتیاز ریسک بالایی ایجاد کنه
EDR
ها به چه چیزایی دقت میکنن؟
ارتباط بین پروسهها (Process Tree)
ترتیب رخدادها (Event Correlation)
دسترسی های غیرعادی به حافظه
اپلود DLL های غیرمنتظره
تغییرات در Tokenها و دسترسیها
الگوهای ارتباط شبکه
اطلاعات تله متری ویندوز مثل ETW
چرا فقط یک رفتار کافی نیست؟
مثلا:
Process Created
↓
Memory Allocation
↓
Memory Write
↓
Thread Execution
هر کدوم از اینها به تنهایی ممکنه طبیعی باشن اما وقتی پشت سر هم باشن برای EDR یک الگوی مشکوک ایجاد میکنن
تشخیص دادن
نسل جدید EDR ها معمولا از مدل های رفتاری استفاده میکنن نه فقط Signature
به همین دلیل ممکنه دو فایل کاملا متفاوت اگر رفتار مشابهی داشته باشن هر دو شناسایی بشن
How EDRs Detect Attacks?
Many people think that EDRs only look for file signatures or API names, but the truth is that the new generation of EDRs focuses more on behavior
If a program does these things:
Creates a new process
Reserves executable memory
Writes data into that memory
Runs a new thread
There may not be any malicious files on disk, but this chain of behavior can generate a high risk score
What do EDRs look for?
Process Tree
Event Correlation
Unusual Memory Access
Unexpected DLL Uploads
Token Changes and Accesses
Network Communication Patterns
Windows Telemetry Information like ETW
Why is just one behavior not enough?
For example:
Process Created
↓
Memory Allocation
↓
Memory Write
↓
Thread Execution
Each of these may be normal on their own, but when they are in a row, they create a suspicious pattern for EDR
Detection
Newer generation EDRs usually use behavioral models, not just Signature
That's why two completely different files may both be detected if they have similar behavior
@reverseengine
🔥1
Accelerating EDR Evasion with LLM-Driven Analysis
https://specterops.io/blog/2026/06/29/llm-powered-edr-analysis/#
https://specterops.io/blog/2026/06/29/llm-powered-edr-analysis/#
https://specterops.io/blog/2026/06/29/llm-powered-edr-analysisSpecterOps
Accelerating EDR Evasion with LLM-Driven Analysis
SpecterOps reverse engineered Cortex XDR with LLMs to extract YARA rules, ML models, and behavioral detections.