© Abhijit Mohanta, Anoop Saldanha 2020
A. Mohanta, A. SaldanhaMalware Analysis and Detection Engineeringhttps://doi.org/10.1007/978-1-4842-6193-4_13

13. Dynamic Analysis

Abhijit Mohanta1  and Anoop Saldanha2
(1)
Independent Cybersecurity Consultant, Bhubaneswar, Odisha, India
(2)
Independent Cybersecurity Consultant, Mangalore, Karnataka, India
 

In the previous chapter, you learned about static analysis, which lets us analyze a sample without executing it. In this chapter, you learn the other side of the analysis coin: dynamic analysis. It involves executing a sample using the aid of various tools and recording not only the behavior but also observing the various artifacts generated by the executed malware. Combined, it can help us analyze and make conclusions about the sample more accurately.

Although dynamic analysis and static analysis sound like two different phases in the analysis process, they are not. As you run through the various dynamic analysis steps and tools, you might have to go back and run through the various static analysis steps that you learned, and then come back to dynamic analysis again. This cycle might continue several more times.

In the chapters in Part 3, we cover various dynamic analysis techniques along with hands-on exercises. In this chapter, we rehash many of the techniques that we introduced earlier in the book. As you read this chapter, we suggest you go back and forth between this chapter and the previous chapters and their various hands-on exercises and content so that you can solidify everything you learned earlier. Practice makes perfect.

Keep Your Base Snapshot Handy

In Chapter 2, you learned that we need a base snapshot of our analysis VM with all the system tweaks setup and the analysis tools installed. Every new sample that we obtain should start the analysis from the base snapshot. When analyzing a sample, you might have to re-run the sample and re-analyzed it again and again. Some of these re-runs you might want to start from scratch by going back to the base snapshot. The reasons why using the pristine state of a base snapshot is important are,
  • During the execution of the sample, the sample might make some changes to the system, dropping some hints for itself in case it is re-run later. If you re-run the same sample later again in the same environment without resetting your VM, the malware might start up, check for the existence of hints that indicate that it has already run in that environment, and if so, behave differently or exit. Some hints/artifacts from malware are registry entries, config files, or dummy files on the disk, mutexes, and so forth

  • Sometimes malware you analyzed earlier in the analysis VM might still be running even though you think you killed it. When you re-run the sample, it might clash with the existing process, or it might check for the hints/artifacts it left inside the analysis VM, so it now behaves differently or exits. As a result, you may not get the malware’s true behavior and events.

  • If you reuse a VM environment that you used to analyze a different sample, then there might be artifacts and events from that earlier malware that you might mix up and confuse as those generated and belonging to any new malware you analyze. Resting the VM ensures that you have a clean environment to analyze a new sample, with no stray events and artifacts from any older analyzed sample that you could get confused with.

First Run: A Bird’s-Eye View

The best first step in the analysis process is to casually run the sample and notice at a very high level its behavior. This is important for two reasons.
  • A lot of samples, like ransomware, have very public or explicit behavior. Running the sample and observing the effects that the malware had on the system, and the files on disk might be enough to conclude that the sample is malware and figure out the type and intent of the malware.

  • Casually observing the behavior of the malware under execution, helps us set a tone, and our expectations, and prepare ourselves for the next set of tools needed to continue with its analysis in depth.

We might have to repeat this process and casually re-run the same sample multiple times, since a single execution may not help us observe enough about its behavior. Every time we casually re-run the sample, it is highly recommended that we reset the VM to the pristine base snapshot. While we carry out this process, we also want to take the aid of a few simple tools like Process Hacker and the file browser, that help us observe the sample’s behavior passively.

Whoa! The Sample Refuses to Run!

Not every malware sample you obtain might run when you try to execute it for the first time. Some of the reasons for this can be,
  • Sometimes the samples might need a certain environment or a certain SDK/framework installed, which might be missing in your analysis VM. For example, the sample you are analyzing might be a .NET sample that requires a particular version of the .NET Framework, which may not be installed on your system.

    Or the sample might be Java malware that requires the Java Runtime Engine (JRE), which is not installed on the system.

  • The malware might have certain dependencies on DLLs and config files that it needs to run, which might be missing from your analysis VM.

