1 730
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 CreateThreadEach 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

