Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Enhanced Session for Kali Linux.
#!/bin/bash
# Original : https://raw.githubusercontent.com/Microsoft/linux-vm-tools/master/arch/install-config.sh
###############################################################################
# Update our machine to the latest code if we need to.
#
if [ "$(id -u)" -ne 0 ]; then
echo 'This script must be run with root privileges' >&2
exit 1
fi
apt update && apt upgrade -y
if [ -f /var/run/reboot-required ]; then
echo "A reboot is required in order to proceed with the install." >&2
echo "Please reboot and re-run this script to finish the install." >&2
exit 1
fi
###############################################################################
# Install XRDP
#
apt install -y xrdp
###############################################################################
# Configure XRDP
#
systemctl enable xrdp
systemctl enable xrdp-sesman
# Configure the installed XRDP ini files.
# use vsock transport.
# sed -i_orig -e 's/use_vsock=false/use_vsock=true/g' /etc/xrdp/xrdp.ini
sed -i_orig -e 's/port=3389/port=vsock://-1:3389/g' /etc/xrdp/xrdp.ini # 2020.1 support.
# use rdp security.
sed -i_orig -e 's/security_layer=negotiate/security_layer=rdp/g' /etc/xrdp/xrdp.ini
# remove encryption validation.
sed -i_orig -e 's/crypt_level=high/crypt_level=none/g' /etc/xrdp/xrdp.ini
# disable bitmap compression since its local its much faster
sed -i_orig -e 's/bitmap_compression=true/bitmap_compression=false/g' /etc/xrdp/xrdp.ini
sed -n -e 's/max_bpp=32/max_bpp=24/g' /etc/xrdp/xrdp.ini
sed -i_orig -e 's/X11DisplayOffset=10/X11DisplayOffset=0/g' /etc/xrdp/sesman.ini
# rename the redirected drives to 'shared-drives'
sed -i_orig -e 's/FuseMountName=thinclient_drives/FuseMountName=shared-drives/g' /etc/xrdp/sesman.ini
# Change the allowed_users
echo "allowed_users=anybody" > /etc/X11/Xwrapper.config
#Ensure hv_sock gets loaded
if [ ! -e /etc/modules-load.d/hv_sock.conf ]; then
echo "hv_sock" > /etc/modules-load.d/hv_sock.conf
fi
# Configure the policy xrdp session
cat > /etc/polkit-1/localauthority/50-local.d/45-allow-colord.pkla <<EOF
[Allow Colord all Users]
Identity=unix-user:*
Action=org.freedesktop.color-manager.create-device;org.freedesktop.color-manager.create-profile;org.freedesktop.color-manager.delete-device;org.freedesktop.color-manager.delete-profile;org.freedesktop.color-manager.modify-device;org.freedesktop.color-manager.modify-profile
ResultAny=no
ResultInactive=no
ResultActive=yes
EOF
###############################################################################
# .xinitrc has to be modified manually.
#
#echo "exec gnome-session" > ~/.xinitrc
echo "exec startxfce4" > ~/.xinitrc # thanks @rasschaert and @patrickceg.
echo "You will have to configure .xinitrc to start your windows manager, see https://wiki.archlinux.org/index.php/Xinit"
echo "Reboot your machine to begin using XRDP."
@jsorah

This comment has been minimized.

Copy link

jsorah commented Feb 24, 2019

In case anyone else stumbles upon this, don't forget to set your Hyper-V VM to actually use Enhanced Session Mode:

Set-VM -VMName <your_vm_name> -EnhancedSessionTransportType HvSocket

This worked perfectly on the 2019.1 release of Kali.

@Metal0gic

This comment has been minimized.

Copy link

Metal0gic commented Apr 17, 2019

can you be more specific with what we have to do to configure initxrc to start our windows manager? i read the article but its not clear what i have to do on my specific system, fresh kali install

@calvaradocl

This comment has been minimized.

Copy link

calvaradocl commented May 13, 2019

Thanks, works great with Kali 2019.1, you have to run the script 2 times (two reboots) and then use the command provided by @jsorah

@rasschaert

This comment has been minimized.

Copy link

rasschaert commented Dec 14, 2019

XFCE is now the default desktop in Kali, starting in the 2019.4 update. Might I suggest echo "exec startxfce4" > ~/.xinitrc at the end of the script?

@patrickceg

This comment has been minimized.

Copy link