A lot of these dependencies, frameworks, environments needed by a sample to run can be figured out from the static analysis phase. Once we figure out these missing dependencies and install and set them up, the sample runs as expected.

Keep in mind is that when PE Executable samples fail to run, the easiest way to figure out the issue is to run the sample using a debugger like OllyDbg. Using a debugger helps you figure out the issue very quickly and efficiently, saving your precious time. You don’t have to be a super reverse engineer to use OllyDbg or any other debugger. You learn more about using OllyDbg and the reverse engineering process in Part 4 of this book.

Run as Administrator or Not

By default, if you double-click any sample on the system, it runs as a non-administrator, with fewer privileges, functionalities, features available for the running process. Some malware requires administrator privileges to perform certain operations that require special privileges. For example, if malware wants to copy a file into the protected OS system folder C:WindowsSystem32, it needs administrator privileges.

While running any malware sample, you want to test it by running both with and without administrator privileges. Start by running it without administrator privileges, which is easy to do, since all you need to do is double click.

Reset your VM and run the sample as an administrator, which you can by right-clicking the sample and selecting Run as an Administrator.

Each of the scenarios might provide different sets of events and behaviors for the running malware process, which you may not see with the other, and the difference might be crucial in your figuring out if the sample is malicious or not.

Now let’s play with some hands-on exercises that involve real malware samples and see how having a casual eye on the execution of the sample is all that we need most of the time to conclude enough about a sample.

Case Study 1

Let’s start with Sample-13-1 from the samples repository, to which you can add the .exe file extension. In the samples repository, it is named Sample-13-1.txt because it is a text file that holds the instructions that you need to follow to download the real malware sample. Don’t run the sample yet. Start Process Hacker and open the folder that holds the sample file, which should look similar to the left side of Figure 13-1.
../images/491809_1_En_13_Chapter/491809_1_En_13_Fig1_HTML.jpg
Figure 13-1

The state of the system before and after running Sample-13-1

Now that you have that in place, run the sample. A new process called svchost.exe opens, as you can see on the right side of Figure 13-1. This is suspicious, and from what we have covered so far in this book, it points to malware-related behavior, where malware uses system programs like svchost.exe for stealth (see Chapter 11) using code injection/process hollowing (see Chapter 9).

What else can you observe that can further confirm these early indicators that this new svohost.exe process is hosting malware code? Let’s walk back through what you learned in Chapter 5. Two important points about system processes like svchost.exe are as follows.
  • They have a certain parent hierarchy. All svchost.exe processes have services.exe as their parent, which in turn has wininit.exe as its parent, as seen in Figure 5-14.

  • They are started under session 0, as seen in Figure 5-14.

Our new svchost.exe in Figure 13-1 doesn’t have services.exe as its parent, as confirmed from the left side of Figure 13-2. Combine all the things we observed visually, and they all point to Sample-13-1 being malware. Now reset your VM, re-run the sample as an administrator, and observe how it behaves to see if there is a difference.
../images/491809_1_En_13_Chapter/491809_1_En_13_Fig2_HTML.jpg
Figure 13-2

The properties, the absent parent process, session 1 for the newly created process indicate suspicious behavior and points to it being malware

Case Study 2

Let’s now play with Sample-13-2, to which you can add the .exe file extension. In the samples repo, it is named Sample-13-2.txt because it is a text file that holds instructions that you need to download the real malware sample. Don’t run the sample yet. Start Process Hacker and open the folder that holds the sample file, which should look similar to the left side of Figure 13-2.

Now that you have that in place, run the sample as an administrator by right-clicking it and selecting Run as an Administrator. A new process called SVOHOST.EXE pops up, as seen on the right side of Figure 13-3. Sample-13-2.exe is deleted from the disk.
../images/491809_1_En_13_Chapter/491809_1_En_13_Fig3_HTML.jpg
Figure 13-3

The state of the system before and after running Sample-13-2

Both symptoms are suspicious. The name of the new process SVOHOST.EXE is suspiciously similar to the OS process svchost.exe, which is like the psycholinguistic technique, a stealth technique explained in Chapter 11. The deletion of the executable file on the disk is also a classic technique used by a lot of malware, which we explain later in the chapter.

Now let’s check the properties and see if we notice anything. In the properties seen in Figure 13-4, we notice that the executable file from which the new process SVOHOST.EXE is created is located at C:WindowsSystem32SVOHOST.EXE. You can go back to a pristine system, or use your own experience, but there is no system program located in C:WindowsSystem32 that is called SVOHOST.EXE.
../images/491809_1_En_13_Chapter/491809_1_En_13_Fig4_HTML.jpg
Figure 13-4

Path of the newly created process is located in the protected OS system folder

All the observations made so far—both visually or through some minor inspection—all but point that the sample is malicious.

Case Study 3

Let’s now play with Sample-13-3, to which you can add the .exe file extension. In the samples repository, it is named Sample-13-3.txt because it is a text file that holds the instructions that you need to follow to download the real malware sample. Start Process Hacker and open the folder that holds the sample file, which should look similar to the left side of Figure 13-5. Notice that we have some dummy PDF (.pdf) and Excel (.xlsx) files in that folder. This is part of the process where we want our analysis VM setup to look and mimic a regular victim’s machine, also explained in Chapter 2.
../images/491809_1_En_13_Chapter/491809_1_En_13_Fig5_HTML.jpg
Figure 13-5

The state of the system before and after running Sample-13-3

Now that you have that in place, run the sample. What do you see? From the right side of Figure 13-5, we see that suddenly all the files have been modified and a .doc file extension added to them. We also see a new file created in the same folder called Read___ME.html. Both indicators point to the Sample-13-3 being ransomware.

The newly created Read___ME.html is an HTML file. Opening it confirms that we have ransomware, as seen in Figure 13-6.
../images/491809_1_En_13_Chapter/491809_1_En_13_Fig6_HTML.jpg
Figure 13-6

The ransom note created by our ransomware Sample-13-3.exe

These exercises taught that by casually running a sample and viewing its behavior and properties from a high level without using complex analysis tools, you can typically conclude whether a sample is malware or not, and in some cases, classify the type of malware.

APIMiner: API Log Behavior Identification

Malware carries out its activities that result in Win32 APIs being invoked. By using an API logger tool like APIMiner or Cuckoo Sandbox, you can obtain the APIs used by a sample. Based on the APIs, you can conclude if the sample is malware and figure out its category.

Let’s use Sample-13-1 as an exercise. You can run it using APIMiner. To use APIMiner, open a command prompt as an administrator and issue the command displayed in Figure 13-7.
../images/491809_1_En_13_Chapter/491809_1_En_13_Fig7_HTML.jpg
Figure 13-7

APIMiner command line issued from the command prompt to analyze Sample-13-1

It generates three API log files. The log files are arranged in the alphabetical order using a timestamp, so that the first file you see is the first one created. Opening the first log file and observing the logs, you can see the following set of APIs, as seen in Figure 13-8.
../images/491809_1_En_13_Chapter/491809_1_En_13_Fig8_HTML.jpg
Figure 13-8

APIMiner API logs for Sample-13-1 shows a malicious sequence of APIs

Due to the image size, we can’t list the arguments, but you can see the same APIs and the arguments to the API calls using the log files generated on your system. Note that the argument values listed in the API log files in Figure 13-8 and Listing 31-1 may be different from the ones generated in your log files, but the concept remains the name. Let’s relist the APIs and their important argument values in Listing 13-1.
CreateProcessInternalW([command_line]"svchost.exe",
                       [process_identifier]4080,
                       [thread_identifier]3248,
                       [creation_flags]4
                       [process_handle]0x00002A7C,
                       [thread_handle]0x00002A78)
NtReadVirtualMemory([process_handle]0x00002A7C)
NtMapViewOfSection([process_handle]0x00002A7C)
NtReadVirtualMemory([process_handle]0x00002A7C)
NtUnmapViewOfSection([process_handle]0x00002A7C)
NtResumeThread([thread_handle]0x00002A78,
               [process_identifier]4080)
Listing 13-1

A replica off Figure-13-8 above, holding a part of the APIMiner API trace output obtained by executing Sample-13-8 using APIMin

These APIs are related to each other, and the relation comes in the form of the common arguments shared among them. Notice the common process_handle, process_identifier, and thread_handle. What do you infer from the API logs?
  • The sample using the CreateProcessInternalW API creates a new process for the program svchost.exe, which as you know is a system process located at C:WindowsSystem32svchost.exe

  • The process created is in a SUSPENDED state, identified using the argument value of 4 using [creation_flags]4. How do we know that the value of 4 means SUSPENDED? Check out the API description in MSDN for CreateProcess API and check for the CREATE_SUSPENDED flag.

  • The handle of this newly created process and thread are 0x00002A7C and 0x00002A78.

  • The sample using the NtReadVirtualMemory API then reads the memory from the remote process identified using the process handle 0x00002A7C.

  • The sample using the NtMapViewOfSection API then creates a section and maps a view of it into the remote process again identified using the handle 0x00002A7C.

  • It resumes the SUSPENDED thread/process using ResumeThread API, identified using the thread handle 0x00002A78, and process identifier 4080.

What does this entire sequence of APIs look like? If you go back to Chapter 9 and check the APIs in the section on process hollowing, you see the same set/sequence of APIs, which means the sample is using process hollowing, which is a feature mostly used by malware, if not only used by malware, thereby allowing us to conclude that it is malware.

Classify the Malware Family

We concluded it is malware from what was in the API logs, but can we conclude the family of the malware? Every malware and malware belonging to the same family have traits or artifacts specific to that family. You can search for traits through the API logs. For the sample, there are three API log files generated. Take the first log file and search for the CreateMutant API , which creates a mutex. In Chapter 5, we discussed that mutexes are a synchronization method commonly used by malware. As you can see via the API call by our malware Sample-13-1, it creates a mutex named 2GVWNQJz1, which you can see in Listing 13-2.
NtCreateMutant([mutant_handle]0x00002A78,
               [desired_access]2031617,
               [initial_owner]0,
               [mutant_name]"2GVWNQJz1")
Listing 13-2.

Excerpt from the APIMiner API traces obtained by executing Sample-13-1.exe that shows the mutant related Win32 API being invoked

Let’s take this mutex name and search for it on the web via Google. In Figure 13-9, there are analysis reports for other malware samples belonging to the same family that creates the same mutant, and it identifies the malware family as kuluoz and the category as Botnet. Voila! We were not only able to conclude that it is malware, but we also determined its family and type.
../images/491809_1_En_13_Chapter/491809_1_En_13_Fig9_HTML.jpg
Figure 13-9

Mutex created by Sample-12-1 reveals it belongs to kuluoz family and is a bot

As an exercise, go through the API logs of various other malware samples, including Sample-13-2 and Sample-13-3. Note that we mention the most basic Win32 APIs used by malware throughout various chapters in this book. But the APIs that we listed are not extensive. As you analyze new categories of malware that carry out their dirty work through various sets of Win32 APIs that have never used before by other malware you have seen before, make a note of these API sequences so that you can use them to detect and classify other malware in the future.

String Analysis Dynamically

We covered strings extensively in Chapter 7 and Chapter 12. Continuing from where we left off in Chapter 12, you can use string analysis on running processes. Using strings for malware analysis is probably the most powerful tool in dynamic analysis. With it, you learn if a sample is malware or not, but also how to classify it (more on this in Chapter 15).

In Chapter 7, you saw that most malware is packed, which means most of the strings are obfuscated in the static malware file. This makes static analysis of strings using BinText useless. When we run packed malware, they unpack themselves in memory. After unpacking itself, all its obfuscated strings are now deobfuscated. The malware process’s memory becomes the buffer that contains various strings that we can use for string analysis.

