Created
April 9, 2024 14:51
-
-
Save rkttu/11b2531df0bd846f9e3b49467fc9ad90 to your computer and use it in GitHub Desktop.
RDP Password Embedding Sample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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