From charlesreid1

 
(24 intermediate revisions by the same user not shown)
Line 1: Line 1:
This is a guide to connecting to a headless installation of Kali Linux on a Raspberry Pi: [[Kali Raspberry Pi]]
[[Image:KaliPi.jpg|400px]]


For general instructions on connecting to a headless Raspberry Pi, visit this page: [[RaspberryPi/Headless]]
This is a guide to connecting to a headless installation of Kali Linux on a Raspberry Pi. General info about running Kali on the Pi here: [[Kali Raspberry Pi]]


For info/pages on Kali, visit this page: [[Kali]]
More info about all-things Kali Linux: [[Kali]]
 
=A Note on Headless=
 
Why did I write this article? Two reasons:
 
{|class="wikitable"
!Reason Number One
!Reason Number Two
|-
|[[Image:Adapter1.jpg|300px]]
|[[Image:Adapter2.jpg|200px]]
|}
 
I simply didn't have the luxury (or the hardware and adapters) to get this thing working. I had to get this headless Kali Linux Raspberry Pi working, without a screen, without a keyboard: literally, a black box.
 
The perfect puzzle.


=Connecting to Kali Pi=
=Connecting to Kali Pi=
Line 13: Line 29:
[[Image:LaptopKaliPi.jpg|700px]]
[[Image:LaptopKaliPi.jpg|700px]]


==Double Check your Pi Version==
==Download Correct Image Version==


Although it's best to do this before you wait 30 minutes while your computer flashes an image to an SD card, you should probably check to make sure your Kali Pi image matches your Raspberry Pi version. Version B+ has two USB ports, and Version 2 has four USB ports.
Check to make sure your Kali Pi image matches your Raspberry Pi version. Version B+ has two USB ports, and Version 2 has four USB ports. You can download your Raspberry Pi Kali image from the Offensive Security webpage: https://www.offensive-security.com/kali-linux-arm-images/
 
There are 3 Raspberry Pi images listed on that page. I downloaded the "Raspberry Pi" image kali-2.0.1-rpi.img and this worked on the Raspberry Pi B (older design, 2 USB ports). If you have a B+ (newer design, 4 USB ports), get the "Raspberry Pi 2" image.
 
Once you've downloaded the image. it will be named something like kali-2.0.1-rpi.img.xz. The xz extension means it is a compressed file, so decompress it with `tar xf kali-2.0.1-rpi.img.xf`.
 
You can use the resulting image file to flash the SD card that your Raspberry Pi will use.
 
==Setting a Static IP==
 
You'll want to set a static IP address for the Raspbery Pi before you boot. Assuming we're connecting the Pi directly to the laptop with a crossover cable, we'll use an IP address in the range <code>169.254.X.Y</code>. The IP prefix 169.254, like the IP prefixes 192.168 or 10.X, is a special IP address for special networks. In this case, 169.254 is the "link-local address" - an IP address range for devices connected directly to the computer with a crossover cable. (Original source of this IP address was [https://pihw.wordpress.com/guides/direct-network-connection/in-a-nut-shell-direct-network-connection/ here], but a search for 169.254 will point you toward the "link-local address" Wikipedia page [https://en.wikipedia.org/wiki/Link-local_address here]).
 
My favorite IP address in this space happens to be <code>169.254.113.200</code>.
 
You will add <code>ip=169.254.113.200</code> to the end of the boot line, which is on the SD card's boot partition in <code>cmdline.txt</code>. When you're done, it should look something like this:
 
<pre>
dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 elevator=deadline root=/dev/mmcblk0p2 rootfstype=ext4 rootwait ip=169.254.113.200
</pre>
 
For more details on this procedure, see [[RaspberryPi/Headless]]
 
