From 918b3c5775152c15fafade956b59d98382b993e6 Mon Sep 17 00:00:00 2001 From: BoogleCloud Date: Sun, 2 Sep 2018 11:53:41 -0700 Subject: [PATCH 01/17] Added hyper-v specific options and message regarding the share mount --- Vagrantfile | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/Vagrantfile b/Vagrantfile index 667e06b7..f9185da5 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -15,6 +15,12 @@ Vagrant.configure("2") do |config| v.name = "Metasploitable3-ub1404" v.memory = 2048 end + + config.vm.provider "hyperv" do |h| + config.vm.boot_timeout = 300 + h.linked_clone = true + h.memory = 2048 + end end config.vm.define "win2k8" do |win2k8| @@ -26,6 +32,30 @@ Vagrant.configure("2") do |config| win2k8.winrm.retry_delay = 10 win2k8.vm.network "private_network", type: "dhcp" + + config.vm.provider "hyperv" do |h| + config.vm.boot_timeout = 300 + h.linked_clone = true + h.memory = 2048 + h.maxmemory = 4096 + config.vm.post_up_message = < Date: Sun, 2 Sep 2018 11:56:32 -0700 Subject: [PATCH 02/17] Updated logic to check for hyper-v and updated variables for packer and vagrant builds to appropriately use the virtualization technology chosen --- build.ps1 | 65 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 36 insertions(+), 29 deletions(-) diff --git a/build.ps1 b/build.ps1 index 47052914..5636a2f3 100755 --- a/build.ps1 +++ b/build.ps1 @@ -32,35 +32,43 @@ function CompareVersions ($actualVersion, $expectedVersion, $exactMatch = $False } Write-Host ""; -$expectedVBoxLocation = "C:\Program Files\Oracle\VirtualBox" - -If ($(Test-Path "$expectedVBoxLocation\VBoxManage.exe") -eq $True) { - - $vboxVersion = cmd.exe /c "$expectedVBoxLocation\VBoxManage.exe" -v - $vboxVersion = $vboxVersion.split("r")[0] +If($(Get-WindowsOptionalFeature -FeatureName Microsoft-Hyper-V -Online).State = "Enabled") { + Write-Host "Using Hyper-V as provider." + $provider = "hyperv" + } else { - - Write-Host "VirtualBox is not installed (or not in the expected location of $expectedVBoxLocation\)" - Write-Host "Please download and install it from https://www.virtualbox.org/" - exit - + + $expectedVBoxLocation = "C:\Program Files\Oracle\VirtualBox" + If ($(Test-Path "$expectedVBoxLocation\VBoxManage.exe") -eq $True) { + + $vboxVersion = cmd.exe /c "$expectedVBoxLocation\VBoxManage.exe" -v + $vboxVersion = $vboxVersion.split("r")[0] + + If (CompareVersions -actualVersion $vboxVersion -expectedVersion $virtualBoxMinVersion -exactMatch $False) { + Write-Host "Compatible version of VirtualBox found, using as provider." + $provider = "virtualbox" + + } else { + + Write-Host "A compatible version of VirtualBox was not found." + Write-Host "Current Version=[$vboxVersion], Minimum Version=[$virtualBoxMinVersion]" + Write-Host "Please download and install it from https://www.virtualbox.org/" + exit + + } + + } else { + Write-Host "Neither Hyper-V nor VirtualBox was found (or not in the expected location of $expectedVBoxLocation\)" + Write-Host "Follow these instructions if you want to use Hyper-V:" + Write-Host "https://docs.microsoft.com/en-us/virtualization/hyper-v-on-windows/quick-start/enable-hyper-v" + Write-Host "Or download and install VirtualBox from https://www.virtualbox.org/" + exit + + } } -If (CompareVersions -actualVersion $vboxVersion -expectedVersion $virtualBoxMinVersion -exactMatch $False) { - - Write-Host "Compatible version of VirtualBox found." - -} else { - - Write-Host "A compatible version of VirtualBox was not found." - Write-Host "Current Version=[$vboxVersion], Minimum Version=[$virtualBoxMinVersion]" - Write-Host "Please download and install it from https://www.virtualbox.org/" - exit - -} - $packerVersion = cmd.exe /c $packer -v If (CompareVersions -actualVersion $packerVersion -expectedVersion $packerMinVersion) { @@ -135,14 +143,14 @@ function InstallBox($os_full, $os_short) $boxversion = $boxversion.toString().trim().split('"')[3] Write-Host "Building metasploitable3-$os_short Vagrant box..." - - If ($(Test-Path "packer\builds\$($os_full)_virtualbox_$boxversion.box") -eq $True) { + + If ($(Test-Path "packer\builds\$($os_full)_$($provider)_$boxversion.box") -eq $True) { Write-Host "It looks like the Vagrant box already exists. Skipping the Packer build." } else { - cmd.exe /c $packer build --only=virtualbox-iso packer\templates\$os_full.json + cmd.exe /c $packer build --only=$provider-iso packer\templates\$os_full.json if($?) { Write-Host "Box successfully built by Packer." @@ -158,7 +166,7 @@ function InstallBox($os_full, $os_short) Write-Host "rapid7/metasploitable3-$os_short already found in Vagrant box repository. Skipping the addition to Vagrant." } else { - cmd.exe /c vagrant box add packer\builds\$($os_full)_virtualbox_$boxversion.box --name rapid7/metasploitable3-$os_short + cmd.exe /c vagrant box add packer\builds\$($os_full)_$($provider)_$boxversion.box --name rapid7/metasploitable3-$os_short if($?) { Write-Host "rapid7/metasploitable3-$os_short box successfully added to Vagrant." @@ -169,7 +177,6 @@ function InstallBox($os_full, $os_short) } - Write-Host "All requirements found. Proceeding..." if($args.Length -eq 0) From 1152dfcdd7bd8793e3acfc437269705a02ca7062 Mon Sep 17 00:00:00 2001 From: BoogleCloud Date: Sun, 2 Sep 2018 11:57:27 -0700 Subject: [PATCH 03/17] Added entry to install the Hyper-V tools if present. This is required for Hyper-V to correctly detect the IP address of the guest for the remaining packer provisioning --- packer/answer_files/2008_r2/Autounattend.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packer/answer_files/2008_r2/Autounattend.xml b/packer/answer_files/2008_r2/Autounattend.xml index f9e19786..40e9668e 100644 --- a/packer/answer_files/2008_r2/Autounattend.xml +++ b/packer/answer_files/2008_r2/Autounattend.xml @@ -279,6 +279,12 @@ 99 true + + cmd.exe /c "set PACKER_BUILDER_TYPE=hyperv-first-boot&&a:\vm-guest-tools.bat + Install VM tools for Hyper-V (currently the only provisioner which will add this script) + 100 + true + From 34134eafe83a4d8f328ba79035dab2e6c64db07a Mon Sep 17 00:00:00 2001 From: BoogleCloud Date: Sun, 2 Sep 2018 12:03:00 -0700 Subject: [PATCH 04/17] Added linux-cloud-tools packages so that Hyper-V will know the ubuntu system IP address for packer provisioning --- packer/http/preseed.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packer/http/preseed.cfg b/packer/http/preseed.cfg index 40a40815..12981aff 100644 --- a/packer/http/preseed.cfg +++ b/packer/http/preseed.cfg @@ -16,7 +16,7 @@ d-i partman/choose_partition select finish d-i partman/confirm boolean true d-i partman/confirm_nooverwrite boolean true d-i partman/confirm_write_new_label boolean true -d-i pkgsel/include string openssh-server cryptsetup build-essential libssl-dev libreadline-dev zlib1g-dev linux-source dkms nfs-common curl wget ca-certificates libwww-perl python open-vm-tools-lts-trusty +d-i pkgsel/include string openssh-server cryptsetup build-essential libssl-dev libreadline-dev zlib1g-dev linux-source dkms nfs-common curl wget ca-certificates libwww-perl python open-vm-tools-lts-trusty linux-tools-$(uname -r) linux-cloud-tools-$(uname -r) linux-cloud-tools-common d-i pkgsel/install-language-support boolean false d-i pkgsel/update-policy select unattended-upgrades d-i pkgsel/upgrade select full-upgrade From c48ce3a14e78344f4ee32aeb9bed645c7f1af61c Mon Sep 17 00:00:00 2001 From: BoogleCloud Date: Sun, 2 Sep 2018 12:04:47 -0700 Subject: [PATCH 05/17] Added hyper-v builder section for packer --- packer/templates/ubuntu_1404.json | 32 +++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/packer/templates/ubuntu_1404.json b/packer/templates/ubuntu_1404.json index d8cfeb12..ef082353 100644 --- a/packer/templates/ubuntu_1404.json +++ b/packer/templates/ubuntu_1404.json @@ -1,5 +1,37 @@ { "builders": [ + { + "type": "hyperv-iso", + "iso_url": "{{user `iso_url`}}", + "iso_checksum_type": "{{user `iso_checksum_type`}}", + "iso_checksum": "{{user `iso_checksum`}}", + "http_directory" : "{{template_dir}}/../http", + "http_port_min" : 9001, + "http_port_max" : 9001, + "boot_command": [ + "", + "", + "", + "/install/vmlinuz", + " auto=true", + " priority=critical", + " initrd=/install/initrd.gz", + " preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed.cfg", + " -- ", + "" + ], + "boot_wait": "20s", + "communicator": "ssh", + "ssh_username": "vagrant", + "ssh_password": "vagrant", + "ssh_timeout": "2h", + "shutdown_command": "echo 'packer' | sudo -S shutdown -P now", + "disk_size": 40000, + "vm_name": "metasploitable3-ub1404", + "cpu": "2", + "ram_size": "4096", + "enable_dynamic_memory": "false" + }, { "type": "vmware-iso", "iso_url": "{{user `iso_url`}}", From 0ef3837c7fce4bd5de7b8d2a83d2a4acfd649ea8 Mon Sep 17 00:00:00 2001 From: BoogleCloud Date: Sun, 2 Sep 2018 12:05:05 -0700 Subject: [PATCH 06/17] Added hyper-v builder section for packer --- packer/templates/windows_2008_r2.json | 44 +++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/packer/templates/windows_2008_r2.json b/packer/templates/windows_2008_r2.json index 0ccf2360..9c78a2ad 100644 --- a/packer/templates/windows_2008_r2.json +++ b/packer/templates/windows_2008_r2.json @@ -1,5 +1,43 @@ { "builders": [ + { + "type": "hyperv-iso", + "iso_url": "{{user `iso_url`}}", + "iso_checksum_type": "{{user `iso_checksum_type`}}", + "iso_checksum": "{{user `iso_checksum`}}", + "communicator": "ssh", + "ssh_username": "vagrant", + "ssh_password": "vagrant", + "ssh_timeout":"2h", + "shutdown_command": "shutdown /s /t 10 /f /d p:4:1 /c \"Packer Shutdown\"", + "boot_wait": "10m", + "floppy_files": [ + "{{user `autounattend`}}", + "{{user `scripts_dir`}}/configs/microsoft-updates.bat", + "{{user `scripts_dir`}}/configs/win-updates.ps1", + "{{user `scripts_dir`}}/installs/openssh.ps1", + "{{user `scripts_dir`}}/installs/install_dotnet45.ps1", + "{{user `scripts_dir`}}/installs/install_wmf.ps1", + "{{user `scripts_dir`}}/installs/vm-guest-tools.bat", + "{{user `resources_dir`}}/certs/oracle-cert.cer", + "{{user `resources_dir`}}/certs/gdig2.crt", + "{{user `resources_dir`}}/certs/comodorsadomainvalidationsecureserverca.crt", + "{{user `resources_dir`}}/certs/comodorsacertificationauthority.crt", + "{{user `resources_dir`}}/certs/addtrust_external_ca.cer", + "{{user `resources_dir`}}/certs/baltimore_ca.cer", + "{{user `resources_dir`}}/certs/digicert.cer", + "{{user `resources_dir`}}/certs/equifax.cer", + "{{user `resources_dir`}}/certs/globalsign.cer", + "{{user `resources_dir`}}/certs/gte_cybertrust.cer", + "{{user `resources_dir`}}/certs/microsoft_root_2011.cer", + "{{user `resources_dir`}}/certs/thawte_primary_root.cer", + "{{user `resources_dir`}}/certs/utn-userfirst.cer" + ], + "vm_name": "metasploitable3-win2k8", + "cpu": "2", + "ram_size": "4096", + "enable_dynamic_memory": "false" + }, { "type": "vmware-iso", "iso_url": "{{user `iso_url`}}", @@ -141,6 +179,12 @@ } ], "provisioners": [ + { + "type": "file", + "source": "{{user `scripts_dir`}}", + "destination": "C:/vagrant", + "pause_before": "2m" + }, { "type": "file", "source": "{{user `scripts_dir`}}", From 4dbe828107d6a5a4c67a582c81b3864e844f61eb Mon Sep 17 00:00:00 2001 From: BoogleCloud Date: Sun, 2 Sep 2018 12:05:38 -0700 Subject: [PATCH 07/17] Added section to install hyper-v tools on first boot. It needs to be done then so that the remaining packer provisioning can occur --- scripts/installs/vm-guest-tools.bat | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/scripts/installs/vm-guest-tools.bat b/scripts/installs/vm-guest-tools.bat index 5639cd35..a347e6c6 100644 --- a/scripts/installs/vm-guest-tools.bat +++ b/scripts/installs/vm-guest-tools.bat @@ -6,6 +6,7 @@ msiexec /qb /i C:\Windows\Temp\7zInstaller-x64.msi if "%PACKER_BUILDER_TYPE%" equ "vmware-iso" goto :vmware if "%PACKER_BUILDER_TYPE%" equ "virtualbox-iso" goto :virtualbox if "%PACKER_BUILDER_TYPE%" equ "parallels-iso" goto :parallels +if "%PACKER_BUILDER_TYPE%" equ "hyperv-first-boot" goto :hyperv goto :done :vmware @@ -46,5 +47,15 @@ if exist "C:\Users\vagrant\prl-tools-win.iso" ( rd /S /Q "c:\Windows\Temp\parallels" ) +:hyperv +if not exist "C:\Windows\Temp\vmguest.iso" ( + echo "Downloading and installing Hyper-V tools" + powershell -Command "(New-Object System.Net.WebClient).DownloadFile('https://content.deltik.org/mirror/os/windows/vmguest.iso', 'C:\Windows\Temp\vmguest.iso')" Date: Sat, 15 Sep 2018 18:57:17 -0400 Subject: [PATCH 08/17] Added execute_command option to correctly handle inline powershell over GNU SSH --- packer/templates/windows_2008_r2.json | 1 + 1 file changed, 1 insertion(+) diff --git a/packer/templates/windows_2008_r2.json b/packer/templates/windows_2008_r2.json index 9c78a2ad..63b9b4b7 100644 --- a/packer/templates/windows_2008_r2.json +++ b/packer/templates/windows_2008_r2.json @@ -290,6 +290,7 @@ }, { "type":"powershell", + "execute_command": "powershell -executionpolicy bypass \"& { if (Test-Path variable:global:ProgressPreference){\\$ProgressPreference='SilentlyContinue'};. {{.Vars}}; &'{{.Path}}'; exit \\$LastExitCode }\"", "inline": [ "mkdir -p C:/startup" ] From e905d0a3d6667202aa1fd34088aa25f1a12ef6c9 Mon Sep 17 00:00:00 2001 From: BoogleCloud Date: Sun, 2 Sep 2018 11:53:41 -0700 Subject: [PATCH 09/17] Added hyper-v specific options and message regarding the share mount --- Vagrantfile | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/Vagrantfile b/Vagrantfile index 667e06b7..f9185da5 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -15,6 +15,12 @@ Vagrant.configure("2") do |config| v.name = "Metasploitable3-ub1404" v.memory = 2048 end + + config.vm.provider "hyperv" do |h| + config.vm.boot_timeout = 300 + h.linked_clone = true + h.memory = 2048 + end end config.vm.define "win2k8" do |win2k8| @@ -26,6 +32,30 @@ Vagrant.configure("2") do |config| win2k8.winrm.retry_delay = 10 win2k8.vm.network "private_network", type: "dhcp" + + config.vm.provider "hyperv" do |h| + config.vm.boot_timeout = 300 + h.linked_clone = true + h.memory = 2048 + h.maxmemory = 4096 + config.vm.post_up_message = < Date: Sun, 2 Sep 2018 11:56:32 -0700 Subject: [PATCH 10/17] Updated logic to check for hyper-v and updated variables for packer and vagrant builds to appropriately use the virtualization technology chosen --- build.ps1 | 65 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 36 insertions(+), 29 deletions(-) diff --git a/build.ps1 b/build.ps1 index 47052914..5636a2f3 100755 --- a/build.ps1 +++ b/build.ps1 @@ -32,35 +32,43 @@ function CompareVersions ($actualVersion, $expectedVersion, $exactMatch = $False } Write-Host ""; -$expectedVBoxLocation = "C:\Program Files\Oracle\VirtualBox" - -If ($(Test-Path "$expectedVBoxLocation\VBoxManage.exe") -eq $True) { - - $vboxVersion = cmd.exe /c "$expectedVBoxLocation\VBoxManage.exe" -v - $vboxVersion = $vboxVersion.split("r")[0] +If($(Get-WindowsOptionalFeature -FeatureName Microsoft-Hyper-V -Online).State = "Enabled") { + Write-Host "Using Hyper-V as provider." + $provider = "hyperv" + } else { - - Write-Host "VirtualBox is not installed (or not in the expected location of $expectedVBoxLocation\)" - Write-Host "Please download and install it from https://www.virtualbox.org/" - exit - + + $expectedVBoxLocation = "C:\Program Files\Oracle\VirtualBox" + If ($(Test-Path "$expectedVBoxLocation\VBoxManage.exe") -eq $True) { + + $vboxVersion = cmd.exe /c "$expectedVBoxLocation\VBoxManage.exe" -v + $vboxVersion = $vboxVersion.split("r")[0] + + If (CompareVersions -actualVersion $vboxVersion -expectedVersion $virtualBoxMinVersion -exactMatch $False) { + Write-Host "Compatible version of VirtualBox found, using as provider." + $provider = "virtualbox" + + } else { + + Write-Host "A compatible version of VirtualBox was not found." + Write-Host "Current Version=[$vboxVersion], Minimum Version=[$virtualBoxMinVersion]" + Write-Host "Please download and install it from https://www.virtualbox.org/" + exit + + } + + } else { + Write-Host "Neither Hyper-V nor VirtualBox was found (or not in the expected location of $expectedVBoxLocation\)" + Write-Host "Follow these instructions if you want to use Hyper-V:" + Write-Host "https://docs.microsoft.com/en-us/virtualization/hyper-v-on-windows/quick-start/enable-hyper-v" + Write-Host "Or download and install VirtualBox from https://www.virtualbox.org/" + exit + + } } -If (CompareVersions -actualVersion $vboxVersion -expectedVersion $virtualBoxMinVersion -exactMatch $False) { - - Write-Host "Compatible version of VirtualBox found." - -} else { - - Write-Host "A compatible version of VirtualBox was not found." - Write-Host "Current Version=[$vboxVersion], Minimum Version=[$virtualBoxMinVersion]" - Write-Host "Please download and install it from https://www.virtualbox.org/" - exit - -} - $packerVersion = cmd.exe /c $packer -v If (CompareVersions -actualVersion $packerVersion -expectedVersion $packerMinVersion) { @@ -135,14 +143,14 @@ function InstallBox($os_full, $os_short) $boxversion = $boxversion.toString().trim().split('"')[3] Write-Host "Building metasploitable3-$os_short Vagrant box..." - - If ($(Test-Path "packer\builds\$($os_full)_virtualbox_$boxversion.box") -eq $True) { + + If ($(Test-Path "packer\builds\$($os_full)_$($provider)_$boxversion.box") -eq $True) { Write-Host "It looks like the Vagrant box already exists. Skipping the Packer build." } else { - cmd.exe /c $packer build --only=virtualbox-iso packer\templates\$os_full.json + cmd.exe /c $packer build --only=$provider-iso packer\templates\$os_full.json if($?) { Write-Host "Box successfully built by Packer." @@ -158,7 +166,7 @@ function InstallBox($os_full, $os_short) Write-Host "rapid7/metasploitable3-$os_short already found in Vagrant box repository. Skipping the addition to Vagrant." } else { - cmd.exe /c vagrant box add packer\builds\$($os_full)_virtualbox_$boxversion.box --name rapid7/metasploitable3-$os_short + cmd.exe /c vagrant box add packer\builds\$($os_full)_$($provider)_$boxversion.box --name rapid7/metasploitable3-$os_short if($?) { Write-Host "rapid7/metasploitable3-$os_short box successfully added to Vagrant." @@ -169,7 +177,6 @@ function InstallBox($os_full, $os_short) } - Write-Host "All requirements found. Proceeding..." if($args.Length -eq 0) From 51675f10c302b7f00f704e0329435a2dc07c116d Mon Sep 17 00:00:00 2001 From: BoogleCloud Date: Sun, 2 Sep 2018 11:57:27 -0700 Subject: [PATCH 11/17] Added entry to install the Hyper-V tools if present. This is required for Hyper-V to correctly detect the IP address of the guest for the remaining packer provisioning --- packer/answer_files/2008_r2/Autounattend.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packer/answer_files/2008_r2/Autounattend.xml b/packer/answer_files/2008_r2/Autounattend.xml index f9e19786..40e9668e 100644 --- a/packer/answer_files/2008_r2/Autounattend.xml +++ b/packer/answer_files/2008_r2/Autounattend.xml @@ -279,6 +279,12 @@ 99 true + + cmd.exe /c "set PACKER_BUILDER_TYPE=hyperv-first-boot&&a:\vm-guest-tools.bat + Install VM tools for Hyper-V (currently the only provisioner which will add this script) + 100 + true + From 4329f912bb84ca4d87ef4530fe3d13c12e5e034c Mon Sep 17 00:00:00 2001 From: BoogleCloud Date: Sun, 2 Sep 2018 12:03:00 -0700 Subject: [PATCH 12/17] Added linux-cloud-tools packages so that Hyper-V will know the ubuntu system IP address for packer provisioning --- packer/http/preseed.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packer/http/preseed.cfg b/packer/http/preseed.cfg index 40a40815..12981aff 100644 --- a/packer/http/preseed.cfg +++ b/packer/http/preseed.cfg @@ -16,7 +16,7 @@ d-i partman/choose_partition select finish d-i partman/confirm boolean true d-i partman/confirm_nooverwrite boolean true d-i partman/confirm_write_new_label boolean true -d-i pkgsel/include string openssh-server cryptsetup build-essential libssl-dev libreadline-dev zlib1g-dev linux-source dkms nfs-common curl wget ca-certificates libwww-perl python open-vm-tools-lts-trusty +d-i pkgsel/include string openssh-server cryptsetup build-essential libssl-dev libreadline-dev zlib1g-dev linux-source dkms nfs-common curl wget ca-certificates libwww-perl python open-vm-tools-lts-trusty linux-tools-$(uname -r) linux-cloud-tools-$(uname -r) linux-cloud-tools-common d-i pkgsel/install-language-support boolean false d-i pkgsel/update-policy select unattended-upgrades d-i pkgsel/upgrade select full-upgrade From 55eacacc6dc124b6ed3c8e4ccc0bb0e36bf13209 Mon Sep 17 00:00:00 2001 From: BoogleCloud Date: Sun, 2 Sep 2018 12:04:47 -0700 Subject: [PATCH 13/17] Added hyper-v builder section for packer --- packer/templates/ubuntu_1404.json | 32 +++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/packer/templates/ubuntu_1404.json b/packer/templates/ubuntu_1404.json index d8cfeb12..ef082353 100644 --- a/packer/templates/ubuntu_1404.json +++ b/packer/templates/ubuntu_1404.json @@ -1,5 +1,37 @@ { "builders": [ + { + "type": "hyperv-iso", + "iso_url": "{{user `iso_url`}}", + "iso_checksum_type": "{{user `iso_checksum_type`}}", + "iso_checksum": "{{user `iso_checksum`}}", + "http_directory" : "{{template_dir}}/../http", + "http_port_min" : 9001, + "http_port_max" : 9001, + "boot_command": [ + "", + "", + "", + "/install/vmlinuz", + " auto=true", + " priority=critical", + " initrd=/install/initrd.gz", + " preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed.cfg", + " -- ", + "" + ], + "boot_wait": "20s", + "communicator": "ssh", + "ssh_username": "vagrant", + "ssh_password": "vagrant", + "ssh_timeout": "2h", + "shutdown_command": "echo 'packer' | sudo -S shutdown -P now", + "disk_size": 40000, + "vm_name": "metasploitable3-ub1404", + "cpu": "2", + "ram_size": "4096", + "enable_dynamic_memory": "false" + }, { "type": "vmware-iso", "iso_url": "{{user `iso_url`}}", From e557691036fff202351b519c9d3693052a811ed2 Mon Sep 17 00:00:00 2001 From: BoogleCloud Date: Sun, 2 Sep 2018 12:05:05 -0700 Subject: [PATCH 14/17] Added hyper-v builder section for packer --- packer/templates/windows_2008_r2.json | 44 +++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/packer/templates/windows_2008_r2.json b/packer/templates/windows_2008_r2.json index 0ccf2360..9c78a2ad 100644 --- a/packer/templates/windows_2008_r2.json +++ b/packer/templates/windows_2008_r2.json @@ -1,5 +1,43 @@ { "builders": [ + { + "type": "hyperv-iso", + "iso_url": "{{user `iso_url`}}", + "iso_checksum_type": "{{user `iso_checksum_type`}}", + "iso_checksum": "{{user `iso_checksum`}}", + "communicator": "ssh", + "ssh_username": "vagrant", + "ssh_password": "vagrant", + "ssh_timeout":"2h", + "shutdown_command": "shutdown /s /t 10 /f /d p:4:1 /c \"Packer Shutdown\"", + "boot_wait": "10m", + "floppy_files": [ + "{{user `autounattend`}}", + "{{user `scripts_dir`}}/configs/microsoft-updates.bat", + "{{user `scripts_dir`}}/configs/win-updates.ps1", + "{{user `scripts_dir`}}/installs/openssh.ps1", + "{{user `scripts_dir`}}/installs/install_dotnet45.ps1", + "{{user `scripts_dir`}}/installs/install_wmf.ps1", + "{{user `scripts_dir`}}/installs/vm-guest-tools.bat", + "{{user `resources_dir`}}/certs/oracle-cert.cer", + "{{user `resources_dir`}}/certs/gdig2.crt", + "{{user `resources_dir`}}/certs/comodorsadomainvalidationsecureserverca.crt", + "{{user `resources_dir`}}/certs/comodorsacertificationauthority.crt", + "{{user `resources_dir`}}/certs/addtrust_external_ca.cer", + "{{user `resources_dir`}}/certs/baltimore_ca.cer", + "{{user `resources_dir`}}/certs/digicert.cer", + "{{user `resources_dir`}}/certs/equifax.cer", + "{{user `resources_dir`}}/certs/globalsign.cer", + "{{user `resources_dir`}}/certs/gte_cybertrust.cer", + "{{user `resources_dir`}}/certs/microsoft_root_2011.cer", + "{{user `resources_dir`}}/certs/thawte_primary_root.cer", + "{{user `resources_dir`}}/certs/utn-userfirst.cer" + ], + "vm_name": "metasploitable3-win2k8", + "cpu": "2", + "ram_size": "4096", + "enable_dynamic_memory": "false" + }, { "type": "vmware-iso", "iso_url": "{{user `iso_url`}}", @@ -141,6 +179,12 @@ } ], "provisioners": [ + { + "type": "file", + "source": "{{user `scripts_dir`}}", + "destination": "C:/vagrant", + "pause_before": "2m" + }, { "type": "file", "source": "{{user `scripts_dir`}}", From d4388a9585417903393a945c4cbe139f9b2d826a Mon Sep 17 00:00:00 2001 From: BoogleCloud Date: Sun, 2 Sep 2018 12:05:38 -0700 Subject: [PATCH 15/17] Added section to install hyper-v tools on first boot. It needs to be done then so that the remaining packer provisioning can occur --- scripts/installs/vm-guest-tools.bat | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/scripts/installs/vm-guest-tools.bat b/scripts/installs/vm-guest-tools.bat index 5639cd35..a347e6c6 100644 --- a/scripts/installs/vm-guest-tools.bat +++ b/scripts/installs/vm-guest-tools.bat @@ -6,6 +6,7 @@ msiexec /qb /i C:\Windows\Temp\7zInstaller-x64.msi if "%PACKER_BUILDER_TYPE%" equ "vmware-iso" goto :vmware if "%PACKER_BUILDER_TYPE%" equ "virtualbox-iso" goto :virtualbox if "%PACKER_BUILDER_TYPE%" equ "parallels-iso" goto :parallels +if "%PACKER_BUILDER_TYPE%" equ "hyperv-first-boot" goto :hyperv goto :done :vmware @@ -46,5 +47,15 @@ if exist "C:\Users\vagrant\prl-tools-win.iso" ( rd /S /Q "c:\Windows\Temp\parallels" ) +:hyperv +if not exist "C:\Windows\Temp\vmguest.iso" ( + echo "Downloading and installing Hyper-V tools" + powershell -Command "(New-Object System.Net.WebClient).DownloadFile('https://content.deltik.org/mirror/os/windows/vmguest.iso', 'C:\Windows\Temp\vmguest.iso')" Date: Sat, 15 Sep 2018 18:57:17 -0400 Subject: [PATCH 16/17] Added execute_command option to correctly handle inline powershell over GNU SSH --- packer/templates/windows_2008_r2.json | 1 + 1 file changed, 1 insertion(+) diff --git a/packer/templates/windows_2008_r2.json b/packer/templates/windows_2008_r2.json index 9c78a2ad..63b9b4b7 100644 --- a/packer/templates/windows_2008_r2.json +++ b/packer/templates/windows_2008_r2.json @@ -290,6 +290,7 @@ }, { "type":"powershell", + "execute_command": "powershell -executionpolicy bypass \"& { if (Test-Path variable:global:ProgressPreference){\\$ProgressPreference='SilentlyContinue'};. {{.Vars}}; &'{{.Path}}'; exit \\$LastExitCode }\"", "inline": [ "mkdir -p C:/startup" ] From d4373d7be003f105763e9957f2b67eeb32e62960 Mon Sep 17 00:00:00 2001 From: BoogleCloud Date: Sun, 16 Sep 2018 08:40:56 -0400 Subject: [PATCH 17/17] Updated Packer minimum version to 1.3.1 for SCP bug --- build.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.ps1 b/build.ps1 index 5636a2f3..003936eb 100755 --- a/build.ps1 +++ b/build.ps1 @@ -1,7 +1,7 @@ $ErrorActionPreference = "Stop" $virtualBoxMinVersion = "5.1.10" -$packerMinVersion = "0.10.0" +$packerMinVersion = "1.3.1" $vagrantMinVersion = "1.9.0" $vagrantreloadMinVersion = "0.0.1" $packer = "packer"