Skip to content
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

when I run build.ps1 file I face some errors, so if found solution tha… #623

Open
wants to merge 2 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
54 changes: 54 additions & 0 deletions ForVMware.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# -- mode: ruby --
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
config.vm.synced_folder '.', '/vagrant', disabled: true

# Define Ubuntu 14.04 VM
config.vm.define "ub1404" do |ub1404|
ub1404.vm.box = "rapid7/metasploitable3-ub1404"
ub1404.vm.hostname = "metasploitable3-ub1404"
config.ssh.username = 'vagrant'
config.ssh.password = 'vagrant'

ub1404.vm.network "private_network", ip: '192.168.50.102'

ub1404.vm.provider "vmware_desktop" do |v|
v.vmx["ethernet0.pcislotnumber"] = "33"
v.memory = 2048
end
end

# Define Windows Server 2008 VM
config.vm.define "win2k8" do |win2k8|
# Base configuration for the VM and provisioner
win2k8.vm.box = "rapid7/metasploitable3-win2k8"
win2k8.vm.hostname = "metasploitable3-win2k8"
win2k8.vm.communicator = "winrm"
win2k8.winrm.retry_limit = 60
win2k8.winrm.retry_delay = 10

win2k8.vm.network "private_network", ip: '192.168.50.103'

config.vm.provider "vmware_desktop" do |v|
v.vmx["ethernet0.pcislotnumber"] = "34"
v.memory = 4096
v.cpus = 2
v.gui= true
end

# Configure Firewall to open up vulnerable services
case ENV['MS3_DIFFICULTY']
when 'easy'
win2k8.vm.provision :shell, inline: "C:\\startup\\disable_firewall.bat"
else
win2k8.vm.provision :shell, inline: "C:\\startup\\enable_firewall.bat"
win2k8.vm.provision :shell, inline: "C:\\startup\\configure_firewall.bat"
end

# Insecure share from the Linux machine
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
60 changes: 60 additions & 0 deletions ForVirtualbox.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
config.vm.synced_folder '.', '/vagrant', disabled: true
config.vm.define "ub1404" do |ub1404|
ub1404.vm.box = "rapid7/metasploitable3-ub1404"
ub1404.vm.hostname = "metasploitable3-ub1404"
config.ssh.username = 'vagrant'
config.ssh.password = 'vagrant'

ub1404.vm.network "private_network", ip: '172.28.128.3'

ub1404.vm.provider "virtualbox" do |v|
v.name = "Metasploitable3-ub1404"
v.memory = 2048
end
end

config.vm.define "win2k8" do |win2k8|
# Base configuration for the VM and provisioner
win2k8.vm.box = "rapid7/metasploitable3-win2k8"
win2k8.vm.hostname = "metasploitable3-win2k8"
win2k8.vm.communicator = "winrm"
win2k8.winrm.retry_limit = 60
win2k8.winrm.retry_delay = 10

win2k8.vm.network "private_network", type: "dhcp"

win2k8.vm.provider "libvirt" do |v|
v.memory = 4096
v.cpus = 2
v.video_type = 'qxl'
v.input :type => "tablet", :bus => "usb"
v.channel :type => 'unix', :target_name => 'org.qemu.guest_agent.0', :target_type => 'virtio'
v.channel :type => 'spicevmc', :target_name => 'com.redhat.spice.0', :target_type => 'virtio'
v.graphics_type = "spice"

# Enable Hyper-V enlightenments: https://blog.wikichoon.com/2014/07/enabling-hyper-v-enlightenments-with-kvm.html
v.hyperv_feature :name => 'stimer', :state => 'on'
v.hyperv_feature :name => 'relaxed', :state => 'on'
v.hyperv_feature :name => 'vapic', :state => 'on'
v.hyperv_feature :name => 'synic', :state => 'on'
end

# Configure Firewall to open up vulnerable services
case ENV['MS3_DIFFICULTY']
when 'easy'
win2k8.vm.provision :shell, inline: "C:\\startup\\disable_firewall.bat"
else
win2k8.vm.provision :shell, inline: "C:\\startup\\enable_firewall.bat"
win2k8.vm.provision :shell, inline: "C:\\startup\\configure_firewall.bat"
end

