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 = <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 + 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 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`}}", diff --git a/packer/templates/windows_2008_r2.json b/packer/templates/windows_2008_r2.json index 0ccf2360..63b9b4b7 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`}}", @@ -246,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" ] 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')"