forked from HyperSine/how-does-navicat-encrypt-password
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShowNavicat.py
147 lines (124 loc) · 5.77 KB
/
ShowNavicat.py
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/usr/bin/env python3
import platform
if platform.system().lower() != 'windows':
print('Please run this script in Windows.')
exit(-1)
import sys, winreg
from Crypto.Hash import SHA1
from Crypto.Cipher import AES, Blowfish
from Crypto.Util import strxor
#
# Navicat12Crypto is not needed
#
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 EncryptString(self, s : str):
if type(s) != str:
raise TypeError('Parameter s must be a str.')
else:
plaintext = s.encode('ascii')
ciphertext = b''
cv = self._IV
full_round, left_length = divmod(len(plaintext), 8)
for i in range(0, full_round * 8, 8):
t = strxor.strxor(plaintext[i:i + 8], cv)
t = self._Cipher.encrypt(t)
cv = strxor.strxor(cv, t)
ciphertext += t
if left_length != 0:
cv = self._Cipher.encrypt(cv)
ciphertext += strxor.strxor(plaintext[8 * full_round:], cv[:left_length])
return ciphertext.hex().upper()
def DecryptString(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')
NavicatCipher = Navicat11Crypto()
ServersTypes = {
'MySQL Server' : 'Software\\PremiumSoft\\Navicat\\Servers',
'MariaDB Server' : 'Software\\PremiumSoft\\NavicatMARIADB\\Servers',
'MongoDB Server' : 'Software\\PremiumSoft\\NavicatMONGODB\\Servers',
'MSSQL Server' : 'Software\\PremiumSoft\\NavicatMSSQL\\Servers',
'OracleSQL Server' : 'Software\\PremiumSoft\\NavicatOra\\Servers',
'PostgreSQL Server' : 'Software\\PremiumSoft\\NavicatPG\\Servers',
# 'SQLite Server' : 'Software\\PremiumSoft\\NavicatSQLite\\Servers'
}
for ServersTypeName, ServersRegistryPath in ServersTypes.items():
print('+--------------------------------------------------+')
print('|%s|' % ServersTypeName.center(50))
print('+--------------------------------------------------+')
try:
ServersRegistryKey = winreg.OpenKey(winreg.HKEY_CURRENT_USER, ServersRegistryPath)
except OSError:
print('')
print('No servers is found.')
print('')
continue
i = 0
try:
while True:
print('')
ServerName = winreg.EnumKey(ServersRegistryKey, i)
ServerRegistryKey = winreg.OpenKey(ServersRegistryKey, ServerName)
try:
ServerHost = winreg.QueryValueEx(ServerRegistryKey, 'Host')[0]
ServerPort = winreg.QueryValueEx(ServerRegistryKey, 'Port')[0]
if ServersTypeName == 'OracleSQL Server':
ServerInitialDb = winreg.QueryValueEx(ServerRegistryKey, 'InitialDatabase')[0]
else:
ServerInitialDb = None
ServerUsername = winreg.QueryValueEx(ServerRegistryKey, 'Username')[0]
ServerPassword = winreg.QueryValueEx(ServerRegistryKey, 'Pwd')[0]
if len(ServerPassword) != 0:
ServerPassword = NavicatCipher.DecryptString(ServerPassword)
ServerUseSsh = winreg.QueryValueEx(ServerRegistryKey, 'UseSSH')[0]
if ServerUseSsh != 0:
ServerSshHost = winreg.QueryValueEx(ServerRegistryKey, 'SSH_Host')[0]
ServerSshPort = winreg.QueryValueEx(ServerRegistryKey, 'SSH_Port')[0]
ServerSshUsername = winreg.QueryValueEx(ServerRegistryKey, 'SSH_Username')[0]
ServerSshPassword = winreg.QueryValueEx(ServerRegistryKey, 'SSH_Password')[0]
if len(ServerSshPassword) != 0:
ServerSshPassword = NavicatCipher.DecryptString(ServerSshPassword)
else:
ServerSshHost = None
ServerSshPort = None
ServerSshUsername = None
ServerSshPassword = None
print(ServerName.center(50, '-'))
print('%-18s' % 'Host:', ServerHost)
print('%-18s' % 'Port:', ServerPort)
if ServerInitialDb != None:
print('%-18s' % 'InitialDatabase:', ServerInitialDb)
print('%-18s' % 'Username:', ServerUsername)
print('%-18s' % 'Password:', ServerPassword)
if ServerUseSsh:
print('%-18s' % 'SSH Host:', ServerSshHost)
print('%-18s' % 'SSH Port:', ServerSshPort)
print('%-18s' % 'SSH Username:', ServerSshUsername)
print('%-18s' % 'SSH Password:', ServerSshPassword)
except:
print('[-] Failed to get info about server "%s". Server info may be corrupted.' % ServerName, file = sys.stderr)
winreg.CloseKey(ServerRegistryKey)
i += 1
except OSError:
if i == 0:
print('No servers is found.')
print('')
continue
winreg.CloseKey(ServersRegistryKey)