Skip to content

Fix libvirt guests #628

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.vagrant/
output-qemu/
packer_cache/
packer/builds/
resources/drivers/
Expand Down
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,23 @@ Requirements:
3. When this process completes, you should be able to open the VM within VirtualBox and login. The default credentials are U: `vagrant` and P: `vagrant`.

### To build manually:

1. Clone this repo and navigate to the main directory.
2. Build the base VM image by running `packer build --only=<provider> ./packer/templates/windows_2008_r2.json` where `<provider>` is your preferred virtualization platform. Currently `virtualbox-iso`, `qemu`, and `vmware-iso` providers are supported. This will take a while the first time you run it since it has to download the OS installation ISO.
3. After the base Vagrant box is created you need to add it to your Vagrant environment. This can be done with the command `vagrant box add packer/builds/windows_2008_r2_*_0.1.0.box --name=rapid7/metasploitable3-win2k8`.
2. Build the base VM image by running `packer build --only=<provider> ./packer/templates/windows_2008_r2.json` where `<provider>` is your preferred virtualization platform. Currently `virtualbox-iso`, `qemu`, and `vmware-iso` providers are supported. This will take a while the first time you run it since it has to download the OS installation ISO. If you are using `qemu`, refer to the section [below](#Downloading-virtio-drivers) to download virtio-drivers.
3. After the base Vagrant box is created you need to add it to your Vagrant environment. This can be done with the command `vagrant box add packer/builds/windows_2008_r2_*_0.1.0.box --name=rapid7/metasploitable3-win2k8`. If using libvirt, you can use a custom pool name, by passing setting `LIBVIRT_POOL=<pool_name>` environment variable.
4. Use `vagrant plugin install vagrant-reload` to install the reload vagrant provisioner if you haven't already.
5. To start the VM, run the command `vagrant up win2k8`. This will start up the VM and run all of the installation and configuration scripts necessary to set everything up. This takes about 10 minutes.
6. Once this process completes, you can open up the VM within VirtualBox and login. The default credentials are:
- Username: `vagrant`
- Password: `vagrant`

#### Downloading virtio-drivers
If you are using QEMU/libvirt, you will need to download **virtio-drivers** for windows. A script in `./packer/scripts/virtio-win-drivers.sh` is already present. To use the script:
```sh
cd ./packer/scripts/
./virtio-win-drivers.sh
```
This will download the drivers and put the `amd64` the `./resources/drivers` directory.

### ub1404 Development and Modification

Using Vagrant and a lightweight Ubuntu 14.04 vagrant cloud box image, you can
Expand Down
15 changes: 14 additions & 1 deletion Vagrantfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
config.vm.synced_folder '.', '/vagrant', disabled: true
config.winrm.transport = :plaintext
config.winrm.basic_auth_only = true

config.vm.define "ub1404" do |ub1404|
ub1404.vm.box = "rapid7/metasploitable3-ub1404"
ub1404.vm.hostname = "metasploitable3-ub1404"
Expand All @@ -15,6 +17,13 @@ Vagrant.configure("2") do |config|
v.name = "Metasploitable3-ub1404"
v.memory = 2048
end

ub1404.vm.provider "libvirt" do |v|
v.memory = 2048
v.title = "Metasploitable3-ub1404"
v.storage_pool_name = ENV['LIBVIRT_POOL'] || "default"
end

end

config.vm.define "win2k8" do |win2k8|
Expand All @@ -41,6 +50,10 @@ Vagrant.configure("2") do |config|
v.hyperv_feature :name => 'relaxed', :state => 'on'
v.hyperv_feature :name => 'vapic', :state => 'on'
v.hyperv_feature :name => 'synic', :state => 'on'
v.hyperv_feature :name => 'vpindex', :state => 'on'
v.clock_timer :name => 'hypervclock', :present => 'yes'
v.title = "Metasploitable3-win2k8"
v.storage_pool_name = ENV['LIBVIRT_POOL'] || "default"
end

# Configure Firewall to open up vulnerable services
Expand Down
4 changes: 2 additions & 2 deletions chef/cookbooks/metasploitable/recipes/docker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#

docker_service 'default' do
install_method 'package'
version '18.06.1'
install_method 'tarball'
version '18.06.0'
action [:create, :start]
group 'docker'
end
Expand Down
2 changes: 2 additions & 0 deletions packer/scripts/virtio-win-drivers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,7 @@ if [ "$have_tools" = true ]; then
else
echo "Downloading and extracting virtio ${virtio_release} drivers."
wget -c "${virtio_uri}" -O ".${virtio_release}.vfd" && 7z x -oresources/drivers/virtio/"${virtio_release}" ".${virtio_release}.vfd" amd64/Win2008R2
mkdir ../../resources/drivers/
cp -r ./resources/drivers/virtio/virtio-win-0.1.117_amd64/amd64/ ../../resources/drivers/
fi
fi
65 changes: 21 additions & 44 deletions packer/templates/windows_2008_r2.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,18 +110,8 @@
"{{user `resources_dir`}}/certs/utn-userfirst.cer"
],
"vboxmanage": [
[
"modifyvm",
"{{.Name}}",
"--memory",
"4096"
],
[
"modifyvm",
"{{.Name}}",
"--cpus",
"2"
]
["modifyvm", "{{.Name}}", "--memory", "4096"],
["modifyvm", "{{.Name}}", "--cpus", "2"]
]
},
{
Expand All @@ -132,8 +122,8 @@
"boot_wait": "10m",
"communicator": "ssh",
"accelerator": "kvm",
"ssh_username": "vagrant",
"ssh_password": "vagrant",
"ssh_username": "vagrant",
"ssh_timeout": "2h",
"shutdown_command": "shutdown /s /t 10 /f /d p:4:1 /c \"Packer Shutdown\"",
"disk_size": 61440,
Expand All @@ -157,34 +147,29 @@
"{{user `resources_dir`}}/certs/microsoft_root_2011.cer",
"{{user `resources_dir`}}/certs/thawte_primary_root.cer",
"{{user `resources_dir`}}/certs/utn-userfirst.cer",
"./resources/drivers/virtio/*"
"{{user `resources_dir`}}/drivers/amd64/Win2008R2/*"
],
"qemuargs": [
[
"-m",
"4096"
],
[
"-smp",
"2"
],
[
"-display",
"gtk"
]
["-m", "4096"],
["-smp", "2"],
["-display", "gtk"]
]
}
],
"provisioners": [
{
"type": "shell-local",
"only_on": ["linux", "darwin"],
"inline": ["cd {{user `resources_dir`}} && {{user `resources_dir`}}/download-windows-files.sh"]
"type": "shell-local",
"only_on": ["linux", "darwin"],
"inline": [
"cd {{user `resources_dir`}} && {{user `resources_dir`}}/download-windows-files.sh"
]
},
{
"type": "shell-local",
"only_on": ["windows"],
"inline": ["cd {{user `resources_dir`}} && powershell {{user `resources_dir`}}/download-windows-files.ps1"]
"type": "shell-local",
"only_on": ["windows"],
"inline": [
"cd {{user `resources_dir`}} && powershell {{user `resources_dir`}}/download-windows-files.ps1"
]
},
{
"type": "file",
Expand All @@ -209,27 +194,21 @@
"type": "windows-shell",
"remote_path": "C:/Windows/Temp/script.bat",
"execute_command": "{{.Vars}} cmd /c C:/Windows/Temp/script.bat",
"scripts": [
"{{user `scripts_dir`}}/configs/disable_firewall.bat"
]
"scripts": ["{{user `scripts_dir`}}/configs/disable_firewall.bat"]
},
{
"type": "windows-restart"
},
{
"type": "powershell",
"scripts": [
"{{user `scripts_dir`}}/installs/install_dotnet45.ps1"
]
"scripts": ["{{user `scripts_dir`}}/installs/install_dotnet45.ps1"]
},
{
"type": "windows-restart"
},
{
"type": "powershell",
"scripts": [
"{{user `scripts_dir`}}/installs/install_wmf.ps1"
]
"scripts": ["{{user `scripts_dir`}}/installs/install_wmf.ps1"]
},
{
"type": "windows-restart",
Expand Down Expand Up @@ -325,9 +304,7 @@
},
{
"type": "powershell",
"inline": [
"mkdir -p C:/startup"
]
"inline": ["mkdir -p C:/startup"]
},
{
"type": "file",
Expand Down