Created
January 24, 2023 14:57
-
-
Save ottosch/87e63959ea826a06ba2b724934c362af to your computer and use it in GitHub Desktop.
Decrypts a DBeaver pass
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python | |
import base64, binascii, sys | |
key = bytearray("sdf@!#$verf^wv%6Fwe%$$#FFGwfsdefwfe135s$^H)dg", "utf8") | |
def main(): | |
if len(sys.argv) < 2: | |
print(f"usage: {sys.argv[0]} <password>", file = sys.stderr) | |
sys.exit(1) | |
password = sys.argv[1] | |
print(f"Encrypted password: {password}") | |
try: | |
password = base64.b64decode(password) | |
except binascii.Error as err: | |
print(f"Invalid base64 password: {err}", file = sys.stderr) | |
sys.exit(1) | |
result = xor(password) | |
if not (result[len(result) - 2] == 0x00 and result[len(result) - 1] == 0x81): | |
print("Invalid encrypted password", file = sys.stderr) | |
sys.exit(1) | |
decrypted = result[:-2].decode() | |
print(f"Decrypted password: {decrypted}") | |
print() | |
def xor(plain): | |
xored = bytearray() | |
for i, b in enumerate(plain): | |
if i >= len(key): | |
xored.append(b ^ key[0]) | |
else: | |
xored.append(b ^ key[i]) | |
return xored | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment