The world of cybersecurity is constantly evolving, and with it, the tools and technologies used by professionals in the field. The Raspberry Pi 5, with its enhanced capabilities, opens up new possibilities. This blog delves into transforming your Raspberry Pi 5 into a versatile cybersecurity gadget running Kali Linux, a top choice for cybersecurity experts.
What is Kali Linux?
Kali Linux is a Debian-based Linux distribution designed for digital forensics and penetration testing. It comes pre-installed with an array of tools for hacking and security testing.
Key Features:
- Comprehensive collection of security tools
- Regular updates with the latest exploits
- User-friendly interface for beginners and experts alike
Why Raspberry Pi 5 with Kali Linux?
The Raspberry Pi 5 is the latest iteration in the Raspberry Pi series, offering superior processing power, increased memory, and enhanced connectivity options. Using it with Kali Linux is a great alternative to virtualisation as we have direct access to hardware and it is also easy to carry with you anywhere.
Using a Raspberry Pi with Kali Linux in gadget mode is particularly useful for cybersecurity professionals and enthusiasts. It allows for the creation of versatile USB devices such as network adapters, HID devices, or storage devices, which can be employed in various penetration testing scenarios. The combination of Kali Linux’s extensive suite of security tools and the Raspberry Pi’s compact, portable, and cost-effective hardware makes it an excellent platform for on-the-go security assessments, learning, and experimentation. Additionally, the low power consumption and strong community support further enhance its practicality and accessibility for cybersecurity applications.
Setting Up Kali Linux on Raspberry Pi 5
You can find the official guide for installing Kali on Raspberry Pi 5 here. For a quicker alternative, I’ve created a brief guide below.
Prerequisites
- Raspberry Pi 5
- MicroSD Card (16GB or larger recommended)
- Access to a PC or Mac for initial setup
Download Kali for Raspberry Pi 5
There is a specific distribution of Kali for Raspberry Pi 5 and it is on their download page (https://www.kali.org/get-kali/), under the ARM platform section. From the platform page, choose the ARM architecture.
Then download the specific version for Raspberry Pi 5.
Create a bootable microSD
The easiest way to create a bootable microSD card is to use an app that flashes operating systems. I usually use Balena Etcher as it can be used on Mac, Windows or Linux. Just open the downloaded file, choose the microSD drive and Flash it.
Configuring Raspberry Pi 5 as a USB Gadget
This section describes how to configure Raspbery Pi in gadget mode. Before starting the configuration, make sure your system is up to date.
sudo apt update && sudo apt -y upgrade
Kernel
First we need to change the kernel configuration by following the 2 steps below.
- Add
dtoverlay=dwc2
to the end of/boot/config.txt
file - Add
modules-load=dwc2,g_ether
to the end of/boot/cmdline.txt
Reboot the system.
Network
Configure the USB interface by creating the file /etc/network/interfaces.d/usb0
with the configuration below.
auto usb0
iface usb0 inet static
address 10.55.0.1
Note that above we are specifying the static address for the Raspberry Pi. You can change to whatever IP address you like.
DHCP Server
Now we are going to configure dnsmasq
as our DHCP server for the USB network. Install dnsmasq with the command below.
sudo apt install dnsmasq
Edit the /etc/dnsmasq.conf
and use the following configuration.
dhcp-authoritative
dhcp-rapid-commit
no-ping
interface=usb0
dhcp-range=10.55.0.2,10.55.0.6,255.255.255.248,1h
dhcp-option=3
leasefile-ro
The configuration above set the range of IPs that will be automatically assigned to devices connected via the USB interface. If you changed the static IP in the USB interface configuration, make sure the dhcp configuration is aligned with the respective change.
After installed and configured, restart and enable the dnsmasq service to ensure the it uses the latest configuration and automatically starts during system initiation.
sudo systemctl enable dnsmasq
sudo systemctl restart dnsmasq
Remote Access with VNC
Now we need to install a remote access application to share the screen from Raspberry Pi. This guide uses TigerVNC, but you can use any other that you feel more comfortable with.
Firstly we need to install all the required packages.
sudo apt install tigervnc-standalone-server tigervnc-xorg-extension tigervnc-viewer
Change the file /home/kali/.vnc/xstartup
to look like the configuration below in order to enable copy and paste.
#!/bin/sh
xrdb $HOME/.Xresources
xsetroot -solid grey
# Enable copy and paste
autocutsel -fork
xhost + kali
# Fix to make GNOME work
export XKL_XMODMAP_DISABLE=1
/etc/X11/Xsession
Create the file /etc/systemd/system/vncserver.service
and include the following:
[Unit]
Description=TigerVNC server
After=syslog.target network.target
[Service]
Type=forking
User=kali
PAMName=login
PIDFile=/root/.vnc/%H:1.pid
ExecStartPre=-/usr/bin/vncserver -kill :1 > /dev/null 2>&1
ExecStart=/usr/bin/vncserver -localhost
ExecStop=/usr/bin/vncserver -kill :1
[Install]
WantedBy=multi-user.target
Start the service and enable it to start automatically after boot:
sudo systemctl start vncserver
sudo systemctl enable vncserver
Now you just need to plug your laptop or iPad via USB and access the remote screen from your Raspberry Pi. I’m currently using Jump Desktop on my Mac and iPad.