ru
Feedback

Не попадитесь на канал ботавода! Telemetrio находит и помечает такие каналы 👉 Хотите видеть метку — оформите подписку

ReverseEngineering

ReverseEngineering

Открыть в Telegram
1 730
Подписчики
-124 часа
-47 дней
+28230 дней
Архив постов
API Call Tracing and Runtime Behavior Analysis How to Understand the Real Behavior of a Program Based on the Order of API Calls So far we have talked about Export Table and GetProcAddress function and how to find the address of functions in DLLs Now we want to enter the next step API Call Tracing That is, we examine what APIs a program calls at runtime and what is the order of these calls and how these functions are related to each other API Call Tracing Suppose we run a program and see these calls
CreateFileW
|
v
ReadFile
|
v
VirtualAlloc
|
v
WriteProcessMemory
|
v
CreateThread
Each of these APIs has a specific task But when we examine them together, we can get more information about the behavior of the program The process of observing and analyzing API calls at runtime is called API Call Tracing The important point is that just seeing the names of the APIs is not enough, we need to know under what circumstances each call occurred and what the result was Why is the order of API calls important Suppose we only see this API in a program
This function is used to allocate virtual memory space
This call itself is quite common and many programs use it
Now suppose several events are recorded in a row
VirtualAlloc | v Memory Write | v VirtualProtect | v Thread Activity
Here we have more information
We can check
Under what conditions the memory was allocated
What information was written inside it
Whether the memory permission has changed
Whether a new thread has been created
What is the Call Stack
Related to this activity
So the order of events can have a different meaning than observing each API separately
Of course, we should note that these events do not necessarily all come from a specific API and may be collected from different sources
Difference between API Monitoring and API Call Tracing
These two terms are close to each other, but analytically we can differentiate between them

For example, Monitoring can record that a Process has called the CreateFileW function
But Tracing helps us examine this event along with previous and subsequent calls
In fact, Monitoring collects information and Tracing helps us better understand the flow of program execution

What does Call Stack
Helps
One of the most important information that can help us when examining an API Call is the Call Stack

Suppose the program has a function like VirtualAlloc  called
The question is what part of the program caused this call

The Call Stack 
can show the chain of functions that lead to the desired call

For example:
ntdll.dll | v kernelbase.dll | v application.dll | v main()
This is just a simplified representation of the call path and does not necessarily show the exact order of frames in a real Stack Trace
By examining the Call Stack, we can find out from which part of the program the desired call started and what functions were in its execution path
Of course, Stack Trace is not always complete and reliable and may be incomplete due to Optimization and lack of Symbol or data collection limitations

API Call Sequence 
and detecting suspicious behavior

In security analysis, instead of focusing on a single API, we sometimes examine a set of calls and events

For example:
Process Start | v File Access | v Registry Access | v Network Connection | v Child Process Creation
This repetition can provide useful information about the behavior of the program
However, we must note that this is just an analytical example and not every program that behaves like this is necessarily malicious
For example, an installer may access files, the Registry, the network, and child processes
What matters is the context and the relationship between events
We need to examine which process performed this activity, at what interval the events occurred, and whether this behavior is consistent with the normal task of the program
How does EDR use this information
An EDR can collect various information to analyze the behavior of the process
For example:
Process Information |
05 нояб., 15:52

API Activity
        |
        v
Memory Events
        |
        v
Thread Events
        |
        v
Network Events
        |
        v
Behavior Correlation
در این مدل EDR صرفا دنبال یک API خاص نمیگرده بلکه تلاش میکنه ارتباط بین رویداد ها رو در طول زمان تشخیص بده برای مثال فراخوانی CreateRemoteThread به‌ تنهایی لزوما نشونه حمله نیست اما اگر با دسترسی غیرمعمول به Process دیگه و تغییرات حافظه و شواهد اجرای کد همراه باشه ارزش بررسی بیشتری پیدا میکنه نکته مهم اینه که EDR ها حتما تمام API Call ها رو به‌صورت مستقیم ثبت نمیکنن و ممکنه از ترکیبی از ETW و Callback های سیستمی و سایر منابع Telemetry برای جمع‌ کردن اطلاعات استفاده کنن ابزارهای مناسب برای API Tracing برای تمرین و بررسی رفتار برنامه‌ ها در ویندوز میتونیم از ابزارهای زیر استفاده کنیم Process Monitor برای مشاهده فعالیت‌های File System و Registry و Process ها این ابزار تمام API Call های برنامه رو ثبت نمیکنه و بیشتر روی رویدادهای سیستمی قابل مشاهده در حوزه خودش تمرکز داره صفحه رسمی Process Monitor API Monitor برای مشاهده فراخوانی API های برنامه و بررسی پارامترها و نتایج اون‌ها وب‌سایت API Monitor WinDbg برای Debugging و بررسی Call Stack و تحلیل اجرای برنامه مستندات رسمی WinDbg Windows Performance Recorder و WPA برای ثبت و تحلیل رویدادهای سیستمی و بررسی Timeline اجرای برنامه مستندات رسمی Windows Performance Toolkit نکته مهم اینه که این ابزارها دقیقا یک نوع Telemetry ارائه نمیدن و هرکدوم برای مشاهده و تحلیل بخش مشخصی از رفتار سیستم مناسب هستن تمرین: یک برنامه ساده و بی‌خطر رو در محیط آزمایشگاهی اجرا کنید مثلا برنامه‌ای که یک فایل متنی درسا ت میکنه چند Byte داخلش مینویسه فایل رو میبنده دوباره فایل رو باز میکنه اطلاعاتش رو میخونه حالا با Process Monitor فعالیت برنامه رو بررسی کنید به این موارد توجه کنید:
Process Name
Operation
Path
Result
Timestamp
بعد ترتیب رویداد ها رو یادداشت کنید سعی کنید بفهمید هر عملیات چه ارتباطی با عملیات قبلی و بعدی داره هدف اینه که از روی فعالیت‌های ثبت‌ شده بفهمید برنامه واقعا چه کاری انجام داده نه اینکه صرفا اسم چند API رو حفظ کنید API Call Tracing برای بررسی فراخوانی‌ ها در زمان اجراست ترتیب فراخوانی‌ها می‌تونه اطلاعات بیشتری درباره رفتار برنامه بده Call Stack به شناسایی مسیر فراخوانی کمک میکنه EDR با ترکیب چند نوع Telemetry میتونه رفتارهای مشکوک رو بررسی کنه یک API یا Sequence به‌تنهایی اثبات‌کننده رفتار مخرب نیست @reverseengine
05 нояб., 15:48

API Call Tracing و تحلیل رفتار در زمان اجرا چطور از روی ترتیب فراخوانی API ها رفتار واقعی یک برنامه رو بفهمیم تا اینجا درباره Export Table و تابع GetProcAddress و نحوه پیدا کردن آدرس توابع در DLLها صحبت کردیم حالا می‌خوایم وارد مرحله بعدی بشیم API Call Tracing یعنی بررسی کنیم یک برنامه در زمان اجرا چه APIهایی رو فراخوانی می‌کنه و ترتیب این فراخوانی‌ها چیه و این توابع چطور با هم ارتباط دارن API Call Tracing فرض کنید یک برنامه رو اجرا میکنیم و این فراخوانی‌ها رو میبینیم
CreateFileW
      |
      v
ReadFile
      |
      v
VirtualAlloc
      |
      v
WriteProcessMemory
      |
      v
CreateThread
هرکدوم از این API ها وظیفه مشخصی دارن اما وقتی اونها رو در کنار هم بررسی می‌کنیم می‌تونیم اطلاعات بیشتری درباره رفتار برنامه به دست بیاریم به فرایند مشاهده و تحلیل فراخوانی‌های API در زمان اجرا API Call Tracing میگیم نکته مهم اینه که فقط دیدن اسم API ها کافی نیست و باید بدونیم هر فراخوانی در چه شرایطی اتفاق افتاده و چه نتیجه‌ای داشته چرا ترتیب فراخوانی APIها مهمه فرض کنید در یک برنامه فقط این API رو ببینیم
VirtualAlloc
این تابع برای اختصاص دادن فضای حافظه مجازی استفاده میشه خود این فراخوانی کاملا عادیه و برنامه‌ های زیادی ازش استفاده میکنن حالا فرض کنید چند رویداد پشت سر هم ثبت شده باشن
VirtualAlloc
      |
      v
Memory Write
      |
      v
VirtualProtect
      |
      v
