Use prebuilt box from vagrant cloud

Update build scripts to remove checks for packer since it is no longer
a requirement.
This commit is contained in:
James Barnett 2017-08-07 10:17:36 -05:00
parent 1810872c47
commit 572588beac
No known key found for this signature in database
GPG Key ID: 647983861A4EC5EA
4 changed files with 18 additions and 67 deletions

9
Vagrantfile vendored
View File

@ -3,14 +3,19 @@
Vagrant.configure("2") do |config| Vagrant.configure("2") do |config|
# Base configuration for the VM and provisioner # Base configuration for the VM and provisioner
config.vm.box = "metasploitable3" config.vm.box = "jbarnett-r7/metasploitable3-win2k8"
config.vm.hostname = "metasploitable3" config.vm.hostname = "metasploitable3-win2k8"
config.vm.communicator = "winrm" config.vm.communicator = "winrm"
config.winrm.retry_limit = 60 config.winrm.retry_limit = 60
config.winrm.retry_delay = 10 config.winrm.retry_delay = 10
config.vm.network "private_network", type: "dhcp" config.vm.network "private_network", type: "dhcp"
config.vm.provider "virtualbox" do |v|
v.name = "metasploitable3-win2k8"
v.memory = 2048
end
# Configure Firewall to open up vulnerable services # Configure Firewall to open up vulnerable services
case ENV['MS3_DIFFICULTY'] case ENV['MS3_DIFFICULTY']
when 'easy' when 'easy'

View File

