Skip to content

Kali RPI4B

reubenajohnston edited this page Apr 14, 2020 · 53 revisions

Programming instructions

  1. Download and copy this latest kali rpi image to the VM and cd into the directory with it
  2. Confirm the file is in your current directory
    
     $ ls kali-linux-2020.1-rpi3-nexmon-64.img.xz
     
  3. Extract the image $ unxz kali-linux-2020.1-rpi3-nexmon-64.img.xz
  4. Verify it extracted
    
     $ ls kali-linux-2020.1-rpi3-nexmon-64.img
     
  5. Plug in your sd-card into the USB reader and attach it to the VM
  6. Identify the block device for your sd-card (SIZE should be close to your SD card size, my sd-card is 64GB and was /dev/sdc)
    
     $ lsblk -p
     NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
     /dev/sda      8:0    0    50G  0 disk 
     ├─/dev/sda1   8:1    0    42G  0 part /
     ├─/dev/sda2   8:2    0     1K  0 part 
     └─/dev/sda5   8:5    0     8G  0 part [SWAP]
     /dev/sdc      8:32   1  59.5G  0 disk 
     ├─/dev/sdc1   8:33   1 122.1M  0 part 
     └─/dev/sdc2   8:34   1  58.6G  0 part 
     /dev/sdd      8:48   1  57.8G  0 disk 
     └─/dev/sdd1   8:49   1  57.8G  0 part /media/kali/TRAVELER1
     /dev/sr0     11:0    1  1024M  0 rom  
     
  7. If there are existing logical partitions on your device, delete them using gparted gui $ sudo gparted /dev/sdc
  8. Write the image to the sd-card using dd
    
     $ sudo dd if=kali-linux-2020.1-rpi3-nexmon-64.img of=/dev/sdc status=progress
     6995849728 bytes (7.0 GB, 6.5 GiB) copied, 1446 s, 4.8 MB/s
     13671874+0 records in
     13671874+0 records out
     6999999488 bytes (7.0 GB, 6.5 GiB) copied, 1449.97 s, 4.8 MB/s
     
  9. Mount the first logical partition to edit cmdline.txt and config.txt $ sudo mount /dev/sdc1 /mnt
  10. Edit /mnt/cmdline.txt to contain the following dwc_otg.fiq_fix_enable=2 console=ttyS0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait rootflags=noload net.ifnames=0
  11. Edit /mnt/config.txt and add the following line to the end of the file enable_uart=1
  12. Unmount the first logical partition $ sudo umount /mnt
  13. Eject the sd-card before you remove it $ sudo eject /dev/sdc
  14. Attach the FTDI-USB-Serial cable to your RPI4's UART0 and attach the USB to your PC (see https://github.com/jhu-information-security-institute/NwSec/wiki/RPI4B for wiring); attach the device to your VM and it should be /dev/ttyUSB0
  15. Open minicom on /dev/ttyUSB0; Settings should be 115200,8N1,No,No $ sudo minicom -D /dev/ttyUSB0 Kali Linux 2020 1-2020-02-24-15-33-46
  16. Insert the sd-card into the RPI4
  17. Power on the RPI4
  18. Wait for the RPI4 to boot and login with root, toor
  19. Setup networking (see the section below)
  20. Run an update and upgrade sequence
    
     $ sudo apt-get update
     $ sudo apt-get upgrade -y
     
  21. Install openssh-server $ sudo apt-get install openssh-server
  22. Start the server $ systemctl start ssh.service
  23. Get the ip address of your rpi $ ifconfig wlan0
  24. From your Kali VM, SSH into the RPI4 using its ip address $ ssh root@ipaddressofpihere

Network setup for WPA2 with pre-shared key (PSK) authentication

E.g., for a home wifi network or when using a wireless hotspot from your smartphone

  1. Generate a skeleton wpa_supplicant.conf for your SSID and WPA2 pre-shared key (PSK) $ wpa_passphrase ssidhere pskhere > /etc/wpa_supplicant/wpa_supplicant.conf
  2. Edit /etc/wpa_supplicant/wpa_supplicant.conf and add lines for ctrl_interface, update_config, country, key_mgmt, proto, pairwise, and group; it should look similar to the following
    
     ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
     update_config=1
     country=US
     
     network={
         ssid="ssidhere"
         #psk="pskhere"
         psk=FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF		
         key_mgmt=WPA-PSK
     }
     
  3. Update /etc/network/interfaces by adding these lines
    
     auto wlan0
     iface wlan0 inet dhcp
     
  4. Create a nwsetup.sh script with the following lines
    
     pkill dhclient
     pkill wpa_supplicant
     wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf
     ip link set dev wlan0 down
     ip link set dev wlan0 up
     dhclient -v wlan0
     
  5. Make nwsetup.sh executable $ chmod +x nwsetup.sh
  6. Run it $ ./nwsetup.sh

Network setup for MSSI-LAB

  1. Instructions are identical to above PSK authentication above, but have a different wpa_supplicant.conf (as described next)
  2. Create /etc/wpa_supplicant/wpa_supplicant.conf similar to the following (replace cooluser and supersecret with your MSSI-LAB credentials)
    
     ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
     update_config=1
     country=US
     
     network={
         ssid="MSSI-LAB"
         identity="cooluser"
         password="supersecret"
         key_mgmt=WPA-EAP
         eap=PEAP
         phase1="peapver=0"
         phase2="auth=MSCHAPV2"
     }
     

sshd server setup

  1. Install the dependencies # apt-get install openssh-server
  2. Start the sshd service # systemctl start ssh.socket Once you have sshd up, identify the ip address for your RPI4B and exit out of minicom. Then, ssh in to the RPI4B (as this is better than using minicom). Also, once sshd is up, you can use scp to copy files back and forth between your VM and the RPI4B. E.g., $ scp root@192.168.1.1:~/hello . or $ scp hello root@192.168.1.1:~/.
  3. To copy your keys over, use: $ ssh-copy-id -i path_to_id_rsa.pub username@ipaddress_of_rpi

Tightvncserver setup

  1. Install the dependencies # apt-get install tightvncserver
  2. Create .vnc/xstartup with the following contents:
    
     #!/bin/sh
     set -xv
     
     xrdb $HOME/.Xresources
     xsetroot -solid grey
     # Fix to make GNOME work
     export XKL_XMODMAP_DISABLE=1
     /etc/X11/Xsession /usr/bin/startxfce4
     vncconfig -iconic &
     
  3. Create vncstart.sh startup script with the following contents:
    
     vncserver :1
     
  4. Start it using vncstart.sh (on first run it will ask you to set the password)
  5. Connect to the server using a vncclient running on your Kali VM (need your ip address of the RPI4B and port should be 5901)

Useful websites

Clone this wiki locally