joubin jabbari
  • home
  • blog
  • work
  • reading
  • photography
  • contact
  • resume

Building Kali for Pi 2

The folks at Offensive Security have provided the source to Kali. We just need to tweak it a little to get where we need to.

Took me all of Saturday and most of Sunday to create my image. It was first time cross-compiling for arm. Therefore, I incorrectly assumed that I need to do it in an arm enviorment. After failing to create the image on a default Rasbian install because my SD wasnt big enought, I created emulated rasbian using Qemu which was slow.

However, to test my script that you see below, I did re-create my image using just Backtrack (64 bit) x86 inside of a virtual machine!

Pre-req:

  • A linux system (can be a virtual machine if you must). I used a regular Kali installed in a VM. Please give it more than 1 core and the default 512M of ram if you have the resource.
  • Make sure that you can access the internet from it.
  • Install git (already there on Kali)

Don't want to do this?

Here is the image you can download and just follow the instructions from the "Create a bootable sd from the image". BUT.....

You should NEVER trust operating systems (or any software) from unidentified sources; Even me. I can promise here that I did nothing malicious to the OS. But you don't know me and you shouldn't trust me.

With that said, if it's just a toy and/or you trust me, go ahead and use it.

User: root

Pass: toor

Note: I am writing this as I go.

Offensive Security provides a workflow.

Original Workflow

Code:

mkdir ~/arm-stuff
cd ~/arm-stuff
git clone https://github.com/offensive-security/gcc-arm-linux-gnueabihf-4.7
export PATH=${PATH}:/root/arm-stuff/gcc-arm-linux-gnueabihf-4.7/bin
git clone https://github.com/offensive-security/kali-arm-build-scripts
cd ~/arm-stuff/kali-arm-build-scripts
./build-deps.sh
./chromebook-arm-samsung.sh 1.0

So, let's change it a bit.

Create the image

As root execute either option 1 or option 2

1:

Code:

joubin@kali$: mkdir ~/arm-pi2
joubin@kali$: cd ~/arm-pi2
joubin@kali$: git clone https://github.com/offensive-security/gcc-arm-linux-gnueabihf-4.7
joubin@kali$: git clone https://github.com/offensive-security/kali-arm-build-scripts
joubin@kali$: export PATH=${PATH}:~/arm-pi2/gcc-arm-linux-gnueabihf-4.7/bin
joubin@kali$: cd ~/arm-pi2/kali-arm-build-scripts
joubin@kali$: curl https://gist.githubusercontent.com/joubin/e454661f82f5f749b2f8/raw/dbf27d37db449d1459f0cea984cb654769597a3c/rpi.sh > rpi.sh
joubin@kali$: https://gist.githubusercontent.com/joubin/cc7adf5196f8c6b2661e/raw/01db3e60154ce483c00c71c360c979cdc8e98f42/pi2_kernel.config > pi2_kernel.config
joubin@kali$: ./build-deps.sh 
joubin@kali$: ./rpi.sh 1.2.3

2: which does exactly everything from #1 :D

Code:

curl https://gist.githubusercontent.com/joubin/156362976b51ee862f9b/raw/d708d9b33dccd97812bf02094ed8edeaac09449f/work.sh | bash

You will have to wait a while. The output should look something like this. If you have a few errors in there, don't panic and just let it finish.

Source: Found my config file here

Create a bootable sd from the image

First, locate the image

Code:

cd rpi-1.2.3/

Then unpack the image

Code:

unxz rpi-1.2.3.img.xz

Then create the bootable media by replacing /dev/sda with whatever your OS has your SD card registered as.

Code:

pv < rpi-1.2.3.img > /dev/sda

EDIT

All that is required is 4GB SD card for all of the steps above.

After booting the Kali image that was built, I found out that it didn't have many of the tools that I know and love -- with that said, I will update this post when I can buy a larger SD card.

More edit

I was able to buy another flash drive and here is how to make Kali more useful. From this point on all commands are being executed from the Pi itself.

Faster SD card:

Speed of the card really matters and that's why I bought this.

Here is the output of the pv command using the original SD:

Code:

root@Data:/Users/joubin/Downloads$ pv < 2015-02-16-raspbian-wheezy.img > !$
pv < 2015-02-16-raspbian-wheezy.img > /dev/disk5
3.05GiB 1:16:34 [ 696KiB/s] [==========================================>] 100% 

and here is the output using my new U3 SD:

Code:

root@Data:/Users/joubin/Desktop$ pv < kali-1.2.3-rpi.img > /dev/disk5
2.93GiB 0:21:52 [2.29MiB/s] [==========================================>] 100% 

Resize the SD card:

Upon my first login I realized I didn't have as much room as I should. The SD card I'm using should be 16GB not 2.8 GB.

Code:

root@kali:~# df -h
Filesystem      Size  Used Avail Use% Mounted on
rootfs          2.8G  1.4G  1.3G  53% /
/dev/root       2.8G  1.4G  1.3G  53% /
devtmpfs        460M     0  460M   0% /dev
tmpfs            93M  476K   93M   1% /run
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           186M     0  186M   0% /run/shm

Code:

root@kali:~# /scripts/rpi-wiggle.sh

After the Pi rebooted, I ran the df command again and was greeted with this:

Code:

root@kali:~# df -h
Filesystem      Size  Used Avail Use% Mounted on
rootfs           15G  1.4G   13G  11% /
/dev/root        15G  1.4G   13G  11% /
devtmpfs        460M     0  460M   0% /dev
tmpfs            93M  472K   93M   1% /run
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           186M     0  186M   0% /run/shm

Some updates

Before we do anything, I want to make sure I have the latest repos.

Code:

root@kali:~# apt-get update

and we want to make sure we are working with the latest toolset:

Code:

root@kali:~# apt-get upgrade

Confession

You know how I promised you a Kali install? Well I lied a little. The truth is, it would take a really long time to cross compile everything Kali needs. So the image we have been working with so far is a basic Kali install.

Now we need "everything" else.

Side Note: Not EVERYTHING has been compiled for ARM and not everything works for ARM.

Code:

root@kali:~# apt-get install kali-linux-full

which install 1162 new packages o__0

Code:

0 upgraded, 1162 newly installed, 1 to remove and 0 not upgraded.

Coffee Time

Depending on your internet speed and your SD card, this could take a while.

So after a 1.5 hours for me, I was done with the updates and Code:

real    90m13.652s
user    31m46.320s
sys 9m44.210s

Another Image

Same things apply. You really shouldn't trust anything from people you don't know. But if you don't care [here]() is the full install image. You will need at least a 16GB SD card. I had to install mysql and some other utilities and there passwords have been set to toor for the user root.

You will need to unzip this image. The image is dd of my SD card including all of its unassociated bytes. You must redo the "Resize the SD card" step once you are booted into it.


February 23 2015

Joubin Jabbari | Github | Twitter