patrickceg commented Dec 19, 2019

XFCE is now the default desktop in Kali, starting in the 2019.4 update. Might I suggest echo "exec startxfce4" > ~/.xinitrc at the end of the script?

I can confirm that's really all you need to do to get it to work for Kali 2019.4: I uploaded a fork of this script with the one liner change (and for the original author, feel free to take the change as I'm not sure if you can pull request a Gist...)

EDIT: Actually I used xfce4-session (because the original used gnome-session) and it works for me. If I recall, the startxfce4 passes additional arguments (which make quite a difference in the default UI you start with in Xubuntu), but the Kali interface looks normal enough through the xfce4-session as the exec.

@mimura1133

This comment has been minimized.

Copy link
Owner Author

mimura1133 commented Jan 3, 2020

Hi @rasschaert and @patrickceg, Thank you for your advice.
I modified the code to echo "exec startxfce4" > ~/.xinitrc from execute the gnome. 👍

@nathanVader

This comment has been minimized.

Copy link

nathanVader commented Jan 22, 2020

Hello,

I installed last Kali Linux Gnome (2019.4) on Hyper-V on Windows 10 ver. 1909... I run the script twice (activating "exec gnome-session" instead of "exec startxfce4", because I used Gnome ISO), and executed the command in PowerShell to use the Enhanced Session, but the Enhanced Session appears deactivated.

Can someone help me?

Thanks.

@nathanVader

This comment has been minimized.

Copy link

nathanVader commented Jan 22, 2020

I found a solution editing xrdp.ini and changing the port value to this:
port=vsock://-1:3389

That makes it work in Kali with Xfce, but in Kali with Gnome fails to connect to RDP session:

image

@patrickceg

This comment has been minimized.

Copy link

patrickceg commented Jan 23, 2020

Thanks @nathanVader for the research: I updated my fork for the Xfce fix although I can't find anything for gnome unfortunately. I'm downloading a Kali Gnome, but I'm concerned my laptop (Core i5-5300U) won't even be able to handle it properly to debug. The newest Kali+Gnome was a disaster for me on VMWare player when I tried last month (half of the screens didn't render and maybe 5 frames per second if I was lucky).

EDIT: Wow... the Hyper-V gods really don't like me debugging this. The second I make a VM checkpoint, I corrupt the VM's disk, so it's difficult to switch out xfce for gnome to see what Gnome is complaining about. I did reproduce the gnome issue before my VM self-destructed, so I'll try again with a Kali Weekly image.

@mimura1133

This comment has been minimized.

Copy link
Owner Author

mimura1133 commented Jan 31, 2020

I just updated the enhanced session script to support Kali linux 2020.1.
https://github.com/mimura1133/linux-vm-tools

@alshawwa

This comment has been minimized.

Copy link

alshawwa commented Feb 24, 2020

still could not get enhanced session enabled on kali 2020.1 with default installation. the script does not error out but the enhanced session mode will not activate for some reason.
any clues? after the reboot the system still boots to lightdm instead of xrdp login screen as in ubuntu

and set-vm -VMname is an invalid parameter at least on windows 10 v1909 . and what i know is that enhanced session mode is enabled by default on windows 10 .

@alshawwa

This comment has been minimized.

Copy link

alshawwa commented Feb 24, 2020

In case anyone else stumbles upon this, don't forget to set your Hyper-V VM to actually use Enhanced Session Mode:

Set-VM -VMName <your_vm_name> -EnhancedSessionTransportType HvSocket

This worked perfectly on the 2019.1 release of Kali.

i cant seem to get this command to work at all . .. invalid parameter name VMname .. Running Windows 10 v1909

@patrickceg

This comment has been minimized.

Copy link

patrickceg commented Feb 25, 2020

Set-VM -Name acamar-kali -EnhancedSessionTransportType HvSocket

Seems to work (my VM is called acamar-kali)

The newest documentation has Set-VM -Name ... Also "-EnhancedSessionTransportType" doesn't exist in the documentation, but it tab-completes on my machine.

https://docs.microsoft.com/en-us/powershell/module/hyper-v/set-vm?view=win10-ps

If you really can't get the name to work, try

Get-VM myvm

...if that returns nothing or has an error, your PowerShell module for Hyper-V is broken.
If the Get-VM works, you can use the pipe notation to run Set-VM:

Get-VM myvm | Set-VM -EnhancedSessionTransportType HvSocket

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.