Post

Building a Virtual Security Home Lab: Part 8 - Malware Analysis Lab Setup

A step-by-step guide for building your very own Cybersecurity Home Lab using VirtualBox

Banner Background by logturnal on Freepik
Hacker Image by catalyststuff on Freepik

In the module, we are going to set up the Malware Analysis Lab. This lab will consist of two VMs. One of the VMs will be for Windows Malware Analysis and the other one will be for Linux Malware Analysis.

Creating New Interface

VirtualBox GUI does not allow us to create more than four Network Interfaces.

vbox-36

However, we can configure up to 8 interfaces per VM. To add more than 4 interfaces we have to utilize the VirtualBox CLI.

VirtualBox CLI Setup

The VirtualBox CLI binary is called VBoxManage.exe.

vbox-37

To be able to use the CLI we have to add its path as an environment variable.
VirtualBox is by default installed at C:\Program Files\Oracle\VirtualBox.

Copy the path to the executable from the navigation bar.

vbox-70

Open Search and type “Environment”. Click on Edit environment variables for your account.

vbox-38

In the top window select the variable named “Path” and then click on Edit.

vbox-40

Click on New and then paste the path to the VirtualBox CLI. Then click on OK.

vbox-41

Click on OK to close the Environment Variables menu.

To test if the variable was added successfully open PowerShell and run the following command:

1
2
# List all installed VMs
VBoxManage list vms

vbox-42

Creating new Interface

Before we create the new interfaces we need to know the name of the pfSense VM (it is “pfSense” in my case). The VM should also be “Powered Off”.

vbox-43

To add a network interface run the following commands:

1
2
3
4
5
6
7
8
9
10
11
# Create a Internet Network
VBoxManage modifyvm "pfSense" --nic5 intnet

# Use the Paravirtualized Adapter
VBoxManage modifyvm "pfSense" --nictype5 virtio

# Give it the name LAN 3
VBoxManage modifyvm "pfSense" --intnet5 "LAN 3"

# Network Interface is connected by Cable
VBoxManage modifyvm "pfSense" --cableconnected5 on

vbox-44

In the above commands “pfSense” is the name of my VM.
In the 3rd command in place of “LAN 3” you can use a different name that matches your network interface naming convention.

Now if we look at the overview of the pfSense VM we should see Adapter 5.

vbox-45

Interfaces that are created using the CLI will not show up in the Settings page for the VM. If you want to modify the adapter settings you have to do it using the CLI.

Enabling the Interface

Start the pfSense VM. On boot, you will notice that there are still only 4 interfaces. The new interface has to be onboarded before it shows up in pfSense.

pfsense-83

Enter 1 to select “Assign Interfaces”.
Should VLANs be set up now? n

pfsense-84

Enter the WAN interface name: vtnet0
Enter the LAN interface name: vtnet1
Enter the Optional 1 interface name: vtnet2
Enter the Optional 2 interface name: vtnet3
Enter the Optional 3 interface name: vtnet4

pfsense-85

Do you want to proceed?: y

pfsense-86

The new interface has been added. Now we need to assign the interface an IP address.

pfsense-87

Enter 2 to select “Set interface(s) IP address”
Enter 5 to select the OPT3 interface.

pfsense-88

Configure IPv4 address OPT3 interface via DHCP?: n
Enter the new OPT3 IPv4 address: 10.99.99.1
Enter the new OPT3 IPv4 subnet bit count: 24

For the next question press Enter. Since we are configuring a LAN interface we do not have to worry about the upstream gateway.

pfsense-89

Configure IPv6 address OPT3 interface via DHCP6: n
For the new OPT3 IPv6 address question press Enter.
Do you want to enable the DHCP server on OPT3?: y
Enter the start address of the IPv4 client address range: 10.99.99.11
Enter the end address of the IPv4 client address range: 10.99.99.243
Do you want to revert to HTTP as the webConfigurator protocol?: n

pfsense-90