Let’s play with Sample-13-4. Note that in the samples repository, it is named Sample-13-4.txt because it is a text file that holds the instructions you need to download the real malware sample. Before we get to analyzing strings in memory, let’s start with some preliminary static analysis on this sample.

File Type

Checking the file type of Sample-13-4 reveals it to be a .NET file type, as seen in Figure 13-10. A .NET sample requires the .NET Framework to be installed to successfully run the sample. But just any framework won’t do. Specific .NET versions require their corresponding .NET frameworks or greater in some cases. If you don’t have the requisite framework installed, the sample may not run.
../images/491809_1_En_13_Chapter/491809_1_En_13_Fig10_HTML.jpg
Figure 13-10

trid.exe reports that Sample-13-4 is of .NET type

In our Windows 7 analysis VM, it is fully updated. It installs the latest .NET Framework, which proves to be enough to run the sample, as you see later on. But if you are unable to run the sample, verify if you have the .NET Framework installed and, if so, check if it is the right version.

Version Information/Details

Let’s check this sample’s properties and details. Refer to Chapter 12 for more information on what we can infer from it. In Figure 13-11, the various fields hold values that look like junk, unlike clean programs that hold legible values for their Product name, Copyright, Original Filename, and File description. This points to show that the sample is suspicious and warrants further investigation.
../images/491809_1_En_13_Chapter/491809_1_En_13_Fig11_HTML.jpg
Figure 13-11

Sample-13-4 can be categorized as suspicious a sit holds junk property values

Packed or Unpacked?

The first step in the string analysis is to figure out if it is packed or not. We covered this in Chapter 7, where we had three main methods to identify if a sample is packed: entropy, static observation of strings in the file, and dynamic observation of strings in memory.

Entropy Check with PEiD

PEiD is a great tool that can provide you the entropy of the static file using which you can figure out if the sample is packed or not. Refer to Figure 7-8 from Chapter 7 on how to use PEiD to extract the entropy of a file. In Figure 13-12, the PEiD reports that the entropy is 7.62 and packed. Job done!
../images/491809_1_En_13_Chapter/491809_1_En_13_Fig12_HTML.jpg
Figure 13-12

PEiD says Sample-13-4 has an entropy of 7.62 which indicates it is packed

Static Observation of Strings in File

Using entropy, we established that the sample is packed. Going through the strings statically using BinText shows us that the sample is indeed packed, as seen through the various junk strings in Figure 13-13. We were hoping that some stray strings in there are still unpacked and reveal something about this sample. But we are out of luck here, and we must rely on dynamic string analysis.
../images/491809_1_En_13_Chapter/491809_1_En_13_Fig13_HTML.jpg
Figure 13-13

BinText reveals static strings that look like junk confirm it is indeed packed

Dynamic Observation of Strings in Memory

Now that we have established that the sample is packed, let’s see if the sample unpacks in memory and if so, the memory holds any deobfuscated strings that can reveal to us more information about this sample. We have established that the sample is suspicious. Run the sample by double-clicking it. Using Process Hacker, it creates a new process called coherence.exe, as seen in Figure 13-14.
../images/491809_1_En_13_Chapter/491809_1_En_13_Fig14_HTML.jpg
Figure 13-14

Running the sample eventually creates a new process called coherence.exe

Using Process Explorer, open the Properties for this process coherence.exe and click the Strings tab. You can also refer to Figure 7-12 from Chapter 7 on how to use Process Explorer for this. In Figure 13-15, which compares the image/memory strings, you can see new deobfuscated strings, which you previously couldn’t see statically, indicating that it is indeed unpacked in memory.
../images/491809_1_En_13_Chapter/491809_1_En_13_Fig15_HTML.jpg
Figure 13-15

Sample-13-4 unpacks in memory as seen in the difference between its static strings in the file and dynamic strings in memory

Let’s dig through these strings in memory and see if we can conclude anything from it. Now let’s continue to observe the strings in Process Hacker instead, although we can also do the same using Process Explorer. Refer to Figure 7-14 and 7-15 from Chapter 7 on how to use Process Hacker to view the strings. In Figure 13-16, you can see various strings that hint at the kind of malware we are dealing with.
../images/491809_1_En_13_Chapter/491809_1_En_13_Fig16_HTML.jpg
Figure 13-16

Sample-13-4 strings using Process Hacker that reveals a lot about this malware

What do you think we can infer from these strings? Go through the strings slowly, taking your time. Do you notice a lot of strings referring to Username and Password, in combination with various protocols, like SMTP and POP, and various tools, like Filezilla and Internet Explorer? This refers to a category of malware called InfoStealers that tries to steal credentials from various tools that the users use.

Now that we have established the type of malware as InfoStealer, let’s see if we can figure out the exact family/name the malware belongs to. Go through the strings slowly again and search for some weird names that look different and yet have some meaning to it (you need a lot of patience for this). Among all these strings, there is a string YUIPWDFILE0YUIPKDFILE0YUICRYPTED0YUI1.0, which is very weird looking but at the same time has a structure with words like CRYPTED and FILE0. Searching for this string on Google points to many analysis reports for other malware samples belonging to the same family as our sample, such as Pony Loader or Fareit, as seen in Figure 13-17.
../images/491809_1_En_13_Chapter/491809_1_En_13_Fig17_HTML.jpg
Figure 13-17

A string from memory for Sample-13-4 points to analysis reports on the web indicating it belongs to malware family Pony Loader or Fareit

ProcMon: Behavior Events Analysis

We have gone through various dynamic analysis techniques and tools like APIMiner, string analysis, and most importantly, a casual inspection of the malware’s behavior. Most of these techniques should be vastly sufficient in concluding this sample.

In this section, we show you how to use ProcMon, another very important analysis tool that can catch various events carried out by our sample when we analyze it and run. We ran through ProcMon in Chapter 11 and other chapters in Part 3, so it is useful to refer to those exercises whenever you want.

Let’s analyze Sample-13-2 in the context of ProcMon. Make sure to add the .exe file extension to this sample,
  1. 1.

    Start Process Hacker so that you have an eye on the process(es) that are started when you run your sample.

     
  2. 2.

    Start ProcMon and hit Ctrl+E to stop capturing events. By default, ProcMon captures all events on the system, and sometimes you have too many events.

     
  3. 3.

    Hit Ctrl+X so that you can clear the existing events displayed by it.

     
  4. 4.

    Hit Ctrl+E so that you can start the capture of events.

     
  5. 5.

    Run Sample-13-2.exe, while making sure via Process Hacker that it is running or at least it has created other child processes.

     
  6. 6.

    Let the sample run for a while, and then hit Ctrl+E in ProcMon. You don’t want to run it too long, however; otherwise, you are inundated with too many events to analyze.

     

Let’s go through the events and see if we can notice any malicious events/indicators from events related directly or indirectly to our sample process. Note that you want to look for events from the main malware process, Sample-13-2.exe, and from all the child processes created by this sample process and from other processes that our sample or its children possibly code inject into. You can filter events first to start with only Sample-13-2.exe.

In Figure 13-18, Sample-13-2.exe creates a file called SVOHOST.EXE in C:WindowsSystem32 and writes into it using the contents from Sample-13-2.exe. How do we know that the contents of Sample-13-2.exe are being copied over into this new file C:WindowsSystem32SVOHOST.exe? Because we can see a ReadFile event for Sample-13-2.exe file and then a WriteFile for SVOHOST.exe file.
../images/491809_1_En_13_Chapter/491809_1_En_13_Fig18_HTML.jpg
Figure 13-18

ProcMon events show the sample copying itself into system folder as a new file SVOHOST.EXE

All the events so far indicate maliciousness.
  1. 1.

    Creating a new file called SVOHOST.EXE, which is named very similar to the system program svchost.exe, which from our experience indicates the psycholinguistic technique, a stealth technique explained in Chapter 11.

     
  2. 2.

    Creating a new file from step 1 in the protected system folder C:WindowsSystem32. Third-party applications don’t make modifications to any content in the OS system folder.

     
  3. 3.

    Copying and pasting its contents into this new file, which is a commonly used malware technique, where malware copy themselves into a new file in another folder on the system so that they can run as a new process from this new file located in this new folder.

     
Let’s search for any registry events and see if the sample creates some Run entries for persistence (see Chapter 8). In Figure 13-19, it creates a new persistence entry in the registry by registering a new Run key, SoundMam, at HKLMSOFTWAREMicrosoftWindowsCurrentVersionRunSoundMam, whose value is the path to newly created malware file C:WindowsSysteme32SVOHOST.EXE. This is another perfect indicator of maliciousness in combination with the events we saw earlier.
../images/491809_1_En_13_Chapter/491809_1_En_13_Fig19_HTML.jpg
Figure 13-19

ProcMon events show the sample creating RUN persistence keys in Registry

AutoRuns

Since the malware sample creates a RUN persistence entry, let’s verify with the AutoRuns tool if this persistence RUN entry still exists. As you can see in Figure 13-20, it does pick it up—double confirmation. Yay!
../images/491809_1_En_13_Chapter/491809_1_En_13_Fig20_HTML.jpg
Figure 13-20

Autoruns picks the RUN entry persistence created by Sample-13-2.exe

Continuing with our analysis process, now let’s search for some process events. Figure 13-21 shows that Sample-13-2.exe creates a new process for the file it created earlier, C:WindowsSystem32SVOHOST.EXE.
../images/491809_1_En_13_Chapter/491809_1_En_13_Fig21_HTML.jpg
Figure 13-21

Process creation events from ProcMon shows Sample-13-2.exe creating a new process out of SVOHOST.exe which it created earlier in the Windows system folder

The following is the full chain of malicious events for Sample-13-2.exe.
  1. 1.

    Creates a new file C:WindowsSystem32SVOHOST.exe in the system folder, using a file name similar to the system program svchost.exe.

     
  2. 2.

    Copies itself into this new file from step 1, SVOHOST.exe.

     
  3. 3.

    Creates a persistence RUN entry in the registry for this new file from step 1.

     
  4. 4.

    Starts a new process out of this new file from step 1, SVOHOST.exe.

     

Combined, there are enough indicators to conclude that Sample-13-2.exe is malware. We can continue with our event analysis by going through the events of SVOHOST.EXE, which is a child process of Sample-13-2.exe. We leave that as an exercise for you.

We have covered the various basic dynamic analysis power tools. In the next set of sections, let’s go through other tools and other malware properties and dynamic events that we can extract in combination with the basic dynamic analysis tools to draw a conclusion on the sample we are analyzing.

Detecting Code Injection

Code injection is one of the most prevalent features used by malware, so detecting it is important.

Code injection is caught using various techniques. One method detects the use of certain Win32 APIs. We listed the various APIs used by different code injection techniques in Chapter 10. Keeping these APIs in mind, and by using a tool like APIMiner, you can easily detect code injection.

Similarly, we can also detect code injection by using ProcMon. Certain code injection techniques involve creating a remote thread in another process, which pops up as an event in ProcMon. Usually, remote thread injection doesn’t always mean it is malware, since even clean software like debuggers can create a remote thread in another process. But if seen, you can treat it as suspicious and possibly code injection in progress and investigate it further. On seeing such an event, you should investigate both the process that created the remote thread and the remote process in which the new thread was created. Another effective method to detect certain code injection techniques is by searching for page properties where injected code pages most often have RWX permission and are private pages. Also, a good means of analysis at this point is to inspect the strings in the remote process memory searching for any malicious memory artifacts.

GMER and Ring3 API Hook Scanner

