Skip to content

Instantly share code, notes, and snippets.

@intfrr
Forked from felipou/decrypt_dbeaver.py
Created July 11, 2020 19:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save intfrr/9eb498b06cf3ca8794c572229f28be56 to your computer and use it in GitHub Desktop.
Save intfrr/9eb498b06cf3ca8794c572229f28be56 to your computer and use it in GitHub Desktop.
DBeaver password decryption script - for newer versions of DBeaver
# https://stackoverflow.com/questions/39928401/recover-db-password-stored-in-my-dbeaver-connection
# requires pycrypto lib (pip install pycrypto)
import sys
import base64
import os
import json
from Crypto.Cipher import AES
if len(sys.argv) < 2:
filepath = os.path.expanduser("~/.local/share/.DBeaverData/workspace6/General/.dbeaver/credentials-config.json")
else:
filepath = sys.argv[1]
print(filepath)
#PASSWORD_DECRYPTION_KEY = bytes([-70, -69, 74, -97, 119, 74, -72, 83, -55, 108, 45, 101, 61, -2, 84, 74])
PASSWORD_DECRYPTION_KEY = bytes([186, 187, 74, 159, 119, 74, 184, 83, 201, 108, 45, 101, 61, 254, 84, 74])
data = open(filepath, 'rb').read()
decryptor = AES.new(PASSWORD_DECRYPTION_KEY, AES.MODE_CBC, data[:16])
# The '-8' was observed in my case, I'm not sure it will be the same in every case
# Basically this was the string '\x08\x08\x08\x08\x08\x08\x08\x08' in the decrypted output
output = decryptor.decrypt(data[16:])[:-8]
try:
print(json.dumps(json.loads(output), indent=4, sort_keys=True))
except:
print(output)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment