Python 解密 Navicat导出的数据库连接,Navicat数据库连接导入DBeaver。
最近公司收到Navicat律师告知书,让停止使用Navicat,用了那么久的数据库连接工具,不得不换其他的。
最终选择了开源的DBeaver。
下载链接:https://dbeaver.io
下载开源版本:
也可以用这个地址:
https://objects.githubusercontent.com/github-production-release-asset-2e65be/44662669/30fdb247-57eb-4183-b836-19d8d625434e?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=releaseassetproduction%2F20241219%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20241219T061958Z&X-Amz-Expires=300&X-Amz-Signature=f55c4bc0a182291a6e29415848ed64ef95a4e3f039e02c8214c6c1de88627af3&X-Amz-SignedHeaders=host&response-content-disposition=attachment%3B%20filename%3Ddbeaver-ce-24.3.0-x86_64-setup.exe&response-content-type=application%2Foctet-stream
若不能使用的话,自己进入上面的页面下载。
收费版本去这:https://dbeaver.com/download/,收费的有5个版本,都挺贵的。收费的话,还是navicat便宜。
-----------------------------------------------------------------------------------
安装完DBeaver后,把Navicat导出的connections.ncx文件直接导入DBeaver。直接访问提示连接失败,因为connections.ncx文件里的密码都是加密的。
如图:
网上找了许久方法,有PHP的,复制代码去线上执行,反正跑不动,有python的,但也搞不定。
后来自己写了一个,大家可以直接使用:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | #!/usr/bin/env python3 import sys from Crypto. Hash import SHA1 from Crypto.Cipher import AES, Blowfish from Crypto.Util import strxor, Padding import xml.etree.ElementTree as ET class Navicat11Crypto: def __init__( self , Key = b '3DC5CA39' ): self ._Key = SHA1.new(Key).digest() self ._Cipher = Blowfish.new( self ._Key, Blowfish.MODE_ECB) self ._IV = self ._Cipher.encrypt(b '\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF' ) def decrypt_string( self , s: str ): if type (s) ! = str : raise TypeError( 'Parameter s must be str.' ) else : plaintext = b'' ciphertext = bytes.fromhex(s) cv = self ._IV full_round, left_length = divmod ( len (ciphertext), 8 ) for i in range ( 0 , full_round * 8 , 8 ): t = self ._Cipher.decrypt(ciphertext[i:i + 8 ]) t = strxor.strxor(t, cv) plaintext + = t cv = strxor.strxor(cv, ciphertext[i:i + 8 ]) if left_length ! = 0 : cv = self ._Cipher.encrypt(cv) plaintext + = strxor.strxor(ciphertext[ 8 * full_round:], cv[:left_length]) return plaintext.decode( 'ascii' ) if __name__ = = '__main__' : pc = Navicat11Crypto() xml_path_x = r 'C:\Users\xxxx\connections-all-20241219.ncx' xml_path_y = r "C:\Users\xxxxx\connections.ncx" tree = ET.parse(xml_path_y) root_element = tree.getroot() for child in root_element: print ( '---------------------------------' ) print ( 'ConnectionName:' , child.attrib[ 'ConnectionName' ]) print ( 'Host:' , child.attrib[ 'Host' ]) print ( 'Port:' , child.attrib[ 'Port' ]) print ( 'UserName:' , child.attrib[ 'UserName' ]) Password1 = pc.decrypt_string(child.attrib[ 'Password' ]) print ( 'Password:' , Password1) print ( 'SSH_Host:' , child.attrib[ 'SSH_Host' ]) print ( 'SSH_Port:' , child.attrib[ 'SSH_Port' ]) print ( 'SSH_UserName:' , child.attrib[ 'SSH_UserName' ]) Password2 = pc.decrypt_string(child.attrib[ 'SSH_Password' ]) print ( 'SSH_Password:' , Password2) print ( '------------------------------------' ) |
执行结果:
得到密码后,替换密码即可:
另外,通过导入navicat的数据库连接文件,ssh默认没有加载,需要自己手动配置。
本文来自博客园,作者:drewgg,转载请注明原文链接:https://www.cnblogs.com/drewgg/p/18617750
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?