Saturday, June 03, 2017

HOWTO : Apache Guacamole Remote Desktop Gateway On Ubuntu 16.04 LTS

Apache Guacamole is a HTML5 remote desktop gateway. It supports VNC, RDP and SSH protocols. You can access your remote desktop or server by using standard browser. You are required a dedicate computer or virtual machine to setup the Guacamole server. This guide will use database authentication for the operation.

Step 1 :

Install Ubuntu Server 16.04.2 LTS as usual. It is recommended to install OpenSSH also.

sudo apt-get -y install libcairo2-dev libjpeg-turbo8-dev libpng12-dev libossp-uuid-dev libavcodec-dev libavutil-dev libswscale-dev libfreerdp-dev libpango1.0-dev libssh2-1-dev libtelnet-dev libvncserver-dev libpulse-dev libssl-dev libssh2-1-dev libvorbis-dev libwebp-dev autoconf autotools-dev libtool build-essential maven default-jdk mysql-common mysql-server mysql-client mysql-utilities tomcat8 tomcat8-admin tomcat8-common tomcat8-docs tomcat8-user ghostscript gsfonts gsfonts-other

Step 2 :

sudo mkdir -p /etc/guacamole
sudo mkdir -p /etc/guacamole/lib
sudo mkdir -p /etc/guacamole/extensions


Step 3 :

sudo nano /etc/default/tomcat8

Append the following lines at the end of the file :

# GUACAMOLE ENV VARIABLE
GUACAMOLE_HOME=/etc/guacamole


Step 4 :

cd ~
git clone git://github.com/apache/incubator-guacamole-server.git
cd incubator-guacamole-server
autoreconf -fi
./configure --with-init-dir=/etc/init.d
make
sudo make install
sudo ldconfig


sudo systemctl enable guacd

Step 5 :

cd ~
git clone git://github.com/apache/incubator-guacamole-client.git
cd incubator-guacamole-client
mvn package

sudo cp ~/incubator-guacamole-client/guacamole/target/guacamole-0.9.12-incubating.war /etc/guacamole/
sudo ln -s /etc/guacamole/guacamole-0.9.12-incubating.war /var/lib/tomcat8/webapps/
sudo cp ~/incubator-guacamole-client/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/target/guacamole-auth-jdbc-mysql-0.9.12-incubating.jar /etc/guacamole/extensions/


Step 6 :

wget https://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-5.1.42.tar.gz
tar -xvzf mysql-connector-java-5.1.42.tar.gz
sudo cp mysql-connector-java-5.1.42/mysql-connector-java-5.1.42-bin.jar /etc/guacamole/lib/


sudo mkdir -p /usr/lib/x86_64-linux-gnu/freerdp
sudo ln -s /usr/local/lib/freerdp/* /usr/lib/x86_64-linux-gnu/freerdp/


Step 7 :

sudo mysql -u root -p
CREATE DATABASE guacamole_db;
CREATE USER 'guacamole_user'@'localhost' identified by '[GUACAMOLE_USER_PASSWORD]';
GRANT SELECT,INSERT,UPDATE,DELETE ON guacamole_db.* TO 'guacamole_user'@'localhost';
flush privileges;
quit


cd ~
cat ~/incubator-guacamole-client/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/schema/*.sql | mysql -u root -p[MYSQL_ROOT_PASSWORD] guacamole_db


Step 8 :

sudo nano /etc/guacamole/guacamole.properties

The content of the file is :

# Hostname and port of guacamole proxy
guacd-hostname: localhost
guacd-port: 4822

# MySQL Authentication
mysql-hostname: localhost
mysql-port: 3306
mysql-database: guacamole_db
mysql-username: guacamole_user
mysql-password: [GUACAMOLE_USER_PASSWORD]


Step 9 :

sudo ln -s /var/lib/tomcat8/webapps/guacamole-0.9.12-incubating.war /var/lib/tomcat8/webapps/ROOT.war

Step 10 :

sudo systemctl restart guacd
sudo systemctl restart tomcat8


Step 11 : (The following Step 11 to 14 are for setting up VNC server on Ubuntu Desktop)

The Ubuntu Desktop will be accessed via VNC. Therefore, we need to install related packages on Ubuntu Desktop.

sudo apt-get install ubuntu-desktop gnome-panel gnome-settings-daemon metacity nautilus gnome-terminal tightvncserver

nano ~/.vnc/xstartup

The file content will be looking like :

#!/bin/sh

xrdb $HOME/.Xresources
xsetroot -solid grey
#x-terminal-emulator -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
#x-window-manager &
# Fix to make GNOME work
export XKL_XMODMAP_DISABLE=1
/etc/X11/Xsession

unset SESSION_MANAGER
vncconfig -iconic &
x-terminal-emulator -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
x-window-manager &
gnome-panel &
gnome-settings-daemon &
nautilus &
metacity &
gnome-session-flashback &


Reconfigure the session manager :

sudo update-alternatives --config x-session-manager

Select :

/usr/lib/gnome-flashback/gnome-flashback-metacity

Step 12 :

sudo nano /lib/systemd/system/vncserver@.service

The file content will be looking like below. Making sure to replace "samiux" to your username :

[Unit]
Description=Start TightVNC server at startup
After=syslog.target network.target

[Service]
Type=forking
User=samiux
PAMName=login
PIDFile=/home/samiux/.vnc/%H:%i.pid
ExecStartPre=-/usr/bin/vncserver -kill :%i > /dev/null 2>&1
ExecStart=/usr/bin/vncserver -depth 24 -geometry 1280x800 :%i
ExecStop=/usr/bin/vncserver -kill :%i

[Install]
WantedBy=multi-user.target


Step 13 :

vncserver

Enter the password of VNC server when prompt and then answer "n" to the last question.

vncserver -kill :1

sudo systemctl daemon-reload
sudo systemctl enable vncserver@1.service


To start VNC server at port 5901 :

sudo systemctl start vncserver@1

Step 14 :

For streaming audio from Ubuntu Desktop :

sudo nano /etc/pulse/default.pa

Append the following line at the end of the file :

load-module module-native-protocol-tcp auth-anonymous=1

To restart PulseAudio :

pulseaudio -k

Port 4713 should be listening for connection. However, it is not very stable at my side.

Step 15 : (The following Step 15 is for setting up RDP on Kali Linux Xfce)

Install Kali Linux Xfce version, Gnome does not work. Lxde may works.

apt-get xrdp
systemctl enable xrdp
systemctl enable xrdp-sesman
systemctl start xrdp
systemctl start xrdp-sesman


update-alternatives --config x-session-manager

Make sure it is selected :

/usr/bin/startxfce4

Step 16 :

To access the Guacamole, you point the browser to the Guacamole box, e.g. http://192.168.20.99:8080. The username and password are both "guacadmin".

When accessing the remote desktop or server, you can launch the submenu by pressing :

ctrl+alt+shift

Reference

Apache Guacamole Manual
How to install SSH ( secure shell ) service on Kali Linux

That's all! See you.