Navicat获取密码
有大神写了解析Navicat中连接的密码的PHP,想要解析密码,需要:
- 将连接导出
- 配置php(本地不需要安装PHP,网上有运行的网页)
- 运行获取密码
导出Navicat连接
- 文件-导出连接-选择想要解析的连接,导出文件即可
解析密码
打开ncx文件,Password里就是密码,
- 打开 https://tool.lu/coderunner/
- 将下面代码拷贝进去
<?php
namespace FatSmallTools;
class NavicatPassword
{
protected $version = 0;
protected $aesKey = 'libcckeylibcckey';
protected $aesIv = 'libcciv libcciv ';
protected $blowString = '3DC5CA39';
protected $blowKey = null;
protected $blowIv = null;
public function __construct($version = 12)
{
$this->version = $version;
$this->blowKey = sha1('3DC5CA39', true);
$this->blowIv = hex2bin('d9c7c3c8870d64bd');
}
public function encrypt($string)
{
$result = FALSE;
switch ($this->version) {
case 11:
$result = $this->encryptEleven($string);
break;
case 12:
$result = $this->encryptTwelve($string);
break;
default:
break;
}
return $result;
}
protected function encryptEleven($string)
{
$round = intval(floor(strlen($string) / 8));
$leftLength = strlen($string) % 8;
$result = '';
$currentVector = $this->blowIv;
for ($i = 0; $i < $round; $i++) {
$temp = $this->encryptBlock($this->xorBytes(substr($string, 8 * $i, 8), $currentVector));
$currentVector = $this->xorBytes($currentVector, $temp);
$result .= $temp;
}
if ($leftLength) {
$currentVector = $this->encryptBlock($currentVector);
$result .= $this->xorBytes(substr($string, 8 * $i, $leftLength), $currentVector);
}
return strtoupper(bin2hex($result));
}
protected function encryptBlock($block)
{
return openssl_encrypt($block, 'BF-ECB', $this->blowKey, OPENSSL_RAW_DATA|OPENSSL_NO_PADDING);
}
protected function decryptBlock($block)
{
return openssl_decrypt($block, 'BF-ECB', $this->blowKey, OPENSSL_RAW_DATA|OPENSSL_NO_PADDING);
}
protected function xorBytes($str1, $str2)
{
$result = '';
for ($i = 0; $i < strlen($str1); $i++) {
$result .= chr(ord($str1[$i]) ^ ord($str2[$i]));
}
return $result;
}
protected function encryptTwelve($string)
{
$result = openssl_encrypt($string, 'AES-128-CBC', $this->aesKey, OPENSSL_RAW_DATA, $this->aesIv);
return strtoupper(bin2hex($result));
}
public function decrypt($string)
{
$result = FALSE;
switch ($this->version) {
case 11:
$result = $this->decryptEleven($string);
break;
case 12:
$result = $this->decryptTwelve($string);
break;
default:
break;
}
return $result;
}
protected function decryptEleven($upperString)
{
$string = hex2bin(strtolower($upperString));
$round = intval(floor(strlen($string) / 8));
$leftLength = strlen($string) % 8;
$result = '';
$currentVector = $this->blowIv;
for ($i = 0; $i < $round; $i++) {
$encryptedBlock = substr($string, 8 * $i, 8);
$temp = $this->xorBytes($this->decryptBlock($encryptedBlock), $currentVector);
$currentVector = $this->xorBytes($currentVector, $encryptedBlock);
$result .= $temp;
}
if ($leftLength) {
$currentVector = $this->encryptBlock($currentVector);
$result .= $this->xorBytes(substr($string, 8 * $i, $leftLength), $currentVector);
}
return $result;
}
protected function decryptTwelve($upperString)
{
$string = hex2bin(strtolower($upperString));
return openssl_decrypt($string, 'AES-128-CBC', $this->aesKey, OPENSSL_RAW_DATA, $this->aesIv);
}
}
use FatSmallToolsNavicatPassword;
//需要指定版本,11或12
$navicatPassword = new NavicatPassword(12);
//$navicatPassword = new NavicatPassword(11);
//解密
//$decode = $navicatPassword->decrypt('15057D7BA390');
$decode = $navicatPassword->decrypt('EDB0DE94B9A53CD3F03A934A9DBE8359');
echo $decode."
";
x
1
2
3
namespace FatSmallTools;
4
5
class NavicatPassword
6
{
7
protected $version = 0;
8
protected $aesKey = 'libcckeylibcckey';
9
protected $aesIv = 'libcciv libcciv ';
10
protected $blowString = '3DC5CA39';
11
protected $blowKey = null;
12
protected $blowIv = null;
13
14
public function __construct($version = 12)
15
{
16
$this->version = $version;
17
$this->blowKey = sha1('3DC5CA39', true);
18
$this->blowIv = hex2bin('d9c7c3c8870d64bd');
19
}
20
21
public function encrypt($string)
22
{
23
$result = FALSE;
24
switch ($this->version) {
25
case 11:
26
$result = $this->encryptEleven($string);
27
break;
28
case 12:
29
$result = $this->encryptTwelve($string);
30
break;
31
default:
32
break;
33
}
34
35
return $result;
36
}
37
38
protected function encryptEleven($string)
39
{
40
$round = intval(floor(strlen($string) / 8));
41
$leftLength = strlen($string) % 8;
42
$result = '';
43
$currentVector = $this->blowIv;
44
45
for ($i = 0; $i < $round; $i++) {
46
$temp = $this->encryptBlock($this->xorBytes(substr($string, 8 * $i, 8), $currentVector));
47
$currentVector = $this->xorBytes($currentVector, $temp);
48
$result .= $temp;
49
}
50
51
if ($leftLength) {
52
$currentVector = $this->encryptBlock($currentVector);
53
$result .= $this->xorBytes(substr($string, 8 * $i, $leftLength), $currentVector);
54
}
55
56
return strtoupper(bin2hex($result));
57
}
58
59
protected function encryptBlock($block)
60
{
61
return openssl_encrypt($block, 'BF-ECB', $this->blowKey, OPENSSL_RAW_DATA|OPENSSL_NO_PADDING);
62
}
63
64
protected function decryptBlock($block)
65
{
66
return openssl_decrypt($block, 'BF-ECB', $this->blowKey, OPENSSL_RAW_DATA|OPENSSL_NO_PADDING);
67
}
68
69
protected function xorBytes($str1, $str2)
70
{
71
$result = '';
72
for ($i = 0; $i < strlen($str1); $i++) {
73
$result .= chr(ord($str1[$i]) ^ ord($str2[$i]));
74
}
75
76
return $result;
77
}
78
79
protected function encryptTwelve($string)
80
{
81
$result = openssl_encrypt($string, 'AES-128-CBC', $this->aesKey, OPENSSL_RAW_DATA, $this->aesIv);
82
return strtoupper(bin2hex($result));
83
}
84
85
public function decrypt($string)
86
{
87
$result = FALSE;
88
switch ($this->version) {
89
case 11:
90
$result = $this->decryptEleven($string);
91
break;
92
case 12:
93
$result = $this->decryptTwelve($string);
94
break;
95
default:
96
break;
97
}
98
99
return $result;
100
}
101
102
protected function decryptEleven($upperString)
103
{
104
$string = hex2bin(strtolower($upperString));
105
106
$round = intval(floor(strlen($string) / 8));
107
$leftLength = strlen($string) % 8;
108
$result = '';
109
$currentVector = $this->blowIv;
110
111
for ($i = 0; $i < $round; $i++) {
112
$encryptedBlock = substr($string, 8 * $i, 8);
113
$temp = $this->xorBytes($this->decryptBlock($encryptedBlock), $currentVector);
114
$currentVector = $this->xorBytes($currentVector, $encryptedBlock);
115
$result .= $temp;
116
}
117
118
if ($leftLength) {
119
$currentVector = $this->encryptBlock($currentVector);
120
$result .= $this->xorBytes(substr($string, 8 * $i, $leftLength), $currentVector);
121
}
122
123
return $result;
124
}
125
126
protected function decryptTwelve($upperString)
127
{
128
$string = hex2bin(strtolower($upperString));
129
return openssl_decrypt($string, 'AES-128-CBC', $this->aesKey, OPENSSL_RAW_DATA, $this->aesIv);
130
}
131
}
132
133
134
use FatSmallToolsNavicatPassword;
135
136
//需要指定版本,11或12
137
$navicatPassword = new NavicatPassword(12);
138
//$navicatPassword = new NavicatPassword(11);
139
140
//解密
141
//$decode = $navicatPassword->decrypt('15057D7BA390');
142
$decode = $navicatPassword->decrypt('EDB0DE94B9A53CD3F03A934A9DBE8359');
143
echo $decode."
";
144
- 设置Navicat的版本(基本现在是12了)
- 在 $navicatPassword->decrypt('')中设置密码
- 执行之后,在右边就解析出密码了
参考:
- https://tool.lu/coderunner/
- https://blog.csdn.net/CCESARE/article/details/104746596
- https://blog.csdn.net/weixin_40903194/article/details/103233127