Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
918b3c5
Added hyper-v specific options and message regarding the share mount
OptmizerLLC Sep 2, 2018
dd8b465
Updated logic to check for hyper-v and updated variables for packer a…
OptmizerLLC Sep 2, 2018
1152dfc
Added entry to install the Hyper-V tools if present. This is required…
OptmizerLLC Sep 2, 2018
34134ea
Added linux-cloud-tools packages so that Hyper-V will know the ubuntu…
OptmizerLLC Sep 2, 2018
c48ce3a
Added hyper-v builder section for packer
OptmizerLLC Sep 2, 2018
0ef3837
Added hyper-v builder section for packer
OptmizerLLC Sep 2, 2018
4dbe828
Added section to install hyper-v tools on first boot. It needs to be …
OptmizerLLC Sep 2, 2018
487bc2d
Added execute_command option to correctly handle inline powershell ov…
OptmizerLLC Sep 15, 2018
e905d0a
Added hyper-v specific options and message regarding the share mount
OptmizerLLC Sep 2, 2018
9ff6c5d
Updated logic to check for hyper-v and updated variables for packer a…
OptmizerLLC Sep 2, 2018
51675f1
Added entry to install the Hyper-V tools if present. This is required…
OptmizerLLC Sep 2, 2018
4329f91
Added linux-cloud-tools packages so that Hyper-V will know the ubuntu…
OptmizerLLC Sep 2, 2018
55eacac
Added hyper-v builder section for packer
OptmizerLLC Sep 2, 2018
e557691
Added hyper-v builder section for packer
OptmizerLLC Sep 2, 2018
d4388a9
Added section to install hyper-v tools on first boot. It needs to be …
OptmizerLLC Sep 2, 2018
6820449
Added execute_command option to correctly handle inline powershell ov…
OptmizerLLC Sep 15, 2018
496188c
Merge branch 'hyperv-1803' of https://github.com/BoogleCloud/metasplo…
OptmizerLLC Sep 15, 2018
d4373d7
Updated Packer minimum version to 1.3.1 for SCP bug
OptmizerLLC Sep 16, 2018
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
31 changes: 31 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand All @@ -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 = <<MSG
------------------------------------------------------
Thanks to Vagrant/Hyper-V limitations we can't automatically set
the VM IP addresses.
(https://www.vagrantup.com/docs/hyperv/limitations.html)

Look above for a line like: "ub1404: IP: X.X.X.X"
and change the ip address listed in
scripts/installs/setup_linux_share.bat
to match this value.

Then run:
'vagrant provision win2k8'
for it to take effect
------------------------------------------------------
MSG
end


# Configure Firewall to open up vulnerable services
case ENV['MS3_DIFFICULTY']
Expand All @@ -40,5 +70,6 @@ Vagrant.configure("2") do |config|
win2k8.vm.provision :shell, inline: "C:\\startup\\install_share_autorun.bat"
win2k8.vm.provision :shell, inline: "C:\\startup\\setup_linux_share.bat"
win2k8.vm.provision :shell, inline: "rm C:\\startup\\*" # Cleanup startup scripts

end
end
67 changes: 37 additions & 30 deletions build.ps1
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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."
Expand All @@ -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."
Expand All @@ -169,7 +177,6 @@ function InstallBox($os_full, $os_short)
}



Write-Host "All requirements found. Proceeding..."

if($args.Length -eq 0)
Expand Down
6 changes: 6 additions & 0 deletions packer/answer_files/2008_r2/Autounattend.xml
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,12 @@
<Order>99</Order>
<RequiresUserInput>true</RequiresUserInput>
</SynchronousCommand>
<SynchronousCommand wcm:action="add">
<CommandLine>cmd.exe /c "set PACKER_BUILDER_TYPE=hyperv-first-boot&amp;&amp;a:\vm-guest-tools.bat</CommandLine>
<Description>Install VM tools for Hyper-V (currently the only provisioner which will add this script)</Description>
<Order>100</Order>
<RequiresUserInput>true</RequiresUserInput>
</SynchronousCommand>
<!-- END WITHOUT WINDOWS UPDATES -->
<!-- WITH WINDOWS UPDATES -->
<!--<SynchronousCommand wcm:action="add">-->
Expand Down
2 changes: 1 addition & 1 deletion packer/http/preseed.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 32 additions & 0 deletions packer/templates/ubuntu_1404.json
Original file line number Diff line number Diff line change
@@ -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": [
"<esc><wait>",
"<esc><wait>",
"<enter><wait>",
"/install/vmlinuz",
" auto=true",
" priority=critical",
" initrd=/install/initrd.gz",
" preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed.cfg",
" -- ",
"<enter>"
],
"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`}}",
Expand Down
45 changes: 45 additions & 0 deletions packer/templates/windows_2008_r2.json
Original file line number Diff line number Diff line change
@@ -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`}}",
Expand Down Expand Up @@ -141,6 +179,12 @@
}
],
"provisioners": [
{
"type": "file",
"source": "{{user `scripts_dir`}}",
"destination": "C:/vagrant",
"pause_before": "2m"
},
{
"type": "file",
"source": "{{user `scripts_dir`}}",
Expand Down Expand Up @@ -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"
]
Expand Down
11 changes: 11 additions & 0 deletions scripts/installs/vm-guest-tools.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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')" <NUL
cmd /C "C:\Program Files\7-Zip\7z.exe" x C:\Windows\Temp\vmguest.iso -oC:\Windows\Temp\hyperv
cmd /c C:\Windows\Temp\hyperv\support\x86\setup.exe /quiet
rd /S /Q "c:\Windows\Temp\hyperv"
)
goto :done

:done
msiexec /qb /x C:\Windows\Temp\7zInstaller-x64.msi