Skip to content

Instantly share code, notes, and snippets.

@rkttu
Created April 9, 2024 14:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rkttu/11b2531df0bd846f9e3b49467fc9ad90 to your computer and use it in GitHub Desktop.
Save rkttu/11b2531df0bd846f9e3b49467fc9ad90 to your computer and use it in GitHub Desktop.
RDP Password Embedding Sample
using System;
using System.Security.Cryptography;
// Original Source Code: https://github.com/RedAndBlueEraser/rdp-file-password-encryptor
// System.Security.dll required
public static class Program
{
public static void Main()
{
Console.Out.WriteLine("Provide passphrase to encrypt: ");
var rawPassword = Console.In.ReadLine();
var optionalEntropy = default(byte[]);
var protectionScope = DataProtectionScope.CurrentUser;
var encrypted = string.Concat(ProtectedData.Protect(
Encoding.Unicode.GetBytes(rawPassword),
optionalEntropy, protectionScope).Select(x => $"{x:X2}"));
Console.Out.WriteLine(encrypted);
var decrypted = Encoding.Unicode.GetString(ProtectedData.Unprotect(Enumerable.Range(0, encrypted.Length / 2)
.Select(x => Convert.ToByte(encrypted.Substring(x * 2, 2), 16)).ToArray(),
optionalEntropy, protectionScope));
var result = string.Equals(rawPassword, decrypted, StringComparison.Ordinal);
Console.Out.WriteLine(result);
}
}
using System;
using System.Security.Cryptography;
// Original Source Code: https://github.com/RedAndBlueEraser/rdp-file-password-encryptor
// System.Security.dll required
public static class Program
{
public static void Main()
{
Console.Out.WriteLine("Provide server address: ");
var serverAddress = Console.In.ReadLine();
Console.Out.WriteLine("Provide user account name: ");
var userAccountName = Console.In.ReadLine();
Console.Out.WriteLine("Provide passphrase to encrypt: ");
var rawPassword = Console.In.ReadLine();
var optionalEntropy = default(byte[]);
var protectionScope = DataProtectionScope.CurrentUser;
var encrypted = string.Concat(ProtectedData.Protect(
Encoding.Unicode.GetBytes(rawPassword),
optionalEntropy, protectionScope).Select(x => $"{x:X2}"));
Console.Out.WriteLine();
var buffer = new StringBuilder();
buffer.AppendLine(string.Concat("full address:s:", serverAddress));
buffer.AppendLine(string.Concat("username:s:", userAccountName));
buffer.AppendLine(string.Concat("password 51:b:", encrypted));
Console.Out.WriteLine(buffer.ToString());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment