Skip to content

Instantly share code, notes, and snippets.

@samyakranjan
Last active January 4, 2022 06:18
Show Gist options
  • Save samyakranjan/e3971d569d03e0044fb04043712cbb69 to your computer and use it in GitHub Desktop.
Save samyakranjan/e3971d569d03e0044fb04043712cbb69 to your computer and use it in GitHub Desktop.
DBeaver Password Decrypter
import os
import sys
import json
import base64
# Pycryptodome (pip install pycryptodome)
from Crypto.Cipher import AES
PASSWORD_DECRYPTION_KEY = bytes(
[186, 187, 74, 159, 119, 74, 184, 83, 201, 108, 45, 101, 61, 254, 84, 74])
lookup_paths = []
if sys.platform == "darwin":
lookup_paths = ['~/Library/DBeaverData/workspace6/General/.dbeaver/credentials-config.json']
elif sys.platform == "win32":
lookup_paths = ['~\AppData\Roaming\DBeaverData\workspace6\General\.dbeaver\credentials-config.json']
if len(sys.argv) == 2:
lookup_paths.append(sys.argv[1])
if not lookup_paths:
print("OS %s not supported. Please provide path to credentials-config.json" % sys.platform)
for path in lookup_paths:
complete_path = os.path.expanduser(path)
try:
if not os.path.isfile(complete_path):
print("File not found")
continue
contents = open(complete_path, 'rb').read()
decryptor = AES.new(PASSWORD_DECRYPTION_KEY, AES.MODE_CBC, contents[:16])
padded_output = decryptor.decrypt(contents[16:])
output = padded_output.rstrip(padded_output[-1:])
print(complete_path)
try:
print(json.dumps(json.loads(output), indent=4, sort_keys=True))
except:
print(output)
except:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment