I’ve been exploring high-level malware analysis over the past few weeks. This post is a collection of thoughts and learnings from exploring this area of research.
First things first, you need to setup a lab environment off of your production network to analyze malware samples. I recommend using a virtual machine to acomplish this wether that is virtual box or VMware. You will need a Windows machine running Windows 7 or later depending on your needs.
I have opted for setting up the FLARE VM on Windows as it includes a plethora of utilities to get you started. A number of which I will be breifly discussing in this post.
Make sure to create a snapshot of a clean state once you have your analysis VM configured. You can restore this snapshot when you have completed an analysis session or need to update your system and tools.
It is important to ensure your VM is set to host-only mode when doing analysis to ensure the malware cannot connect to its C2 server or other machines on your network. This will prevent the malware from doing malicious operations that you will want to prevent when analyzing its inner workings.
Setting up FLARE VM is straight forward and to this point the only set of tools I’ve explored on this journey. Download the installer from https://github.com/fireeye/flare-vm and follow the instructions in Readme.md. This will transform your Windows VM into a malware analysis machine giving you the utilities you need to perform both static and dynamic analysis of malware samples.
PE File Format
Windows executables use the portable executable file format, also called the PE file format. These files contain the information required by the Windows loader to manage the wrapped executable code. The file begins with a header that contains information about the code, type of application, required library functions, and space requirements. Reviewing the PE file for this information gives us a great look at what the program may do. Looking at the required libraries and functions can give hints as to the functionality of the application. Reviewing space requirements may indicate if we are dealing with a packed executable. This is a good place to start when doing basic static analysis.
The four commonly found file sections include the following:
- Contains the instructions that the CPU executes
- This should be the only section that can execute
- Other sections include supporting information
- Contains import and export information
- Can also be used to store other read-only data
- Sometimes different compilers will create a .idata and .edata for import and export information
- Contains global information accessible from anywhere within the program
- Contains resources used by the application such as icons, menus, images, and strings.
While exploring your malware samples you may encounter packed executables. This is fairly common for malware authors to pack executables for both obsucaction and to avoid detection by scanners.
A couple tips on detecting if you are working with a packed executable.
- Running strings returns no human readable text
- The import address table is very sparse
- Section headers have declared sections with RAW Size of 0
When you encounter a packed executable there are a few tools included in the FLARE VM to help you unpack the exe.
Take a look at the following utilities to get started.
- CFF Explorer (supports UPX unpacking)
Tools for Basic Static Analysis
- Resource Hacker
Tools for Basic Dynamic Analysis
- Network monitoring
I’m going to dive a bit into FakeNet-NG as I found it particularly useful. FakeNet-NG is a dynamic network analysis tool for malware analysis. It allows you to intercept and redirect all or specific network traffic while simulating legitimate network services. What does this mean? While you are running in host-only mode on your VM, the malware cannot reach out to its C2 server or other network services. FakeNet-NG steps in and provides network services for the malware to communicate with providing fake network connectivity for your malware sample. During this process, FakeNet-NG will create a pcap file of all the traffic captured during the execution of the malware sample allowing you to dig deeper into what C2 servers or other network resources the malware is communicating with. This allows you to profile the malware functionality in safe manor.
For more information on FakeNet-NG visit https://github.com/fireeye/flare-fakenet-ng and read the provided documentation.
I will continue to update this post with additional information as my research progresses. I hope you found this useful.