Now interface OPT3 will have an IP address.

pfsense-91

Renaming the Interface

Launch the Kali Linux VM. Login to the pfSense web portal. From the navigation bar select Interfaces -> OPT3.

pfsense-92

In the description field enter ISOLATED. Scroll to the bottom and click on Save.

pfsense-93

Click on Apply Changes in the popup that appears to persist the changes.

pfsense-94

Interface Firewall Configuration

From the navigation bar click on Firewall -> Rules.

pfsense-95

Select the ISOLATED tab. Click on the “Add” button to create a new rule.

pfsense-96

Change the values as follows:
Action: Block
Address Family: IPv4+IPv6
Protocol: Any
Source: ISOLATED subnets
Description: Block access to everything

Scroll to the bottom and click on Save.

pfsense-97

In the popup click on Apply Changes to persist the new rule.

pfsense-98

pfsense-99

Since this Interface is going to be used for Malware Analysis we are blocking network access. This will ensure that malware cannot spread to other systems using the network.

Reboot pfSense

Now we need to restart pfSense to ensure that the firewall rules are propagated properly. From the navigation bar select Diagnostics -> Reboot.

pfsense-118

Click on Submit.

pfsense-119

Once pfSense boots up you will be redirected to the login page.

Flare VM Setup

To install Flare we need a Windows machine. Flare can be set up using most versions of Windows. Since we already have the ISO for Windows 10 Enterprise I will be using it to configure Flare.

Windows ISO Download

Go to the following URL: Windows 10 Enterprise | Microsoft Evaluation Center

Click on the 64-bit edition Enterprise ISO download option. The ISO file is ~5GB.

win-download-2

Creating the VM

Select Tools from the sidebar and click on New.

flare-1

Give the VM a name. Select the downloaded Windows 10 ISO Image. Check “Skip Unattended Installation”. Then click on Next.

flare-2

Increase Base Memory to 4096MB and click on Next.

flare-3

Increase the Drive Size to 100GB and click on Next.

flare-4

Verify all the settings and click on Finish.

flare-5

Adding VM to Group

Right-click on the VM and select Move to Group -> [New].

flare-6

Right-click on the group and rename it to “Malware Analysis”.

flare-7

Right-click on the “Malware Analysis” group and select Move to Group -> Home Lab.

flare-8

The final result should look as follows:

flare-9

Configuring the VM

Select the VM then from the toolbar select Settings.

flare-10

Go to System -> Motherboard. In the Boot Order field ensure that Hard Disk is on the top followed by Optical. Uncheck Floppy.

flare-11

Leave the Network Adatper on its default setting of NAT.

flare-12

Machines assigned to the ISOLATED interface does not have internet connection. But to setup Flare we need Internet access. Once we finish the configuring Flare we will move it to the correct subnet.

Click on OK to save the settings.

Installing Windows

Select the Flare VM from the sidebar and click on Start.

vbox-71

Install Windows as shown below. The installation process is identical to the process from the previous module (Part 7).

user-1

user-2

user-4

user-5

user-6

user-7

Select “Domain join instead”.

user-10

Provide a name that does not use special characters and spaces. This is very important. The installer for Flare will not work otherwise.

flare-13

user-13

user-14

user-15

Once on the desktop Windows will ask should access to the Internet be allowed click on Yes.

Guest Additions Installation

Install Guest Additions to enable the resizing on the VM display. Once again you can refer to the last module (Part 7) for more detailed steps.

user-17

user-18

user-19

user-20

user-22

user-23

After rebooting the VM. Remove the Guest Addition Image.

user-25

Creating VM Snapshot 1

Before we proceed we are going to take a snapshot of the VM. Snapshots allow us to roll back to an old functional state of the VM.

Shut down the VM. Click on the Hamburger menu on the right of the VM name in the sidebar. Select Snapshots.

flare-21

Click on Take.

flare-30

Give the Snapshot a descriptive name. Click on OK to create the Snapshot.

