Vagrantfile 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # -*- mode: ruby -*-
  2. # vi: set ft=ruby :
  3. display_name = "metasploit-framework"
  4. Vagrant.configure(2) do |config|
  5. config.ssh.forward_x11 = true
  6. config.vm.box = "hashicorp/bionic64" # https://app.vagrantup.com/hashicorp/boxes/bionic64
  7. config.vm.network :forwarded_port, guest: 4444, host: 4444
  8. config.vm.provider "vmware_desktop" do |v|
  9. v.memory = 2048
  10. v.cpus = 2
  11. v.vmx['displayname'] = display_name
  12. #v.gui = true # uncomment to show VM in your hypervisor's GUI
  13. end
  14. config.vm.provider "virtualbox" do |v|
  15. v.name = display_name
  16. v.memory = 2048
  17. v.cpus = 2
  18. #v.gui = true # uncomment to show VM in your hypervisor's GUI
  19. end
  20. %w(.vimrc .gitconfig).each do |f|
  21. local = File.expand_path "~/#{f}"
  22. if File.exist? local
  23. config.vm.provision "file", source: local, destination: f
  24. end
  25. end
  26. [ #"echo 127.0.1.1 `cat /etc/hostname` >> /etc/hosts", work around a bug in official Ubuntu Xenial cloud images
  27. "apt-get update",
  28. "apt-get dist-upgrade -y",
  29. "apt-get -y install curl build-essential git tig vim john nmap libpq-dev libpcap-dev gnupg2 fortune postgresql postgresql-contrib",
  30. ].each do |step|
  31. config.vm.provision "shell", inline: step
  32. end
  33. [ # use the rvm install method used in omnibus install
  34. # only show stderr when gpg really fails. avoids superfluous stderr from gpg
  35. 'out=`curl -sSL https://rvm.io/mpapis.asc | gpg --import - 2>&1` && echo "imported mpapis.asc" || echo $out 1>&2',
  36. 'out=`curl -sSL https://rvm.io/pkuczynski.asc | gpg --import - 2>&1` && echo "imported pkuczynski.asc" || echo $out 1>&2',
  37. 'out=`curl -L -sSL https://get.rvm.io | bash -s stable 2>&1` && echo "rvm installed" || echo $out 1>&2',
  38. # only install Ruby if the right version isn't already present
  39. "echo 'Installing Ruby if necessary'",
  40. 'cd /vagrant && rv=`cat .ruby-version` && source ~/.rvm/scripts/rvm && rvm list strings | grep -q $rv || rvm install $rv',
  41. 'source ~/.rvm/scripts/rvm && cd /vagrant && gem install --quiet bundler && bundle',
  42. 'mkdir -p ~/.msf4',
  43. ].each do |step|
  44. config.vm.provision "shell", privileged: false, inline: step
  45. end
  46. config.vm.provision "file", source: "config/database.yml.vagrant", destination: "~/.msf4/database.yml"
  47. config.vm.provision "shell", inline: "sudo -u postgres psql postgres -tAc \"SELECT 1 FROM pg_roles WHERE rolname='vagrant'\" | grep -q 1 || sudo -u postgres createuser -s -e -w vagrant && sudo -u postgres psql -c \"ALTER USER vagrant with ENCRYPTED PASSWORD 'vagrant';\""
  48. ["msf_dev_db", "msf_test_db"].each do |database|
  49. config.vm.provision "shell", inline: "sudo -u postgres psql -lqt | awk '{ print $1 }' | grep -w #{database} | wc -l | grep -q 1 || sudo -u postgres createdb --owner vagrant #{database}"
  50. end
  51. end