Navicat 数据库管理软件还原真实连接密码 Python代码

查看 23|回复 3
作者:demo23   
代码用于 Navicat 数据库管理软件还原真实连接密码。
希望能对大家有用。
[Python] 纯文本查看 复制代码import binascii
import hashlib
from Crypto.Cipher import AES, Blowfish
from Crypto.Util.Padding import pad, unpad
from Crypto.Util.strxor import strxor
class NavicatPassword:
    def __init__(self, version=12):
        self.version = version
        self.aes_key = b'libcckeylibcckey'
        self.aes_iv = b'libcciv libcciv '
        self.blow_string = '3DC5CA39'
        self.blow_key = hashlib.sha1(self.blow_string.encode()).digest()
        self.blow_iv = binascii.unhexlify('d9c7c3c8870d64bd')
    def encrypt(self, string):
        if self.version == 11:
            return self._encrypt_eleven(string)
        elif self.version == 12:
            return self._encrypt_twelve(string)
        else:
            return False
    def decrypt(self, string):
        if self.version == 11:
            return self._decrypt_eleven(string)
        elif self.version == 12:
            return self._decrypt_twelve(string)
        else:
            return False
    def _encrypt_eleven(self, string):
        string = string.encode()
        round_count = len(string) // 8
        left_length = len(string) % 8
        result = b''
        current_vector = self.blow_iv
        for i in range(round_count):
            block = string[8 * i: 8 * (i + 1)]
            temp = self._encrypt_block(strxor(block, current_vector))
            current_vector = strxor(current_vector, temp)
            result += temp
        if left_length:
            current_vector = self._encrypt_block(current_vector)
            last_block = string[8 * round_count:]
            result += strxor(last_block, current_vector[:len(last_block)])
        return result.hex().upper()
    def _encrypt_twelve(self, string):
        string = string.encode()
        cipher = AES.new(self.aes_key, AES.MODE_CBC, self.aes_iv)
        padded = pad(string, AES.block_size)
        encrypted = cipher.encrypt(padded)
        return encrypted.hex().upper()
    def _decrypt_eleven(self, upper_string):
        string = binascii.unhexlify(upper_string.lower())
        round_count = len(string) // 8
        left_length = len(string) % 8
        result = b''
        current_vector = self.blow_iv
        for i in range(round_count):
            encrypted_block = string[8 * i: 8 * (i + 1)]
            temp = strxor(self._decrypt_block(encrypted_block), current_vector)
            current_vector = strxor(current_vector, encrypted_block)
            result += temp
        if left_length:
            current_vector = self._encrypt_block(current_vector)
            last_block = string[8 * round_count:]
            result += strxor(last_block, current_vector[:len(last_block)])
        return result.decode()
    def _decrypt_twelve(self, upper_string):
        string = binascii.unhexlify(upper_string.lower())
        cipher = AES.new(self.aes_key, AES.MODE_CBC, self.aes_iv)
        decrypted = cipher.decrypt(string)
        return unpad(decrypted, AES.block_size).decode()
    def _encrypt_block(self, block):
        cipher = Blowfish.new(self.blow_key, Blowfish.MODE_ECB)
        return cipher.encrypt(block)
    def _decrypt_block(self, block):
        cipher = Blowfish.new(self.blow_key, Blowfish.MODE_ECB)
        return cipher.decrypt(block)
navicat_password = NavicatPassword(version=12)
decrypted = navicat_password.decrypt('15057D7BA390')
print(decrypted)
更改自己导出的密码:


image.png (11.21 KB, 下载次数: 1)
下载附件
2025-8-15 15:53 上传

运行后直接输出密码:


image.png (2.61 KB, 下载次数: 2)
下载附件
2025-8-15 15:52 上传

如报错: ModuleNotFoundError: No module named 'Crypto'
则安装库: pip install pycryptodome


image.png (45.63 KB, 下载次数: 2)
下载附件
2025-8-15 15:51 上传

下载次数, 密码

禁之零零   

Traceback (most recent call last):
  File "C:\Users\Administrator\Documents\PycharmProjects\解密Navicat数据库密码.py", line 96, in
    decrypted = navicat_password.decrypt('14A600148C25EDE8EDE18FD7')
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Administrator\Documents\PycharmProjects\解密Navicat数据库密码.py", line 29, in decrypt
    return self._decrypt_twelve(string)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Administrator\Documents\PycharmProjects\解密Navicat数据库密码.py", line 83, in _decrypt_twelve
    decrypted = cipher.decrypt(string)
                ^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python312\Lib\site-packages\Crypto\Cipher\_mode_cbc.py", line 246, in decrypt
    raise ValueError("Data must be padded to %d byte boundary in CBC mode" % self.block_size)
ValueError: Data must be padded to 16 byte boundary in CBC mode
禁之零零   


禁之零零 发表于 2025-9-9 09:35
Traceback (most recent call last):
  File "C:%users\Administrator\Documents\PycharmProjects\解密Nav ...

直接复制下来执行报错
demo23
OP
  


禁之零零 发表于 2025-9-9 09:40
直接复制下来执行报错

试试 python 3.12 。   安装一下库 pip install pycryptodome 。  还有文件格式用 utf-8 编码。 再试一下。
您需要登录后才可以回帖 登录 | 立即注册

返回顶部