当前位置:   article > 正文

SecureCRT密码破解(实验环境:win10,SecureCRT Version 9.1.0 (x64 build 2579))_securecrt 密码解密

securecrt 密码解密

实验环境:win10,

SecureCRT:Version 9.1.0 (x64 build 2579)

1. SecureCRTCipher.py 文件

  1. #!/usr/bin/env python3
  2. import os
  3. from Crypto.Hash import SHA256
  4. from Crypto.Cipher import AES, Blowfish
  5. class SecureCRTCrypto:
  6. def __init__(self):
  7. '''
  8. Initialize SecureCRTCrypto object.
  9. '''
  10. self.IV = b'\x00' * Blowfish.block_size
  11. self.Key1 = b'\x24\xA6\x3D\xDE\x5B\xD3\xB3\x82\x9C\x7E\x06\xF4\x08\x16\xAA\x07'
  12. self.Key2 = b'\x5F\xB0\x45\xA2\x94\x17\xD9\x16\xC6\xC6\xA2\xFF\x06\x41\x82\xB7'
  13. def Encrypt(self, Plaintext : str):
  14. '''
  15. Encrypt plaintext and return corresponding ciphertext.
  16. Args:
  17. Plaintext: A string that will be encrypted.
  18. Returns:
  19. Hexlified ciphertext string.
  20. '''
  21. plain_bytes = Plaintext.encode('utf-16-le')
  22. plain_bytes += b'\x00\x00'
  23. padded_plain_bytes = plain_bytes + os.urandom(Blowfish.block_size - len(plain_bytes) % Blowfish.block_size)
  24. cipher1 = Blowfish.new(self.Key1, Blowfish.MODE_CBC, iv = self.IV)
  25. cipher2 = Blowfish.new(self.Key2, Blowfish.MODE_CBC, iv = self.IV)
  26. return cipher1.encrypt(os.urandom(4) + cipher2.encrypt(padded_plain_bytes) + os.urandom(4)).hex()
  27. def Decrypt(self, Ciphertext : str):
  28. '''
  29. Decrypt ciphertext and return corresponding plaintext.
  30. Args:
  31. Ciphertext: A hex string that will be decrypted.
  32. Returns:
  33. Plaintext string.
  34. '''
  35. cipher1 = Blowfish.new(self.Key1, Blowfish.MODE_CBC, iv = self.IV)
  36. cipher2 = Blowfish.new(self.Key2, Blowfish.MODE_CBC, iv = self.IV)
  37. ciphered_bytes = bytes.fromhex(Ciphertext)
  38. if len(ciphered_bytes) <= 8:
  39. raise ValueError('Invalid Ciphertext.')
  40. padded_plain_bytes = cipher2.decrypt(cipher1.decrypt(ciphered_bytes)[4:-4])
  41. i = 0
  42. for i in range(0, len(padded_plain_bytes), 2):
  43. if padded_plain_bytes[i] == 0 and padded_plain_bytes[i + 1] == 0:
  44. break
  45. plain_bytes = padded_plain_bytes[0:i]
  46. try:
  47. return plain_bytes.decode('utf-16-le')
  48. except UnicodeDecodeError:
  49. raise(ValueError('Invalid Ciphertext.'))
  50. class SecureCRTCryptoV2:
  51. def __init__(self, ConfigPassphrase : str = ''):
  52. '''
  53. Initialize SecureCRTCryptoV2 object.
  54. Args:
  55. ConfigPassphrase: The config passphrase that SecureCRT uses. Leave it empty if config passphrase is not set.
  56. '''
  57. self.IV = b'\x00' * AES.block_size
  58. self.Key = SHA256.new(ConfigPassphrase.encode('utf-8')).digest()
  59. def Encrypt(self, Plaintext : str):
  60. '''
  61. Encrypt plaintext and return corresponding ciphertext.
  62. Args:
  63. Plaintext: A string that will be encrypted.
  64. Returns:
  65. Hexlified ciphertext string.
  66. '''
  67. plain_bytes = Plaintext.encode('utf-8')
  68. if len(plain_bytes) > 0xffffffff:
  69. raise OverflowError('Plaintext is too long.')
  70. plain_bytes = \
  71. len(plain_bytes).to_bytes(4, 'little') + \
  72. plain_bytes + \
  73. SHA256.new(plain_bytes).digest()
  74. padded_plain_bytes = \
  75. plain_bytes + \
  76. os.urandom(AES.block_size - len(plain_bytes) % AES.block_size)
  77. cipher = AES.new(self.Key, AES.MODE_CBC, iv = self.IV)
  78. return cipher.encrypt(padded_plain_bytes).hex()
  79. def Decrypt(self, Ciphertext : str):
  80. '''
  81. Decrypt ciphertext and return corresponding plaintext.
  82. Args:
  83. Ciphertext: A hex string that will be decrypted.
  84. Returns:
  85. Plaintext string.
  86. '''
  87. cipher = AES.new(self.Key, AES.MODE_CBC, iv = self.IV)
  88. padded_plain_bytes = cipher.decrypt(bytes.fromhex(Ciphertext))
  89. plain_bytes_length = int.from_bytes(padded_plain_bytes[0:4], 'little')
  90. plain_bytes = padded_plain_bytes[4:4 + plain_bytes_length]
  91. if len(plain_bytes) != plain_bytes_length:
  92. raise ValueError('Invalid Ciphertext.')
  93. plain_bytes_digest = padded_plain_bytes[4 + plain_bytes_length:4 + plain_bytes_length + SHA256.digest_size]
  94. if len(plain_bytes_digest) != SHA256.digest_size:
  95. raise ValueError('Invalid Ciphertext.')
  96. if SHA256.new(plain_bytes).digest() != plain_bytes_digest:
  97. raise ValueError('Invalid Ciphertext.')
  98. return plain_bytes.decode('utf-8')
  99. if __name__ == '__main__':
  100. import sys
  101. def Help():
  102. print('Usage:')
  103. print(' SecureCRTCipher.py <enc|dec> [-v2] [-p ConfigPassphrase] <plaintext|ciphertext>')
  104. print('')
  105. print(' <enc|dec> "enc" for encryption, "dec" for decryption.')
  106. print(' This parameter must be specified.')
  107. print('')
  108. print(' [-v2] Encrypt/Decrypt with "Password V2" algorithm.')
  109. print(' This parameter is optional.')
  110. print('')
  111. print(' [-p ConfigPassphrase] The config passphrase that SecureCRT uses.')
  112. print(' This parameter is optional.')
  113. print('')
  114. print(' <plaintext|ciphertext> Plaintext string or ciphertext string.')
  115. print(' NOTICE: Ciphertext string must be a hex string.')
  116. print(' This parameter must be specified.')
  117. print('')
  118. def EncryptionRoutine(UseV2 : bool, ConfigPassphrase : str, Plaintext : str):
  119. try:
  120. if UseV2:
  121. print(SecureCRTCryptoV2(ConfigPassphrase).Encrypt(Plaintext))
  122. else:
  123. print(SecureCRTCrypto().Encrypt(Plaintext))
  124. return True
  125. except:
  126. print('Error: Failed to encrypt.')
  127. return False
  128. def DecryptionRoutine(UseV2 : bool, ConfigPassphrase : str, Ciphertext : str):
  129. try:
  130. if UseV2:
  131. print(SecureCRTCryptoV2(ConfigPassphrase).Decrypt(Ciphertext))
  132. else:
  133. print(SecureCRTCrypto().Decrypt(Ciphertext))
  134. return True
  135. except:
  136. print('Error: Failed to decrypt.')
  137. return False
  138. def Main(argc : int, argv : list):
  139. if 3 <= argc and argc <= 6:
  140. bUseV2 = False
  141. ConfigPassphrase = ''
  142. if argv[1].lower() == 'enc':
  143. bEncrypt = True
  144. elif argv[1].lower() == 'dec':
  145. bEncrypt = False
  146. else:
  147. Help()
  148. return -1
  149. i = 2
  150. while i < argc - 1:
  151. if argv[i].lower() == '-v2':
  152. bUseV2 = True
  153. i += 1
  154. elif argv[i].lower() == '-p' and i + 1 < argc - 1:
  155. ConfigPassphrase = argv[i + 1]
  156. i += 2
  157. else:
  158. Help()
  159. return -1
  160. if bUseV2 == False and len(ConfigPassphrase) != 0:
  161. print('Error: ConfigPassphrase is not supported if "-v2" is not specified')
  162. return -1
  163. if bEncrypt:
  164. return 0 if EncryptionRoutine(bUseV2, ConfigPassphrase, argv[-1]) else -1
  165. else:
  166. return 0 if DecryptionRoutine(bUseV2, ConfigPassphrase, argv[-1]) else -1
  167. else:
  168. Help()
  169. exit(Main(len(sys.argv), sys.argv))


2. 安装 python3

【https://www.python.org/ftp/python/3.10.9/python-3.10.9-amd64.exe】(不要安装2)
3. 配置环境变量

【一个是 python.exe 所在目录,另一个是 pip.exe 所在目录】

我的目录是在

C:\Users\admin\AppData\Local\Programs\Python\Python310

C:\Users\admin\AppData\Local\Programs\Python\Python310\Scripts

可按照实际安装情况自行配置


4. 安装 三方库 (不是pyCrypto )
    pip install pycryptodome


5. 找到 SecureCRT 配置文件密码

 C:\Users\admin\AppData\Roaming\VanDyke\Config\Sessions\192.168.1.1.ini

6. 执行解密

    在 cmd 下,执行 
    python SecureCRTCipher.py dec -v2 这里写加密的 02:后面的那串码(下面的截图换行是因为密文太长了,自动换行了,不是分两行执行)
    
各种失败情况及原因:
    1. 不要看他们说的安装 python2版本,安装 3 版本。否则报错   File "SecureCRTCipher.py", line 16 def Encrypt(self, Plaintext : str):


    2. 没有 pip 命令,要将 python 安装目录下的 Scripts 目录也加入到环境变量中
    3. pip install pyCrypto 命令执行失败【原因可能是已经弃用 pyCrypto 包,现在使用 pycryptodome 包】


    4. 其他小问题,打开命令行执行了 SeicureCRTCipher.py 结果报错 python: can't open file 'C:\\Users\\admin\\SecureCRTCipher.py': [Errno 2] No such file or directory
因为我把 SeicureCRTCipher.py 放到了桌面,所以先把 cmd 切换目录到 C:\Users\admin>cd Desktop

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/842573
推荐阅读
相关标签
  

闽ICP备14008679号