xdec

xdec - Xshell 5 Password Decrypter


So recently I needed to recover some passwords that I though were lost forever to Xshell, here is a little solution that I've come up with.

What is xdec?

xdec is a niche C# utility designed to decrypt passwords stored in Xshell 5, a popular terminal emulator. With xdec, users can retrieve passwords stored in Xshell 5 configuration files with ease.

What does xdec do?

At its core, xdec serves a single purpose: to decrypt passwords stored in Xshell 5 configuration files. Here's how it simplifies the process:

Password Decryption: xdec utilizes basic cryptographic techniques to decrypt passwords stored in Xshell 5 configuration files, enabling users to access vital credentials quickly and securely.

Snippet

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace xdec
{
    /// <summary>
    /// Some very basic RC4 decryption.
    /// </summary>
    public static class RC4
    {
        /// <summary>
        /// Decrypt data using key.
        /// </summary>
        /// <param name="key"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public static byte[] Decrypt(byte[] key, byte[] data)
        {
            return EncryptOutput(key, data).ToArray();
        }

        /// <summary>
        /// Init our encryption.
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        private static byte[] EncryptInitalize(byte[] key)
        {
            byte[] s = Enumerable.Range(0, 256)
              .Select(i => (byte)i)
              .ToArray();

            for (int i = 0, j = 0; i < 256; i++)
            {
                j = (j + key[i % key.Length] + s[i]) & 255;

                Swap(s, i, j);
            }

            return s;
        }

        /// <summary>
        /// Loop
        /// </summary>
        /// <param name="key"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        private static IEnumerable<byte> EncryptOutput(byte[] key, IEnumerable<byte> data)
        {
            byte[] s = EncryptInitalize(key);

            int i = 0;
            int j = 0;

            return data.Select((b) =>
            {
                i = (i + 1) & 255;
                j = (j + s[i]) & 255;

                Swap(s, i, j);

                return (byte)(b ^ s[(s[i] + s[j]) & 255]);
            });
        }

        /// <summary>
        /// Swap byte.
        /// </summary>
        /// <param name="s"></param>
        /// <param name="i"></param>
        /// <param name="j"></param>
        private static void Swap(byte[] s, int i, int j)
        {
            byte c = s[i];

            s[i] = s[j];
            s[j] = c;
        }
    }
}