So the build you made wasn’t ideal. Fortunately you can change the build. For this example, let’s assume that you forgot to install some packages, such as net-tools, dnsmasq andmlocate. Rather than reinstalling and re-imaging the device, chroot into the RPi3 SD card from your Kali machine and make the required changes.
Since this is a walkthrough, and not covered in the book, go ahead and “Show Answer” and we’ll walk through.
You’ll begin with the SD card from a previous exercise. In this example, we are using the image from the previous exercise (Exercise 4) — our custom build. First, install
qemu cross compiling tools and related tools into Kali:
|
apt-get install qemu qemu-user qemu-user-static |
Let’s make a /mnt/sd directory to keep our directories we’re working on organized:
Pick up your /dev/sd drive assignment by inserting the Pi’s SD card (ours is /dev/sdc). Your USB-SD adapter makes a difference. We are going to pick up all the physical drive mounts in one shot.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
root@kali:~# mount /dev/sdc2 /mnt/sd/ root@kali:~# ls -l /mnt/sd total 88 drwxr-xr-x 2 root root 4096 Aug 5 11:36 bin drwxr-xr-x 2 root root 4096 Jul 18 03:08 boot drwxr-xr-x 4 root root 4096 Aug 5 11:15 dev drwxr-xr-x 71 root root 4096 Mar 1 16:43 etc drwxr-xr-x 2 root root 4096 Jul 18 03:08 home drwxr-xr-x 13 root root 4096 Aug 5 12:11 lib drwx------ 2 root root 16384 Aug 5 11:39 lost+found drwxr-xr-x 2 root root 4096 Aug 5 11:15 media drwxr-xr-x 2 root root 4096 Aug 5 11:15 mnt drwxr-xr-x 2 root root 4096 Aug 5 11:15 opt drwxr-xr-x 2 root root 4096 Jul 18 03:08 proc drwx------ 2 root root 4096 Mar 1 16:43 root drwxr-xr-x 4 root root 4096 Aug 5 11:15 run drwxr-xr-x 2 root root 4096 Aug 5 11:36 sbin drwxr-xr-x 2 root root 4096 Aug 5 11:15 srv drwxr-xr-x 2 root root 4096 Jul 18 03:08 sys drwxrwxrwt 7 root root 4096 Mar 1 18:40 tmp drwxr-xr-x 10 root root 4096 Aug 5 11:15 usr drwxr-xr-x 11 root root 4096 Aug 5 11:15 var |
Did you notice how all the Raspberry Pi’s SD card directories are now mapped on your system under /mnt/sd?
Mount up all ‘special filesystems’ under /mnt/sd. Notice that we will be overriding mount options from /etc/fstab on some that are already mapped with the -o option:
|
mount -t proc none /mnt/sd/proc mount -t sysfs none /mnt/sd/sys mount -o bind /dev /mnt/sd/dev mount -o bind /dev/pts /mnt/sd/dev/pts |
Let’s pull the emu cross-compiling tools over. We need these to compile the ARM stuff since our target is ARM!
|
cp /usr/bin/qemu-arm-static /mnt/sd/usr/bin |
Time to enter a chroot! Once inside the chroot, all commends we execute will assume that /mnt/sd is our root filesystem. It’s a pretty cool trick. Note that we set LAN=C to suppress locale warnings in your chroot:
Let’s make some changes to the Pi’s filesystem. This is the cool part. All this is happening on your Pi’s filesystem!
|
# apt-get update # apt-get install mlocate # apt-get install net-tools # apt-get install hostapd dnsmasq |
Continue configuration as necessary. Once done, exit the chroot and unmount the SDcard.
We need to unmount all the directories we mounted:
|
umount /mnt/sd/dev/pts umount /mnt/sd/dev/ umount /mnt/sd/sys umount /mnt/sd/proc umount /mnt/sd |
Lastly, insert the SD card into the Pi, and launch!