flare-22

Click on the Hamburger menu and click on Details to return to the original page.

Flare VM Pre-Install Configuration

You can read more about Flare VM and its pre-requisites on the below link:
mandiant/flare-vm: A collection of scripts to setup a reverse engineering environment

TLDR; “Windows Updates” and “Windows Defender” have to be disabled.

Disabling Windows Update

How to change account password on Windows 11 | Windows Central

Open on Search bar and search for “Settings”. Open the Settings app.

flare-14

Click on “Update & Security”.

flare-16

Click on the “Pause updates for 7 days” button.

flare-15

Disabling Windows Defender

Download the following script: jeremybeaume/tools: Script to disable Windows Defender

Right-click on the Shield icon on the taskbar and select “View Security Dashboard”.

flare-17

Click on “Virus & threat protection”.

flare-18

Select “Manage settings” from the “Virus & threat protection settings” section.

flare-19

Disable all the features that are shown in the image below:

flare-20

Right-click on the Start menu and select “Windows PowerShell (Admin)”.

flare-23

Run the following command to download the script:

1
2
# Save the script in the Downloads folder
Invoke-WebRequest "https://raw.githubusercontent.com/jeremybeaume/tools/master/disable-defender.ps1" -OutFile $HOME\Downloads\disable-defender.ps1

flare-48

Use the shortcut Windows+R to open the Run dialog. Enter msconfig and click on OK.

flare-24

Navigate to the Boot tab. In the Boot options section enable “Safe boot” and then click on OK to save changes.

flare-25

Click on Restart to boot into Safe Mode.

flare-26

In Safe Mode, the VM cannot be resizable. Safe Mode essentially disables all features that are not required to run the OS.

flare-27

Right-click on the Start menu and select “Windows PowerShell (Admin)” and enter the following commands:

1
2
3
4
5
6
7
8
# Change directory
cd .\Downloads\
# Unblock the downloaded script
Unblock-File .\disable-defender.ps1
# Disable the PowerShell policy preventing script execution 
Set-ExecutionPolicy Unrestricted -Force
# Start the script
.\disable-defender.ps1

flare-28

Once the script completes its execution press Enter to close the script. Reboot the VM for the changes to take place.

flare-29

Press Windows+R to open the Run dialog. Enter msconfig and click on OK.

Navigate to the Boot tab. From the Boot options section disable “Safe boot”. Click on Apply then OK. Restart the VM to boot normally into Windows.

flare-31

Wait for some time for Defender to load completely and then you will see that “Virus & threat protection” will show as disabled. This means that the script worked successfully.

flare-32

Renaming the VM

Search for “This PC” and from the right side click on “Properties”.

flare-35

Select “Rename this PC”.

flare-36

Give the PC a name. Click on Next and then select “Restart Now” for the changes to take effect.

flare-37

Creating VM Snapshot 2

Shut down the VM. Go to the Snapshot page using the Hamburger menu. Click on Take to create a new Snapshot.

flare-33

Give the Snapshot a descriptive name. Then click on OK.

flare-34

Use the Hamburger menu and return to the Details page. Click on Start to start the VM.

Flare VM Installation

Right-click on the Start menu and select “Windows PowerShell (Admin)”.

flare-23

Enter the following commands to download and run the Flare VM script.

1
2
3
4
5
6
7
8
9
10
# Download the FlareVM script
Invoke-WebRequest "https://raw.githubusercontent.com/mandiant/flare-vm/main/install.ps1" -OutFile $HOME/Downloads/install.ps1
# Go to Downloads Folder
cd $HOME/Downloads
# Unlock the downlaoded script
Unblock-File .\install.ps1
# Disable PowerShell script execution policy 
Set-ExecutionPolicy Unrestricted -Force
# Run the script
.\install.ps1

flare-38

The script will make some checks before starting the installation.

Enter Y when asked about Snapshot. Enter password when prompted.

flare-39

After some time the Flare VM configuration dialog will open.

flare-40

In the Package Installation Customization section from the left side select “debloat.vm” and click on the right arrow to select it for installation.

flare-41

Click on OK to start the install. The VM will restart multiple times during the setup.

flare-42

The installation can take a very long time. Once the setup is complete we will get the following prompt click on Finish to complete the setup.

flare-43

After the installation is complete. Restart the VM to complete the setup.

flare-44

Post-Install Configuration

Installing OpenSSH Server

Once we move this VM to the ISOLATED subnet it will not be able to access the internet. We will not be able to download malware samples directly from the Internet. We will download the samples onto a different VM that has Internet access and then move them to this machine using SSH. I will cover this process in more detail in a later module. For now, we need to install “OpenSSH Server”.

Open the Search bar. Type “Add” and from the results select the “Add or remove programs” option.

flare-49

Click on Optional Features under “Apps & features”.

flare-50

Click on Add a feature. This will open a new menu.

flare-51

Search for “SSH”. Enable “OpenSSH Server” and then click on Install.

flare-52

Once the install is complete if you search for “SSH” in the “Installed features” section you should see “OpenSSH Client” and “OpenSSH Server”.

flare-53

Moving VM to the Isolated Network

Shut down the VM. Open the VM Settings page and go to Network. For the Attached to field select Internal Network. For name select LAN 3. Click on OK to save the changes.

flare-45

Creating VM Snapshot 3

Using the Hamburger menu open the Snapshot page. Click on Take to create a Snapshot. Give the Snapshot a descriptive name and then click on Ok.

flare-46

flare-47

You can now delete the Windows 10 Enterprise ISO if you do not plan to store it in the future.

REMnux VM Setup

Download Image

Go to the following link: Get the Virtual Appliance - REMnux Documentation

Click on Box to open the download page.

remnux-14

Click on the blue Download button. The image is ~5GB.

remnux-15

Once the download is complete we will have an .ova file.

remnux-16

Creating the VM

Click on Tools from the sidebar and then select Import.

remnux-1

Select the downloaded OVA file and click on Next.

remnux-2

Configure the VM as required. Ensure the VM has 4096MB of RAM. For the MAC Address Policy select “Generate new MAC addresses for all network adapters” then click on Finish.

remnux-3

Adding VM to Group

Once the import is complete right-click on the VM and select Move to Group -> Home Lab/Malware Analysis.

remnux-4

Configuring the VM

Select the VM then click on Settings from the toolbar.

Go to System -> Motherboard. In Boot Order ensure that Hard Disk is on the top followed by Optical. Uncheck Floppy. Click on OK to save the changes.

remnux-5

Post-Install Configuration

Select the VM and from the toolbar click on Start.

remnux-6

Updating Guest Additions

The VM will already have Guest Additions installed but it will be an older version. From the VM toolbar select Devices -> Upgrade Guest Additions to update Guest Additions.

remnux-7

Upgrading Packages

Once Guest Additions is updated open a Terminal and enter the following command to update the system packages.

1
remnux upgrade

remnux-8

Once the update is complete restart the VM.

remnux-9

remnux-10

Moving VM to the Isolated Network

Shut down the VM. Open the Settings menu and select Network.

For the Attached to option select Internal Network. For the name field select LAN 3. Click on OK to save the changes. This will move the VM to the ISOLATED interface that does not have internet access.

remnux-11

Creating VM Snapshot

Click on the Hamburger menu and select Snapshot.

remnux-17

Click on Take to create a Snapshot.

remnux-18

Give the Snapshot a descriptive name. Then click on OK.

remnux-12

remnux-13

Use the Hamburger menu to go back to the Details page.

In the next, module we will start configuring the Security subnet. This subnet will have our DFIR VM and SIEM (Splunk).

Part 9 - Tsurugi Linux (DFIR) Setup

This post is licensed under CC BY 4.0 by the author.