Book Image

Penetration Testing with Raspberry Pi - Second Edition

By : Michael McPhee, Jason Beltrame
Book Image

Penetration Testing with Raspberry Pi - Second Edition

By: Michael McPhee, Jason Beltrame

Overview of this book

This book will show you how to utilize the latest credit card sized Raspberry Pi 3 and create a portable, low-cost hacking tool using Kali Linux 2. You’ll begin by installing and tuning Kali Linux 2 on Raspberry Pi 3 and then get started with penetration testing. You will be exposed to various network security scenarios such as wireless security, scanning network packets in order to detect any issues in the network, and capturing sensitive data. You will also learn how to plan and perform various attacks such as man-in-the-middle, password cracking, bypassing SSL encryption, compromising systems using various toolkits, and many more. Finally, you’ll see how to bypass security defenses and avoid detection, turn your Pi 3 into a honeypot, and develop a command and control system to manage a remotely-placed Raspberry Pi 3. By the end of this book you will be able to turn Raspberry Pi 3 into a hacking arsenal to leverage the most popular open source toolkit, Kali Linux 2.0.
Table of Contents (13 chapters)
Penetration Testing with Raspberry Pi - Second Edition
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface

Combining Kali Linux and the Raspberry Pi


We know that it's tempting to just dive on into the Kali Linux interface and start running some great security tools. But first, there are some important housekeeping items to take care of. These items are as follows:

  • Changing our password.

  • Updating Kali Linux.

  • Resizing the partition to use all the available space on that large microSD (32 GB in our case). This will dramatically reduce the chance of running into common issues found with using Kali Linux on Raspberry Pi.

First on our list is to change our password. Kali Linux ships with the same default credentials, so we'll want to make sure that no one can log into our box except us. How embarrassing would be it if we had our penetration testing box penetrated by another party. Think of the irony there! To start this process, we need to open up a terminal and enter the passwd command. We'll be asked to type the password in twice to make sure that it is correct:

The other very important thing to do is to update Kali as soon as we can. This will ensure that we have the latest and greatest versions of code and applications. The process for updating Kali is pretty straightforward. We'll simply type the following commands into the CLI.

The upgrade will install all the newest version of the packages installed. The dist-upgrade command will install this plus intelligently updates all the dependencies with the new versions of packages. The dist-upgrade command is certainly not required, but we definitely recommend it:

apt-get update
apt-get upgrade
apt-get dist-upgrade

After this, we reboot our Raspberry Pi 3, and when it comes back, we should have a fully updated operating system, ready for playing around with some pen-testing tools.

Next, we want to resize the partition to use all the available space on our 32GB microSD card. We will show two different ways of doing this. The first way will be via the CLI. The second will take advantage of gparted in GUI.

Starting with CLI, if we run the  df -h  command, the following figure shows we don't have a partition that is close to the size of our microSD card. It is currently only at 6.7G:

The process to expand this partition involves a couple of steps. The following steps will help us unlock the full usable size of our microSD card. It is important to have that extra space for log files, command outputs, or tcpdumps.

We need to make sure that we follow the steps very carefully, as we wouldn't want to erase our root partition. This process uses the  fdisk, parted and resize2fs commands. Here is the process that we used:

  1. Let's check enter the disk utility, where we can view where the partitions currently stand. Here, we will want to run the fdisk command to check our current partitions:

    fdisk /dev/mmcblk0
    

    This will get us into the fdisk utility so that we can plan our changes to the partition table.

  2. Now we'll obtain partition information. Once at the Command (m for help) prompt, we'll enter p. This will dump out the partition information for our microSD card:

  3. Now let's delete current partition. We'll exit from the fdisk utility by typing q. We now want to get into the parted utility and specify the microSD card we wish to modify. The device information was gleaned from the previous step. We can accomplish this by typing the following command:

    parted /dev/mmcblk0
    
  4. This will take us into the partition table utility. Once at the (parted) prompt, we will want to change the unit to chs, which is for cylinders, head, and sectors. This will allow us to get the correct numbers for the resize. To do this, let's type chs:

    (parted) unit chs
    
  5. Once we set the correct unit, we want to print out the partition information in the correct unit within parted. This will give us the correct sizes that will allow us to resize your partition. To do this, we'll just type print at the prompt:

    (parted) print
    
  6. Now, in this output, we are going to want to write down or remember the total size of the microSD card. This is found in the line that starts with Disk. In our example, it was the following:

    Disk /dev/mmcblk0:  3822,237,62
    
  7. Once we have the total size of the microSD in the chs unit, we can delete the second partition. Let's pay particular attention here, as we don't want to delete the root partition. At the prompt, we will want to type rm 2, where 2 is the partition number:

            (parted) rm 2
    
  8. We will be prompted with an error and asked to either Ignore or Cancel. Let's type i to ignore:

    Ignore/Cancel? i
    
  9. We have now removed the unneeded partition. We can confirm this by printing out the partition information again, and it will show that only one exists:

    (parted) print
    
  10. At this point, we can see that we only have that one partition and are ready to create the extended partition that uses all of the available space. The following figure is a screenshot of all that we talked about in steps 3-9:

  11. Now let's create the new partition. We will use parted again, but this time to create the partition. First, let's start the tool by entering the parted command. Once in parted, we can make the new larger partition. This is where those numbers we saw and recorded in the parted print command in the previous section come into play. At the prompt, we will want to use mkpart to make the partition, with the first number being one number higher than the End sector number on the first partition. The second number is the disk number size we saw in that same output. For our microSD card partition, we ran the following command:

    (parted) mkpart primary 7,199,9 3822,237,62
    
  12. Once that command has been entered, we will get a warning; we can hit i to ignore it. After that, we want to verify that our partition has been created. We can use the print command under parted to accomplish this. We should see the second entry, which shows the correct usable space for our microSD card. We can now quit out of parted. The following screenshot shows steps 11 and 12 of our example:

  13. Let's expand the filesystem. Now that we have all this space, we want to make sure that the filesystem can take advantage of it. We can accomplish this by using the resize2fs command. We will run this against that newly formed partition. The following command results in the following screenshot:

    resize2fs /dev/mmcblk0p2
    

  14. Finally, we'll need to perform some verification. We can now verify that everything worked as planned if you run that same df -h command we did initially. We should see that the size closely matches our microSD card's advertised usable space:

Now that we've seen the CLI commands to increase that partition size, let's look at another way of using the GUI interface within Kali Linux. These steps will walk through the process:

  1. The tool we use is gparted, which is installed using the following command:

    apt-get install gparted
    

  2. Once we have installed it, we can launch it via command line (via X over SSH) using gparted. Once the GUI has started, we can click on the Resize/Move button:

  3. From here, we will click on the edge of the fat16 partition and drag it over to include all of the unallocated space:

  4. Now we will click on Apply and verify that we indeed want this operation:

  5. It will take some time, but it will show us the progress of our repartitioning:

  6. Once it's completed, we can now see that the fat16 partition that Kali Linux resides in now has direct access to the entire SD card:

  7. While it is useful to consume the entire physical drive with this partition, we may have situations that require multiple partitions to be used. We can certainly adjust our approach with gparted to accomplish this.