Thread Activity
اینجا اطلاعات بیشتری در اختیار داریم میتونیم بررسی کنیم حافظه در چه شرایطی تخصیص داده شده چه اطلاعاتی داخل اون نوشته شده آیا Permission حافظه تغییر کرده آیا Thread جدیدی ایجاد شده Call Stack مربوط به این فعالیت چیه پس ترتیب رویدادها میتونه معنایی متفاوت از مشاهده جداگانه هر API داشته باشه البته باید توجه کنیم که این رویدادها الزاما همگی از یک API خاص به دست نمیان و ممکنه از منابع مختلفی جمع‌آوری شده باشن تفاوت API Monitoring و API Call Tracing این دو اصطلاح به هم نزدیک هستن اما از نظر تحلیلی میتونیم بینشون تفاوت قائل بشیم مثلا Monitoring میتونه ثبت کنه که یک Process تابع CreateFileW رو فراخوانی کرده اما Tracing کمک میکنه این رویداد رو در کنار فراخوانی‌ های قبلی و بعدی بررسی کنیم در واقع Monitoring اطلاعات رو جمع‌ میکنه و Tracing به ما کمک میکنه جریان اجرای برنامه رو بهتر درک کنیم Call Stack چه کمکی میکنه یکی از مهم‌ترین اطلاعاتی که هنگام بررسی یک API Call می‌تونه به ما کمک کنه Call Stack هست فرض کنید برنامه تابعی مثل VirtualAlloc رو فراخوانی کرده سوال اینه که چه بخشی از برنامه باعث این فراخوانی شده Call Stack میتونه زنجیره توابعی رو نشون بده که به فراخوانی موردنظر منتهی شدن مثلا:
ntdll.dll
    |
    v
kernelbase.dll
    |
    v
application.dll
    |
    v
main()
این فقط یک نمایش ساده‌ شده از مسیر فراخوانیه و لزوما ترتیب دقیق فریم‌ های یک Stack Trace واقعی رو نشون نمیده با بررسی Call Stack میتونیم متوجه بشیم فراخوانی موردنظر از کدام بخش برنامه شروع شده و چه توابعی در مسیر اجرای اون قرار داشتن البته Stack Trace همیشه کامل و قابل اعتماد نیست و ممکنه به دلیل Optimization و نبود Symbol یا محدودیت‌های جمع‌آوری اطلاعات ناقص باشه API Call Sequence و تشخیص رفتار مشکوک در تحلیل امنیتی گاهی به‌جای تمرکز روی یک API مجموعه‌ای از فراخوانی‌ها و رویدادها رو بررسی میکنیم برای مثال:
Process Start
      |
      v
File Access
      |
      v
Registry Access
      |
      v
Network Connection
      |
      v
Child Process Creation
این تکرار پشت سر هم میتونه درباره رفتار برنامه اطلاعات مفیدی بده اما باید دقت کنیم که این ترتیب فقط یک مثال تحلیلیه و هر برنامه‌ای که چنین رفتاری داشته باشه لزوما مخرب نیست برای مثال یک نرم‌افزار نصب‌کننده ممکنه به فایل‌ها و Registry و شبکه و Process های فرزند دسترسی داشته باشه چیزی که اهمیت داره Context و ارتباط بین رویدادهاست باید بررسی کنیم چه Process ی این فعالیت رو انجام داده و رویدادها با چه فاصله زمانی اتفاق افتادن و آیا این رفتار با وظیفه طبیعی برنامه سازگاره یا نه EDR چطور از این اطلاعات استفاده میکنه یک EDR میتونه اطلاعات مختلفی رو برای تحلیل رفتار Process جمع کنه مثلا:
Process Information
        |
05 нояб., 15:48

An important point about paths not found We should not conclude that the path is impossible every time angr fails to find a path One of the following may have happened The input model is incompletely defined The wrong constraint was added to the state The program reached an unsimulated function or syscall The number of paths is too large Resolving constraints took too long The find condition does not match the actual behavior of the program So before drawing conclusions, we should check the state of the stash, errors, and path constraints @reverseengine
05 нояб., 15:30

print(name, hex(symbol.rebased_addr))
This method is used when the program has usable symbols If the executable file is stripped, the function names may not be available and we will have to use other methods such as CFG analysis or command checking
05 нояб., 15:29

