Keywords
Custom packages
Custom kernel
Custom images
live-build
Persistence
Chapter
9
Advanced Usage
Contents
Modifying Kali Packages
228
Recompiling the Linux Kernel
237
Building Custom Kali Live ISO Images
241
Adding Persistence to the Live ISO with a USB Key
246
Summary
251
Kali has been built as a highly modular and customizable penetration testing platform and allows
for some fairly advanced customization and usage. Customizations can happen at multiple lev-
els, beginning at the source code level. The sources of all Kali packages are publicly available. In
this chapter, we will show how you can retrieve packages, modify them, and build your own cus-
tomized packages out of them. The Linux kernel is somewhat of a special case and as such, it is
covered in a dedicated section (section
9.2
, “
Recompiling the Linux Kernel
” [page 237]), where we
will discuss where to find sources, how to configure the kernel build, and finally how to compile
it and how to build the associated kernel packages.
The second level of customization is in the process of building live ISO images. We will show how
the
live-build
tool offers plenty of hooks and configuration options to customize the resulting
ISO image, including the possibility to use custom Debian packages in place of the packages avail-
able on mirrors.
We will also discuss how you can create a persistent live ISO built onto a USB key that will preserve
files and operating system changes between reboots.
9.1. Modifying Kali Packages
Modifying Kali packages is usually a task for Kali contributors and developers: they update pack-
ages with new upstream versions, they tweak the default configuration for a better integration in
the distribution, or they fix bugs reported by users. But you might have specific needs not fulfilled
by the official packages and knowing how to build a modified package can thus be very valuable.
You might wonder why you need to bother with the package at all. After all, if you have to modify
a piece of software, you can always grab its source code (usually with
git
) and run the modified
version directly from the source checkout. This is fine when it is possible and when you use your
home directory for this purpose, but if your application requires a system-wide setup (for example,
with a
make install
step) then it will pollute your file system with files unknown to
dpkg
and will
soon create problems that cannot be caught by package dependencies. Furthermore, with proper
packages you will be able to share your changes and deploy them on multiple computers much
more easily or revert the changes after having discovered that they were not working as well as
you hoped.
So when would you want to modify a package? Let’s take a look at a few examples. First, we
will assume that you are a heavy user of Social-Engineer Toolkit (SET) and you noticed a new
upstream release but the Kali developers are all busy for a conference and you want to try it out
immediately. You want to update the package yourself. In another case, we will assume that you
are struggling to get your MIFARE NFC card working and you want to rebuild “
libfreefare
” to
enable debug messages in order to have actionable data to provide in a bug report that you are
currently preparing. In a last case, we will assume that the “
pyrit
” program fails with a cryptic
error message. After a web search, you find a commit that you expect to fix your problem in the
upstream GitHub repository and you want to rebuild the package with this fix applied.
228
Kali Linux Revealed
We will go through all of those samples in the following sections. We will try to generalize the
explanations so that you can better apply the instructions to other cases but it is impossible to
cover all situations that you might encounter. If you hit problems, apply your best judgment to
find a solution or go seek help on the most appropriate forums (see chapter
6
, “
Helping Yourself
and Getting Help
” [page 128]).
Whatever change you want to make, the general process is always the same: grab the source pack-
age, extract it, make your changes, then build the package. But for each step, there are often
multiple tools that can handle the task. We picked the most relevant and most popular tools, but
our review is not exhaustive.
9.1.1. Getting the Sources
Rebuilding a Kali package starts with getting its source code. A source package is composed of
multiple files: the main file is the
*.dsc
(Debian Source Control) file as it lists the other accompa-
nying files, which can be
*.tar.
gz,bz2,xz
, sometimes
*.diff.gz
, or
*.debian.tar.
gz,bz2,xz
files.
The source packages are stored on Kali mirrors that are available over HTTP. You could use your
web browser to download all the required files but the easiest way to accomplish this is to use
the
apt source source_package_name
command. This command requires a deb-src line in the
/etc/apt/sources.list
file and up-to-date index files (accomplished by running
apt update
).
By default, Kali doesn’t add the required line as few Kali users actually need to retrieve source
packages but you can easily add it (see sample file in section
8.1.3
, “
Kali Repositories
” [page 179]
and the associated explanations in section
8.1.2
, “
Understanding the
sources.list
File
” [page
178]).
$ apt source libfreefare
Reading package lists... Done
NOTICE: ’libfreefare’ packaging is maintained in the ’Git’ version control system at:
git://anonscm.debian.org/collab-maint/libnfc.git
Please use:
git clone git://anonscm.debian.org/collab-maint/libnfc.git
to retrieve the latest (possibly unreleased) updates to the package.
Need to get 119 kB of source archives.
Get:1 http://kali.download/kali kali-rolling/main libfreefare 0.4.0-2.1 (dsc) [2,144 B]
Get:2 http://kali.download/kali kali-rolling/main libfreefare 0.4.0-2.1 (tar) [113 kB]
Get:3 http://kali.download/kali kali-rolling/main libfreefare 0.4.0-2.1 (diff) [3,732 B]
Fetched 119 kB in 1s (100 kB/s)
dpkg-source: info: extracting libfreefare in libfreefare-0.4.0
dpkg-source: info: unpacking libfreefare_0.4.0.orig.tar.gz
dpkg-source: info: unpacking libfreefare_0.4.0-2.1.debian.tar.xz
$ cd libfreefare-0.4.0
$ ls
AUTHORS
cmake
configure.ac
COPYING
examples
libfreefare
m4
NEWS
test
ChangeLog
CMakeLists.txt
contrib
debian
HACKING
libfreefare.pc.in
Makefile.am
README
TODO
$ ls debian
changelog
compat
control
copyright
libfreefare0.install
libfreefare-bin.install
libfreefare-dev.install
libfreefare-doc.install
README.Source
rules
source
watch
In this example, while we received the source package from a Kali mirror, the package is the
same as in Debian since the version string doesn’t contain “kali.” This means that no kali-specific
changes have been applied.
If you need a specific version of the source package, which is currently not available in the repos-
itories listed in
/etc/apt/sources.list
, then the easiest way to download it is to find out the
URL of its
.dsc
file by looking it up on
https://pkg.kali.org/
and then handing that URL over
to
dget
(from the devscripts package).
229
Chapter 9 — Advanced Usage
After having looked up the URL of the libreefare source package available in kali-dev, you can
download it with
dget
. It will first download the
.dsc
file, then parse it to know what other files
are referenced, and then download those from the same location:
$ dget http://http.kali.org/pool/main/libf/libfreefare/libfreefare_0.4.0+0~
å
|