At this stage, let’s assume you have figured that the malware sample carries out code injection. Not every code injection technique indicates that the malware intends to do API hooking or is trying to use rootkit functionality. But it is a high possibility at this point that one of the intentions of the malware might be API hooking or rootkits. At this stage, it is best to run tools like GMER and Ring3 API Hook Scanner, both of which can easily tell you if any APIs have been hooked and if a rootkit has been detected. For more on this, you can refer to Chapter 10 and Chapter 11 for rootkits.

Yara on Live Processes

In Chapter 12, we explored how you can write YARA rules and run them on files on disk. You can also use the YARA tool. Run it with YARA rules against live running processes, which then use the process’s memory as a buffer to run the rules against. Try the YARA exercises in Chapter 12, but run the exercise samples against the live process by using the command line yara32.exe <yara_rules_file_path> <PID_OF_PROCESS>. The third parameter (<PID_OF_PROCESS>) is the PID of the process whose memory you want to scan with the YARA rules.

Other Malicious Behavior

Throughout Part 3 of this book, hands-on exercises demonstrated the various features and behaviors displayed by malware. We used various tools, both static and dynamic, for detecting malware features and events and not only concluded that a sample was malware but also determined its intent.

In this section, we rehash some of these notable malware features and how to identify them. To catch these malware features, we need static and dynamic analysis tools. It is important to know how to use these tools and all the malware features and events. Please refer to prior chapters when asked and play with the hands-on exercises. The more these concepts are ingrained in your mind, the more they become second-nature.

Stealing System File Names for Stealth

We covered stealing system file names for stealth in Chapter 11. In this technique, the malware uses the names of various OS system programs to name their malware files and processes in a bid to fool users into thinking they are clean OS programs and processes.

This mechanism of the malware can easily be noted by casually observing its behavior, the path of the process’s program file on disk, and other process properties by using tools like Process Hacker and Process Explorer.

Weird File and Process Names

We covered weird file names and process names in Chapter 11. With these techniques, malware uses enticing and misleading names to fool the user into clicking its files or ignoring process names in Task Manager.

This mechanism of the malware can easily be noted—first, by a good dose of common sense, and second, by having good knowledge of what normal programs and processes are named on your clean system. If you know how most OS system programs and processes are actually named, this will help you catch anomalous files and process names that look similar to the real ones.

ProcMon, APIMiner, Process Hacker, and casual observing file and process properties using a file browser are easy ways to obtain malware-event information, on top of which you can apply your common sense to catch anomalous behavior.

Disappearing Executable

A very common mechanism used by most malware is to copy itself to another location and then delete its program file on disk. You saw an example of this in Figure 13-3.

This malware technique easily pops up in the file browser if you casually observe its behavior when you run it. Similarly, ProcMon catches the event when the file is deleted. APIMiner catches the same events through CopyFile() and DeleteFile()Win32 API calls.

Number of Process Instances

Malware has a habit of using OS program/process names for its programs/processes. But we can catch this malware technique by exploiting the fact that there are only a certain fixed number of OS system processes that run at an instance of time. We see more processes than the fixed number for that OS system process name, and we can conclude we have something malicious going on.

We talked about this in Chapter 5. This technique can be easily caught by a tool like Process Hacker by casually observing the name of every process created when you run your analysis sample. If the newly created processes have a system program/process name, manually counting the number of instances with that process name.

Process Session IDs

Malware often names its programs/processes after OS system programs/processes. But most OS system programs run under session 0, as you learned in Chapter 5.

We can easily catch this malware behavior using Process Hacker by casually observing the name of every process created when you run your analysis sample. If it has a system program/process name, and verify if its session ID is 0 or not.

Summary

Continuing from Chapter 12, where we explained how to statically analyze samples, in this chapter, you learned how to run a sample and observe its behavior dynamically. We rehashed the dynamic analysis tools and techniques that we covered in Part 3. These techniques and tools help us identify a sample as malicious and then classify and categorize them. We extended your knowledge of string analysis, and you learned how to use it to dynamically search for malware string artifacts in a process’s memory. We also rehashed the other important malware behaviors that you can detect with the aid of dynamic tools.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.164.121