1

I am having issues using kali-win-kex in ESM mode on Kali Linux. I followed instructions for win kex step-by-step as shown on kali.org.(Note that I have carried out this process multiple times before with no issues) On attempting to run kex --esm -s I get the following error:

┌──(jralphw㉿jralphw)-[~]
└─$ kex --esm -s
/usr/bin/kex: line 291: cmdkey.exe: command not found
Please enter ESM password for user jralphw:
/usr/bin/kex: line 371: mstsc.exe: command not found

Both cmdkey.exe and mstsc.exe are valid windows programs on my machine... with cmdkey producing terminal output and mstsc opening the RDP client when executed through Win+R Run dialog In addition, simply starting Kali using the kali or wsl commands gives me the following error message:

 -bash: .: filename argument required
.: usage: . filename [arguments]
┌──(jralphw㉿jralphw)-[~]
└─$

note: I have used kali-win-kex on this very machine before with no issues. However, a situation arose where I had no option but to reinstall windows and set everything up again.

4 Answers4

1

Had the same problem. Disabling systemd in /etc/wsl.conf fixed it for me (when wsl.conf is changed, a restart (i.e. wsl --shutdown) is required).

Toto
  • 19,304
PeterN
  • 11
0

Same problem, here's what finally worked for me:

First run the following, and set a password:

sudo kex -esm 

From then on it just starts working. Don't know why error doesn't mention pwd.

Since I had already set a password for the "kex --win -s" which was also working with kex --sl -s so it never occurred to me that esm needs a password set again.

This is probably required as --esm brings up a VNC client to connect to Kali while the --win & the --sl modes bring up RDP client and an X-Server (client) resp.

I did not make any other changes before this - only read through various proposed resolution steps on the net, regarding log file permissions & exe's etc - so I expect this should work for others.

FYI this is the 3rd install of kali win kex (on different machines) when some kex mode has given an error while other 2 work. Previously it was an incorrect firewall issue (fixed after editing firewall rules) and windows X-server config issue (solved by installing a diff x-server app as i had no idea what is wrong)

0

This appears to be a bug in Kali for WSL in general. It's not specific to Kex. It started showing up recently since apparently the Kali WSL installers have finally (after being out of date for several years) been updated on the CDN.

As noted in this Github issue, the problem is due to a broken /etc/profile. There are multiple issues with the file, and it seems to be due to something like a broken quoting/escaping issue in the Kali build system. Severable variable names and other string interpolations are flat out missing from the file.

In addition to the error when starting Kali, you'll find that the Windows path is no longer appended to the WSL/Kali path due to these issues.

As far as I can tell the /etc/profile from a previous Kali release works just fine. Using sudo -e /etc/profile, replace the entire file with:

# /etc/profile: system-wide .profile file for the Bourne shell (sh(1))
# and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).

IS_WSL=grep -i microsoft /proc/version # WSL already sets PATH, shouldn't be overridden if test "$IS_WSL" = ""; then if [ "id -u" -eq 0 ]; then PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" else PATH="/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games" fi fi export PATH

if [ "${PS1-}" ]; then if [ "${BASH-}" ] && [ "$BASH" != "/bin/sh" ]; then # The file bash.bashrc already sets the default PS1. # PS1='\h:\w$ ' if [ -f /etc/bash.bashrc ]; then . /etc/bash.bashrc fi else if [ "id -u" -eq 0 ]; then PS1='# ' else PS1='$ ' fi fi fi

if [ -d /etc/profile.d ]; then for i in /etc/profile.d/*.sh; do if [ -r $i ]; then . $i fi done unset i fi

NotTheDr01ds
  • 28,025
0

Considering the following output:

-bash: .: filename argument required .: usage: . filename [arguments]

Have a look into /etc/profile in the last for loop at the bottom where it dot sources the *.sh scripts under /etc/profile.d/ It seems like it's missing the filenames as arguments (in $i).

Change it from this..

if [ -d /etc/profile.d ]; then
  for i in /etc/profile.d/*.sh; do
    if [ -r ]; then
      .
    fi
  done
  unset i
fi

.. to this:

if [ -d /etc/profile.d ]; then
  for i in /etc/profile.d/*.sh; do
    if [ -r "$i" ]; then
      . "$i"
    fi
  done
  unset i
fi