首页 > 系统相关 > KAL1 LINUX 官方文档之虚拟机版本 --- Kali inside Vagrant (Guest VM)(更新于2022)

KAL1 LINUX 官方文档之虚拟机版本 --- Kali inside Vagrant (Guest VM)(更新于2022)

时间:2022-10-07 11:00:20浏览次数:95  
标签:Guest default Kali 虚拟机 vagrant dev Vagrant kali rolling

Kali inside Vagrant (Guest VM)

根据他们的网站,Vagrant 是“在单一工作流程中构建和管理虚拟机环境的工具”。这一切都通过单个配置文件进行控制,该文件具有大量配置,可根据您的需要调整虚拟机 (VM)。我们将看看默认配置文件在做什么,但更多内容超出了本页的范围。

系统设置

为了正确使用 Vagrant,我们需要两件事。Vagrant 本身,以及受支持的管理程序。Kali Vagrant 文件支持两种,VirtualBox 和 VMware。

我们首先将下载Vagrant

如果我们在 Windows 上,我们需要按照上一个链接下载正确的版本(打开设置然后转到关于,如果 64 位下载 amd64,如果 32 位下载 686)。这也适用于 macOS,只需下载 Vagrant 并完成设置。

如果我们在基于 Debian 的 Linux 系统(如 Kali Linux)上,我们可能有vagrant可供下载的软件包:

kali@kali:~$ sudo apt search vagrant
Sorting... Done
Full Text Search... Done
[...]
vagrant/kali-dev,kali-dev,kali-rolling,kali-rolling,now 2.2.19+dfsg-1 all [installed]
  Tool for building and distributing virtualized development environments

vagrant-cachier/kali-dev,kali-dev,kali-rolling,kali-rolling 1.2.1-3.1 all
  share a common package cache among similar VM instances

vagrant-hostmanager/kali-dev,kali-dev,kali-rolling,kali-rolling 1.8.9-1.1 all
  Vagrant plugin for managing /etc/hosts on guests and host

vagrant-libvirt/kali-dev,kali-dev,kali-rolling,kali-rolling,now 0.8.0-1 all [installed,automatic]
  Vagrant plugin that adds an Libvirt provider to Vagrant

vagrant-lxc/kali-dev,kali-dev,kali-rolling,kali-rolling 1.4.3-2 all
  Linux Containers provider for Vagrant

vagrant-mutate/kali-dev,kali-dev,kali-rolling,kali-rolling 1.2.0-4.1 all
  convert vagrant boxes to work with different providers

vagrant-sshfs/kali-dev,kali-dev,kali-rolling,kali-rolling 1.3.6-1 all
  vagrant plugin that adds synced folder support with sshfs
kali@kali:~$

否则,我们应该按照 Vagrant 下载页面上的说明进行操作。

我们接下来需要下载一个管理程序。出于本指南的目的,我们将下载免费的VirtualBox。如果我们使用的是 Windows 或 macOS,我们可以单击相应的下载链接并完成设置。否则,我们可以在Linux 主机页面上查找我们的发行版。如果我们使用的是 Kali Linux,我们已经可以遵循文档。

使用流浪者

现在我们已经安装了管理程序和 Vagrant,我们可以提取我们的第一个配置文件。

我们必须在命令行中创建一个空的新文件夹/目录。对于本指南,我们将使用 Kali Linux 主机系统,但是vagrant无论使用什么主机,以开头的命令都是相同的。

kali@kali:~/vagrant$ vagrant init kalilinux/rolling
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.

kali@kali:~/vagrant$
kali@kali:~/vagrant$ cat Vagrantfile | grep -v '#'

Vagrant.configure("2") do |config|

  config.vm.box = "kalilinux/rolling"

end

kali@kali:~/vagrant$

我们可以看到它是一个非常小的配置文件,但是这将使用最新版本的 Kali Linux 启动一个 VM,并在下载并启动后占用大约 10GB。

要启动这台机器,我们将运行以下命令:

kali@kali:~/vagrant$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Box 'kalilinux/rolling' could not be found. Attempting to find and install...
    default: Box Provider: virtualbox
    default: Box Version: >= 0
==> default: Loading metadata for box 'kalilinux/rolling'
    default: URL: https://vagrantcloud.com/kalilinux/rolling
==> default: Adding box 'kalilinux/rolling' (v2022.3.1) for provider: virtualbox
    default: Downloading: https://vagrantcloud.com/kalilinux/boxes/rolling/versions/2022.3.1/providers/virtualbox.box
==> default: Successfully added box 'kalilinux/rolling' (v2022.3.1) for 'virtualbox'!
[...]
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
==> default: Mounting shared folders...
    default: /vagrant => /home/morales/vagrant

kali@kali:~/vagrant$

kali@kali:~/vagrant$ vagrant ssh
Linux kali 5.16.0-kali7-amd64 #1 SMP PREEMPT Debian 5.16.18-1kali1 (2022-04-01) x86_64

The programs included with the Kali GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Kali GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
kali@kali:~$
kali@kali:~$ exit

kali@kali:~/vagrant$

kali@kali:~/vagrant$ vagrant halt
==> default: Attempting graceful shutdown of VM...

kali@kali:~/vagrant$

如果我们想调整我们的配置文件,我们可以执行以下操作:

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
  config.vm.box = "kalilinux/rolling"

  # Create a forwarded port
  config.vm.network "forwarded_port", guest: 80, host: 8080

  # Create a private network. In VirtualBox, this is a Host-Only network
  config.vm.network "private_network", ip: "192.168.33.10"

  # VirtualBox specific settings
  config.vm.provider "virtualbox" do |vb|
    # Hide the VirtualBox GUI when booting the machine
    vb.gui = false

    # Customize the amount of memory on the VM:
    vb.memory = "4096"
  end

  # Provision the machine with a shell script
  config.vm.provision "shell", inline: <<-SHELL
    sudo apt update
    sudo apt install -y crowbar
  SHELL
end

然后我们可以通过运行以下命令将其加载到正在运行的 Vagrant 实例中:

kali@kali:~$ vagrant reload
kali@kali:~$

如果我们想重新配置我们的虚拟机,它通常只在机器第一次启动时运行,我们可以执行以下命令之一:

$ vagrant provision  # provision the powered on VM
$ vagrant up --provision  # when VM is powered off, power it on then provision
$ vagrant reload --provision  # reboot the VM then provision

在Vagrant 的文档中可以找到更多配置选项。


更新日期:2022 年 8 月 10 日
作者: gamb1t

标签:Guest,default,Kali,虚拟机,vagrant,dev,Vagrant,kali,rolling
From: https://www.cnblogs.com/GKLBB/p/16759239.html

相关文章