@ -1,7 +1,6 @@
$ErrorActionPreference = "Stop" $ErrorActionPreference = "Stop"
$virtualBoxMinVersion = "5.1.10" $virtualBoxMinVersion = "5.1.10"
$packerMinVersion = "0.10.0"
$vagrantMinVersion = "1.9.0" $vagrantMinVersion = "1.9.0"
$vagrantreloadMinVersion = "0.0.1" $vagrantreloadMinVersion = "0.0.1"
@ -48,15 +47,6 @@ If (CompareVersions -actualVersion $vboxVersion -expectedVersion $virtualBoxMinV
exit exit
} }
$packerVersion = cmd.exe /c "packer" -v
If (CompareVersions -actualVersion $packerVersion -expectedVersion $packerMinVersion) {
Write-Host "Compatible version of packer found."
} else {
Write-Host "Could not find a compatible version of packer. Please download it from https://www.packer.io/downloads.html and add it to your PATH."
exit
}
If ($(Test-Path "C:\HashiCorp\Vagrant\bin\vagrant.exe") -eq $True) { If ($(Test-Path "C:\HashiCorp\Vagrant\bin\vagrant.exe") -eq $True) {
$vagrantVersion = cmd.exe /c "vagrant" -v $vagrantVersion = cmd.exe /c "vagrant" -v
$vagrantVersion = $vagrantVersion.split(" ")[1] $vagrantVersion = $vagrantVersion.split(" ")[1]
@ -95,30 +85,15 @@ If (![string]::IsNullOrEmpty($vagrantPlugins)) {
Write-Host "All requirements found. Proceeding..." Write-Host "All requirements found. Proceeding..."
If ($(Test-Path "windows_2008_r2_virtualbox.box") -eq $True) { $vagrant_box_list = cmd.exe /c "vagrant box list" | select-string -pattern "jbarnett-r7/metasploitable3-win2k8"
Write-Host "It looks like the Vagrant box already exists. Skipping the Packer build."
} else {
Write-Host "Building the Vagrant box..."
cmd.exe /c packer build --only=virtualbox-iso windows_2008_r2.json
if($?) {
Write-Host "Box successfully built by Packer."
} else {
throw "Error building the Vagrant box using Packer. Please check the output above for any error messages."
}
}
echo "Attempting to add the box to Vagrant..."
$vagrant_box_list = cmd.exe /c "vagrant box list" | select-string -pattern "metasploitable3"
If ($vagrant_box_list) { $vagrant_box_list = $vagrant_box_list.ToString().Trim() } If ($vagrant_box_list) { $vagrant_box_list = $vagrant_box_list.ToString().Trim() }
If ($vagrant_box_list -eq "metasploitable3") { If ($vagrant_box_list -eq "jbarnett-r7/metasploitable3-win2k8") {
Write-Host "metasploitable3 already found in Vagrant box repository. Skipping the addition to Vagrant." Write-Host "jbarnett-r7/metasploitable3-win2k8 already found in Vagrant box repository. Skipping the addition to Vagrant."
} else { } else {
Write-Host "Attempting to add the box to Vagrant. This may take a while..."
cmd.exe /c vagrant box add metasploitable3 windows_2008_r2_virtualbox.box cmd.exe /c vagrant box add jbarnett-r7/metasploitable3-win2k8
if($?) { if($?) {
Write-Host "Box successfully added to Vagrant." Write-Host "Box successfully added to Vagrant."

View File

@ -4,7 +4,6 @@ min_vbox_ver="5.1.10"
min_vagrant_ver="1.9.0" min_vagrant_ver="1.9.0"
min_packer_ver="0.10.0" min_packer_ver="0.10.0"
min_vagrantreload_ver="0.0.1" min_vagrantreload_ver="0.0.1"
packer_bin="packer"
function compare_versions { function compare_versions {
actual_version=$1 actual_version=$1
@ -42,9 +41,6 @@ if [ $(uname) = "Darwin" ]; then
vagrant_exact_match=false vagrant_exact_match=false
elif [ $(uname) = "Linux" ]; then elif [ $(uname) = "Linux" ]; then
vagrant_exact_match=false vagrant_exact_match=false
if (cat /etc/*-release | grep -q 'DISTRIB_ID=Arch')|(cat /etc/os-release | grep -q 'ID=arch'); then
packer_bin="packer-io"
fi
fi fi
if [ -x "$(which VBoxManage)" ] ; then if [ -x "$(which VBoxManage)" ] ; then
@ -63,18 +59,6 @@ else
exit 1 exit 1
fi fi
if compare_versions $($packer_bin -v) $min_packer_ver false; then
echo "Compatible version of $packer_bin was found."
else
packer_bin=packer
if compare_versions $($packer_bin -v) $min_packer_ver false; then
echo "Compatible version of $packer_bin was found."
else
echo "A compatible version of packer was not found. Please install from here: https://www.packer.io/downloads.html"
exit 1
fi
fi
if compare_versions $(vagrant -v | cut -d' ' -f2) $min_vagrant_ver $vagrant_exact_match; then if compare_versions $(vagrant -v | cut -d' ' -f2) $min_vagrant_ver $vagrant_exact_match; then
echo 'Correct version of vagrant was found.' echo 'Correct version of vagrant was found.'
else else
@ -97,25 +81,12 @@ fi
echo "All requirements found. Proceeding..." echo "All requirements found. Proceeding..."
if ls | grep -q 'windows_2008_r2_virtualbox.box'; then if vagrant box list | grep -q 'jbarnett-r7/metasploitable3-win2k8'; then
echo "It looks like the vagrant box already exists. Skipping the Packer build." echo 'jbarnett-r7/metasploitable3-win2k8 already found in Vagrant box repository. Skipping the addition to Vagrant.'
else
echo "Building the Vagrant box..."
if $packer_bin build --only=virtualbox-iso windows_2008_r2.json; then
echo "Box successfully built by Packer."
else
echo "Error building the Vagrant box using Packer. Please check the output above for any error messages."
exit 1
fi
fi
echo "Attempting to add the box to Vagrant..."
if vagrant box list | grep -q 'metasploitable3'; then
echo 'metasploitable3 already found in Vagrant box repository. Skipping the addition to Vagrant.'
echo "NOTE: If you are having issues, try starting over by doing 'vagrant destroy' and then 'vagrant up'." echo "NOTE: If you are having issues, try starting over by doing 'vagrant destroy' and then 'vagrant up'."
else else
if vagrant box add windows_2008_r2_virtualbox.box --name metasploitable3; then echo 'Attempting to add the box to Vagrant. This may take a while...'
if vagrant box add jbarnett-r7/metasploitable3-win2k8; then
echo "Box successfully added to Vagrant." echo "Box successfully added to Vagrant."
else else
echo "Error adding box to Vagrant. See the above output for any error messages." echo "Error adding box to Vagrant. See the above output for any error messages."

View File

@ -14,7 +14,7 @@
"shutdown_command": "shutdown /s /t 10 /f /d p:4:1 /c \"Packer Shutdown\"", "shutdown_command": "shutdown /s /t 10 /f /d p:4:1 /c \"Packer Shutdown\"",
"guest_os_type": "winServer2008Standard-64", "guest_os_type": "winServer2008Standard-64",
"tools_upload_flavor": "windows", "tools_upload_flavor": "windows",
"disk_size": 61440, "disk_size": 30000,
"floppy_files": [ "floppy_files": [
"{{user `autounattend`}}", "{{user `autounattend`}}",
"./scripts/configs/microsoft-updates.bat", "./scripts/configs/microsoft-updates.bat",
@ -57,7 +57,7 @@
"ssh_wait_timeout": "2h", "ssh_wait_timeout": "2h",
"shutdown_command": "shutdown /s /t 10 /f /d p:4:1 /c \"Packer Shutdown\"", "shutdown_command": "shutdown /s /t 10 /f /d p:4:1 /c \"Packer Shutdown\"",
"guest_os_type": "Windows2008_64", "guest_os_type": "Windows2008_64",
"disk_size": 61440, "disk_size": 30000,
"vm_name": "metasploitable3-win2k8", "vm_name": "metasploitable3-win2k8",
"floppy_files": [ "floppy_files": [
"{{user `autounattend`}}", "{{user `autounattend`}}",