SamuraiWTF, short for the Samurai Web Testing Framework, is a virtual machine designed for application security professionals. SamuraiWTF is similar in nature to Kali, but it is trimmed down to include tools that are primarily applicable to testing and attacking websites. Although I don’t particularly like using SamuraiWTF as my primary penetration testing platform, I feel it makes a great learning environment, as it is bundled with a number of open source tools that you can use right out of the gate.
If you use Vagrant and VirtualBox, you can literally be up and running with SamuraiWTF in minutes.
Not so with me…
My primary development box is a Windows 10 box. All 64-bit editions of Windows 8 Pro and Enterprise or later come prepackaged with Hyper-V. If you live in the Windows world, this is great, because Hyper-V is an absolutely fantastic virtualization platform.
There are alternatives out there, of course, the two primary candidates being VirtualBox and VMWare. Even though I like VirtualBox, it isn’t nearly as performant as Hyper-V. VMWare is great as well, but you have to pay for a license.
So I figured that there must be an easy way to get up and running using Vagrant to install SamuraiWTF on Hyper-V. I mean, Hyper-V has been a prepackaged provider in Vagrant for quite some time, so I thought it should be a cinch. And it really is…
As long as you know what you’re doing.
I didn’t. So it took me a little longer. I’m here to make sure that you don’t make the same mistake.
Configure the Hyper-V Network
By far the most frustrating aspect of using Vagrant with Hyper-V is the Hyper-V provider’s numerous networking limitations. These limitations make us go through a couple of hoops in order to allow us to provision a virtual machine. Before you can use Hyper-V with Vagrant, you’ll need to ensure that newly provisioned virtual machines will automatically receive an IP address and will have access to the internet.
There are two ways to accomplish this. First, you can configure the virtual machine to use a Hyper-V Virtual Switch with an External Network connection type. The problem with this option is that the external switch will kill your host’s Internet connection. This issue will hopefully be resolved in April’s Windows build, but I haven’t been able to test it out yet.
Your second alternative is to use a Hyper-V Virtual Switch with an Internal Network connection type. You can grant this switch access to your primary network adapter. Since Hyper-V comes prepackaged with a Default Switch with an internal network connection type, this is by far the easiest solution. The only thing you have left to do is grant this switch access to your primary network adapter.
Because the Default Switch comes bundled with Hyper-V and because using an external network connection brings your host’s network connection to the ground, I will be going with the second option. There doesn’t appear to be an easier option when installing SamuraiWTF on Hyper-V with Vagrant.
Grant Hyper-V’s Default Switch Access to the Internet
To grant the default switch access to your network adapter, perform the following steps:
Launch the Control Panel.
Choose Network and Internet | Network and Sharing Center. In the sidebar, click the Change adapter settings link. This will open the Network Connections window.
Right-click your primary network adapter and choose Properties. This will open the Properties dialog.
Activate the Sharing tab. At this point, the Allow other network users to connect through this computer’s Internet connection checkbox should be unchecked.
Check the Checkbox and select the Default Switch in the Home networking connection drop down. Then click the OK command button.
Now that you have allowed the default switch to use your network connection, it will grant your new VM an IP address on boot. This is absolutely imperative, as Vagrant will not work otherwise.
Install Vagrant
The next thing you need to do is install Vagrant if you haven’t already. If you are unfamiliar with Vagrant, it is utility that makes provisioning a virtual machine as simple as typing two words into a command prompt. It’s awesome.
To install Vagrant, follow the steps below:
- Visit https://www.vagrantup.com/.
- Click the Download link.
- Download the version for your Operating System. That should be 64-bit Windows if you’re reading this article…
- Run the installer to install Vagrant. You will need to reboot your machine once the installation completes.
Configure Vagrant
Even though Vagrant comes with support for Hyper-V by default, it won’t be the default configured provider. Also, SamuraiWTF will require the ‘reload’ plugin.
You’ll need to open an elevated PowerShell prompt to perform the following commands. All we’re doing is configuring an environment variable so that the default provider is Hyper-V and installing the reload plugin.
> $Env:VAGRANT_DEFAULT_PROVIDER = "hyperv" > vagrant plugin update > vagrant plugin install vagrant-reload
Clone the SamuraiWTF Git Repository
Next, you’ll need to clone the SamuraiWTF repository. The main branch doesn’t have support for Hyper-V, so’ll you’ll need to clone the “hyperv_support” branch. If you have a Git client installed, then you can just execute this command in your elevated PowerShell command prompt:
> git clone --branch hyperv_support https://github.com/SamuraiWTF/samuraiwtf.git > cd samuraiwtf
If you don’t have a Git client, then head on over to the project on GitHub and download the repository as a zip file. Unzip the folder to somewhere on your local drive. Then open an elevated PowerShell prompt in that directory.
Provision the SamuraiWTF Virtual Machine
From the SamuraiWTF directory in an elevated PowerShell prompt, execute the following command:
> vagrant up
This will begin the lengthy process of provisioning the SamuraiWTF VM in Hyper-V. Don’t go too far. You’ll need to answer a few questions.
First, you may be asked to select a virtual switch so that vagrant can communicate with the newly provisioned VM. You may see a screen that looks like this:
Bringing machine 'samuraiwtf' up with 'hyperv' provider... ==> samuraiwtf: Verifying Hyper-V is enabled... ==> samuraiwtf: Verifying Hyper-V is accessible... ==> samuraiwtf: Importing a Hyper-V instance samuraiwtf: Creating and registering the VM... samuraiwtf: Successfully imported VM samuraiwtf: Please choose a switch to attach to your Hyper-V instance. samuraiwtf: If none of these are appropriate, please open the Hyper-V manager samuraiwtf: to create a new virtual switch. samuraiwtf: samuraiwtf: 1) DockerNAT samuraiwtf: 2) Default Switch samuraiwtf: samuraiwtf: What switch would you like to use? 2
You’ll want to select the Default Switch that you configured above. Note that these switches seemingly appear in random order, so it won’t always appear first or second in the list.
Next, Vagrant will attempt to establish an SMB share on your host machine. This SMB share will be used by vagrant to transmit necessary files to the newly provisioned virtual machine. In order to do this, Vagrant will prompt you for an SMB username and password. This needs to be an administrative account on your host Windows box. I’m an administrator, so I used my account. If your account is a domain user, don’t include the domain in the username.
Vagrant requires administrator access for pruning SMB shares and may request access to complete removal of stale shares. ==> samuraiwtf: Preparing SMB shared folders... samuraiwtf: You will be asked for the username and password to use for the SMB samuraiwtf: folders shortly. Please use the proper username/password of your samuraiwtf: account. samuraiwtf: samuraiwtf: Username: <hidden> samuraiwtf: Password (will be hidden): <hidden>
Vagrant will restart your virtual machine during the provisioning process. At around the 10 minute mark, you will have to enter your SMB username and password again. At the end of the installation, your virtual machine will turn off with the following message:
samuraiwtf: Install is complete. samuraiwtf: Reboot your machine to begin using XRDP. samuraiwtf: Be sure to run Set-VM -VMName <NAME> -EnhancedSessionTransportType HvSocket in powershell ==> samuraiwtf: Running provisioner: shell... samuraiwtf: Running: inline script ==> samuraiwtf: Running provisioner: shell... The provider for this Vagrant-managed machine is reporting that it is not yet ready for SSH. Depending on your provider this can carry different meanings. Make sure your machine is created and running and try again. Additionally, check the output of `vagrant status` to verify that the machine is in the state that you expect. If you continue to get this error message, please view the documentation for the provider you're using.
Run the ‘vagrant up’ command once more to complete the provisioning process.You’ll need to enter your SMB credentials one more time. The provisioning scripts will finally complete and the VM will be fully up and running.
Connect to the SamuraiWTF VM
In order to connect to SamuraiWTF, you must do so through Hyper-V Manager. Open Hyper-V Manager and select the newly created virtual machine. Then, in the Actions menu, click the “Connect…” link. This will open the VM in a new window.
You should see a login prompt, although the prompt may be obstructed with a bit of console error output.
You can simply hit the [ENTER] key once for a clean username prompt. Enter the following credentials:
Ubuntu 18.04.2 LTS SamuraiWTF tty1 SamuraiWTF login: samurai Password: samurai
After you enter the credentials, you will be presented with the SamuraiWTF desktop. Congratulations!
Conclusion
In this post, I showed how you can use Vagrant to install SamuraiWTF on Hyper-V. By using Vagrant, you can be up and running with SamuraiWTF in minutes.