Sitemap

Basic Malware Lab

7 min readDec 2, 2022

--

with Remnux and Oracle VB

Malware is any piece of code -compiled or otherwise- that’s harmful to your system. Unfortunately, discovering and eradicating malware remains challenging as attackers write increasingly sophisticated programs to evade detection.

Analysts often carry out malware analysis to understand the scope of impact that it may have on computer infrastructure and to understand the origin and internal structure of malware. A thorough study can reveal valuable information. Appropriate teams can then use this information to aid in preventing and neutering malware-related threats.

With the advent of cyberwarfare and the proven involvement of state actors, otherwise known as ‘APTs’ or Advanced Persistent Threats, malware analysis has become even more critical to understanding and studying targeted attacks.

Information security professionals like Lenny Zelster break down the malware analysis process into four stages, each with pros and cons.

Also, it gets progressively more complex as you get to the pyramid’s apex.

The Four Stages of Malware Analysis [7]

Not unlike the ‘Pyramid of Pain’ often referenced by defense teams on blue team operations.

We will look at creating a malware lab, also known as a sandbox, to study the malware’s static and dynamic properties in a safe environment. We will download a malware sample once we have created the lab.

We will use two virtual machines on a type 2 hypervisor, and for this project, I have selected Oracle’s virtual box, but others like VMWare or Hyper-V will also fit the bill.

As for virtual machines, one will be a windows box, and the other is Remnux — an ubuntu Linux distribution with malware tools — which will be the primary VM. Installing the VMs is pretty straightforward. Please see the references below for more information. [1]

After installing Remnux, please use the following command to update the system.

$remnux upgrade
$remnux update

$sudo apt update
$sudo apt autoremove
$sudo apt --fix-broken install

You don’t need to update the Windows machine; you can select any of the windows machines available for download at the Microsoft evaluation site. [6]

Remnux comes preinstalled with many malware inspection tools. As such, you only need to run the update as mentioned earlier to ensure the latest version of each program is installed for malware inspection. However, for the windows VM, please install the following tools manually. Installation should be straightforward. You can also take a snapshot of the VM if you want to revert to the ‘just-after-installation’ stage later in the process or if you want a do-over.

Tools to be installed on windows are:

1) Process Hacker (Dynamic)
2) Process Viewer (Dynamic)
3) PE Studio (Static)
4) Procmon (Dynamic)
5) Procdot (Dynamic)
6) Wireshark (Dynamic)
7) Regshot (Dynamic)

The analyst may launch one or more of the dynamic tools just before executing the malware sample. Some of these tools can be rather noisy, and analysts can leverage the in-built filters where appropriate.

Now that the VMs are ready, and just before shutting down the internet connection (this is to prevent C2 callouts from your IP), we need to download the malware sample. For studying highly sophisticated malware or worms, it is best to have a separate Type 1 hypervisor on a dedicated physical machine. The lab discussed here is suitable for studying droppers, RATs, and macro viruses. Also, please be reminded that some malware has anti-VM capabilities and will know if they are being run in a virtualized environment and either behave differently or stop executing altogether. Others will check to see if the host is part of an AD domain and will act accordingly. As such, there may be instances you will have to tailor your lab according to the malware type that you intend to study. There may also be an instance where we need the internet connection open to explore other nuances of malware activity, and for this, we may need to use a TOR relay or a VPN. For such complex needs, consider a different architecture.

Press enter or click to view image in full size
Malware Lab Architecture — Internal Network Only

We will download a RAT malware from ‘Any. Run’ malware repository. [5]

You can download a sample in Remnux for static analysis and another copy of the same malware in windows for interactive or dynamic analysis.

Now that the samples have been downloaded, we will need to do the following:

  1. Put Remnux on a static IP (Make sure the ifupdown package is installed)

The ifupdown is a set of high-level scripts in Debian/Ubuntu Linux distributions that can configure network interfaces, bridges, VLAN interfaces, bonding, and so on.

$sudo apt install ifupdown 
$sudo ifdown -av
$sudo nano /etc/network/interfaces

auto enp0s3
iface enp0s3 inet static
address 10.0.0.1
netmask 255.255.255.0

$sudo ifup -av
ifupdown package
Press enter or click to view image in full size
interfaces file for ifupdown
Press enter or click to view image in full size
Static IP on Remnux

2) For both VMs, change the Virtual Box networking setting to ‘Internal Network’ from ‘NAT.’ Also, give a name to the network. E.g., Malware Lab

Press enter or click to view image in full size
Internal Network name Malware Lab

3) On Windows VM

Set the default gateway to remnux IP
Set DNS to RemNUX IP
Only IPV4 enabled
Static IP on Windows Host

4) On Remnux, please do the following:

  • INetSim is a software suite for simulating common internet services in a lab environment, e.g., for analyzing the network behavior of unknown malware samples. [2]
  • fakedns: A fake DNS server for malware analysis written in Python3. [3]
$inetsim 
$fakedns
Inetsim
Fakedns

Please input the below commands to accept connections to all IPv4 and IPv6 addresses and redirect them to the corresponding local port.

$accept-all-ips start
or
$accept-all-ips start enp0s3

This technique uses IPtables’ NAT capabilities, as outlined in https://techanarchy.net/2013/10/inetsim-and-ip-addresses. This is convenient for intercepting and redirecting traffic in the malware analysis lab when malicious software attempts to connect to hard-coded or dynamically generated IP addresses. [4]

Press enter or click to view image in full size
To accept connections to all IPv4 and IPv6 addresses and redirect them to the corresponding local port

Before proceeding further, please navigate to www.google.com on the windows machine and make sure the ‘inetsim’ and ‘fakedns’ are working. (It is best to restart the windows machine before trying this.)

Press enter or click to view image in full size
Ping, DNS and all traffic are now being routed to Remnux!
Press enter or click to view image in full size
Intercepting Web Browser Traffic

We can test out the lab, and we have selected the ‘Bladabindi Trojan’ for this example. The file name is Amphetamine. solution.bin.(.exe) in any. run website. [5]

Press enter or click to view image in full size
Bladabindi Trojan\Amphetamine. solution.bin.(.exe) Hash
Press enter or click to view image in full size
Bladabindi Trojan downloaded from Any.Run

Static Analysis (Windows)

Press enter or click to view image in full size
PE Studio

Static Analysis (Remnux)

Press enter or click to view image in full size
Press enter or click to view image in full size
Press enter or click to view image in full size
Static Analysis using Remnux Tools

Interactive Analysis (Windows as host and Remnux as a lab)

Press enter or click to view image in full size
Press enter or click to view image in full size
Execution of the program spawns server.exe, and a connection to IP 37.235.48.172

Conclusion

To conclude, we could examine simple malware using this simple sandbox setup and see its static and dynamic properties. It is now possible to write YARA rules for threat hunting utilizing the information derived from the static analysis.

Get Rajanikanth Sugumar’s stories in your inbox

Join Medium for free to get updates from this writer.

And with Dynamic analysis, we could see the attempted connection to a possible C2 server.

Bonus

The author created the following basic YARA rule based on the results from the static properties of malware analysis. [8]

rule bladabindi
{
meta:
Author = "Raj Sugumar"
Version = "1.0"
Date = "12/2/2022"
Description = "(Yara.Rule) Rule for detecting Balabindi Malware"

strings:
$a1 = "https://dl.dropbox.com/s/p84aaz28t0hepul/Pass.exe?dl=0"
$a2 = "Exsample.exe" wide
$a3 = "37.235.48.172" wide
$a4 = "server.exe" wide
$a5 = "cmd.exe /k ping 0 & del"
$a6 = "netsh firewall delete allowedprogram"

condition:
any of them

}
Press enter or click to view image in full size
Yara Detection -YARA detected the malicious file using the YARA ruleset

References

1) https://docs.remnux.org/install-distro/get-virtual-appliance

2) INetSim: Internet Services Simulation Suite — Project Homepage

3) GitHub — wahlflo/fakedns: A fake DNS server for malware analysis written in Python3

4) https://raw.githubusercontent.com/REMnux/distro/master/files/accept-all-ips

5) https://any.run/

6) https://developer.microsoft.com/en-us/microsoft-edge/tools/vms/

7) https://zeltser.com/mastering-4-stages-of-malware-analysis/

8) https://yara.readthedocs.io/en/stable/

9) Bladabindi-njrat-Yara/njrat-Balabindi-YARA at main · rajanikanth-sugumar/Bladabindi-njrat-Yara · GitHub

Burp trouble

If Burp Suite is not installed on Remnux, please install it, and if you have issues running it, please use the command listed below as an option.

java -jar –add-opens=java.base/java.lang=ALL-UNNAMED –add-opens=java.desktop/javax.swing=ALL-UNNAMED /opt/burpsuite-community/burpsuite-community.jar

Some Networking Notes

$ifup -av / ifdown -av (Bring up/down all interfaces)
$httpd start  (If you need to start the Nginx Webserver)
Nginx Configuration path:
/var/www/html
nano index.html

After analysis in Remnux, you can transfer the file via an HTTP server (NGINX)

Press enter or click to view image in full size
Downloading Malware from Remnux to Windows via NGINX
Press enter or click to view image in full size
Launching Burpsuite
Press enter or click to view image in full size
Burpsuite Proxy Setup

--

--