SYS-CON MEDIA Authors: Kevin Benedict, Gilad Parann-Nissany

Related Topics: Security

Security: Blog Post

Malware Analysis - A Cost Effective and Quick "How To"

Full time malware analysis is expensive, this method provides a fast and simplified approach that produces results.

Malware analysis can be a time consuming process, especially when dealing with a sample from skilled attackers with time and money on their side . There is no doubt that fully reversing malware and finding out how it works is the most effective way to learn how to defend against it, but most businesses don't have the time or the professional resources to do it.

There are ways in which you, a Computer Network Defender, can glean enough information from malware to be used in IDS and AV signature creation, DNS poisoning and blocking as well as sharing with the CND community. This can be accomplished in a cost effective manner (maybe even free) and in an efficient manner that can rival very long code based analysis.  There are even cases where in depth knowledge of how to fully reverse the sample is not needed.

It should be noted that this is a low tech, high level mechanism for capturing indicators from malware. It should not be considered a substitute for fully analyzing malicious software, as sophisticated samples can defeat a lab environment similar to this quite easily. I will not be covering anything related to debugging the malware, that is outside of the intention of this "How-to".

Requirements
Before we start, you will need to procure a few bits and pieces:

  • Host machine with enough storage and memory to run at least 2 virtual machines concurrently, 4GB of ram and at least 30GB would be the minimum requirement.
  • A virtualization platform, there are several on the market, some of them are free to use, VirtualBox and Xen to name a couple. I will be using VMWare Fusion for this demonstration.
  • A copy of "REMNUX", a reverse-engineering malware linux distribution available at http://zeltser.com/remnux/.
  • A licensed copy of MS Windows (this will be your victim host). I will be using WindowsXP for this demonstration.
  • Free and open source tools for analysis of the Windows host (Putty, RegShot, Sysinternals, etc etc)

Setting Up the Victim Host Machine
Something to consider when setting up your victim host machine is system and software patches. Depending on what you are testing on your victim host, it may only affect a certain version of Windows, or possibly only to a certain patch level. Something I like to do is to "snapshot" my "victim" host machines through various patch stages, that way if I need to roll back, it's as easy as choosing a snapshot and "rolling back". This also applies to the types of software you install on your victim, snapshot your host with different versions of java, flash and adobe reader to be able to quickly select a vulnerable configuration. Consider outfitting your malware analysis lab setup with hosts that mimic your native operating environment. If you only utilize Windows 7 and do not allow Firefox on your network, then set up your victim machines to match that configuration.

A screenshot of the VMWare Fusion "Snapshot" process

Once you have finished patching your host, downloading and installing various types of software to aid in allowing successful exploitation you are going to setup a new network adapter, and set it for "host-only". This will keep your host from accidentally reaching the Internet once infected. It will also allow you to send the traffic to another machine to analyze what your victim is trying to do once successful exploitation has taken place.

  • Set the IP on your victim host to a non-routable address, for instance 10.1.1.10.
  • Set your router or gateway to be 10.1.1.1, this will the IP address of your REMNUX virtual machine.

Setting Up the REMNUX Host Machine
One of the main purposes for the REMNUX virtual machine in this demonstration is simply to act as a catch-all for network traffic originating from your now exploited victim host. REMNUX has many uses and capabilities both for the beginner and advanced malware reverse engineer, but we want fast indicators from our malware sample so that we can start defending against it immediately.

The REMNUX virtual machine is ready to go once imported into your virtualization platform with minimal modifications.  We are simply going to add a network adapter in "host-only" mode and set the IP address to a non-routable IP. REMNUX will act as the internet "gateway" and DNS server for our victim machine. This will allow us to see all network requests and DNS requests that come from our infected victim host.

A screenshot of the "REMNUX" desktop
A screenshot of the "REMNUX" network interfaces config, modify to suite your needs.

Infecting the Host
Now that you have the infrastructure in place, test your connectivity between the victim virtual machine and the gateway virtual machine. Have Wireshark running on the gateway box to verify successful connectivity. Attempt to SSH from your victim host to the gateway using putty. You can use "pscp.exe" within the Putty suite to move the original malware, and any malicious files the malware creates or drops onto your victim. Once you have moved the file over to your REMNUX host, you can take the MD5 of the original malware, before it is run. This will help in creating virus signatures and give you the required information for sharing within the CND community.

The victim host pre-infection with Process Explorer running.

Utilizing "Regshot", take a snapshot of the "C:" drive pre infection, that way you will have something to compare after your host is infected. Regshot will record the current windows registry, all windows directories and files before infection, allow you to record again after infection, and then compare the changes made to the host.

The victim host running Regshot and Process Explorer

You can now move your malware sample to the victim host. Ensure that you are running the necessary services and tools on your REMNUX host to capture the traffic. If you are not looking to interact with the malware, Wireshark can provide a wealth of data with not much in-depth knowledge. If you are looking to interact however, please consult the REMNUX readme for more information on "honeyd", "farpd" and "fakedns".

I also recommend running some kind of process explorer on the victim host to monitor what the malware does, any new processes it may spawn or kill. Sysinternals suite has several great tools, Process Explorer and Process Monitor are my two favorites.

Capturing the Indicators
Once executed on your victim host, you can record the information being fed to ProcMon, allowing you to watch what the malware does. You may see new applications start, processes get killed and new processes start. These are all indicators of the malware, and essential data to capture.

The victim host has a new process running attached to an executable with PID 2168

Watch your REMNUX host, check to see if any callouts are being made by the malware and see if it attempts to resolve DNS addresses. Often times once the DNS has successfully resolved, you will witness the malware attempt to connect to the Command & Control domain over an HTTP/HTTPS port.

A screenshot of Wireshark capturing the first DNS resolution attempt by the malware.
A screenshot of Wireshark capturing the second DNS resolution attempt by the malware.

A Note on DNS Resolution with Malware
The malware may attempt to resolve a known good website, this can be for internet connectivity checking as well as an attempt to fool someone monitoring it. If the malware is unable to resolve lets say “google.com” it may simply die on the victim host, and never try to reach the real command and control domain (CnC). This is when you want to have “fakedns” running on your REMNUX host, it will resolve any domain asked, this will then give the malware the positive connectivity test it is looking for, at which point may try to resolve the actual CnC domain.

Once you are satisfied with the length of time you have let the malware run, 10 minutes or less usually suffices, you can take the second “Regshot’ of the system. This will capture any changes made to the system by the malware. Once it has completed the second pass, compare the two and analyze the output. “Regshot” will reveal any new files created, deleted or modified. It will show you if any new registry keys were added or changed and any services that were created. It is an essential tool in the analysis toolbox.

A screenshot of the "Regshot" compare results.

As you can see with the "dir /ah" command, the files that were hidden on the victim. These files were all dropped from the malicious word document.

A screenshot showing the hidden files added to the temp directory on the victim host.

Once you have located the dropped or newly added malware on the victim host, you should move them over to your "REMNUX" host for analysis. These files are also indicators of a positive infection and should be included in your analysis of the initial malware. The MD5 hashes of these files are just as relevant for blocking and signature development as the principle delivery of these files, e.g. malicious word document, can easily change in future attempts.

Share Your Findings - One of the Most Important Pieces to Computer Network Defense
From this quick, and high level analysis of the malicious word document you were presented with several indicators that can benefit other Computer Network Defenders. One thing that I  have learned is that not everyone catches or sees something the way I may I see it.  So when I look at a piece of malware, no matter how simple I think it may be, I share it with the hopes that the indicators could assist others.

It is essential that you share as much information as you are comfortable with, as it may help to thwart future attempts against other targets. Collaboration amongst teams can help to stop these types of infections and identify current infections if they exist within your network. If possible, share any Command & Control Domains, MD5 Hashes, IP addresses, File Names and Sizes and anything else you feel is relevant to the infection.

More Stories By Cory Marchand

Cory Marchand is a trusted subject matter expert on topics of Cyber Security Threats, Network and Host based Assessment and Computer Forensics. Mr. Marchand has supported several customers over his 10+ years within the field of Computer Security including State, Federal and Military Government as well as the Private sector. Mr. Marchand holds several industry related certificates including CISSP, EnCE, GSEC, GCIA, GCIH, GREM, GSNA and CEH.