In this walkthrough we will be explaining certain things that are only on a VM. It is your choice if you want to install a full Kali system (or if you already have one, if you want to use it) or if you want to use a VM, however keep in mind what commands you’re entering if it is an install.
Setting up the VM
It’s important to set up a development environment. The easiest way to go about this is to set up a VM with the latest Kali image and give it a large filesystem. 80GB+ is good for a few packages at a time, however 150GB+ is recommended if you are using mr to download all packaging repositories. Likely, you will not need all of the packages to be downloaded.
Installing packages
We will install tools that we will use later for packaging. packaging-dev is a metapackage, and will install many of the proper packages that are needed:
Packaging needs to be done on a non-root user with sudo privileges. The default Kali user is suitable for this.
you must log out of your account and switch to the new user (rather than using su). This is done as some pieces (such as variables that are set) of the following setup require you to be on that account, su will not work.
Next, we should generate SSH and GPG keys. These are important for packaging as they will allow us to access our files on GitLab easily and ensure the work is ours. This step is not always necessary, however it is helpful in certain cases. You will know if you need to set up a GPG key, however we recommend setting up an SSH key as it will make the packaging process quicker:
:~$ ssh-keygen -t rsa
[...]
:~$
:~$ gpg --gen-key
gpg (GnuPG) 1.4.12; Copyright (C) 2012 Free Software Foundation, Inc.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
gpg: directory `/home/packaging/.gnupg' created
gpg: new configuration file `/home/packaging/.gnupg/gpg.conf' created
gpg: WARNING: options in `/home/packaging/.gnupg/gpg.conf' are not yet active during this run
gpg: keyring `/home/packaging/.gnupg/secring.gpg' created
gpg: keyring `/home/packaging/.gnupg/pubring.gpg' created
Please select what kind of key you want:
(1) RSA and RSA (default)
(2) DSA and Elgamal
(3) DSA (sign only)
(4) RSA (sign only)
Your selection? 1
RSA keys may be between 1024 and 4096 bits long.
What keysize do you want? (2048)
Requested keysize is 2048 bits
Please specify how long the key should be valid.
0 = key does not expire
<n> = key expires in n days
<n>w = key expires in n weeks
<n>m = key expires in n months
<n>y = key expires in n years
Key is valid for? (0)
Key does not expire at all
Is this correct? (y/N) y
You need a user ID to identify your key; the software constructs the user ID
from the Real Name, Comment and Email Address in this form:
"Heinrich Heine (Der Dichter) <>"
Real name: First Last
Email address:
Comment:
You selected this USER-ID:
"First Last <>"
Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? O
You need a Passphrase to protect your secret key.
We need to generate a lot of random bytes. It is a good idea to perform
some other action (type on the keyboard, move the mouse, utilize the
disks) during the prime generation; this gives the random number
generator a better chance to gain enough entropy.
Not enough random bytes available. Please do some other work to give
the OS a chance to collect more entropy! (Need 284 more bytes)
gpg: /home/packaging/.gnupg/trustdb.gpg: trustdb created
gpg: key A123BC4D marked as ultimately trusted
public and secret key created and signed.
gpg: checking the trustdb
gpg: 3 marginal(s) needed, 1 complete(s) needed, PGP trust model
gpg: depth: 0 valid: 1 signed: 0 trust: 0-, 0q, 0n, 0m, 0f, 1u
pub 2048R/1234AB5C 2000-00-00
Key fingerprint = 12AB 34C4 67DE F890 12G3 H45I 6789 J90K L123 MN4O
uid First Last <>
sub 2048R/12345A6B 2000-00-00
:~$
Please remember to change “First Last [email protected]” to be your name and email.
The next step is to add the SSH key to your GitLab account. This can be done in the keys section. Run the commands below to put the key in the copy-paste buffer and paste it on GitLab’s web page:
Be sure to replace [email protected] with your email, and ensure it is the same one used with your GPG key, if that was setup.
We enable pristine-tar by default as we will use this tool to (efficiently) store a copy of the upstream tarball in the Git repository. We also set export-dir so that package builds happen outside of the git checkout directory.
Below, we’re customizing some useful tools provided by the devscripts package:
The user.name and user.email must match your gpg key details (gpg -k) or you will get a “Secret Key Not Available” error later on. Be sure to put your own key id in user.signingkey. In this example we can see from gpg -k that our key is ABC123DE45678F90123G4567HIJK890LM12345N6
We also want to enable a dedicated git merge driver for the debian/changelog files:
Once that is done, we need to edit /etc/schroot/chroot.d/kali-dev-amd64-sbuild*, note that “*” is used as it will generate the last bit randomly. Alternatively, use TAB auto-completion:
When building a package with a sbuild, a lot of time (and bandwidth) is spent downloading the build dependencies. To speed up this step, it’s possible to use a caching proxy, such as apt-cacher-ng:
:~$ sudo apt install -y apt-cacher-ng
Check the version that was installed. If it’s below 0.6.1-1, Kali is not supported out of the box, and there’s a little config to do:
:~$ echo "http://http.kali.org/kali/" | sudo tee /etc/apt-cacher-ng/kali_mirrors
:~$
:~$ echo "http://kali.download/kali/" | sudo tee /etc/apt-cacher-ng/backends_kali
:~$
:~$ cat <<EOF | sudo tee /etc/apt-cacher-ng/kali.conf
# Repository remapping for Kali. See acng.conf and manual for details.
Remap-klxrep: file:kali_mirrors /kali ; file:backends_kali
EOF
:~$
:~$ sudo systemctl enable apt-cacher-ng --now
:~$
In the snippet above, note that:
The file kali_mirrors lists all the mirrors for which apt-cacher-ng will cache the requests. In this list, there should be at least the mirror that you used with the command sbuild-createchroot above.
The file backends_kali lists the mirror that apt-cacher-ng will actually use to download packages. You should set it to a mirror that is close to you.
Finally, we just need to add a line of configuration inside our chroot, so that apt is configured to use the proxy: