云网牛站
所在位置:首页 > Linux教程 > 在VirtualBox中使用Vagrant运行Kali Linux的方法

在VirtualBox中使用Vagrant运行Kali Linux的方法

2019-01-19 12:11:32作者:戴进稿源:云网牛站

本文将介绍使用Vagrant和VirtualBox虚拟机管理程序运行Kali Linux的方法,请先安装VirtualBox和Vagrant,同时需要具有VT-X/AMD虚拟化扩展的CPU。

 

在Kali Linux上安装VirtualBox和Vagrant

一、在Kali Linux上安装VirtualBox

1、添加存储库密钥:

wget -q https://www.virtualbox.org/download/oracle_vbox_2016.asc -O- | sudo apt-key add -

wget -q https://www.virtualbox.org/download/oracle_vbox.asc -O- | sudo apt-key add -

2、添加VirtualBox存储库:

既然已导入存储库密钥,请通过运行以下命令添加VirtualBox存储库:

echo "deb [arch=amd64] http://download.virtualbox.org/virtualbox/debian $(lsb_release -sc) contrib" | sudo tee /etc/apt/sources.list.d/virtualbox.list

3、安装VirtualBox和Extension Pack

在Kali Linux上安装VirtualBox和Extension Pack:

sudo apt update

sudo apt install linux-headers-$(uname -r) dkms

sudo apt install virtualbox virtualbox-ext-pack

安装VirtualBox后,就可以启动了。

二、参考安装Vagrant的文章

在Ubuntu 18.04/Debian 9/Kali Linux上安装Vagrant的方法

 

下载Kali Vagrant box

安装VirtualBox和Vagrant后,下载Kali Linux Vagrant box image,你有两种选择:

1、下载Kali Linux full image - 随附所有Kali包

2、下载Kali Linux Light - 包含精简包列表

使用以下命令下载Vagrant box:

$ vagrant box add offensive-security/kali-linux

box: Loading metadata for box 'offensive-security/kali-linux'

box: URL: https://vagrantcloud.com/offensive-security/kali-linux

box: Adding box 'offensive-security/kali-linux' (v2018.3.1) for provider: virtualbox

box: Downloading: https://vagrantcloud.com/offensive-security/boxes/kali-linux/versions/2018.3.1/providers/virtualbox.box

box: Box download is resuming from prior download progress

box: Successfully added box 'offensive-security/kali-linux' (v2018.3.1) for 'virtualbox'!

对于Kali Linux Light,用kali-linux-light替换kali-linux:

$ vagrant box add offensive-security/kali-linux-light

box: Loading metadata for box 'offensive-security/kali-linux-light'

box: URL: https://vagrantcloud.com/offensive-security/kali-linux-light

box: Adding box 'offensive-security/kali-linux-light' (v2018.3.1) for provider: virtualbox

box: Downloading: https://vagrantcloud.com/offensive-security/boxes/kali-linux-light/versions/2018.3.1/providers/virtualbox.box

box: Successfully added box 'offensive-security/kali-linux-light' (v2018.3.1) for 'virtualbox'!

添加的Vagrant boxes应该是可见的:

$ vagrant box list  | grep offensive 

offensive-security/kali-linux       (virtualbox, 2018.3.1)

offensive-security/kali-linux-light (virtualbox, 2018.3.1)

 

启动Kali Linux虚拟机

首先为Kali项目创建一个空目录,然后从那里生成一个Vagrant文​​件:

$ mkdir -p vagrant-projects/kali

$ cd vagrant-projects/kali

$ vagrant init offensive-security/kali-linux

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.

此命令为你生成Vagrantfile,其中包含虚拟机的所有配置选项,值得一提的是,每个vagrant命令都应该从包含Vagrantfile的目录运行。

可以在运行vagrant up命令之前根据自己的喜好修改文件:

# -*- mode: ruby -*-

# vi: set ft=ruby :

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

config.vm.box = "offensive-security/kali-linux"

config.vm.box_check_update = false

config.vm.hostname = "kali"

config.vm.network "private_network", ip: "192.168.90.99"

config.vm.synced_folder "/home/jmutai/Projects", "/vagrant_data"

config.vm.provider "virtualbox" do |vb|

# Display the VirtualBox GUI when booting the machine

vb.gui = false

vb.memory = "2048"

end

end

完成修改后,保存文件并运行:

$ vagrant up

下面是一个示例的输出信息,如图:

在VirtualBox中使用Vagrant运行Kali Linux的方法

要访问VM shell,请运行:

$ vagrant ssh

你还可以使用主机ssh客户端,并通过分配的专用IP地址访问Kali Linux实例shell:

$ ssh vagrant@192.168.90.99

Warning: Permanently added '192.168.90.99' (ECDSA) to the list of known hosts.

vagrant@192.168.90.99's password: 

Linux kali 4.18.0-kali1-amd64 #1 SMP Debian 4.18.6-1kali1 (2018-09-10) 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.

Last login: Sat Jan 18 10:20:41 2019 from 10.0.2.2

vagrant@kali:~$ 

如果检查实例IP地址,则Vagrantfile上配置的地址应该可用:

在VirtualBox中使用Vagrant运行Kali Linux的方法

每当对Vagrantfile进行更改时,请重新启动计算机以使更改生效:

$ vagrant reload

要停止实例,请使用:

$ vagrant halt

如果要在停止VM的同时保存VM的当前状态,请使用:

$ vagrant suspend

有了这个,你将在以后启动VM时返回到完全相同的状态。

通过运行完成后销毁Vagrant:

$ vagrant destroy

以上就是使用Vagrant运行管理Kali Linux实例的方法了。

 

相关主题

在虚拟机VMware下安装Kali Linux系统教程

精选文章
热门文章