{"id":5041,"date":"2022-06-15T01:18:02","date_gmt":"2022-06-14T17:18:02","guid":{"rendered":"http:\/\/www.menglanglang.cn\/?p=5041"},"modified":"2022-06-15T01:18:52","modified_gmt":"2022-06-14T17:18:52","slug":"securecrt-%e6%9c%8d%e5%8a%a1%e5%99%a8%e9%93%be%e6%8e%a5%e4%bf%a1%e6%81%af%e5%af%86%e7%a0%81%e5%bf%98%e8%ae%b0%e6%89%be%e5%9b%9e","status":"publish","type":"post","link":"http:\/\/www.menglanglang.cn\/?p=5041","title":{"rendered":"SecureCRT \u670d\u52a1\u5668\u94fe\u63a5\u4fe1\u606f\u5bc6\u7801\u5fd8\u8bb0\u627e\u56de"},"content":{"rendered":"\n<p>\u200b\u5728\u65e5\u5e38\u5de5\u4f5c\u548c\u5b66\u4e60\u4e2d\uff0c\u670d\u52a1\u5668\u5e38\u4e3a Linux \u670d\u52a1\u5668\uff0c\u800c\u4e3b\u673a\u7535\u8111\u4e00\u7248\u4e3a Windows \u7cfb\u7edf\uff0c\u5728\u4e3b\u673a\u4e0a\u5982\u4f55\u8fde\u63a5 Linux \u670d\u52a1\u5668\uff0c\u5927\u5bb6\u7528\u5230\u7684\u5de5\u5177\u4e5f\u662f\u4e94\u82b1\u516b\u95e8\uff0c\u5f88\u591a\u670b\u53cb\u90fd\u559c\u6b22\u7528 XShell\uff0c\u800c\u6211\u4e60\u60ef\u7528 SecureCRT\u3002<\/p>\n\n\n\n<p>\u53ef\u5f53\u6709\u65f6\u5019\uff0c\u5de5\u5177\u4e2d\u94fe\u63a5\u670d\u52a1\u5668\u7684\u94fe\u63a5\u4fe1\u606f\uff0c\u5fd8\u8bb0\u4e86\u7528\u6237\u5bf9\u5e94\u7684\u5bc6\u7801\uff0c\u800c\u4e14\u624b\u5934\u8fd8\u6ca1\u6709\u4fdd\u5b58\u660e\u6587\u5bc6\u7801\uff0c\u8fd9\u5c31\u6bd4\u8f83\u5c34\u5c2c\u4e86\u3002\u90a3\u5982\u4f55\u627e\u56de\u5bc6\u7801\u5462\uff1f\u8fd9\u7bc7\u7b80\u5355\u8bf4\u8bf4\u627e\u56de\u6b65\u9aa4\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u7b2c\u4e00\u6b65\uff1a\u627e\u5230 SecureCRT \u4fdd\u5b58\u94fe\u63a5\u4fe1\u606f\u7684\u914d\u7f6e\u6587\u4ef6\u3002<\/h3>\n\n\n\n<p>\u5728\u5de5\u5177\u83dc\u5355\u680f\uff0c\u4f9d\u6b21\u70b9\u51fb Options -&gt; Global Options...\uff0c\u6253\u5f00\u9009\u9879\u9762\u677f\uff0c\u627e\u5230\u5982\u56fe\u6240\u793a\u4f4d\u7f6e\u3002<\/p>\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" height=\"369\" width=\"705\" src=\"\/\/images.weserv.nl\/?url=https:\/\/img-blog.csdnimg.cn\/1ef98ca0d4fe4a36b560bfab56157514.png\" alt=\"\"\/><img height=\"15\" width=\"15\"\/><\/p>\n\n\n\n<p>\u5728\u5bf9\u5e94\u8def\u5f84\u627e\u5230\u673a\u5668\u5bf9\u5e94\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u6bd4\u5982\u8fd9\u91cc\u8981\u627e\u56de <strong>192.168.220.10<\/strong> \u673a\u5668\u7684\u94fe\u63a5\u5bc6\u7801\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" height=\"412\" width=\"900\" src=\"\/\/images.weserv.nl\/?url=https:\/\/img-blog.csdnimg.cn\/55a9ccda6d3a44a684628b6c0191cfce.png\" alt=\"\"\/><\/p>\n\n\n\n<p>\u6253\u5f00\u914d\u7f6e\u6587\u4ef6\u540e\uff0c\u53ef\u4ee5\u770b\u5230\u7528\u6237\u540d\u548c\u5bc6\u7801\u4fe1\u606f\u7b49\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" height=\"350\" width=\"900\" src=\"\/\/images.weserv.nl\/?url=https:\/\/img-blog.csdnimg.cn\/2443f5c5107a4038a4acd61c837b2c22.png\" alt=\"\"\/><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u7b2c\u4e8c\u6b65\uff1a\u65b0\u5efa\u4e00\u4e2a Python \u811a\u672c\uff0c\u4ee3\u7801\u5982\u4e0b\uff1a<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/usr\/bin\/env python3\nimport os\nfrom Crypto.Hash import SHA256\nfrom Crypto.Cipher import AES, Blowfish\n \nclass SecureCRTCrypto:\n \n    def __init__(self):\n        '''\n        Initialize SecureCRTCrypto object.\n        '''\n        self.IV = b'\\x00' * Blowfish.block_size\n        self.Key1 = b'\\x24\\xA6\\x3D\\xDE\\x5B\\xD3\\xB3\\x82\\x9C\\x7E\\x06\\xF4\\x08\\x16\\xAA\\x07'\n        self.Key2 = b'\\x5F\\xB0\\x45\\xA2\\x94\\x17\\xD9\\x16\\xC6\\xC6\\xA2\\xFF\\x06\\x41\\x82\\xB7'\n \n    def Encrypt(self, Plaintext : str):\n        '''\n        Encrypt plaintext and return corresponding ciphertext.\n        Args:\n            Plaintext: A string that will be encrypted.\n        Returns:\n            Hexlified ciphertext string.\n        '''\n        plain_bytes = Plaintext.encode('utf-16-le')\n        plain_bytes += b'\\x00\\x00'\n        padded_plain_bytes = plain_bytes + os.urandom(Blowfish.block_size - len(plain_bytes) % Blowfish.block_size)\n \n        cipher1 = Blowfish.new(self.Key1, Blowfish.MODE_CBC, iv = self.IV)\n        cipher2 = Blowfish.new(self.Key2, Blowfish.MODE_CBC, iv = self.IV)\n        return cipher1.encrypt(os.urandom(4) + cipher2.encrypt(padded_plain_bytes) + os.urandom(4)).hex()\n \n    def Decrypt(self, Ciphertext : str):\n        '''\n        Decrypt ciphertext and return corresponding plaintext.\n        Args:\n            Ciphertext: A hex string that will be decrypted.\n        Returns:\n            Plaintext string.\n        '''\n \n        cipher1 = Blowfish.new(self.Key1, Blowfish.MODE_CBC, iv = self.IV)\n        cipher2 = Blowfish.new(self.Key2, Blowfish.MODE_CBC, iv = self.IV)\n        ciphered_bytes = bytes.fromhex(Ciphertext)\n        if len(ciphered_bytes) &lt;= 8:\n            raise ValueError('Invalid Ciphertext.')\n        \n        padded_plain_bytes = cipher2.decrypt(cipher1.decrypt(ciphered_bytes)&#91;4:-4])\n        \n        i = 0\n        for i in range(0, len(padded_plain_bytes), 2):\n            if padded_plain_bytes&#91;i] == 0 and padded_plain_bytes&#91;i + 1] == 0:\n                break\n        plain_bytes = padded_plain_bytes&#91;0:i]\n \n        try:\n            return plain_bytes.decode('utf-16-le')\n        except UnicodeDecodeError:\n            raise(ValueError('Invalid Ciphertext.'))\n \nclass SecureCRTCryptoV2:\n \n    def __init__(self, ConfigPassphrase : str = ''):\n        '''\n        Initialize SecureCRTCryptoV2 object.\n        Args:\n            ConfigPassphrase: The config passphrase that SecureCRT uses. Leave it empty if config passphrase is not set.\n        '''\n        self.IV = b'\\x00' * AES.block_size\n        self.Key = SHA256.new(ConfigPassphrase.encode('utf-8')).digest()\n \n    def Encrypt(self, Plaintext : str):\n        '''\n        Encrypt plaintext and return corresponding ciphertext.\n        Args:\n            Plaintext: A string that will be encrypted.\n        Returns:\n            Hexlified ciphertext string.\n        '''\n        plain_bytes = Plaintext.encode('utf-8')\n        if len(plain_bytes) &gt; 0xffffffff:\n            raise OverflowError('Plaintext is too long.')\n        \n        plain_bytes = \\\n            len(plain_bytes).to_bytes(4, 'little') + \\\n            plain_bytes + \\\n            SHA256.new(plain_bytes).digest()\n        padded_plain_bytes = \\\n            plain_bytes + \\\n            os.urandom(AES.block_size - len(plain_bytes) % AES.block_size)\n        cipher = AES.new(self.Key, AES.MODE_CBC, iv = self.IV)\n        return cipher.encrypt(padded_plain_bytes).hex()\n \n    def Decrypt(self, Ciphertext : str):\n        '''\n        Decrypt ciphertext and return corresponding plaintext.\n        Args:\n            Ciphertext: A hex string that will be decrypted.\n        Returns:\n            Plaintext string.\n        '''\n        cipher = AES.new(self.Key, AES.MODE_CBC, iv = self.IV)\n        padded_plain_bytes = cipher.decrypt(bytes.fromhex(Ciphertext))\n        \n        plain_bytes_length = int.from_bytes(padded_plain_bytes&#91;0:4], 'little')\n        plain_bytes = padded_plain_bytes&#91;4:4 + plain_bytes_length]\n        if len(plain_bytes) != plain_bytes_length:\n            raise ValueError('Invalid Ciphertext.')\n \n        plain_bytes_digest = padded_plain_bytes&#91;4 + plain_bytes_length:4 + plain_bytes_length + SHA256.digest_size]\n        if len(plain_bytes_digest) != SHA256.digest_size:\n            raise ValueError('Invalid Ciphertext.')\n \n        if SHA256.new(plain_bytes).digest() != plain_bytes_digest:\n            raise ValueError('Invalid Ciphertext.')\n \n        return plain_bytes.decode('utf-8')\n \nif __name__ == '__main__':\n    import sys\n \n    def Help():\n        print('Usage:')\n        print('    SecureCRTCipher.py &lt;enc|dec&gt; &#91;-v2] &#91;-p ConfigPassphrase] &lt;plaintext|ciphertext&gt;')\n        print('')\n        print('    &lt;enc|dec&gt;              \"enc\" for encryption, \"dec\" for decryption.')\n        print('                           This parameter must be specified.')\n        print('')\n        print('    &#91;-v2]                  Encrypt\/Decrypt with \"Password V2\" algorithm.')\n        print('                           This parameter is optional.')\n        print('')\n        print('    &#91;-p ConfigPassphrase]  The config passphrase that SecureCRT uses.')\n        print('                           This parameter is optional.')\n        print('')\n        print('    &lt;plaintext|ciphertext&gt; Plaintext string or ciphertext string.')\n        print('                           NOTICE: Ciphertext string must be a hex string.')\n        print('                           This parameter must be specified.')\n        print('')\n    \n    def EncryptionRoutine(UseV2 : bool, ConfigPassphrase : str, Plaintext : str):\n        try:\n            if UseV2:\n                print(SecureCRTCryptoV2(ConfigPassphrase).Encrypt(Plaintext))\n            else:\n                print(SecureCRTCrypto().Encrypt(Plaintext))\n            return True\n        except:\n            print('Error: Failed to encrypt.')\n            return False\n \n    def DecryptionRoutine(UseV2 : bool, ConfigPassphrase : str, Ciphertext : str):\n        try:\n            if UseV2:\n                print(SecureCRTCryptoV2(ConfigPassphrase).Decrypt(Ciphertext))\n            else:\n                print(SecureCRTCrypto().Decrypt(Ciphertext))\n            return True\n        except:\n            print('Error: Failed to decrypt.')\n            return False\n \n    def Main(argc : int, argv : list):\n        if 3 &lt;= argc and argc &lt;= 6:\n            bUseV2 = False\n            ConfigPassphrase = ''\n \n            if argv&#91;1].lower() == 'enc':\n                bEncrypt = True\n            elif argv&#91;1].lower() == 'dec':\n                bEncrypt = False\n            else:\n                Help()\n                return -1\n            \n            i = 2\n            while i &lt; argc - 1:\n                if argv&#91;i].lower() == '-v2':\n                    bUseV2 = True\n                    i += 1\n                elif argv&#91;i].lower() == '-p' and i + 1 &lt; argc - 1:\n                    ConfigPassphrase = argv&#91;i + 1]\n                    i += 2\n                else:\n                    Help()\n                    return -1\n \n            if bUseV2 == False and len(ConfigPassphrase) != 0:\n                print('Error: ConfigPassphrase is not supported if \"-v2\" is not specified')\n                return -1\n \n            if bEncrypt:\n                return 0 if EncryptionRoutine(bUseV2, ConfigPassphrase, argv&#91;-1]) else -1\n            else:\n                return 0 if DecryptionRoutine(bUseV2, ConfigPassphrase, argv&#91;-1]) else -1\n        else:\n            Help()\n \n    exit(Main(len(sys.argv), sys.argv))<\/code><\/pre>\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" height=\"15\" src=\"blob:http:\/\/www.menglanglang.cn\/e483cab2-d229-40fb-bc42-296d9b426b21\" width=\"15\"\/><\/p>\n\n\n\n<p>\u6587\u4ef6\u540d\u968f\u4fbf\u81ea\u5b9a\u4e49\uff0c\u6bd4\u5982 SecureCRTCipher.py\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u7b2c\u4e09\u6b65\uff1a\u4e3b\u673a\u642d\u5efa Python3 \u73af\u5883\u3002<\/h3>\n\n\n\n<p>\u7531\u4e8e\u811a\u672c\u4e3a Python \u811a\u672c\uff0c\u9700\u8981 Python \u73af\u5883\u624d\u80fd\u6267\u884c\uff0c\u9700\u8981\u5728 Windows \u4e3b\u673a\u4e0a\u5b89\u88c5 Python3 \u73af\u5883\u3002\u8be5\u6b65\u9aa4\u6b64\u5904\u7701\u7565\uff0c\u8bf7\u81ea\u884c\u5b89\u88c5\u5e76\u914d\u7f6e\u73af\u5883\u53d8\u91cf\u7b49\u3002<\/p>\n\n\n\n<p>\u53e6\u5916\u6ce8\u610f\uff0c\u9700\u8981\u5b89\u88c5\u6a21\u5757 pycryptodome\uff0c\u5426\u5219\u5728\u7b2c\u56db\u6b65\u6267\u884c\u547d\u4ee4\u65f6\uff0c\u4f1a\u62a5\u5982\u4e0b\u9519\u8bef\uff1a<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>Traceback (most recent call last):<br \/>&nbsp; File \"SecureCRTCipher.py\", line 3, in &lt;module&gt;<br \/>&nbsp; &nbsp; from Crypto.Hash import SHA256<br \/>ModuleNotFoundError: No module named 'Crypto'<\/p><\/blockquote>\n\n\n\n<p>\u5b89\u88c5\u6a21\u5757\u547d\u4ee4\uff1a<strong>pip install pycryptodome<\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u7b2c\u56db\u6b65\uff1a\u6267\u884c\u811a\u672c\uff0c\u627e\u56de\u5bc6\u7801\u3002<\/h3>\n\n\n\n<p>\u6253\u5f00 CMD \u7a97\u53e3\uff0c\u8fdb\u5165\u811a\u672c\u5b58\u653e\u76ee\u5f55\u4f4d\u7f6e\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" height=\"464\" width=\"761\" src=\"\/\/images.weserv.nl\/?url=https:\/\/img-blog.csdnimg.cn\/d00b6465f3224424a995f7f4583b5e95.png\" alt=\"\"\/><img loading=\"lazy\" decoding=\"async\" height=\"15\" width=\"15\" src=\"blob:http:\/\/www.menglanglang.cn\/9474a27f-9c4b-48f8-a810-cd2289feaca1\"\/><\/p>\n\n\n\n<p>SecureCRT \u7684\u7248\u672c\u4e0d\u540c\uff0c\u52a0\u5bc6\u683c\u5f0f\u6709\u4e24\u79cd\u3002<\/p>\n\n\n\n<p><strong>\u683c\u5f0f\u4e00\uff1a<\/strong><\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>S:\"Password V2\"=02:30d93758e1ea303c18235301266dc93a5d69070b40668251a2c75de132a5a034b018dab1a172bd73da69151d6fd4099824f2a4fb5f57c5f854e9a9012ff0e6c1<\/p><\/blockquote>\n\n\n\n<p>\u6267\u884c\u547d\u4ee4\uff1a<strong>python SecureCRTCipher.py dec -v2 30d93758e1ea303c18235301266dc93a5d69070b40668251a2c75de132a5a034b018dab1a172bd73da69151d6fd4099824f2a4fb5f57c5f854e9a9012ff0e6c1<\/strong><\/p>\n\n\n\n<p>\u6ce8\u610f\uff1a-V2 \u53c2\u6570\u540e\u7684\u503c\uff0c\u662f\u683c\u5f0f\u4e00\u4e2d\u3010=\u3011\u540e\u9762\u7684\u503c\uff0c\u5e76\u4e14\u53bb\u6389\u301002\uff1a\u3011\u3002<\/p>\n\n\n\n<p>\u6267\u884c\u540e\uff0c\u53ef\u4ee5\u770b\u5230\u660e\u6587\u5bc6\u7801\u5df2\u7ecf\u8f93\u51fa\u5230\u7ec8\u7aef\u4e2d\u4e86\uff0c\u5982\u56fe\uff1a&nbsp;<\/p>\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" height=\"90\" width=\"900\" src=\"\/\/images.weserv.nl\/?url=https:\/\/img-blog.csdnimg.cn\/f5dcdea9c9084c75b05c89c7fc0b3a32.png\" alt=\"\"\/><\/p>\n\n\n\n<p><strong>\u683c\u5f0f\u4e8c\uff1a<\/strong><\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>S:\"Password\"=uc71bd1c86f3b804e42432f53247c50d9287f410c7e59166969acab69daa6eaadbe15c0c54c0e076e945a6d82f9e13df2<\/p><\/blockquote>\n\n\n\n<p>\u6267\u884c\u547d\u4ee4\uff1a<strong>python SecureCRTCipher.py dec<\/strong> c71bd1c86f3b804e42432f53247c50d9287f410c7e59166969acab69daa6eaadbe15c0c54c0e076e945a6d82f9e13df2<\/p>\n\n\n\n<p>\u6ce8\u610f\uff1adec \u540e\u7684\u503c\uff0c\u662f\u683c\u5f0f\u4e8c\u4e2d\u3010=\u3011\u540e\u9762\u7684\u503c\uff0c\u5e76\u4e14\u53bb\u6389\u3010u\u3011\u3002<\/p>\n\n\n\n<p>\u6267\u884c\u540e\uff0c\u53ef\u4ee5\u770b\u5230\u660e\u6587\u5bc6\u7801\u5df2\u7ecf\u8f93\u51fa\u5230\u7ec8\u7aef\u4e2d\u4e86\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" height=\"82\" width=\"900\" src=\"\/\/images.weserv.nl\/?url=https:\/\/img-blog.csdnimg.cn\/2289871132804cc4ae245bd6812446c1.png\" alt=\"\"\/><\/p>\n\n\n\n<p>Good Luck\uff01 \u200b<\/p>\n\n\n\n<p>\u539f\u6587\u94fe\u63a5\uff1a<a href=\"https:\/\/blog.csdn.net\/tzhuwb\/article\/details\/125288970\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/blog.csdn.net\/tzhuwb\/article\/details\/125288970<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u200b\u5728\u65e5\u5e38\u5de5\u4f5c\u548c\u5b66\u4e60\u4e2d\uff0c\u670d\u52a1\u5668\u5e38\u4e3a Linux \u670d\u52a1\u5668\uff0c\u800c\u4e3b\u673a\u7535\u8111\u4e00\u7248\u4e3a Windows \u7cfb\u7edf\uff0c\u5728\u4e3b\u673a\u4e0a\u5982\u4f55\u8fde\u63a5 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[602,813,773,597,183,862],"class_list":["post-5041","post","type-post","status-publish","format-standard","hentry","category-it-utility","tag-linux","tag-python","tag-773","tag-development-tools","tag-183","tag-862"],"_links":{"self":[{"href":"http:\/\/www.menglanglang.cn\/index.php?rest_route=\/wp\/v2\/posts\/5041","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.menglanglang.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.menglanglang.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.menglanglang.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.menglanglang.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5041"}],"version-history":[{"count":2,"href":"http:\/\/www.menglanglang.cn\/index.php?rest_route=\/wp\/v2\/posts\/5041\/revisions"}],"predecessor-version":[{"id":5043,"href":"http:\/\/www.menglanglang.cn\/index.php?rest_route=\/wp\/v2\/posts\/5041\/revisions\/5043"}],"wp:attachment":[{"href":"http:\/\/www.menglanglang.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5041"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.menglanglang.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5041"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.menglanglang.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5041"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}