Last active
June 28, 2024 10:15
-
-
Save huntfx/612550168254f4075897ec4665d64f1d 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 | |
_group = '(?P<{}>{}+)' | |
WORKBENCH_PATTERN = '{dbm}@{host}:{port}\2{user}\3{password}'.format( | |
dbm=_group.format('dbm', r'\w'), | |
host=_group.format('host', r'[\w\.-]'), | |
port=_group.format('port', r'\d'), | |
user=_group.format('user', r'[\w\.-]'), | |
password=_group.format('password', '.'), | |
) | |
def read_workbench_user_data(file_path=None): | |
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 = re.match(WORKBENCH_PATTERN, 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