恢复存储在我的DBeaver连接中的数据库密码

Git*_*gal 43 database encryption passwords dbeaver

我忘记了开发实例的密码(不负责任......是的,我正在研究它).我使用密码保存在我的DBeaver中的连接.我仍然可以使用该连接进行连接.DBeaver没有以纯文本显示它.无论如何我可以检索密码吗?要求DBA重置密码是最后的手段.我试图将粘贴复制到记事本中,显然禁用了复制.

so-*_*ude 128

我最近遇到了这个问题.请按照以下步骤操作(我的DBeaver版本是3.5.8,它是在Mac OSX El Capitan上)

  1. 找到DBeaver存储连接详细信息的文件.对我来说,它就在这个位置 ~/.dbeaver/General/.dbeaver-data-sources.xml.此文件是隐藏的,因此在您查找时请记住这一点.
  2. 在该文件中找到您感兴趣的数据源定义节点.
  3. 解密密码:不幸的是,除密码外,一切都是纯文本; 密码是某种加密形式.我通过复制DBeaver解密密码的核心来整理一个快速而又脏的Java程序.获得加密密码字符串后,只需执行此程序,它就会将密码转换为纯文本并打印出来

如何运行它

在第13行,只需替换OwEKLE4jpQ==您在.dbeaver-data-sources.xml感兴趣的数据源文件中找到的任何加密密码.编译并运行它,它将打印纯文本密码.

https://github.com/so-random-dude/oneoffcodes/blob/master/SimpleStringEncrypter.java

编辑

显然,这是一个"流行"的错误.所以我已经使用上述代码部署了一个AWS lambda函数.使用此风险需要您自担风险,您永远不会知道我是否记录了您的密码:D

curl https://lmqm83ysii.execute-api.us-west-2.amazonaws.com/prod/dbeaver-password-decrypter \
-X POST --data "OwEKLE4jpQ=="
Run Code Online (Sandbox Code Playgroud)

编辑2

更好的是,这里是用户界面http://dbeaver-password-decrypter.s3-website-us-west-2.amazonaws.com/.不言而喻,使用此风险需要您自担风险.非Https是你最不担心的!:)

  • 我使用您的代码作为参考创建了一个等效的python脚本:https://gist.github.com/felipou/f5472ad5f6a414528b44beb102e17fb4它比我安装Java编译器要快得多:) (6认同)
  • @felipou您的解决方案很棒,应将其发布为答案。 (2认同)
  • 从6.1.3版开始,此功能不再起作用。现在,凭据将根据以下内容以加密方式存储在`.dbeaver / credentials-config.json`中:https://github.com/dbeaver/dbeaver/wiki/Admin-Manage-Connections。我假设这是一个加密的json文件(不是纯文本json)。 (2认同)

Fia*_*eid 67

对于 Windows 用户(测试版本 7.3.4,还测试了 22.2.3)

按文件 > 导出 > DBeaver > 项目

将导出文件的名称更改为.zip,然后解压

下载OpenSSL,并复制\projects\General\.dbeaver\credentials-config.json到openssl的bin目录同一个文件夹中

然后运行:

openssl aes-128-cbc -d -K babb4a9f774ab853c96c2d653dfe544a -iv 00000000000000000000000000000000 -in "credentials-config.json"
Run Code Online (Sandbox Code Playgroud)

which openssl如果您安装了 WSL,则还可以从 Linux 安装中运行此命令,并且可从 Linux 安装内的任何目录中使用 openssl ( )(在 WSL2 上使用 Ubuntu 进行测试,将文件复制到\\wsl$\Ubuntu\home\me\dbeaver\credentials)。

它将默认输出到终端,如果您需要在文件中添加 > chosen_filename.json到命令中。

  • 也适用于 Ubuntu (3认同)
  • 确认工作! (2认同)

Tat*_*tsh 49

这可以通过 OpenSSL 完成:

openssl aes-128-cbc -d \
  -K babb4a9f774ab853c96c2d653dfe544a \
  -iv 00000000000000000000000000000000 \
  -in credentials-config.json | \
  dd bs=1 skip=16 2>/dev/null
Run Code Online (Sandbox Code Playgroud)

一行中的 macOS 示例:

openssl aes-128-cbc -d -K babb4a9f774ab853c96c2d653dfe544a -iv 00000000000000000000000000000000 -in "${HOME}/Library/DBeaverData/workspace6/General/.dbeaver/credentials-config.json" | dd bs=1 skip=16 2>/dev/null
Run Code Online (Sandbox Code Playgroud)

对于 Linux,将上述路径更改为~/.local/share/DBeaverData/workspace6/General/.dbeaver/credentials-config.json.

密钥来自源代码并转换为十六进制。这可以在 Python 中完成:

>>> import struct
>>> struct.pack('<16b', -70, -69, 74, -97, 119, 74, -72, 83, -55, 108, 45, 101, 61, -2, 84, 74).hex()
'babb4a9f774ab853c96c2d653dfe544a'
Run Code Online (Sandbox Code Playgroud)

编辑:我已经在这里发布了这个脚本

  • 适用于新的 21+:事实上,经过测试:版本 21.0.3.202104181339 (5认同)
  • 与 Windows 版本的 dbeaver 配合得很好,我刚刚在 WSL2 中运行它。 (2认同)
  • 现在,解密密钥存储在 https://github.com/dbeaver/dbeaver/blob/8ed6d430a12ddc065a8bb69ec11babb152462f15/plugins/org.jkiss.dbeaver.registry/src/org/jkiss/dbeaver/registry/BaseProjectImpl.java#L77 (2认同)

fel*_*pou 17

DBeaver 6.1.3+ 版本的 Python 解密脚本,基于@rogerdpack 的回答:

https://gist.github.com/felipou/50b60309f99b70b1e28f6d22da5d8e61

对于较旧的 DBeaver 版本,还有另一个基于 @so-random-dude 回答的脚本:

https://gist.github.com/felipou/f5472ad5f6a414528b44beb102e17fb4


lew*_*s4u 11

对于 Linux 操作系统用户,请在终端中运行以下命令:

openssl aes-128-cbc -d -K babb4a9f774ab853c96c2d653dfe544a -iv 00000000000000000000000000000000 -in "path_to/credentials-config.json" | dd bs=1 skip=16 2>/dev/null
Run Code Online (Sandbox Code Playgroud)

只需将字符串“path_to/credentials-config.json”替换为该文件的实际路径,您将得到如下内容:

{"mysql8-17e009389a8-5fc414bd64e183f4":{"#connection":{"user":"root","password":"root"}},"mysql8-18099236fdf-3c3fc761c6fdde":{"#connection":{"user":"user.name","password":"your_secret_password"},"network/ssh_tunnel":{"user":"sql","jumpServer0.password":""}}}%
Run Code Online (Sandbox Code Playgroud)


Tal*_*iqi 10

这是在所需目标路径上获取 dbeaver 凭据文件的解密版本的命令:

openssl aes-128-cbc -d \
-K babb4a9f774ab853c96c2d653dfe544a \
-iv 00000000000000000000000000000000 \
-in {path for the encrypted credentials file} > \
{your desired destination file}
Run Code Online (Sandbox Code Playgroud)
  • {您想要的目标文件} 例如~/Desktop/dbeaver-credentials.json

您将在桌面上找到dbeaver-credentials.json该文件。但此文件将仅包含带有某些连接节的用户名和密码的列表(例如mysql5-17be86ca5ea-294e2a427af47fc4)。那里不会有数据库或服务器名称。您必须找到针对对象 ID 的连接。


对于 Ubuntusnap软件包dbeaver-ce

  • {加密凭据文件的路径} =~/snap/dbeaver-ce/current/.local/share/DBeaverData/workspace6/General/.dbeaver/credentials-config.json


rog*_*ack 7

对于DBeaver 6.1.3+,现在使用不同的加密将凭据存储在“ json”文件中。

这似乎为我完成了工作:

import javax.crypto.*;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.security.*;

public class DecryptDbeaver {

  // from the DBeaver source 8/23/19 https://github.com/dbeaver/dbeaver/blob/57cec8ddfdbbf311261ebd0c7f957fdcd80a085f/plugins/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/model/impl/app/DefaultSecureStorage.java#L31
  private static final byte[] LOCAL_KEY_CACHE = new byte[] { -70, -69, 74, -97, 119, 74, -72, 83, -55, 108, 45, 101, 61, -2, 84, 74 };

  static String decrypt(byte[] contents) throws InvalidAlgorithmParameterException, InvalidKeyException, IOException, NoSuchPaddingException, NoSuchAlgorithmException {
    try (InputStream byteStream = new ByteArrayInputStream(contents)) {
      byte[] fileIv = new byte[16];
      byteStream.read(fileIv);
      Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
      SecretKey aes = new SecretKeySpec(LOCAL_KEY_CACHE, "AES");
      cipher.init(Cipher.DECRYPT_MODE, aes, new IvParameterSpec(fileIv));
      try (CipherInputStream cipherIn = new CipherInputStream(byteStream, cipher)) {
        return inputStreamToString(cipherIn);
      }
    }
  }

  static String inputStreamToString(java.io.InputStream is) {
    java.util.Scanner s = new java.util.Scanner(is).useDelimiter("\\A");
    return s.hasNext() ? s.next() : "";
  }

  public static void main(String[] args) throws Exception {
    if (args.length != 1) {
      System.err.println("syntax: param1: full path to your credentials-config.json file");
      System.exit(1);
    }
    System.out.println(decrypt(Files.readAllBytes(Paths.get(args[0]))));
  }

}
Run Code Online (Sandbox Code Playgroud)

在本地文件系统上将您的凭据-config.json文件的路径传递给我,

 javac DecryptDbeaver.java # compile it
 java DecryptDbeaver ~/Library/DBeaverData/workspace6/General/.dbeaver/credentials-config.json
Run Code Online (Sandbox Code Playgroud)

它将把用于连接的用户+密码输出到控制台。如果您不知道哪个密码进入哪个数据库,则必须交叉链接ID名称,该ID名称也会输出到同级data-sources.json文件(该文件应该已经存在并且未加密)。

  • 和以前一样,这里是 Python (3) 版本:https://gist.github.com/felipou/50b60309f99b70b1e28f6d22da5d8e61 (5认同)
  • Linux 用户请注意,该文件位于 &lt;workspace&gt;/General/.dbeaver/credentials-config.json Workspace 目录可以在首选项 -&gt; General -&gt; Workspace 中找到。所以对我来说是:〜/.local/share/DBeaverData/workspace6/General/.dbeaver/credentials-config.json (3认同)
  • 在一个 CLI 中,java 现在可以运行 java 文件: `java DecryptDbeaver.java ~/.local/share/DBeaverData/workspace6/General/.dbeaver/credentials-config.json ` (2认同)