Section 38 Buffer Overflow Debugging Unfound Paths in ANGR In the previous section, we learned how to use ANGR to create a symbolic input and find a path that will take the program to a specific output But in real projects, things don't always go that easily Sometimes ANGR doesn't find any path and we only encounter the output No solution found Here we need to understand exactly where the problem is Is there really no valid input Is the desired path executed at all Is the program stopped due to a limitation or simulation error To answer these questions, we need to check the status of ANGR execution paths Getting to know stash In ANGR, program execution paths are managed inside a structure called SimulationManager This structure stores the paths based on their status in sections called stash Some important cases of these stashes: active Paths that are still executable found Paths that are not used for the intended purpose reach deadended Paths that have finished executing avoid Paths that we have marked as undesirable errored Paths that encountered an error while executing unconstrained Paths whose execution control status is undefined This classification helps us understand what state the program paths are in Checking the state of paths Suppose we ran the previous script but no paths were found After running explore, we can print the status of the stash
simgr.explore(
find=lambda s: b"Success" in s.posix.dumps(1)

)

print("Active:", len(simgr.active))
print("Found:", len(simgr.found))
print("Deadended:", len(simgr.deadended))
print("Errored:", len(simgr.errored))
print("Unconstrained:",  len(simgr.unconstrained))
Now we can understand what happened to the paths For example, if the number of deadended is high but found is empty, it means that the paths have been executed but none of them met our desired condition Of course, this alone does not prove that there is no valid input Checking path execution errors One of the most important parts of debugging in angr is checking errored paths Each error provides us with information about the state of the path that failed
for error in simgr.errored:
print("Error:", error.error)
print("Address:", hex(error.state.addr))
Here error.error indicates the cause of the error error.state is the state of the program at the time of the error error.state.addr indicates the address of the instruction that the path was on at the time of the error This information is useful for finding parts that angr cannot simulate correctly Checking the state of symbolic input Sometimes the problem is self-explanatory The model we defined for the input Suppose the program expects the input to be exactly 8 characters, but we only provided it with 4 symbolic bytes In such a situation, the program may enter a path that does not reach our desired goal at all To check the constraints that have been applied to a path so far, we can use the following command
state = simgr.active[0]

print(state.solver.constraints)
This command displays the constraints registered for the path For example, the output may contain constraints like this
symbolic_arg[1] == 69
symbolic_arg[2] == 86
The numbers 82, 69, and 86 are the ASCII equivalents of the characters R, E, and V, respectively So by examining these constraints, we can understand what conditions the solver has considered for continuing the path Of course, note that simgr.active[0] selects only one of the active paths and if there is no active path, this command will encounter an error Restricting unwanted paths Another feature of angr is that we can specify the paths that we do not want to be checked To do this, we use the avoid parameter
simgr.explore(
find=TARGET_ADDRESS,
avoid=BAD_ADDRESS
)
In this example TARGET_ADDRESS is the path address that we want to reach BAD_ADDRESS is the path address that we do not want to enter To find the addresses, we can use the program symbol information
05 нояб., 15:29

یک نکته مهم درباره مسیرهای پیدا نشده نباید هر بار که angr نتونست یک مسیر رو پیدا کنه نتیجه بگیریم که اون مسیر غیر ممکنه ممکنه یکی از این اتفاق‌ ها افتاده باشه مدل ورودی ناقص تعریف شده محدودیت اشتباهی به state اضافه شده برنامه به یک تابع یا syscall شبیه‌سازی‌ نشده رسیده تعداد مسیرها بیش از حد زیاد شده حل محدودیت‌ ها زمان زیادی برده شرط find با رفتار واقعی برنامه مطابقت نداره بنابراین قبل از نتیجه‌گیری باید وضعیت stash ها و خطاها و محدودیت‌های مسیر رو بررسی کنیم @reverseengine
05 нояб., 15:26

بخش سی و هشتم بافر اورفلو
دیباگ کردن مسیرهای پیدا نشده در angr در قسمت قبل یاد گرفتیم که چطور با angr میشه یک ورودی نمادین ساخت و مسیری رو پیدا کرد که برنامه به یک خروجی مشخص برسه اما توی پروژه‌ های واقعی همیشه همه‌چیز به همین سادگی پیش نمیره گاهی angr هیچ مسیری پیدا نمی‌کنه و فقط با خروجی No solution found مواجه میشیم اینجا باید بفهمیم مشکل دقیقا از کجاست آیا واقعا هیچ ورودی معتبری وجود نداره آیا مسیر موردنظر اصلا اجرا میشه آیا برنامه به خاطر یک محدودیت یا خطای شبیه‌سازی متوقف شده برای جواب دادن به این سؤال‌ها باید وضعیت مسیرهای اجرای angr رو بررسی کنیم آشنایی با stash ها در angr مسیرهای اجرای برنامه داخل ساختاری به اسم SimulationManager مدیریت میشن این ساختار مسیرها رو بر اساس وضعیتشون در بخش‌هایی به اسم stash نگه میداره چند مورد مهم از این stash ها: active مسیرهایی که هنوز قابلیت اجرا دارن found مسیر هایی که به هدف موردنظر رسیدن deadended مسیرهایی که اجرای اونها به پایان رسیده avoid مسیرهایی که به‌ عنوان مسیر نامطلوب مشخص کردیم errored مسیرهایی که هنگام اجرا با خطا مواجه شدن unconstrained مسیرهایی که وضعیت کنترل اجرای اونها نامشخص شده این دسته‌بندی کمک میکنه بفهمیم مسیرهای برنامه در چه وضعیتی قرار دارن بررسی وضعیت مسیرها فرض کنید اسکریپت قبلی رو اجرا کردیم اما هیچ مسیری پیدا نشده بعد از اجرای explore می‌تونیم وضعیت stashها رو چاپ کنیم
simgr.explore(
    find=lambda s: b"Success" in s.posix.dumps(1)
)

print("Active:", len(simgr.active))
print("Found:", len(simgr.found))
print("Deadended:", len(simgr.deadended))
print("Errored:", len(simgr.errored))
print("Unconstrained:", len(simgr.unconstrained))
حالا میتونیم بفهمیم چه اتفاقی برای مسیرها افتاده مثلا اگر تعداد deadended زیاد باشه اما found خالی بمونه یعنی مسیرهای اجرا تموم شدن اما هیچکدوم به شرط موردنظر ما نرسیدن البته این موضوع به‌ تنهایی ثابت نمیکنه که ورودی معتبری وجود نداره بررسی خطاهای اجرای مسیر یکی از مهم‌ترین بخش‌ها در دیباگ angr بررسی مسیرهای errored هست هر خطا اطلاعاتی درباره وضعیت مسیری که با شکست مواجه شده در اختیارمون قرار میده
for error in simgr.errored:
    print("Error:", error.error)
    print("Address:", hex(error.state.addr))
اینجا error.error علت خطا رو نشون میده error.state وضعیت برنامه در زمان اتفاق افتادن خطاست error.state.addr آدرس دستوری رو نشون میده که مسیر در زمان خطا روی اون قرار داشته این اطلاعات برای پیدا کردن بخش‌هایی که angr نمیتونه درست شبیه‌سازی کنه مفیدن بررسی وضعیت ورودی نمادین گاهی مشکل از خود مدلیه که برای ورودی تعریف کردیم فرض کنید برنامه انتظار داره ورودی دقیقا 8 کاراکتر داشته باشه اما ما فقط 4 بایت نمادین در اختیارش قرار دادیم در چنین شرایطی ممکنه برنامه وارد مسیری بشه که اصلاً به هدف موردنظر ما نمیرسه برای بررسی محدودیت‌ هایی که تا اون لحظه روی یک مسیر اعمال شدن میتونیم از دستور زیر استفاده کنیم
state = simgr.active[0]

print(state.solver.constraints)
این دستور محدودیت‌ های ثبت‌ شده برای مسیر رو نمایش میده مثلا ممکنه خروجی شامل محدودیت‌ هایی شبیه این باشه
symbolic_arg[0] == 82
symbolic_arg[1] == 69
symbolic_arg[2] == 86
اعداد 82 و 69 و 86 به‌ترتیب معادل ASCII کاراکترهای R و E و V هستن پس با بررسی این محدودیت‌ ها میتونیم بفهمیم حل‌کننده چه شرایطی رو برای ادامه مسیر در نظر گرفته البته دقت کنید که simgr.active[0] فقط یکی از مسیرهای فعال رو انتخاب می‌کنه و اگر مسیر فعالی وجود نداشته باشه این دستور با خطا مواجه میشه محدود کردن مسیرهای نامطلوب یکی دیگه از قابلیت‌های angr اینه که می‌تونیم مسیرهایی رو که نمی‌خوایم بررسی بشن مشخص کنیم برای این کار از پارامتر avoid استفاده میکنیم
simgr.explore(
    find=TARGET_ADDRESS,
    avoid=BAD_ADDRESS
)
در این مثال TARGET_ADDRESS آدرس مسیریه که میخوایم بهش برسیم BAD_ADDRESS آدرس مسیریه که نمیخوایم واردش بشیم برای پیدا کردن آدرس‌ ها میتونیم از اطلاعات سمبل‌های برنامه استفاده کنیم
for name, symbol in project.loader.main_object.symbols_by_name.items():
    print(name, hex(symbol.rebased_addr))
این روش زمانی کاربرد داره که برنامه سمبل‌های قابل استفاده داشته باشه اگر فایل اجرایی stripped باشه ممکنه اسم تابع‌ها در دسترس نباشن و مجبور بشیم از روش‌های دیگه‌ ای مثل تحلیل CFG یا بررسی دستور ها استفاده کنیم
05 нояб., 15:26

ببخشید دوستان امیدوارم حال همه تون خوش باشه کم کار شدم ی مدتی خیلی مشغولم یک سری کار دارم قول میدم از این به بعد زودتر پست بزارم 😁 Alone 🩶 Sorry friends, I hope everyone is well. I haven't been very active lately; I’ve been really busy with some things. I promise to post more frequently from now on 😁 Alone 🖤
30 окт., 10:40

Process Injection without R/W target memory and without creating a remote thread https://github.com/Maff1t/InjectNtdllPOC @reverseengine
30 окт., 08:59

30 окт., 08:49

Finding and exploiting process killer drivers with LOL for 3000$ In this article, I will introduce some kernel driver/internals theory and explain how to use the data in LOLDrivers to find interesting drivers. Finally, I will present 2 examples of vulnerable drivers and explain how to quickly reverse them and create a PoC to exploit them. https://alice.climent-pommeret.red/posts/process-killer-driver/ @reverseengine
30 окт., 08:47

WindowsNoExec - Abusing existing instructions to executing arbitrary code without allocating executable memory https://www.x86matthew.com/view_post?id=windows_no_exec #windows #ctf #malware #tips
30 окт., 08:46

Living Off The Land Drivers is a curated list of Windows drivers used by adversaries to bypass security controls and carry out attacks. The project helps security professionals stay informed and mitigate potential threats. https://www.loldrivers.io/ #redteam #loldrivers #windows
30 окт., 08:46

Rusty Bootkit - Windows UEFI Bootkit in Rust (Codename: RedLotus) https://github.com/memN0ps/bootkit-rs #redteam #malware #bootkit #windows #rust
30 окт., 08:45

Debugging Windows Isolated User Mode (IUM) Processes In this blog post discussed how to debug Windows' Isolated User Mode (IUM) processes, also known as Trustlets, using the virtual TPM of Microsoft Hyper-V as our target. https://blog.quarkslab.com/debugging-windows-isolated-user-mode-ium-processes.html #reverse #windows #trustlets
30 окт., 08:45

Dissecting and Exploiting TCP/IP RCE Vulnerability “EvilESP” https://securityintelligence.com/x-force/dissecting-exploiting-tcp-ip-rce-vulnerability-evilesp/ #expdev #windows #1day
30 окт., 08:44

Another important point is that the address of a function in memory may vary between different processes, so we should not consider the address we see in a particular execution as the fixed and permanent address of the function. API Resolution What is its use in Reverse Engineering? Suppose you open an executable file in the Disassembler. You may encounter calls like this in different parts of the program.
GetProcAddress

CreateFileW

VirtualAlloc
The presence of these names can give us useful clues about the behavior of the program. However, if the program finds the address of the functions at runtime, we may not be able to determine all its dependencies just from the list of file imports. For proper analysis, we need to know the difference between these concepts. These concepts are used both in analyzing normal software and in investigating suspicious programs. Is Dynamic API Resolution a sign of malware? No Normal programs may also use GetProcAddress For example, a software may want to load some features optionally or manage its dependencies at runtime. On the other hand, some malicious programs use Dynamic API Resolution to make analyzing program dependencies more complex So
≠
Malware
To detect suspicious behavior, we need to examine the Context of the program and the functions used and the actual behavior of the Process Just finding GetProcAddress or LoadLibrary is not enough to conclude that a program is malicious Analyzer Practice Open a valid Windows DLL in the PE analysis tool and check the Exports section Then find these items
Ordinal
RVA
Now calculate the corresponding virtual address using ImageBase and RVA In the next step, compare the result with the information you see through the Debugger When comparing, note that the RVA value is different from the final virtual address and you must consider the ImageBase of the same Module to calculate the address Purpose of this exercise This is to better understand the relationship between the information stored in the file and the actual addresses in memory In this section, we learned Export Table holds information about exported symbols GetProcAddress is used to find the address of an exported symbol Ordinal and Name are two different ways to identify exports Common addresses in the Export Address Table are stored as RVA To calculate the virtual address, we need to consider ImageBase and RVA Some exports are Forwarded Exports and do not directly point to the function body Dynamic API Resolution alone is not an indication of malicious behavior The main point is that when we analyze a binary, we should not only pay attention to the Import Table, we should also know how the program loads modules and how it finds the addresses of functions so that we can examine the actual dependencies and behavior of the program more accurately @reverseengine
30 окт., 08:43

But in real analysis, we must also consider cases such as Forwarded Exports, because in this case the Export value may Instead of a direct function address, point to a string referencing Module and another symbol.
30 окт., 08:39

API Resolution and Export Table How does Windows find the address of a DLL's functions So far we have talked about the PE structure and how to load modules and PEB and LDR structures Now we want to move on to one of the important topics in software reverse engineering, namely API Resolution Suppose a program wants to execute a function from a DLL. The question is how does the program know where the desired function is located in memory Export Table Some DLLs provide functions or symbols to other programs The information about these symbols is placed in a structure called Export Table For example, suppose we have a DLL called example.dll example.dll | └── Export Table | ├── FunctionA ├── FunctionB └── FunctionC This example is just for understanding the concept and the function names are hypothetical The Export Table holds information about the symbols that the DLL makes available for external use The important point is that not every function that is inside a DLL is necessarily exported A function may exist inside the file, but other programs cannot access it directly through the Export Table What does the GetProcAddress function do There is a function called GetProcAddress in the Windows API This function is used to find the address of a function or symbol exported from a Module The general flow of work is as follows Loaded DLL | v GetProcAddress | v Find Export | v Function Address For example, a program might first load a DLL and then get the address of one of its exported functions Simple example in C #include <windows.h> #include <stdio.h> int main(void) { HMODULE module = LoadLibraryA("user32.dll"); if (module == NULL) { printf("LoadLibrary failed\n"); return 1; } FARPROC function = GetProcAddress(module, "MessageBoxA"); if (function == NULL) { printf("GetProcAddress failed\n"); FreeLibrary(module); return 1; } printf("Function address: %p\n", (void *)function); FreeLibrary(module); return 0; } In this example, the program receives the address of the MessageBoxA function from user32.dll Note that the program only receives the address of the function and does not execute the function itself in this example Also, the address that is received is related to the loading state of the Module in the same Process and we should not assume that this address is always the same between different Processes Export Table How to find the address of the function To understand this, we need to be familiar with 3 concepts Export Name Export Ordinal Export Address Each of these items has a different role Export Name A name that is used to identify an exported symbol For example MessageBoxA Export Ordinal A number to identify the symbol in the Export table Some Exports can be found through Ordinal even if their name does not exist in the name table Export Address Specifies information related to the address of the exported symbol In the PE structure, the information in this section is managed through several related tables Export Directory | ├── Export Address Table | ├── Name Pointer Table | └── Ordinal Table These tables are related and allow you to find the entry related to a symbol by name or Ordinal Of course, the final output does not always directly point to the actual body of the function For example, some Exports are of the Forwarded Export type and refer to a symbol in another Module The difference between RVA and the actual address of a function Remember this part from previous posts In the PE file, the address related to the function in the Export Address Table is usually stored as RVA That is, the address is defined relative to the ImageBase The calculation formula is as follows VA = ImageBase + RVA For example
ImageBase = 0x180000000
RVA = 0x12340
So
VA = 0x180012340
This calculation assumes that the RVA value points to an address within the same Image and by considering the ImageBase, the corresponding virtual address can be obtained
30 окт., 08:39

Мы используем файлы cookie для улучшения вашего опыта просмотра.
Нажав «Принять все», вы соглашаетесь с политикой использования файлов cookie.