For more details on how the SD card works, see [[Kali Raspberry Pi/Installing#How the Kali Linux Startup SD Card Works]]


==Enabling SSH==
==Enabling SSH==


Now we come to a question: is SSH enabled by default on Kali Linux builds for the Raspberry Pi?
I detailed a problem connecting to the Pi via SSH, which took me a long time to resolve. The issue was that I was powering the Pi through a mini USB hooked up to a computer, which was not providing the Pi with enough power to run the ethernet port 100% of the time (or most of the time). Plugging it into the wall socket resolved the issue with SSH connectivity.
 
The details are here: [[Kali Raspberry Pi/Headless SSH Problem]]
 
In the process, I discovered a few things.
 
===By The Way: Modifying Headless Raspberry Pi Boot Sequence===
 
Part of my struggles in debugging the issue above led me to the <code>rc.d</code> and <code>init.d</code>  on the SD card, and modifying the services that start on boot on the headless Raspberry Pi.
 
Here's how to add and modify startup services and configurations on the Pi:
 
First load up the SD card and mount it (as described at [[Kali_Raspberry_Pi/Installing#How_the_Kali_Linux_Startup_SD_Card_Works]]).
 
Now you can modify files in the Linux partition, to change what starts up at different runtime levels. Debian Raspberry Pis start in runtime level 2, so anything you want to start up should go in <code>etc/rc2.d</code>.
 
Actually, what you should do is, put a service script in <code>etc/init.d/myservice</code>, make it executable, then create a symbolic link in <code>etc/rc2.d</code>.
 
More details here: http://raspberrywebserver.com/serveradmin/run-a-script-on-start-up.html
 
===By The Way: Modifying Configuration Files on the Raspberry Pi===
 
Note that the above handy trick, editing the Linux partition on the SD card, can also be used to modify configuration files for programs. Want SSH to listen on port 8080? You can edit the <code>etc/ssh/ssh_config</code> file to change the SSH configuration. Want to edit the crontab file? Go for it.
 
YOU CAN DO... ANYTHING... YOU... WANT!!!
 
===Debugging Headless Raspberry Pi Problems with Logs===
 
I had to waste a lot of time and bang my head in figuring out this SSH problem. But in the process I discovered that (duh!) the headless Raspberry Pi logs everything that's happening. You can modify the startup services or configuration files of the Raspberry Pi, set various logging levels for various programs, boot the headless Raspberry Pi, try and do whatever you're trying to do, and if it doesn't work, you can mount the SD card on your laptop and inspect the log files.
 
'''NOTE: This requires you to be able to mount the Raspberry Pi's ext4 filesystem in Mac.'''
 
<pre>
$ cd /Volumes/NO\ NAME/
$ tail var/log/syslog
Jan  1 01:03:07 kali dhclient: No DHCPOFFERS received.
Jan  1 01:03:07 kali dhclient: No working leases in persistent database - sleeping.
Jan  1 01:06:58 kali dhclient: DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 8
Jan  1 01:07:06 kali dhclient: DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 14
Jan  1 01:07:20 kali dhclient: DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 20
Jan  1 01:07:40 kali dhclient: DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 10
Jan  1 01:07:50 kali dhclient: DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 9
</pre>
 
==Good To Go==
 
With these and the many other hints, tricks, and tips available online, I'm sure you'll be able to find your way <code>$HOME</code> on the headless Kali Linux Raspberry Pi.


Some say yes, some say no. I say, sort of.


In my experience, the Kali Linux Raspberry Pi image '''will''' start an SSH service, and it '''will''' listen on port 22, but you have to wait a while, and give it multiple tries. If at first your connection is refused, wait a little while, and try again.


See [[Kali Raspberry Pi/Headless]]


[[Category:Kali]]
{{KaliFlag}}
[[Category:Raspberry Pi]]
{{PiFlag}}

Latest revision as of 00:12, 23 January 2016

KaliPi.jpg

This is a guide to connecting to a headless installation of Kali Linux on a Raspberry Pi. General info about running Kali on the Pi here: Kali Raspberry Pi

More info about all-things Kali Linux: Kali

A Note on Headless

Why did I write this article? Two reasons:

Reason Number One Reason Number Two
Adapter1.jpg Adapter2.jpg

I simply didn't have the luxury (or the hardware and adapters) to get this thing working. I had to get this headless Kali Linux Raspberry Pi working, without a screen, without a keyboard: literally, a black box.

The perfect puzzle.

Connecting to Kali Pi

Once you've got Kali on the Raspberry Pi, now what? Well, it's pretty easy: once you boot up the Raspberry Pi, it will have a static IP address. The one we picked will let us SSH into the Pi if we have a network cable plugged into our laptop.

That's right: one end of the network cable into the laptop, the other end into the Pi:

LaptopKaliPi.jpg

Download Correct Image Version

Check to make sure your Kali Pi image matches your Raspberry Pi version. Version B+ has two USB ports, and Version 2 has four USB ports. You can download your Raspberry Pi Kali image from the Offensive Security webpage: https://www.offensive-security.com/kali-linux-arm-images/

There are 3 Raspberry Pi images listed on that page. I downloaded the "Raspberry Pi" image kali-2.0.1-rpi.img and this worked on the Raspberry Pi B (older design, 2 USB ports). If you have a B+ (newer design, 4 USB ports), get the "Raspberry Pi 2" image.

Once you've downloaded the image. it will be named something like kali-2.0.1-rpi.img.xz. The xz extension means it is a compressed file, so decompress it with `tar xf kali-2.0.1-rpi.img.xf`.

You can use the resulting image file to flash the SD card that your Raspberry Pi will use.

Setting a Static IP

You'll want to set a static IP address for the Raspbery Pi before you boot. Assuming we're connecting the Pi directly to the laptop with a crossover cable, we'll use an IP address in the range 169.254.X.Y. The IP prefix 169.254, like the IP prefixes 192.168 or 10.X, is a special IP address for special networks. In this case, 169.254 is the "link-local address" - an IP address range for devices connected directly to the computer with a crossover cable. (Original source of this IP address was here, but a search for 169.254 will point you toward the "link-local address" Wikipedia page here).

My favorite IP address in this space happens to be 169.254.113.200.

You will add ip=169.254.113.200 to the end of the boot line, which is on the SD card's boot partition in cmdline.txt. When you're done, it should look something like this:

dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 elevator=deadline root=/dev/mmcblk0p2 rootfstype=ext4 rootwait ip=169.254.113.200

For more details on this procedure, see RaspberryPi/Headless

For more details on how the SD card works, see Kali Raspberry Pi/Installing#How the Kali Linux Startup SD Card Works

Enabling SSH

I detailed a problem connecting to the Pi via SSH, which took me a long time to resolve. The issue was that I was powering the Pi through a mini USB hooked up to a computer, which was not providing the Pi with enough power to run the ethernet port 100% of the time (or most of the time). Plugging it into the wall socket resolved the issue with SSH connectivity.

The details are here: Kali Raspberry Pi/Headless SSH Problem

In the process, I discovered a few things.

By The Way: Modifying Headless Raspberry Pi Boot Sequence

Part of my struggles in debugging the issue above led me to the rc.d and init.d on the SD card, and modifying the services that start on boot on the headless Raspberry Pi.

Here's how to add and modify startup services and configurations on the Pi:

First load up the SD card and mount it (as described at Kali_Raspberry_Pi/Installing#How_the_Kali_Linux_Startup_SD_Card_Works).

Now you can modify files in the Linux partition, to change what starts up at different runtime levels. Debian Raspberry Pis start in runtime level 2, so anything you want to start up should go in etc/rc2.d.

Actually, what you should do is, put a service script in etc/init.d/myservice, make it executable, then create a symbolic link in etc/rc2.d.

More details here: http://raspberrywebserver.com/serveradmin/run-a-script-on-start-up.html

By The Way: Modifying Configuration Files on the Raspberry Pi

Note that the above handy trick, editing the Linux partition on the SD card, can also be used to modify configuration files for programs. Want SSH to listen on port 8080? You can edit the etc/ssh/ssh_config file to change the SSH configuration. Want to edit the crontab file? Go for it.

YOU CAN DO... ANYTHING... YOU... WANT!!!

Debugging Headless Raspberry Pi Problems with Logs

I had to waste a lot of time and bang my head in figuring out this SSH problem. But in the process I discovered that (duh!) the headless Raspberry Pi logs everything that's happening. You can modify the startup services or configuration files of the Raspberry Pi, set various logging levels for various programs, boot the headless Raspberry Pi, try and do whatever you're trying to do, and if it doesn't work, you can mount the SD card on your laptop and inspect the log files.

NOTE: This requires you to be able to mount the Raspberry Pi's ext4 filesystem in Mac.

$ cd /Volumes/NO\ NAME/
$ tail var/log/syslog
Jan  1 01:03:07 kali dhclient: No DHCPOFFERS received.
Jan  1 01:03:07 kali dhclient: No working leases in persistent database - sleeping.
Jan  1 01:06:58 kali dhclient: DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 8
Jan  1 01:07:06 kali dhclient: DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 14
Jan  1 01:07:20 kali dhclient: DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 20
Jan  1 01:07:40 kali dhclient: DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 10
Jan  1 01:07:50 kali dhclient: DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 9

Good To Go

With these and the many other hints, tricks, and tips available online, I'm sure you'll be able to find your way $HOME on the headless Kali Linux Raspberry Pi.