Introduction️
Kali Linux is a security auditing Linux distribution based on Debian GNU/Linux. Kali is aimed at security professionals and IT administrators, allowing them to perform advanced penetration testing, forensic analysis, and security audits. Debian GNU/Linux is one of the main generic Linux distributions, known for its quality and stability. Kali Linux is based on the work of the Debian project and adds over 400 special purpose packages of its own, all related to information security, particularly in the field of penetration testing. The default ISO images can be downloaded from the Kali website.️
The tool live-build offers a lot of configuration options to customize the resulting ISO image. We will modify the image to set Spanish (Spain) as the default language, along with Spain peninsular time zone and keyboard layout, disable boot menu beeps, and personalize partitions to copy Kali image onto a USB drive and save Kali data on an unencrypted and encrypted persistent partition. We will include an updated version of the aircrack-ng tool and Realtek RTL8812AU network card drivers. Finally, we will create a configuration file to enable almost automatic system installation.️
Installation of dependencies️
We will first install the required dependencies for live-build and for creating .dpkg files with devscripts.️
$ sudo apt update
$ sudo apt install curl git live-build -y
$ sudo apt install devscripts -y
Cloned the repository with the live-build configuration
We will clone the repository that contains the default configuration to create images of Kali Linux.️
$ git clone https://gitlab.com/kalilinux/build-scripts/live-build-config
$ cd live-build-config
Creation of the new variant of Kali️
In the folder kali-config you will find several configurations for each type of desktop (XFCE, KDE, GNOME, etc) in the folders variant-*, for different installers in the folders installer-* and a common configuration for all in the folder common. We are going to create our own variant called custom that will contain the basic packages kali-linux-core and kali-desktop-live along with kali-linux-default (if we want to install the tools of the default image) or kali-tools-top10 (if we want to install only the top 10 most used tools). We will select the KDE desktop with the package kali-desktop-kde. The file to create is kali-config/variant-custom/package-lists/kali.list.chroot.️
$ mkdir -p kali-config/variant-custom/package-lists
$ cat<<EOF>kali-config/variant-custom/package-lists/kali.list.chroot
kali-linux-core
kali-desktop-live
kali-tools-top10
#kali-linux-default
kali-desktop-kde
EOF
Customizable language in the image and installation
In this case, we will set up the Spanish language from Spain (es_ES.UTF-8) along with the time zone for Madrid (Europe/Madrid) and keyboard layout. First, we will configure the auto/config file to preload the configuration before starting the installation so that it is not requested later. We change the line:️
--bootappend-install "net.ifnames=0" \
to:
--bootappend-install "net.ifnames=0 language=es country=ES locale=es_ES.UTF-8 keymap=es" \
Change the language in the “live” image configuration, which is the one that runs directly without being installed and allows saving data to a persistent partition. We will add some variables to the file kali-config/common/includes.chroot/etc/live/config.conf.d/kali.conf.️
$ cat<<EOF>>kali-config/common/includes.chroot/etc/live/config.conf.d/kali.conf
# español de España
LIVE_LOCALES="es_ES.UTF-8"
LIVE_TIMEZONE="Europe/Madrid"
LIVE_KEYBOARD_LAYOUTS="es"
EOF
Disable the bootloader beeps at startup
To disable the beeps in the bootloader when booting up, these two lines will be commented out in the file kali-config/common/bootloaders/grub-pc/config.cfg.️
insmod play
play 960 440 1 0 4 440 1
Add the driver for the Realtek RTL8812AU network card
Adding the Realtek RTL8812AU network card driver, not present by default in Kali Linux images, will be as simple as adding the package name realtek-rtl88xxau-dkms to the file kali-config/common/package-lists/standard.list.chroot.️
$ echo 'realtek-rtl88xxau-dkms' >> kali-config/common/package-lists/standard.list.chroot
Modification of persistent partition names️
With the use of persistent mode in Kali Linux, it allows saving files generated during a live version execution on a USB memory. By default, the system searches for a partition named persistence. In this case we will change the name of the non-encrypted persistent partition to p3rs1st and the encrypted one to p3rs1stenc. We will modify first the bootloader ISOLINUX configuration (if BIOS is used in the boot process) and then that of GRUB (using UEFI). With ISOLINUX we modify these two lines from the file kali-config/common/bootloaders/syslinux_common/live.cfg.in:️
append boot=live username=kali hostname=kali persistence
append boot=live persistent=cryptsetup persistence-encryption=luks username=kali hostname=kali persistence
to:
append boot=live username=kali hostname=kali persistence-label=p3rs1st persistence
append boot=live persistent=cryptsetup persistence-encryption=luks username=kali hostname=kali persistence-label=p3rs1stenc persistence
With GRUB the lines of the file kali-config/common/bootloaders/grub-pc/grub.cfg are modified:️
linux @KERNEL_LIVE@ @APPEND_LIVE@ persistence
linux @KERNEL_LIVE@ @APPEND_LIVE@ persistent=cryptsetup persistence-encryption=luks persistence
to:
linux @KERNEL_LIVE@ @APPEND_LIVE@ persistence-label=p3rs1st persistence
linux @KERNEL_LIVE@ @APPEND_LIVE@ persistent=cryptsetup persistence-encryption=luks persistence-label=p3rs1stenc persistence
aircrack-ng tool update
In Kali repositories, generally include the latest versions of tools. But in the case of some, like aircrack-ng, are updated infrequently so to get their latest news (although not updated version) it is necessary to compile it from source code and generate a package .dpkg. First we will obtain the source code of the application from the official repository (pkg.kali.org) downloading the file with format .dsc, in this case version 1:1.7-5:. Then we will proceed to download the source code with the application dget.️
With the Kali source code, the current source code from the repository will be downloaded and the debian folder from the Kali source code will be copied to the updated source code. Then enter the updated source code directory and update the change control with dch tool. Finally, install necessary dependencies for compilation and generate .dpkg package with dpkg-buildpackage tool.️
$ dget http://http.kali.org/pool/main/a/aircrack-ng/aircrack-ng_1.7-5.dsc
$ git clone https://github.com/aircrack-ng/aircrack-ng aircrack-ng-updated
$ cd aircrack-ng-updated
$ cp -r ../aircrack-ng-1.7/debian .
$ dch --local custom -m "Updated upstream"
$ sudo apt build-dep ./
$ dpkg-buildpackage -us -uc -b
In the parent directory a package named aircrack-ng_1.7-5custom1_amd64.deb will have been generated.️
$ cd ..
$ ls -1 aircrack*deb
aircrack-ng_1.7-5custom1_amd64.deb
aircrack-ng-dbgsym_1.7-5custom1_amd64.deb
We will copy this file to the directory kali-config/common/packages.chroot.
$ mkdir -p kali-config/common/packages.chroot
$ cp aircrack-ng_1.7-5custom1_amd64.deb kali-config/common/packages.chroot
Semi-automated installation️
To perform a nearly automated installation (only the partitions will need to be configured), we will add a series of configurations such as the computer name, the domain of the computer, the username, its password and time zone to the file kali-config/common/includes.installer/preseed.cfg.️
$ cat<<EOF>>kali-config/common/includes.installer/preseed.cfg
# Unattended install
d-i netcfg/get_hostname string kali-machine
d-i netcfg/get_domain string KL.local
d-i passwd/user-fullname string kaliuser
d-i passwd/username string kaliuser
d-i passwd/user-password password password
d-i passwd/user-password-again password password
d-i time/zone string EU/Madrid
EOF
Creation of the image, copy and partitioning of the memory USB
For the creation of the image we will use the script ./build.sh.️
$ ./build.sh --variant custom --verbose
From this point on, we will find the image .iso in the directory images.️
$ ls -l images/*.iso
Having introduced the USB memory and identified as /dev/sdb, it will copy the image using the tool dd (all data on the USB memory will be lost).️
$ sudo dd if=images/kali-linux-rolling-live-custom-amd64.iso of=/dev/sdb bs=4M
Finally, the non-encrypted persistent partition p3rs1st and the encrypted persistent partition p3rs1st will be created with the tool parted, mkfs.ext4, and cryptsetup.️
$ sudo parted /dev/sdb
(parted) mkpart primary 3591M 5691M
(parted) mkpart primary 5691M 100%
$ sudo mkfs.ext4 -L p3rs1st /dev/sdb3
$ sudo mount /dev/sdb3 /mnt
$ echo "/ union" | sudo tee /mnt/persistence.conf
$ sudo umount /dev/sdb3
$ sudo cryptsetup luksFormat /dev/sdb4
$ sudo cryptsetup open /dev/sdb4 p3rs1stenc
$ sudo mkfs.ext4 -L p3rs1stenc /dev/mapper/p3rs1stenc
$ sudo mount /dev/mapper/p3rs1stenc /mnt
$ echo "/ union" | sudo tee /mnt/persistence.conf
$ sudo umount /dev/mapper/p3rs1stenc
$ sudo cryptsetup close /dev/mapper/p3rs1stenc
Conclusion️
Apart from the modifications made, it is possible to configure more deeply and complex images of Kali Linux. These are found in the course Kali Linux Revealed by OffSec.️