How to access your Pi remotely via VNC

In my previous post I talked about setting up a headless Raspberry Pi configuration -- the real purpose of using a Pi as a pentesting tool. The first step in making our Pi portable is the installation and activation of a VNC (Virtual Network Computing) connection.
I will be glad to answer any questions you might have after reading this guide.





Requirements

As always, verify that you have the necessary material:
  • Raspberry Pi 3 running Kali Linux (tutorial here)
  • Power adapter
  • HDMI cable
  • TV or monitor
  • Decent internet connection

Installing the VNC server on the Pi

There are many VNC softwares but we'll be using TightVNC because it's simple to configure and compatible with most devices. In a terminal window on your Pi, type apt-get install tightvncserver to download the software. Once completed, type tightvncserver to start the VNC service. You will be prompted to choose a password, note that it cannot exceed 8 characters. You will also be asked if you want to setup a view-only password: in our case it's not necessary so you can decline (type N and hit enter).

Configuring TightVNC server

In order to access our Pi remotely, the VNC connection must start upon boot. Navigate to the directory by typing cd /etc/init.d. We will then create a startup script using whichever text editor you like, for example Nano: nano /etc/init.d/vncboot. In the blank document that is created, insert the following script:

#!/bin/sh
### BEGIN INIT INFO
# Provides: vncboot
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start VNC Server at boot time
# Description: Start VNC Server at boot time.
### END INIT INFO

USER=root
HOME=/root

export USER HOME

case "$1" in
start)
echo "Starting VNC Server"
#Insert your favoured settings for a VNC session
/usr/bin/vncserver :0 -geometry 1280x800 -depth 16 -pixelformat rgb565
;;

stop)
echo "Stopping VNC Server"
/usr/bin/vncserver -kill :0
;;

*)
echo "Usage: /etc/init.d/vncboot {start|stop}"
exit 1
;;
esac

exit 0


Once you're done, save the document by hitting the Esc key and typing :wq!. After closing the document, we'll need to grant the script admin permissions. This is done by using the chmod command like so:
chmod 755 /etc/init.d/vncboot
Next, add the dependencies to it:
update-rc.d vncboot defaults

Downloading & installing the VNC client

You have the choice regarding what VNC client you want to use. In this guide we'll choose RealVNC because it's one of the few clients that work on Linux, Windows and Android. On your PC, download it from the official website and install it like any other program.


Connecting to the Pi

To connect to the Pi, we need its IP address. To find it, go back to the Pi, open a terminal window and display the current network configuration with the command ifconfig and write it down.

Finally, to connect to the Pi via your computer, open VNC Viewer. Go to File>New Connection. In the VNC Server field, type your Pi's IP address. Save the connection with the name of your choice and click OK to finalize the setup.
You can now double-click on the new connection to access your Pi remotely! If you have any questions, problems or suggestions, feel free to leave a comment below and I'll get back to you.


Stay tuned for my upcoming post where things should start to get interesting.

Comments

Popular posts from this blog

Pixie-Dust Wifi Attack: Theory & Practice

How to capture a WPA handshake

Getting started in scripting