# Insecure share from the Linux machine
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ recipes, so that you can always return to an initial state (`vagrant restore fre
If you want a _totally_ fresh snapshot, you can do the initialization with
`vagrant up --no-provision`, then take a snapshot, followed by `vagrant provision`.

## Error Solutions
> If you are facing problem when you run build.ps1 file you can use updatedBuild.ps1 file and make sure packer.pkr.hcl is configure correctly.

## Vulnerabilities
* [See the wiki page](https://github.com/rapid7/metasploitable3/wiki/Vulnerabilities)
Expand Down
8 changes: 8 additions & 0 deletions packer.pkr.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
packer {
required_plugins {
vagrant = {
version = ">= 1.0.0"
source = "github.com/hashicorp/vagrant"
}
}
}
193 changes: 193 additions & 0 deletions updatedBuild.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
$ErrorActionPreference = "Stop"

$virtualBoxMinVersion = "6.1.0"
$packerMinVersion = "1.6.0"
$vagrantMinVersion = "1.9.0"
$vagrantreloadMinVersion = "0.0.1"
$packer = "packer.exe"
$expectedVBoxLocation = "C:\Program Files\Oracle\VirtualBox"
$expectedVagrantLocation = "C:\Program Files\Vagrant\bin"

function CompareVersions ($actualVersion, $expectedVersion, $exactMatch = $False) {
If ($exactMatch) {
If ($actualVersion -eq $expectedVersion) {
return $True
} else {
return $False
}
}

$actualVersion = $actualVersion.split(".")
$expectedVersion = $expectedVersion.split(".")

for($i=0; $i -lt $expectedVersion.length; $i++) {
If([INT]$actualVersion[$i] -gt [INT]$expectedVersion[$i]) {
return $True
}

If([INT]$actualVersion[$i] -lt [INT]$expectedVersion[$i]) {
return $False
}
}
return $True
}

Write-Host ""

If (Test-Path "$expectedVBoxLocation\VBoxManage.exe") {

$vboxVersion = cmd.exe /c "$expectedVBoxLocation\VBoxManage.exe" -v
$vboxVersion = $vboxVersion.split("r")[0].Trim()

} 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

}

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
$packerVersion = $packerVersion -replace '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 "$expectedVagrantLocation\vagrant.exe") {

$vagrantVersion = cmd.exe /c "vagrant" -v
$vagrantVersion = $vagrantVersion.split(" ")[1].Trim()

} else {

Write-Host "Vagrant is not installed (or not in the expected location of $expectedVagrantLocation\)"
Write-Host "Please download and install it from https://www.vagrantup.com/downloads.html/"
exit

}

If (CompareVersions -actualVersion $vagrantVersion -expectedVersion $vagrantMinVersion) {

Write-Host "Compatible version of Vagrant found."

} else {

Write-Host "Could not find a compatible version of Vagrant at C:\HashiCorp\Vagrant\bin\. Please download and install it from https://www.vagrantup.com/downloads.html."
exit

}

$vagrantPlugins = cmd.exe /c "vagrant plugin list" | select-string -pattern "vagrant-reload"

If (![string]::IsNullOrEmpty($vagrantPlugins)) {

$vagrantPlugins = $vagrantPlugins.ToString().Trim()
$vagrantreloadVersion = $vagrantPlugins.Replace("(", "")
$vagrantreloadVersion = $vagrantreloadVersion.Replace(")", "")
$vagrantreloadVersion = $vagrantreloadVersion.split(" ")[1]

If (CompareVersions -actualVersion $vagrantreloadVersion -expectedVersion $vagrantreloadMinVersion) {

Write-Host "Compatible version of vagrant-reload plugin found."

}

} else {

Write-Host "Could not find a compatible version of vagrant-reload plugin. Attempting to install..."
cmd.exe /c "vagrant plugin install vagrant-reload"

# Hacky version of Try-Catch for non-terminating errors.
# See http://stackoverflow.com/questions/1142211/try-catch-does-not-seem-to-have-an-effect

if($?) {
Write-Host "The vagrant-reload plugin was successfully installed."
} else {
throw "Error installing vagrant-reload plugin. Please check the output above for any error messages."
}

}

function InstallBox($os_full, $os_short)
{
$boxversion = Get-Content .\packer\templates\$os_full.json | Select-String -Pattern "box_version" | Select-String -Pattern "[0-9]\.[0-9]\.[0-9]+"
$boxversion = $boxversion.toString().trim().split('"')[3]

Write-Host "Building metasploitable3-$os_short Vagrant box..."

If (Test-Path "packer\builds\$($os_full)_virtualbox_$boxversion.box") {

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

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."
}
}

Write-Host "Attempting to add metasploitable3-$os_short box to Vagrant..."
$vagrant_box_list = cmd.exe /c "vagrant box list"

If ($vagrant_box_list -match "rapid7/metasploitable3-$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

if($?) {
Write-Host "rapid7/metasploitable3-$os_short box successfully added to Vagrant."
} else {
throw "Error adding metasploitable3-$os_short box to Vagrant. See the above output for any error messages."
}
}
}

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

if ($args.Length -eq 0) {
$option = Read-Host -Prompt 'No box name passed as input. Build both the boxes ? (y/n)';
if ($option -eq 'y') {
InstallBox -os_full "windows_2008_r2" -os_short "win2k8"
InstallBox -os_full "ubuntu_1404" -os_short "ub1404"
} else {
Write-Host "To build metasploitable boxes separately, use the following commands:"
Write-Host "- .\build.ps1 windows2008"
Write-Host "- .\build.ps1 ubuntu1404"
}
} ElseIf ($args.Length -eq 1) {
if ($args -eq "windows2008") {
InstallBox -os_full "windows_2008_r2" -os_short "win2k8"
} ElseIf ($args -eq "ubuntu1404") {
InstallBox -os_full "ubuntu_1404" -os_short "ub1404"
} else {
Write-Host "Invalid OS. Valid options are 'ubuntu1404' and 'windows2008'"
}
}

Write-Host ""