Skip to content

Instantly share code, notes, and snippets.

@superzadeh
Last active August 31, 2023 14:37
Show Gist options
  • Save superzadeh/18deb8fd590c8687019f to your computer and use it in GitHub Desktop.
Save superzadeh/18deb8fd590c8687019f to your computer and use it in GitHub Desktop.
Guide to setup a Kali pentest lab with CTF4 machine from LAMPSecurity #tags: ceh, kali, hacking, lab

How to setup the Kali Linux VM

Lab Configuration

VirtualBox configuration

Install VirtualBox as well as the Oracle VM VirtualBox Extension from Oracle's VirtualBox website: https://www.virtualbox.org/wiki/Downloads.

Double click on the latest Kali *.ova. VirtualBox will start and ask you to import the VM. You can change the name, and make sure to check "Reinitialize MAC addresses of all network cards". Then click next untill the end (you can change these settings later).

Once the VM is imported, click on Configuration. Go to the Network tab and create two adapters:

  • Set the first one to NAT
  • Set the second one to Private host only

Repeat for the CTF4 .ova file, but only create one network adapter to Privaate Host only. Again, do not forget to "Reinitialize MAC addresses of the network card" (in advanced settings of the adapter).

Hyper-V configuration (Windows 10) - NOT WORKING YET

Networking

  • Virtual Switch Manager, create a new Internal one and name it Pentest
  • Go to Network and Sharing center -> change adapter settings, select your ethernet or Wifi adapter, right click -> properties.
  • Go to the Sharing tab, check " Allow other network users to connect through this computer's internet connection" and select the Pentest adapter.

Open Hyper-V Manager

Then we need to create CTF4

  • New Virtual Machine
  • Name it CTF4
  • First Generation (important, otherwise it won't load)
  • Startup memory 1024, use Dynamic
  • Connect it to the Pentest switch
  • Use an existing virtual Hard Disk, browse to the ctf4.vhdx

Now download a small DHCP server and install it on your host machine. Alternatively, you can also configure a NAT Windows Server image

VMWare Workstation configuration

Start VMWare Workstation, click on "Open a Virtual Machine", select the Kali Linux file. This will start the VM in VMWare. If you are prompted with "did you move or copy it", select "Moved it".

Then open the settings of the VM, go to Network Adapter and set VMNet8 (NAT). This allows to have your VM on a private network but still provide it with internet access. Your host (your physical computer) will also be able to access this machine, using ssh for example.

Repeat for CTF4 (the VMWare image is in the .wip download), That's it! (Also put CTF4 on the VMNet8).

Configure the Kali VM

  1. Start the VM. On the boot screen (GNU GRUB), select the first option (Kali GNU/Linux).

  2. Enter the default username ("root") and password ("toor")

  3. -- forAZERTY keyboards only -- On the desktop, click in the top right corner on the "Settings" icon and go to "Region and language". Alternatively, you can also press the Windows key and type "region and language"

    1. In the input sources, add the keyboard "French"
    2. Once added, remove the US Keyboard. This will allow to boot with a French keyboard when typing your password
  4. Open a terminal and type passwd

    1. Supply your new password
    2. Confirm it
    3. This is now the password used to login to your VM
  5. If you use a High DPI device, it is recommended to run the following command to setup scaling:

     gsettings set org.gnome.desktop.interface text-scaling-factor 1.5		
    
  6. Go to the settings again, then Privacy, click on Screen Lock and Disable the Automatic Screen Lock.

Configure the network

By default, DHCP is disabled on Kali Linux.

vi /etc/network/interfaces

Add the following lines (press "i" to go in insertion mode, allowing you to type)

auto eth0
allow-hotplug eth0
iface eth0 inet dhcp

If you are using VirtualBox, also add the following line to configure both network adapters:

auto eth1
allow-hotplug eth1
iface eth1 inet dhcp

Then press "Esc" and type :wq to save the changes. In the terminal, type the following command to restart the network service

service networking restart

You should now be connected to internet. Try it by starting Iceweasel and search something on google.

Configure SSH

SSH is a very convenient way to run commands on your Kali Linux machine from a remote host. This is very useful if you use Cmder or CYGWIN on Windows since it has built in ssh support.

Regenerating SSH keys

Kali linux comes with pre-generated SSH keys. It is important to regenerate them, otherwise you would be vulnerable to MITM (Man in the Middle) attacks. Follow the procedure below to regenerate your SSH keys.

Move the default Kali ssh keys to a new folder:

cd /etc/ssh/
mkdir default_kali_keys
mv ssh_host_* default_kali_keys/

Regenerate the keys:

dpkg-reconfigure openssh-server

Compute the md5sum of your new keys

md5sum ssh_host_*

Now do the same for the default keys

cd default_kali_keys/
md5sum *

Make sure that the hashes are different, otherwise it means you did something wrong.

Configuring the SSH service

Now that we have good SSH key, we need to configure the SSH service.

apt-get install openssh-server

This will download and install the openssh server. Run the following commands to make it start automatically when your VM boots:

update-rc.d -f ssh remove
update-rc.d -f ssh enable 2 3 4 5

Now, edit the following file:

vi /etc/ssh/sshd_config		

And set PermitRootLogin to PermitRootLogin yes. Again, press "Esc" and :wqto write and quit.

Now, very important part, setup your MOTD (message of the day). This is displayed when you will login using SSH from a remote host. Go the following website: http://patorjk.com/software/taag and type your welcome message. Then set it as your message of the day by editing the following file. Type "i" to go in insert mode and paste the content using Ctrl+Shift+v. Don't forget to press "Esc" and :wq to save the changes.

vi /etc/motd

Once done, restart the SSH service:

service ssh restart

Testing the connection

Restart the VM. We can now test the SSH connection from your remote host or Windows Machine. the first thing we need is the IP address of your VM.

ifconfig

You should see two ethernet interfaces: eth0 and eth1. One of them is connected to a local network and has an address that starts with 192.168.xxx.xxx, this is one you should save.

Now go back to your Windows Host and type the following command in Cmder (replace the xxx by the actual IP address of your Kali VM):

ssh root@192.168.xxx.xxx

You should be prompted to type your password, type it and you should see your MOTD followed by a prompt root@kali. This means that you are now connected in SSH on your Kali VM. For convenience, you can create an alias in Cmder to avoid typing the IP address everytime:

alias sshkali=ssh root@192.168.xxx.xxx

Keeping your Kali VM up to date

Fist off, make sure your VM has internet access (depending on what type of virtualization you use, refer to the instructions at the beginning of this guide).

One of the new features introduced with Kali 2.0 is that the distribution now has an auto-update built in. Run the two following commands to get the latest version of the Kali distribution. Note that the second one might take a while.

apt-get update
apt-get dist-upgrade

Additional Tools

You might also want to install a few additional tools that will come handy:

apt-get install fish python3-dev python3-pip
pip3 install thefuck
chsh -s `which fish`

Then update you fish.config (vim ~/.config/fish/config.fish) and add the following line:

eval (thefuck --alias | tr '\n' ';')

This will get you the Fish shell as well as TheFuck:

Example thefuck

Once this is done, I recommend that you switch back to a private network and take snapshot of your VM, just in case you mess things up later on.

@shatgupt
Copy link

shatgupt commented Dec 8, 2018

While configuring ssh to start automatically, it fails on enable with error: update-rc.d: error: no runlevel symlinks to modify, aborting!. You need to do defaults before enable.

update-rc.d -f ssh remove
update-rc.d -f ssh defaults
update-rc.d -f ssh enable 2 3 4 5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment