Forked from huntfx/decrypt-mysql-workbench-user-data.py
Created
November 21, 2023 12:06
-
-
Save neilser/360060dd2cf5f9ac77237667ae16ce5c to your computer and use it in GitHub Desktop.
Read and decrypt the user data from MySQL workbench.
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
import os | |
import re | |
import win32crypt # Requires pywin32 package | |
WORKBENCH_REGEX = re.compile( | |
'(?P<dbm>[A-z]+)' | |
'@' | |
'(?P<host>[A-z0-9._-]+)' | |
':' | |
'(?P<port>[0-9]+)' | |
'\2' | |
'(?P<user>[A-z0-9_-]+)' | |
'\3' | |
'(?P<password>.*)' | |
) | |
def read_workbench_user_data(file_path=None): | |
"""Read and decrypt the raw user data from the workbench file. | |
Adapted from: | |
https://github.com/mysql/mysql-workbench/blob/8.0/library/forms/winforms/src/wf_utilities.cpp#L827-L886 | |
Returns: | |
List of strings in the format "dmb@host:port\2user\3password" | |
""" | |
if file_path is None: | |
file_path = os.path.join(os.getenv('APPDATA'), 'MySQL/Workbench/workbench_user_data.dat') | |
with open(file_path, 'rb') as file: | |
encrypted_data = file.read() | |
decrypted_data = win32crypt.CryptUnprotectData(encrypted_data, None, None, None, 0) | |
decrypted_content = decrypted_data[1].decode('utf-8') | |
return decrypted_content.split('\n')[:-1] | |
if __name__ == '__main__': | |
for item in read_workbench_user_data(): | |
match = WORKBENCH_REGEX.match(item) | |
print(f'{match.group("dbm")}:') | |
print(f'\tHost: {match.group("host")}:{match.group("port")}') | |
print(f'\tUsername: {match.group("user")}') | |
print(f'\tPassword: {match.group("password")}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment