1 – Kali from Git clone and Booting in 19 steps + some more – UPDATED 24/02/2015

This has been left here for historical purposes, please see the new fully working guide here!

Ok I had a previous attempt running the install from Linux Mint 17 and I had some issues, one of those issues being a 3GB partition with only one script in it and nothing else which was a bit strange, I did however notice during creation certain folders failed to be found like “init” for example which at the time I figured was a bit odd but I proceeded nonetheless. What follows is a full guide on how I got Kali Linux running on the Raspberry Pi 2 successfully:

Step 1:

Create a directory to work out of and navigate into it

mkdir Kali-Git

cd Kali-Git

1 - Kali make dir

 

1.1 - Kali change dir

Step 2:

git clone https://github.com/offensive-security/gcc-arm-linux-gnueabihf-4.7 to pull down for the “armhf” image creation

2 - Kali Git Clone

Output once finished it should look as follows

2.1 - Kali Git Clone Finish

Step 3:

Check your working directory with “pwd” and then ls to check the gcc-arm directory is there and use this information to export the path

3 - Check pwd and directory

Step 4:

Export the path with /root/Kali-Git being the working directory and gcc-arm-linux-gnueabihf-4.7/bin being the directory and bin directory contained within that you just cloned from git

4 - Export Kali

Step 5:

Clone the kali-arm-build-scripts from github

5 - Clone Kali Arm Scripts

Output once finished it should look as follows

5.1 - Clone Kali Arm Scripts finish

Step 6:

Now as the Pi has a different architecture you need to modify the rpi.sh script in the cloned repository with the editor of your choice

6 - Change to Kali arm scripts dir

Step 7:

Modifying two separate locations as outlined in the below image

7 - Change Kali architecture

Step 8:

I also choose to comment out the last few lines at the end in order to be able to troubleshoot and not compress or build a shasum as you can see below and make sure to save it

8 - rpi script comment out

Step 9:

Copy the following pastebin script from here and create a new file in the kernel directory or alternatively run wget http://pastebin.com/download.php?i=Rv3zpsiv -O rpi-3.1.8.config from the terminal to do this for you and download it straight to the directory ready to edit.

9 - change kernel and create file

Step 10:

Paste the above pastebin content into the new file, save it and then modify the following line so that we can copy the Raspbian boot directory over afterwards as this is also required in order to make things run smoothly and get rid of X freezing. CONFIG_LOCALVERSION=”-v7″ to CONFIG_LOCALVERSION=”-v7+” you only need to add a + to the end.

10 - Change kernel

Step 11:

Fix any local dependencies you may require by running the following script

11 - Build Kali dependencies

Output of the above script should finish like the following with no errors

11.1 - Kali dependencies finish

Step 12:

Now modify the rpi.sh script for the kernel changes to be picked up and change the kernel number to match the file that you just created

12 - Kali config change

Step 13:

The output should initiate as below when the rpi.sh script is run with the version number of your choice and be patient as depending on your internet connection this can take some time to complete

13 - run rpi script

 

When finished it should look something like this

13.1 - run rpi script finish

Step 14:

Check the directory and your image are there

14 - check the kali image is created

Step 15:

Now it’s time to burn your image to your micro sd card with dd but first you will have to find your micro sd card. Use “fdisk -l” to list available partitions /dev/sda is my main local disk and /dev/sdb is the micro sd card. If you don’t know which one is your micro sd just unplug it and run “fdisk -l” again and see what has changed, then plug it back in again and you should see it now.

14.1 Kali list disk

Now it’s time to run the dd command to burn the image to the micro sd

Usage:

dd – to run and copy the image file

if=/the directory of your image file in this case the rpi-1.0.1 file directory

of=/the micro sd card to copy the image to

bs=1M – for a blocksize of 1MB

14.2 Kali dd to disk

Output should look similar to the following

14.3 Kali dd finish

Step 16:

I booted up at this stage and I was getting the freeze that was talked about on the Kali Linux forum once Kali is installed.

Step 17:

I then copied the boot loader partition from the Raspbian image over and replaced the files that had been installed on the Kali Pi image just created. First though you need to mount the Raspbian image to extract the boot loader

Calculate the block size for mounting first by calculating the number of bytes by the starting block so in this case 512 x 122880.

17 - calculate block size

Once you have this information you can then mount Raspbian with the following command

mount -o loop,offset=$((512 * 122880)) 2015-01-31-raspbian.img /mnt/raspbian

 

17.1 - mnt raspbian

Step 18:

Insert your Micro SD card create a folder in the Kali Pi /lib/ directory on the main partition called modules

18 - create modules directory

Step 19:

Copy the directory “3.18.5-v7+” from the Raspbian image over to theKali Pi /lib/modules/ directory that was just created. I advise opening a new terminal window for this though so you can check with “pwd” and get the correct working directory

19 - copy raspbian to kali

So from this we need to copy /mnt/raspbian/lib/modules/3.18.5-v7+ to the Kali Micro SD card  which is in the following directory for me and yours will be different to this /media/96ceeab2-4f55-41fb-8e55-91cd598e066e/lib/modules

cp -r (Copy the directory)

/mnt/raspbian/lib/modules/3.18.5-v7+ (The Raspbian directory we are copying)

/media/96ceeab2-4f55-41fb-8e55-91cd598e066e/lib/modules (Kali on the Micro SD card)

cp -r /mnt/raspbian/lib/modules/3.18.5-v7+ /media/96ceeab2-4f55-41fb-8e55-91cd598e066e/lib/modules

19.1 - copy raspbian to kali copied

Check the directory copied over correctly

19.2 - copy raspbian to kali copied check

Now to repeat a somewhat similar process of mounting and copying with the boot loader

19.3 - mount raspbian boot loader

Calculate the block size for mounting first by calculating the number of bytes by the starting block so in this case 512 x 8192.

19.4 - mount raspbian boot loader active

Now to Copy the boot-loader contents from the Raspbian Pi image to replace the contents of the Kali boot-loader but first remove all the contents on the Kali Micro SD card in the bootloader with “rm -rf *” Be careful with this as if you don’t know what you are doing you will remove the contents of the directory you are currently in. You have been warned.

19.6 - Kali boot loader directory clear

 

Copy the full directory, all contents on the Raspbian boot loader to the Kali Micro SD boot loader

19.7 - Kali boot raspbian copy

Check the Kali boot-loader again with ls and you should now see the Raspbian contents in the Kali boot-loader

19.8 - Kali boot raspbian copied

Result: Kali Pi is booting up and X is also working and I have to say it is extremely fast! The first Pi was so slow compared to this and I only ever used it via SSH and used the terminal. I don’t think I can use the old one any longer now after this, I might re-purpose it as something but from now all focus is on the RPi 2!

BUT! We need to also get the kernel patched for Wi-Fi injection also so 

Step 20:

SSH into your Kali distro

20 - recompile kernel for wi-fi

Using the editor of your choosing create a file called “recompile_kernel” or whatever you want like below and then copy and paste into your new file. Thanks to Cyberkryption for this as I hadn’t spotted it yet but this was the reason I was wanted to boot Kali on the Pi

sudo apt-get install linux-source
sudo apt-get install bc gcc gcc-4.6 libc-bin libc-dev-bin libc6 libc6-dev linux-libc-dev make manpages-dev
git clone --depth=1 https://github.com/raspberrypi/linux
cd linux
zcat /proc/config.gz > ~/linux/arch/arm/configs/pi_defconfig
mkdir -p ../patches
wget https://raw.github.com/offensive-security/kali-arm-build-scripts/master/patches/kali-wifi-injection-3.12.patch -O ../patches/mac80211.patch
patch -p1 --no-backup-if-mismatch < ../patches/mac80211.patch
make pi_defconfig
make modules
make modules install
sudo cp /boot/kernel.img /boot/kernel-bup.img
sudo cp arch/arm/boot/Image /boot/kernel.img

20.1 - recompile kernel for wi-fi

Should look like this

20.2 - recompile kernel for wi-fi

Now chmod +x the file to make it executable

20.3 - recompile kernel for wi-fi

Should look like this

20.4 - recompile kernel for wi-fi

 

Step 20 is not working for me yet and I am getting a few errors that I need to look into a bit further, Cyberkryption on the other hand has this working.

Going back to the start of step 20 again to get wi-fi injection working on the Pi

Step 20 revisited:

I was having problems with installing “linux-source” so I had to run “apt-get update –fix-missing” first to rectify the problem, most likely due to something I was doing last night

1 - apt-get-update-fix-missing

It finished like this

1.1 - apt-get-update-fix-missing-finish

Now to run “apt-get install linux-source” again and accept with -y

2 - linux-source

It finishes like this

2 - linux-source-finish

Now run “apt-get install bc gcc gcc-4.6 libc-bin libc-dev-bin libc6 libc6-dev linux-libc-dev make manpages-dev” but as that step had ran without issue previously this step was already completed last night.

3 - more install

Now run “git clone –depth=1 https://github.com/raspberrypi/linux” and it should finish like below

4 - git linux

“cd” into linux and “ls” to check the contents

5 cd linux and ls

Output the current kernel
zcat /proc/config.gz > ~/linux/arch/arm/configs/pi_defconfig
6 - output current kernel

Make a directory called patches in the previous directory where you created the linux file

7 make dir patches

Run:
wget https://raw.github.com/offensive-security/kali-arm-build-scripts/master/patches/kali-wifi-injection-3.12.patch -O ../patches/mac80211.patch
patch -p1 –no-backup-if-mismatch < ../patches/mac80211.patch
8 - wifi injection patch
Patch:
patch -p1 –no-backup-if-mismatch < ../patches/mac80211.patch
9 - wifi injection patched

make pi_defconfig

10 - Write kernel config

make modules – currently looks like this after a few hours so be patient!

11 - make modules

TO BE CONTINUED!

Congratulations on making it this far, have fun!

References:

Kali Fourm

Cyberkryption Blog

Big thanks to:
mame82, Ram0n & Cyberkryption for fixes along the way and sharing their knowledge.

 

8 thoughts on “1 – Kali from Git clone and Booting in 19 steps + some more – UPDATED 24/02/2015

  1. Awesome guide! Everything runs beautifully until step 13 for me.

    It has a TON of errors, and never creates the .img file.

    I’m doing this with a Linux Mint 17 VM on a 26GB partition. Thoughts?

    (first few lines)

    boosted240-virtual-machine kali-arm-build-scripts # ./rpi.sh 2
    ./rpi.sh: line 54: debootstrap: command not found
    cp: cannot stat ‘/usr/bin/qemu-arm-static’: No such file or directory
    chroot: cannot change root directory to kali-armhf: No such file or directory
    ./rpi.sh: line 59: kali-armhf/etc/apt/sources.list: No such file or directory
    ./rpi.sh: line 65: kali-armhf/etc/hostname: No such file or directory
    ./rpi.sh: line 68: kali-armhf/etc/hosts: No such file or directory
    ./rpi.sh: line 77: kali-armhf/etc/network/interfaces: No such file or directory
    ./rpi.sh: line 85: kali-armhf/etc/resolv.conf: No such file or directory
    mount: mount point kali-armhf/proc does not exist
    mount: mount point kali-armhf/dev/ does not exist
    mount: mount point kali-armhf/dev/pts does not exist
    ./rpi.sh: line 97: kali-armhf/debconf.set: No such file or directory
    ./rpi.sh: line 102: kali-armhf/third-stage: No such file or directory
    chmod: cannot access ‘kali-armhf/third-stage’: No such file or directory
    chroot: cannot change root directory to kali-armhf: No such file or directory
    ./rpi.sh: line 134: kali-armhf/cleanup: No such file or directory
    chmod: cannot access ‘kali-armhf/cleanup’: No such file or directory
    chroot: cannot change root directory to kali-armhf: No such file or directory
    umount: kali-armhf/proc/sys/fs/binfmt_misc: not found
    umount: kali-armhf/dev/pts: not found
    umount: kali-armhf/dev/: not found
    umount: kali-armhf/proc: not found
    Creating image file for Raspberry Pi
    3000+0 records in
    3000+0 records out
    3145728000 bytes (3.1 GB) copied, 2.21663 s, 1.4 GB/s
    Warning: The resulting partition is not properly aligned for best performance.
    Warning: The resulting partition is not properly aligned for best performance.
    ./rpi.sh: line 162: kpartx: command not found
    mkfs.fat 3.0.26 (2014-03-07)
    /dev/mapper/p1: No such file or directory
    mke2fs 1.42.9 (4-Feb-2014)
    Could not stat /dev/mapper/p2 — No such file or directory

Leave a Reply