がじぇ

お金と家電とプログラミングのブログ

ハッキングラボの構築(Vagrant+VirtualboxでKali Linuxの導入)

おはようございます。

がじぇったー (@hackmylife7) | Twitter


です。


サイバーセキュリティの本を買ったので、こちらも勉強していきたいと思います。




f:id:gadgeterkun:20190727155810j:plain

TL;DR(要約)

  • Kali Linuxは攻撃的な侵入テストの標準と見なされているLinuxベースのオペレーションシステム


やっていく本は下記です。結構なボリュームがあってなかなか面白そう。

基本的に勉強のためで人様には迷惑はかけません。

Kali Linuxの導入


Kali Linuxは侵入テスト、およびセキュリティ監査に特化したOSであり、それらに関する数百のツールが含まれています。

Dockerでもいいんですが、色々ツールのインストールが必要そうなのでVirtualBoxVagrantにKali Linuxに導入していきます。




Virtual BoxとVagrant のインストール方法はくさるほど他の記事であるので、どれか参照してください。

install


Vagrant fileの追加

 
$ 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.

$ ls
Vagrantfile


コメント行を除いてcatするとファイルには
osはkali-linux使うよ、くらいしか書いていない。

 
$ cat Vagrantfile | grep -v "^\s*$" | grep -v "^\s*#"
Vagrant.configure("2") do |config|
  config.vm.box = "offensive-security/kali-linux"
end


vagrant upで起動させます
※エラーが出る方は文末のエラー対応の箇所を確認ください

>|bash|
 
$ vagrant up


sshでマシンに接続します

 
$ vagrant ssh
Linux kali 4.19.0-kali5-amd64 #1 SMP Debian 4.19.37-2kali1 (2019-05-15) 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.
vagrant@kali:~$

一旦抜けます

 
vagrant@kali:~$ exit


Vagrantfileを公式ドキュメントで記載されいている通り書き換えましょう。
そのまま貼り付けたら動かなかったので一部修正しています。

またvagrant 起動時にGUIが自動で起動されないようになります。



 
Vagrant.configure("2") do |config|
  config.vm.box = "offensive-security/kali-linux"

  # 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
end


下記の共有設定を付け加えると、ホストマシン(Mac)とVagrantでファイルを共有できるので、いれたい人はいれましょう。"/Users/hoge/project/study/security"がホストマシンのパスで"/root/shared"がVagrantマシンのパスです。

 
   config.vm.synced_folder "/Users/hoge/project/study/security", "/root/shared",
     id: "vagrant-root", :nfs => false,
     :mount_options => ["dmode=777,fmode=777"]


では次回から色々試していきたいと思います。

エラー対応

vagrantのバージョンが古い

vagrantのバージョンが古いと以下のようなエラーが表示される場合があります。

vagrantのバージョン

 
$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Box 'offensive-security/kali-linux' could not be found. Attempting to find and install...
    default: Box Provider: virtualbox
    default: Box Version: >= 0
The box 'offensive-security/kali-linux' could not be found or
could not be accessed in the remote catalog. If this is a private
box on HashiCorp's Atlas, please verify you're logged in via
`vagrant login`. Also, please double-check the name. The expanded
URL and error message are shown below:

URL: ["https://atlas.hashicorp.com/offensive-security/kali-linux"]
Error: The requested URL returned error: 404 Not Found

その際はVagrantのバージョンをあげてください。おそらく古いバージョンはリポジトリの向き先が違う

 
$ vagrant --version
Vagrant 1.9.5
$ vagrant --version
Vagrant 2.2.5
$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...

** virtual boxのバージョン

このエラーが出力される場合は、VirtualBoxのバージョンをあげることで解消されるので
以下から新しいバージョンをダウンロードしてください
Oracle VM VirtualBox - Downloads | Oracle Technology Network | Oracle

 
There was an error while executing `VBoxManage`, a CLI used by Vagrant
for controlling VirtualBox. The command and stderr is shown below.

Command: ["startvm", "61129dd1-526e-42d8-a58c-1daf906a50b2", "--type", "gui"]

Stderr: VBoxManage: error: The virtual machine 'security_default_1564196435266_3790' has terminated unexpectedly during startup with exit code 1 (0x1)
VBoxManage: error: Details: code NS_ERROR_FAILURE (0x80004005), component MachineWrap, interface IMachine


これからこの環境を使って色々やっていきます。

参考

How to run Kali Linux rolling release with Vagrant on VirtualBox - Computing for Geeks