Mounting the environment
A successful penetration test largely depends on how well your work environment and labs are configured. Moreover, a successful test answers the following set of questions:
- How well is your test lab configured?
- Are all the necessary tools for testing available? How good is your hardware to support such tools?
Before we start testing anything, we must make sure that all of the required sets of tools are available and updated.
Let's go ahead and set up Metasploit in a virtual environment.
Setting up Metasploit in a virtual environment
Before using Metasploit, we need to have a test lab. The best idea for setting up a test lab is to gather different machines and install different OSes on them. However, if we only have a single device, the best idea is to set up a virtual environment.
Virtualization plays an essential role in penetration testing today. Due to the high cost of hardware, virtualization plays a cost-effective role in penetration testing. Emulating different operating systems under the host OSes not only saves you money but also cuts down on electricity and space. However, setting up a virtual penetration test lab prevents any modifications from being made to the actual host system and allows us to perform operations in an isolated environment.
Moreover, the snapshot feature of virtualization helps preserve the state of the virtual machine (VM) at a particular point in time. This feature proves to be very helpful, as we can compare or reload a previous state of the operating system while testing a virtual environment, without reinstalling the entire software in case the files are modified after an attack simulation.
Virtualization expects the host system to have enough hardware resources, such as RAM, processing capabilities, drive space, and so on, to run smoothly.
Tip
For more information on snapshots, refer to https://www.virtualbox.org/manual/ch01.html#snapshots.
So, let's see how we can create a virtual environment with the Ubuntu operating system and install Metasploit 5 on it.
To create a virtual environment, we need virtual machine software. We can use either of the most popular ones, that is, VirtualBox or VMware Workstation Player. We will be using VMware Workstation Player throughout the book. So, let's begin with the installation by performing the following steps:
- Download VMware Workstation Player (https://www.vmware.com/in/products/workstation-player/workstation-player-evaluation.html) and set it up for your machine's architecture.
- Run the setup wizard and finalize the installation.
- Download the latest Ubuntu ISO image (https://ubuntu.com/download/desktop).
- Run the VM Player program, as shown in the following screenshot:
- Next, choose the Create a New Virtual Machine icon, which will populate the following window:
- Browse to the downloaded Ubuntu image and click Next.
- On the next screen, type in your full name and your desired User name and Password, as shown in the following screenshot:
- After choosing the desired name of the VM on the next screen, the Disk Capacity settings will populate, as shown in the following screenshot:
- By choosing a disk size of 40 GB, we will be shown the complete settings for the VM, as follows:
- At this point, we can go ahead with the default settings, that is, 1 GB of RAM and a 1-core processor. Alternatively, we can customize these settings based on the hardware capacity of the host machine. I will choose to customize the hardware and set Memory to 4 GB and 2 cores as the processor. The modified stings should look something similar to the following:
- After customizing the hardware requirements, we are ready to begin the installation process by clicking the Finish button. The installation process should begin and will look similar to the following screen:
- After a successful install, we will be greeted with the login page of our newly installed Ubuntu machine, as shown in the following screenshot:
- After successfully logging in with the password we set during the installation in step 7, we can set a root password using the sudo passwd root command, as follows:
- By setting a root password, we can switch to root anytime using the su command. Let's install the curl and nmap packages by typing apt-get install curl and apt-get install nmap before installing Metasploit, as shown in the following screenshot:
- Next, we simply need to download Metasploit using the curl https://raw.githubusercontent.com/rapid7/metasploit-omnibus/master/config/templates/metasploit-framework-wrappers/msfupdate.er> msfinstall command, as shown in the following screenshot:
- Once Metasploit has downloaded, we need to provide 755 permissions to the installer file using the chmod 755 msfinstall command and run the installer using the ./msfinstall command, as follows:
- Metasploit should now be installed. Once the installation is complete, we can check for the Metasploit utilities by typinmsf, followed by a tab, as shown in the following screenshot:
- With that, we have successfully installed Metasploit. Next, we need to initialize the Metasploit database using the msfdb init command, as follows:
- We will be prompted to set up a web service username and password during installation so that we can use the Metasploit API. We can choose any desired username and password. On successfully initializing the database, the web service will be live on port 5443, as shown in the following screenshot. We can use the credentials we set in the previous step to log into the web service:
- Finally, let's start the Metasploit console using the msfconsole command, as follows:
We have successfully installed Metasploit. Now, let's focus on some of the basic fundamentals before moving on to the actual testing.
Important Note
To set up a Metasploit development environment, refer to https://github.com/rapid7/metasploit-framework/wiki/Setting-Up-a-Metasploit-Development-Environment.
Metasploit 5.0 is a part of the latest Kali image, which can be downloaded from https://www.offensive-security.com/kali-linux-vm-vmware-virtualbox-image-download/.